Skip to content

Instantly share code, notes, and snippets.

View gist:570562
I have an issue with co-ordinate transform from within Django, to do with SRID 29902 (Irish National Grid).
/usr/share/proj/epsg contains the following line:
<29902> +proj=tmerc +lat_0=53.5 +lon_0=-8 +k=1.000035 +x_0=200000 +y_0=250000 +a=6377340.189 +b=6356034.447938534 +units=m +no_defs +datum=ire65 <>
And this works from the command line:
$ cs2cs -f "%.15f" +init=epsg:29902 +to +init=epsg:4326
326905 369342
dracos /
Created Jul 19, 2011
BBC News front page scraper
#!/usr/pkg/bin/perl -w
use strict;
use POSIX qw(strftime);
use Text::Diff;
chdir 'web/';
# Fetch current page
my $web = get_bbc_news();
dracos / gist:2695266
Created May 14, 2012
Installing a new GeoDjango project on my Mac
View gist:2695266
sudo port install python27
sudo port install postgresql91
sudo port install postgresql91-server
sudo port install postgis
# Will now install psycopg2 system wide with ports, but could have done it later in the virtualenv
sudo port install py-psycopg2 +postgresql91
# follow instructions printed by the above to set up a database
sudo mkdir -p /opt/local/var/db/postgresql91/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql91/defaultdb
dracos / gist:2794525
Created May 26, 2012
Setting up tweet2voice on a Mac
View gist:2794525
# Open a Terminal window, and then one by one type the things after the $ signs below, wait for a new prompt before the next command.
$ sudo easy_install virtualenv
# Will print out some stuff, hopefully nothing that looks like an error
$ virtualenv tweet2voice
# Will print out some more stuff
$ cd tweet2voice
$ source bin/activate
# The bit before the $ will now change a bit.
$ git clone git://
# Again, some more stuff about what's going on
dracos /
Last active Dec 15, 2015
This basic GM script adds a "Pull requests only" tickbox to your dashboard issue pages on GitHub; clicking it hides non-PR issues. It doesn't work over pagination (without a refresh) or other things like that.
// ==UserScript==
// @name GitHub Assigned Issues Pull Requests tickbox
// @namespace github-assigned-issues-pull-requests
// @version 1.0
// @description Show only pull requests on the Assigned Issues dashboard page (e.g. or the similar org page)
// @match *://*
// @match *://*/dashboard/issues/*
// @require
// @author Matthew Somerville >>
// ==/UserScript==
dracos /
Last active Dec 18, 2015
Upgrading Django 1.1 to 1.5 validation issue

I'm upgrading an old Django 1.1 project to a clean Django 1.5 installation. The Django upgrade itself has gone very well; {% url %} changes, settings, some class-based generic views, some core patches replaced with a custom User model, others done with nicer middleware, and so on, hooray.

What I didn't expect to stop working, but has, is a model creation form that lets someone add a related object at the same time. In the code, this is done using a MultiValueField subclass:

class AutoCompleteMultiValueField(forms.MultiValueField):
    def __init__(self, model, column, *args, **kwargs):
        self.model = model
        self.column = column
        super(AutoCompleteMultiValueField, self).__init__(*args, **kwargs)
dracos / gist:6307176
Last active Sep 1, 2017
Stopping the daemon fixmystreet app, and starting it in debug mode, printing everything to console
View gist:6307176
$ sudo /etc/init.d/fixmystreet stop
$ sudo /etc/init.d/nginx stop
$ sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
$ sudo su - fms
$ cd /var/www/fixmystreet/fixmystreet
$ script/server
dracos / hangs
Last active Dec 27, 2015
Output of script
View hangs
$ python
[Binary data]
Output #0, s16le, to 'pipe:':
encoder : Lavf55.19.104
Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (mp3 -> pcm_s16le)
View gist:7707347
import urllib
from lxml import etree
parl_members_xml = etree.parse(urllib.urlopen(''))
parl_members = parl_members_xml.getroot()
print etree.tostring(parl_members.find('Member[@Member_Id="638"]'))
for member in parl_members:
if member.attrib['Member_Id'] == '638':
dracos / gist:9933033
Last active Aug 29, 2015
Iterators of prev/curr/next
View gist:9933033
import itertools
def prevnext(it):
prev, curr, next = itertools.tee(it, 3)
prev = itertools.chain([None], prev)
next = itertools.islice(next, 1, None)
return itertools.izip_longest(prev, curr, next)
def prevnext(it):
it = iter(it)
prev = None