This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
class Table: | |
def __init__(self): | |
self.items = [] | |
self.indices = {} | |
@staticmethod | |
def _get_key(item, key): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is the embedded DSL | |
tasks! { | |
heap h; | |
task { | |
loop { | |
wait for AbsDiff(1, 2); | |
[3] = h[&1] - h[&2]; | |
if (h[&3] > 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "modelqc" | |
version = "0.1.0" | |
authors = ["Caleb Jones <code@calebjones.net>"] | |
[dependencies] | |
rand = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Sin functions | |
// | |
const S1: f64 = -0.166666666416265235595; /* -0x15555554cbac77.0p-55 */ | |
const S2: f64 = 0.0083333293858894631756; /* 0x111110896efbb2.0p-59 */ | |
const S3: f64 = -0.000198393348360966317347; /* -0x1a00f9e2cae774.0p-65 */ | |
const S4: f64 = 0.0000027183114939898219064; /* 0x16cd878c3b46a7.0p-71 */ | |
pub fn k_sinf(x: f64) -> f32 { | |
let z = x * x; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%default total | |
data Direction = L | R | |
record Machine state halt alphabet where | |
constructor MkMachine | |
initial : state | |
transition : state -> Maybe alphabet -> Maybe (Either halt state, Maybe alphabet, Direction) | |
data Tape : (a : Type) -> Type where |