Life

I’ve been messing around with JavaScript and the new HTML5 canvas element. After a couple of random experiments, I decided that I needed a well-defined goal, and I picked Conway's Game of Life. Here’s the result:

You'll need to turn on JavaScript (and have a recent, canvas-supporting browser) to see this.

Hopefully, the interface should be relatively self-explanatory (see the Wikipedia page linked above for details of the game itself). The Save button produces a string representing the game board; to go back to a previous state, paste such a string into the box and hit Restore. The whole thing should work in recent versions of Firefox, Chrome, Safari and Opera. It won’t work in IE, as that browser doesn’t support canvas.

Thing’s I’ve learnt in doing this:

* The interface to canvas works pretty well, and I’ve not (yet) found any major gotchas between the browsers that support it. * JavaScript is surprisingly good (and fun) language, especially if you stick to the good parts. * JavaScript performance varies noticeably between browsers; in particular, Firefox (3.6) seems slower than the others. My hunch is that the difference is in the optimisation of JavaScript’s somewhat unorthodox handling of arrays - this is something I’ll have to look into. * The game works, glacially slowly, on my iPhone 3G, but the editing (which uses onclick) doesn’t. I might fix this.

The code is up on GitHub.

Update: I’ve added this entry as my first “thing” on Flattr. Be gentle with me.

Weekend Project: Worksheets

Last week, I had need to run some queries against the internal database at work. These weren’t reports that needed to be run forever more, but I wanted to keep a record of them - both the queries and the results. I ended up writing my queries into a text file, evaluating them using Emacs’ SQL mode, and pasting the results back into the file. This worked quite well, but I thought I could do better.

I’ve been wondering about worksheet-style interface, as found in, for example, the Sage open source maths system. SQL, at least if you’re running SELECT queries, is ideal for this, as each query is independent, so you don’t have to manage things like ordering and mutation. Hence, last weekend, I knocked up a rough draft of what such an interface might look like. I’ve tidied it up a little, and an posted it here. There’s still plenty to add (support for other databases, UI improvements, some semblance of security), but the basic functionality is there, and it should serve as a basis for further experiments.

A problem with time

I recently read a talk by the founder of GitHub saying that I (and everyone else) should start a side project. I’ve been thinking that I should do this for ages now, and the author made some good points that provide me with even more reasons to do so. One of thing things that he points out is that you need to allocate a chunk of your free time to working on your project. Fine; that isn’t the problem.

The problem I encountered was when I tried to implement one of his time-freeing suggestions, which was to stop reading RSS, and instead keep up with things on Twitter. This sounded like a good idea, and I’m already on Twitter, so I decided to give it a go. I started to follow John Gruber, author of the excellent Daring Fireball, and ran into the problem of the title. John lives in Philladelphia, which is on the east coast of the US (I admit I had to check this on Google Maps). This means that he’s five hours behind GMT. Given that Twitter is a more-or-less real-time service, the difference is immediately apparent. He doesn’t get up and start twittering until fairly late in the day where I am, and he carries on way past my bedtime. The upshot is that I get up and have a bunch of unread tweets, which isn’t all that different to my usual habit of reading RSS over breakfast. I’ll give it another few days, but I suspect I’ll be back on RSS before too long.

Rob Hague is a computer programmer by profession, and an amateur at everything else. This blog is where he posts pretty much anything that pops into his head. He's based near Cambridge in the UK. Mail him at rob@rho.org.uk.
Subscribe
Powered by Jekyll