Skip to content

Instantly share code, notes, and snippets.

@hwayne
hwayne / rainbow-sort.js
Created December 4, 2023 17:54
Rainbow sort
// put in https://editor.p5js.org/
// generated (mostly) with GPT4
let cols, rows;
let w = 2;
let colors = [];
let i = 0;
let j = 0;
let sorted = false;
@hwayne
hwayne / petrinet.pi
Created October 2, 2023 20:44
Petri net solver in Picat
import planner.
lookup(Val, Arr1, Arr2) = Out =>
nth(I, Arr1, Val),
nth(I, Arr2, Out).
main =>
Machine = [{{load1, 1}, {proc1, 0}, {done1, 0}, {load2, 1}, {proc2, 0}, {done2, 0}, {lock, 1}},
[ {load1,
{{load1, 1}, {lock, 1}}, % Maybe the inner ones should be lists, they're only iterated over
@hwayne
hwayne / sumfinder.pi
Created October 1, 2023 21:05
Sum finder
import planner.
main =>
S0 = {22, 0, [6, 6, 9, 5, 9, 1, 10, 9, 9, 3]},
plan(S0, Plan),
nl,
writeln(Plan),
nl.
final({Target, Current, _}) =>
@hwayne
hwayne / distlock.cfg
Created August 15, 2023 20:29
Demonstration of bug in distributed lock
CONSTANTS
Threads = {t1, t2, t3}
NULL = NULL
SPECIFICATION Spec
PROPERTY NoRaces
@hwayne
hwayne / etl.als
Created June 26, 2023 20:38
Simple ETL pipeline in Alloy
// ETL pipeline
sig DataSource {}
sig Step {
requires: set Step
}
sig Database, File extends DataSource {}
sig Extract in Step {
@hwayne
hwayne / gpt.lua
Created April 25, 2023 01:54
Lua code for running GPT from Neovim
-- Put this in after/plugins
local api = vim.api
local function chunk(text)
local sections = {}
for line in vim.gsplit(text, "@@@") do
if line:find("^s") then
table.insert(sections, {role = "system", content = line:sub(3)})
@hwayne
hwayne / Intro.md
Last active August 24, 2024 10:42
Securedrop TLA+ specification review

People who take my TLA+ Class get a free specification review. Cory Myers asked for a review of his Reply.tla spec, reproduced from the PR below, and has graciously agreed to let me make it public. The review itself is here.

Note this is a "light" review: I'm looking for general TLA+ antipatterns and techniques that don't require me to deeply understand the problem domain. This represents about an hour of review.

@hwayne
hwayne / script.py
Created March 13, 2023 19:59
Script that notifies me when a cubs game is happening
# This is running on an aws lambda instance with a CloudWatch trigger:
# Trigger is cron(0 17 * * ? *)
# CSV is from https://www.mlb.com/cubs/schedule/downloadable-schedule
import json
from urllib.request import urlopen, Request
from urllib.parse import urlencode
from os import getenv
from csv import DictReader
from datetime import datetime
@hwayne
hwayne / circuit.als
Created February 6, 2023 21:53
Simple example of alloy synthesis
enum Val {On, Off}
sig P {} //"Permutation"
abstract sig Input {
val: Val one -> P
}
sig Source extends Input {}
abstract sig Gate extends Input {
@hwayne
hwayne / Readme.md
Created January 17, 2023 18:14
Tab Provenance

I forget I added it to the firefox store so hopefully you're smarter than I am srry

Also you'll need a "border-48.png" icon which is in the manifest file