Wednesday, 7 October 2009

Regular Expressions in Erlang

My favourite general-purpose language is still Perl. It's not that it's the best at everything, but that it's good enough for just about anything (and better than most).

Probably as a side-effect of what many would consider this misguided affection, one of the first things I look at in a new language is its regular expression support. Mostly, this is a no-brainer: Perl 5 is the de-facto standard, and its regex engine is available as a library to link into your favourite C-binding language.

So I was disappointed initially when looking for advice on regular expressions in Erlang. The first hit on Google (at the time of this writing) is here, and indicates the regex module. Unfortunately, that module is really, really limited compared to the mind-bending flexibility of the Perl 5 engine.

I was disappointed. I'm going to re-write my CTCS clone in Erlang, and it makes quite a lot of use of regular expressions to extract information from the various messages ctorrent sends throughout its lifetime. In this case, it was a bit of a show-stopper: there's absolutely no point in doing the re-write if it's going to be more difficult to create the new version than improve the old.

But then, salvation! The re module, an (almost) mapping onto PCRE!

Suddenly, extracting groups from a string was easy:


regex_example() ->
Name = "Danny Woods",
{ match, [ Forename, Surname ] } =
re:run(Name, "(\\w+)\\s+(\\w+)", [{capture,all_but_first,list}]),
{ Forename, Surname }.


The escaped backslashes are ugly, but the direct capturing of groups as a list is pretty sweet.

Monday, 5 October 2009

Another Sad Day

It's been almost six months since Garfield died. Every Garfield needs his Odie, and my Garfield's was Jake. We had to take Jake to his final visit to the vet's today: he was diagnosed with aggressive terminal cancer three weeks ago and given six months to live, but a turn for the worse last week pulled that date back to today. He was sixteen.

We got Jake as a pup in 1993, and he kept those puppy looks right up until the end. I visited him at my mother's yesterday, and gave him a hug and touched our foreheads together like we've done since we were both young. He was the best of dogs.

Sleep peacefully boy.

I will miss you.

jake.jpg

Wednesday, 9 September 2009

Wastage

I stumbled across this amusing video of a cat drinking by dunking its head under a flowing tap. Even this light-hearted fun had some people in the comments bemoaning the wasted water of a tap being on for a few minutes of recorded video.

Then, with the subject of wasted water fresh in my mind, I switched tabs to this story (also from Reddit), and almost snorted my tea.

It was funny at the time.

Monday, 7 September 2009

Building MPlayer from SVN on Mac OS X Snow Leopard

I use the command line mplayer on Mac OS. The only competition for this superb video player is VLC, but sometimes I like to just quickly launch something without a bulky UI getting in the way.

But today I upgraded to Snow Leopard, distinctive from it's predecessor in being a truly native 64-bit operating system. And my SVN checkout of MPlayer stopped working, giving me a green video window and needing some effort to kill. So, to get MPlayer working, you're going to need the following:



...and, of course, your MPlayer sources. If you want FAAC support, get libfaac and build/install it using the same procedure as for freetype below.



Install the Apple Developer Tools using the graphical installer.

Build libpng and libjpeg:

./configure --arch=x86_64

make

sudo make install

Build freetype:

./configure --target=x86_64-Darwin

make

sudo make install

Build mplayer:

./configure --target=x86_64-Darwin --enable-menu

make

sudo make install




Now, you should have a native 64-bit /usr/local/bin/mplayer:



danny@mirror ~ [1] % file /usr/local/bin/mplayer


/usr/local/bin/mplayer: Mach-O 64-bit executable x86_64


danny@mirror ~ [2] %



Success!

Thursday, 27 August 2009

Why I Write My CV in LaTeX

For many people, even technical people, LaTeX is a relic. I recently had a chat with some colleagues who were looking to write documentation in a format that could be easily converted into other formats (PDF, HTML, etc.), which could maintain its own indexing and cross-referencing easily, and which would, of course, look good. I mentioned LaTeX and got some amused eye-rolling and comments about how no-one uses that anymore.

Even if that were true, I maintain my CV in LaTeX. Why? Simple:


  • It enables absolute control over what gets rendered, and where, on the page.

  • There's MiKTeX for Windows, TeXShop for Mac and TeX Live for Linux. In other words, it's available for your favourite platform.

  • The source files are plain text. This makes for easy versioning using your favourite version control system, and thereafter, comparing the differences between any two versions.

  • Producing good looking PDFs is simple with pdflatex.


Sure, it takes more time than knocking something together in Microsoft Word or OpenOffice Writer, but there's a distinct satisfaction to be enjoyed from tweaking and crafting something until it's exactly how you want it to be.

Definitely not for everyone, but if you've gone to all the trouble to develop a skill-set that you're proud of, you may as well take the effort to show it off in the best way possible!

Monday, 10 August 2009

ScotRail is Stuck in the 80's

My wife and I went on a shopping trip to Edinburgh yesterday, involving a train journey to Glasgow Central station, a short walk to Queen Street station, and another train ride to Edinburgh.

Now, for some truly bizarre reason, it's cheaper to get a return ticket to Central, and then a separate return ticket for the Glasgow–Edinburgh link, than it is to get a return from East Kilbride to Edinburgh. Go figure. But we skip over that little bit of insanity, and ask for one return ticket from East Kilbride to Glasgow Central, and two returns from Glasgow to Edinburgh. See, I work in Glasgow, so already have a season ticket. With a queue building up, we pay, bundle our tickets together and get on the train.

As it starts to pull away, we look through the tickets to see that the ticket office in East Kilbride has issued us with two return tickets for the East Kilbride to Glasgow link. Mildly irritating, but no big issue: we can just get a refund on the tickets that we're not going to use. We ask the conductor on the train, and get the response that he can't issue a refund, because he'd be out of pocket. We'd need to get the station at East Kilbride to do that, or possibly get it done at the ticket office at Central. He's a ScotRail ticket conductor, and these are ScotRail tickets, and he can't... Something in my head implodes from the stupidity. I thank him for his 'help' and he goes away.

Once in Central Station, we're told that we can't get the refund there: we'd have to get it from East Kilbride. The reasoning is that they didn't issue the physical tickets, so the ticket number wouldn't be on their system, only in the East Kilbride one. The most he can do is give us a form to fill out.

Now, this is our outbound journey. It's 13:00, and our home station closes at 17:00. Chances of making it back from Edinburgh in time? Approximately zero.

Both stations at East Kilbride and Glasgow Central are run by ScotRail. The conductor on the train is a ScotRail employee. It's a mere ten miles between the town and the city, and this is 2009. And ScotRail still don't have the facilities to provide refunds, except at the issuing station?

Embarrassing.

Sunday, 21 June 2009

Other Uses for the FreeBSD Daemon?

A friend of mine has been visiting from the Czech Republic over the weekend, an infrequent thing that inevitably results in visits to East Kilbride's pubs and nightclubs that we'll later regret. Some special strangeness last night came in the form of a sex-toy vending machine in the male toilets in Shenanigans in East Kilbride's town centre. Who would have thought that the FreeBSD daemon (right) was moonlighting as a purveyor of kinky goods?

vendie.pngbsd.jpg