Erlang, emacs and parse transforms.

I have tried the latest version of the IntelliJ Erlang IDE and I have to say, what an awesome job. Awesome. However… being a died in the wool emacs user I just find myself being overwhelmed by IntelliJ in general. I use PHPStorm every day and even that grinds me down sometimes.

I am currently developing an Erlang version of a computer language system I wrote a while back and I use the “C-c C-K” shortcut; compile buffer. All was well  until I decided I want to use erlando.

The Problem

The problem manifested itself as an error message during the compilation of the buffer, caused no doubt by the fact that the code path is not set up properly:

lexer.erl: undefined parse transform ‘do’

I am using rebar and git dependencies for pmod_transform, erlando and mochiweb so they all have their own ebin folders too.

The Solution

To cut to the chase, the solution is both a couple of entries in the .erlang folder as well as a specific startup process. Follow it, it works every time and it means you can continue to enjoy the beautifully unobtrusive erlang mode and still be able to use the parse transforms.

1. In the root of your project add these lines to your .erlang file, creating it if you don’t already have on in effect:


2. Gentlemen, start your emacs.

3. Start an erlang shell with M-x erlang-shell

4. Open your source file and use C-c C-k to compile the buffer. Voila!

It is important to note that you must start the shell before you compile to ensure it picks up the ,erlang file. This then adds the required dependencies to the code path and then when you do compile, the compiler uses the current shell session. Problem solved!

A while back I did notice that in the skeleton project that Mochiweb creates, there is awesome bit of code in the <project>_deps called ensure/0 but for now this is good enough.


Traditional edit-compile-refresh for D and Vibe.d

I have recently been writing a browser based stop-motion animation package, simple as it can be and I chose to use “D” and the web framework “Vibe.d” in order to learn something new.

Using the “dub” tool will build the project and then run the server but I wanted to be able to have a more traditional edit-refresh cycle like PHP for example.

Step One – /shutdown

Implement a handler for a shutdown call then put it on a menubar, for me, I am using Bootstrap si it was relatively easy. Here is the code that shutdown the server with the “/api/shutdown” URL is requested:

And finally, the little bit of jQuery code that is called from the Diet template to make it all happen:

Step Two – Bash Loops

Then I created a simple bash script that runs “dub” then just does it again and again and again… you get it:

When I run this from the shell prompt, my code compiles and the server runs… then I can evaluate my site so far, make code changes then hit the “Shutdown”menu option and watch it rebuild and run all over again.

That’s about as nice as I can make it I think without delving into the realms of detecting changes (notify) …if it can be this simple then why not leave it as it is!

Hope that helps other Vibe.d developers out there.

Stopmotion with D-lang

Having recently done a stint with C++ again on a large NHS product, I had a look around to see what may have improved on C++ in recent years. I found “D”. This language is by no means the new kid on the block but having gotten really “into” more scripted environments in recent years like PHP, Ruby etc. it was intriguing to find something that promised all those benefits but with the ability to provide a binary at the end of it!

After evaluating it for a few hours, I realised that in fact, for “practical” purposes i.e. nobody else I know uses Erlang, Haskell or LISP, that “D” just might be the best thing I’ve found since sliced bread in a long long time for delivering an end-user application that is portable across platforms and goes like the wind.

Stop Motion

Having an interest in making Lego movies for fun with my son, I decided that I would try out the libraries to see if I could write a little application that could grab an image from an Android device running the absolutely brilliant little application called IPWebcam Remote.

Here is the result of me work: Slomograb on GitHub

Once built and copied to somewher on your “path” it provides a simple means to grab whatever the camera is seeing and saves it into the current working directory using the next highest numbered frame file it finds.


I also provide a simple ffmpeg incantation to stitch the frames into an MP4 clip for viewing or incorporation into iMovie (for us) or whatever you have to hand.

That’s it, hope somebody finds it useful.

Good Vibe(.d)rations

I am now working on a fully fledged stop-motion suite that also should be cross platform and run in a web browser using the Vibe.d web framework that is also written in D-lang. I have spent some time doing the basics and it feels very useful. Not sure how this project will pan out but I think it will be finished.

Framegrabber Breakdown

Might as well show some code… and how little there is of it. One of the nice surprises with D is just how good the stock libraries appear to be. I have read opinions to the contrary but they are just opinions after all. I just prefer to get on and do things instead of debating the edge cases and exceptions to rules.

Here’s the whole thing… then I will break it down…

18-21: D main() is where we come in, all it does is call the capture frame function with the first command line parameter, this would be the IP:Port value displayed when IPWebcam Remote is running. It appends to this to build the URL for getting a high resolution shot of what the camer is looking at.

24-29: using the library function we can simply get the camera image by extrapolating the required URL from the cameraIp parameter and saving it to the next highest frame number.

32-35: Not used anymore, I guess I could have removed this but what the hell! :)

38-53: Gets the highest numbered frame in the current working directory. Line 41 starts to demonstrate some of the power in the D language. The “auto” basically says, “Oi, compiler, you work out the data type because I can’t be arsed”. And it does. This is a great one liner to basically list all of the files in the current working directory that end with “.jpg”. The shallow option means just this directory and the false is the to not follow symlinks.

43: Simple iterator form of a for loop over the files returned from line 41.

45: This uses the current name of the file being processed in frame, the iterator target, and it then chomps the file extension from the end and the leadinf “./f” from the fron leaving just a string containing the frame number as a zero padded eight digit number.

46: Turns the string into a real integer. The to!(int) is from std.conv. Templating in action.

48-50: Makes sure we get the highest numbered frame.

52: Game over, return it.


Prime Peace

I think prime numbers are the numerical expression of peace. Restful nodes in the vibration of everything.

Prime factorisation has always struck me as something truly astounding and it is reassuring to know that awsesome minds are hard at work trying to solve the Riemann hypothesis right now.

There are some truly wonderful profressional and amateur (in the nicest sense of the word) explorations I have watched recently and the ones tha t recently moved me the most, in order of cool factor were:

This guy,Carlos Paris, has put in some serious work with AutoCAD and made some interesting observations. I truly enjoyed watching all of these videos. Awesome work Carlos. As an interested amateur I found his work and thougts to be very compelling. I am sure the professionals would groan or moan but to me this video is most excellent and informative.

Speaking of the professionals, this video is also very interesting to watch as it goes some way to visually explaining the Riemann hypothesis in a way that a layman can understand (that’s me), in fact I believe his audience to have mostly consisted of young kids and their parents!

So… as I continue my studies and dreaming of a million dollars, I truly hope that there is another (Sir) Andrew John Wiles out there close to a proof of RH.



Love2D and Lua, a match made in heaven!

I have discovered the most amazing Lua based graphics engine: Love2D

I have not been able to sleep deeply since starting to learn it as the endless ideas that keep popping up are hard to thump down. This is the most amazing *free* bit of kit that I think that I have ever seen. Within a few hours I have a game, not yet complete, but a game nonetheless.

It has collision detection, missiles going up, an evil alien  (Bender!) to shoot at and a score counter. All within a few hours of not only learning Lua but Love2D as well.

Details to follow and some  YouTube footage as well I think. This is truly amazing. This library seems to have abstracted all the rotten hard to grasp concepts about using OpenGL for Orthographic/2D gaming and produced something so simple to use that a 12 year old could do it.

And he did.

Lua… finally got to learn it but…

After a long long time of promising myself I would learn Lua, I finally got around to it for the most amazing reason:

My son wants to learn Lua scripting

He loves Roblox, if you have kids, you may well have heard of it. As a parent you worry that kids spend too much time online doing nothing but I have to say, given his two hours a day, I’d rather he spent it here than most anywhere else on the net.

At first sight it looks like just another MMORPG but the key difference is that the games they play, most often that not, they write themselves using Roblox Studio. All credit to the developers and designers at Roblox; they have created an absolutely fantastic suite of tools and the kids go mad on it!

One of the things you can do is make the games and worlds you create more interactive by using Lua scripts within the Game model to add events handlers, message popups, audio, pretty much anything you can think of really, a part of your creation.

So today I sat down with my twelve year old wanna-be-Roblox-hacker son and we set of to learn it together and I have to say I was impressed with not only how easy it is to learn but how well it sat with him too, I think he will be impressing me within a few more lessons that’s for sure.

Using an iMac, I plugged in a second mouse and keyboard (driving instructors have dual controls, it seemed like a good idea and worked well!) so that we could both “drive” but I let him do most of the work to learn. I fired up Sublime Text and a Terminal window to the right and the documentation to the left and off we went.

Being something of an “old school” hacker myself I thought, “What can we do that is visual and simple but rewarding”. We created a simple set of functions to allow us to send ANSI escape sequences to the terminal so that he could control the output and stuff.

Cutting a long story (75 minutes, I was amazed!) we ended up with this code, which although guided by me, was written by Captin[sic] Sprankles himself and of which is proud of and rightly so:

I think we are both going to have a lot of fun learning Lua and I think he will be a master at it in no time at all… and when his school ICT class finally stop wasting time showing them how to save Excel spreadsheets and actually do some coding, he will cruise it already, well done George!

Nokogiri is…Japanese for “Awesome HTML scraping library”

I am in the final stages of releasing an Android application into the market place and I wanted to write some example application code in various languages to show how easy it is to use. It is essentially a remote controlled web browser; you get a full screen (almost!) web view on your device and you can then tell it what to show, play video (YouTube or anywhere else) and all other stuff. It is called ExtraMon.

Anyway, I love XKCD and I love Ruby too so I decided to write as small a program as I could to load a random comic from the XKCD site, extract the URL for the image and then turn that into a REST API call to the ExtraMon application. Simples. The end result is that my Sony tablet sits nets to my iMac and once a minute it shows me a different cartoon.

I looked around and found “Nokogiri” and boy was I impressed at just how easy it was, here is the complete script, amazingly short thanks to the expressive power of Ruby and Nokogiri:

It makes me cry when I think of web scraping with PHP sometimes and regex hell not far behind. Whatever. Nokogiri is cool and I seriously recommend it of you are Ruby bound and looking for a good scraping toolkit.