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 HeadingNode = { | |
element: HTMLHeadingElement; | |
children: HeadingNode[]; | |
}; | |
function createHeadingTree(): HeadingNode[] { | |
const root: HeadingNode[] = []; | |
const stack: HeadingNode[] = []; | |
for (const heading of document.querySelectorAll<HTMLHeadingElement>( |
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
# Install VMware Workstation Pro 16.2.3 on Fedora 36 | |
# Install packages to build kernel modules | |
sudo dnf install @development-tools | |
sudo dnf install kernel-headers-$(uname -r) kernel-devel-$(uname -r) dkms elfutils-libelf-devel qt5-qtx11extras | |
# Download VMware Workstation Pro here: https://www.vmware.com/go/getworkstation-linux | |
# Install VMware Workstation Pro | |
chmod +x VMware-Workstation-Full-16.2.3-19376536.x86_64.bundle |
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 * as React from 'react'; | |
import { render, screen } from '@testing-library/react'; | |
import { createMemoryHistory } from 'history'; | |
import { IonRedirect, IonRoute, IonRouterOutlet } from '@ionic/react'; | |
import { IonReactRouter } from '@ionic/react-router'; | |
import '@testing-library/jest-dom'; | |
// Using `IonRouterOutlet` here will make `jsdom` render the following DOM tree: | |
// <body> |
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 nthDay = (n, year) => { | |
const firstDay = new Date(`${year}`); | |
const newDay = new Date(firstDay.getTime()); | |
newDay.setDate(firstDay.getDate() + n); | |
return newDay; | |
}; | |
const isLeapYear = (year) => | |
((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 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
const DEFAULT_MAX_CONCURRENT_PROMISES = 5; | |
/** | |
* Runs a stream of promises and ensures only `max` promises are run at a time | |
* @param {*} promiseRunnerGen | |
* @param {*} max | |
*/ | |
const run = (promiseRunnerGen, max = DEFAULT_MAX_CONCURRENT_PROMISES) => { | |
const iterator = promiseRunnerGen(); | |
let runningPromiseCount = 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
let runningPromiseCount = 0; | |
const examplePromiseRunnerQueue = new Array(10) | |
.fill(0) | |
.map((_, idx) => idx) | |
.map((idx) => { | |
return async () => { | |
console.log( | |
`[${new Date().toISOString()}] Promise ${idx} will run! \n# of running promises: ${runningPromiseCount}` | |
); |
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 _ from 'lodash'; | |
const isPlainObject = value => | |
value === Object(value) && | |
!Array.isArray(value); | |
function* leaves(node, path = []) { | |
if (!isPlainObject(node)) { | |
return yield {value: node, path}; |
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 memoizeFactory = hashFn => fn => { | |
const memoize = fn => { | |
const cache = {}; | |
return (...args) => { | |
const key = hashFn(args); | |
if (key in cache) { | |
return cache[key]; | |
} |
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
/** | |
* Transforms a function of the form: | |
* fn = (p1, ..., pN) => f(p1, ...pN) | |
* to its curried form: | |
* curried = p1 => p2 => ... => pN => fn(p1, p2, ..., pN); | |
* | |
* @param fn | |
* @returns the curried form of fn | |
*/ | |
const curry = fn => |
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
/** | |
* Initializes an empty sieve | |
* | |
* @returns {{primes: Set<number>, crossed: Set<number>, greatestComputedMultiples: Map<number, number>}} | |
*/ | |
const createSieve = () => ({ | |
primes: new Set(), | |
crossed: new Set(), | |
greatestComputedMultiples: new Map(), // `prime` -> greatest computed multiple for `prime` | |
}); |
NewerOlder