Skip to content

Instantly share code, notes, and snippets.

View durden's full-sized avatar

Luke Lee durden

View GitHub Profile
@durden
durden / pyqtsignal_decorator_connection.py
Created April 4, 2013 13:31
Example of using pyqtSignal.connect as a decorator for slot connection
# Example modified from:
# http://pysnippet.blogspot.com/2010/06/qsignalmapper-at-your-service.html
#
# Example showing how QSignalMapper can be used to manage an arbitrary
# numbers of parameterless signals and re-emit them with an argument
# identifying the sender.
#
# Each signal is associated in the QSignalMapper with either an int,
# QString, QObject or a QWidget which is passed as argument to the slot
@durden
durden / sanitize.py
Last active April 26, 2023 11:13
Different ways to 'sanitize' a list of strings to ensure they don't contain any of the contents of another 'ignored' list
"""
Demonstration of ways to implement this API:
sanitize(unsanitized_input, ignored_words)
Related discussions:
- Modifying a list while looping over it:
- http://stackoverflow.com/questions/1207406/remove-items-from-a-list-while-iterating-in-python
- Remove all occurences of a value in a list:
- http://stackoverflow.com/questions/1157106/remove-all-occurences-of-a-value-from-a-python-list
@durden
durden / fuzzy_float_dict.py
Created December 7, 2012 21:09
Compare dicts with fuzzy float comparison
def fuzzyDictEqual(d1, d2, precision):
"""
Compare two dicts recursively (just as standard '==' except floating point
values are compared within given precision.
"""
if len(d1) != len(d2):
return False
for k, v in d1.iteritems():
@durden
durden / getsizeof_recursive.py
Last active February 13, 2023 13:59
Get size of Python object recursively to handle size of containers within containers
##### Taken from https://github.com/bosswissam/pysize
import sys
def get_size(obj, seen=None):
"""Recursively finds size of objects"""
size = sys.getsizeof(obj)
if seen is None:
seen = set()
@durden
durden / callable.py
Created June 16, 2011 02:22
Clever way to use Python __call__ and __getattr__ to create web APIs that can map directly (dynamically) to actual API
class MyCallable(object):
def __init__(self, urlparts, callable):
self.urlparts = urlparts
self.callable = callable
def __call__(self, **kwargs):
print kwargs
print self.urlparts
def __getattr__(self, name):
# Return a callable object of this same type so that you can just keep
# chaining together calls and just adding that missing attribute to the
@durden
durden / signal_disconnect.py
Last active May 24, 2022 07:22
Context manager to temporarily disconnect a pyqt signal
from contextlib import contextmanager
@contextmanager
def slot_disconnected(signal, slot):
"""
Create context to perform operations with given slot disconnected from
given signal and automatically connected afterwards.
usage:
@durden
durden / notes.md
Last active July 14, 2021 07:28
Script, Library, or Executable: You can have it all!
@durden
durden / msg_ids.txt
Last active July 13, 2021 01:09
pylint message ids
C0102: Black listed name "%s"
C0103: Invalid %s name "%s"
C0111: Missing %s docstring
C0112: Empty %s docstring
C0121: Missing required attribute "%s"
C0202: Class method %s should have cls as first argument
C0203: Metaclass method %s should have mcs as first argument
C0204: Metaclass class method %s should have %s as first argument
C0301: Line too long (%s/%s)
C0302: Too many lines in module (%s)
@durden
durden / mac_defaults.sh
Created October 29, 2014 21:07
Collection of OS X defaults
# Taken from
# https://github.com/MatthewMueller/dots/blob/master/os/osx/defaults.sh
echo "Expanding the save panel by default"
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true
echo "Enabling full keyboard access for all controls (e.g. enable Tab in modal dialogs)"
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
@durden
durden / dynamic_imports.py
Last active October 1, 2020 23:42
Diff removing dynamic imports from pyqtgraph/__init__.py
# This is a raw listing of the imports that take place dynamically by calling
# the pyqtgraph/__init__.py:importAll() in the following scenarios:
#importAll('graphicsItems', globals(), locals())
#importAll('widgets', globals(), locals(), excludes=['MatplotlibWidget', 'RemoteGraphicsView'])
from .graphicsItems.ArrowItem import ArrowItem
from .graphicsItems.GraphicsWidgetAnchor import GraphicsWidgetAnchor
from .graphicsItems.GraphicsWidgetAnchor import Point
from .graphicsItems.GraphicsWidgetAnchor import QtCore