Skip to content

Instantly share code, notes, and snippets.

View anthonyquizon's full-sized avatar

Anthony Quizon anthonyquizon

  • Sydney, Australia
View GitHub Profile
@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⟩]
@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 / 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 / namespace.bqn
Created December 3, 2024 06:39
conveniently allocate names to namespace with ids
n←•BQN∾{"{"∾𝕩∾"}"} (↕≠d){ ∾⟨𝕩,"⇐",•Fmt𝕨,","⟩ }¨ d←"foo"‿"bar"
#
# 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+w⊏p)⊸∧˘(1+⌈´d)↑w=⌜w⊏d # matrix of ordered depth path cut off
n↩(0≠∨˝n)⊸/˘n↩>(↕≠)⊸({«⍟𝕨 𝕩}˘)n # shift columns under parent node and remove empty space
s←0<∊⊸∧˘n⋄e←0<(⌽∘∊∘⌽)⊸∧˘n⋄h←s+`∘-˘e⋄m←0<h∧n⋄v←s∧e # s: start, e: ends, h: horizontals, m: middles, v: verticals
b←" ─┬├┐│"⊏˜(0⥊˜≠⍉n)∾1↓⌈´h‿m‿s‿e‿vר1+↕5 # branches - nullify root layer. 1: horizontal, 2: middle, 3: start, 4: end, 5: vertical,