Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am stesh on github.
  • I am stesh (https://keybase.io/stesh) on keybase.
  • I have a public key ASDB0VqQYaP4igLHS3te3PuHl8rM26fyeyTxo0gq1VjG-Qo

To claim this, I am signing this object:

>>> from Queue import PriorityQueue
>>> l = [PriorityQueue()] * 10
>>> [hash(x) for x in l]
[-9223372036579180054, -9223372036579180054, -9223372036579180054, -9223372036579180054, -9223372036579180054, -9223372036579180054, -9223372036579180054, -9223372036579180054, -9223372036579180054, -9223372036579180054]
>>> l = [PriorityQueue() for _ in range(10)]
>>> [hash(x) for x in l]
[275597326, 275597335, 275597371, -9223372036579178388, 275597470, -9223372036579178289, 275597829, -9223372036579177930, 275597928, -9223372036579177831]
@stesh
stesh / gist:8928821
Created February 11, 2014 03:28
Instead of defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(float))))
#!/usr/bin/python
from collections import defaultdict
def nested_defaultdict(f, n):
if n == 1:
return defaultdict(f)
else:
return defaultdict(lambda: nested_defaultdict(f, n-1))
@stesh
stesh / gist:8796219
Created February 4, 2014 02:02
Overcoming library path silliness in SWI Prolog on OS X
#!/bin/sh
app="/Applications/SWI-Prolog.app"
export SWI_HOME_DIR="$app/Contents/swipl"
exec "$app/Contents/MacOS/$(basename $0)" $@
@stesh
stesh / gist:8698674
Created January 29, 2014 22:37
youtube2mp3
#!/bin/bash
[ -z "$1" -o -z "$2" ] && (
cat <<EOF >&2
Usage: $0 <YouTube URL> <filename>
EOF
exit 1
)
URL="$1"
<Perl>
use Apache2::ServerUtil;
my @sites = (
"netsoc.tcd.ie",
"issue.netsoc.tcd.ie",
"meta.netsoc.tcd.ie",
"cubewww.cube-external.netsoc.tcd.ie",
"meecro.netsoc.tcd.ie",
"phpmyadmin.netsoc.tcd.ie",
@stesh
stesh / gist:7833975
Created December 6, 2013 23:33
News
#!/usr/bin/python
from subprocess import call
open = lambda s: call(['open', 'http://%s' % s])
news = [
'bbc.co.uk',
'theguardian.co.uk',
'telegraph.co.uk',
@stesh
stesh / gist:7784529
Created December 4, 2013 09:06
Haderp
#!/bin/bash
export PATH=$PATH:/opt/hadoop/hadoop-0.20.2/bin/
HDFS_PATH="/user/s1317371"
if [ -e $1 ]; then
rm $1
fi
>>> detect_language(u'Buenas días')
'spanish'
>>> detect_language(u'Hello there')
'english'
>>> detect_language(u'Guten Tag')
'german'
@stesh
stesh / gist:6874191
Created October 7, 2013 20:15
Make a new tex document
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $0 <title>" > /dev/stderr
exit 1
fi
title="$1"
cat > "$title.tex" <<EOF