Skip to content

Instantly share code, notes, and snippets.

View tnthung's full-sized avatar

TNThung tnthung

View GitHub Profile
@tnthung
tnthung / finy.js
Last active May 21, 2026 00:52
Finy - a tiny framework for writing notes with html with components
var M=new class{#j=!0;enable(){this.#j=!0}disable(){this.#j=!1}debug(...z){if(this.#j)console.debug(...z)}info(...z){if(this.#j)console.info(...z)}warn(...z){if(this.#j)console.warn(...z)}error(...z){if(this.#j)console.error(...z)}tap(z){return this.debug("tap:",z),z}tapJson(z){return this.debug("tap:",JSON.stringify(z,null,2)),z}};function Q(j,z){return Function(...Object.keys(z),`"use strict"; return (${j});`)(...Object.values(z))}function Y(j,z,D){let G=0;for(let F=0;F<j.length;F++){let J=j[F];if(J===z)G++;if(J===D)G--;if(G===0)return F}return-1}function Z(j){let z=new Set,D=j.trimStart(),G=D.match(/^[a-zA-Z_$][a-zA-Z0-9_$]*/)?.[0];if(G)return z.add(G),z;if(D.startsWith("[")||D.startsWith("{")){let F=D[0],H=Y(D,F,F==="["?"]":"}");if(H===-1)throw Error(`Mismatched ${F==="["?"brackets":"braces"} in expression "${j}".`);let K=D.slice(1,H);for(let O of K.matchAll(/[a-zA-Z_$][a-zA-Z0-9_$]*/g))z.add(O[0]);return z}throw Error(`Unsupported expression format "${j}". Only simple identifiers and destructuring patter
class Tree:
def __init__(self, value):
self.__value = value
self.__children = []
def setChildren(self, children):
self.__children = children
return self