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
'''Pipeline | |
(yield) -> receiver | |
.send -> producer | |
''' | |
import time | |
N = 0 |
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
# Run the server with: | |
# $> newrelic-admin run-python newrelic-tornado6.py --logging=debug | |
# Hit the server with: | |
# $> curl http://localhost:8888/ | |
# Note the error in the server logs | |
import tornado.httpclient | |
import tornado.ioloop | |
from tornado.options import parse_command_line |
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
""" | |
This is a simple example of WebSocket + Tornado + Redis Pub/Sub usage. | |
Do not forget to replace YOURSERVER by the correct value. | |
Keep in mind that you need the *very latest* version of your web browser. | |
You also need to add Jacob Kristhammar's websocket implementation to Tornado: | |
Grab it here: | |
http://gist.github.com/526746 | |
Or clone my fork of Tornado with websocket included: | |
http://github.com/pelletier/tornado | |
Oh and the Pub/Sub protocol is only available in Redis 2.0.0: |
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 re | |
line = 'filename.py:24: error: Dict entry 0 has incompatible type "str": "str"; expected "int": "str"' | |
output_matcher = re.compile( | |
r'(?P<filename>[^:]+):' | |
r'(?P<line_number>[^:]+):' | |
r'((?P<column_number>[^:]+):)?' # Column number is optional, depending on mypy options | |
r' (?P<level>[^:]+):' | |
r' (?P<description>.+)$') |
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
~/src/cherrypy-lbolla(master*) » hey -c 5 -n 1000 http://127.0.0.1:8888/ | |
Summary: | |
Total: 1.8755 secs | |
Slowest: 0.0195 secs | |
Fastest: 0.0013 secs | |
Average: 0.0093 secs | |
Requests/sec: 533.1808 | |
Total data: 144000 bytes |
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 time | |
import multiprocessing.queues | |
from Queue import Empty | |
import futures | |
q = multiprocessing.queues.Queue() | |
N = 10000 | |
M = 4 | |
timeout = 1 |
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
" Add to .vimrc | |
" Need to have .vim/compiler/ghc.vim | |
augroup HSK | |
au Bufenter *.hs compiler ghc | |
autocmd FileType haskell setlocal formatoptions+=t | |
autocmd FileType haskell let b:ghc_staticoptions = '-Wall -Werror' | |
augroup END |
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
from functools import partial | |
class Infix(object): | |
def __init__(self, func): | |
self.func = func | |
def __or__(self, other): | |
return self.func(other) |
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
# How to use PG Point type in SQAlchemy | |
# | |
# Most of the code comes from here: | |
# http://initd.org/psycopg/docs/advanced.html#adapting-new-types | |
import re | |
import sqlalchemy | |
import psycopg2 | |
from psycopg2.extensions import adapt, register_adapter, AsIs |
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
from threading import Thread | |
def busy_sleep(n): | |
while n > 0: | |
n -= 1 | |
N = 99999999 | |
t1 = Thread(target=busy_sleep, args=(N, )) |