Zen and the Art of Programming

I wanted to be an architect when I grew up. My dad wanted me to be a lawyer. I ended up a programmer. Oddly enough I liken this to being a carpenter. If I was not a programmer I would probably be a carpenter. I like building things, particularly beautiful things, that people use in their every day life.

  • Mysql
  • PHP
  • Javascript
  • Selenium

Some functions for mysql that I have found to be very useful:

function randpasswd(length)
[sp] Generate a random password in mysql - /code/randpasswd.sql
function mail(to, subject, body)
[udf] Send email via send mail - /code/mail_udf.c
Generating reproducable unique ID's
I had a need for create a unique ID but one that was reproducable, previously I had used random but there was an instance where I needed to be able to generate the same ID on a subsequent function call: md5(serialize(debug_backtrace())); There are some tricks and issues with this, if you have a PDO or other object that cant call __sleep() then you have to create wrapper classes with your own __sleep() functions. Instead of having to store random id's in memory you can now recreate them based on point in code.

XPath is alot more than just selecting nodes.

Table column sum
I had a monetary column so I had to cheat a little, I wrapped the numeric part in a span tag and then did a sum on those: document.evaluate("sum(//table[@id='table_35318']/tbody/tr/td[position()=8]/span)", window.document.body, null, 1, null).numberValue;

Selenium RC is an excellent extension of the xUnit tests.

Assert a table column sum with its summary
Building on the javascript XPath column sum: $this->assertEquals('$ '.number_format($this->getEval('window.document.evaluate("sum(//table[@id=\'table_35318\']/tbody/tr/td[position()=8]/span)", window.document.body, null, 1, null).numberValue'),0), $this->getTable('table_6bdaf.1.0'));