Skip to content

Instantly share code, notes, and snippets.

SDK = /home/tom/src/android-sdk-linux_86
VERSION = 2.0
MANIFEST = AndroidManifest.xml
ANDROID_JAR = $(SDK)/platforms/android-$(VERSION)/android.jar
RESOURCE_FILE = res.res
CLASSPATH = $(ANDROID_JAR):.:/usr/share/java/scala-library.jar
AAPT = $(SDK)/platforms/android-$(VERSION)/tools/aapt
DEX = $(SDK)/platforms/android-$(VERSION)/tools/dx
APKBUILDER = $(SDK)/tools/apkbuilder
@teh
teh / enum_hack.py
Created July 28, 2011 17:44
Another enum hack
# inspired by https://bitbucket.org/tebeka/pythonwise/src/c68764fa3a8b/enum.py
def enum(name, members, bitmask=False):
'''
>>> Hi = enum('Hi', 'a b c')
>>> print Hi.a
1
>>> print Hi.c
3
>>> Hi2 = enum('Hi2', 'a b c', bitmask=True)
@teh
teh / shutdown_example.py
Created August 4, 2011 21:13
Proper shut down in-flight requests for eventlet's wsgi server
import daemon, lockfile, signal, logging
import eventlet
from eventlet import wsgi, timeout
worker_pool = eventlet.GreenPool(20)
sock = eventlet.listen(('', 8000))
def proper_shutdown():
worker_pool.resize(0)
@teh
teh / gist:1623516
Created January 16, 2012 23:11
uploader
import eventlet
from eventlet import wsgi
CHUNK_SIZE = 2**13 # 8k
def upload(env, start_response):
data = []
while True:
d = env['wsgi.input'].read(CHUNK_SIZE)
if len(d) < CHUNK_SIZE:
@teh
teh / gist:1795101
Created February 11, 2012 01:47
Silly solution to instagrams Tokyo stitching challenge
import numpy as np
from PIL import Image
# Hacky solution to the reassemble-Tokyo challenge:
# http://instagram-engineering.tumblr.com/
image = np.asarray(Image.open('/tmp/tokyo.png'))
# Auto-detect step size
guesses = np.arange(2, 200)
@teh
teh / miller_rabin.py
Created February 21, 2012 15:33
Miller Rabin primality test
import random
def is_probably_prime(n, num_iterations):
s = bin(n - 1)[::-1].index('1')
d = n // 2**s
for k in range(num_iterations):
a = random.randint(2, n - 2)
x = pow(a, d, n)
if x == 1 or x == n - 1:
@teh
teh / rsa.py
Created February 22, 2012 16:28
RSA in 3 lines
def rsa(m, key, n):
h = '{:x}'.format(pow(int(m.encode('hex'), 16), key, n))
return ('0'+h if len(h) % 2 else h).decode('hex')
import collections
import numpy as np
# customer -> product mapping
purchases = {
'A': (0, 1),
'B': (0, 2, 3),
'C': (0, 3),
'D': (1,),
'E': (0, 1, 3),
# http://en.wikipedia.org/wiki/Rijndael_S-box
sbox = [
0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
From d4e033f64f3d2dc93be7ba65875d370678287611 Mon Sep 17 00:00:00 2001
From: Thomas Hunger <tehunger@gmail.com>
Date: Fri, 16 Mar 2012 17:53:53 +0000
Subject: [PATCH] Enable ipv6
---
desir/desir.py | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/desir/desir.py b/desir/desir.py
index a4f9273..dbe4d0f 100644