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
- 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
Reasonable Defaults for MySQL Server
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
Human Name Parsing in PHP
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.
nameparse.phpcan 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.phphandles 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()orrequire()nameparse.phpand callparse_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.phpis 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 )
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);
}
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).
Check out SNI (multiple SSL vhosts) and mod_proxy_balancer in this great article from Linux Magazine!
Excellent cron tutorial
Here’s an excellent overview of cron, how to run a script every five minutes, and all that fun stuff.
Easy startup scripts using crontab
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
Axioms of building a “boring” system
From a presentation from Percona. This should be on every developer’s wall:
- If it worked 10, 20, 30 years ago, it is worth considering.
- If a crisis makes you come alive, you have your priorities wrong.
- If you are working on urgent system problems, it’s not a boring architecture.
- You should be working on exciting new things that serve your customers and are otherwise unimportant.