Skip to content

Instantly share code, notes, and snippets.

function generateAllCombinations(listsOfArgs) {
return listsOfArgs.reduce((acc, list) => mix(acc, list), []);
}
function mix(listA, listB) {
if (listA.length === 0) return listB;
if (listB.length === 0) return listA;
const result = [];
@akovalev
akovalev / 00 xdb.ts
Created January 16, 2020 13:41 — forked from rsms/00 xdb.ts
import { EventEmitter } from "./event"
const print = console.log.bind(console)
const _indexedDB = (window.indexedDB
|| window["mozIndexedDB"]
|| window["webkitIndexedDB"]
|| window["msIndexedDB"]) as IDBFactory
export {
whenElementVisible
}
const threshold = [0, 0.25, 0.5, 0.75, 1];
const rootMargin = '40px';
const observer = new window.IntersectionObserver(observerCallback, { threshold, rootMargin });
const callbacks = window.callbacks = new WeakMap();
@akovalev
akovalev / context.js
Last active December 10, 2023 22:41
Happy Eyeballs implementation using Context
// inspired by https://golang.org/pkg/context/
function noop() {
}
function makeBarrier() {
let open;
const whenOpened = new Promise((resolve, reject) => {
open = resolve;
});