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 random | |
def scramble(text): | |
"""Scrambles the letters in given text, except for first | |
and last one in every word. | |
""" | |
words = text.split() | |
for i in xrange(words): | |
if len(words[i]) < 3: | |
continue |
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
#:kivy 1.4.1 | |
<Ball>: | |
size: 25, 25 | |
canvas: | |
Color: | |
rgb: 1, 0, 1 | |
Ellipse: | |
pos: self.pos | |
size: self.size |
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 objectproperty(func): | |
"""Alternate version of the standard ``@property`` decorator, | |
useful for proeperties that expose setter (or deleter) in addition to getter. | |
It allows to contain all two/three functions and prevent PEP8 warnings | |
about redefinion of ``x`` when using ``@x.setter`` or ``@x.deleter``. | |
Usage:: |
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 L(object): | |
def __init__(self, iterable): | |
self.value = iterable | |
def map(self, fn): | |
self.value = map(fn, self.value) | |
return self | |
def join(self, s): | |
self.value = s.join(self.value) | |
return 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
import re | |
from flask import url_for | |
from myflaskapp import app | |
def url_for_ex(endpoint, **values): | |
"""Improved version of standard Flask's :func:`url_for` | |
that accepts an additional, optional ``_strict`` argument. | |
:param _strict: If ``False``, values for the endpoint are not checked |
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 inspect | |
def split(iterable, by): | |
"""Generalized split function that works on any iterable.""" | |
separator = by if inspect.isfunction(by) else lambda x: x == by | |
res = [] | |
curr = [] | |
for elem in iterable: | |
if separator(elem): |
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/env python | |
""" | |
Experiment with automatic generation of English plurals. | |
""" | |
import os | |
import random | |
def main(): | |
total_count = 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
import imp | |
import inspect | |
import sys | |
__all__ = [] | |
class PassthroughImporter(object): | |
"""Import hook that simulates the standard import flow |
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 functools | |
import inspect | |
import os | |
import warnings | |
class _DeprecatedDecorator(object): | |
MESSAGE = "%s is @deprecated" | |
def __call__(self, symbol): |
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/env python | |
""" | |
Decorator for fluent interface classes. | |
""" | |
import functools | |
import inspect | |
def chained(method): | |
"""Method decorator to allow chaining.""" |