Skip to content

Instantly share code, notes, and snippets.

View postspectacular's full-sized avatar
🎉
Celebrating 24 years of building open source tools

Karsten Schmidt postspectacular

🎉
Celebrating 24 years of building open source tools
View GitHub Profile
@postspectacular
postspectacular / ffmpeg-xfade.ts
Last active August 3, 2024 12:41
TypeScript & ffmpeg-based crossfading & looping slideshow generator. Supports GIF or MP4 output. Configure options at the end of the file, then run via https://bun.sh
import { Z4, type Stringer } from "@thi.ng/strings";
import {
comp,
iterator,
map,
mapcat,
partition,
range,
wrapSides,
} from "@thi.ng/transducers";
import {
asSvg,
bounds,
circleFrom2Points,
group,
GroupAttribs,
line,
Polygon,
starWithCentroid,
svgDoc,
@postspectacular
postspectacular / ANSI.md
Created February 19, 2024 10:34 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@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 / 01_main.zig
Last active August 29, 2023 22:12
#HowToThing #010 — Creating a basic web app with Zig/WebAssembly and the extensible https://thi.ng/wasm-api and its https://thi.ng/wasm-api-dom add-on module
const std = @import("std");
const wasm = @import("wasm-api");
const dom = @import("wasm-api-dom");
// expose thi.ng/wasm-api core API (incl. panic handler & allocation fns)
pub usingnamespace wasm;
// main entry point
export fn start() void {
init() catch |e| @panic(@errorName(e));
@postspectacular
postspectacular / 008.ts
Last active August 28, 2023 12:29
#HowToThing #008 — Multi-plot COVID data visualization via https://thi.ng/csv and https://thi.ng/viz
import { epoch, int, parseCSV, type CSVRecord, type ColumnSpecs } from "@thi.ng/csv";
import { defFormat, months } from "@thi.ng/date";
import { readText, writeText } from "@thi.ng/file-io";
import { serialize } from "@thi.ng/hiccup";
import { svg } from "@thi.ng/hiccup-svg";
import { closedOpen } from "@thi.ng/intervals";
import { split } from "@thi.ng/strings";
import { comp, filter, push, transduce } from "@thi.ng/transducers";
import {
barPlot, dataBounds, dataMaxLog,
@postspectacular
postspectacular / 007.ts
Last active August 27, 2023 11:27
#HowToThing #007 — Converting Google Maps Saved Places (exported via Google Takeout) to KML
import { readJSON, writeText } from "@thi.ng/file-io";
import { XML_PROC, serialize } from "@thi.ng/hiccup";
// source path of the Google Takeout (GT) places
const path = "/Downloads/Takeout/Maps (your places)/Saved Places.json";
// load GT places
const places = readJSON(path).features;
// FYI: partial structure of a GT place
@postspectacular
postspectacular / 006.ts
Created August 26, 2023 11:59
#HowToThing #006 — Clustering data using https://thi.ng/k-means, using customizable distance functions and centroid strategies
import { HAVERSINE_LATLON } from "@thi.ng/distance";
import { kmeans, meansLatLon } from "@thi.ng/k-means";
// 20 world cities, sorted alphabetically
// data sourced from:
// https://github.com/OpenDataFormats/worldcities/blob/master/src/data/cities.json
const cities = [
{ id: "anchorage", latlon: [61.21806, -149.90028] },
{ id: "berlin", latlon: [52.52437, 13.41053] },
{ id: "boston", latlon: [42.35843, -71.05977] },
@postspectacular
postspectacular / 004.js
Last active March 7, 2024 06:32
#HowToThing #004 Creating text-based plots to debug & visualize sequential data in a REPL-driven workflow. Here we're using https://thi.ng/dsp signal generators, but any numeric array or iterable will work...
// $ node
// Welcome to Node.js v20.5.1.
// Type ".help" for more information.
const { barChartHStr, lineChartStr } = await import("@thi.ng/text-canvas");
const { adsr, osc, modOsc, rect, saw, sin, tri } = await import("@thi.ng/dsp");
// display line plot of 100 samples from an amplitude-modulate sine oscillator
console.log(lineChartStr(20, modOsc(sin, 0.01, 0, osc(sin, 0.2)).take(100)));
// ╭╮ ╭╮ ╭╮ ╭╮
@postspectacular
postspectacular / foreach.ts
Created August 10, 2023 21:52
Performance comparison between different for-loop variations and payload sizes
import { FORMAT_MD, suite } from "@thi.ng/bench";
import { range } from "@thi.ng/transducers";
const testForIndexFwd = (src: number[]) => {
let m = 0;
for (let i = 0, n = src.length; i < n; i++) m += src[i];
return m;
};
const testForIndexRev = (src: number[]) => {