This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface EventEmitterOn { | |
on(event: string, listener: (...args: any) => void): any; | |
} | |
type EventNames<T extends EventEmitterOn> = T extends { | |
on(event: infer N1, listener: any): any; | |
on(event: infer N2, listener: any): any; | |
on(event: infer N3, listener: any): any; | |
on(event: infer N4, listener: any): any; | |
on(event: infer N5, listener: any): any; | |
on(event: infer N6, listener: any): any; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$ref": "#/definitions/Settings", | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"definitions": { | |
"AccessibilitySettings": { | |
"additionalProperties": false, | |
"properties": { | |
"disableLoadingPhrases": { | |
"type": "boolean" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { Primitive } from 'type-fest'; | |
interface TypeguardTuple<T> extends Omit<readonly [T, ...T[]], never> { | |
includes(searchElement: unknown): searchElement is T; | |
includes(searchElement: T, fromIndex?: number): boolean; | |
} | |
const typeguardTuple = <T extends Primitive>(tuple: readonly [T, ...T[]]) => | |
tuple as Omit<readonly [T, ...T[]], never> as TypeguardTuple<T>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ObjectId } from 'bson'; | |
export class ObjectIdSet { | |
map = new Map<number, Set<number>>(); | |
constructor(values: Iterable<ObjectId>) { | |
for (const value of values) { | |
this.add(value); | |
} | |
} | |
add(value: ObjectId): this { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const port = process.argv[2]; | |
const host = process.argv[3]; | |
const delay = 1000; | |
const socket = new net.Socket(); | |
socket.on('close', () => { | |
setTimeout(() => { | |
socket.connect(port, host); | |
}, delay); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function analyseObjectId(/** @type {import('bson').ObjectId} */ oid) { | |
const randomidBuffer = Buffer.from( | |
oid.buffer.buffer, | |
oid.buffer.byteOffset + 4, | |
5, | |
); | |
const counterBuffer = Buffer.alloc(4); | |
oid.buffer.copy(counterBuffer, 1, 9); | |
return { | |
timestamp: oid.buffer.readInt32BE(0), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// just for hacking about in the node.js repl | |
PackFileCacheStrategy = require('webpack/lib/cache/PackFileCacheStrategy') | |
logger = Object.assign(Object.create(console), {getChildLogger() { return this }}) | |
cacheLocation = '.angular/cache/17.3.8/angular-webpack/INSERT_HASH_HERE' | |
packStrategy = new PackFileCacheStrategy({version: '', cacheLocation, fs, compiler: { options: { output: {} } }, snapshot: {}, logger}); | |
pack = await packStrategy.packPromise |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is equivalent to Map.groupBy; replace this function with Map.groupBy in Node 21+ */ | |
function mapGroupBy<T, K>(array: T[], iteratee: (value: T, index: number, array: T[]) => K) { | |
return array.reduce((result, value, index, array) => { | |
const key = iteratee(value, index, array); | |
const group = result.get(key); | |
if (group) { | |
group.push(value); | |
} else { | |
result.set(key, [value]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
NewerOlder