Skip to content

Instantly share code, notes, and snippets.

@justinfay
justinfay / minilang.py
Created June 18, 2019 11:40
Mini language for simple operations
import operator
from functools import partialmethod
class Forward:
def resolve(self, env):
raise NotImplementedError()
def op(self, op, rhs):
@justinfay
justinfay / ws.py
Created May 31, 2019 14:20
An example of using pubsub with websockets
"""
A websocket example.
We want to be able to subscribe and unsbscribe to streams.
"""
import asyncio
import collections
import json
import logging
#!/usr/bin/env bash
# “a” and “arga” have optional arguments with default values.
# “b” and “argb” have no arguments, acting as sort of a flag.
# “c” and “argc” have required arguments.
# set an initial value for the flag
ARG_B=0
# read the options
My favourite eponymous laws
Zawinski's law: Every program attempts to expand until it can read mail. Those programs which cannot expand are replaced by ones which can.
Tobler's first law of geography: "Everything is related to everything else, but near things are more related than distant things." Coined by Waldo R. Tobler (b. 1930).
Roemer's law: A hospital bed built is a bed filled.
Rothbard's law: Everyone specializes in his own area of weakness.
@justinfay
justinfay / grph.py
Last active November 23, 2018 16:02
A simple graph query using generators
def id_generator():
i = 0
def _generator():
while True:
nonlocal i
yield i
i += 1
return _generator()
@justinfay
justinfay / count_min_sketch.ipynb
Created October 3, 2018 14:38
Count-Min sketch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from functools import partial, wraps
pipetypes = {}
def pipetype(func):
pipetypes[func.__name__] = func
@wraps(func)
def wrapper(*args, **kwargs):
select prosrc from pg_trigger,pg_proc where
pg_proc.oid=pg_trigger.tgfoid
and pg_trigger.tgname = '<name>'
@justinfay
justinfay / getout
Created July 11, 2018 08:14
get output of running process
strace -p1234 -s9999 -e write
# -p pid -s size
strace -p1234 -s9999 -o log.txt
@justinfay
justinfay / gist:5b5a760ed567d8668c43e5fd1247622b
Created March 12, 2018 10:12
My favourite eponymous laws
My favourite eponymous laws
Zawinski's law: Every program attempts to expand until it can read mail. Those programs which cannot expand are replaced by ones which can.
Tobler's first law of geography: "Everything is related to everything else, but near things are more related than distant things." Coined by Waldo R. Tobler (b. 1930).
Roemer's law: A hospital bed built is a bed filled.
Rothbard's law: Everyone specializes in his own area of weakness.