Skip to content

Instantly share code, notes, and snippets.

View chadrik's full-sized avatar

Chad Dombrova chadrik

  • Luma Pictures
  • Santa Monica, CA
View GitHub Profile
@chadrik
chadrik / abstract_types_for_immutability1.py
Last active February 25, 2022 05:30
Practical Guide to Python Static Typing
from functools import lru_cache
@lru_cache(None)
def getvalue() -> List[Set[int]]:
return [{1, 2}, {3}]
x = getvalue()
x.append({4})
y = getvalue()
@chadrik
chadrik / beam_custom_window.py
Last active June 2, 2019 04:11
Custom beam WindowFn
from __future__ import absolute_import, print_function
import logging
import datetime
from google.protobuf import duration_pb2
from apache_beam.coders import coders
from apache_beam.portability import common_urns
from apache_beam.portability.api import standard_window_fns_pb2
"""
Demo of a bunch of asyncio + gevent scenarios using aiogevent.
These are not tests in the sense that there are no assertions, but pytest
is a nice way to run them in bulk or choose a specific "test"
Run like this:
python3 -m pytest test_coexist.py -s -v
from __future__ import absolute_import, print_function
from typing import Generic
# MRO code adapted from https://gist.github.com/pendulm/2271366
def head(l):
return l[0]
def tail(l):
@chadrik
chadrik / sqlalchemy_after_flush_issue.py
Last active August 29, 2015 14:05
sqlalchemy_after_flush_issue.py
import sqlalchemy
from sqlalchemy import event
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine, Table, Column, Integer, String, ForeignKey
from sqlalchemy.orm import sessionmaker, scoped_session, relationship, backref
import datetime
Base = declarative_base()
engine = create_engine('sqlite://', echo=False)
Session = scoped_session(sessionmaker(bind=engine))
@chadrik
chadrik / sqlalchemy_after_flush.py
Last active August 29, 2015 14:05
exploring usage of after_flush
import sqlalchemy
from sqlalchemy import event
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine, Table, Column, Integer, String, ForeignKey
from sqlalchemy.orm import sessionmaker, scoped_session, relationship, backref
import datetime
Base = declarative_base()
engine = create_engine('sqlite://', echo=False)
Session = scoped_session(sessionmaker(bind=engine))
@chadrik
chadrik / sqlbooks.py
Last active August 29, 2015 14:04
demo of non-deterministic event ordering
import sqlalchemy
from sqlalchemy import event
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine, Table, Column, Integer, String, ForeignKey
from sqlalchemy.orm import sessionmaker, scoped_session, relationship, backref
import datetime
Base = declarative_base()
@chadrik
chadrik / foo.py
Created August 1, 2013 16:37
testing gist gem
print "top foo"
f = open("/Volumes/newhome/chad/python/multiproc.py", 'r')
exec f