Skip to content

Instantly share code, notes, and snippets.


PL cowbert

View GitHub Profile
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)
cowbert /
Last active Apr 2, 2019
RFC 4122 Version 1 UUID with CSPRNG-based node ID and clock sequence
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`
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
cowbert /
Last active Feb 17, 2020
class decorators with staticmethod
from tornado.web import RequestHandler
class BaseHandler(RequestHandler):
def prepare(self):
self.current_user = None
def _render_401(self):
if self._req_was_rest:
from uuid import UUID as py_UUID
from sqlalchemy.dialects.postgresql import BYTEA as pg_BYTEA
from import RAW as ora_RAW
from sqlalchemy.types import TypeDecorator, BINARY
class sqla_type_UUID(TypeDecorator):
impl = BINARY
def __init__(self):
cowbert /
Created Aug 23, 2018
tornado virtual url path patching
# import tornado bits
import tornado.ioloop
import tornado.web
# Import some controllers
from controllers import RequestHandler1, RequestHandler2, RequestHandler3
# original routes
routes = [
(r'/path1', RequestHandler1),
cowbert /
Last active Jan 9, 2018
Inherit an argument-accepting method decorator pattern
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):
You can’t perform that action at this time.