Skip to content

Instantly share code, notes, and snippets.

View postspectacular's full-sized avatar
🎉
Celebrating 27+ years of building open source tools. Migrating to Codeberg...

Karsten Schmidt postspectacular

🎉
Celebrating 27+ years of building open source tools. Migrating to Codeberg...
View GitHub Profile
import { output, processImage } from "@thi.ng/imago";
import { GRAY8 } from "@thi.ng/pixel";
import { readGeoTiff } from "@thi.ng/pixel-io-geotiff";
import { range2d } from "@thi.ng/transducers";
import { readFileSync } from "node:fs";
// a 44155 x 25153 pixel GeoTIFF file
const path = "DOM_Tirol_5m_epsg31254/DOM_Tirol_5m_epsg31254_2017-2023.tif";
// load GeoTIFF
@postspectacular
postspectacular / hsv2rgb.ino
Last active June 10, 2026 10:27
Super compact HSV/RGB conversions for Arduino/C
int redPin = 6;
int greenPin = 5;
int bluePin = 9;
float col[3];
float hue = 0.0;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);

Toxi's Lebkuchen (plain "Elisen" style)

Spice blend

  • 3 whole star anise
  • 15 whole cardamon pods
  • 2 tblsp ground cinnamon (or ~0.75 stick)
  • 1.5 tblsp ground cloves
  • 0.5 tsp ground coriander
  • 0.75 tsp ground ginger
@postspectacular
postspectacular / tag-query.test.ts
Created November 6, 2025 22:21
Query engine example using a Lisp-like syntax to perform nested tag queries with Set-semantics (TODO insert URL)
import type { FnU2, Maybe, Predicate2 } from "@thi.ng/api";
import { difference, intersection, union } from "@thi.ng/associative";
import { isArray, isString } from "@thi.ng/checks";
import { illegalArgs } from "@thi.ng/errors";
import { evalSource } from "@thi.ng/lispy";
import { defQuery, type QueryOpts } from "@thi.ng/oquery";
import { expect, test } from "bun:test";
type Note = { id: number; tags: string[] };
@postspectacular
postspectacular / mastodon-markdown.ts
Created November 5, 2025 15:07
Example code to convert the body of a single Mastodon post to Markdown (see https://mastodon.thi.ng/@toxi/115496400071927410 for details)
import { parseHtml } from "@thi.ng/hiccup-html-parse";
import { serialize } from "@thi.ng/hiccup-markdown";
import { arrayZipper, type Location } from "@thi.ng/zipper";
const HOST = "mastodon.thi.ng";
const STATUS_ID = "115464108396925195";
// load a Mastodon status via API
const res = await (
await fetch(`https://${HOST}/api/v1/statuses/${STATUS_ID}`)

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 / delete-bookmarks.js
Last active September 17, 2025 10:24
Configurable batch deletion of Mastodon bookmarks (using Mastodon API). MIT Licensed.
// your account domain
const DOMAIN = "mastodon.social";
// your registered mastodon app's access token
// (might need to first create an app via mastodon preferences and
// assign scopes: read:bookmarks and write:bookmarks)
const ACCESS_TOKEN = "TODO";
// only remove bookmarks older than this date
const THRESHOLD_DATE = "2025-06-01";
@postspectacular
postspectacular / swizzle.zig
Created September 15, 2025 12:54
Comptime enum-based 1D-4D vector swizzling
fn swizzleEnum(comptime N: usize, comptime T: type, a: @Vector(N, T), comptime id: Swizzle) @Vector(swizzleLength(id), T) {
comptime var code = @intFromEnum(id);
comptime var i = 0;
comptime var offset = 0;
comptime var count = 4;
inline while (code >= offset + count) {
offset += count;
count <<= 2;
i += 1;
}
@postspectacular
postspectacular / 018.ts
Created September 28, 2023 06:51
#HowToThing #018 — Topological sorting, creating and visualizing a task dependency graph
import { identity } from "@thi.ng/api";
import { topoSort } from "@thi.ng/arrays";
import { defDGraph } from "@thi.ng/dgraph";
import { toDot } from "@thi.ng/dgraph-dot";
import { comp, filter, map, mapcat, pairs, run, trace } from "@thi.ng/transducers";
interface Task {
title: string;
done?: boolean;
// IDs of other tasks this task depends on (aka is blocked by)
@postspectacular
postspectacular / tetrahedron-intersect.clj
Last active April 22, 2025 17:29
Tetrahedron intersection (currently runs in ~36% time than original revision of this gist)
;; Tetrahedron intersection based on this paper & algorithm:
;; http://vcg.isti.cnr.it/Publications/2003/GPR03/fast_tetrahedron_tetrahedron_overlap_algorithm.pdf
;;
;; Unlike original algorithm this implementation produces correct
;; results regardless of the orientation/ordering of points defining
;; the two tetrahedra. This is achieved via the orient-tetra function,
;; which ensures the correct ordering of vertices for this algorithm
;; to function properly.
;;
;; Implementation extracted from upcoming geometry library