Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
mkdir -p a/b/c
touch {a,a/b,a/b/c}/__init__.py
cat >a/b/c/d.py<<EOF
class e(object):
pass
EOF
#!/usr/bin/env python
# vim: fileencoding=utf8:et:sta:ai:sw=4:ts=4:sts=4
import pprint
from shorty import App
from feather.wsgi import serve
app = App()
@teepark
teepark / btree.py
Created September 9, 2010 22:45
a pure-python B tree and B+ tree implementation
import bisect
import itertools
import operator
class _BNode(object):
__slots__ = ["tree", "contents", "children"]
def __init__(self, tree, contents=None, children=None):
self.tree = tree
#!/usr/bin/env python
'''greenhouse network loader
this script's only goal is to get a greenhouse-based server up and running and
IO bound.
'''
import optparse
import socket
#!/usr/bin/env zsh
VIM=$(/usr/bin/which vim) # vim executable
servers=`$VIM --serverlist` # servers: currently active vim servers
if [ "$(echo "$servers" | grep GVIM)" ]; then
servername=GVIM
server=GVIM
else
name=$(hostname)
@teepark
teepark / gist:776765
Created January 12, 2011 19:52
in javascript's anonymous functions this would be spelled 'var'
(lambda newname: operations_on_new_name(newname))(operation_on_old_name(oldname))
acl is_foo hdr(host) -i foo.mysite.com
acl is_bar hdr(host) -i bar.mysite.com
&c
redirect prefix https://foo.mysite.com if is_foo
redirect prefix https://bar.mysite.com if is_bar
&c
#!/usr/bin/env python
# vim: fileencoding=utf8:et:sta:ai:sw=4:ts=4:sts=4
from feather import wsgi
import greenhouse
import cgi
import logging
import tempfile
import urllib
@teepark
teepark / coroutine scheduler microbenchmarks
Created February 19, 2011 00:15
coroutine scheduler microbenchmarks
# corotest.io:
Base := Object clone do(
go := method(
counter atPut(0, counter at(0) + 1)
)
counter := list(0)
)
schedule := Date secondsToRun(
for (i, 1, 10000,
@teepark
teepark / webserver.io
Created February 19, 2011 01:26
a little http server (and hello world app) in io
HttpServer := Object clone do(
at := method(address,
server := self clone
address = address splitN(":", 1)
ip := address at(0)
port := if(address size > 1, address at(1) asNumber, 80);
if (ip at(0) > 57 or ip at(0) < 48,
ip = DNSResolver ipForHostName(ip)