View ca.lua
--- Create a rule function which calculates the next value of a single cell in
-- a cellular automaton
-- @param rule
-- Rule number.
-- @param neighbours
-- Number of neighbours in each direction which affect the next state of a
-- cell. With 0, a cell only affects itself. With 1, the two immediate
-- neighbours also affect the cell.
function wolfram_ca_rule_fn(rule, neighbours)
return function(get_cell_fn)
View debug-call.py
#! /usr/bin/env python3
import sys
def main():
args = sys.argv
for i, x in enumerate(args):
print('[{}] = {!r}'.format(i, x))
View method_lru_cache.py
from functools import lru_cache, wraps
from itertools import count
_method_lru_cache_sequence = count()
def method_lru_cache(*lru_args, **lru_kwargs):
"""
Like `functools.lru_cache` which can be used on methods of a class
View lock_file.py
from contextlib import contextmanager
import fcntl
@contextmanager
def lock_file(path):
with open(path, 'wb') as file:
fcntl.flock(file, fcntl.LOCK_EX)
View partition.py
def partition_items(items, num_top_items, key=lambda x: x):
if items and 0 < num_top_items < len(items):
pivot = items[0]
smaller = []
larger = []
for i in items[1:]:
if key(i) < key(pivot):
smaller.append(i)
View hashable.py
class Hashable:
def __eq__(self, other):
return type(self) is type(other) and self._hashable_key() == other._hashable_key()
def __hash__(self):
return hash(self._hashable_key())
def _hashable_key(self):
raise NotImplementedError()
View example.py
@contextlib.contextmanager
def temp_file_path(path):
"""
Context manager which returns slight variation of the specified path, which can be used to write a file to without clobbering an already existing file until the write is successful. The file at the returned path will either be moved onto the passed path (if the context is left normally) or deleted (if the context is left by throwing an exception).
"""
temp_path = path + '~'
dir_path = os.path.dirname(path)
if not os.path.exists(dir_path):
View retry.py
#! /usr/bin/env python3
import sys, os, argparse, subprocess, time
class UserError(Exception):
def __init__(self, msg, *args):
super().__init__(msg.format(*args))
View empty-1.scad
minkowski() {
cube();
intersection() {
cube();
translate([2, 2, 2]) {
cube();
}
}
View prowl.py
#! /usr/bin/env python3
import os, sys, argparse, subprocess, json, re, getpass, socket, requests
script_dir = os.path.dirname(os.path.realpath(__file__))
terminal_notifier = os.path.join(script_dir, 'terminal-notifier.app/Contents/MacOS/terminal-notifier')
def log(msg, *args):