View AllTicTacToe.idr
import Data.Vect
%default total
||| A player in the Tic Tac Toe game
data Move = X | O
implementation Eq Move where
X == X = True
O == O = True
View Leftpad.idr
import Data.Vect
-- `minus` is saturating subtraction, so this works like we want it to
eq_max : (n, k : Nat) -> maximum k n = plus (n `minus` k) k
eq_max n Z = rewrite minusZeroRight n in rewrite plusZeroRightNeutral n in Refl
eq_max Z (S _) = Refl
eq_max (S n) (S k) = rewrite sym $ plusSuccRightSucc (n `minus` k) k in rewrite eq_max n k in Refl
-- The type here says "the result is" padded to (maximum k n), and is padding plus the original
leftPad : (x : a) -> (n : Nat) -> (xs : Vect k a)
View Cargo.toml
[package]
name = "modelqc"
version = "0.1.0"
authors = ["Caleb Jones <code@calebjones.net>"]
[dependencies]
rand = "*"
View cfg.py
# usage:
# otool -tv program | python3 graph.py | dot -Tsvg -o program.svg; open program.svg
# (objdump will need a slightly different parser)
import sys
def split(items, before=None, after=None):
result = []
for item in items:
if before and before(item):
View audio2jpeg.sh
#!/bin/sh
set -ex
ffmpeg -y -i "$1" -f u8 -ac 1 all-star.pcm
size=`wc -c all-star.pcm | tr -s ' ' | cut -d' ' -f2`
size=`python3 -c "M = $size//3; N=int(M**0.5); print(f'{N}x{M//N}')"`
convert -size "$size" -depth 8 rgb:all-star.pcm -quality 0% "$2"
View 01-tasks
// this is the embedded DSL
tasks! {
heap h;
task {
loop {
wait for AbsDiff(1, 2);
[3] = h[&1] - h[&2];
if (h[&3] > 0) {
View codl-pep.rst

PEP: 9999 Title: Add Lab to colorsys Author: C Jones <code@calebjones.net>

codl

Status: Draft Type: Standards Track Content-Type: text/x-rst Created: 28-Nov-2017 Python-Version: 3.7 Post-History: 30-Aug-2002

View table.py
from collections import defaultdict
class Table:
def __init__(self):
self.items = []
self.indices = {}
@staticmethod
def _get_key(item, key):
View bytecode
def fib(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
return a
Then, using dis.dis(fib)
CPython bytecode:
2 0 LOAD_CONST 3 ((0, 1))
View bfmemo.py
import itertools
import time
COUNTS_SUMMING = {0: [[]]}
def counts_summing(n):
if n not in COUNTS_SUMMING:
sums = []
for first in range(1, n+1):
for rest in counts_summing(n - first):
sums.append([first] + rest)