javascript in the shell

Different languages are good for different things. But unix shell style trumps all. An example: bin/urlencode #!/usr/bin/js   function urlEncode(str){ str=escape(str); str=str.replace(new RegExp(’\+’,‘g’),’%2B’); return str.replace(new RegExp(’%20’,‘g’),’‘); }     if(arguments && arguments.length > 0) { for(var i = 0; i < arguments.length; i+) { r = urlEncode(arguments[i]); print(r); } } else { importPackage(; importPackage(java.lang); S […]

line numbers in shell

AKA ‘Today’s exciting shell command I learned’ nl e.g. $ echo -e "hello\ncruel\nworld" | nl 1 hello 2 cruel 3 world

ack – best thing since sliced bread

Someone at work recently pointed out ack. It’s a powerful replacement for find and grep. My favorite features: it ignores CVS/.svn directories; can easily specify file types with a flag (and of course define your own types); and it has colour highlighting on the output. On Ubuntu it is called ‘ack-grep’ instead of just ‘ack’: […]


I scribbled some design notes on my whiteboard… now I need a camera so I can record them!

testing 123

If this worked I should get blog posts appearing in my Facebook feed. Hello?

Rhythmbox + iPod, part 2

I spent some time reading up a couple of web pages to try to figure out what the support was for reporting to the tracks that I’ve listened to on my iPod. Apparently the reading was a bit of a waste of time – all I really needed to do was plug in the […]

it’s all about the features

At home we have a D-Link DNS-323 as a file and print server. Among other things, we store all our music on it, as it runs an “iTunes Server” (actually mt-daapd, now known as Firefly). My wife has a MacBook and an iPod, and runs iTunes. Strangely enough, this combination is missing some desirable features: […]

target of a symlink

It took me ages to find this, so I will record it. To find the target of a symbolic link, you can use the ‘readlink’ command. Or in my case, you can find the real file or directory of the current script like this: #!/bin/bash MY_FILE=`readlink -f $0` MY_DIR=`dirname $MY_FILE` … The ‘-f’ option means […]

useful sed scripts

A common problem – replace DOS line endings with Unix ones, across a bunch of files. (I had a dump from my old Windows work machine, which was not cooperating with CVS when I just copied it onto this machine). To type the ‘^M’ in Bash, type ctrl-V, then ctrl-M. find . -type f -exec […]

fonts for programmers

I believe a good choice of font can help programmers. Certain characteristics make for easier editing of code. Firstly, it has to be monospaced. This may make it look ‘primitive’ compared to nicely laid out text, but code isn’t text. It is much easier to understand the structure of code when indentations and characters line […]