Skip to content

Instantly share code, notes, and snippets.

View schlamar's full-sized avatar

Marc Schlaich schlamar

View GitHub Profile
@schlamar
schlamar / conf.ini
Last active August 29, 2015 14:00
Click: override default options with config file(s)
[test]
count = 2
import functools
import os
import socket
import time
import pyuv
def on_connection(message, handle, loop):
@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 / gioloop.py
Last active November 30, 2017 09:55
Tornado IOLoop implementation with gobject/gtk.
import datetime
import functools
import logging
import os
import time
import gobject
import gtk
@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():
import ctypes
from ctypes import POINTER
from ctypes.wintypes import HANDLE, LPVOID, WORD, DWORD, BOOL
LPSTR = ctypes.c_char_p
LPBYTE = LPSTR
LPHANDLE = POINTER(HANDLE)
LPDWORD = POINTER(DWORD)
@schlamar
schlamar / gist:7024668
Created October 17, 2013 13:14
Handle Windows privileges from Python. Based on http://stackoverflow.com/a/2129589/851737
from __future__ import print_function
import ctypes
from ctypes import wintypes
GetCurrentProcess = ctypes.windll.kernel32.GetCurrentProcess
GetCurrentProcess.restype = wintypes.HANDLE
OpenProcessToken = ctypes.windll.advapi32.OpenProcessToken
OpenProcessToken.argtypes = (wintypes.HANDLE, wintypes.DWORD, ctypes.POINTER(wintypes.HANDLE))
OpenProcessToken.restype = wintypes.BOOL
@schlamar
schlamar / example.py
Last active February 13, 2022 18:15
mplog: Python advanced multiprocessing logging.
import logging
import multiprocessing
import time
import mplog
FORMAT = '%(asctime)s - %(processName)s - %(levelname)s - %(message)s'
logging.basicConfig(level=logging.DEBUG, format=FORMAT)
existing_logger = logging.getLogger('x')
@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 / 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