Skip to content

Instantly share code, notes, and snippets.

Avatar
🎉
Celebrating 20 years of building open source tools

Karsten Schmidt postspectacular

🎉
Celebrating 20 years of building open source tools
View GitHub Profile
@postspectacular
postspectacular / rectops.ts
Created November 22, 2022 14:27
(Non-exhaustive) selection/overview of rectangle operations provided by https://thi.ng/geom
View rectops.ts
rect(100)
// Rect { pos: [ 0, 0 ], attribs: undefined, size: [ 100, 100 ] }
rect([100, 200], 100)
// Rect { pos: [ 100, 200 ], attribs: undefined, size: [ 100, 100 ] }
rect([100, 200], [10, 20])
// Rect { pos: [ 100, 200 ], attribs: undefined, size: [ 10, 20 ] }
rectFromCentroid([100, 200], 100)
@postspectacular
postspectacular / sequencer.ts
Last active November 16, 2022 17:22
Generative audio sequencer & WAV file export using thi.ng/dsp
View sequencer.ts
/*
* Copyright (c) 2022 Karsten Schmidt
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@postspectacular
postspectacular / lottery.ts
Last active October 25, 2022 13:30
NFT giveaway lottery code
View lottery.ts
import { int, parseCSVSimple } from "@thi.ng/csv";
import { readText } from "@thi.ng/file-io";
import { pickRandom } from "@thi.ng/random";
import { split } from "@thi.ng/strings";
import {
comp,
distinct,
mapcat,
push,
repeat,
@postspectacular
postspectacular / benchmark.js
Last active October 18, 2022 10:43
JS ImageData update benchmarks showing perf gains (2-4x) from using u32 memory views over standard u8 accesses
View benchmark.js
import { suite } from "@thi.ng/bench";
const w = 640;
const h = 480;
const idata = new ImageData(w, h);
// exposed u8clampedarray
const u8 = idata.data;
// rewrap same memory as u32
const u32 = new Uint32Array(u8.buffer);
@postspectacular
postspectacular / build.sh
Created October 4, 2022 11:00
Zig command to build a WASM library, can't figure out equivalent using `build.zig` - help?
View build.sh
#!/bin/sh
zig build-lib -O ReleaseSmall -target wasm32-freestanding -dynamic --strip \
--pkg-begin wasmapi ../../node_modules/@thi.ng/wasm-api/include/wasmapi.zig --pkg-end \
--pkg-begin dom ../../node_modules/@thi.ng/wasm-api-dom/include/dom.zig --pkg-end \
src/main.zig
# optional post processing & optimization
wasm-opt main.wasm -o main.wasm -O3
View manifesto.md

PostSpectacular Manifesto

Literacy

  • Learn by doing
    • Take away a sound understanding of new concepts learned at the end of each activity
    • Transform knowledge into intuition
    • Share your learnings
    • Experiment to avoid/overcome procrastination
  • Go further, Carpe noctem
@postspectacular
postspectacular / textcanvas-blitting.js
Last active July 9, 2022 20:48
Tiny ASCII art demo for https://thi.ng/text-canvas showing how to compose an overlay image with transparency mask with another text canvas...
View textcanvas-blitting.js
import { SYSTEM } from "@thi.ng/random";
import { blitMask, canvas, canvasFromText, formatCanvas, hline } from "@thi.ng/text-canvas";
// overlay text canvas
const logo = canvasFromText([
"########### #### #### # #######",
"######### ░░░ ## ░░░ ## ░░░ ░░░░░░ ░░░░░░ ######",
"######## ░░░░░░░░░ ░░░░░░░░░ ░░░░░░░░░ ░░░░ ░░░░ #######",
"####### ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ #######",
"####### ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ #######",
@postspectacular
postspectacular / pack-intervals-example.js
Last active July 22, 2022 11:44
Interval-based compression (using thi.ng/bitstream). Finds and compresses sub-ranges of successive values in an array of monotonically increasing integer values in [0..n] interval.
View pack-intervals-example.js
import { equiv } from "@thi.ng/equiv";
import { encode, decode } from "./pack-intervals.js";
// example source array (will be compressed into just 7 bytes)
const src = [
1, 2, 3, 4,
6, 7,
9, 10, 11, 12, 13, 14,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
];
@postspectacular
postspectacular / lottery.js
Last active June 2, 2022 17:22
Lottery script for picking a number of weighted random addresses of FXHash token holders, import from a number of CSV files. These CSV files are per-project and each have the format: `address, numTokens`. Furthermore, the weight of the projects can be adjusted via the `PROJECT_WEIGHTS` object...
View lottery.js
import { float, parseCSVSimpleFromString } from "@thi.ng/csv";
import { readText } from "@thi.ng/file-io";
import { weightedRandomKey } from "@thi.ng/random";
import {
assocObj,
keys,
map,
normFrequenciesAuto,
repeatedly,
transduce,
@postspectacular
postspectacular / tzprofile.txt
Created November 20, 2021 23:35
tzprofiles verify
View tzprofile.txt
I am attesting that this GitHub handle postspectacular is linked to the Tezos account tz1d4ThofujwwaWvxDQHF7VyJfaeR2ay3jhf for tzprofiles
sig:edsigtzC6ZGMWGVC7jWZBBe26iNdewHxc9oxJFq4b2mXo3nzovaoDW5b3V9wP6rVaQfDLVT7TS3vdBQiqMZaqsyxAbqDH1onUPP