Skip to content
Nov 24 09

Javascript reserved words trigger “Expected Identifier” error on IE

by Jonathon

If you’re getting an unreasonable “Expected Identifier” Javascript error on IE6/7, check to see if you have any variable names which are reserved words.

This also goes for HTML form element names:

<form name="aform">
    <input type="text" name="name" />
</form>

Then accessing document.aform.name.value would throw an error since name is a reserved word.

Javascript Reserved Words

  • abstract
  • alert
  • Anchor
  • Area
  • arguments
  • Array
  • assign
  • blur
  • boolean or Boolean
  • break
  • Button
  • byte
  • callee
  • caller
  • captureEvents
  • case
  • catch
  • char
  • Checkbox
  • class
  • clearInterval
  • clearTimeout
  • close
  • closed
  • comment
  • confirm
  • const
  • constructor
  • continue
  • Date
  • debugger
  • default
  • defaultStatus
  • delete
  • do
  • document
  • Document
  • double
  • Element
  • else
  • enum
  • escape
  • eval
  • export
  • extends
  • false
  • FileUpload
  • final
  • finally
  • find
  • float
  • focus
  • for
  • Form
  • Frame
  • frames
  • function
  • Function
  • getClass
  • goto
  • Hidden
  • history or History
  • home
  • if
  • Image
  • implements
  • import
  • in
  • Infinity
  • innerHeight
  • innerWidth
  • instanceOf
  • int
  • interface
  • isFinite
  • isNan
  • java
  • JavaArray
  • JavaClass
  • JavaObject
  • JavaPackage
  • label
  • length
  • Link
  • location or Location
  • locationbar
  • long
  • Math
  • menubar
  • MimeType
  • moveBy
  • moveTo
  • name
  • NaN
  • native
  • navigate
  • navigator or Navigator
  • netscape
  • new
  • null
  • Number
  • Object
  • onBlur
  • onError
  • onFocus
  • onLoad
  • onUnload
  • open
  • opener
  • Option
  • outerHeight
  • outerWidth
  • package
  • Packages
  • pageXoffset
  • pageYoffset
  • parent
  • parseFloat
  • parseInt
  • Password
  • personalbar
  • Plugin
  • print
  • private
  • prompt
  • protected
  • prototype
  • public
  • Radio
  • ref
  • RegExp
  • releaseEvents
  • Reset
  • resizeBy
  • resizeTo
  • return
  • routeEvent
  • scroll
  • scrollbars
  • scrollBy
  • scrollTo
  • Select
  • self
  • setInterval
  • setTimeout
  • short
  • static
  • status
  • statusbar
  • stop
  • String
  • Submit
  • sun
  • super
  • switch
  • synchronized
  • taint
  • Text
  • Textarea
  • this
  • throw
  • throws
  • toolbar
  • top
  • toString
  • transient
  • true
  • try
  • typeof
  • unescape
  • untaint
  • unwatch
  • valueOf
  • var
  • void
  • watch
  • while
  • window
  • Window
  • with
Nov 16 09

Reasonable Defaults for MySQL Server

by Jonathon

Jeremy Zawodny posted yet another great article over at Linux Magazine on some improved defaults that can save you a lot of grief when your network fails intermittently. In summary:

Faster replication heartbeat (old default is 3600 seconds = 1 hour):

slave_net_timeout 10

Disable DNS hostname lookups:

skip-name-resolve

Sane connection timeout (may need to be raised if your network is flaky):

connect_timeout 5

Disable host blacklisting after x number of failed connections:

max_connect_errors 1844674407370954751
Oct 31 09

Human Name Parsing in PHP

by Jonathon

Parsing human names are not exactly easy, but they can be done. Keith Beckman’s nameparse.php is an excellent PHP library for doing this.

Download nameparse.php

nameparse.php can recognize names in “[title]first[middles]last[,][suffix]” and “last,first[middles][,][suffix]” forms, which, when you think about it, cover most if not all well-formed name input formats. nameparse.php handles last names of arbitrary complexity, such as “bin Laden”, “van der Vort”, and “Garcia y Vega”, as well as middle names of arbitrary size and complexity, differentiating between most last names and the first or middle names or initials preceding them.

An example of names correctly parse by nameparse.php:

  • Doe, John. A. Kenneth III
  • Velasquez y Garcia, Dr. Juan, Jr.
  • Dr. Juan Q. Xavier de la Vega, Jr.

To use, simple include() or require() nameparse.php and call parse_name($string) on any name. parse_name() returns an associative array of all name segments found of “title”,”first”,”middle”,”last”, and “suffix”. Do note that no spelling, capitalization, or punctuation of titles, prefixes, or suffixes is normalized. That is, every token remains as entered: nameparse.php is a semantic parser only. If you want orthographic or other normalization, you’ll have to postprocess the output. However, since the name is now semantically parsed, such postprocessing is (for applications which require it) simple.

print_r(parse_name('Velasquez y Garcia, Dr. Juan Q. Xavier III'));

yields . . .

Array
(
    [title] => Dr.
    [first] => Juan
    [middle] => Q. Xavier
    [suffix] => III
    [last] => Velasquez y Garcia
)
Sep 4 09

Performing a bitwise NOT on arbitrarily long integers

by Jonathon

Here’s the surprisingly simple solution to a fairly challenging problem. I do not understand why PHPs GMP extension does not include a gmp_not() function.

function gmp_not($n) {

	# convert to binary string
	$n = gmp_strval($n, 2);

	# invert each bit, one at a time
	for($i = 0; $i < strlen($n); $i++) {
		$n[$i] = ~$n[$i];
	}

	# convert back to decimal
	return gmp_strval(gmp_init($n, 2), 10);
}
Sep 4 09

Arbitrary-length base conversion in PHP

by Jonathon

After some digging, I found a great way to convert number bases when dealing with arbitrary length integers (esp. integers > 32 bits):

return gmp_strval(gmp_init($n, 2), 10);

This will convert a large base 2 (binary) number to base 10 (decimal).

Sep 1 09

Ten Things You Didn’t Know Apache (2.2) Could Do

by Jonathon

Check out SNI (multiple SSL vhosts) and mod_proxy_balancer in this great article from Linux Magazine!

Aug 27 09

How to handle headers and footers in CodeIgniter

by Jonathon

I got this question from a reader and thought it would be useful to post for everyone:

Hi Jonathon,

I really like some of your solutions to making things simpler when using CodeIgniter. On the subject, I was wondering if you had a preference for a simple way to include headers and footers in your views. I know you can either do views within views, but that just doesn’t feel right to me. Although the advantage is only having to use one line to call your views within a controller. The method of building your views within an action by calling each view seperately also doesn’t interest me, because I’m trying to adhere to the DRY principle. I’ve also seen a solution where you create your own MY_controller and build the view that way then inherit from all your other controllers.

Do you have a recommended way to include your common views that’s simple and doesn’t require you add multiple lines of code to each controller action? I’m trying to keep my view calling to one line within each action of the controller.

Thanks,

Lee

My preference on that is simply calling views within views. It just makes sense to do it that way. If there is data that must be passed to the header and footer globally, then I would extend the Loader class with a global data function like this:

class MY_Loader extends CI_Loader {

	function MY_Loader() {
		parent::CI_Loader();
	}

	function global_view_data($key, $val) {
		# normalize the data array
		$data = (is_array($key))? $key : array($key => $val);

		# merge into the view data array
		$this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $data);
	}

}

Copy that to a file called MY_Loader.php and save it in your libraries folder as described in the user guide. Once that is done you can load data which will be passed to all views globally:

$this->load->global_view_data($stuff);

Note: I have found that including views within views is aggravating without a helper function, so I wrote the Modularity plugin to help with that.

Aug 20 09

Excellent cron tutorial

by Jonathon

Here’s an excellent overview of cron, how to run a script every five minutes, and all that fun stuff.

Aug 18 09

Easy startup scripts using crontab

by Jonathon

There is a super-easy way to start a program during system boot. Just put this in your crontab:

@reboot /path/to/my/program

The command will be executed on every (re)boot. Crontab can be modified by running:

sudo crontab -e
Aug 11 09

Axioms of building a “boring” system

by Jonathon

From a presentation from Percona. This should be on every developer’s wall:

  1. If it worked 10, 20, 30 years ago, it is worth considering.
  2. If a crisis makes you come alive, you have your priorities wrong.
  3. If you are working on urgent system problems, it’s not a boring architecture.
  4. You should be working on exciting new things that serve your customers and are otherwise unimportant.