Skip to content

Instantly share code, notes, and snippets.

#http://www.nhs.uk/NHSEngland/Healthcosts/Pages/Prescriptioncosts.aspx
Given a user is dispensed a prescription
When their age is >= 60
Then the prescription cost should be 0
Given a user is dispensed a prescription
And their age is < 16
Then the prescription cost should be 0
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 / https.py
Created September 24, 2015 13:54
A minimal HTTPS server in python
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
import ssl
# Use a higher port if you don't want to have to run as root
httpd = HTTPServer(('', 443), SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile='server.pem', server_side=True)
httpd.serve_forever()
@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
$ cpanm -L local Catalyst
$ cpanm -L local Catalyst::Devel
$ cpanm -L local Catalyst::View::TT
$ PERL5LIB=local/lib/perl5 local/bin/catalyst.pl MyApp
$ cd MyApp/
$ PERL5LIB=../local/lib/perl5 script/myapp_create.pl view Web TT
$ vim lib/MyApp/Controller/Root.pm # Change index line to $c->stash->{template} = 'foo.html';
$ PERL5LIB=../local/lib/perl5 script/myapp_server.pl
[info] *** Request 1 (0.200/s) [89599] [Thu Oct 8 17:44:14 2015] ***
[debug] Path is "/"
1,2c1
<
< <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
---
> <!DOCTYPE html>
18a18,58
> <meta name=viewport content="initial-scale=1">
> <style>
> @media (max-width: 730px) {
>
@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)