Skip to content

Instantly share code, notes, and snippets.

View mcho421-snippets's full-sized avatar

mcho421-snippets

View GitHub Profile
@mcho421-snippets
mcho421-snippets / gist:4243437
Created December 9, 2012 05:12
Python: Flatten irregular list of lists
def flatten(l):
for el in l:
if isinstance(el, collections.Iterable) and not isinstance(el, basestring):
for sub in flatten(el):
yield sub
else:
yield el
@mcho421-snippets
mcho421-snippets / unittest_test.py
Created December 7, 2012 22:02
Python: Unit test example
import random
import unittest
class TestSequenceFunctions(unittest.TestCase):
def setUp(self):
self.seq = range(10)
def test_shuffle(self):
# make sure the shuffled sequence does not lose any elements
@mcho421-snippets
mcho421-snippets / gist:4027304
Created November 6, 2012 20:28
doc test example
def test():
"""
use -v flag to be more verbose
>>> test()
hello world
"""
print("hello world")
if __name__ == "__main__":
import doctest
@mcho421-snippets
mcho421-snippets / gist:3942838
Created October 24, 2012 00:10
Python: PyQt: Editable Tab Labels
# http://stackoverflow.com/questions/8707457/pyqt-editable-tab-labels
from PyQt4 import QtGui, QtCore
class TabBar(QtGui.QTabBar):
def __init__(self, parent):
QtGui.QTabBar.__init__(self, parent)
self._editor = QtGui.QLineEdit(self)
self._editor.setWindowFlags(QtCore.Qt.Popup)
self._editor.setFocusProxy(self)
self._editor.editingFinished.connect(self.handleEditingFinished)