Skip to content

Instantly share code, notes, and snippets.

View fabiospampinato's full-sized avatar

Fabio Spampinato fabiospampinato

View GitHub Profile
@fabiospampinato
fabiospampinato / fast-npm-run.sh
Last active March 12, 2025 07:24
20x faster replacement for "npm run"
# 20x faster replacement for "npm run"
# - It supports scripts executing a built-in shell function
# - It supports scripts executing a binary found in PATH
# - It supports scripts executing a binary found in node_modules
# - It supports passing arguments and options to scripts
# - It supports reading scripts either via ripgrep (fast) or via jq (slower, but safer)
# - It adds ./node_modules/.bin to the $PATH
# - It handles gracefully when a script has not been found
# - It handles gracefully when "&", "&&", "|", "||", or ENV variables are used, falling back to "npm run"
@fabiospampinato
fabiospampinato / monaco.js
Created July 24, 2020 21:15
monaco aggressive tokenization
This file has been truncated, but you can view the full file.
// The Monaco Editor can be easily created, given an
// empty container and an options literal.
// Two members of the literal are "value" and "language".
// The editor takes the full size of its container.
const WarAndPeace = `# 00 - A War and Peace
BOOK ONE: 1805
CHAPTER I
@fabiospampinato
fabiospampinato / rg.txt
Last active June 9, 2024 15:40
output for "rg something linux-master --sort path"
~/Downloads ❯ time (rg something linux-master --sort path)
linux-master/Documentation/ABI/stable/sysfs-class-infiniband
214: unless set to something else by the driver. Users may echo a
linux-master/Documentation/ABI/stable/sysfs-class-rfkill
64: transmitter is forced off by something outside of
78: The transmitter is forced off by something outside of
linux-master/Documentation/ABI/stable/vdso
14:if you set CS on x86 to something strange, the vDSO functions are
@fabiospampinato
fabiospampinato / gg.txt
Last active June 9, 2024 15:40
output for "gg something linux-master --sort path"
~/Downloads ❯ time (gg something linux-master --sort path)
linux-master/Documentation/ABI/stable/sysfs-class-infiniband
214: unless set to something else by the driver. Users may echo a
linux-master/Documentation/ABI/stable/sysfs-class-rfkill
64: transmitter is forced off by something outside of
78: The transmitter is forced off by something outside of
linux-master/Documentation/ABI/stable/vdso
14:if you set CS on x86 to something strange, the vDSO functions are
@fabiospampinato
fabiospampinato / indexof_bench.js
Created June 2, 2024 17:54
String.prototype.indexOf vs Uint8Array.prototype.indexOf
const string = ` ${'This is just some example big file with lots of strings\n'.repeat ( 100_000 )}`.slice ( 1 );
const uint8 = new TextEncoder ().encode ( string );
const getRangesFromString = value => {
let pos = 0;
let length = value.length;
while ( pos < length ) {
@fabiospampinato
fabiospampinato / nvm_bypass.sh
Created May 31, 2024 19:05
Code for avoiding calling NVM, which slows down the shell by a lot
export NVM_DIR="$HOME/.nvm"
export NVM_DEFAULT_VERSION=$(cat $NVM_DIR/alias/default)
export PATH="$NVM_DIR/versions/node/$NVM_DEFAULT_VERSION/bin:$PATH"
export MANPATH="$NVM_DIR/versions/node/$NVM_DEFAULT_VERSION/share/man:$MANPATH"
export NODE_PATH="$NVM_DIR/versions/node/$NVM_DEFAULT_VERSION/lib/node_modules"
function find-up () {
local look=${PWD%/}
@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;