Skip to content

Instantly share code, notes, and snippets.

@y21
y21 / vm2.js
Last active April 6, 2023 07:16
vm2
const {NodeVM} = require('vm2');
const {isMainThread, Worker, parentPort} = require('worker_threads');
if (isMainThread) {
const worker = new Worker(__filename);
let lastMessage = null;
worker.on('message', () => lastMessage = Date.now());
worker.on('online', () => lastMessage = Date.now());
@tigt
tigt / git-branch-to-favicon.js
Created March 18, 2020 21:10
Creates an SVG string that can be used as a favicon across different Git branches. Actually getting this into the browser is sadly project-specific.
const { execSync } = require('child_process')
const { createHash } = require('crypto')
const invertColor = require('invert-color')
const branchName = execSync('git rev-parse --abbrev-ref HEAD')
const hash = createHash('sha256')
hash.update(branchName)
const color = '#' + hash.digest().toString('hex').substring(0, 6)
const invertedColor = invertColor(color, true)
@creationix
creationix / BaseBee.js
Last active June 1, 2025 15:44
This is a base 80 encoding that uses the 40 characters (upper and lower case) of the deseret alphabet invented by pioneers in the mid 1800s. It's not a very useful encoding since it's less efficient than base-16. But it is a pretty fun unicode test since these are high enough in the unicode space to require surrogate pairs in JavaScript.
// ๐œ๐ฎ๐‘… ๐ฎ๐‘† ๐ฉ ๐บ๐ฉ๐‘… 80 ๐ฏ๐‘Œ๐ฟ๐ฌ๐ผ๐ฎ๐‘ ๐‘„๐ฐ๐ป ๐ฒ๐‘…๐ฒ๐‘† ๐‘„ 40 ๐ฟ๐ฐ๐‘‰๐ฎ๐ฟ๐ป๐ฒ๐‘‰๐‘† (๐ฒ๐น๐ฒ๐‘‰ ๐ฐ๐‘Œ๐ผ ๐‘Š๐ต๐ฒ๐‘‰ ๐ฟ๐ฉ๐‘…)
// ๐ฒ๐‘‚ ๐‘„ ๐ผ๐ฏ๐‘…๐จ๐‘‰๐ฏ๐ป ๐ฐ๐‘Š๐‘๐ฐ๐บ๐ฏ๐ป ๐ฎ๐‘Œ๐‘‚๐ฏ๐‘Œ๐ป๐ฒ๐ผ ๐บ๐ด ๐’๐‘‰๐ฎ๐‘€๐ฒ๐‘‹ ๐๐ฒ๐‘ ๐ฎ๐‘Œ ๐‘„ ๐‘‹๐ฎ๐ผ 1800๐ฏ๐‘….
// ๐†๐ป ๐ฎ๐‘† ๐‘Œ๐ช๐ป ๐ฉ ๐‘‚๐ฏ๐‘‰๐จ ๐ท๐ญ๐‘…๐‘๐ฒ๐‘Š ๐ฏ๐‘Œ๐ฟ๐ฌ๐ผ๐ฎ๐‘ ๐‘…๐ฎ๐‘Œ๐‘… ๐ฎ๐ป ๐ฎ๐‘† ๐ฒ๐บ๐ต๐ป ๐ฐ๐‘† ๐ฎ๐‘๐ฎ๐‘‡๐ฒ๐‘Œ๐ป ๐ฐ๐‘† ๐บ๐ฉ๐‘…
// 16. ๐’๐ฒ๐ป ๐ฎ๐ป ๐ฎ๐‘† ๐ฉ ๐น๐‘‰๐ฎ๐ป๐จ ๐‘๐ฒ๐‘Œ unicode ๐ป๐ฏ๐‘…๐ป ๐‘…๐ฎ๐‘Œ๐‘… ๐‘„๐จ๐‘† ๐ช๐‘‰ ๐ธ๐ด ๐ฎ๐‘Œ๐ฒ๐‘ ๐ฎ๐‘Œ ๐‘„
// unicode ๐‘…๐น๐ฉ ๐ป๐ญ ๐‘‰๐ฎ๐ฟ๐ถ๐ด๐ฒ๐‘‰ ๐‘…๐ฒ๐‘‰๐ฒ๐‘€๐ฉ๐ป ๐น๐ฏ๐‘† ๐ฎ๐‘Œ ๐–๐ช๐‘‚๐ฒ๐๐ฟ๐‘‰๐ฎ๐น๐ป.
let ๐”๐ฏ๐‘…๐จ๐‘‰๐ฏ๐ป = '๐€๐๐‚๐ƒ๐„๐…๐†๐‡๐ˆ๐‰๐Š๐‹๐Œ๐๐Ž๐๐๐‘๐’๐“๐”๐•๐–๐—๐˜๐™๐š๐›๐œ๐๐ž๐Ÿ๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง' +
'๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐‘€๐‘๐‘‚๐‘ƒ๐‘„๐‘…๐‘†๐‘‡๐‘ˆ๐‘‰๐‘Š๐‘‹๐‘Œ๐‘๐‘Ž๐‘';
export function ๐’๐ฉ๐‘…๐’๐จ(๐ค๐ฒ๐‘‹๐บ๐ฒ๐‘‰) {
@blixt
blixt / prng.js
Last active March 30, 2025 04:16
A very simple, seedable JavaScript PRNG. NOTE: Please read comments on why this is not a good choice.
// NOTICE 2020-04-18
// Please see the comments below about why this is not a great PRNG.
// Read summary by @bryc here:
// https://github.com/bryc/code/blob/master/jshash/PRNGs.md
// Have a look at js-arbit which uses Alea:
// https://github.com/blixt/js-arbit
/**
@kylefox
kylefox / liquid-mode.js
Created November 11, 2011 00:02
Liquid syntax highlighting for CodeMirror.
/*
This overlay provides a 'liquid' mode to the excellent CodeMirror editor (http://codemirror.net/).
Add something like this to your CSS:
.cm-liquid-tag {
color: #32273f;
background: #ead9ff;
}
.cm-liquid-variable {