Skip to content

Instantly share code, notes, and snippets.

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
dracos / bbcnews.pl
Created July 19, 2011 10:56
BBC News front page scraper
#!/usr/pkg/bin/perl -w
use strict;
use POSIX qw(strftime);
use Text::Diff;
chdir 'web/dracos.co.uk/public_html/work/bbc-news-archive/';
# Fetch current page
my $web = get_bbc_news();
@dracos
dracos / gist:2695266
Created May 14, 2012 17:40
Installing a new GeoDjango project on my Mac
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
dracos / gist:2794525
Created May 26, 2012 16:28
Setting up tweet2voice on a Mac
# 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://github.com/dracos/tweet2voice.git
# Again, some more stuff about what's going on
@dracos
dracos / github.pr.tamper.js
Last active December 15, 2015 23:59
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. https://github.com/dashboard/issues/assigned or the similar org page)
// @match *://github.com/dashboard/issues/*
// @match *://github.com/organizations/*/dashboard/issues/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @author Matthew Somerville >> https://github.com/dracos
// ==/UserScript==
@dracos
dracos / help-with-django-1.5-upgrade.md
Last active December 18, 2015 11:49
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
dracos / gist:6307176
Last active September 1, 2017 20:55
Stopping the daemon fixmystreet app, and starting it in debug mode, printing everything to console
$ 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
dracos / hangs
Last active December 27, 2015 13:29
Output of script
$ python broken.py
speeches/fixtures/expected_outputs/mp3/lamb_first_three_seconds.mp3
[Binary data]
Output #0, s16le, to 'pipe:':
Metadata:
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)
import urllib
from lxml import etree
parl_members_xml = etree.parse(urllib.urlopen('http://data.parliament.uk/membersdataplatform/services/mnis/members/query/House=Commons%7CIsEligible=true/'))
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
dracos / gist:9933033
Last active August 29, 2015 13:58
Iterators of prev/curr/next
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