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
/** | |
* Shorthand function for document.createElement. Accepts and appends attributes to the newly created element and appends child element, if any. | |
* @param tagName The name of the element eg. a or script | |
* @param attributes Any additional attributes to add to the element after creating. Eg. href | |
* @param children Any child elements you want appended on creating this element, obviously they could be createElement calls as well | |
*/ | |
export function createElement(tagName, attributes, children) { | |
const ele = attributes === (void 0) | |
? document.createElement(tagName) | |
: Object.assign(document.createElement(tagName), attributes); |
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
using System; | |
using System.Text; | |
/// <summary> | |
/// A class for encrypting and decrypting a string into base64 format which makes it safe for transfer | |
/// between applications. | |
/// | |
/// Reference: | |
/// Based upon the javascript implementation of xxtea by: Chris Veness | |
/// www.movable-type.co.uk/tea-block.html |
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
// Production steps of ECMA-262, Edition 5, 15.4.4.21 | |
// Reference: http://es5.github.io/#x15.4.4.21 | |
if (!Array.prototype.reduce) { | |
Array.prototype.reduce = function(callback /*, initialValue*/) { | |
'use strict'; | |
if (this == null) { | |
throw new TypeError('Array.prototype.reduce called on null or undefined'); | |
} | |
if (typeof callback !== 'function') { | |
throw new TypeError(callback + ' is not a function'); |
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
<# | |
.SYNOPSIS | |
Converts windows path into a linux path and vice versa. | |
.DESCRIPTION | |
Converts windows path into a linux path and vice versa. Use WSL under the hood, so needs to be installed. | |
See docs wslpath docs for more information. | |
.PARAMETER path | |
The path to convert |
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 |
NewerOlder