Sunday, 20 January 2013

Haxe & HaxePunk

I've had a lot of fun looking into cool stuff this new year and having made a move into the gaming industry; with my first job based around the development of a small, tablet based, casual game I've been looking into multi-platform, 2D, off the shelf, games engines.

I came across a project called Haxe (pronounced: Hex) that uses a language which is a derivative of ActionScript3 that compiles to native code for Android, IOS, Blackberry, Windows, Linux and Mac as well as Flash or HTML5 + Javascript... Which is pretty awesome in my opinion.
http://haxe.org/ 

HaxePunk is a Haxe port of the FlashPunk game engine which is extremely handy as it means there is a wealth of resources and tutorials on developing games with it.
Haxe Punk: http://haxepunk.com/
FlashPunk learning resources: http://flashpunk.net/learn/

I ran into a couple of problems while setting up my environment on OSX so I'll cover installing Haxe plus a couple of the problems I had here:

#1 Download Haxe here: http://haxe.org/download.

#2 Run these from the command prompt (you may need to sudo these, depending on your setup):

haxelib install jeash
haxelib install actuate
haxelib install nme
haxelib run nme setup
haxelib run nme setup android

#3 The last line will start up the android SDK installer, but the one it downloads will need upgrading. After the auto update remember to reopen the android SDK installer and select the version 8 API then download and install before continuing on with the setup script.

#4 The Haxe language bindings for MonoDevelop 3.0 didn't show up for me in:
MonoDevelop > Add-ins > Gallery
So I downloaded them manually from: http://addins.monodevelop.com/Beta/Mac/3.0/MonoDevelop.HaxeBinding-0.4.0.mpack

#5 When targeting IOS in MonoDevelop the IDE just hung. So I tried from the command prompt with:
$ sudo haxelib run nme test "project.nmml" ios  -simulator
From the directory containing my project.nmml.
This provided me with a meaningful error about the compiler not being able to find clang++ this, I think, was due to me having XCode 4.2 intalled .
Make a note of the directory it was looking for clang++ in then run:
$ which clang++ to find out where clang++ is on your system (/usr/bin/clang++ on my system) and symlink it to the directory that you made note of earlier.
Rerun: $ sudo haxelib run nme test "project.nmml" ios  -simulator
If it works then you should be ok to target iOS from MonoDevelop again, without it hanging this time.

#6 If you're having performance problems with HaxePunk on Android check out this Stackoverflow post

Setting up D v2.061 on OSX (Mountain Lion)... rdmd not installing.

I've recently been playing with the D language on my MacBook and found the latest dmg (v 2.061) from: http://dlang.org/download.html did not install rdmd or the D shell.

The sollution to this was to download the "all platforms" zip file, from the D downloads page, then following the guide here: http://dlang.org/dmd-osx.html

Once this is done you can use the #!/usr/local/bin/rdmd shebang at the top of your .d files.
Note: this differs slightly from the one used in the tutorials at : http://www.informit.com/articles/article.aspx?p=1381876 (which uses #!/use/bin/rdmd)

This may have just been a problem specific to my particular system and/or setup, I'm not sure... But if not I hope this helps someone.

D

I read an article about functional programming in C++ by John Carmack (of Doom fame) last week and while it did little to warm me to C++ the article was very interesting and covered the the virtues of immutability and pure functions as they can be applied by anyone in almost any language.
http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/

In the article John mentions a programming language called D, so having enjoyed the article I took the time to check it out.

There was a lot to like about D: It has 'immutable' and 'pure' keywords, anonymous functions and closures, a garbage collector, built in tools for concurrency, unit testing, contract coding (pre and post conditions, etc). It also compiles to native code and can introp with C and extend Python (Pyd: http://pyd.dsource.org/index.html)

I'm liking a lot of what I'm seeing about D ... More posts on D to come.

Setting up Ubuntu (12.04 LTS) in VirtualBox under OSX Mountain Lion


I've recently needed  to run an Ubuntu VM on my 2012 Mac Book Pro (Retina) and being a cheapskate I reached for VirtualBox.

Initial installation is fairly easy but I immediately ran into a whole host of problems:

  • The newest version of Ubuntu (12.10) desktop requires 3D acceleration so it runs like crap.
  • I can't see my Mac's Documents folder that I had marked as a shared folder in VirtualBox's settings.
  • I couldn't ssh into the VM.

So to save anyone else the trouble I thought I would document the steps I went through here.

#1 System Configuration

Download Ubuntu 12.04 LTS (instead of 12.10). OK so it's not the latest version but not having to wait 2 seconds for the Ubuntu desktop to respond is vital to not loosing patience with the whole setup.
I chose 12.04 LTS 64 bit which is in the downloads section just bellow the download link for the latest version, here (Note: 32-bit is selected by default): http://www.ubuntu.com/download/desktop.

Using VirtualBox (https://www.virtualbox.org/) I set up a VM with the following configuration:

* General
Name: Ubuntu

* System
RAM: 2048 GB
HDD: 8GB , Virtual Disk Image (VDI), dynamically allocated
CPU: 2 x CPU (though this causes a non-optimal settings warning, not sure why).

* Network
Type: NAT
Port forwarding (under 'Advanced' tab in networking):
 name: 'ssh'
 host port: 2222
 guest port: 22

* Shared Folders
Name: Documents, Path : /Users/jamesdoig/Documents
Do not check "Auto mount" (as it's bugged)

#2 Installation
* Under Settings -> Storage place the Ubuntu .iso into the CD/DVD drive and start the virtual machine.

* Go through the Ubuntu installation procedure.
I chose the: English: Macintosh, international keyboard layout to match my Mac Books kb layout.

* Once you have booted into the operating system and logged in: From the virtual box menu select: Device-> Install Guest Additions. Follow the on screen prompts.

* Reboot your VM.

#3 Folder sharing setup

* Sign into Ubuntu and open up a terminal,
Make a directory in /media to mount your shared folder to:
$ sudo mkdir /media/shared
Mount the shared folder (In my case Documents) :
$ sudo mount -t vboxsf Documents /media/shared

This will mount your Documents folder at /media/shared but you will have permission problems.

* Still in your Ubuntu VM terminal do:
$ cat /etc/passwd
and make note of the numbers that appear in the entry for your login name:
e.g: james:x:1000:1000:james,,,:/home/james:/bin/bash
So 1000 in my case.

* Now using your text editor of choice (I installed emacs by this point) :
$ sudo emacs /etc/fstab
and add the line:
Documents   /media/shared  vboxsf  uid=1000,gid=1000,nodev,noexec,nosuid,auto,rw 0 0
Where uid & gid = the number you noted earlier,
'Documents' is the name of the folder you shared in VirtualBox
And '/media/shared' is the mount point your created earlier.

* Reboot your VM.

#4 SSH setup

Open up the Ubuntu terminal and do:
$ sudo apt-get install openssh-server

I'd rebooted the VM a lot during this process so can't be sure if this step also required it.

Now you should be able ssh into your Ubuntu VM from your Mac terminal with:
$ ssh -p 2222 <your login name>@127.0.0.1

#5 Running the VM in headless mode and SSHing in

This step isn't required but I did it for convenience:
In your Mac terminal:
Edit your ~/.bash_profile
e.g: $ emacs ~/.bash_profile
And add the following:

alias ubu='ssh -p 2222 james@127.0.0.1'
alias uvm='VBoxHeadless --startvm "Ubuntu"'
alias uvmx='VBoxManage controlvm "Ubuntu" poweroff'

Where "Ubuntu" is the name you gave the VM in Virtual box.
Also pick aliases that work for you.

Using these I can launch my VM headlessly (Without launching the GUI and VM desktop) from the terminal with: $ uvm
Shut down the vm with: $ uvmx
And ssh into the vm with: $ ubu

Tuesday, 11 September 2012

Experimenting with ZooKeeper


I've recently been reading up on Zookeeper; with a view to give a lightning talk on it.

At first glance I found it hard to get a firm grasp on what it is that Zookeeper actualy is/does. When I started telling people I was planning a talk on Zookeeper it turned out that I was not alone, I got a lot of responses along the lines of "great! I heard Zookeeper was awesome but I have no idea why or what it is".

After having spent some time playing with Zookeeper in Python and Closure I'm both very impressed with it and puzzled as to why I didn't get it in the first place...
It's such a simple concept and it is, pretty much, as described on the official web site. I guess I could attribute mine and others confusion to the fact that Zookeeper is kinda "low level" in as much that the site has patterns you can implement to build such things as distributed locks and leader election, but as it stands Zookeeper is just a tree based file system for meta-data... It just so happens this is the exact foundation you want for these high-level constructs.

There are some great libraries for working with Zookeeper, here are the handful I've used so far:
The first thing I wanted to try with ZooKeeper was to tackle the messy issue of configuring applications in an environment specific way.
To this end I built Enclosure, a python command line tool that I can point at ZooKeeper and an on disk directory; it models znodes on the structure of that directory and loads the data from files into those nodes.
I also built a script in Python (Clojure version coming soon) that would allow an application to join an environment, download its configuration and subscribe to updates to that configuration file.
You can find Enclosure here: https://github.com/jdoig/Enclosure

I was also mulling over a system for caching bulk API calls that involved a two stage, distributed, caching mechanism that would need to communicate amongst other instances & processes as to whether a call was:
a) not yet started
b) started and streaming into level 2 cache or
c) finished, sorted, cleaned and stored into level 1 cache.
...Zookeeper's barrier recipe (a distributed lock) fit the bill just perfectly.

I'll put my lightning talk video up over the next few weeks.

Sunday, 12 August 2012

Trello Rocks!

Almost a year ago now we started doing daily "stand-ups" and tracking progress on story cards with a view to becoming more agile.

I like the idea of getting everyone together and talking about the tasks at hand and having some way to track that work that is simple and tactile.

The problem is the paraphernalia... You can't move the board easily if you wan't to relocate, its not easy to attach documents to the wall and a lot of people's handwriting is illegible.

I'd spotted Tello on hacker-news some time back and thought it looked like an amazing tool but attempts to push it at work had met with: "But then we have to track tasks in two places"
(That wall was going nowhere; it was the only remaining artefact of a, very expensive, agile adoption attempt).

Just recently a handfull of our most awesome rockstar developers and myself landed a pretty cool "Friday project" that we would be self-managing.

So we went with Trello and it has been nothing short of a joy to work with.

The bulk of that joy comes from the fact that rather than standing round a bunch of cards in a stuffy office we can sit in a coffee shop, scoffing croissants and flicking tasks around on Charlies iPad (trying not to get jam all over it).

We also have access to it anywhere... If all of a sudden we remember something that was missed or have a question we can just bring up trello on our phones, tablet or laptops and throw stuff in there.

We've also given the client access to our board so, at any time, they can log-on and see how things are going, follow the links to our showcase environment, watch videos of walkthroughs, etc.

What are you waiting for? Get you some Trello!: https://trello.com/

Using Java github repo's from Clojure

This week after watching Mike's lightning talk on bloom & count-min sketch algorithms I found myself hacking away at a Clojure implementation of a bloom filter and needing to pull in a Java project from github (a murmur hash implementation).



Here's how it's done:
  1. Add the following line to ~/.lein/profiles: [lein-git-deps "0.0.1-SNAPSHOT"] under :user :plugins, like so:
  2. Form the command line run: lein deps

  3. In your projects project.clj file add the following: where :git-dependencies is the github url of the repo you wish to use and :java-source-paths is the path where Leiningen will find the source code to build (note: it will be downloaded from github into a directory .lein-git-deps/ by default
  4. From the command like run: lein git-deps

  5. Add an import statement to your clojure files: