http://nbviewer.ipython.org/gist/glamp/20a18d52c539b87de2af