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 { useCallback, useEffect } from 'react'; | |
function useDebounceEffect( | |
effect: () => void, | |
delay: number | undefined, | |
deps: any[] | |
) { | |
const callback = useCallback(effect, deps); | |
useEffect(() => { |
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
type JobFunction<T> = () => Promise<T>; | |
async function promiseAll<T>( | |
jobs: JobFunction<T>[], | |
concurrency: number = Infinity, | |
): Promise<T[]> { | |
const results: T[] = new Array(jobs.length).fill(0); | |
const queue = new Array(concurrency).fill(Promise.resolve()); | |
// const queue = jobs.splice(0, concurrency).map((fn: JobFunction<T>) => | |
// fn().then((result: 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 User { | |
id: number; | |
} | |
const storageCache = new Map<number, Promise<User>>(); | |
function fetchUser(id: number): Promise<User> { | |
console.log('id', id) | |
return new Promise((res) => { | |
setTimeout(() => res({ id }), 2000); |
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 versions = [ | |
"0.4", | |
"0.11", | |
"0.4.1", | |
"0.4", | |
"0.4.2", | |
"2.0.1", | |
"2", | |
"0.0.1", | |
"0.2.3", |
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
node ./none-memo && node ./memo | |
none_memo: 10.005s | |
memo: 989.782ms | |
node ./none-memo && node ./memo | |
none_memo: 9.897s | |
memo: 974.547ms | |
node ./none-memo && node ./memo | |
none_memo: 9.953s |
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
// Here is our log file; essentially a list of tuples. | |
// Each tuple has two items: `(request_path, user_id)` | |
const logFile = [ | |
["/", "user_1"], | |
["/about", "user_1"], | |
["/", "user_3"], | |
["/features", "user_1"], | |
["/about", "user_2"], | |
["/purchase", "user_2"], | |
["/purchase", "user_1"], |
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 APLHA_MOD = 26; | |
const nt = (n = 0) => ((n % APLHA_MOD) + 10).toString(APLHA_MOD + 10); | |
const ct = (n = 0, acc = "") => { | |
if (n - APLHA_MOD > 0) { | |
return ct(n - APLHA_MOD, acc + nt(APLHA_MOD)); | |
} | |
return acc + nt(n); | |
}; |
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 _get = require('lodash.get') | |
const _isEmpty = require('lodash.isempty') | |
const _sumBy = require('lodash.sumby') | |
const _max = require('lodash.max') | |
const _flatten = require('lodash.flatten') | |
const _last = require('lodash.last') | |
const _size = require('lodash.size') | |
const _first = require('lodash.first') | |
const _map = (arr = [], fn) => Array.from(arr).map(fn) |
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 assert = require('assert') | |
const debug = require('debug')('app:aws-sqs') | |
const { | |
SQSClient, | |
DeleteMessageCommand, | |
SendMessageCommand, | |
ReceiveMessageCommand, | |
} = require('@aws-sdk/client-sqs') | |
const { pack } = require('./utils-data') |
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
/* eslint-disable indent */ | |
/** | |
* Create a promise wrapper for function(err, arg1, ...argN) | |
* @param {function} fn - Function that should be promisified | |
* @returns {function} - Promisified function fn wrapper | |
* @example <caption>Example usage of promisify.</caption> | |
* const asynFn = require(...) // asynFn((err, a, b) => { ... }) | |
* const pMyFn = promisify(asynFn) | |
* console.log('asynFn result', await pMyfn(1, 2)) |