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 countAllList(lst): | |
# define the list of accumulators: | |
counts = [0]*10 | |
# counts == [0,0,0...0] length of 10 | |
# iterate over lst to process each string at a time | |
for s in lst: | |
# lets turn the string into a list of letters | |
s_list = list(s) |
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
""" | |
We patch uuid.uuid1() to take a random `node` (used to be the 48 bit MAC | |
address) according to RFC 4122 section 4.5 and CSPRNG 14 bit `clockseq` | |
See: https://docs.python.org/2/library/uuid.html#uuid.uuid1 | |
and https://svn.python.org/projects/python/branches/release27-maint/Lib/uuid.py | |
and https://tools.ietf.org/html/rfc4122#section-4.5 | |
The primary use-case for a UUID like this is to guarantee a virtually | |
collision-free monotonically-increasing value (based on the clock) such | |
that it can replace an object like an 'autoincrementing' integer primary |
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 tornado.web import RequestHandler | |
class BaseHandler(RequestHandler): | |
def prepare(self): | |
self.current_user = None | |
def _render_401(self): | |
if self._req_was_rest: | |
self.set_status(401) |
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 uuid import UUID as py_UUID | |
from sqlalchemy.dialects.postgresql import BYTEA as pg_BYTEA | |
from sqlalchemy.dialects.oracle import RAW as ora_RAW | |
from sqlalchemy.types import TypeDecorator, BINARY | |
class sqla_type_UUID(TypeDecorator): | |
impl = BINARY | |
def __init__(self): |
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
# import tornado bits | |
import tornado.ioloop | |
import tornado.web | |
# Import some controllers | |
from controllers import RequestHandler1, RequestHandler2, RequestHandler3 | |
# original routes | |
routes = [ | |
(r'/path1', RequestHandler1), |
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
""" | |
I want to enforce coupling between a decorator that takes params and the method | |
it should apply to (invoking the decorator outside of the class would make no | |
semantic sense) | |
""" | |
class Foo(object): | |
attr = ['a','b','c'] | |
def __init__(self, *args, **kwargs): | |
for i, arg in enumerate(args): |