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
from twisted.internet import reactor, defer, protocol, task | |
from twisted.internet.ssl import ClientContextFactory | |
from twisted.words.protocols import irc | |
class NoPingBotProtocol(irc.IRCClient): | |
def __init__(self, *args, **kwargs): | |
self.nickname = 'noping' | |
self.password = 'balloonatics' |
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
>>> A.mro() | |
[<class '__main__.A'>, <type 'object'>] | |
>>> B.mro() | |
[<class '__main__.B'>, <type 'object'>] | |
>>> set.mro() | |
[<type 'set'>, <type 'object'>] | |
>>> dict.mro() | |
[<type 'dict'>, <type 'object'>] | |
>>> class C(A, B): pass | |
... |
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
from itertools import chain, combinations | |
def powerset(iterable): | |
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)" | |
s = list(iterable) | |
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) | |
def remove_indices(s, indices): | |
ret, prev = '', 0 |
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
def collect_keys(d): | |
if not isinstance(d, dict): | |
return [] | |
level = d.keys() | |
for k, v in d.items(): | |
level.extend('%s.%s' % (k, c) for c in collect_keys(v)) | |
return level | |
def analyze(paths): |
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 csv | |
from parsley import makeGrammar | |
import sys | |
raw = r''' | |
squote = '\'' | |
escaped_squote = '\\' squote | |
float = <digit+ '.' digit*>:f -> float(f) | |
int = <digit+>:i -> int(i) | |
string = squote <(escaped_squote | ~squote anything)*>:s squote -> s |
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 re | |
from collections import namedtuple | |
ParseResult = namedtuple('ParseResult', 'captured remaining matched') | |
class Rule(object): | |
def __init__(self, value, bind=None): | |
self.value = value | |
self.bind = bind |
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
from __future__ import division | |
import random | |
from itertools import tee, izip_longest | |
from collections import defaultdict | |
class Occurrences(object): |
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
def merge(classes_list): | |
merged = [None] | |
while classes_list: | |
for classes in classes_list: | |
head = classes[0] | |
tails = [c[1:] for c in classes_list] | |
if not any(head in tail for tail in tails): | |
if head != merged[-1]: | |
merged.append(head) | |
for classes in classes_list: |
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
# setup.py | |
from setuptools import setup | |
setup(name='lxml', | |
version='3.2', | |
py_modules=['lxml']) | |
# lxml.py | |
print 'FOOLED YOU' |
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 lxml.etree | |
from zipfile import ZipFile | |
class DocX(object): | |
DOCPATH = 'word/document.xml' | |
def __init__(self, fn): | |
with ZipFile(fn).open(self.DOCPATH) as f: | |
self.doc = lxml.etree.parse(f) |