Skip to content

Instantly share code, notes, and snippets.

Avatar

EBNull EBNull

View GitHub Profile
@EBNull
EBNull / formatmessagesystem.py
Last active Jun 2, 2020
FormatMessage() in python, for system messages.
View formatmessagesystem.py
__all__ = (
FormatMessageSystem,
LCID_ENGLISH,
LCID_NEUTRAL,
)
import ctypes
import ctypes.wintypes
LANG_NEUTRAL = 0x00
@EBNull
EBNull / relations.py
Created Aug 17, 2011
Returns all foreign key relations to a django model and their accessors
View relations.py
#Some utilities to work with django models and foreign keys.
#Especially useful for finding (and writing out) code to illuminate information about relations.
#
#To try it out, run show_relation_accessors(model) in a python prompt, or to be more general, get_related_instance_ids_code(model)
#
#-2011 CBWhiz
#
#
#Usage sample:
# from django.db import transaction
@EBNull
EBNull / getobject.py
Created Dec 5, 2012
"Missing" win32com utilities for getting object instances from DLLs or from run-time licenced servers
View getobject.py
__all__ = (
####### Class Objects
#CoGetClassObject - Normal, not wrapped
'CoDllGetClassObject', #Get ClassObject from a DLL file
####### ClassFactory::CreateInstance Wrappers
'CoCreateInstanceFromFactory', #Create an object via IClassFactory::CreateInstance
'CoCreateInstanceFromFactoryLicenced', #Create a licenced object via IClassFactory2::CreateInstanceLic
@EBNull
EBNull / screenon.py
Created Mar 27, 2013
Forces Windows to keep the display on (temporarily disables sleep mode while running). Netflix's silverlight app failed to do this for me :/
View screenon.py
import os
import sys
import ctypes
ES_AWAYMODE_REQUIRED = 0x00000040
ES_CONTINUOUS = 0x80000000
ES_DISPLAY_REQUIRED = 0x2 #Forces the display to be on by resetting the display idle timer.
ES_SYSTEM_REQUIRED = 0x1 #Forces the system to be in the working state by resetting the system idle timer.
@EBNull
EBNull / forcefocus.py
Created Dec 1, 2011
Force windows application focus (attempting to bypass SetForegroundWindow restrictions)
View forcefocus.py
import platform
#wnd is a HWND
def forceFocus(wnd):
if platform.system() != 'Windows':
return
SPI_GETFOREGROUNDLOCKTIMEOUT = 0x2000
SPI_SETFOREGROUNDLOCKTIMEOUT = 0x2001
SW_RESTORE = 9
View pipe.py
import subprocess
import signal
def pipeline(cmds, first_stdin=None, last_stdout=None):
"""Pipe together programs using subprocess"""
pcount = len(cmds)
plist = []
for i, cmd in enumerate(cmds):
stdin = None
stdout = None
@EBNull
EBNull / PyQt4.pth
Created Jul 17, 2013
Add PyQt4 to a virtualenv when it's installed on the system. Place PyQt4.pth into your local site-packages dir.
View PyQt4.pth
import sys; import os; _p = os.path.join(sys.real_prefix, 'lib', 'site-packages'); sys.path.append(_p); import sip; import PyQt4; sys.path.remove(_p)
@EBNull
EBNull / 4096_tc.py
Last active Dec 15, 2015
Testcase of Python issue 706263, with a workaround.
View 4096_tc.py
#This file is a testcase of http://bugs.python.org/issue706263 with a workaround.
#Z:\>python 4096_tc.py
#Z:\>cat result.txt
#stdin: 0 stdout: 1 stderr: 2
#Bytes printed: 199998
#Z:\>pythonw 4096_tc.py
#Z:\>cat result.txt
#stdin: -2 stdout: -2 stderr: -2
#Bytes printed before exception was raised: 4096
#Traceback (most recent call last):
@EBNull
EBNull / normaldictreader.py
Created Jan 14, 2013
Replacement for csv.reader that reads encoded input into a dict based on column definitions.
View normaldictreader.py
import csv
class StreamedDataConverter(object):
"""A conversion description that can convert one list of data into a processed dict using the cols attribute.
>>> class MyConverter(StreamedDataConverter):
... cols = ['a', 'b', 'c']
...
>>> c = MyConverter(iter([[4,5,6],[6,7,8]]))
>>> c.map_fieldnames(['a','b','c'])
@EBNull
EBNull / comfind.py
Created Dec 5, 2012
Given a directory, find files containing COM objects
View comfind.py
import os
import sys
import glob
import ctypes
import logging
log = logging.getLogger(__name__)
from collections import namedtuple
def path_iter(path, root=None, dirsortkey=None):
You can’t perform that action at this time.