Skip to content

Instantly share code, notes, and snippets.

View porglezomp's full-sized avatar
💖
GITHUB DROP ICE

Cassie Jones porglezomp

💖
GITHUB DROP ICE
View GitHub Profile
@porglezomp
porglezomp / bfmemo.py
Last active August 25, 2017 05:44
BF Trees
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)
@porglezomp
porglezomp / bytecode
Last active October 24, 2017 16:07
python 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))
@porglezomp
porglezomp / table.py
Created November 2, 2017 05:54
Python DB-Table Ish Thing
from collections import defaultdict
class Table:
def __init__(self):
self.items = []
self.indices = {}
@staticmethod
def _get_key(item, key):
@porglezomp
porglezomp / 01-tasks
Last active December 9, 2017 06:23
the great and terrible macro DSL
// this is the embedded DSL
tasks! {
heap h;
task {
loop {
wait for AbsDiff(1, 2);
[3] = h[&1] - h[&2];
if (h[&3] > 0) {
@porglezomp
porglezomp / audio2jpeg.sh
Last active December 19, 2017 22:40
All Star but it's been transcoded through a 0% quality JPEG
#!/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"
@porglezomp
porglezomp / Cargo.toml
Created April 5, 2018 17:37
Quickcheck Exploration
[package]
name = "modelqc"
version = "0.1.0"
authors = ["Caleb Jones <code@calebjones.net>"]
[dependencies]
rand = "*"
@porglezomp
porglezomp / AllTicTacToe.idr
Last active May 10, 2018 21:13
Every possible game of Tic Tac Toe! This was a bit hard to prove total…
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
@porglezomp
porglezomp / cfg.py
Created January 4, 2018 01:31
Disassembly Control Flow Graph
# 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):
@porglezomp
porglezomp / errorulp.rs
Created July 19, 2018 00:05
Sin/Cos error ULPs
//
// 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;
@porglezomp
porglezomp / Turing.idr
Last active August 14, 2018 19:05
A constructive proof that Idris is Turing complete.
%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