This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
± $ 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from flask import Flask, request | |
app = Flask(__name__) | |
app.debug = True | |
fnids = {} | |
idx = 0 | |
def store_fnid(fn): | |
global idx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def show(*args): | |
for obj in args: | |
frame = sys._getframe(1) | |
for k, v in frame.f_locals.iteritems(): | |
if v is obj: | |
print "%s=%r" % (k, v) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'timeout' | |
module ForkTimeout | |
def self.timeout(sec) | |
if (pid = fork).nil? | |
yield | |
else | |
begin | |
Timeout::timeout(sec) { Process.waitpid(pid) } | |
rescue Timeout::Error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Copyright (c) Rich Hickey. All rights reserved. | |
; The use and distribution terms for this software are covered by the | |
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php) | |
; which can be found in the file CPL.TXT at the root of this distribution. | |
; By using this software in any fashion, you are agreeing to be bound by | |
; the terms of this license. | |
; You must not remove this notice, or any other, from this software. | |
;dimensions of square world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang web-server | |
(require web-server/servlet-env) | |
(define-syntax page | |
(syntax-rules () | |
[(page x ...) | |
(response/xexpr `(html (body ,x ...)))])) | |
(define (ask action kont-field msg) | |
(page |