Skip to content

Instantly share code, notes, and snippets.

View schlamar's full-sized avatar

Marc Schlaich schlamar

View GitHub Profile
@schlamar
schlamar / example.py
Last active December 19, 2015 19:49
Tornado's IOStream on top of tulip's Transport/Protocol API.
import re
import tulip
import tulipiostream
loop = tulip.get_event_loop()
LENGTH_PATTERN = re.compile(b'Content-Length: (\d*)\\r\\n')
@schlamar
schlamar / gist:6317614
Created August 23, 2013 10:00
SQLAlchemy: count number of executed statements
import sys
from sqlalchemy import create_engine, event
from sqlalchemy.orm import sessionmaker
import model
if sys.version_info >= (2, 7):
import unittest as unittest2
@schlamar
schlamar / Tulip Log
Last active December 22, 2015 00:19
Tulip benchmark profiled
DEBUG:tulip:Using selector: SelectSelector
DEBUG:tulip:poll0.000 took 0.000 seconds
DEBUG:tulip:poll0.010 took 0.016 seconds
DEBUG:tulip:poll0.000 took 0.000 seconds
DEBUG:tulip:poll0.010 took 0.015 seconds
DEBUG:tulip:poll0.000 took 0.000 seconds
DEBUG:tulip:poll0.010 took 0.000 seconds
DEBUG:tulip:poll0.010 took 0.016 seconds
DEBUG:tulip:poll0.000 took 0.000 seconds
DEBUG:tulip:poll0.010 took 0.015 seconds
@schlamar
schlamar / gist:6713843
Created September 26, 2013 13:02
SQLAlchemy ordered collection.
from sqlalchemy import create_engine, event, Column, Integer
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql import func, select
Base = declarative_base()
class Job(Base):
__tablename__ = 'job'
@schlamar
schlamar / gist:7791242
Created December 4, 2013 17:01
Dropbox authentication with Python SDK,
import webbrowser
from dropbox import client
APP_KEY = ''
APP_SECRET = ''
def authorize():
@schlamar
schlamar / gist:8519530
Created January 20, 2014 13:03
WSAAccept with Python and ctypes
import errno
import multiprocessing
import socket
import time
import ctypes
from ctypes import windll
from ctypes import POINTER, WINFUNCTYPE, c_char_p, c_char, c_int, c_ushort
from ctypes.wintypes import DWORD, UINT, INT, ULONG
@schlamar
schlamar / gist:7921ec587dd58a72a6d6
Last active August 26, 2016 05:56
zmq + SetConsoleCtrlHandler
from ctypes import WINFUNCTYPE, windll
from ctypes.wintypes import BOOL, DWORD
import zmq
kernel32 = windll.LoadLibrary('kernel32')
PHANDLER_ROUTINE = WINFUNCTYPE(BOOL, DWORD)
SetConsoleCtrlHandler = kernel32.SetConsoleCtrlHandler
@schlamar
schlamar / gist:2993700
Last active September 23, 2016 20:55
urllib2 HTTPS connection with proxy and cert verification
import httplib
import urllib2
import ssl
import certifi
from backports.ssl_match_hostname import match_hostname
class CertValidatingHTTPSConnection(httplib.HTTPConnection):
default_port = httplib.HTTPS_PORT
@schlamar
schlamar / remconsole.py
Created April 11, 2013 13:31
Fork of `rfoo.utils.rconsole` to run with other RPC implementations.
"""
remconsole.py
A Python console you can embed in a program and attach to remotely.
To spawn a Python console in a script do the following in any scope
of any module:
import remconsole
remconsole.spawn_server()
@schlamar
schlamar / !Python serialization
Created July 18, 2012 05:32
Python serializer benchmark: json, simplejson, cPickle, messagepack, simpleubjson, marshal, literal_eval
System
======
Windows 7
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]
Small data
==========