Skip to content

Instantly share code, notes, and snippets.

def auto_version(endpoint, **values):
"""
Auto versions static assets.
"""
from flask import current_app as app
from flask import url_for
if app.debug:
return url_for(endpoint, **values)
# Check if accessing static file.
static_root = None
def _simple_processor(processor, ext_private, ext_public):
if not request.path.endswith(ext_public):
return
public_file = request.path[len(config.app.static_url_path) + 1:]
public_file_path = os.path.join(config.app.static_folder, public_file)
private_file_path = public_file_path[:-len(ext_public)] + ext_private
# File does not exist in app static - check blueprints.
if not os.path.isfile(private_file_path):
for blueprint_name, blueprint in config.app.blueprints.iteritems():
if request.path.startswith(blueprint.static_url_path):
@rahulkmr
rahulkmr / latency.txt
Created May 31, 2012 14:29 — forked from jboner/latency.txt
Latency numbers every programmer should know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 25 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 3,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns
Read 1 MB sequentially from memory 250,000 ns
Round trip within same datacenter 500,000 ns
Disk seek 10,000,000 ns
(defn fact-iter [product counter max-count]
(if (> counter max-count)
product
(recur (* counter product) (inc counter) max-count)))
(defn factorial [n]
(fact-iter 1 1 n))
#!/usr/bin/env python
from flask import Flask, request
app = Flask(__name__)
app.debug = True
fnids = {}
idx = 0
def store_fnid(fn):
global idx
± $ python streaming.py
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 438, in handle_one_response
self.run_application()
File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 425, in run_application
self.process_result()
File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 416, in process_result
self.write(data)
File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 368, in write
towrite.append("%x\r\n%s\r\n" % (len(data), data))
#!/usr/bin/env python
import gevent
from gevent.pywsgi import WSGIServer
from gevent import monkey
monkey.patch_all()
from flask import Flask, Response
app = Flask(__name__)
#!/usr/bin/env python
import gevent
from gevent.pywsgi import WSGIServer
from gevent import monkey
monkey.patch_all()
from flask import Flask, Response
app = Flask(__name__)
user root;
worker_processes 4;
# [ debug | info | notice | warn | error | crit ]
events {
worker_connections 1024;
}
http {
# remap prefix to C-a
unbind C-b
set -g prefix C-a
bind a send-prefix
# force a reload of the config files.
unbind r
bind r source-file ~/.tmux.conf
# Screen like bindings.