Skip to content

Instantly share code, notes, and snippets.

View bruntonspall's full-sized avatar

Michael Brunton-Spall bruntonspall

View GitHub Profile
@bruntonspall
bruntonspall / 01-keynote.md
Last active January 3, 2020 11:52
Pycon UK 2014

Keynote

It's successes

10 years ago, python was still an esoteric language - paul graham's python paradox, the best language to learn is one that you don't want to learn for a job, but for the enjoyment of it. Today python is one of the biggest langauges.

CTO magazine says Python is a solid enterprise choice.

Increasingly popular is various places, animation pipelines, etc.

@bruntonspall
bruntonspall / load_or_build.py
Created January 14, 2010 11:24
A simple memoize function that writes json out to a file, momoizing between python executions
import json
import functools
def load_or_build(filename):
def wraps(fun):
@functools.wraps(fun)
def wrapped(*args, **kwargs):
try:
f = file(filename)
return json.load(f)
@bruntonspall
bruntonspall / boxstarter.ps1
Last active March 8, 2019 19:32 — forked from jessfraz/boxstarter.ps1
Boxstarter Commands for a new Windows box.
# Description: Boxstarter Script
# Author: Jess Frazelle <jess@linux.com>
# Last Updated: 2017-09-11
#
# Install boxstarter:
# . { iwr -useb http://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force
#
# You might need to set: Set-ExecutionPolicy RemoteSigned
#
# Run this boxstarter by calling the following from an **elevated** command-prompt:
@bruntonspall
bruntonspall / gist:4038400
Created November 8, 2012 12:05
Get star ratings from the guardian content api
baseUrl="http://content.guardianapis.com/search?tag=tone%2Freviews&section=technology&format=json&show-fields=starRating"
pagef="&page=%d"
for i in range(200):
j = json.loads(''.join(urllib2.urlopen(baseUrl+pagef % (i+1)).readlines()))
reviews = [(item['id'],item['fields'].get('starRating')) for item in j['response']['results'] if item['fields'].get('starRating')]
for id,rating in reviews:
d[rating] = d.get(rating, []) + [id]
sorted([(k, len(v)) for k,v in d.items()])
@bruntonspall
bruntonspall / javaish.scala
Created September 1, 2011 19:21
Scala Samples
for(i <- 1 to 10) {
if (isSocketOpen) return
Thread.sleep(duration/10)
}
sys.error("Timed out")
@bruntonspall
bruntonspall / better.scala
Created April 12, 2011 10:10
This morning I turned ugly.scala into better.scala - still looking for a best.scala though
val optContacts = person.expand[BasicDBList]("contacts.pending")
for {
contacts <- optContacts;
contact <- contacts
if contact.isInstanceOf[DBObject]
pendingContact = contact.asInstanceOf[DBObject]
if pendingContact.expand[String]("contactId").get == contactId
} {
// Do stuff on contact and update mongo
}
@bruntonspall
bruntonspall / runtest.sh
Created January 20, 2011 15:43
How I run perf tests repeatably with records of what I did
#!/bin/bash
#Set Defaults
requests=${requests:=10}
threads=${threads:=1}
url=${url:=http://testserver/}
while getopts "r:t:u:h" Option
do
case $Option in
@bruntonspall
bruntonspall / gist:788063
Created January 20, 2011 15:39
Connecting your local master to an origin so git pull works
(gnm60091 test_runs/page…oser :+)% git branch --set-upstream master origin/master
Branch master set up to track remote branch master from origin.
(gnm60091 test_runs/page…oser :+)%
@bruntonspall
bruntonspall / gist:769421
Created January 7, 2011 12:54
Convert pip download cache into normal files
for fname in *;
do
mv $fname $(echo $fname | sed -e 's/%2F/\//g' -e 's/.*\///');
done
@bruntonspall
bruntonspall / tim.js
Created September 9, 2010 18:01 — forked from premasagar/tim.js
tim.js
/*
== Tim ==
A tiny JavaScript micro-templating script.
http://gist.github.com/521352
You can use Tim to write simple templates that use JavaScript's
familiar dot notation to replace template tags with JSON object
properties.