Skip to content

Instantly share code, notes, and snippets.

View steveruizok's full-sized avatar
🏠

Steve Ruiz steveruizok

🏠
View GitHub Profile
@steveruizok
steveruizok / en.json
Created April 2, 2023 19:05
tldraw keys
{
"action.convert-to-bookmark": "Convert to Bookmark",
"action.convert-to-embed": "Convert to Embed",
"action.open-embed-link": "Open link",
"action.align-bottom": "Align bottom",
"action.align-center-horizontal": "Align horizontally",
"action.align-center-vertical": "Align vertically",
"action.align-center-horizontal.short": "Align H",
"action.align-center-vertical.short": "Align V",
"action.align-left": "Align left",
@steveruizok
steveruizok / embeds.ts
Last active March 6, 2023 11:04
tldraw beta embeds
type EmbedDefinition = {
type: string
title: string
hostnames: string[]
minWidth?: number
minHeight?: number
width: number
height: number
doesResize: boolean
isAspectRatioLocked?: boolean
@steveruizok
steveruizok / tldraw-pre-seed.txt
Created November 28, 2022 15:55
Pre-seed investors in tldraw.
Lux Capital (lead)
Amplify Partners
Sabrina Hahn
Guillermo Rauch, founder Vercel
Liu Jiang
NP-Hard Ventures
Badrul Farooqi
Soleio Cuervo
Tom Preston-Werner, co-founder Github
Adam Wiggins, founder Ink and Switch, Muse
@steveruizok
steveruizok / visibility-polygon.ts
Created November 21, 2022 23:49
Get a visibility polygon (for shadow casting).
// segments are all of the segments in all of the shapes in the scene
// point is light point
// viewport is top left, top right, bottom right, bottom left
function getVisibilityPolygon(segments: Segment[], point: Point, viewport: Point[]) {
const brokenSegments: Segment[] = []
const viewportMinCorner = viewport[0]
const viewportMaxCorner = viewport[2]
@steveruizok
steveruizok / app.animatecamera.ts
Last active November 16, 2022 18:39
Animate camera
animateCamera = (
x: number,
y: number,
z: number,
opts = {} as { duration: number; ease: (t: number) => number }
) => {
const { duration = 1000 } = opts
const { center } = this.viewport
const currCenter = new Vec2d(center.x, center.y, this.camera.z)
const nextCenter = new Vec2d(x, y, z)
@steveruizok
steveruizok / intersectSets.ts
Created October 30, 2022 20:10
Combine multiple sets into a single set containing only the common elements of all sets.
export function intersectSets<T>(sets: Set<T>[]) {
if (sets.length === 0) return new Set<T>()
const first = sets[0]
const rest = sets.slice(1)
const result = new Set<T>()
for (const val of first) {
if (rest.every((set) => set.has(val))) {
result.add(val)
}
@steveruizok
steveruizok / cache.ts
Last active May 8, 2025 03:01
weak map gist
export class Cache<T extends object, K> {
items = new WeakMap<T, K>()
get<P extends T>(item: P, cb: (item: P) => K) {
if (!this.items.has(item)) {
this.items.set(item, cb(item))
}
return this.items.get(item)!
}
@steveruizok
steveruizok / arcs.ts
Last active September 7, 2022 10:23
TypeScript methods for calculating arcs.
const TAU = Math.PI / 2
const PI2 = Math.PI * 2
interface VecLike {x: number, y: number }
/**
* Get info about an arc formed by three points.
*
* @param a The start of the arc
* @param b A point on the arc
@steveruizok
steveruizok / export.ts
Created May 11, 2022 08:29
tldraw export endpoint on next.js with chrome-aws-lambda
import { NextApiRequest, NextApiResponse } from 'next'
import chromium from 'chrome-aws-lambda'
import Cors from 'cors'
import { TDExport, TDExportTypes, TldrawApp } from '@tldraw/tldraw'
// NOTE: You might have to downgrade puppeteer etc in order to fit under the endpoint size limit of 50mb.
const cors = Cors({
methods: ['POST'],
})
@steveruizok
steveruizok / getQuadraticControlPoint.ts
Created April 12, 2022 12:33
Find the control points for a quadratic bezier curve segment from point a to point c passing through point b.
/**
* Find the control points for a quadratic segment from point a to point c passing through point b.
* @param a The segments's first point
* @param b The point to curve through
* @param c The segment's end point
*/
export function getQuadraticControlPoints(
a: { x: number; y: number },
b: { x: number; y: number },
c: { x: number; y: number }