Skip to content

Instantly share code, notes, and snippets.

View andylolz's full-sized avatar

Andy Lulham andylolz

View GitHub Profile
@andylolz
andylolz / demo.py
Last active January 2, 2016 13:49
Python module for solving assignment problems: http://en.wikipedia.org/wiki/Assignment_problem
import election_data
from match import match
'''
Match BBC constituency names with TheyWorkForYou constituency names,
using MP name and party as extra queues
'''
twfy_data = election_data.get_twfy_data()
twfy_fields = ('party', 'name', 'constituency')
@andylolz
andylolz / assange.xml
Last active May 6, 2019 06:24
Parse the wikileaks transcript of a meeting between Julian Assange and Eric Schmidt into the Akoma Ntoso format, in order to import it into SayIt (https://github.com/mysociety/sayit)
<akomaNtoso>
<debate name="Transcript of secret meeting between Julian Assange and Google CEO Eric Schmidt">
<meta>
<references source="#">
<TLCPerson id="SC" href="/ontology/person/SC" showAs="Scott Malcomson" />
<TLCPerson id="JC" href="/ontology/person/JC" showAs="Jared Cohen" />
<TLCPerson id="JA" href="/ontology/person/JA" showAs="Julian Assange" />
@andylolz
andylolz / uppercase.js
Last active December 30, 2015 07:09
Uppercase map operator for use with http://datapipes.okfnlabs.org
// Uppercase operator
//
// Transforms all characters in a data file to
// uppercase
function transform(chunk) {
// `transform(chunk)` is called on each
// chunk (in the case of csv, each line) of
// the data file.
var json = JSON.parse(chunk);
@andylolz
andylolz / compare_pb_gov_uk.py
Created July 6, 2013 00:19
For all public bodies listed on gov.uk, find the best match currently on publicbodies.org
import csv
import urllib2
from bs4 import BeautifulSoup, UnicodeDammit
import Levenshtein
class compare_pb_gov_uk():
def __init__(self):
@andylolz
andylolz / jekyll_to_wp.py
Last active December 19, 2015 00:58
convert a directory of jekyll posts to wordpress posts
# -*- coding: utf-8 -*-
import os
import markdown
import yaml
from pywordpress import Wordpress
import xmlrpclib
class jekyll_to_wp():
@andylolz
andylolz / datagrab_assets_hack.diff
Created March 5, 2013 10:12
Hack to get DataGrab (roughly) working with Assets 2, and Assets 2 inside a Matrix field.
diff --git a/assets/third_party_code/ajw_datagrab/fieldtypes/datagrab_assets.php b/assets/third_party_code/ajw_datagrab/fieldtypes/datagrab_assets.php
index ea3f8ec..4f22dc2 100644
--- a/assets/third_party_code/ajw_datagrab/fieldtypes/datagrab_assets.php
+++ b/assets/third_party_code/ajw_datagrab/fieldtypes/datagrab_assets.php
@@ -24,8 +24,21 @@ class Datagrab_assets extends Datagrab_fieldtype {
while( $subitem = $DG->datatype->get_sub_item(
$item, $DG->settings["cf"][ $field ], $DG->settings, $field ) ) {
- $data[ "field_id_" . $field_id ][] = $subitem;
-
@andylolz
andylolz / _typesetter.php
Created November 28, 2012 23:44
Typeset some content for a textbox; truncate it to fit.
<?php
/**
* Preliminary work on the typesetter.
*
* $input_str - the input
* $width - the width of the text area in characters
* $height - the height of the text area in characters
* $overflow_str - the string appended to the text area, in the event of an overflow
*
* returns the typeset contents of the text area
@andylolz
andylolz / Student.php
Created October 14, 2012 23:36
Fun extending the User model. This is my solution to the problem I posted here: http://gist.github.com/3885906 Thanks to Kindari on laravel IRC
<?php
class Student extends User {
public function reports() {
// I know I said the relationship here is one-to-one..!
// But I don't mind hacking this too much.
return $this->has_many('Report', 'student_id');
}
}
@andylolz
andylolz / Artisan patch
Created October 14, 2012 16:14
Make key:generate work with the --env switch
diff --git a/laravel/cli/tasks/key.php b/laravel/cli/tasks/key.php
index 0c08a84..b7b5d00 100644
--- a/laravel/cli/tasks/key.php
+++ b/laravel/cli/tasks/key.php
@@ -19,7 +19,14 @@ class Key extends Task {
*/
public function __construct()
{
- $this->path = path('app').'config/application'.EXT;
+ if($environment = get_cli_option('env'))
@andylolz
andylolz / gist:3885906
Created October 13, 2012 19:49
Laravel question

The problem

So this isn’t my actual scenario, but I think it illustrates my problem quite well. Imagine an online school report system. I have Teachers, Students, and Reports. Teachers and Students are both Users. The relationship between Students and Reports is one-to-one (a student just has a single report card), but between Teachers and Reports is one-to-many (a teacher has a whole classroom-worth of reports.) The Report model has both a student_id and a teacher_id, both of which are foreign keys to the User table.

I’d like to represent these relationships in my models, so for a given User I can call:

User::find(5)->reports;