Skip to content

Instantly share code, notes, and snippets.

View schlamar's full-sized avatar

Marc Schlaich schlamar

View GitHub Profile
@schlamar
schlamar / gist:5003484
Last active December 14, 2015 01:08
Asynchronous child IO with pyuv
import os
import re
import pyuv
LINESEP = os.linesep.encode()
PATTERN = re.compile(r'^(?P<file_name>([A-Za-z]:)?[^:]+):'
'(?P<line_number>\d+):((?P<position>\d+):)?'
'\s+((?P<code>\w{4,4})\s+)?(?P<reason>.*)$')
@schlamar
schlamar / gist:5003934
Last active December 14, 2015 01:09
Sublime Text 3 asynchronous linting with libuv event loop
.
@schlamar
schlamar / start_test.sh
Last active December 14, 2015 11:38
Test urllib3 and requests for HTTPS proxy CONNECT support (https://github.com/shazow/urllib3/pull/170).
curl -L -o requests.tar.gz https://github.com/schlamar/requests/archive/new-urllib3-api.tar.gz
tar -xzvf requests.tar.gz
curl -L -o test_proxy.py https://gist.github.com/schlamar/5080598/raw/test_proxy.py
python test_proxy.py
class VLCFileSystem(object):
_cur_path = None
_cur_dir = None
@classmethod
def listdir(cls, path):
url = 'http://127.0.0.1:8080/requests/browse.json?dir=%s' % path
resp = requests.get(url)
data = resp.json()['element']
@schlamar
schlamar / stpip.py
Last active December 15, 2015 17:59
Run pip within Sublime Text.
import sys
import os
def _packages_path():
t = os.path.join(os.path.dirname(__file__), '..')
return os.path.abspath(t)
SITE_PACKAGES = os.path.join(_packages_path(), 'Lib', 'site-packages')
_PACKAGING_MODS = os.path.join(_packages_path(), 'Lib', 'packaging')
@schlamar
schlamar / gist:5319691
Created April 5, 2013 14:28
Insertion sort.
from operator import lt
def insertion_sort(data, cmp_func=lt):
for i in xrange(1, len(data)):
if cmp_func(data[i], data[i - 1]):
el = data.pop(i)
j = i - 1
while j > 0 and cmp_func(el, data[j - 1]):
@schlamar
schlamar / gist:5458717
Last active December 16, 2015 15:49
Deap function composition as alternative to eval lamba expression in lambdify.
def _lookup(pos):
def composition(*args):
return args[pos]
return composition
def _apply(func, *funcs):
def composition(*args):
return func(*(f(*args) for f in funcs))
return composition
@schlamar
schlamar / gist:5965809
Last active December 19, 2015 13:59
Some helpers for PEP 3156 Futures.
def link(f, other):
'''Resolve other with the current Future.'''
def on_done(f):
e = f.exception()
if e:
other.set_exception(e)
else:
other.set_result(f.result())
@schlamar
schlamar / gist:5966805
Created July 10, 2013 14:33
tulip.coroutine vs. tulip.task
import timeit
import tulip
loop = tulip.get_event_loop()
def async_func(value):
p = tulip.Future()
@schlamar
schlamar / bench_torn.py
Created July 11, 2013 09:30
Tulip vs. Tornado benchmark.
import timeit
import tornloop
import tulip
loop = tornloop.TornadoLoop()
tulip.set_event_loop(loop)