Skip to content

Instantly share code, notes, and snippets.

View jomido's full-sized avatar
🎯
Focusing

Jonathan Dobson jomido

🎯
Focusing
View GitHub Profile
@jomido
jomido / Dockerfile.template
Last active June 6, 2017 13:06
local docker dev off any image (like python:3.6-alpine)
FROM ${image_name}
WORKDIR /app
@jomido
jomido / main.py
Last active March 9, 2017 19:51
Asynchronous Equivalencies
# NOTE: won't run, just an example
# in all cases, we're trying to get to "# hooray"
# asynchronous via Twisted's callbacks
from wherever import bar, baz
def foo():
@jomido
jomido / example.py
Last active March 14, 2017 14:47
Async By Default
import asyncio
import aiohttp
import time
from utils import start, auto
class Context(object):
@jomido
jomido / counter.py
Created March 15, 2017 19:39
Asyncio Sync Counter
import asyncio
class Counter(object):
def __init__(self, max=500, duration=100, loop=None):
self.max = max
self.duration = duration
self.loop = loop or asyncio.get_event_loop()
@jomido
jomido / get_filenames.py
Last active April 3, 2017 21:03
Recursive, max depth file walk, with filtering
always = lambda f: True
def get_filenames(root_path, max_depth=1, predicate=None):
predicate = predicate or always
path = os.path.normpath(root_path)
filenames = []
@jomido
jomido / auth.py
Created May 23, 2017 21:53
asyncio gcloud auth (Python 3.6)
"""
Google Cloud auth via service account file
"""
# stdlib
import datetime
import time
import typing
# 3rd party
@jomido
jomido / taskqueue.py
Created May 23, 2017 21:56
asyncio gcloud TaskQueue (Python 3.6)
"""
An asynchronous queue for Google Appengine Task Queues
For `auth` and `http_tools` imports, see:
https://gist.github.com/jomido/93940858a803327197314ceae8b31462
"""
import asyncio
import base64
@jomido
jomido / main.py
Created May 25, 2017 14:22
memoize decorator
from functools32 import lru_cache
from functools import partial
memoize = partial(lru_cache, maxsize=128)
@memoize()
def function_to_memoize(arg1, arg2, kwarg1=None):
pass
@jomido
jomido / partials.md
Last active October 12, 2017 19:39
Partial Application & Predicates (https://docs.python.org/3.6/howto/functional.html)

partial application

what

Partial application lets you lock in one or more arguments to a function. It gives you a new function that only takes the remaining, as-yet-to-be-specified arguments. If arguments are applied against a function, then partial application allows you to apply only some of them - that is, you can partially apply them. Later on, you can finish out the argument application.

One can also read the Python docs.

from functools import partial
@jomido
jomido / validation.py
Created June 1, 2017 16:10
Beginnings of a validation lib
from functools import partial as part
# some utils
def partial(func, *args, **kwargs):
# replace partial