Skip to content

Instantly share code, notes, and snippets.

@dhwthompson
dhwthompson / urinal.hs
Created February 22, 2015 12:44
Urinal protocol simulation
import Data.Function
import Data.List
import System.Environment
data Urinal = Free | Taken deriving (Show, Eq)
empty n = take n $ repeat Free
place urinals
| all (== Free) urinals = Taken : tail urinals
body {
background: #fff;
color: #000;
}
#pulls {
text-shadow: unset;
color: #000;
}
@dhwthompson
dhwthompson / friday12th.py
Last active December 16, 2015 03:49
A script to list upcoming Fridays 12th.
#!/usr/bin/env python
from datetime import date, timedelta
def fridays_12th():
d = date.today()
while True:
if d.weekday() == 4 and d.day == 12:
yield d
d += timedelta(days=1)
@dhwthompson
dhwthompson / gist:2224913
Created March 28, 2012 08:58
Mass update of Git user emails
for git_path in $(find `pwd` -name .git); do cd `dirname $git_path`; git config user.email user@example.com; done
@dhwthompson
dhwthompson / enable-flash-cookies.sh
Created October 24, 2011 21:32
Flash cookie enable script
#!/bin/bash
set -e
cd ~/Library/Preferences/Macromedia
chmod u+w .
echo "Hit Return to disable Flash cookies again..."
read
srm -sr 'Flash Player' .DS_Store 2>/dev/null
@dhwthompson
dhwthompson / sort-current-block.vim
Created May 21, 2011 15:22
A snippet of Vim code to sort the current contiguous line block: useful for Python imports
:?^$?+1,/^$/-1sort
def group_by(source, key_func):
acc = {}
for item in source:
acc.setdefault(key_func(item), []).append(item)
return acc
if __name__ == '__main__':
print group_by([(1, 2), (1, 3), (2, 3), (2, 4)], lambda x: x[0])
print group_by([(1, 2), (1, 3), (2, 3), (2, 4)], lambda x: x[1])