Skip to content

Instantly share code, notes, and snippets.

View mutewinter's full-sized avatar

Jeremy Mack mutewinter

View GitHub Profile
@gaearon
gaearon / 00-README-NEXT-SPA.md
Last active March 28, 2024 09:26
Next.js SPA example with dynamic client-only routing and static hosting

Next.js client-only SPA example

Made this example to show how to use Next.js router for a 100% SPA (no JS server) app.

You use Next.js router like normally, but don't define getStaticProps and such. Instead you do client-only fetching with swr, react-query, or similar methods.

You can generate HTML fallback for the page if there's something meaningful to show before you "know" the params. (Remember, HTML is static, so it can't respond to dynamic query. But it can be different per route.)

Don't like Next? Here's how to do the same in Gatsby.

@steveruizok
steveruizok / useCursor.ts
Last active May 13, 2022 06:25
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 / findSnapPoints.ts
Last active June 23, 2023 01:50
Find the snap points between a bounding box and several other bounding boxes.
interface TLBoundsWithCenter {
minX: number
midX: number
maxX: number
minY: number
midY: number
maxY: number
width: number
height: number
}
@pesterhazy
pesterhazy / indexeddb-problems.md
Last active April 19, 2024 02:40
The pain and anguish of using IndexedDB: problems, bugs and oddities

This gist lists challenges you run into when building offline-first applications based on IndexedDB, including open-source libraries like Firebase, pouchdb and AWS amplify (more).

Note that some of the following issues affect only Safari. Out of the major browsers, Chrome's IndexedDB implementation is the best.

Backing file on disk (WAL file) keeps growing (Safari)

When this bug occurs, every time you use the indexeddb, the WAL file grows. Garbage collection doesn't seem to be working, so after a while, you end up with gigabytes of data.

Random exceptions when working with a large number of indexeddb databases (Safari)

@andrewharvey
andrewharvey / index.md
Last active May 24, 2023 10:21
Comparison of point and box spatial index libraries for JavaScript
Library Static / Dynamic Cartesian / Geographic kNN Index containing points Index containing boxes Within radius
rbush dynamic 🗺️ cartesian ✔️ ✔️
rbush-knn dynamic 🗺️ cartesian ✔️ ✔️ ✔️ ✔️
kdbush static 🗺️ cartesian ✔️ ✔️
geokdbush static 🌏 geo ✔️ ✔️ ✔️
flatbush static 🗺️ cartesian ✔️ ✔️ ✔️ ✔️
geoflatbush static 🌏 geo ✔️ :heavy_che
@darknoon
darknoon / sign_s3_url.sql
Last active March 30, 2022 16:37
A function that lets you sign S3 urls for viewing from within your database queries
-- This function is based on this description:
-- https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html
CREATE OR REPLACE FUNCTION
sign_s3_url(
m_host text,
m_verb text,
m_resource text,
m_region text,
m_key text,
@nijicha
nijicha / install_nodejs_and_yarn_homebrew.md
Last active January 30, 2024 12:14
Install NVM, Node.js, Yarn via Homebrew
@vladholubiev
vladholubiev / aws-lambda-libraries.txt
Last active July 24, 2022 15:51 — forked from gojko/gist:aaea440be880d0162767639f8a6681f9
Libraries available in AWS Lambda
# AWS Lambda `ldconfig -p`, region `us-east-1`, nodejs 8.10 runtime, 22 May 2019, Amazon Linux 2018.03
# See https://github.com/claudiajs/lambda-vm-info for how this was generated and to create an updated version
241 libs found in cache `/etc/ld.so.cache'
libz.so.1 (libc6,x86-64) => /lib64/libz.so.1
libxslt.so.1 (libc6,x86-64) => /usr/lib64/libxslt.so.1
libxshmfence.so.1 (libc6,x86-64) => /usr/lib64/libxshmfence.so.1
libxml2.so.2 (libc6,x86-64) => /usr/lib64/libxml2.so.2
libxcb.so.1 (libc6,x86-64) => /usr/lib64/libxcb.so.1
libxcb-xvmc.so.0 (libc6,x86-64) => /usr/lib64/libxcb-xvmc.so.0
@joshbuchea
joshbuchea / semantic-commit-messages.md
Last active April 25, 2024 16:04
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@aortbals
aortbals / checkStatus.js
Last active April 4, 2017 21:30
Check the status of a fetch response
/**
* Check the status of a fetch response.
*/
export default function checkStatus(response) {
if (response.ok) {
return response;
}
const error = new Error(response.statusText);
error.response = response;