Skip to content

Instantly share code, notes, and snippets.

@lbolla
lbolla / pipeline_1.py
Created April 20, 2012 12:34
Python pipelines
'''Pipeline
(yield) -> receiver
.send -> producer
'''
import time
N = 0
# 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 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:
@lbolla
lbolla / mypy-checkers.py
Created March 8, 2019 15:59
Example for pycheckers bug report msherry/flycheck-pycheckers#33
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>.+)$')
@lbolla
lbolla / socket_timeout_0
Created January 10, 2019 20:13
cherrypy #1764
~/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
import time
import multiprocessing.queues
from Queue import Empty
import futures
q = multiprocessing.queues.Queue()
N = 10000
M = 4
timeout = 1
@lbolla
lbolla / haskell-.vimrc.vim
Created October 15, 2011 09:59
Haskell VIM files
" 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
from functools import partial
class Infix(object):
def __init__(self, func):
self.func = func
def __or__(self, other):
return self.func(other)
# 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
@lbolla
lbolla / par.py
Last active January 1, 2016 05:19
Python GIL and Cython
from threading import Thread
def busy_sleep(n):
while n > 0:
n -= 1
N = 99999999
t1 = Thread(target=busy_sleep, args=(N, ))