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)
#! /usr/bin/env python3
import sys
def main():
args = sys.argv
for i, x in enumerate(args):
print('[{}] = {!r}'.format(i, x))
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
from contextlib import contextmanager
import fcntl
def lock_file(path):
with open(path, 'wb') as file:
fcntl.flock(file, fcntl.LOCK_EX)
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):
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()
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):
#! /usr/bin/env python3
import sys, os, argparse, subprocess, time
class UserError(Exception):
def __init__(self, msg, *args):
View empty-1.scad
minkowski() {
intersection() {
translate([2, 2, 2]) {
#! /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, '')
def log(msg, *args):