Skip to content

Instantly share code, notes, and snippets.

Dougal J. Sutherland dougalsutherland

View GitHub Profile
@dougalsutherland
dougalsutherland / ssh-tunnel.sh
Created Jan 1, 2010
A bash script for managing ssh tunnels for smtp (or whatever)
View ssh-tunnel.sh
#!/bin/bash
SOCKS_PORT=''
LOCAL_PORT='5525'
SSH_HOST='sccs.swarthmore.edu'
TARGET_HOST='smtp.swarthmore.edu'
TARGET_PORT='25'
while getopts 'D:p:s:h:P:' OPTION
do
@dougalsutherland
dougalsutherland / latex-clean.sh
Last active Dec 24, 2018
A bash script to clean latex temp files
View latex-clean.sh
#!/bin/bash
exts=".aux .lof .log .lot .fls .out .toc .dvi .bbl .bcf .blg -blx.aux -blx.bib -blx.bib .run.xml .fdb_latexmk .synctex.gz .syntex.gz(busy) .pdfsync .algorithms .alg .loa .thm .nav .snm .vrb .acn .acr .glg .glo .gls .brf .lol .idx .ilg .ind .ist .maf .mtc .mtc0 .pyg .nlo .tdo .xdy .keys"
for x in "${@:-.}"; do
arg=$(echo ${x:-.} | perl -pe 's/\.(tex|pdf)$//')
if [[ -d "$arg" ]]; then
for ext in $exts; do
rm -f "$arg"/*$ext
@dougalsutherland
dougalsutherland / hg-to-git.sh
Created Jan 7, 2010
A script to set up an hg-to-git clone
View hg-to-git.sh
#!/bin/sh
# hg-to-git
# sets up a clone of a remote mercurial repository to a git repo
# relies on the wonderful tools from http://repo.or.cz/w/fast-export.git
PROJ_NAME=$1
HG_REMOTE=$2
GIT_REMOTE=$3
echo "---- making the project in $PROJ_NAME"
View gist:430959
from django.core.management.base import NoArgsCommand, CommandError
from django.conf import settings
import datetime
import sys, os, os.path
DUMP_DIRECTORY = os.path.expanduser("~/db-backups/")
DUMP_PATTERN = "gazjango_%Y-%m-%d_%H-%M.sql.bz2"
class Command(NoArgsCommand):
def handle_noargs(self, **options):
View gist:430962
from django.core.management.base import NoArgsCommand
from gazjango.misc.management.commands.backup_db import DUMP_DIRECTORY, DUMP_PATTERN
import os, re
DUMP_MATCHER = re.compile(r"^%s$" % re.sub(r'\\%[a-zA-Z]',
r'.+',
re.escape(DUMP_PATTERN)))
NUM_TO_SAVE = 8
class Command(NoArgsCommand):
@dougalsutherland
dougalsutherland / better_prop_download.py
Created Jul 2, 2010
download mp3s from betterpropaganda.com in bulk
View better_prop_download.py
#!/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
dougalsutherland / keepalive.sh
Created Aug 4, 2010
trivial "keepalive" script for ssh tunnel
View keepalive.sh
#!/bin/sh
while true; do
$*
sleep 30
done
@dougalsutherland
dougalsutherland / table-genders.py
Created Sep 22, 2010
table genders problem from stat 61
View table-genders.py
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
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
dougalsutherland / move_subs.py
Created Mar 15, 2011
Shift all the times in SRT subtitles by a constant amount
View move_subs.py
#!/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
You can’t perform that action at this time.