Skip to content

Instantly share code, notes, and snippets.

View t3dotgg's full-sized avatar

Theo Browne t3dotgg

View GitHub Profile
@t3dotgg
t3dotgg / useChromeStorage.js
Created February 2, 2020 05:11
Custom hook to use Chrome's sync storage api as a stateful variable store. Drop-in replacement for useState
const useChromeStorage = (key, initialValue) => {
const [storedValue, setStoredValue] = useState(() => {
chrome.storage.sync.get([key], result => {
if (result && result[key] !== undefined) {
setStoredValue(result[key]);
} else {
chrome.storage.sync.set({ [key]: initialValue }, () => {});
}
});
return initialValue;

Keybase proof

I hereby claim:

  • I am theobr on github.
  • I am nottheo (https://keybase.io/nottheo) on keybase.
  • I have a public key ASAA3CySsM7igLpj__FeNQ98lPL_UwG7BXam_pVAlwWYzQo

To claim this, I am signing this object:

diff --git a/node_modules/pubnub-react/.DS_Store b/node_modules/pubnub-react/.DS_Store
new file mode 100644
index 0000000..c31aa91
Binary files /dev/null and b/node_modules/pubnub-react/.DS_Store differ
diff --git a/node_modules/pubnub-react/dist/.DS_Store b/node_modules/pubnub-react/dist/.DS_Store
new file mode 100644
index 0000000..5008ddf
Binary files /dev/null and b/node_modules/pubnub-react/dist/.DS_Store differ
diff --git a/node_modules/pubnub-react/dist/pubnub-react.cjs.development.js b/node_modules/pubnub-react/dist/pubnub-react.cjs.development.js
index 8017ac7..20b50d8 100644
@t3dotgg
t3dotgg / persisted-synced-atom.ts
Last active June 24, 2021 19:07
A pattern for persisting and syncing an atom's value in Jotai
import { atom, useAtom } from "jotai";
const atomWithSyncedLocalStorage = <T>(key: string, initialValue: T) => {
const baseAtom = atom(initialValue);
baseAtom.onMount = (setValue) => {
const storageUpdateListener = (e: StorageEvent) => {
if (e.key === key) {
console.log("Updating instance of ", key, " remotely");
setValue(e.newValue ? JSON.parse(e.newValue) : undefined);
}
@t3dotgg
t3dotgg / proposal.jsx
Created July 12, 2021 00:25
A proposal for a `useBackend` React hook that is compiled out into an API route. Inspired by Vercel and Next.js
// /pages/index.tsx
function ExamplePage() {
const { data } = useBackend(
"get-user-info",
async () => {
const data = await getProfileFromDB();
return data; // {name: string}
},
{ prefetch: true }
export const useGetUserProfile = (userId: string) => {
return useQuery(["user-profile", userId], async () => {
return await fetch("/user/"+userId);
});
}
@t3dotgg
t3dotgg / .env
Created November 25, 2021 06:59
Recommended .env for PScale local dev
DATABASE_URL="mysql://[email protected]:3309/roundest-mon"
SHADOW_URL="mysql://[email protected]:3310/roundest-mon"
export const options: QualityOption[] = [
{
tag: "480p_30",
name: "480p 30fps",
configuration: {
width: 640,
height: 480,
frameRate: 30,
bitrateMin: 750,
@t3dotgg
t3dotgg / day25.ts
Created December 25, 2022 05:27
typescript aoc day 25 solution
const input = await Deno.readTextFile("./input.txt");
const lines = input.split("\n");
const dv = {
"2": 2,
"1": 1,
"0": 0,
"-": -1, // === -1
"=": -2, // === -2
import { useQuery } from "@tanstack/react-query";
type Action<TActionInput = unknown, TActionReturn = unknown> = (
input: TActionInput,
) => Promise<TActionReturn>;
export type BundledAction<TAction extends Action> = {
key: string[];
result: Awaited<ReturnType<TAction>>;
action: TAction;