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 / README.md
Last active July 6, 2017 20:29
Requests Google TaskQueue Insert (& auth via service file)

Do: pip install -r requirements.txt Do: python taskqueue.py

You will need a service file. Amend the location in the entry point in taskqueue.py.

@jomido
jomido / main.py
Last active December 27, 2017 16:11
asyncio pools (threaded and subprocessed)
import asyncio
import time
from pools import threads, processes
in_thread = threads(10)
in_process = processes(4)
def fib(n):
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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):