Skip to content

Instantly share code, notes, and snippets.

View joedougherty's full-sized avatar

Joe Dougherty joedougherty

View GitHub Profile
from z3 import *
"""
Generate a 3x3 magic square.
Imagine it like so:
-------------
| a | b | c |
-------------
@joedougherty
joedougherty / timeblocks.py
Created April 5, 2019 02:47
find free time where you can
from datetime import date, datetime, time
class Block:
"""
Base class to represent a block of time.
Instantiation can be like:
# Use datetime objects directly
@joedougherty
joedougherty / autopool.py
Last active September 9, 2019 15:07
shell out...in parallel
from multiprocessing import Pool
import subprocess
import sys
def run(args):
cmd, echo = args
process = subprocess.Popen(
cmd,
@joedougherty
joedougherty / FunctionChain.py
Last active April 4, 2020 17:03
A small to class to chain together multiple single-argument functions.
class FunctionChain:
"""
Chains together two or more functions together
and returns final result when called.
functions:
* must be named
* must take *exactly one* required argument
* ought to have explict return statements
( in this example I use "TOS" to mean "Top of Stack" )
( Here is a one-line word, `f`, that computes the nth fibonacci number. )
: f 0 1 rot 1 ?DO swap over + LOOP swap . ;
10 f . ( compute the 10th fibonacci number. )
( `.` pops the computed fibonacci number off the stack and prints it. )
( the stack is empty once again. )
def f(nth):
stack = [0, 1]
for _ in range(nth):
stack = [stack[1], stack[0]] # swap
stack.append(stack[0]) # over
stack[1] = stack[1] + stack[2] # +
stack.pop()
return stack[1]