Skip to content

Instantly share code, notes, and snippets.

View steveruizok's full-sized avatar
🏠

Steve Ruiz steveruizok

🏠
View GitHub Profile
@steveruizok
steveruizok / getComponents.js
Last active July 16, 2023 22:37
Get components and styles (as full nodes) from a Figma file.
async function getComponents(fileKey, token) {
// Get file
const file = await fetch(`https://api.figma.com/v1/files/${fileKey}`, {
headers: { "X-Figma-Token": token }
}).then((r) => r.json())
if (file.err === undefined) {
// Get style ids
const styleIds = Object.keys(file.styles)
@steveruizok
steveruizok / getCornerResizer.ts
Last active May 13, 2022 06:30
Resizing boxes by corner.
interface Box {
x: number
y: number
w: number
h: number
maxX: number
maxY: number
}
interface BoxWithId extends Box {
@steveruizok
steveruizok / circleFromThreePoints.ts
Created December 12, 2020 12:27
Circle from three points.
// This is a very fast implementation.
const det = (
a: number,
b: number,
c: number,
d: number,
e: number,
f: number,
g: number,
h: number,
@steveruizok
steveruizok / results.json
Created December 11, 2020 16:12
result of figma api request
{
"document": {
"id": "0:0",
"name": "Document",
"type": "DOCUMENT",
"children": [
{
"id": "0:1",
"name": "Page 1",
"type": "CANVAS",
@steveruizok
steveruizok / example.tsx
Last active December 2, 2020 03:48
A utility function for getting the type-asserted value of a ref in React.
import * as React from "react"
import { getRef } from "./getRef"
export default function App() {
const rCanvas = React.useRef<HTMLCanvasElement>(null)
React.useEffect(() => {
const canvas = getRef(rCanvas)
canvas.width = window.innerWidth
canvas.width = window.innerHeight
@steveruizok
steveruizok / .env.local
Last active March 14, 2023 19:20
Next.js SSR firebase auth
NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY=your_firebase_email
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_firebase_auth_domain
NEXT_PUBLIC_FIREBASE_DATABASE_URL=your_firebase_database_url
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
NEXT_PUBLIC_BASE_API_URL=http://localhost:3000
NEXT_PUBLIC_SERVICE_ACCOUNT=your_config_json_converted_to_base64
NEXT_PUBLIC_COOKIE_NAME=auth
@steveruizok
steveruizok / auth.ts
Created November 26, 2020 21:17
Client Firebase Auth State Designer
// refresh reset
import router from "next/router"
import { createState } from "@state-designer/core"
import firebase from "firebase/app"
import "firebase/auth"
import * as Types from "types"
const config = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
@steveruizok
steveruizok / GraphState.ts
Created November 21, 2020 15:02
Graph State
import * as React from "react"
import { S } from "@state-designer/core"
import { useStateDesigner } from "./useStateDesigner"
const EventList: React.FC<{
state: S.State<any, any>
}> = ({ state }) => {
function getEvents(state: S.State<any, any>): string[] {
const localEvents: string[] = []
@steveruizok
steveruizok / render-state.js
Last active November 17, 2020 14:01
Render a State Designer state in the terminal.
import log from "ololog"
class Grid {
rows = []
width = 0
height = 0
chars = {
active: ["┌", "─", "┒", "┃", "┛", "━", "┕", "│"],
inactive: ["┌", "─", "┐", "│", "┘", "─", "└", "│"],
@steveruizok
steveruizok / distributeEvenly.ts
Last active November 23, 2020 19:01
A function to distribute boxes evenly along either the x or y axis.
function distributeEvenly<
T extends { x: number; y: number; height: number; width: number }
>(axis: "x" | "y", boxes: T[]) {
const mboxes = [...boxes]
const extent = axis === "x" ? "width" : "height"
mboxes.sort((a, b) => a[axis] - b[axis])
// Overall boxes span
const last = mboxes[mboxes.length - 1]
const dist = last[axis] + last[extent] - mboxes[0][axis]