Skip to content

Instantly share code, notes, and snippets.

View forivall's full-sized avatar
🕴️
levitating

Emily Marigold Klassen forivall

🕴️
levitating
View GitHub Profile
@forivall
forivall / exclusifyUnion.ts
Last active February 23, 2024 20:27
ExclusifyUnion improved goto definiion
import { UnionToIntersection } from 'type-fest';
export type ExclusifyUnion<T> = ExclusifyUnion_<T, T>;
type ExclusifyUnion_<T, U> = T extends never
? never
: T & EmptyDifference<T, Exclude<U, T>>; // eslint-disable-line @typescript-eslint/sort-type-constituents
type EmptyDifference<T, U> = Omit<
UnionToIntersection<T extends never ? never : { [K in keyof U]?: never }>,
keyof T
>;
interface AsyncCompose {
<Options, R1, R2, R3>(
f: (options: Options) => R1,
g: (arg: Awaited<R1>, options: Options) => R2,
h: (arg: Awaited<R2>, options: Options) => R3,
): (options: Options) => R2;
<R1, R2>(f: () => R1, g: (arg: Awaited<R1>) => R2): () => R2;
<Options, R1, R2>(
f: (options: Options) => R1,
g: (arg: Awaited<R1>, options: Options) => R2,
@forivall
forivall / entry.ts
Created February 1, 2024 02:03
esm/cjs module bootstrap
async function main() {
console.log('main');
}
(async function () {
if ('undefined' !== typeof module) {
return require.main === module && main();
}
// eslint-disable-next-line no-new-func
const meta: ImportMeta = new Function('import.meta')();
@forivall
forivall / lazy.ts
Last active December 9, 2023 02:43
Fastest and smallest once wrapper in js
const unit = <T>(value: T) => () => value;
const lazy = <T>(fn: () => T) => {
let f = (): T => (f = unit(fn()))();
return () => f();
};
const lazyWithReset = <T>(fn: () => T) => {
let f: () => T;
const reset = () => {
f = () => (f = unit(fn()))();
// limit to 9 entries in the union, otherwise type instantiation gets very deep
export type ConstArrayOf<T, T2 = T> = [T] extends [never]
? []
: T extends infer U
? [U, ...ConstArrayOf<Exclude<T2, U>>]
: never;
@forivall
forivall / overrides.ts
Created November 4, 2023 02:27
override signatures
export type Overrides<T extends (...args: any) => any> = T extends {
(...args: infer A0): infer R0;
(...args: infer A1): infer R1;
(...args: infer A2): infer R2;
(...args: infer A3): infer R3;
(...args: infer A4): infer R4;
(...args: infer A5): infer R5;
(...args: infer A6): infer R6;
(...args: infer A7): infer R7;
(...args: infer A8): infer R8;
@forivall
forivall / mongosh.d.ts
Created June 16, 2023 02:18
Typescript definition hack for writing mongosh scripts
import {
Collection,
Database,
ReplicaSet,
Shard,
ShellInstanceState,
} from '@mongosh/shell-api';
import { ShellApiClass } from '@mongosh/shell-api/lib/decorators';
type ShellApi = ShellInstanceState['shellApi'];
@forivall
forivall / README.md
Last active March 16, 2023 17:45
git-credential-manager reaper script

This is a simple background script to kill git-credential-manager when it hits the 100% cpu bug

@forivall
forivall / settings.jsonc
Last active December 28, 2022 21:42
vscode theme color customizations
{
"editor.semanticTokenColorCustomizations": {
"rules": {
"*.mutable": {
"fontStyle": "bold"
},
"*.typeHint": {
"fontStyle": "italic"
},
"interface": {
@forivall
forivall / settings.json
Created December 16, 2022 01:37
My extensive customizeui settings
{
"customizeUI.font.monospace": "FantasqueSansMono Nerd Font",
"customizeUI.font.regular": "SF Pro Display",
"customizeUI.fontSizeMap": {
"13px": "12px"
},
"customizeUI.stylesheet": {
".mac, .windows, .linux": "letter-spacing: -0.02rem",
".mac.trongthanh-theme-boxythemekit-themes-Boxy-Yesterday-json": "-webkit-text-stroke: 0.3px",
".minimap": "opacity: 0.5",