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
<script lang="ts"> | |
/// ... | |
import { customStoreDebouncer /*, storeDebouncer */ } from "./stores/stringStore"; | |
const stringStoreDebounced = customStoreDebouncer(400); // debounced store read | |
$: { | |
const text = $stringStoreDebounced; // resolved value, after debounce timeout | |
/// ... | |
} | |
</script> |
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
// SEE: https://github.com/yakovkhalinsky/backblaze-b2/issues/118 | |
import { | |
S3Client, | |
PutObjectCommand, | |
// S3ClientConfig, | |
// DeleteObjectCommand, | |
} from "@aws-sdk/client-s3"; | |
const region = process.env.B2_REGION; |
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
export const assign = (...objs) => Object.assign({}, ...objs) | |
export const assign2 = (...objs) => { | |
objs.unshift({}); | |
let len = objs.length; | |
while (--len > 0) | |
for (let i in objs[len]) | |
objs[0][i] = objs[len][i] | |
return objs[0] | |
} | |
// no spread operator overhead, raw arguments access, obj[0] *is* mutated! |
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
(function (root, factory) { | |
if(typeof define === "function" && define.amd) { | |
// Now we're wrapping the factory and assigning the return | |
// value to the root (window) and returning it as well to | |
// the AMD loader. | |
define(["postal"], function(postal){ | |
return (root.myModule = factory(postal)); | |
}); | |
} else if(typeof module === "object" && module.exports) { | |
// I've not encountered a need for this yet, since I haven't |
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
body, .grid-wrapper { | |
height: 100vh; | |
padding: 0; | |
margin: 0; | |
} | |
.grid-wrapper { | |
display: grid; | |
grid-template-columns: minmax(0, 200px) minmax(80vw, 1fr); | |
grid-template-rows: auto 1fr auto; |
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
export function cacher<T>(thunk: () => Promise<T>, ttlSeconds = 60) { | |
const noCache: unique symbol = Symbol("cache"); | |
let cache: Promise<T> | symbol = noCache; | |
return function execThunk(): Promise<T> { | |
if (typeof cache !== "symbol") { | |
return cache; | |
} | |
cache = thunk(); |
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 { useCallback, useEffect, useMemo, useRef, useState } from "react"; | |
interface ScrollTrackerResult { | |
isScrollable: boolean; | |
isAtTop: boolean; | |
isAtBottom: boolean; | |
} | |
function useScrollTracker(ref: React.RefObject<HTMLElement>): ScrollTrackerResult { | |
const [isScrollable, setIsScrollable] = useState(false); |
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 React from "react"; | |
import ReactDOM from "react-dom"; | |
import { Tooltip, Popper, TooltipProps } from "@mui/material"; | |
import { styled } from "@mui/material/styles"; | |
const StyledPopper = styled(Popper)({ | |
padding: "1rem", // offset for larger arrow size | |
"& .MuiTooltip-tooltip": { | |
backgroundColor: "white", |
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 { Timeout, TimeoutError } from "https://deno.land/x/timeout/mod.ts" | |
const delay = (ms) => new Promise((res) => setTimeout(res, ms)); | |
function newThrottler({ isBusy, lock, unlock, waitMs, size }) { | |
async function throttler(cb, ...args) { | |
size(1); | |
await Promise.resolve(); | |
while (!!isBusy()) { | |
await delay(waitMs()); // waits in event loop queue, until it interrupts for another attempt! |
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
function chunkedMergeSort(arr, callback) { | |
function merge(left, right, arr, callback) { | |
let i = 0; | |
let j = 0; | |
let k = 0; | |
function mergeStep() { | |
while (i < left.length && j < right.length) { | |
if (left[i] <= right[j]) { | |
arr[k++] = left[i++]; |
NewerOlder