Archive for March, 2015

Writing a game without sleep, power or internet at JFK

Desolate JFK

Desolate JFK

I have a small (…) obsession with programming on the go. With that I mean that I want to be able to write software where ever I am and no matter what I might be doing. Or under what circumstances. So if I don’t have any power or internet for 20 hours I still need to be able to code. This has been one of the things I have been trying to achieve over the past 20 years. My biggest issues have been battery life and portability.

The are kind of related in the end, but to start with the former; batteries came a long way since I touched my first laptop somewhere end 80s. I was slightly spoiled mind you; I had a PC-1211 for years already by then which had seemingly infinite battery life. (Not to mention that I still have it and it still works well) That machine was obviously limited in power, but it allowed me to try out some algorithms on the go. Battery life has been somewhat of an issue though; tablets/phones/laptops all have abysmal battery life. I need days, not hours. And ‘day long’ which has been promised for years now, is definitely not for my days nor the work I do. My new Macbook seldom makes 4 hours while coding.

Laptops aren’t very portable either besides the Macbook Air 11 inch that is (and possible the new ‘Macbook’?), so it is also quite annoying to lug them around especially when I’m off for a 2 day hike in the mountains (and yes, I would like to code while walking). That brings us to portability and that has also been getting better (faster than battery life) but I must say my favorite portable devices are, in order: iPad Air 2 because it’s big enough to do ‘real’ work on, but weighs very little and is fast, Samsung s5 for the same reasons but different work and the OpenPandora 1 ghz version. The last one because it’s just ‘complete’; it has Linux, Android and runs everything I need (sometimes with some effort but we decided to find that fun).

The OpenPandora and the S5 allow me to swap batteries, giving me around 25 hours on the Pandora without any power outlet and around 20 hours on the S5. All that fits easily in a light bag still. For the iPad I bring an external battery which makes everything a lot heavier which is the reason the iPad only comes when I know I need to work on spreadsheets or documents a lot.

Last year around this time I went to the US on vacation; to Orlando to see if Disney World was still fun (it was) and, to get cheaper tickets we had a stopover at JFK from 11 PM to 8 AM. We were a bit naive being from Europe in thinking that JFK is a big airport so there must be stuff open all night and 11 to 8 is not enough time to go into NYC.

After landing we got into a little food court where we thought we would browse the web a bit and have some snacks and coffee until the morning. Unfortunately that was not going to happen. Everything closed at midnight. I still am flabbergasted by that fact and don’t really understand it, but it happened and there was nothing we could do about it. A bit worse; internet wasn’t working on our devices for some reason. So we had no internet, no power and after a while, no lights(!).

I brought my iPhone 5s, OpenPandora and my Macbook Air 11 (I did not have an iPad yet) to watch movies in the hotel or something. As there were no public power outlets, I knew I could not work on my Macbook too much because it would shut down after 2-3 hours (I opened it in the airplane…). Without internet I was a bit lost as I didn’t feel like reading at that time and we started to get tired (different timezone).

By then (around 00:30) I remembered some swiping game a friend told me to try. I did not download it yet, but I played it. Looking it up in the Appstore now I think it was Dots. And because I don’t actually like playing games (I only like making them; I don’t nearly make enough of them though), I decided to recreate that game from just my short interaction with it.


Squares screenshot

On my Macbook I only had Corona for games and because that is LUA I knew on the OpenPandora I could only use Load81 (as I had nothing else for LUA but a basic installation, and, still, no internet). Load81 is a great tool for teaching people to code as it has no no setup times; you just start it and start programming. Antirez of Redis fame wrote it so it’s like a C=64 from the 80s so people can, again, jump straight in as they could back then, without all the dll hell and compiling, linking etc. Just something to play around. I wrote the basic generators and game algorithms on the OpenPandora; aka, most of the code you see in this file was written in Load81.

After I was happy with how all of that worked in Load81, I used an USB stick to move the code to my Macbook and created the working version in Corona from the demo project. That took only a very short amount of time luckily. My wife and I played it in the Disney World queues most of the time. It’s addictive 🙂

Things that this experience taught me are:

  1. Train your brain; without internet you’d be surprised how much you don’t remember; I was anyway
  2. Downloading and setting up/updating development dependencies is actually far more annoying and time consuming than previously I realized; this was actually one of the smoothest dev experiences in years, despite the constraints
  3. You can finish something nice and addictive in a few hours, so don’t let lack of time stop you; just start coding already
  4. Battery life is indeed great on the OpenPandora
  5. Pulling an all nighter once in a while will focus you
  6. I should (and have been) pursue on-the-go coding like never before (I can code now without internet on the iPad & 5S & S5; more about that soon)

Link to the project in Github. Requires Corona.

HTML5: Fetching videos (etc.) and storing them in Localstorage to play them later offline.

We write a lot of mobile apps and web apps; they both serve their purpose. Usually mobile apps need to also work offline and sync to the server later while web apps have usually an online requirement; aka they won’t work when you have no internet.

A client recently asked to build a web application which could fully work offline. Meaning that all the assets, including quite heavy videos, need to be loaded the first time the app loads and after that should be available to the user even though there is bad or no internet. The logic should be on the client side and the data should be synced when the browser detects internet again.

For the data side of things, we decided to use PouchDB, but for the video side of things I had to make a little demonstration if it was even possible to get this working on modern browsers.

I know it’s theoretically possible to fetch videos and then store them in HTML5 Localstorage and then play them. I did not know it was that easy (using a few external libraries). I combined a few examples and libraries from the web, namely this and LargeLocalStorage and created a working version using Google I/O 2014 MP4 videos.

See the code here.

Tested on Safari desktop, Chrome desktop, Android browser.

Physics Body Editor Java 7 – Mac OS X

Because the downloads and binaries for the Physics Body Editor / Box2D editor do not work on modern versions of Mac OS X / Java 7.x, here is the recompiled binary.

Run with:

java -jar physics-body-editor.jar



This does not yet work with Java 8 (issue with Java 8 and LibGDK). If you have Java 8 installed, here is a version which includes the Java 6 runtime so it will work always.


Using Physics body editor files in actual games;