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 / pyTypeConstrain.py
Last active October 8, 2015 00:10
Python Type Constraints (with Reserved Attributes)
class SchemaFailException(Exception):
def __init__(self, message, attr, valid_types):
Exception.__init__(self, message)
self.attr = attr
self.valid_types = valid_types
@jomido
jomido / fizzbuzz.py
Last active December 16, 2015 19:30
General Fizzbuzz II
def n_of_k(n, k):
return lambda n: n % k == 0
def n_for_ks(n, *ks):
return [n_of_k(n, k) for k in ks]
@jomido
jomido / fizzbuzz.py
Last active December 16, 2015 19:59
General Fizzbuzz III
def n_of_k(n, k):
return lambda n: n % k == 0
def n_for_ks(n, *ks):
return [n_of_k(n, k) for k in ks]
@jomido
jomido / keybase.md
Created January 20, 2015 19:49
keybase Github proof

Keybase proof

I hereby claim:

  • I am jomido on github.
  • I am jomido (https://keybase.io/jomido) on keybase.
  • I have a public key whose fingerprint is 4571 E8DE 72AC EC4A 0475 98FD F53B 06CC 331F 0CD3

To claim this, I am signing this object:

@jomido
jomido / main.py
Last active September 28, 2016 13:56
Twisted Sync & Async (@in_thread & @in_reactor)
import random
import time
from twisted.internet import task
from twisted.internet.defer import (
inlineCallbacks as inline,
returnValue,
DeferredList as when_all
)
@jomido
jomido / tiq.rfc.1.md
Last active October 12, 2017 19:46
TIQ.RFC.1: gcloud pipeline services take two

TIQ.RFC 1: gcloud pipeline services take two

backgrounder: ETL

An ETL service is comprised of this stuff:

  • IO - network calls
  • transformations - computations

The IO stuff has two variants:

@jomido
jomido / call_later.py
Last active January 2, 2021 05:50
An asyncio call_later that works with both sync and async functions...woot
import asyncio
def maybeAsync(callable, *args, **kwargs):
"""
Turn a callable into a coroutine if it isn't
"""
@jomido
jomido / inflate.py
Created November 3, 2016 15:28
Auto create classes from arbitrarily nested dicts, preserving list context
from collections import defaultdict
class AutoClass(object):
pass
def inflate(data, class_from_fields):
@jomido
jomido / what_is_a_class.md
Last active February 9, 2017 16:15
What is a Class?

What is a class?

A class is a type. A type of thing. There are lots of cars, but there are also lots of types of cars. A Porsche 911 is such a type. If you go out onto a road, you will see lots of cars, and you will be able to identify their types. But what you will definitely not see is the type or class itself. Just instances of that type.

A class or type is defined by its properties and abilities. Another way to think of a class is as a table schema in a database. The schema defines the columns via a name and a kind of data. That is, it defines the table's type, or its class. Individual rows inside the table are instances of the type.

In addition, types (or classes) of things seem to be arranged in a hierarchy. A Porsche 911 is a type of car that has instances in the real world. But a Porsche 911, while being a type, belongs to yet another type called "motor vehicle". There are people and birds and lamp posts on the street too, none of which are types of motor vehicles. "Motor vehicle" is a pare

@jomido
jomido / README.md
Last active March 2, 2017 03:27
Twisted Inter-protocol Communication

Inter-protocol Communication

Run it

Open three terminals, then (in order):

  • python server_b.py
  • python server_a.py
  • python client.py