Skip to content

Instantly share code, notes, and snippets.

View steveruizok's full-sized avatar
🏠

Steve Ruiz steveruizok

🏠
View GitHub Profile
@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 }
@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.