Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
#!/usr/bin/env python | |
# simple command line application and utility library for building modular flask applications. | |
# Just drop me in your root, chmod +x ./testserver.py, and ./flaskr.py init | |
# then you can chmod +x ./testserver.py and ./testserver.py to run it. | |
# finally create new modules using ./flaskr new module-name and add | |
# the name to mods.py. | |
# v0.0.1 | |
def build_flask(config): | |
from flask import Flask |
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
Guess the output: | |
>>> def exec_code_object_and_return_x(codeobj, x): | |
... exec codeobj | |
... return x | |
... | |
>>> co1 = compile("""x = x + 1""", '<string>', 'exec') | |
>>> co2 = compile("""del x""", '<string>', 'exec') | |
>>> exec_code_object_and_return_x(co1, 1) | |
# What do you get here? |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
""" | |
A really stupid python template language inspired by coffeekup, markaby. | |
Do not use this code, it will ruin your day. A byproduct of insomnia. | |
TL;DR | |
----- | |
This module defines a template language that allows us to do: | |
d = Doc() |
Originally: | |
https://gist.github.com/7565976a89d5da1511ce | |
Hi Donald (and Martin), | |
Thanks for pinging me; it's nice to know Typesafe is keeping tabs on this, and I | |
appreciate the tone. This is a Yegge-long response, but given that you and | |
Martin are the two people best-situated to do anything about this, I'd rather | |
err on the side of giving you too much to think about. I realize I'm being very | |
critical of something in which you've invested a great deal (both financially |
#!/usr/bin/env bash | |
# Use this one-liner to produce a JSON literal from the Git log: | |
git log \ | |
--pretty=format:'{%n "commit": "%H",%n "author": "%aN <%aE>",%n "date": "%ad",%n "message": "%f"%n},' \ | |
$@ | \ | |
perl -pe 'BEGIN{print "["}; END{print "]\n"}' | \ | |
perl -pe 's/},]/}]/' |
#!/usr/bin/python | |
# Equivalent of "tail -f" as a webpage using websocket | |
# Usage: webtail.py PORT FILENAME | |
# Tested with tornado 2.1 | |
# Thanks to Thomas Pelletier for it's great introduction to tornado+websocket | |
# http://thomas.pelletier.im/2010/08/websocket-tornado-redis/ | |
import tornado.httpserver |
from subprocess import Popen, PIPE | |
import re | |
import glob | |
import shlex | |
class Pipeline(object): | |
def __init__(self, descriptor=None): | |
self.steps = [] | |
if descriptor: | |
for step in descriptor.split("|"): |
worldclock() { | |
ADDIS_ABABA=`TZ=Africa/Addis_Ababa date +"%c (%z %Z)"` | |
BERLIN=`TZ=Europe/Berlin date +"%c (%z %Z)"` | |
CHICAGO=`TZ=America/Chicago date +"%c (%z %Z)"` | |
HONK_KONG=`TZ=Asia/Hong_Kong date +"%c (%z %Z)"` | |
LONDON=`TZ=Europe/London date +"%c (%z %Z)"` | |
LOS_ANGELES=`TZ=America/Los_Angeles date +"%c (%z %Z)"` | |
MOSCOW=`TZ=Europe/Moscow date +"%c (%z %Z)"` | |
NEW_YORK=`TZ=America/New_York date +"%c (%z %Z)"` | |
SOFIA=`TZ=Europe/Sofia date +"%c (%z %Z)"` |