Skip to content

Instantly share code, notes, and snippets.

View schlamar's full-sized avatar

Marc Schlaich schlamar

View GitHub Profile
@schlamar
schlamar / processify.py
Last active April 17, 2024 19:19
processify
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 April 20, 2012 12:45
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
schlamar / gist:2652543
Created May 10, 2012 11:34
Find the root document of a given LaTeX file
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 June 20, 2012 07:56
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
# http://tools.ietf.org/html/rfc4345
@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 / !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
==========
@schlamar
schlamar / win32i18n.py
Last active October 13, 2015 03:08
I18N with Python on win32
#!/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
@schlamar
schlamar / gist:4149031
Created November 26, 2012 16:11
pygtk + pyglet
#!/usr/bin/python
import sys
import time
import math
import gtk
import gobject
import pyglet
import pyglet.gl 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
schlamar / gist:4345304
Created December 20, 2012 13:21
Safe pickle implementations
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