Skip to content

Instantly share code, notes, and snippets.

View djsutherland's full-sized avatar

Danica J. Sutherland djsutherland

View GitHub Profile
@djsutherland
djsutherland / ssh-tunnel.sh
Created January 1, 2010 00:33
A bash script for managing ssh tunnels for smtp (or whatever)
#!/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
@djsutherland
djsutherland / latex-clean.sh
Last active July 16, 2024 11:39
A bash script to clean latex temp files
#!/bin/bash
# Note: you might prefer latexmk -c since latexmk is great. It doesn't clean all of these, but see
# https://tex.stackexchange.com/questions/83341/clean-bbl-files-with-latexmk-c/83386#83386
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)$//')
@djsutherland
djsutherland / hg-to-git.sh
Created January 7, 2010 04:03
A script to set up an hg-to-git clone
#!/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"
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):
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):
@djsutherland
djsutherland / better_prop_download.py
Created July 2, 2010 20:05
download mp3s from betterpropaganda.com 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])
@djsutherland
djsutherland / keepalive.sh
Created August 4, 2010 22:58
trivial "keepalive" script for ssh tunnel
#!/bin/sh
while true; do
$*
sleep 30
done
@djsutherland
djsutherland / table-genders.py
Created September 22, 2010 03:23
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
@djsutherland
djsutherland / timediff.c
Created November 6, 2010 22:37
CS 33: one solution to the time-difference problem
#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;
@djsutherland
djsutherland / move_subs.py
Created March 15, 2011 09:19
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