View Example 2.ts
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 mode: "idle" | "dragging" = "idle" | |
const dragHandler: InteractionHandler = { | |
onDragStart(gesture, app) { | |
if (intersection(gesture.elementsUnderCursor, app.selectedElements).size) { | |
mode = "dragging"; | |
} | |
}, | |
onPointerMove(gesture) { | |
// ignore pointer-moves when we haven't started dragging |
View ChakraColorModeComponents.tsx
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 {ChakraProvider, useColorMode} from "@chakra-ui/react" | |
import {Html} from "next/document" | |
import React from "react" | |
type ColorMode = "light" | "dark" | |
export function ChakraThemedHtmlComponent(props: { | |
colorMode: ColorMode | |
children: React.ReactNode | |
}) { | |
return ( |
View promiseSequencer.ts
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 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 |
View useTaskQueue.ts
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 useTaskQueue(params: { | |
shouldProcess: boolean | |
}): { | |
tasks: ReadonlyArray<Task> | |
isProcessing: boolean | |
addTask: (task: Task) => void | |
} { | |
const [queue, setQueue] = React.useState<{ | |
isProcessing: boolean | |
tasks: Array<Task> |
View InternalLink.tsx
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 {InternalRoutes} from "types/routes" | |
import Link, {LinkProps} from "next/link" | |
export function InternalLink({ | |
routeName, | |
routeParams, | |
...linkProps | |
}: Omit<LinkProps, "href" | "as"> & | |
InternalRoutes & {children: React.ReactChild}) { |
View node-svm.cc
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
#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; |
View sweep-swoop.js
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 audioCtx = new window.AudioContext(); | |
const oscillator = audioCtx.createOscillator(); | |
oscillator.connect(audioCtx.destination); | |
oscillator.type = "sine"; | |
let numItems = 0 | |
oscillator.frequency.setValueAtTime( | |
1, | |
audioCtx.currentTime |
View plink-plonk.js
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
/* | |
Copy this into the console of any web page that is interactive and doesn't | |
do hard reloads. You will hear your DOM changes as different pitches of | |
audio. | |
I have found this interesting for debugging, but also fun to hear web pages | |
render like UIs do in movies. | |
*/ | |
const audioCtx = new (window.AudioContext || window.webkitAudioContext)() |
View SpoingyScrollView.tsx
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 {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 |
NewerOlder