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 randomUint32 = () => (Math.random() * 2 ** 32) >>> 0; | |
const merge = (operations) => { | |
const result = []; | |
for (const operation of operations) { | |
switch (operation.kind) { | |
case "insert": { | |
if (!result[operation.position]) { | |
result[operation.position] = operation; |
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
/** | |
* Generate set of permutations for given length. | |
*/ | |
function* permute(len) { | |
if (len <= 0 || len > 10) throw "argument must be in range 0..10"; | |
function* go(n, permutation, members) { | |
if (n === 0) { | |
yield permutation; | |
} else { |
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
// hack | |
const f1 = (n) => String(n).length; | |
// log10 | |
const f2 = (n) => Math.floor(Math.log10(n) + 1); | |
// recursive | |
const f3 = (n) => { | |
if (n < 10) return 1; | |
return 1 + fc(n / 10); |
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
--- /etc/ssl/openssl.cnf~original 2022-03-16 08:35:51.000000000 +0000 | |
+++ /etc/ssl/openssl.cnf 2022-05-04 02:37:30.336530711 +0000 | |
@@ -56,6 +56,7 @@ | |
# List of providers to load | |
[provider_sect] | |
default = default_sect | |
+legacy = legacy_sect | |
# The fips section name should match the section name inside the | |
# included fipsmodule.cnf. | |
# fips = fips_sect |
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 flatten = object => { | |
const result = {}; | |
const go = (curr, parents) => { | |
Object.entries(curr).forEach(([key, value]) => { | |
const path = [...parents, key]; | |
if (value !== null && typeof value === 'object') { | |
go(value, path); | |
} else { | |
result[path.join('.')] = value; | |
} |
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 swap = (items, first, second) => { | |
const tmp = items[first]; | |
items[first] = items[second]; | |
items[second] = tmp; | |
}; | |
const partition = (items, left, right) => { | |
const pivot = items[Math.trunc((right + left) / 2)]; | |
while (left <= right) { |
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 observers = []; | |
const call = f => f(); | |
const callAll = x => () => x.forEach(call); | |
let t; | |
const notify = () => { | |
clearTimeout(t); | |
t = setTimeout(callAll(observers), 0); |
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
import { useLayoutEffect, useRef, useState } from 'react'; | |
export type Dispose = () => void | undefined; | |
export type Disposable<T> = { | |
instance: T; | |
dispose: Dispose; | |
}; | |
export type Factory<Arguments extends Tuple, Instance> = ( |
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
import assert from "assert"; | |
import { Option, isSome, none, some } from '@keiii/k-stream'; | |
const range = ( | |
[a, b]: [number, number], | |
inclusive = false | |
): Iterable<number> => { | |
assert(b >= a, "Invalid range"); | |
const isDone = inclusive ? (x: number) => x > b : (x: number) => x >= b; | |
return { |
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
/** | |
* @link https://bugs.chromium.org/p/v8/issues/detail?id=3547 | |
* @link https://github.com/nodejs/node/issues/33306 | |
*/ | |
const oldTimezoneOffsetFix = (d: Date): number => { | |
const ms = d.getTime(); | |
if (isNaN(ms)) return 0; | |
const utc = new Date(d.toISOString().slice(0, -1)).getTime(); | |
const offset = d.getTimezoneOffset() * 60_000; | |
return ms - utc + offset; |
NewerOlder