Skip to content

Instantly share code, notes, and snippets.

html[dark] {
background-color: #000 !important;
}
* {
--yt-spec-general-background-a: #000 !important;
--yt-spec-general-background-b: #000;
--yt-spec-brand-background-primary: #000 !important;
--yt-spec-brand-background-solid: #000;
--ytd-searchbox-legacy-button-color: #090909;
@miyaokamarina
miyaokamarina / fs-extra-sync.js
Created May 28, 2021 03:24
NodeJS FS Extra Sync
// WTFPL or MIT
//
// Like `fs-extra`, but everything is sync.
// May be used with `webpack`/`enhanced-resolve`
// to allow the `resolveSync` method:
//
// const compiler = webpack(...);
//
// compiler.inputFileSystem = require('./fses');
//
@miyaokamarina
miyaokamarina / scan-exports.js
Last active May 28, 2021 05:01
Scan JS/TS files for exported symbols
// WTFPL or MIT
//
// Extracts all the exported symbols from files.
// For example, if you have a prelude and want to feed all its symbols
// to the `webpack.ProvidePlugin` or your fav Babel auto-import plugin.
//
// Written to be used with webpack (depends on its resolver),
// but it’s pretty easy to get rid of this dependency.
//
// Only supports ES modules. Doesn’t support Flow.
@miyaokamarina
miyaokamarina / typescript-type-level-spread.ts
Last active June 1, 2021 11:57
Infers the type of object spread operation; like { ...a, ...b }, but for types.
declare type Refine<from, to> = from extends to ? from : never;
declare type ArraySize<t> = Refine<GetProperty<t, 'length'>, number>;
declare type GetProperty<t, k> = t[Refine<k, keyof t>];
declare type ArrayType<t> = t extends ReadonlyArray<infer u> ? u : never;
declare type ArrayHead<a> = a extends readonly [infer h] ? h : never;
declare type Rebuild<t> = { [k in keyof t]: t[k] };
declare type KeyofReq<o, k extends keyof o = keyof o> = k extends any ? (undefined extends o[k] ? never : k) : never;
// Binary spread
declare type ObjectSpread<

Largest number less than one

IEEE 754 binary64

0 01111111110 1111111111111111111111111111111111111111111111111111 === 1 - 2**(-53)
@miyaokamarina
miyaokamarina / README.md
Created June 3, 2021 19:14
(Probably) The fastest Mersenne Twister for JavaScript/TypeScript

Yet Another Mersenne Twister

  • Hella fast.
  • Compact af.
  • Built with typed arrays.
  • Provides an API to save/restore the state.
  • Written in TypeScript.
import { MersenneTwister } from './mersenne-twister.ts';
@miyaokamarina
miyaokamarina / chmod.pegjs
Last active June 8, 2021 22:39
Sorta kinda UNIX chmod command permissions notation parser.
{
const MASK = 0;
const COPY = 1;
const ADD = 0;
const SUB = 1;
const SET = 2;
const Symbolic = (s, o, v) => {
s ??= { class: 0o7, umasked: true };
@miyaokamarina
miyaokamarina / grapheme-cluster-length.js
Created June 19, 2021 15:49
String length in Unicode grapheme clusters.
const segmenter = new Intl.Segmenter('en-us', {
granularity: 'grapheme',
});
const length = x => {
x = x.normalize('NFC');
const graphemes = segmenter.segment(x);
return Array.from(graphemes).length;
@miyaokamarina
miyaokamarina / desktop-entry-parsers.md
Last active February 19, 2023 12:41
Desktop Entry Parsers Comparison

Desktop Entry Parsers

KConfig

  • Only recognizes \n newlines.
  • Accepts [ \t\n\r] as whitespace:
    • At the start of line.
    • At the end of line.
    • Before =.
  • After =.
@miyaokamarina
miyaokamarina / toyhash.js
Created July 11, 2023 21:11
Illustrative examples of hash functions and their inverses for 4, 8, and 16-bit inputs.
// @ts-check
// SPDX-License-Identifier: CC0-1.0
/**
* 4-bit hash.
*
* Single LCG step + xorshift.
*
* @param {number} x
*/