Using AngularJS and Django Rest Framework

AngularJS and Django are the perfect couple, particulary when you introduce Restangular and Django REST Framework.

I’m open-sourcing a project which harnesses this stack, my RC flight logging app. It’s in its infancy, but I have some good ideas for it which I will soon share.

flyguy - AngularJS Javascript client. Uses Restangular to handle REST resources. Routed using Angular UI router. JWT (JSON Web Tokens) for authentication. Jasmine test suite. Bootstrap styling. Currently deployed to Github pages.

flyguy-service - Django Rest API service. Uses Django REST Framework. Currently running an instance via Dokku with a Postgresql database.

See app below, new user registration coming soon.

Update 26th August

New user registration is now implemented and live.

Building a Mini Quad

(A.K.A. Drone/Quadcopter/Multirotor/ZMR250)

It was Christmas 2014 when it all began, the conception of my Multirotor fascination and subsequent obsession. I’d eyed up a £30 micro quadcopter earlier on in the year but sensibly (or foolishly) avoided it. However it wasn’t long before in the usual last minute Christmas rush I found the quad for £16 from ebuyer. I ordered 3 Hubsan Q4 Nanos for Christmas presents. The fun we had flying these later led us to the larger Hubsan X4 with HD Camera.

Once I’d mastered the toys, it was time to move onto something bigger and better. I decided to avoid the out of the box RTF (Ready to Fly) models such as the Phantom, that all seemed to easy. I wanted to go deeper into the hobby and build my own.

After crawling the Internet I discovered a lot of people talking about the ZMR250. A seemingly decent clone of the way more expensive “Blackout” frame. Shiny Black, Carbon fibre, space to hold all sorts of fancy tech, £13.00? I was sold.

The Build



Working on the Mini Quad.

Soldering ESCs. This was tricky as the solder pads were staggered, so all 3 motor wires needed to be just the right length. The weight loss through not using bullet connectors is certainly worth it though.

Bringing the circuitry all together via the Simple PDB.

The Taranis X9D was my choice of TX. This shot also included the FPV (First Person View) gear.

Nice Fringe.

Until next time...

Next up:

  • Installation of the long awaited Overcraft PDB Batch 4.
  • GPS antenna for PH (Position hold), and RTL (Return to Launch).
  • Contribute to Cleanflight (waypoints?).
  • Build a web app to log flights.

Some video footage

Flying FPV in Cornwall and on Hampstead Heath.

Common Dokku Pitfalls

Dokku is a Docker powered Heroku clone which you can install on your own hardware. I’ve been using it for over a year now and have recently moved all of my sites over to run on it. It doesn’t come without its quirks, see below for more.

1. Insufficient physical memory

runtime: panic before malloc heap initialized
fatal error: runtime: cannot allocate heap metadata

Solution: Configure virtual memory (swap file).

dd if=/dev/zero of=/swapfile bs=1M count=512
mkswap /swapfile
chmod 600 /swapfile

Then add the following to /etc/fstab:

/swapfile         none            swap    sw                0       0

Then run the following to persist it.

swapon -a

2. Python/Ruby app incorrectly detected as Node app

This is down to the presence of a package.json file in your app root.

-----> Building node-js-app ...
Node.js app detected

Solution 1: Set your build pack explicitly to Python (see below). Then install Node.js via dokku-nodejs.

Solution 2: Use heroku-buildpack-multi to set both buildpacks (I haven’t tested this solution).

This way your app will be correctly built as well as your package.json dependencies installed.

3. TLS/SSL config + custom domain plugin incompatibilities

Using plugins such as dokku-domains-plugin or dokku-custom-domains, in combination with Dokku’s TLS support can result in unexpected TLS behaviour (i.e. Some certificates not being applied).

Solution: Use the dokku-nginx-hostname plugin which is compatible with Dokku’s TLS/SSL.

4. BUILDPACK_URL env var not recognised by build

Solution: Create file .env in the root of your app.

Add your build pack to it:

echo "export BUILDPACK_URL=" > .env

NOTE: This has been fixed in Dokku >=0.3.9.

5. Cannot deploy static app

buildpack-nginx doesn’t support Dokku >0.3 (Ubuntu 14.04).

Err quantal/main amd64 Packages
  404  Not Found [IP: 80]
Err quantal/restricted amd64 Packages
  404  Not Found [IP: 80]

W: Failed to fetch  404  Not Found [IP: 80]

Solution: Use the following build pack

See above on how to apply it.