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 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...
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.
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...
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
I am attesting that this GitHub handle postspectacular is linked to the Tezos account tz1d4ThofujwwaWvxDQHF7VyJfaeR2ay3jhf for tzprofiles
sig:edsigtzC6ZGMWGVC7jWZBBe26iNdewHxc9oxJFq4b2mXo3nzovaoDW5b3V9wP6rVaQfDLVT7TS3vdBQiqMZaqsyxAbqDH1onUPP
[["adapt-dpi/src/index.ts","adjacency/src/bfs.ts","adjacency/src/binary.ts","adjacency/src/dfs.ts","adjacency/src/disjoint-set.ts","adjacency/src/mst.ts","adjacency/src/sparse.ts","api/src/api/assoc.ts","api/src/api/bind.ts","api/src/api/buffered.ts","api/src/api/clear.ts","api/src/api/compare.ts","api/src/api/contains.ts","api/src/api/copy.ts","api/src/api/deref.ts","api/src/api/dissoc.ts","api/src/api/enable.ts","api/src/api/equiv.ts","api/src/api/event.ts","api/src/api/fn.ts","api/src/api/get.ts","api/src/api/hash.ts","api/src/api/id.ts","api/src/api/indexed.ts","api/src/api/into.ts","api/src/api/keyval.ts","api/src/api/length.ts","api/src/api/meta.ts","api/src/api/object.ts","api/src/api/path.ts","api/src/api/predicate.ts","api/src/api/range.ts","api/src/api/release.ts","api/src/api/reset.ts","api/src/api/seq.ts","api/src/api/set.ts","api/src/api/stack.ts","api/src/api/tuple.ts","api/src/api/typedarray.ts","api/src/api/watch.ts","api/src/assert.ts","api/src/constants.ts","api/src/decorators/configurable.t
@postspectacular
postspectacular / 00-sigmoid-approx.ts
Last active November 2, 2019 20:31
Sigmoid versions (AssemblyScript)
// uses Math.exp() approximation from:
// https://www.musicdsp.org/en/latest/Other/222-fast-exp-approximations.html
// @ts-ignore: decorator
@inline
function fastexp9(x: f64): f64 {
// prettier-ignore
return (362880+x*(362880+x*(181440+x*(60480+x*(15120+x*(3024+x*(504+x*(72+x*(9+x)))))))))*2.75573192e-6;
}
@postspectacular
postspectacular / accessors.ts
Last active October 14, 2019 15:25
Super slow numeric property accessors - why is [0] / [1] access 110x slower than .x/.y?
import { bench } from "@thi.ng/bench";
import { map, range } from "@thi.ng/transducers";
export class Vec2 {
buf: Float32Array;
constructor(buf: ArrayBuffer, off: number) {
this.buf = new Float32Array(buf, off, 2);
}
@postspectacular
postspectacular / tokenizer.js
Created September 10, 2019 20:47
S-expr tokenizer
function tokenizeSexpr(src) {
let curr = "";
const scopes = [[]];
const $word = () => {
if (curr) {
scopes[scopes.length - 1].push(curr);
curr = "";
}
};
for(let i = 0; i < src.length; i++) {
import {
area,
centroid,
clipConvex,
convexHull,
points,
polygon,
rect,
scatter,
withAttribs