Testing new Ubuntu versions

Newer Ubuntu versions are less dramatically new these days, which is probably a good thing, but I like to take them for a spin anyway – old habits and all that. One nice change since the days of Dapper Drake is the ability to boot off a usb stick – much easier than having to burn CDs. On my laptop, I get to the boot menu by pressing the Esc key soon after booting and then selecting the USB stick to boot off. But there can still be problems. In particular, I was receiving the error message:

gfxboot.c32: not a COM32R image

Turns out you need to press the tab key and then type in “live”. Obvious really (not) Ubuntu 14.04 LTS live USB boot error (gfxboot.c32:not a valid COM32R imag).

Another good thing about modern Ubuntus is that they generally work out of the box just how I like them. I remove items from the launcher, shrink the icon size and add the Show Desktop icon to the launcher (under System Settings > Appearance), and I’m almost good to go. There is still one thing that takes a bit of fiddling – adding the ability to minimise on click (Ubuntu 14.04 Adds ‘Click to Minimize App’ Option to Unity Launcher).

Step 1: Open Ubuntu Software Centre
Step 2: Install CompizConfig Settings Manager
Step 3: Open Ubuntu Unity plugin
Step 4: Launcher > Minimize Single Window Applications (Unsupported)

On the one hand the version changes aren’t as exciting as they used to be, but on the other, it’s never been easier to check them out.

Deploying simple flask app on heroku

I’m now a fan of Heroku. How cool is it to be able to deploy a Python app to free hosting?!

Blackbox flask app on Heroku

But in spite of great docs at Getting Started with Python on Heroku there were a few issues I had to handle. The main problems were because the instructions assumed you wanted to start with their demo app and not your own – which meant that they only explained things like requirements.txt and Procfile after you needed to have already made them (they were already present in the demo version).

Note – I am already familiar with git so I don’t explain that here – see Starting a simple Flask app with Heroku for more fleshed-out instructions.

Anyway, here is what I needed to do at the start:

1) Change the app.run(host='') line to
port = int(os.environ.get("PORT", 33507))
app.run(host='', port=port)

Otherwise the app would fail because of a problem with the port when I ran

heroku ps:scale web=1

Starting process with command `python main.py`
Web process failed to bind to $PORT within 60 seconds of launch

2) I really needed to use virtualenvwrapper and create a requirements.txt file e.g.

cd <folder with code in it>
mkvirtualenv blackbox

Otherwise heroku wouldn’t know what dependencies my app needed fulfilled to work successfully.

To update requirements.txt after changes,

cd <folder with code in it>
workon blackbox
pip freeze > requirements.txt
deactivate blackbox

3) I needed to make a Procfile:

web: python main.py

Note, this was a toy flask app so not using gunicorn etc. Probably should look into that later:

4) Setting debug mode off probably isn’t essential for deployment but probably a good idea anyway: app.debug = False before deploying.

Some other points: when developing on a different machine, I needed to supply my public key to heroku from that other machine (Permission denied (publickey) when deploying heroku code. fatal: The remote end hung up unexpectedly).

heroku keys:add ~/.ssh/id_rsa.pub

And the full sequence for upgrading your app after the prerequisites have been fulfilled is:

  1. Make sure you have the port set for heroku
  2. Then git to local repo
  3. Then git push to heroku
  4. Then run heroku ps:scale web=1 again
  5. Revert from the heroku port back to local for local testing and dev.

IDLE3 as default for py files on Ubuntu

Yes – I know, there are better alternatives to IDLE out there, but I am used to it for quick and dirty changes to python files (I use eclipse + pydev for more serious work). And I am increasingly making the switch to Python 3. So when I double click on a py file, odds are I want to open it with IDLE for Python 3 not Python 2.

Start by making sure you have a desktop file like the following:

gksudo gedit /usr/share/applications/idle-python3.4.desktop

[Desktop Entry]
Name=IDLE (using Python-3.4)
Comment=Integrated Development Environment for Python (using Python-3.4)

Then make the desktop entry the default for python files:

gedit ~/.local/share/application/mimeapps.list

[Default Applications]

Note – no trailing semi-colon.

And in Linux Mint:

Linux Mint:

ls /usr/share/applications/

identify appropriate .desktop file

gedit /usr/share/applications/defaults.list

add the appropriate .desktop file reference at the front of the python line as appropriate.

Saddest Programming Concept Ever

Python has spoiled me for other languages – I accept that – but I still wasn’t fully prepared for some of the horrors I discovered in Javascript. Which made the satiric article by James Mickens, “To Wash It All Away“, all the more enjoyable. Here is a slice I especially liked:

Much like C, JavaScript uses semicolons to terminate many kinds of statements. However, in JavaScript, if you forget a semicolon, the JavaScript parser can automatically insert semicolons where it thinks that semicolons might ought to possibly maybe go. This sounds really helpful until you realize that semicolons have semantic meaning. You can’t just scatter them around like you’re the Johnny Appleseed of punctuation. Automatically inserting semicolons into source code is like mishearing someone over a poor cell-phone connection, and then assuming that each of the dropped words should be replaced with the phrase “your mom.” This is a great way to create excitement in your interpersonal relationships, but it is not a good way to parse code. Some JavaScript libraries intentionally begin with an initial semicolon, to ensure that if the library is appended to another one (e.g., to save HTTP roundtrips during download), the JavaScript parser will not try to merge the last statement of the first library and the first statement of the second library into some kind of semicolon-riven statement party. Such an initial semicolon is called a “defensive semicolon.” That is the saddest programming concept that I’ve ever heard, and I am fluent in C++.

Nice deal on programming books

First a disclosure – I will be getting two free e-books for promoting the Packt Sale ;-). But I wouldn’t bother writing this up unless I thought Packt books would be of some value to me – so that makes it a genuine endorsement. For reference, here are the three I’m weighing up:

  1. Learning IPython for Interactive Computing and Data Visualization
  2. Git: Version Control for Everyone
  3. Responsive Web Design with jQuery

Buy One - Get One Free

Apparently the deal is:

  • Unlimited purchases during the offer period
  • Offer is automatically applied at checkout

I procrastinated a bit so there are only a couple of days left (ends 26th March). So be fast! Here’s the promotion link

Installing iNZight on Ubuntu (13.10)

Existing documentation for installing iNZight on Ubuntu covers a wide range of possible scenarios in Step 1. For my own specific case, however, I needed to translate it into a series of precise step-by-step instructions.

So here are the instructions that worked for me for Step 1. Once that is done, just follow steps 2 onwards in the official docs.


It is probably best you don’t already have R already installed. And if you’re using iNZight, you probably won’t. But if you do, purge it! Installation may or may not work depending on the version of R you install so remove one source of difference from what the support people will have tested.

  1. ctrl-alt-t to open terminal window
  2. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
  3. sudo gedit /etc/apt/sources.list

    and then append

    deb-src http://cran.stat.auckland.ac.nz/bin/linux/ubuntu saucy/

    Note: must have trailing slash (/) at end
  4. Click on “Save” button on toolbar or enter ctrl s on keyboard to save
  5. sudo apt-get update
  6. sudo apt-get install r-base
  7. Open R by typing R into terminal
  8. From R prompt:
    update.packages(ask = FALSE)

    y to everything

  9. q("no")

    to quit the R prompt.

  10. Then follow steps 2 onwards in the official instructions …

USB 2 on VirtualBox

Get the appropriate version of the VirtualBox extension pack installed – I found the correct version in here: Download VirtualBox (Old Builds): VirtualBox 4.2

Add self to vboxusers group as per Set up USB for Virtualbox. Must reboot for change to take effect.

sudo usermod -aG vboxusers

Then follow the additional steps. For Windows XP at least, must add a filter before opening so that the USB is recognised by the File Manager and displayed as an extra drive.

Dual boot Samsung 700 Ubuntu / Win8

My Mother found Windows 8 very bewildering (actually, so did I) and asked me to install Ubuntu (13.10) instead on her Samsung 700 tablet/notebook. I thought I’d set it up dual boot so I could occasionally use Windows 8 for testing purposes and in case there was any sofware that we needed in the future that was Windows only.

  1. Power off
  2. Put bootable Ubuntu USB in
  3. Boot but hold down F2
  4. In the BIOS config (it was touchscreen which was quite nice):
    • Advanced:
      • Fast BIOS Mode: Off
    • Boot:
      • Secure Boot: Off
      • OS Mode Selection: CSM and UEFI OS
      • PXE boot: On
  5. Save>Yes
  6. Reboot but hold down F2
  7. Boot to Device now showed: UEFI: DSE MicroDrive 2GB 1.00 (or however your USB identifies itself)
  8. Boot into Ubuntu installer
  9. Shrink Windows partition (the NTFS one)
  10. Add a large Ext4 partition for Ubuntu and a smaller swap partition
  11. Install Ubuntu onto the new Ext4 partition with / as mount point
  12. Reboot and set everything up. Success :-).

My favourite eclipse settings

Preferences>PyDev>Editor>Code Style>Code Formatter – Tick “Right trim lines?”

Preferences>PyDev>Editor>Typing – untick After ‘(‘ indent to its level (indents by
tabs if unchecked)

Number of indentation levels to add: 1

Switch pylint off so pydev code analysis can do its job:

Preferences>PyDev>Editor>PyLint Untick “Use pylint?”.

Preferences>General>Editors>Text Editors>Annotations>Occurences (PyDev) set to #6BF459 so bright enough to see when very small but can read text on top.

Preferences>General>Editors>Text Editors>

Displayed tab width: 4

Tick “Insert spaces for tabs”
Tick “Show print margin” and set to 80.

Tick “Show line numbers”.

Rotate video (and cope with frame rate problem)

The problem – I had taken a video on a smart phone upside down and needed to rotate it (Note – rotating is not the same as flipping). Here is the successful command I used on Ubuntu:

avconv -i "my_input_video.mp4" -r 25 -vf transpose=1,transpose=1 my_output_video.mp4

Note – I needed to rotate it so chaining two 90 degree transpose commands (transpose=1 is a single 90 degree transposition) worked (see How can I rotate video by 180 degrees with avconv).

Note the -r 25. I don’t pretend to understand all the options of ffmpeg/avconv but the -r 25 forced the conversion to use a manageable number of frames. Without it, converting one particular video was failing, thrashing the CPU, and taking forever. There was a message in the ffmpeg/avconv output about MB rate > level limit. Another video worked fine without -r 25 but if you have the same problem with MB rate give -r 25 a try. Or better yet, learn more about what you’re doing ;-). I didn’t have the time or inclination so tried to do the least I could to get a good result.