This file contains 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 effects: Map<number, () => void> = new Map(); | |
let nextEffectId = 1; | |
/** | |
* Similar to useEffect, but an effect from another randomly chosen instance of useButterflyEffect is called | |
* when given deps change. | |
*/ | |
function useButterflyEffect(effect: () => void, deps: readonly unknown[]) { | |
useEffect(() => { | |
const effectId = nextEffectId++; |
This file contains 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 svg = document.querySelector('svg.vlmbi.H21Mnd'); | |
const svg2 = cl(svg); | |
const paths = svg2.querySelectorAll('path.xH0v4d'); | |
const cs = [ | |
'rgb(218, 220, 224)', | |
'rgb(0, 155, 216)', | |
'rgb(166, 220, 241)', | |
'rgb(241, 176, 180)', | |
'rgb(219, 29, 40)', |
This file contains 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 offsetRange(arr) { | |
return ( | |
arr.map(v => [v, v+1]) | |
.join(",") | |
.replace(/(,\d+)\1/g, "-") | |
.replace(/(-+,)\d+/g, (_, s) => "-" + (s.length)) | |
.replace(/(,\d+),\d+/g, (_, s) => `${s}-1`) | |
.split(",") | |
.map((v) => { | |
const [offset, range] = v.split("-"); |
This file contains 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
Promise.prototype.then = (()=> { | |
const _then = Promise.prototype.then; | |
return function(...args) { | |
_then.call(this, (res) => { | |
promiseResultMap.set(this, res); | |
}) | |
this.then = _then; | |
return _then.apply(this, args); | |
} | |
})(); |
This file contains 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 use\uffa0std = { | |
collections: { | |
get HashMap() { | |
globalThis.HashMap = class HashMap {}; | |
return undefined; | |
} | |
} | |
} |
This file contains 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
let fizzbuzz = false; | |
function* range() { | |
for (let i=1; i<=100; i++) yield i; | |
} | |
async function fizz() { | |
for (const i of range()) { | |
if (i % 3 === 0) { | |
fizzbuzz=true; | |
process.stdout.write("Fizz"); | |
} |
This file contains 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 numBegArr = ["-", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; | |
const numBegSet = new Set(numBegArr); | |
const isNumericBeginning = char => numBegSet.has(char); | |
const isNumericBeginning2 = char => numBegArr.includes(char); | |
const isNumericBeginning3 = char => | |
char === "-" || | |
char === "0" || | |
char === "1" || | |
char === "2" || |
This file contains 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
type AtLeast<N extends number, T> = AtLeastRec<N, T, T[], []>; | |
type AtLeastRec<Num, Elm, T extends unknown[], C extends unknown[]> = { | |
0: T; | |
1: ((arg: Elm, ...rest: T) => void) extends ((...args: infer T2) => void) | |
? ((arg: unknown, ...rest: C) => void) extends ((...args: infer T3) => void) | |
? AtLeastRec<Num, Elm, T2, T3> | |
: never | |
: never; | |
}[C extends { length: Num } ? 0 : 1]; |
This file contains 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
type Digged<T, Keys extends string[]> = DigFunI<T, (...args: Keys) => void>[0]; | |
interface DigFunI<T, F> extends Array<F extends (()=>void) ? T : | |
F extends ((key: infer K, ...rest: infer Rest) => void) ? | |
K extends keyof T ? (DigFunI<T[K],((...args: Rest)=>void)> extends Array<infer E> ? E : unknown) | |
: unknown : unknown>{ | |
} | |
function dig<T, Keys extends string[]>(obj: T, ...keys: Keys): Digged<T, Keys> { | |
let result: any= obj; |
This file contains 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
// Builderオブジェクトの型 | |
type Builder<Props, Result> = ({} extends Props | |
? { | |
build: () => Result; | |
} | |
: {}) & | |
{ [P in keyof Props]-?: SetFunction<Props, P, Result> }; | |
type SetFunction<Props, K extends keyof Props, Result> = ( | |
value: Exclude<Props[K], undefined> |
NewerOlder