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.

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…

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.

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.

Yet another new job!

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.

 

Ruby ruby ruby…

Loving it… learned it years ago when it came out but then not used in in at least five years. Recently had cause to go back and develop an API server using Rack and all the other great stuff.

Wow.

If only the PHP world was like the Ruby world…