Skip to content

Instantly share code, notes, and snippets.

View nicholaswmin's full-sized avatar
💭
I may be slow to respond.

Nicholas Kyriakides nicholaswmin

💭
I may be slow to respond.
View GitHub Profile
@nicholaswmin
nicholaswmin / flow.spec.md
Last active February 17, 2025 11:10
flow documentation format for LLM-assisted refactoring

flow

format for flow documenation in [LLM][llm]-assisted refactoring

This spec is given to the LLM which in turn utilizes it to
produce documentation of [system flows][flow], each showing
[state transitions][state], [steps][step], and [side effects][effect].

These flow documents support:

@nicholaswmin
nicholaswmin / test-runner.sh
Last active February 14, 2025 16:27
POSIX test runner
#!/bin/sh
# test.sh
# ----------------------
# scaffold example test:
# sh --init
#
# quickstart:
#
@nicholaswmin
nicholaswmin / validated.js
Last active February 15, 2025 11:26
type-validator function for primitives, null & array. Includes unit-tests and docs
/** @function
* @name validated
* @summary validate the type of a value
*
* @description
* validates a value against a {spec}. object, specifying:
* - parameter {name}
* - expected {type}
* {type} suppers & differentiates non-standard "array" and "null" types.
*
@nicholaswmin
nicholaswmin / reset.js
Created December 16, 2024 16:49
sensible DOM in 3 lines of code
/* examples:
$$('.button').map(el => el.on('click', console.log))
$('body').on('mouseenter', console.log) */
Node.prototype.on = Node.prototype.addEventListener
window.$ = document.querySelectorAll.bind(document)
window.$$ = (...a) => Array.from(document.querySelectorAll(...a))
@nicholaswmin
nicholaswmin / README.md
Last active December 12, 2024 14:40
pretty-inspect.js

pretty printer for object/arrays

CLI screenshot of result: 2D table. everything is colourized dimmed, except the values

const result = inspect([ { index: 1,   value: 'foo bar baz '.repeat(100) },
                         { index: 2,   value: 'foo bar baz '.repeat(10)  },
                         { index: 125, value:  null                      },
                         { index: 16,  value: 0123456789                 },
{ index: 300, value: function foo() {} },
@nicholaswmin
nicholaswmin / undo.md
Last active December 19, 2024 17:24
oops
@nicholaswmin
nicholaswmin / calc.js
Last active December 8, 2024 09:03
majestically tiny, stack-based calculator in ES6+
/*
tiny stack-based calculator
- If you're looking for a fancier expression calculator,
this isn't it. What you're looking for is a "Shunting Yard"
implementation. This is intentionally simple.
@nicholaswmin, MIT License
-- Usage: --
@nicholaswmin
nicholaswmin / pptr.mixin.test.js
Last active December 8, 2024 12:36
minimally extended puppeteer for clutter-free test files. unit-tests below.
/*
** IMPORTANT: This is rather pointless. The Locator API does most of the work replicated here **
Browser unit-tests for: `pptr.mixin.js`
> in chrome ~~& firefox~~
The following should have beeen installed on `npm install`:
```bash
@nicholaswmin
nicholaswmin / pretty-syntax-error.js
Last active November 25, 2024 03:05
A pretty-printed SyntaxError for compilers/tokenizers/lexers
/*
Pretty Syntax Errors
> @nicholaswmin, MIT License
A SyntaxError that pretty-prints the and higlights error line & column,
in your source.
This is only useful if you're building a compiler/lexer/tokenizer.
Although it is an `instanceof SyntaxError`, their similarities end there.
This file has been truncated, but you can view the full file.
// highlighted.js
// patched to adapt to external layout changes
/*! (c) Andrea Giammarchi @webreflection ISC */
!function(){"use strict";var e=function(e,t){var n=function(e){for(var t=0,n=e.length;t<n;t++)r(e[t])},r=function(e){var t=e.target,n=e.attributeName,r=e.oldValue;t.attributeChangedCallback(n,r,t.getAttribute(n))};return function(o,a){var l=o.constructor.observedAttributes;return l&&e(a).then((function(){new t(n).observe(o,{attributes:!0,attributeOldValue:!0,attributeFilter:l});for(var e=0,a=l.length;e<a;e++)o.hasAttribute(l[e])&&r({target:o,attributeName:l[e],oldValue:null})})),o}};function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function n(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(