Arni Lochner
Barry Pace
Chris Dowling
Chris Herring
Colin Dean
Craig Curchin
Gareth Foote
Gareth Leeding
Gemma Bardsley
Lucy Burchell
Marc Hibbins
Tim Crook
Tim Kalic
→ Barry Pace | 10 Mar 2012 | 11:45am GMT
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius.
Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.
------------------------------------------------------------------------------------------
One Note→ Marc Hibbins | 21 Sep 2011 | 11:41am GMT
In addition to my last post on Python development environments, here’s a note on using the PyDev plug-in for Eclipse with our virtualenv set-up.
Assuming everything went swimmingly — virutalenv running, Django installed with a project folder (let’s call it ‘myproject’) having done something like this:
$ mkdir dev
$ cd dev
$ virtualenv --no-site-packages env
$ source env/bin/activate
(env) $ pip install django
(env) $ django-admin.py startproject myproject
First install PyDev in Eclipse under “Install New Software” with the URL: http://pydev.org/updates
Once that’s done, configure the Python interpreter. In your Preferences, under PyDev and Interpreter – Python, hit the Auto Config option to find all your libraries and populate the Python Path.
Otherwise, manually add Python and locate your interpreter, mine is under /usr/bin/python2.7.
For now, this only includes your globally-installed system-wide libraries, not those you’ve installed within the virtualenv environment.
To create a new “PyDev Django project” however, you’ll need to have Django installed globally (or otherwise configured in the above Python Path settings) so PyDev can see it. Right now ours isn’t, so we have an extra step.
Instead, we’ll create a “New PyDev project” (non-Django), add our virtualenv location containing the libraries in our local site-packages directory, then convert that to a Django Project once PyDev is satisfied we have the goods.
This method means we don’t have to install Django globally just for the sake of using this IDE.
To do this, from the File menu and New PyDev Project, I un-tick ‘Create src folder and add it to the PYTHONPATH’, instead selecting ‘Don’t configure PYTHONPATH (to be done manually later on)’.
Right-click the project folder, go to Properties and PyDev – PYTHONPATH and add a Source Folder pointing to your virtualenv site-packages. In this instance:
dev/env/lib/python2.7/site-packages
Having found Django, PyDev now let’s us convert this to a Django project. Right-click again and under the PyDev menu select Set as Django Project.
Now everything can be performed within Eclipse, rather than by the command line.
For example, to run the server we’ll add a Custom Command. Under the Django menu select Custom Command and add the following:
runserver --noreload
You may be asked to select which manage.py to run from, choose the one within your project, i.e. myproject/manage.py.
Hit Run and test http://localhost:8000/ within your browser.
Note the --noreload option allows Eclipse to maintain control over the process, rather than spawning a new thread. This function usually allows the server to reload automatically when changes are made to your code, at your convenience.
------------------------------------------------------------------------------------------
Here’s to Taking It Easy→ Marc Hibbins | 15 Sep 2011 | 4:43pm GMT
I mentioned in my previous post that I borked my system meddling with Python. Having reset my workspace, I’ve now set up a solid system that makes handling projects and multiple development environments super simple.
The new set up easily handles multiple Python projects, without compatibility or version conflicts. The installation is equally straightforward.
Before switching to a desktop Linux, I used to sing the praises of VMware and developing with virtual machines when dealing with unique environments. By “unique”, I rather mean any odd project out of the ordinary LAMP set-up I usually work with, or something that requires a specific version of a piece of software.
Since then however, I’ve found no need. So long as you think before you leap.
Virtual boxes (as closed, single-piece software) are good and all, you can be as venturous as you wish without risk of damaging your native system. Plus, if you screw one of these you can restore a saved state in a few clicks. However, the VM safety net allows you to proceed without caution, perhaps recklessly, at the expense of fully comprehending the commands you’re executing and tasks you’re running.
In that sense, they’re great for beginners uncertain of how (or if) they should install software, e.g. Apache, PHP, Python etc — appliances and virtual stacks are helpful.
Otherwise they can convolute your workspace — and more often than not, won’t be configured exactly how you want or need them. Running software natively is simple and as intended, it also allows you to configure your entire environment without any assumptions made by distributors.
Virtualenv
Virtualenv is quite the revelation. It facilitates multiple isolated Python environments on a single system, dynamically handling your Python Path so packages are install within an enclosed local directory, rather than in amongst your top-level system packages.
This means you can create project-by-project virtual environments avoiding compatibility and version conflicts. When an environment is created (and activated) libraries are thereafter installed within discreet directories that aren’t shared with other virtualenv environments.
This means nothing is installed “system-wide”, so libraries don’t accrue over time, there’s no balancing of versions. It also means you can work with different version of Python simultaneously.
Python packages should be installed with a package manager. The latest of which is pip.
Prior to this, easy_install was the manager du jour (part of Setuptools, both now out-dated), but we’ll only be using that to install pip:
$ sudo easy_install pip
Pip is a direct replacement for easy_install, improving on a few things (a comparison can be found on the installer site). Packages that are available with easy_install should be pip-installable and the installation method is the same — the following installs virtualenv:
$ sudo pip install virtualenv
With virtualenv installed we can create an environment within your workspace, all it needs is the environment directory name, here ‘env’:
$ virtualenv env
There are a few options you have with this command. In the following example, the --no-site-packages flag means that the new environment will not inherit any system-wide global site packages. The --distribute flag will install Distribute rather than Setuptools:
$ virtualenv --no-site-packages --distribute env
Distribute is to setuptools as Pip is to easy_install. Distribute and pip are the new hotness, Setuptools and easy_install are old and busted — for now.
Anyway, activate your environment:
$ source env/bin/activate
You’ll see from your shell prompt that the environment is activated, with the name prepended.
Then we’ll install something with pip. Yolk is a tool for querying the packages currently installed on your system, so we’ll install that and grab a list:
(env) $ pip install yolk
(env) $ yolk -l
Then you’ll see everything the environment can see in the output (this will depend on your global site packages and how you created the environment, as above).
Note that you don’t need to sudo whilst in the activated environment.
As a test, we’ll deactivate the environment and run the same command, which gets the following error (unless you have yolk installed globally):
(env) $ deactivate
$ yolk -l
yolk: command not found
If installed within an environment, a package is only available whilst it is activated. This is the means to install whatever you wish, without worrying about cross-project conflicts.
More pip
Another good feature of pip is to generate a list of requirements for your working set of packages. The command is called freeze and generates a text file as follows:
(env) $ pip freeze > requirements.txt
This will create a list of all installed packages with specific versions for each library. This is in a custom syntax and looks something like this:
distribute==0.6.19
wsgiref==0.1.2
yolk==0.4.1
This list can then be distributed (e.g. to a team of developers) and used to install those packages on other systems, like so:
(env) $ pip install -r requirements.txt
Note, this isn’t couple with virtualenv, which actually has it’s own method of bootstrapping — see “Creating Your Own Bootstrap Scripts”.
------------------------------------------------------------------------------------------
Home Security→ Marc Hibbins | 8 Sep 2011 | 3:43pm GMT
Since deciding to work exclusively in a Linux environment at the beginning of the year, I’ve been more than pleasantly surprised not to have found myself needing to reset my system as a result of the frequent changes of set-up and numerous installations and removals of software that I’ve needed to perform in order to work on various projects.
The inevitable day, however, came a couple of weeks ago when I royally screwed my system messing around with Python (solution in another blog post. Update: here it is).
Once Ubuntu was reinstalled, I encountered a problem attempting to recreate my workspace having opted to encrypt my home directory during user setup.
Running the normal LAMP-server setup, Apache is unable to access files within the encrypted home.
I was tying to duplicate my previous configuration, using individual VirtualHosts locating directories within my user home, for example:
/home/marc/sites/dev/
I’m pretty sure my home directory was encrypted last time too, but this problem was new for me — perhaps something from an update in between?
The permissions problem occurs as only my user, marc, has access to the home and Apache’s user, www-data, does not. This results in a HTTP 403 Forbidden when attempting to serve files.
Having a look around, I found a convoluted method using symlinks and Apache’s UserDir then a far simpler solution, on AskUbuntu, as follows.
It’s unsafe to change your home ownership (to www-data, for example) but Apache needs execute permissions there. So selectively chmod the directory:
sudo chmod 751 /home
This grants execute access to others, who can only read files with correct knowledge of names and locations. It also removes your user’s read access to /home, so you’ll have to sudo for that.
Another precaution benefiting those on development-only machines, is to restrict IP listening within Apache’s ports.conf, so only local connections get any attention:
Listen 127.0.0.1:80
Alternatives
As for alternatives, you could encrypt your whole drive rather than just the home directory. You shouldn’t see any problems then.
Or you could just ignore encryption all together.
You could, of course, just work out of the traditional /var/www/ location, which is the Apache default. Simply create a directory there and chown to your user so you don’t have to always sudo changes.
sudo mkdir /var/www/dev/
sudo chown marc /var/www/dev/
If you’re directories are elsewhere on your system, for example in SVN repositories such as /srv/svn/ or /usr/local/svn/ then you’ll need to chown those to www-data so they’re readable, similar to our method of reading from within /home above.
The Ubuntu docs on Subversion offer the best solution for handling user permissions for SVN over HTTP.
Create a new user group, subversion, add the users marc and www-data to it and chown the repo to www-data:subversion, giving read/write access to the group (granting privileges to marc). Finally chmod with -s so that new files inherit that group ID, like so:
cd /srv/svn/
sudo chown -R www-data:subversion dev/
sudo chmod -R g+rws dev/
The -s flag means that all files created inside that directory will inherit the group of the directory, otherwise files takes on the primary group of the user. New subdirectories will also inherit this.
The -R option applies the changes recursively (i.e. existing subdirectories).
------------------------------------------------------------------------------------------
As Long as You Follow→ Marc Hibbins | 18 May 2011 | 10:48pm GMT
The final part of Beats Per Mile worth mentioning is the Twitter integration.
The application was designed to send automated tweets on Gemma’s behalf from her personal Twitter account giving updates of her progress to those following.
Mainly the tweets would report her current location for the purposes of spectators waiting ahead, others would be sent at intervals of a mile or so to report pace and ongoing form.
Similar to the mechanism for fetching Instagram images at predetermined locations on the course, the application contained a list of agreed points at which to tweet.
These were at landmarks and certain spectator spots too, but also at course milestones — the first mile complete, halfway complete, one mile to go etc, as well as the start and finish.
The application monitored the elapsed distance and updated accordingly, grabbing the latest time and statistics from the RunKeeper data, as well as geolocating the tweet with the latest set of GPS coordinates.
Since Twitter deprecated support of Basic Auth, applications much authenticate users with OAuth to gain write access.
This means rather than handing over your username and password to applications and trust (hope) that they’re friendly — as used to be the only way — OAuth allows applications to request access on your behalf without users ever parting with precious login credentials. You simple give, or deny, permission.
Using TwitterOAuth
Twitter offer a number of links to OAuth libraries for various languages to make the this job a lot easier. There are many Twitter specific OAuth libraries in particular, purposely tailored for the API.
I picked up PHP-based TwitterOAuth by Abraham Williams, which gets you up and running very rapidly.
The OAuth flow is documented at length, but essentially performs three major tasks:
- Obtains access from Twitter to make requests on behalf of a user
- Directs a user to Twitter in order to authenticate their account
- Gains authorisation from the user to make requests on their behalf
This is achieved with a cycle of exchanging authenticating tokens between application and Twitter to verify permission. TwitterOAuth particularly creates a session object in your application and rebuilds itself with each token exchange to remain contained in a single class instance.
In a very abridged manner, something like the following:
// Build TwitterOAuth object with client credentials
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
// Get temporary credentials to allow application to make requests and set callback
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);
This initial call verifies your application has access the Twitter API, basically that it’s registered and good to go. Twitter returns two tokens, if successful, that we store:
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
Then the application sends the user to Twitter to authorise it’s access, using a URL generated with the token received above:
$authoriseURL = $connection->getAuthorizeURL($request_token['oauth_token']);
header(‘Location: ‘ . $authoriseURL);
On successful authorisation Twitter will return the user to your callback URL (set above) with a verification token. TwitterOAuth now rebuilds for the first time with the OAuth tokens in our session and uses the new verification token to get an a new access token which will grant us user account access:
// Create TwitterOAuth object with application tokens
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
// Request access tokens from Twitter on behalf of current user with verifier
$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
This final request gets us two OAuth tokens specific to the current user, allowing us to make requests on their behalf, with which TwitterOAuth rebuilds again:
// Rebuild TwitterOAuth object with user granted tokens
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
// Test that everything is working
$connection->get(‘account/verify_credentials’);
The dance made a hell of a lot easier with a library such as this.
Usually applications store these tokens final two tokens, the user generated oauth_token and oauth_token_secret, which saves the need to authorise the user again.
Storing these details (in a session or database) means that a username and password need not be saved. The tokens are good until the user revokes access, no sensitive information is ever released to the application, all the user ever gives is their permission.
With access tokens stored, the connection to Twitter is a lot simpler — just create the TwitterOAuth object with those user-generated codes as in the very last step, without any of the redirecting to and from Twitter.com. Of course, those tokens could only have ever been obtained by carrying out the full process to begin with.
Beats Per Mile is a single-user case application, so Gemma only had to authenticate the application once and then we hard-coded them into the scripts.
Tweet Away
With access granted the application was free to send out updates, based on the run data we were collecting and posting it directly.
As mentioned, locations translated into distances and that’s when we tweeted.
At mile twenty, it looked back at the mile splits so far and reported which were the fastest:
Relying on the total reported distance alone was flawed. There was a slight hiccup when RunKeeper lost GPS coverage under Blackfriars tunnel and in an attempt to compensate found the nearest location to be the other side of the Thames.

This caused a problem by adding extra distance to her total, so some of the latter tweets (“one mile to go”, for example) posted a little prematurely.
It was more of a problem for Gemma when running, the app announcing in her ear that she’d run further than she had, disheartened to see mile markers on the course thought to have already passed.
This is also why the total distance on the site clocks up to 27.65 miles, the race was long enough as it is!
The final touch to was to drop them on the map, alongside the Instagram images.
------------------------------------------------------------------------------------------
I Heart Play - Blogs Widget
Version: 1.2
Post Date: March 5, 2007
File Size: 220K
System Requirements
Mac OS X 10.4.4 or later












