TL;DR: telnet gameoflife.erikzaadi.com 1337
This Saturday (8th of December, 2012), was the second Global Coderetreat, and I was amongst the lucky ones to participate from Tel Aviv.
The event was epic, 30-ish geeks pairing up to 45 minutes of hacking sessions on Conway’s Game Of Life.
And that was just in Tel Aviv, about 3500 people worldwide took part in this Geekathon.
The last session I teamed up with Roy Rothenberg and Pablo Klijnjan (Yes that last name is in Klingon), both my day to day teammates at work.
We had this idea of making a Telnet version of Game Of Life, inspired by the Telnet Nyan Cat ( telnet miku.acm.uiuc.edu
).
We hacked together a working Python version in that session, that I thought would be hilarous if it was available online.
We used a very simply Telnet server using Python’s socket
module and most of the time was spent understanding how the f#!@#k to clear the screen:
|
|
The problem with the Python version we hacked together was that if you connected more than one Telnet client, it would crash.
During the session we looked at using Twisted to improve the Telnet server, but we had a crappy connection and it took ages for it to download.
Yesterday when I looked at improving the code to make it available online (yes I didn’t delete that sessions' code :$), I had a look at some Twisted Telnet implementations, but the code was to Twisted for me.
Reactor this, Factory that. No thanks.
So, I decided to hipster up and try it in nodejs, initially setting a 45 minute target as one of the sessions we did at Coderetreat.
Getting up the Telnet server was easy, a quick npm search telnet
found me wez-telnet.
Writing the coffeescript version of The Game Of Life took me most of the time.
I used Mocha as testing framework, which is very smooth. Writing the game and telnet server took me about 55 minutes (while multitasking other stuff).
I tested the Telnet server by connecting from 10 clients from different machines in our network, seem to not even flicker.
When I connected via ConnectBot on my Android, it crashed the server. So, before putting it up online, I needed some kind of daemon that restarts the server if (when) it crashes. This was easy with forever.
Here’s the entire package.json
with the scripts for testing, testing continuously, starting and stopping daemon:
|
|
So to get this working, all you need to do is clone the repo and one npm command and you’re done:
|
|
To run tests:
|
|
To run as a daemon:
|
|
Grab the source code or run the live sample:
|
|
|
|
Enjoy and prosper!