Skip to content

Instantly share code, notes, and snippets.

tomhicks / promiseSequencer.ts
Last active Jul 5, 2022
Lets you continually push to a "stream" of promises, to be notified of their resolution/rejection, with the guarantee that the resolved values will be emitted in order, skipping any that come back out of order.
View promiseSequencer.ts
type PromiseSequencer<T> = {
* Add a promise to the end of the queue. When this promise resolves, you
* may be notified via onLatest, assuming that no later promise has resolved
* in the meantime.
push(promise: Promise<T>): void;
* Remove all promises from the queue. Any promises in the queue can still
tomhicks / useScreenShare.ts
Created Mar 17, 2021
How splitting useEffect calls simplifies code, and reduces bugs
View useScreenShare.ts
// ATTEMPT 1 - everything in one useEffect
React.useEffect(() => {
if (screenVideoTrack) {
} else {
// 🐞 called before share, on mount
// 🐞 called even if screen was never shared
tomhicks / useTaskQueue.ts
Created Jan 11, 2021
React Hook for queueing and processing async tasks sequentially
View useTaskQueue.ts
function useTaskQueue(params: {
shouldProcess: boolean
}): {
tasks: ReadonlyArray<Task>
isProcessing: boolean
addTask: (task: Task) => void
} {
const [queue, setQueue] = React.useState<{
isProcessing: boolean
tasks: Array<Task>
tomhicks / InternalLink.tsx
Created Jul 24, 2020
Strongly-typed NextJS internal links
View InternalLink.tsx
tomhicks /
Created Feb 20, 2020
Node 12 node-svm fix
#include "node-svm.h"
#include "training-worker.h"
#include "prediction-worker.h"
#include "probability-prediction-worker.h"
using v8::FunctionTemplate;
using v8::Object;
using v8::String;
using v8::Array;
tomhicks / sweep-swoop.js
Last active Dec 10, 2021
Listen to your web pages
View sweep-swoop.js
const audioCtx = new window.AudioContext();
const oscillator = audioCtx.createOscillator();
oscillator.type = "sine";
let numItems = 0
tomhicks / plink-plonk.js
Last active Jun 11, 2022
Listen to your web pages
View plink-plonk.js
View SpoingyScrollView.tsx
import * as React from "react"
import {captureScroll, getSpoingyTransform} from "spoingyHelpers"
import {Animated} from "react-native"
const headerHeight = 300
export default () => {
// use an instance variable if using component classes
const scrollY = React.useRef(new Animated.Value(0)).current
tomhicks / spoingyHeaders.ts
Created Jun 20, 2019
Bouncy header helper functions
View spoingyHeaders.ts
import {Animated} from "react-native"
export function getSpoingyTransform(
scrollY: Animated.Value,
headerHeight: number,
) {
return [
translateY: scrollY.interpolate({
inputRange: [-headerHeight, 0, 1],