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
export async function runConcurrentAsync<T, A extends IterableIterator<unknown>>(tasks: Task<T>[], argsList: A[] = [], concurrency = 5): Promise<T[]> { | |
const semaphore = new Semaphore(concurrency); | |
const promises = tasks.map(async (task, index) => { | |
await semaphore.acquire(); | |
try { | |
const args = argsList[index] || []; | |
return await task(...args); | |
} finally { | |
semaphore.release(); | |
} |
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
export async function fetchAll(urls: string[], concurrency = 5, retryPolicy = defaultRetryPolicy): Promise<Response[]> { | |
const controller = new AbortController(); | |
const semaphore = new Semaphore(concurrency); | |
const promises = urls.map(async url => { | |
await semaphore.acquire(); | |
try { | |
return await fetchWithRetry(url, retryPolicy, controller.signal); | |
} catch (error) { | |
controller.abort(); // abort all requests on fatal error | |
throw error; |
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
/* | |
You are given an integer n representing the length of an unknown array that you are trying to recover. You are also given an array sums containing the values of all 2n subset sums of the unknown array (in no particular order). | |
Return the array ans of length n representing the unknown array. If multiple answers exist, return any of them. | |
An array sub is a subset of an array arr if sub can be obtained from arr by deleting some (possibly zero or all) elements of arr. The sum of the elements in sub is one possible subset sum of arr. The sum of an empty array is considered to be 0. | |
Note: Test cases are generated such that there will always be at least one correct answer. | |
Constraints: |
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
from cards import Card, Deck | |
MENU ='''Prompt the user for an option and check that the input has the | |
form requested in the menu, printing an error message, if not. | |
Return: | |
TT s d: Move card from end of Tableau pile s to end of pile d. | |
TF s d: Move card from end of Tableau pile s to Foundation d. | |
WT d: Move card from Waste to Tableau pile d. | |
WF d: Move card from Waste to Foundation pile d. | |
SW : Move card from Stock to Waste. |
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
<?php | |
class BlacklistItem { | |
private $value; | |
public function __construct($string) { | |
$string = trim($string); | |
if (self::isValid($string)) { | |
$this->value = $string; | |
} else { | |
throw new \InvalidArgumentException('$string must be a valid IP address, email, country, or web domain.'); |
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
/** | |
* Convert a file size with unit to bytes | |
* | |
* @author Travis Aaron Wagner <[email protected]> | |
* @param {string} size File size with unit (e.g. 50MB) | |
* @returns {number} File size in bytes as number | |
*/ | |
const getBytes = size => { | |
const matches = String(size).toLowerCase().replace(/[\s,]+/g, '').match(/([^a-z]+)([^\d.])/) || []; | |
return matches[2] ? matches[1] * (1024 ** ('kmgtpezy'.indexOf(matches[2]) + 1)) : Number(size); |
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
/** | |
* Convert a file size with unit to bytes | |
* | |
* @author Travis Aaron Wagner <[email protected]> | |
* @param {string} size File size with unit (e.g. 50MB) | |
* @returns {number} File size in bytes as number | |
*/ | |
const getBytes = size => { | |
const matches = size.toLowerCase().replace(/[\s,]+/g, '').match(/([^a-z]+)([^\d.])/) || []; | |
return matches[2] ? matches[1] * (1024 ** ('kmgtpezy'.indexOf(matches[2]) + 1)) : Number(size); |
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
<div class="container"> | |
<div class="row justify-content-center"> | |
<div class="col-md-8"> | |
<div class="row"> | |
<a href="#" class="col-sm-4" data-bs-toggle="modal" data-bs-target="#exampleLightbox"> | |
<img data-bs-target="#lightboxExampleCarousel" data-bs-slide-to="0" src="https://unsplash.it/200.jpg?image=250" class="img-fluid"> | |
</a> | |
<a href="#" class="col-sm-4" data-bs-toggle="modal" data-bs-target="#exampleLightbox"> | |
<img data-bs-target="#lightboxExampleCarousel" data-bs-slide-to="1" src="https://unsplash.it/200.jpg?image=251" class="img-fluid"> | |
</a> |
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 BuildPowersOf2LengthArrays<N extends number, R extends never[][]> = | |
R[0][N] extends never ? R : BuildPowersOf2LengthArrays<N, [[...R[0], ...R[0]], ...R]>; | |
type ConcatLargestUntilDone<N extends number, R extends never[][], B extends never[]> = | |
B["length"] extends N ? B : [...R[0], ...B][N] extends never | |
? ConcatLargestUntilDone<N, R extends [R[0], ...infer U] ? U extends never[][] ? U : never : never, B> | |
: ConcatLargestUntilDone<N, R extends [R[0], ...infer U] ? U extends never[][] ? U : never : never, [...R[0], ...B]>; | |
type Replace<R extends any[], T> = { [K in keyof R]: 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
/** | |
* Update CSS variables --vh and --vh to be accurate taking mobile browser address and bottom action bars into consideration. | |
* | |
* @author Travis Aaron Wagner <[email protected]> | |
*/ | |
let wHSaved = Math.min(window.innerHeight, window.outerHeight); | |
let wWSaved = Math.min(window.innerWidth, window.outerWidth); | |
/** |