Skip to content

Instantly share code, notes, and snippets.

@bazzargh
bazzargh / waffle.py
Created April 23, 2024 09:59
generate waffle puzzles
#!/usr/bin/env python3
import fileinput
import random
# words contains the 5 letter wordle solution list
with fileinput.input(files=("words")) as f:
words = [line.strip() for line in f]
@bazzargh
bazzargh / aocwatch.sh
Created December 15, 2023 13:14
for advent of code, run on save of .py or .txt data. Used as: tmux new -s aoc -n log aocwatch \; splitw -h
#!/bin/bash
echo Starting watch in $(pwd)
fswatch --event=Updated . | while read -r event; do
if [[ "$event" == *.py ]]; then
echo Setting script to ${event}. Data is ${data:-not set}
script=$event
elif [[ "$event" == *.txt ]]; then
echo Setting data to ${event}. Script is ${script:-not set}
data=$event;
@bazzargh
bazzargh / cmd-line-fu.sh
Last active November 9, 2023 21:31
insert prepared snippets when you press Esc-j, with fuzzy search
# insert prepared snippets when you press Esc-j, with fuzzy search
fu-complete() {
# the whole command line up to last pipe left of the cursor
local prefix=$(printf "%s" "${LBUFFER}"|sed -E 's/(.*[|] *).*/\1/')
# everything left of cursor after the last pipe, gets used as the fzf prompt
local suffix=$(printf "%s" "${LBUFFER}"|sed -E 's/.*[|] *//')
# Grab snippets from ~/.cmd-line-fu . The file can have optional one-line comments before
# commands, which appear in fzf inlined and are searchable, eg:
# # print first column
# awk '{print $1}'
@bazzargh
bazzargh / monotile.js
Last active September 13, 2023 15:33
recursively plot the h7/h8 substitution rule from the monotile paper p18
// this version lets the canvas take care of all the matrix operations.
let canvas = document.getElementById('canvas');
let ctx = canvas.getContext('2d');
let A60 = Math.PI/3;
let A90 = Math.PI/2;
let S3 = Math.sqrt(3);
let ANGLES = [0, -2*A60, -A60, 0, 2*A60, A60, 0];
// Centres of patches in H8 at each substitution level.
@bazzargh
bazzargh / sketch.html
Created February 26, 2023 02:17
code generating a sketch of mark twain. This should really be in codepen
<canvas id="image" width=374 height=480>
</canvas>
<canvas id="sketch" width=374 height=480>
</canvas>
@bazzargh
bazzargh / draw.html
Created December 30, 2022 14:29
rudimentary drawing program, that outputs bbc basic code to reproduce the image
<svg viewbox="0 0 255 255" id="svg_canvas" width="512" height="512" style="border: 1px solid black;">
</svg>
Click to add points.
<form id="form">
<input type="range" id="ppos__slider" min="0" max="0"><input type="text" id="ppos" enabled=false><label for="ppos">Point</label><br>
<input type="range" id="xpos__slider" min="0" max="255"><input type="text" id="xpos" enabled=false><label for="xpos">X</label><br>
<input type="range" id="ypos__slider" min="0" max="255"><input type="text" id="ypos" enabled=false><label for="ypos">Y</label><br>
<input type="range" id="cpos__slider" min="-32" max="32" value="0"><input type="text" id="cpos" enabled=false><label for="cpos">Curvature</label><br>
<input type="text" id="image" value=monalisa.jpg><label for="image">Image</label><br>
<input type="text" id="offsetx" value=0><label for="offsetx">X Offset</label><br>
#!/bin/bash -exuo pipefail
GIF=$1
ffmpeg -i "$GIF" -vf "scale=w=640:h=360:force_original_aspect_ratio=1,pad=640:360:(ow-iw)/2:(oh-ih)/2" -pix_fmt yuv420p "${GIF%.gif}.mp4"
@bazzargh
bazzargh / forth.bas
Created November 11, 2022 12:14
Forth rail bridge at night, bbc basic https://bbcmic.ro/
MODE2
VDU 23,3,16,32,0,0,0,0,0,0
GCOL32,0
FORX=0TO1280STEP RND(32)
Z=RND(500):MOVEX,440-Z:PLOT5,X,440+Z
NEXT
GCOL16,0
MOVE0,404
MOVE0,712:PLOT5,1080,460
FORZ=0TO6STEP0.2
@bazzargh
bazzargh / bisonator.sh
Last active November 4, 2022 12:09
Misinterpret date formats like General Bison
#!/bin/bash
a=$(( ${1:-$(date +%d)} % 100 ))
b=$(( ${2:-$(date +%m)} % 100 ))
c=$(( ${3:-$(date +%y)} % 100 ))
input=$(printf "%02d-%02d-%02d" "$a" "$b" "$c")
for fmt in "%d-%m-%y" "%d-%y-%m" "%y-%d-%m" "%y-%m-%d" "%m-%y-%d" "%m-%d-%y"; do
if [[ "$(date -j -f "$fmt" "$input" +%u 2>/dev/null || echo 0)" == "2" ]]; then
date -j -f "$fmt" "$input" +"%B %e, %Y? For me, it was Tuesday." 2>/dev/null
@bazzargh
bazzargh / signs.py
Created September 29, 2022 14:41
abstract interpreter following lecture 16 of http://web.mit.edu/afs/athena.mit.edu/course/16/16.399/www/
import ast
import math
import enum
# implement the abstract interpreter used in lecture 16 of http://web.mit.edu/16.399/www/
# abstraction of sets of machine integers by initialization and simple sign
class Value(enum.Enum):
BOT = 0
NEG = 1
ZERO = 2