Skip to content

Instantly share code, notes, and snippets.

Dougal J. Sutherland dougalsutherland

Block or report user

Report or block dougalsutherland

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:430962
from import NoArgsCommand
import os, re
DUMP_MATCHER = re.compile(r"^%s$" % re.sub(r'\\%[a-zA-Z]',
class Command(NoArgsCommand):
dougalsutherland /
Created Jul 2, 2010
download mp3s from in bulk
#!/usr/bin/env python
import lxml.html
import urllib
import Queue
import re
import sys
import threading
doc = lxml.html.parse(sys.argv[1])
dougalsutherland /
Created Aug 4, 2010
trivial "keepalive" script for ssh tunnel
while true; do
sleep 30
dougalsutherland /
Created Sep 22, 2010
table genders problem from stat 61
from __future__ import division
import random
from collections import defaultdict
def find_pmf(fun, iters=100000):
counts = defaultdict(int)
for i in range(iters):
counts[fun()] += 1
dougalsutherland / timediff.c
Created Nov 6, 2010
CS 33: one solution to the time-difference problem
View timediff.c
#include <stdio.h>
#include <stdlib.h>
// Prompts the user for two times (in hh:mm format) and outputs
// the difference between them, assuming they're on the same day.
// No error checking.
int main() {
int hours1, minutes1, hours2, minutes2;
int hourDiff, minuteDiff;
dougalsutherland /
Created Mar 15, 2011
Shift all the times in SRT subtitles by a constant amount
#!/usr/bin/env python
# A little script to move the times in SRT subtitle files to
# align properly with your video.
import datetime
import re
time_re = re.compile(r'(\d\d):(\d\d):(\d\d),(\d\d\d)')
def next(i): # for python 2.5
dougalsutherland /
Created Mar 18, 2011
silly secretary problem simulation for probability seminar
#!/usr/bin/env python
# Grinstead + Snell, exercise 3.1.24
from __future__ import division
from random import shuffle
from itertools import islice
def sequence(n):
x = range(1, n+1)
dougalsutherland /
Created Mar 22, 2011
Print out a color code based on the current battery level of a mac laptop
# get the relevant numbers
tmp=`mktemp -t battery`
ioreg -rc AppleSmartBattery | egrep '(MaxCapacity|CurrentCapacity)' > $tmp
max=`grep Max $tmp | egrep -o '[[:digit:]]+'`
curr=`grep Current $tmp | egrep -o '[[:digit:]]+'`
rm -f $tmp
View testing_drd_log_mac
==43388== drd, a thread error detector
==43388== Copyright (C) 2006-2011, and GNU GPL'd, by Bart Van Assche.
==43388== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==43388== Command: ./testing
==43388== Parent PID: 74761
==43388== Thread 2:
==43388== Conflicting load by thread 2 at 0x0004b518 size 8
==43388== at 0x3B837: void boost::call_once<void (*)()>(boost::once_flag&, void (*)()) (in /usr/local/boost/boost_1_48_0/stage/lib/libboost_thread-mt-d.dylib)
==43388== by 0x2BCD4: boost::detail::set_current_thread_data(boost::detail::thread_data_base*) (in /usr/local/boost/boost_1_48_0/stage/lib/libboost_thread-mt-d.dylib)
View simpletest.cpp
#include <boost/thread.hpp>
void doNothing() { return; }
void doWork() {
boost::thread t1(doNothing);
#ifdef NO_MEX
You can’t perform that action at this time.