Skip to content

Instantly share code, notes, and snippets.

Avatar

Luke Lee durden

View GitHub Profile
@durden
durden / notes.md
Last active Oct 24, 2018
Script, Library, or Executable: You can have it all!
View notes.md
@durden
durden / logger_size.py
Created Nov 15, 2017
Get size in KB of your logging infrastructure
View logger_size.py
import sys
import logging
def get_logger_memory_footprint():
"""
Get tuple of (logger names, size in KB)
"""
loggers = logging.Logger.manager.loggerDict
@durden
durden / mock.py
Created Nov 14, 2017
Simple mocking in Python
View mock.py
import contextlib
@contextlib.contextmanager
def mock_attr(object_, orig_attr_name, mock_attr):
"""
Temporarily mock object attribute for testing
This is similiar to the unittest.patch.object in Python 3.3 just much
simpler for our limited needs and use in Python 2.7.
@durden
durden / getsizeof_recursive.py
Last active Dec 25, 2019
Get size of Python object recursively to handle size of containers within containers
View getsizeof_recursive.py
##### 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 / css_edits.diff
Created Jun 27, 2016
CSS edits for markdown rendering
View css_edits.diff
diff --git a/pskb_website/static/css/base.css b/pskb_website/static/css/base.css
index 519b677..30dfec1 100644
--- a/pskb_website/static/css/base.css
+++ b/pskb_website/static/css/base.css
@@ -588,7 +588,6 @@ a:hover.emphasize-dark {
}
#article pre, #article blockquote, #article form {
- margin-left: 21px;
word-wrap: break-word;
View decorators_as_classes.md

A common definition of a Python decorator is 'A function that takes a function and returns a function.' This is a straight-forward definition, however, it's a bit inaccurate. In practice, a Python decorator is actually more flexible than simply a function.

Callables

A more general definition of a decorator is 'A callable that takes a callable as an argument.' This is a subtle distinction, but it opens up a few new possibilities. This new definition now leads to another question.

@durden
durden / article.md
Last active Oct 26, 2015
Python versioning
View article.md

Python spelunking

Motivation

I recently spent a little time reviewing a Python bug report and determining if I was running with a fixed version of the Python interpreter. I think this is a useful exercise for someone who is overly curious and not a core developer of the language.

This post is a rundown of my thought process while trying to figure this out.

@durden
durden / mac_defaults.sh
Created Oct 29, 2014
Collection of OS X defaults
View mac_defaults.sh
# 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
You can’t perform that action at this time.