Skip to content

Instantly share code, notes, and snippets.

@tompaton
tompaton / trueskill.py
Created December 22, 2010 08:41
Version of true_skill() Python algorithm that handles draws.
#!/usr/bin/env python2.6
from __future__ import print_function
import sys
from scipy.stats.distributions import norm as scipy_norm
beta = 25/6
gamma = 25/300
epsilon = 0.08
@tompaton
tompaton / process-podcasts-Makefile
Last active August 26, 2017 10:33
Makefile to pre-process downloaded podcasts
# process podcasts
MP3S = $(filter-out $(wildcard *.64kbit.mp3),$(wildcard *.mp3))
PROCESSED = $(patsubst %.mp3,%.64kbit.mp3,$(MP3S))
.PHONY: process
process: videos $(PROCESSED)
@echo Done.
.PHONY: videos
@tompaton
tompaton / svn_diff_defs.py
Created September 20, 2011 07:06
Get SVN diff and summarise added/removed/changed function definitions
#!/bin/env python
"""get svn diff and compare added functions to removed functions,
command line args passed through to svn diff, e.g. use -r nnn:nnn to filter a specific revision."""
import sys, subprocess, re
from collections import defaultdict
svn_diff = subprocess.Popen(['svn', 'diff'] + sys.argv[1:], stdout=subprocess.PIPE).communicate()[0]
defn1 = "\W((?:def|class)\s+\w+)[:\(]" # python def and class
@tompaton
tompaton / kdtree.py
Created March 10, 2011 00:15
Python kd-tree spatial index and nearest neighbour search
#!/usr/bin/env python
# kd-tree index and nearest neighbour search
# includes doctests, run with: python -m doctest kdtree.py
class KDTree(object):
"""
kd-tree spatial index and nearest neighbour search
http://en.wikipedia.org/wiki/Kd-tree
"""
@tompaton
tompaton / apm_osd.py
Created May 2, 2011 02:11
Python script to add an OSD to a video based on ArduPilotMega log file
#!/usr/bin/env python
# add OSD from ArduPilotMega log file to a video
import sys
from path import path
from datetime import datetime, timedelta
from PIL import Image, ImageDraw
from math import sin, cos, radians
# STEP 1: use mplayer to extract jpgs and wav
@tompaton
tompaton / backup.py
Created September 10, 2011 14:31
Python backup script
#!/usr/bin/env python
"""
backup.py
Create an archive which will be suitable for rsyncing to a remote backup.
- will not copy data unnecessarily for common operations such as
renaming a file or reorganising the directory structure.
(assumes large files are generally going to be immutable, e.g. audio/video)
- doesn't try to do anything fancy with permissions etc.