GNU Prolog and UUID generation

I am poking around with GNU Prolog again and I needed the ability to create a UUID for something.

Using the brilliantly simple “gplc” and the “foreign” declaration I had a working solution in less than half an hour. Some tidy up and this is what I have, first the Prolog FFI declarations:

Then the C code for the glue:

And finally the magic gplc invocation.

Of course, you could just get it from here:

Next: is to integrate RabbitMQ (librabbitmq), or just enough so I can consume and produce stuff… I have a mad plan to write a Micro Services based application with GNU Prolog… mwah hah hah haaahh…

Nicer Erlang docs layout

If like me you download and use the documentation (build from source) locally you will often find yourself irritated by the small left hand pane for the contents / index section. I know I do.

Here is a small change to the otp_doc.css file that will make it a little easier to read. It works for me, on OSX Yosemite in all the browsers and should be fine on any platform, it is just a CSS change after all.

In the doc folder locate the file otp_doc.css and change the following entries as indicated:

Now when you read the docs you can actually see stuff. My guide for the value was being able to see all of the gen_server functions listed properly.


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.