Unsound Bytes

All of the tangents. All of them.

Serving Dice From Node

| Comments

I recently took an interest in server-side javascript, specifically node. I am a big fan of literate programming, and CoffeeScript fits the syntactic bill for that quite a bit better than vanilla JavaScript. Fortunately, CoffeScript is “just JavaScript”, so it can be used as a drop-in replacement.

Since I knew the first thing I would need is to take the dice expression and parse it. The tool I found to do this was the excellent PEGjs, assisted by a CoffeeScript plugin. Parsing Expression Grammars differ from the types of parser I’ve implemented in the past, so I had to take care to avoid left recursion. Ultimately, I used an interesting trick to flatten the recursion into iteration for left-associative opperators.

Since my parser returns a sane AST, writing an interpetter was not difficult, although combining the need to track state with the async nature of node required a bit of work, made more difficult by the fact that I have not worked with prototypal inheritance much before.

Using Expressjs to slap a frontend on it was not difficult, a process very similar to Sinatra.

Check out the source here, and see it in action here.

Left to do: write clients to integrate with IRC/other chat protocols, spruce up the default frontend, figure out what test framework to use for JS.

Life According to Conway

| Comments

Recently, I have been lacking a good sandbox to try out new interesting things. So, I decided to implement Conway’s Game of Life in Ruby. The repo is on GitHub, and I plan to extend it in various ways, such as adding a GUI and perhaps a C extension of the core algorithm. Watch this space.

Welcome

| Comments

This is some cool text.

Autovivifying hash in ruby.
1
Hash.new {|hsh, key| hsh[key] = Hash.new(&hsh.default_proc) }