Skip to content

Instantly share code, notes, and snippets.

import os
import sys
import traceback
from functools import wraps
from multiprocessing import Process, Queue
def processify(func):
'''Decorator to run a function as a process.
Be sure that every argument and the return value
schlamar /
Created Apr 20, 2012
Simple Python SSDP discovery
import socket
import struct
import sys
from httplib import HTTPResponse
from BaseHTTPServer import BaseHTTPRequestHandler
from StringIO import StringIO
import gtk
import gobject
schlamar / gist:2652543
Created May 10, 2012
Find the root document of a given LaTeX file
View gist:2652543
import glob
import os
import re
MAIN_PATTERN = re.compile(r'\\begin{document}')
def is_main(tex_file):
with open(tex_file) as fobj:
for line in fobj:
schlamar /
Created Jun 20, 2012
RC4 encryption
from hashlib import sha1
from itertools import islice, imap
from operator import xor, eq
DROP_N = 1536
# drop 1536 bytes is adviced in RFC 4345
schlamar / gist:2993700
Last active Sep 23, 2016
urllib2 HTTPS connection with proxy and cert verification
View gist:2993700
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 / !Python serialization
Created Jul 18, 2012
Python serializer benchmark: json, simplejson, cPickle, messagepack, simpleubjson, marshal, literal_eval
View !Python serialization
Windows 7
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]
Small data
schlamar /
Last active Oct 13, 2015
I18N with Python on win32
#!/usr/bin/env python
# -*- coding: utf-8 -*-
This is the modified module `libi18n.locale` from
It is fixed to distinguish internationalization and
localization. Reference:
View gist:4149031
import sys
import time
import math
import gtk
import gobject
import pyglet
import as gl
import sys
import gevent
from gevent.coros import RLock
from gevent.server import StreamServer
from gevent.socket import create_connection
lock = RLock()
schlamar / gist:4345304
Created Dec 20, 2012
Safe pickle implementations
View gist:4345304
In [1]: %paste
import hmac
import hashlib
import cPickle
import cStringIO
key = '\xa7\x9ePS\xf5\x84\xce\xc8\xad\xcdfEb\x94\x10K\x9b\x12\xed'
dig_size = hashlib.sha1().digest_size