This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Updates or adds an item to a new array. | |
* | |
* @param arr The array to check if item exists | |
* @param item The item to add/insert | |
* @param comparer Run against each item in the array to see if it matches an existing item | |
* @returns A new array with the item replaced if found, or added to the end if not found. | |
*/ | |
export const upsert = <T,>(arr: T[], item: T, comparer: (existingItem: T, newItem: T, index: number) => boolean = (item1, item2) => item1 === item2): T[] => { | |
const output = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const useRenderCount = () => { | |
const count = useRef(0); | |
count.current++; | |
return count.current; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, DependencyList, useState } from 'react'; | |
/** | |
* `useLoadData` wraps loading data via fetch in as a hook. | |
* | |
* Supports handling a loading and error state for the current component and handles | |
* cleanup using a useEffect via an AbortSignal to prevent updates happening on | |
* unmounted components. To control how often it runs, use the dependancy list parameter, | |
* see useEffect for more details. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Echo usage to console | |
usage() { | |
cat << EOF | |
usage: replace-branch.sh [options] repo-url | |
options: | |
-s | |
The source folder (default: './build') | |
-b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PORT=${1:-80} | |
FILE=${2:-/etc/nginx/conf.d/default.conf} | |
# Replace the port number, retaining whitespace | |
sed -i 's|\([\s]*listen\) *[0-9]*;|\1 '$PORT';|g' "$FILE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=NordVPN Auto Start | |
After=multi-user.target | |
After=network-online.target | |
[Service] | |
User=root | |
Type=forking | |
ExecStart=/home/pi/nordvpn.sh open uk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reg add HKLM\SOFTWARE\Classes\.json /v PerceivedType /t REG_SZ /d text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates a new function that will run the callback a maximum of once at the end of the timeout period. | |
* Useful for using with event listeners that fire often. The opposite of throttling. | |
* | |
* @param delay The length of time in ms before firing the callbcak | |
* @param callback The callback to fire once the time has passed | |
*/ | |
export function debounce(delay, callback) { | |
let _args; | |
let _running = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
export const createStorage = (key, scope = localStorage) => { | |
return { | |
get() { | |
const stored = scope.getItem(key); | |
if (stored === null) { | |
return null; | |
} | |
return JSON.parse(stored); | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Opens the current folder in the Windows Terminal | |
function term() { | |
# Open's terminal | |
function __runTerm() { | |
# Using the wslpath tool to convert the current directory to windows format | |
# which is required by wt. Also using printf to escape the characters so they arent expanded | |
local var=$(printf "%q" "$(wslpath -w $(pwd))") | |
# Run wt using powershell command |
NewerOlder