Skip to content

Instantly share code, notes, and snippets.

View processify.py
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
schlamar / ssdp.py
Created Apr 20, 2012
Simple Python SSDP discovery
View ssdp.py
import socket
import struct
import sys
from httplib import HTTPResponse
from BaseHTTPServer import BaseHTTPRequestHandler
from StringIO import StringIO
import gtk
import gobject
@schlamar
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
schlamar / rc4.py
Created Jun 20, 2012
RC4 encryption
View rc4.py
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
# http://tools.ietf.org/html/rfc4345
@schlamar
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
schlamar / !Python serialization
Created Jul 18, 2012
Python serializer benchmark: json, simplejson, cPickle, messagepack, simpleubjson, marshal, literal_eval
View !Python serialization
System
======
Windows 7
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]
Small data
==========
@schlamar
schlamar / win32i18n.py
Last active Oct 13, 2015
I18N with Python on win32
View win32i18n.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
This is the modified module `libi18n.locale` from
https://www.mail-archive.com/python-list@python.org/msg188668.html.
It is fixed to distinguish internationalization and
localization. Reference: http://tinyurl.com/gnulocale
View gist:4149031
#!/usr/bin/python
import sys
import time
import math
import gtk
import gobject
import pyglet
import pyglet.gl as gl
View gevent_sendall.py
import sys
import gevent
from gevent.coros import RLock
from gevent.server import StreamServer
from gevent.socket import create_connection
lock = RLock()
@schlamar
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