Skip to content

Instantly share code, notes, and snippets.

View anthonyquizon's full-sized avatar

Anthony Quizon anthonyquizon

  • Sydney, Australia
View GitHub Profile
#
# Example of how to render an ascii tree from a parent vector
#
Draw⇐{
d←(⊢∾1+⊏)´p𝕩 # p: parent vector, d: depth vector
w←{(1-˜)(𝕨(⊣⊔˜)p)(⊢∾¨˜)((𝕩𝕨p)/)𝕩}´d⊔↕≠p # order depths depending on parent groups
n←(1+wp)˘(1+⌈´d)w=wd # matrix of ordered depth path cut off
n↩(0≠∨˝n)/˘n>(↕≠)({«𝕨 𝕩}˘)n # shift columns under parent node and remove empty space
s0<∊˘ne0<()˘nhs+`-˘em0<hnvse # s: start, e: ends, h: horizontals, m: middles, v: verticals
b" ─┬├┐│"˜(0˜≠⍉n)1↓⌈´hmsevר1+↕5 # branches - nullify root layer. 1: horizontal, 2: middle, 3: start, 4: end, 5: vertical,
@anthonyquizon
anthonyquizon / namespace.bqn
Created December 3, 2024 06:39
conveniently allocate names to namespace with ids
n•BQN∾{"{"𝕩"}"} (↕≠d){ 𝕩,"",•Fmt𝕨,","⟩ }¨ d"foo""bar"
@anthonyquizon
anthonyquizon / query.bqn
Created November 29, 2024 11:30
Query engine in 100 lines of js in 10 lines of bqn
# Reference: https://www.instantdb.com/essays/datalogjs
db←[
"100", "person/name", "James Cameron"⟩,
"100", "person/born", "1954-08-16T00:00:00Z"⟩,
"101", "person/name", "Arnold Schwarzenegger"⟩,
"101", "person/born", "1947-07-30T00:00:00Z"⟩,
"102", "person/name", "Linda Hamilton"⟩,
"102", "person/born", "1956-09-26T00:00:00Z"⟩,
"103", "person/name", "Michael Biehn"⟩,
@anthonyquizon
anthonyquizon / lib.c
Created November 25, 2024 23:50
bqn ffi for replxx
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <termios.h>
#include <unistd.h>
#include <wchar.h>
#include <locale.h>
#include "replxx.h"
#include "sqlite3.h"
@anthonyquizon
anthonyquizon / example-html.bqn
Last active September 23, 2024 23:40
BQN String interpolation
string•Import "string.bqn"
# Poor mans templating engine
Fmt←{ 𝕨string.Fmt¨<˘𝕩}
foo∾∾
"<div>"
"<span>{value}</span>" Fmt 10
"<span class='{0}'>{1}</span>" Fmt [⟨"foo",1⟩,⟨"bar",2⟩]
Bytecode: ⟨ 0 1 33 0 0 48 6 0 1 0 0 34 0 0 17 7 ⟩
Loc: ⟨ ⟨ 2 2 0 0 0 1 3 6 6 5 5 4 4 4 5 4 ⟩ ⟨ 2 2 0 0 0 1 3 6 6 5 5 4 4 4 5 4 ⟩ ⟩
Token:
┌─
· ⟨ 95 72 96 64 95 0 96 ⟩ ⟨ 0 ¯3 0 ¯1 0 1 0 ⟩ ⟨ ⟨ "a" ⟩ ⟨⟩ ⟨ 2 ⟩ ⟨⟩ ⟨⟩ ⟩ ⟨ 0 1 2 3 4 5 6 ⟩ ⟨ 0 1 2 3 4 5 6 ⟩
lib.so: lib.c
gcc -shared lib.c -o lib.so
@anthonyquizon
anthonyquizon / data.csv
Last active February 27, 2024 04:55
Segmentation fault example bqn
Date Description Credit Debit Balance
26/02/2024 Foo Bar Baz Card 12345xxxxxx5678 -11.19 2017.05
26/02/2024 Foo Bar Baz Card 12345xxxxxx5678 -11.19 2017.05
26/02/2024 Foo Bar Baz Card 12345xxxxxx5678 -11.19 2017.05
26/02/2024 Foo Bar Baz Card 12345xxxxxx5678 -11.19 2017.05
26/02/2024 Foo Bar Baz Card 12345xxxxxx5678 -11.19 2017.05
26/02/2024 Foo Bar Baz Card 12345xxxxxx5678 -11.19 2017.05
26/02/2024 Foo Bar Baz Card 12345xxxxxx5678 -11.19 2017.05
26/02/2024 Foo Bar Baz Card 12345xxxxxx5678 -11.19 2017.05
26/02/2024 Foo Bar Baz Card 12345xxxxxx5678 -11.19 2017.05
@anthonyquizon
anthonyquizon / unicode.d
Created July 30, 2021 11:52
print out valid unicode identifier characters for dlang
import std.stdio;
import std.uni;
import std.conv;
///Taken from https://github.com/dlang/dmd/blob/0517fc93ceb9e74e979bbbc9de64eb64d610094c/src/dmd/utf.d
static immutable wchar[2][] ALPHA_TABLE =
[
[0x00AA, 0x00AA],
[0x00B5, 0x00B5],
[0x00B7, 0x00B7],
[0x00BA, 0x00BA],
@anthonyquizon
anthonyquizon / read-dt.org
Created December 5, 2020 03:35 — forked from queertypes/read-dt.org
Implement a Dependently Typed Language and Then Some