Skip to content

Instantly share code, notes, and snippets.

View steveruizok's full-sized avatar
🏠

Steve Ruiz steveruizok

🏠
View GitHub Profile
@steveruizok
steveruizok / findCubicControlPoints.ts
Last active April 13, 2022 01:09
Find the control points for a cubic bezier curve segment from point a to point c passing through point b.
/**
* Find the control points for a cubic segment from point a to point c passing through point b.
* @param a The curve's start point
* @param b The point to curve through
* @param c The curve's end point
*/
export function findCubicControlPoints(
a: { x: number; y: number },
b: { x: number; y: number },
c: { x: number; y: number }
var DBOpenRequest = window.indexedDB.open("keyval-store", 1);
DBOpenRequest.onsuccess = function(event) {
db = DBOpenRequest.result;
var transaction = db.transaction(["keyval"], "readwrite");
var objectStore = transaction.objectStore("keyval");
var objectStoreRequest = objectStore.get("home");
objectStoreRequest.onsuccess = function(event) {
console.log(JSON.stringify(objectStoreRequest.result))
};
};
@steveruizok
steveruizok / Player.js
Last active March 14, 2022 23:50
TypeScript declarations for Warrior.js. (mostly complete)
class Player {
/**
* @param {Warrior} warrior
*/
playTurn(warrior) {
warrior.walk()
}
}
@steveruizok
steveruizok / [...nextauth].ts
Last active May 12, 2022 21:39
Helpers for Github Sponsorware
// pages/api/auth/[...nextauth.ts]
// Follow docs in nextauth
import { isSignedInUserSponsoringMe } from 'utils/github'
import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next'
import NextAuth from 'next-auth'
import GithubProvider from 'next-auth/providers/github'
export default function Auth(
@steveruizok
steveruizok / classes.ts
Last active May 12, 2022 21:39
Stupidly complex TypeScript class solution
type Model<T> = {
[E in keyof T]: unknown;
}
export type DefaultModel = {
[k: string]: unknown;
};
class View<E extends Model<E> = Model<unknown>> {
model: E;
@steveruizok
steveruizok / build.js
Last active February 5, 2022 09:31
esbuild scripts for building packages
/* eslint-disable */
const fs = require('fs')
const path = require('path')
const esbuild = require('esbuild')
const { gzip } = require('zlib')
const { log } = console
const cwd = process.cwd()
const pkg = require(path.join(cwd, 'package.json'))
@steveruizok
steveruizok / README.md
Last active February 10, 2022 12:34
Add undo/redo JSON patches to mobx-utils deepObserve method.
@steveruizok
steveruizok / multiclick.test.ts
Created January 27, 2022 15:12
Tests for multi-clicks.
import { DOUBLE_CLICK } from '~constants'
import { TLTestApp } from './TLTestApp'
jest.useFakeTimers()
describe('When detecting double/triple/quadruple clicks...', () => {
it('Detects a click', () => {
const app = new TLTestApp()
app.onClick = jest.fn()
app.onDoubleClick = jest.fn()
@steveruizok
steveruizok / useCursor.ts
Last active July 15, 2025 04:33
Generate a rotated cursor based on a cursor and rotation.
import { GeomUtils, TLCursor } from '@tldraw/core'
import * as React from 'react'
function getCursorCss(svg: string, r: number, f = false) {
return (
`url("data:image/svg+xml,<svg height='32' width='32' viewBox='0 0 35 35' xmlns='http://www.w3.org/2000/svg'><g fill='none' style='transform-origin:center center' transform='rotate(${r})${
f ? ` scale(-1,-1) translate(0, -32)` : ''
}'>` +
svg.replaceAll(`"`, `'`) +
'</g></svg>") 16 16, pointer'
@steveruizok
steveruizok / getLineLineIntersection.ts
Last active December 5, 2021 12:35
Get the intersection point, if any, between two infinite lines.
export function intersectLineLine(AB: number[][], PQ: number[][]): number[] | undefined {
const slopeAB = AB[0][0] === AB[1][0] ? NaN : (AB[0][1] - AB[1][1]) / (AB[0][0] - AB[1][0])
const slopePQ = AB[0][0] === PQ[1][0] ? NaN : (PQ[0][1] - PQ[1][1]) / (PQ[0][0] - PQ[1][0])
if (slopeAB === slopePQ) return undefined
if (Number.isNaN(slopeAB) && !Number.isNaN(slopePQ)) {
return [AB[0][0], (AB[0][0] - PQ[0][0]) * slopePQ + PQ[0][1]]
}