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:

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.

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:

C

1

2

3

4

5

6

7

8

// ...the router setup...

router.get("/api/shutdown",&shutdownNow);

// ...the handler...

voidshutdownNow(HTTPServerRequest req,HTTPServerResponse res)

{

vibe.core.core.exitEventLoop();

}

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

JavaScript

1

$.get("/api/shutdown");

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:

Shell

1

2

#!/bin/bash

whiletrue;dodub;done

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!

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.

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.

Simples.

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…

Frame Grabber

C

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

import std.algorithm;

import std.conv;

import std.file;

import std.net.curl;

import std.stdio;

import std.string;

/**

@file slomograb.d

@author Sean Charles

@licence MIT spread it around!

A simple frame grabber tool for use with IPWebcam Remote (Android).

*/

voidmain(string[]args)

{

captureFrame(args[1]);

}

voidcaptureFrame(stringcameraIp)

{

download(

format("http://%s/photo.jpg",cameraIp),

format("f%08d.jpg",findHighestFrame()+1));

}

char[]grabImage(stringcamera_ip)

{

returnget(format("%s/photo.jpg",camera_ip));

}

intfindHighestFrame()

{

intmax=0;

autoframes=dirEntries(".","f*.jpg",SpanMode.shallow,false);

foreach(frame;frames)

{

autoframeStr=chompPrefix(chomp(frame.name,".jpg"),"./f");

intframeNum=to!(int)(frameStr);

if(frameNum&gt;max){

max=frameNum;

}

}

returnmax;

}

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 std.net.curl.download 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.

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.

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.

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:

Lua

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

-- These are CONSTANTS which means that I can use the

-- word RED_INK in my code instead of the number 31

RED_INK=31

GREEN_INK=32

YELLOW_INK=33

ROBLOX_NAME="Captain Sprankles !!!!"

-- These constants mean I can set the background color

-- and use words instead of mysterious magic numbers!

BLACK_PAPER=40

RED_PAPER=41

WHITE_PAPER=47

GREEN_PAPER=42

-- This little function clears the terminal window

functionclearTheScreen()

escape("2J")

end

-- This function prints stuff after the ESC character

functionescape(stuff)

print("\x1b["..stuff)

end

-- This function sets a terminal color

functionsetTheColour(colour)

escape(colour.."m")

end

--[[

MAIN :: this is where Lua starts to run my program

--]]

clearTheScreen()

setTheColour(WHITE_PAPER)

setTheColour(GREEN_INK)

print("Hello my name is "..ROBLOX_NAME)

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!

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:

XKCD / Nokogiri Scraper

Ruby

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

# xkcd.com image viewer - Sean Charles 2014.

# (Ruby 1.9.3-p448, YMMV with 2.0+)

#

# Usage: ruby xkcd.rb ADDRESS

# e.g.: ruby xkcd.rb http://192.168.0.8:31415

require'nokogiri'# gem install nokogiri

require'open-uri'

require'net/http'

address=ARGV[0]

address="http://#{address}"unlessaddress.start_with?('http://')

begin

whiletrue

doc=Nokogiri::HTML(open('http://dynamic.xkcd.com/random/comic/'))

img=doc.css('div#comic img')

Net::HTTP.get(URI("#{address}/url/#{img[0]['src']}"))

sleep300# five minutes, be polite to the server

end

rescueSystemExit,Interrupt

puts"\nThanks for using ExtraMon!\n"

exit

end

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.

Sadly, for various reasons, my last job at Vualto didn’t turn out the way that I thought it would; ultimately I guess I just didn’t click with in-house methodologies so I decided to leave. Christmas 2013 came and went and with only four weeks of having a new job of “finding myself a job” I found myself a new job!

I have worked here (Microtest) for one day only and yet I feel like I have been here a year already, in a good way not a bad way that is. And if that wasn’t enough, on the first afternoon my new dev. machine turned up as promised, the fastest machine I have every used with two dual 24 inch ViewSonic monitors, 16GB of RAM and the biggest fastest SSD drive I have had the pleasure of yet. It boots Windows 7 but of course the first thing I did was to install VirtualBox and Ubuntu 13 for real work.

Ironically I applied as a PHP/web-dev role but I noticed they had a C++ vacancy too so I attached some example code and mentioned to the agent that I was once hired as a C++ guru and it went from there and so here I am, back to my roots with C++. I was as surprised as anybody to be hired after not using C++ commercially for so long but I still have the chops as they say.

I am going to enjoy it here.

The most interesting thing is that they have a large legacy code base running on SCO System V which they want to port to a more modern Linux, more than likely Ubuntu 12.04 LTS. They are using the commercial version of “Qt” for both visual and non-visual libraries so I get to learn Qt too which is also cool as I have dabbled with it but never really learned it.

All in all I am really looking forward to getting stuck in here and pouring myself into whatever transpires here and I shall look to drivel on about the more interesting things that come about from tackling SCO or just porting or coding at large without mentioning any names or otherwise blowing my cover.