Skip to content

Instantly share code, notes, and snippets.

View martinpi's full-sized avatar

Martin Pichlmair martinpi

View GitHub Profile
@martinpi
martinpi / readme.txt
Created September 1, 2022 10:43
constellation z (PuzzleScript Script)
Play this game by pasting the script in http://www.puzzlescript.net/editor.html
@martinpi
martinpi / usePersistentState.ts
Created August 25, 2023 08:16
A persistent React hook that supports update functions. Couldn't find any on the interwebs so I had to roll my own.
import { useEffect, useRef, useState } from 'react';
// This hook receives three parameters:
// storageKey: This is the name of our storage that gets used when we retrieve/save our persistent data.
// ttl (seconds): How long it should be kept in browser storage
// initialState: This is our default value, but only if the store doesn't exist, otherwise it gets overwritten by the store.
// Example:
// Store a state that can be any or null and keep it cached for 15 minutes.
// [state, setState] = usePersistentState<any | null>("project.key", 15 * 60, null);
@martinpi
martinpi / readme.txt
Created August 30, 2023 08:36
EYE EYE EYE (PuzzleScript Script)
Play this game by pasting the script in http://www.puzzlescript.net/editor.html