- Live slides
- Use and arrow keys to step through
- Video of talk from Pycon 2013
- I had the pleasure of giving this talk at Pycon 2013 in a slightly shorter form.
- Presentation markdown source
- Links to repository with actual markdown source that is used for HTML5 slides
- Landslide
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
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: |
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
# Turn list of rows into columns | |
>>> x = [(1,2,3), (4,5,6)] | |
>>> zip(*x) | |
[(1, 4), (2, 5), (3, 6)] | |
# Reverse key-value mapping in a dict | |
>>> x = {'a': 1, 'b': 2} | |
>>> dict([reversed(kv) for kv in x.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
" Searches Dash for the word under your cursor in vim, using the keyword | |
" operator, based on file type. E.g. for JavaScript files, I have it | |
" configured to search j:term, which immediately brings up the JS doc | |
" for that keyword. Might need some customisation for your own keywords! | |
function! SearchDash() | |
" Some setup | |
let s:browser = "/usr/bin/open" | |
let s:wordUnderCursor = expand("<cword>") |
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 profile_this(fn): | |
def profiled_fn(*args, **kwargs): | |
fpath = fn.__name__ + '.profile' | |
prof = cProfile.Profile() | |
ret = prof.runcall(fn, *args, **kwargs) | |
prof.dump_stats(fpath) | |
return ret | |
return profiled_fn | |
@profile_this |
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
# 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 |
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
from PyQt4.QtCore import pyqtSignal, QObject | |
from PyQt4.QtGui import QApplication, QFrame, QGridLayout, QPushButton | |
class View(QFrame): | |
openStuff = pyqtSignal() | |
def __init__(self, parent=None): | |
super(View, self).__init__(parent) |
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 debug_signals(cls): | |
""" | |
Attach to all available signals in decoratored class and print debug | |
message each time one of the signals is emitted. | |
""" | |
from PyQt4 import QtCore | |
def stripArgsFromSignature(signature): | |
""" |
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 _parse_config_file(config_file): | |
""" | |
Parse given config file and return dict of settings | |
[load] | |
files=a,b,c | |
[process] | |
for x in xrange(10): | |
foo() |
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
# | |
# © 2011 Christopher Arndt, MIT License | |
# | |
# Taken from: http://wiki.python.org/moin/PythonDecoratorLibrary | |
import time | |
class cached_property(object): | |
'''Decorator for read-only properties evaluated only once within TTL period. |