Code matters less than data.

Good code is boring.

Things I Learned From Node Knockout

I had the great fortune to join Paul Armstrong and Zach Johnson of Team Watermelon Sauce to build an entry to the Node Knockout. We built a browser-based multi-player banana-throwing game featuring gorillas in space in just 48 hours.

It's fun to work with your friends, especially if your friends are highly skilled and you can get along amidst stress, lack of sleep, and strictly junk-food based "nutrition." This isn't the first game that I've worked on with them, and it wasn't my first node-based project, but it was our first together with a clean sheet and no outside pressures. I can't stress enough how wonderful it was to have such an experienced pair leading the team. Both Paul and Zach have been building games in their free time, so they cranked out code like machines. I had spent a chunk of time before the competition researching and prototyping orbital mechanics and spent most of my productive time honing the flight of bananas. I would have been more productive, but every iteration was more addicting than the last, and we threw thousands of test bananas before the 48 hours were up.

Without further ado: Apestronauts!

Don't Go In The Basement

What if there was a serial killer putting the "execute" in "executing your code"? Recently, I was working on some tests within the codebase in company. I can't share the exact code, but I can paraphrase:

$ cat foo.js

var foo = 'bar',
baz = {
},
monkey = {
pirate: {
ninja: 'zombie'
}
};

if (baz.pirate.ninja !== monkey.pirate.ninja) {
console.log('This test is failing');
}

What was the result of running that?

$ node foo.js


node.js:116
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot read property 'ninja' of undefined
at Object. (/net/homestar/home/jmullan/imvu/platform/foo.js:10:15)
at Module._compile (module.js:373:26)
at Object..js (module.js:379:10)
at Module.load (module.js:305:31)
at Function._load (module.js:271:10)
at Array. (module.js:392:10)
at EventEmitter._tickCallback (node.js:108:26)

If only there was a way to spot that bloody hand print on the door to the cellar.

$ cat foo.js

var foo = 'bar',
baz = {
},
monkey = {
pirate: {
ninja: 'zombie'
}
};

if (baz.pirate) {
if (baz.pirate.ninja !== monkey.pirate.ninja) {
console.log('This test is failing because the ninjas are not the same.');
}
} else {
console.log('This test is failing because baz has no pirate.');
}

I know this is basic, but people still go to the basement and get eaten by cannibals in movies. Please take the time to imagine that the people who will be next working on your code are nightmare hell beasts who want an excuse to consume the souls of your children.

MySQL drivers for PDO in PHP 5.3+ on Ubuntu

I needed to get PHP to talk to MySQL through PDO on an AWS Ubuntu instance.

Here was my initial error:

PHP Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'

This means that PDO didn't have the right driver. In this case, MySQL.

What version of PHP was I running?

$ php -v

PHP 5.3.2-1ubuntu4.9 with Suhosin-Patch (cli) (built: May 3 2011 00:45:52)

I tried to install PDO, just in case:

$ sudo pecl install pdo

[Some stuff excluded for brevity]
make: *** [pdo_dbh.lo] Error 1 ERROR: `make' failed

That just means that PDO is already baked into PHP 5.3, so we don't have to install PDO at all. Ok, so let's install the pdo_mysql driver the old fashioned way.

$ sudo pecl install pdo_mysql

[Some stuff excluded for brevity]
checking for PDO includes... checking for PDO includes...
configure: error: Cannot find php_pdo_driver.h.
ERROR: `/tmp/pear/temp/PDO_MYSQL/configure' failed

No love, and searching for the error didn't tell me what I needed to know: the pdo_mysql driver is included in the php5-mysql package on ubuntu. It's not explicitly obvious.

sudo apt-get install php5-mysql

I also restarted apache, even though it looked like apt did it for me, but after that, no more errors.