Dear Future Me

Supervisor rolling restart

20 Jul 2011
I recently “discovered” Supervisord, while looking at ways to run webservers. It’s much better than doing while [ 1 ]; do ./main; done in a screen session… Well, it’s not really hard to do something better than that… Anyway. It works well, and does what I want, except it’s missing rolling restarts. That is, when you have multiple instances of a program running, restart the first instance, check if it’s running correctly, if it is, restart the next instance, and so on. Without rolling restart you have the risk of finding yourself with no running jobs at all, and not...   Read more

Operation: Arduino Lo-jack

23 Apr 2011
Here is my car lo-jack system I just finished prototyping. It uses an Arduino, a cellular shield with a SIM card, a GPS, and a RFID reader. The basic idea is that when I get in car, I have with me a RFID card. Before starting the engine, I have to scan the RFID card. Since it’s RFID, there is no contact needed, and the reader can be completely hidden inside the dashboard and I don’t even have to take the card out of my wallet. If the card is correctly detected, nothing happens. However, if someone wants to “borrow”...   Read more

Capturing keyboard events and keys with JQuery

08 Feb 2011
There are tons of tutorials on how to capture keyboard events in javascript, especially to create keyboard shortcuts. However, I could not find a way to get all the actual keys that were pressed to simulate a text field. For example, punctuation, or special characters such as &, #, @…. would not be returned by String.fromCharCode(event.which) (where event.which is a normalized field created by JQuery). It turns out that using keydown and keypress events don’t do the same thing. It seems obvious now, but it took me some time to find out. So, basically: $("body").keydown(function(event) { var w = event.which;...   Read more

Starting a dev server with the right IP address

06 Feb 2011
I often need to start a dev server with my current IP address. I don’t want to use 127.0.0.1, because other computers on the network, or mobile phones on wifi, etc, can’t access it. So I need the IP address attributed by my router to my computer. Here is how to get it in 1 line of bash: IP=`ifconfig wlan0 | \ grep 'inet addr:'| \ cut -d: -f2 | \ awk '{ print $1}'` # Then, for example start the server with: ./main --ip=$IP I suppose it works on ubuntu linux as of today, but is pretty dependent on...   Read more

GNU Screen sessions - sort of.

06 Feb 2011
When working on some projects, I usually have to repeat a bunch of operations every time I start a “work session”. Like cd project-dir, opening a set of terminals, running a database server, compiling and starting the server, etc. At some point I was creating a bash script that would do all that, starting xterms, etc. but that’s not really scalable. But I just found how to fake sessions with GNU screen here. Basically, at the root of my project, I create a file “screenrc”, containing for example: screen -t "client-src" stuff "cd src/client-js/static/^M" screen -t "server-src" stuff "cd src/server-go/src/^M"...   Read more
« Older Posts