Skip to content

Instantly share code, notes, and snippets.

@wting
wting / prime.py
Created April 24, 2012 05:07
misc. prime number related functions
#!/usr/bin/env python
import pudb
import random
# infinite prime number generator
def gen_prime():
tbl = dict()
i = 2
while True:
@wting
wting / tree.md
Created April 25, 2012 23:36 — forked from hrldcpr/tree.md
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@wting
wting / gist:2495828
Created April 26, 2012 04:29
codejam: alien language
#!/usr/bin/env python2
import re
_, lines, cases = map(int,raw_input().split())
words = []
for _ in xrange(lines):
words.append(raw_input())
for c in xrange(cases):
@wting
wting / uri.js
Created May 7, 2012 19:31 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
import XMonad
main = xmonad defaultConfig
{ modMask = mod4Mask -- Use Super instead of Alt
, terminal = "urxvt"
-- more changes
}
@wting
wting / .jhbuildrc
Created May 14, 2012 22:39
JHBuild - Epiphany
# -*- mode: python -*-
# -*- coding: utf-8 -*-
# edit this file to match your settings and copy it to ~/.jhbuildrc
# if you have a GNOME git account, uncomment this line
# repos['git.gnome.org'] = 'ssh://[email protected]/git/'
# what module set should be used. The default can be found in
# jhbuild/defaults.jhbuildrc, but can be any file in the modulesets directory
@wting
wting / dreamhost_python_setup.sh
Created May 31, 2012 00:16
Dreamhost Python Setup script
#!/usr/bin/env bash
# Written by William Ting for the following blog post:
# http://williamting.com/posts/2012/04/18/set-up-python-and-django-on-dreamhost/
rcfile="${HOME}/.bashrc"
version="2.7.3"
setuptools_version="2.7"
tmp_dir="${HOME}/tmp-${RANDOM}"
if [[ ${#} == 0 ]]; then
@wting
wting / tail_call_optimization.py
Last active October 1, 2016 02:38
Tail call optimization decorator, from https://code.activestate.com/recipes/474088/
#!/usr/bin/env python2
# This program shows off a python decorator(
# which implements tail call optimization. It
# does this by throwing an exception if it is
# it's own grandparent, and catching such
# exceptions to recall the stack.
import sys
class TailRecurseException:
@wting
wting / .gitignore
Last active December 10, 2015 17:08
autojump-git PKGBUILD
*.tar.xz
pkg/
src/
@wting
wting / gfm.rb
Created January 9, 2013 00:11 — forked from mojombo/gfm.rb
require 'digest/md5'
def gfm(text)
# Extract pre blocks
extractions = {}
text.gsub!(%r{<pre>.*?</pre>}m) do |match|
md5 = Digest::MD5.hexdigest(match)
extractions[md5] = match
"{gfm-extraction-#{md5}}"
end