Skip to content

Instantly share code, notes, and snippets.

@jsg2021
jsg2021 / parse.js
Created September 6, 2022 15:29
url replacement
export const NULL_PROTO = "file:/";
const isDefault = (x, y) =>
!`${x}`.startsWith("file:") &&
(!y || y === NULL_PROTO || !`${y}`.startsWith("file:"));
const filterString = (str, defaulted) =>
defaulted ? str.replace(/^file:\/\//, "") : str;
class LooseURL extends URL {
@jsg2021
jsg2021 / use-store-value.js
Last active September 8, 2022 17:20
Example hook using a Proxy to subscribe to used properties of a store
import { useEffect } from "react";
/**
* Exercises left to reader to implement:
*
* useResolvedStore
* getValueFromStore
* shouldUpdateForChange
* forceUpdate
* addChangeListener
@jsg2021
jsg2021 / use-async-value.js
Created May 27, 2022 21:08
A react hook to use Suspense for data loading
import { useEffect } from 'react';
/**
* @template T
* @typedef {{ read: () => T }} Reader
*/
const DATA = {
/** @type {Object<string, Reader<any>>} */
objects: {},
@jsg2021
jsg2021 / backup
Created April 3, 2020 04:39
1password gpg & ssh backup/restore
#!/usr/bin/env bash
set -e
eval 'SESSION=(${!'"OP_SESSION_"'@})'
if [[ -z $SESSION ]]; then
echo "Login required: eval \$(op signin accountname)"
exit 1;
fi
@jsg2021
jsg2021 / ranges.js
Created February 18, 2020 15:21
Render Range Utility
/**
*
* @generator
* @param {number} start
* @param {number} end
* @yeilds {number} The next number in the range
*/
export function* range(start, end) {
let x = start;
while (x++ < end) {

Keybase proof

I hereby claim:

  • I am jsg2021 on github.
  • I am jsg2021 (https://keybase.io/jsg2021) on keybase.
  • I have a public key ASAPjLrrz_LIX88JW1G_8ZW5bKG-BjrPQG5ZVc1-blv48Ao

To claim this, I am signing this object: