Skip to content

Instantly share code, notes, and snippets.

View fabiospampinato's full-sized avatar

Fabio Spampinato fabiospampinato

View GitHub Profile
@fabiospampinato
fabiospampinato / inspect.zsh
Last active April 20, 2024 23:37
Node.js inspect function and plugin for zsh
# INSPECT
function inspect () {
eval NODE_OPTIONS="--inspect-brk" $@
}
# INSPECT PLUGIN
# Toggles the "inspect " prefix upon double ESC key
function plugin-inspect () {
@fabiospampinato
fabiospampinato / repro.js
Created April 3, 2024 15:16
Setting Array.prototype.length doesn't explicitly tell you which properties got deleted
const proxy = new Proxy ( [0, 1, 2], {
get: ( ...args ) => {
console.log ( '[get]', ...args );
return Reflect.get ( ...args );
},
apply: ( ...args ) => {
console.log ( '[apply]', ...args );
return Reflect.apply ( ...args );
},
@fabiospampinato
fabiospampinato / use_controlled.ts
Created March 16, 2024 19:14
use:controlled directive for voby
/* IMPORT */
import {$$, createDirective} from 'voby';
import {useUpdateEffect} from '~/hooks';
/* HELPERS */
const onCheckboxChange = ( target: HTMLInputElement, value: $<undefined | boolean | number | string>, onChange?: ( value: boolean | string ) => void ): void => {
@fabiospampinato
fabiospampinato / emoji_re.js
Last active February 24, 2024 20:46
A regex that can match any emoji, I think. It will also match some emojis that are nonsensically joined by a zero-width joiner though. And nonsensical applications of skin tone modifiers too.
const emojiRe = /(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F)(?:\u200d(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F))*/gu;
@fabiospampinato
fabiospampinato / string-width_slowness_bench.js
Created February 24, 2024 18:03
string-width_slowness_bench.js
/* IMPORT */
import benchmark from 'benchloop';
import stringWidth from 'string-width';
// import fastStringWidth from '../dist/index.js';
/* HELPERS */
const IMPLEMENTATIONS = [
@fabiospampinato
fabiospampinato / bench.js
Created December 9, 2023 18:25
dot ignore bench
/* IMPORT */
import benchmark from 'benchloop';
import fs from 'node:fs';
import path from 'node:path';
import toIgnore from 'fast-ignore';
import dotignore from 'dotignore';
/* HELPERS */
@fabiospampinato
fabiospampinato / use_rulers.ts
Created September 15, 2023 11:02
A little Voby hook for rendering rulers around an element on the page
/* IMPORT */
import {$} from 'voby';
import {useCanvasOverlay, useEffect, useEventListener, useRect, useResolved} from '~/hooks';
/* TYPES */
type Line = {
offset: number
@fabiospampinato
fabiospampinato / nitropack_duplicates_report.txt
Created August 11, 2023 23:13
Duplicates report for Nitropack v2.5.2
- string_decoder
- 1.1.1
- Repository: https://github.com/nodejs/string_decoder
- Readme: https://raw.githubusercontent.com/nodejs/string_decoder/master/README.md
- License: https://raw.githubusercontent.com/nodejs/string_decoder/master/LICENSE
- 1.3.0
- Repository: https://github.com/nodejs/string_decoder
- Readme: https://raw.githubusercontent.com/nodejs/string_decoder/master/README.md
- License: https://raw.githubusercontent.com/nodejs/string_decoder/master/LICENSE
- source-map
@fabiospampinato
fabiospampinato / sieve.js
Created August 4, 2023 22:19
A little Sieve of Eratosthenes
const sieve = ( size ) => {
//TODO: add windowing for the buffer, allocating a fixed-size buffer that gets repopulated when needed
const buffer = new Uint8Array ( Math.ceil ( size / 8 ) ).fill ( 255 );
const primes = [];
let prev = 2;
@fabiospampinato
fabiospampinato / use_boxer.ts
Created May 1, 2023 17:34
A little Voby hook for rendering hit boxes around each element on the page
/* IMPORT */
import {$$} from 'voby';
import {useEffect} from '~/hooks';
/* MAIN */
const useResizeObserver = ( ref: $<Element | undefined>, fn: ResizeObserverCallback, options: ResizeObserverOptions = {} ): void => {