– Chuck Palahniuk
– Chuck Palahniuk
This week Jerod Santo released a nifty little app he had written for the Mac called Detours. It’s pretty cool, it’s a nice GUI where you can add routing information. So, you can make the DNS resolver think google.com is located at 127.0.0.1. Stuff like that.
That evening I set off to write a portable version of Detours by using the hosts file (/etc/hosts) on Linux. Naturally since I’m groking a text format it’s uglier, and it requires a daemon/client set up since the hosts file is write-locked for normal users.
But, I got one working that night and I’ve built it out since then. So I present to the Linux users of the world, Detours Clone. Lame name I know, if you have a suggestion for a better one let me know.
Anyway, I have a nice Python daemon and three Python clients (Qt4, GTK+ and a web server!). They speak JSON over TCP sockets (bound to 127.0.0.1 of course) and work well so far. I even wrote a few tests and a distutils installer.
So go check it out!
The Qt4 Client
“To be happy I think you have to be doing something you not only enjoy, but admire. You have to be able to say, at the end, wow, that’s pretty cool.”
– Paul Graham
How to Do What You Love
So, about a week or go I dove back into Ruby out of necessity. The Twitter daemon I had written in Python for Confurrent was chronically ill. My socket would block and eat 100% CPU and it seemed like nobody knew how to work around it, least of all me.
So I pulled out Ruby. I’ve only ever done any real Ruby work with Rails, when I wrote ThirtyDayList to learn the tech.
One thing I will note is that learning Rails basics does not teach you Ruby, or at least not enough Ruby to be useful. However, writing my Twitter daemon has made me confident in Ruby, and I like it a lot more now than after the Rails experiment.
The daemon was quick to write, using Tweetstream, and I only ran into one roadblock, which was all my fault.
See, I wanted to use the track method, which takes an unlimited and variable set of arguments (like *args in Python) but I had my arguments in an array. I could not figure out how to pass those on correctly, and even bust into the gem and started adding code to get it to work.
I finally realized that there is no way that there isn’t a built-in for this and I went back to Googling. A short while later I found a short post from detailing exactly what I should be doing.
Evidently you can use the asterisk to unpack an array for this. Super easy, but I feel silly for not finding that sooner. The pitfalls of unfocused autodidactism.
The Wrong Way
predicates = [ 'a', 'b', 'c' ] @client.track( predicates ) # Tracks 'abc'
The Right Way
predicates = [ 'a', 'b', 'c' ] @client.track( *predicates ) # Tracks 'a,b,c'