Skip to content

Instantly share code, notes, and snippets.

@sheenobu
sheenobu / flaskr.py
Created June 14, 2012 18:46
Flaskr - utility building modular flask applications. Prototype/v0.0.1
#!/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
@jboner
jboner / latency.txt
Last active May 19, 2025 16:12
Latency Numbers Every Programmer Should Know
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
@dcrosta
dcrosta / gist:2562350
Created April 30, 2012 20:17
A Python Mystery
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?
@hrldcpr
hrldcpr / tree.md
Last active January 6, 2025 22:43
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!

@jamescasbon
jamescasbon / template.py
Created December 11, 2011 16:37
Pure python templates using with statement
"""
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()
anonymous
anonymous / gist:1406238
Created November 29, 2011 20:09
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
@textarcana
textarcana / git-log2json.sh
Last active January 24, 2025 22:12
Convert Git logs to JSON. The first script (git-log2json.sh) is all you need, the other two files contain only optional bonus features 😀THIS GIST NOW HAS A FULL GIT REPO: https://github.com/context-driven-testing-toolkit/git-log2json
#!/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/},]/}]/'
@maximebf
maximebf / webtail.py
Created October 21, 2011 13:25
Web tail / tail -f as a webpage using websocket
#!/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
@fmoralesc
fmoralesc / pipelines.py
Created October 20, 2011 03:23
Shell Pipelines for Python
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("|"):
@miku
miku / worldclock.sh
Created October 18, 2011 08:22
Worldclock for bash.
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)"`