This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
logging.basicConfig(level=logging.INFO) | |
logger = logging.getLogger("log") | |
def simple(): | |
if logger.isEnabledFor(logging.DEBUG): | |
logger.debug('Stupid log message ' + ' '.join([str(i) for i in range(20)])) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IMPLEMENTATION | |
class LazyLogging(object): | |
""" | |
A utility class that wraps a method | |
""" | |
def __init__(self, function): | |
self.function = function | |
def __str__(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DEFINITION | |
# ========== | |
class PythonEnumWrapper(sa.Enum): | |
def __init__(self, cls): | |
""" | |
Initializes a new ``PythonEnumWrapper`` to be used as ``sqlalchemy.Enum`` | |
Args: | |
cls: a classic enumeration type | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wrapt | |
import functools | |
def for_all_methods(decorator): | |
""" | |
CLASS DECORATOR. | |
Based on http://stackoverflow.com/a/6307868/916568 | |
When applied to a class, will automatically decorate all public | |
methods (ones that don't start with an underscore) using the | |
given ``decorator``. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# Script was modified from: | |
# https://steveswinsburg.wordpress.com/2014/09/26/textwrangler-filters-to-tidy-xml-and-tidy-json/ | |
# Modified by Guy Arad, and can be found in: | |
# https://gist.github.com/guyarad/d80b9d5652a6616e1c3138b6a86310c4 | |
# | |
# Installation: | |
# Copy to "~/Library/Application Support/TextWrangler/Text Filters" | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SlotsPicklingMixin(object): | |
# otherwise, subclasses will still have `__dict__` | |
__slots__ = () | |
def __init__(self): | |
assert hasattr(self, '__slots__') | |
def __getstate__(self): | |
all_slots = itertools.chain.from_iterable( | |
getattr(t, '__slots__', ()) for t in type(self).__mro__) |
NewerOlder