This file contains 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
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(): |
This file contains 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
if __name__ == "__main__": | |
import sys | |
import pstats | |
stats = pstats.Stats(sys.argv[1]) | |
stats.strip_dirs() | |
stats.sort_stats('cumulative') | |
stats.print_stats() |
This file contains 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
def call_only_once(func): | |
def new_func(*args, **kwargs): | |
if not new_func._called: | |
try: | |
return func(*args, **kwargs) | |
finally: | |
new_func._called = True | |
else: | |
# We already called the real func once, so let's pick a completely | |
# different one from the globals and call it instead |
This file contains 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 base(object): | |
def gen(self): | |
for ii in [1,2,3]: | |
yield ii | |
class child(base): | |
def gen(self): | |
for ii in [4,5,6]: | |
yield ii |
This file contains 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
""" | |
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 |
This file contains 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
export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking-mode | |
export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold-mode | |
export LESS_TERMCAP_me=$'\E[0m' # end (blinking/bold)-mode | |
export LESS_TERMCAP_so=$'\E[38;5;246m' # begin standout-mode - info box | |
export LESS_TERMCAP_se=$'\E[0m' # end standout-mode | |
export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline | |
export LESS_TERMCAP_ue=$'\E[0m' # end underline | |
# Copied from: http://www.quora.com/Unix/What-are-some-hacks-when-reading-man-pages/answer/Igor-Pozgaj?srid=5axS&st=ns |
This file contains 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
# See the following for a discussion I later found on stackoverflow, should | |
# have searched there first ;) | |
# http://stackoverflow.com/questions/1388818/how-can-i-compare-two-lists-in-python-and-return-matches | |
from timeit import timeit | |
# Different ways to implement a function that compares lists without | |
# taking into account their order | |
compare_lists_without_order = lambda x, y: sorted(x) == sorted(y) | |
compare_lists_without_order = lambda x, y: True if not len(set(x) - set(y)) else False |
This file contains 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
# YOU NEED TO INSERT YOUR APP KEY AND SECRET BELOW! | |
# Go to dropbox.com/developers/apps to create an app. | |
app_key = 'YOUR_APP_KEY' | |
app_secret = 'YOUR_APP_SECRET' | |
# access_type can be 'app_folder' or 'dropbox', depending on | |
# how you registered your app. | |
access_type = 'app_folder' |
This file contains 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/env python | |
import argparse | |
import inspect | |
import logging | |
import pydoc | |
import pkgutil | |
import sys | |
log = logging.getLogger("import_searcher") |
This file contains 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
""" | |
Script to see the memory usage of each individual PyQt4 module. | |
Meant to be run with the memory_profiler: | |
- http://pypi.python.org/pypi/memory_profiler | |
Usage: python -m memory_profiler qt_memory_usage.py | |
""" | |
@profile |