Skip to content

Instantly share code, notes, and snippets.

View nfarina's full-sized avatar

Nick Farina nfarina

View GitHub Profile
#!/bin/bash
#
# Backs up my entire website, in case Tumblr or CloudApp goes down someday.
# Last time I ran this, it took 18 minutes.
#
wget \
--mirror `# turns on recursion and timestamping, basically says we want to "mirror" the whole site` \
--convert-links `# after download, convert all links to point to localhost` \
@nfarina
nfarina / useResettableState.ts
Created August 6, 2021 16:24
A version of React's `useState` that resets the value to initial whenever the given dependency array changes. Very helpful when you need to reset some internal state as the result of getting new props.
import { DependencyList, Dispatch, SetStateAction, useState } from "react";
/**
* This is like useState() but with the added feature of returning the initial
* value whenever the dependency list changes. This is super useful for allowing
* components to "reset" some internal state as a result of getting new props.
*/
export function useResettableState<S>(
initial: S | (() => S),
deps: DependencyList,
'Declare statements
DECLARE SUB playGame ()
DECLARE SUB setParms ()
DECLARE SUB clearTanks ()
DECLARE SUB checkGround ()
DECLARE SUB explodeTank ()
DECLARE SUB fireShotRight ()
DECLARE SUB fireShotLeft ()
DECLARE SUB getInfoRight ()
@nfarina
nfarina / stripeiterators.ts
Last active January 5, 2023 22:56
Helpful utility functions for iterating objects from the Stripe API using new async iterators
import Stripe from "stripe";
/**
* Utility functions for iterating objects from the Stripe API.
*/
/**
* Iterates over a Stripe API list, automatically handling pagination.
*
@nfarina
nfarina / package.json
Created March 15, 2024 16:34
Reproduction of `tsc --watch` not working
{
"name": "tsc-test",
"version": "1.0.0",
"description": "tsc watch problem repro",
"license": "ISC",
"scripts": {
"start": "tsc test.ts --watch"
},
"dependencies": {
"typescript": "^5.4.2"
@nfarina
nfarina / worker.js
Created August 8, 2024 17:44
Our solution for hosting and transforming images stored in Firebase Storage, using Cloudflare Image Transformations. It's fast (~11ms per request for us) and cheap ($0.50 per million images served through Cloudflare). Modify as needed.
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
// Our images are immutable, so we can cache them forever.
const ONE_YEAR = 31536000;
const CACHE_CONTROL = `public, max-age=${ONE_YEAR}, immutable`
// One way (the most efficient way) to get the raw images is to fetch them
// directly from the underlying Google Cloud Storage bucket. But that requires
@nfarina
nfarina / eslint-plugin-react-compiler.js
Created October 28, 2024 20:23
React Compiler ESLint Plugin with all errors surfaced
import * as BabelParser from "@babel/parser";
import BabelTraverse from "@babel/traverse";
import {
compileProgram,
parsePluginOptions,
} from "babel-plugin-react-compiler";
const traverse = BabelTraverse["default"];
const parse = BabelParser.parse;