Skip to content

Instantly share code, notes, and snippets.

View Alwinfy's full-sized avatar

Alwinfy Alwinfy

  • United States
View GitHub Profile
(def prgn
[2 4
1 2
7 5
0 3
1 7
4 1
5 5
3 0])
@Alwinfy
Alwinfy / aoc2024_day11.ts
Last active December 12, 2024 20:00
well well well if it isnt the coroutines wacko
function biLen(value: bigint, base: bigint): number {
let acc = 1;
while (value >= base) {
acc++;
value /= base;
}
return acc;
}
function pow(base: bigint, pow: number): bigint {
@Alwinfy
Alwinfy / aoc2024_day3.clj
Last active December 3, 2024 06:53
yet another parser problem
(set! *warn-on-reflection* true)
(defn chp [okay?]
(fn [munch]
(when-let [[h & more] munch]
(and (okay? h) [h more]))))
(defn seqp [& parsers]
(fn [munch]
(loop [parsers parsers munch munch acc []]
def ziprec(parms, vals):
if isinstance(parms, list):
for p, v in zip(parms, vals):
yield from ziprec(p, v)
else: yield parms, vals
class Env(dict):
__slots__ = ["parent"]
def __init__(self, l, parent):
super().__init__(l)
import java.util.Arrays;
import java.util.Optional;
import java.util.Map;
import java.util.Iterator;
import java.util.AbstractMap.SimpleImmutableEntry;
public class Hamt<K, V> implements Iterable<Map.Entry<K, V>> {
static <K> boolean equals(K left, K right) {
return left.equals(right);
from warnings import catch_warnings, filterwarnings # this is always nice to see at the top of a file
class Primitive:
__slots__ = ["args"]
def __init__(self, *args): self.args = args
def __await__(self): return (yield self.args) # also a fun sight to see
async def eof(): return await Primitive("eof")
async def munch(): return await Primitive("munch")
async def choice(*args): return await Primitive("choice", args)
@Alwinfy
Alwinfy / audio_demo.py
Last active May 30, 2024 04:01
audio DSP demo (WARNING: LOUD)
#!/usr/bin/env python3
# requires `pip install pyaudio`
import pyaudio
# most DSP software on the market uses floats -1 to 1
# we instead use ints 0 to 255, due to a quirk of pyaudio
single_rotation = [int(i * 255 / 99) for i in range(100)]
# or:
{
"plugin": "Stoermelder-P1",
"model": "Stroke",
"version": "2.0",
"params": [],
"data": {
"panelTheme": 1,
"keys": [
{
"button": -1,
@Alwinfy
Alwinfy / bake.py
Last active March 25, 2024 19:57
bake a poem into a colourful cake
#!/usr/bin/env python3
# bake.py - score a poem with colourized ANSI codes
# Type a poem at stdin, print the colourized poem at stdout.
# Requires at least 256-color support from the teletype.
import sys
def ansi(*codes):
return "\x1b[" + ";".join(map(str, codes)) + "m"
def color(nib):
def modifyat(ls, ix, fn):
return ls[:ix] + (fn(ls[ix]),) + ls[ix + 1:]
def global_counter():
code = global_counter.__code__
global_counter.__code__ = code.replace(co_consts = modifyat(code.co_consts, len(code.co_consts) - 1, (1).__add__))
return 0