There is a top level navigation menu at the foot of the page

I (heart) ccl: Detailed back story of the history and evolution of MCL

2014-09-05 by cms in computers, history, links, programming

LambdaPi: A bare metal scheme based lispOS for the rPi

2014-07-14 by cms in computers, links, programming

What’s new in Unicode 7.0: Linear A! (and inevitably, lots more emoji)

2014-06-17 by cms in history, links, programming

Serapeum: is a conservative library of Common Lisp utilities. It is a supplement, not a competitor, to Alexandria.

2014-03-31 by cms in computers, links, programming

Elisp lexical closures are readable forms: Lexical scoping for emacs lisp means doing some unlearning.

2014-01-01 by cms in computers, links, programming

Album Shuffle: I published my playlist generating python tool onto github

2013-04-25 by cms in computers, links, programming

Cool Shell Prompts

If you have a Mac, and you use to run UNIX commands, try executing this for a cool shell prompt

export PS1="\360\237\220\232 $ "

See what I did there?

If you are using a UTF-8 encoding for your terminal, which you probably are, and if you're using a recent OS X, and have the right fonts installed, which you probably do, you should have a little sea-shell graphic for your prompt. Literally a cool shell prompt.

Screen Shot 2013 04 09 at 19 11 42

In a recent revision to Unicode, code points were assigned for many emoji. Emoji-what-now? These are little emoticon glyphs that rose to popularity in Japan. Apple have included a nice typeface with full colour icons for a subset of these in the last couple of releases of both iOS and OS X, so you can use them in most applications that use the system type rendering library, like Messages. On OS X, this includes the bundled terminal emulator. So you can print little icons in your shell, if you know an encoding for a particular glyph.

Here's the ever popular 'pile of poo' ( U+1F4A9

Screen Shot 2013 04 09 at 20 09 46


Not sure what that is supposed to be used for, but it's terribly popular on the internet. "But how", I hear you ask, "do you find out the encoding sequences for these appealing novelties?"

Well, you can search for unicode code tables on the internet. On the Mac though, the easiest thing to do is probably to enable the Character Viewer tool via the Language and Text System preference pane. 

Screen Shot 2013 04 09 at 20 19 23

This gets you a panel like this, where you can browse all the characters your computer knows how to render, including all the emoji sets, and find out their Unicode code points, and more importantly, a way to encode that code point in UTF-8.

Character viewer copy 

So, as you can see in my fecal example, the UTF-8 byte sequence for 'pile of poo' ( U+1F4A9 ) is F0 9F 92 A9, and we can print that in a bash shell, using echo with the -e flag to enable interpreting of escape sequences, using the \x escape prefix to indicate bytes in hex. 

Going back to the original shell trick, the shell emoji ( U+1F41A ) has the UTF-8 encoding F0 9F 90 9A. The bash shell doesn't seem to have an escape sequence for hex encoded bytes in it's prompt string, but it does interpret 3 digit codes prefixed with a plain \ as octal encoded literal bytes, so if we convert this hex string to four octal numbers, using bc or od, or emacs or just, we get the escape sequence from my initial shell example – "\360\237\220\232"

So far so cute. But is there anything vaguely useful you can do with this sort of thing? Sort of. A picture's worth a thousand words. So we could perhaps encode mnemonic information in icons, and somehow dynamically update the prompt to reflect this.

Bash will execute the contents of an environment variable PROMPT_COMMAND as a shell command immediately before the shell prompt is printed. Typically this is used to update terminal colours or title strings with escape sequences, or update PS1 to add some content that can't be printed using the built-in prompt escape functions. I decided to make my prompt respond to the result of my most recent command.

Here's the relevant shell glue I just stuck in my .bashrc 

emoji () {
if [ $1 -eq 0 ]
echo "\360\237\230\203 $ "
elif [ $1 -gt 0 ]
echo "\360\237\230\225 $ "
export PROMPT_COMMAND='PS1=$(emoji $?)'

This runs a shell function called emoji in a subshell, which returns a string based on the input argument. The input argument I'm using is the exit status of the last shell command. This gets me a smiley face in my shell prompt, unless the last command I ran returned a non-zero exit state, which in UNIX, indicates a problem happened. This makes my prompt draw as a 'confused smiley', if something has gone wrong.

Screen Shot 2013 04 09 at 20 41 56

Still cute, and almost useful!

I think I'll keep it for a while.


posted Tuesday, April 9, 2013 at 19:47 by cms in computers, programming | Comments Off on Cool Shell Prompts

-AppleLanguages: Overload the locale for cocoa programs at the command line. 

2013-03-26 by cms in computers, links, programming

Case for Numbers: I had no idea that this was even a thing.

2013-03-26 by cms in links, programming

Presenting elfm.el


elfm.el is a rudimentary radio client implemented within emacs lisp. I wrote this at work to present at our internal "Radio Hackday"; dedicated to encouraging staff to experiment with the radio services and API, and make something with them in a day and a half for show-and-tell. Kind of 20% time distilled right down to an essence.

I wasn't sure if I was going to have enough time to contribute anything, so I wanted to focus on something I could hack on by myself, because I didn't want to hold a team back if I got called away. So I picked something jokey, inessential, yet hopefully thought-provoking, as per my usual idiom.

I had a real blast participating. I don't usually get time to attend things like proper hack days, being all old and family-bound. I really enjoyed the atmosphere of inspiration and industry. All the other hacks were amazing, and waiting for my turn to demo I felt quite embarrassed about my stupid cryptic toy, but it worked perfectly in the spotlight. I got almost all the laughs, and all of the bemusement I was aiming for.

The code is here. It is awful. I haven't written any coherent lisp on this scale for many years. It uses too many global variables and special buffers. It doesn't scrobble. I had to rewrite all my planned asychronous network event machine halfway through implementation, when I re-discovered the lack of lexical closures in elisp. ( I've been reading too many common lisp books in the interim, I suspect ). I think there's enough of the germ of a useful idea in there that I might just clean it up and try and extend it into a proper thing.

I built and run it using GNU Emacs 23.4.1 . I used an external library for HTTP POST, which I found on emacswiki ( HTTP GET I glued together using the built in URL libraries). I've also put a copy of the version I used in the distribution directory. I used mpg123 for mp3 playback, which I installed using Mac Ports. The path to mpg123 is hardcoded in the lisp somewhere, probably inside play-playlist-mpg123.

Here's my demo script, which I evaluated in a scratch buffer. Evaluating these forms in sequence will authorise the application, tune in the radio, and then fetch a playlist of five tracks and start playing them.

;;;; -----DEMO , this example code is out of date, see README 
; will open a browser to authorise application
; authenticate a user session
; tune the radio to this URL
(radio-tune "lastfm://user/colins/library/") 
; refresh the playlist 
(get-request (get-playlist-url)) 
; filter the playlist response to sexps, play the list
(play-playlist-mpg123 (reduce-playlist)) 

There is only one playback control at the moment; stop, which you can manage by killing the buffer *lastfm-radio* which has the playback process attached to it.  You can retune the radio with any lastfm:// URL format,  by re-evaluating radio-tune, and then refreshing and playing the playlist i.e. repeating the last three steps in sequence.

 The internal hackday was a cracking idea. Most of the hacks were focused around radio enhancements with broad-ranging appeal, the vast majority of them looked practically useful. I suspect most of the work will filter out into site and product updates. In addition to this, and perhaps more valuably, it worked really well as a community exercise, evolving knowledge-sharing, cross-team working, and enthusiasm, and converting them into inspiration, craft, and art. More of this sort of thing, everywhere!


I've iterated on the original hack quite a lot to make it slightly less brain-damaged, and a bit cleaner to import into anyone else's emacs. Updated code is here and so is a README file with updated running instructions. It's still not really in a usable state for anyone else, but it's amusing me to fiddle with it, and I vaguely plan to get it to a releasable alpha state, at which point I will publish a repository.

posted Saturday, April 28, 2012 at 10:49 by cms in computers, internet, programming | Comments Off on Presenting elfm.el