useSearchState is used similarly to useState in that it returns a value and setter.
The simplest use case is to tie the value to the search params with a key.
MyComponent.tsx
| /** | |
| * A recursive function that applies a callback to nodes in a tree (may include Maps and Arrays). | |
| * @param {*} tree the tree to walk | |
| * @param {walkTreeCb} callback function to apply to nodes that pass the filter function, passed a node, index, and depth. Return true to walk a node that matches the filter. | |
| * @param {walkTreeFilterFunc=} filter a filter function to apply. If not specified will callback for leaf nodes only (not Maps or Arrays). Return true to apply callback. | |
| * @param {number=} i index into array or -1 if parent is an object. Not normally specified in initial call | |
| * @param {number=} d the depth. Not normally specified in initial call | |
| * @param {[]=} k list of ancestor keys. Not normally specified in initaial call | |
| * @param {[]=} a list of ancestor objects. Not normall specified in initial call | |
| * @param {boolean=} walkCyclic indicates cyclic references should be walked. Callback must handle short circuiting by return false. |
| /** | |
| * Render a number as a fraction | |
| * @param {number} v the decimal value to convert to a fraction | |
| * @param {number[]} denom the list of denominators | |
| * @returns {string} the fraction closest to the decimal value | |
| */ | |
| const toFraction = (v, denom=[2,3,4,7,8,10,16,32,64,100]) => { | |
| denom = denom.sort((a,b)=>a-b) | |
| // whole and fractional parts |
| const noVowelsToUpper = key => key.match(/[aeiouy]/) ? key : key.toUpperCase() | |
| const lowerCaseTwoLetter = w => { | |
| const words = [ 'of', 'to', 'in', 'it', 'is', 'as', 'at', 'by', 'or', 'on', 'if', 'an' ] | |
| if (w.length === 2 && words.indexOf(w.toLowerCase()) >= 0) return w.toLowerCase() | |
| return w | |
| } | |
| const upperCaseTwoLetter = w => { | |
| const words = [ 'CA', 'ID' ] | |
| if (w.length === 2 && words.indexOf(w.toUpperCase()) >= 0) return w.toUpperCase() |
My workplace has recently begun using github-enterprise hosted by github in the cloud, rather than using github-enterprise in a self-hosted environment. This means that I now have another account tied to my company user-identity which conflicted with my git ssh configuration.
I wasn't thrilled with the other solutions I'd found to manage two accounts:
A couple of alias to remind me how to change colors in bash or zsh
in ~/.bashrc or ~/.zshrc
alias colors='for ((i=30;i<=37;i++));do echo -e "\033[0;"$i"m echo -e \"\\\033[0;"$i"m"\";done;echo -e "\033[0;m echo -e \"\\\033[0;m\""'
alias declare_clr='\
echo "declare -A clr";
for a in 30m/black 31m/red 32m/green 33m/yellow 34m/purple 35m/magenta 36m/cyan 37m/white m/reset; do \
| module.exports = withShutdown | |
| // This may be unnessary with server.closeIdleConnections and server.closeAllConnections added in Node v18.2.0. | |
| /** | |
| * Adds a shutdown function that destroys active connections | |
| * (such as keep-alive). Idle connections end immediately, | |
| * others are destroyed after all data is written. | |
| * | |
| * @param {http.Server} server http.Server instance |
| #!/bin/bash | |
| tmp=$(mktemp -d -t tmp.XXXXXXXXXX) | |
| function finish { | |
| rm -rf "$tmp" | |
| } | |
| trap finish EXIT | |
| OPTS="" | |
| if [[ $1 == --region ]]; then | |
| OPTS="--region $2" |
| # | |
| # This file should be sourced from ~/.bashrc or ~/.zshrc | |
| # | |
| # export VAULT_ADDR=<your vault URL> | |
| # source ~/.yv-funcs | |
| # | |
| # It requires yq, gdate, and gum to be installed (brew install yq coreutils gum) | |
| # | |
| # It requires a yaml file ~/.yv-funcs.rc to contain entries: | |
| # |
| // npm i express@^4.15.2 @aws-sdk/client-s3@^3.540.0 | |
| import { Request, Response, Router } from 'express' | |
| import { GetObjectCommand, HeadObjectCommand, S3Client } from '@aws-sdk/client-s3' | |
| const router = Router() | |
| /** stream a video from S3 */ | |
| router.get('/:filepath(*.mp4)', async (req: Request, res: Response) => { | |
| const filepath = req.params.filepath || req.params[0] | |
| const range = req.headers.range; |