Skip to content

Instantly share code, notes, and snippets.

EBNull EBNull

Block or report user

Report or block EBNull

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@EBNull
EBNull / globalinteract-withdjango.py
Created Feb 10, 2011
Version of Python's code.interact() that takes a `globals` argument
View globalinteract-withdjango.py
import code, sys
from code import softspace
class GlobalInteractiveConsole(code.InteractiveConsole):
"""Interactive console that also takes a globals argument"""
def __init__(self, locals=None, filename="<console>", globals=None):
try:
super(GlobalInteractiveConsole, self).__init__(locals=locals, filename=filename)
except TypeError:
code.InteractiveConsole.__init__(self, locals=locals, filename=filename)
if globals is None:
@EBNull
EBNull / install_winprint_hylafax_7.py
Created Mar 15, 2011
Install script for https://sourceforge.net/projects/wphfforwin7 . Installs files, port monitor, port, driver, and printer.
View install_winprint_hylafax_7.py
#Run this script to install system files, port monitor, port, driver, and printer
#You can change settings in the main() function
#
#(c) 2011 CBWhiz
import os
import sys
import ctypes
import subprocess
import codecs
import tempfile
@EBNull
EBNull / stickyrouter.py
Created Mar 25, 2011
Lets django find certain models on a certain database. Cross DB joins will still probably fail.
View stickyrouter.py
from django.conf import settings
#STICKY_DB_DEFAULT=None
#STICKY_DB_ALLOW_CROSS_DB_RELATIONS=False
#STICKY_DB_MODELS = {
# ('app', 'model'): 'dbalias',
# ('app', 'model'): 'dbalias',
# ('app', 'model'): 'dbalias',
#}
@EBNull
EBNull / AdminTemplateRedirector.py
Created Sep 27, 2011
Changes prefix for admin templates based on request path
View AdminTemplateRedirector.py
"""
Before loading an admin template, it first modifies the template name based on the current thread's request url.
It will also fall back to the standard template name if themodified one is not found.
This uses a threadlocal hack.
settings.py:
MIDDLEWARE_CLASSES = (
...,
'AdminTemplateRedirector.AdminTemplateRedirectorMiddleware',
...
@EBNull
EBNull / basicapp.py
Created Feb 16, 2012
Basis for a general PyQT app
View basicapp.py
import os
import sys
import ctypes
import traceback
import logging
log = logging.getLogger()
from QtBinding import QtCore, QtGui
def remove_window_context_help_button(qwindow):
@EBNull
EBNull / usergroups_win32.py
Created Feb 28, 2012
Get current user groups (win32)
View usergroups_win32.py
import ctypes
import win32net
def getUsername(name_format=8):
#Only NameUserSamCompatable supported if not on a domain.
#'' is returned in that case.
#NameUserSamCompatable = 2
#NameUserPrincipal = 8,
bufsz = ctypes.c_ulong()
ctypes.windll.secur32.GetUserNameExW(name_format, None, ctypes.byref(bufsz))
View django_revert_lookup_security.py
from django.contrib import admin
#Allow lookup by any kwargs in admin
#Reverts https://docs.djangoproject.com/en/1.2/releases/1.2.4/#restricted-filters-in-admin-interface
admin.ModelAdmin.lookup_allowed = lambda i, k, v: True
@EBNull
EBNull / qsettingswrap.py
Created Apr 4, 2012
Wrap a QSettings object with a more pythonic attribute based paradigm
View qsettingswrap.py
from PyQt4 import QtCore
from config import get_data_path
class SettingsWrapper(object):
"""Wrapper for QSettings using attribute access with conversion functions"""
_known_settings = {
#'setting': (conversionFuncRead, conversionFuncReadAttr, default),
}
def __init__(self, settings, subtree=None):
self._settings = settings
@EBNull
EBNull / clipboard.py
Created Sep 4, 2012
Copy / Retreive text to / from windows clipboard
View clipboard.py
def clipcopy(z):
#http://stackoverflow.com/questions/579687
z = unicode(z)
try:
import win32clipboard
except ImportError:
from Tkinter import Tk
r = Tk()
r.withdraw()
r.clipboard_clear()
@EBNull
EBNull / reversem2m.py
Created Sep 28, 2012
Django reverse M2M field (for admin, etc)
View reversem2m.py
#This class lets you add the 'other side' of a m2m to a django model.
#Why this is better than just using related_name:
# -Admin sees it as a real field, gives you the filter_horizontal widget if you ask
#
#Issues:
# -Probably breaks syncdb (table tries to be created twice)
#
#Non-issues:
# -Doesn't break south (custom introspection rule makes this field ignored)
You can’t perform that action at this time.