Skip to content

Instantly share code, notes, and snippets.

View brettinternet's full-sized avatar
👋

Brett brettinternet

👋
View GitHub Profile
@brettinternet
brettinternet / update-git-mirrors.mjs
Last active April 23, 2023 03:50
Update list of git mirrors
/**
* environment variables:
* WORKING_DIRECTORY - set to absolute path such as /tmp
* GIT_REMOTE_{some unique number or key} - set to cloneable HTTPS repo URL such as 'https://github.com/brettinternet/homelab'
*/
import { stat } from "node:fs/promises"
import { existsSync } from "node:fs"
import { dirname, parse as pathParse, join as pathJoin } from "node:path"
import { parse as urlParse, fileURLToPath } from "node:url"
import { promisify } from "node:util"
const createList = (length) =>
[...new Array(length)].map((_, index) => ({id: (index + 1).toString() }))
const length = 10000
const items = createList(length).map(c => ({ ...c, inner: createList(length) }))
console.log(items)
const lastId = length.toString()
const itemId = lastId
const innerItemId = lastId
@brettinternet
brettinternet / try-catch-helper.ts
Last active December 15, 2022 22:57
try catch hell 🤷‍♂️
const tc =
<T extends (...args: Parameters<T>) => ReturnType<T>>(
cb: T,
condition = true
): ((...args: Parameters<T>) => ReturnType<T> | undefined) =>
(...args: Parameters<T>) => {
if (condition) {
try {
return cb(...args)
} catch (error) {
@brettinternet
brettinternet / 0-remote-setup-arch.sh
Last active December 5, 2022 07:49
Arch Linux setup with dm-crypt encryption, btrfs and rEFInd
#!/bin/bash
# Work from a terminal you're more comfortable in (and for scrolling)
set -xe
if passwd -S root | grep -q "NP"; then
echo "Set root password:"
passwd
fi
@brettinternet
brettinternet / scale-deployments.sh
Last active November 15, 2022 19:12
Scale up or down kubernetes deployments within a container from a bash script
#!/bin/bash
set -e
DEPLOYMENTS="$1"
NUMBER_OF_REPLICAS="${2:-1}"
API_SERVER="https://kubernetes.default.svc"
SERVICE_ACCOUNT_FOLDER="/var/run/secrets/kubernetes.io/serviceaccount"
NAMESPACE=$(cat ${SERVICE_ACCOUNT_FOLDER}/namespace)
@brettinternet
brettinternet / privatebin-dev.sh
Last active October 9, 2022 21:10
Develop PrivateBin client views
#!/bin/bash
# https://github.com/PrivateBin/PrivateBin
if [ ! -f ./conf.ini ]; then
curl https://github.com/PrivateBin/PrivateBin/blob/master/cfg/conf.sample.php \
--output ./conf.ini
fi
mkdir -p tpl
@brettinternet
brettinternet / update-zfs.sh
Created May 27, 2022 17:03
Update zfs-dkms and zfs-utils on Arch Linux with an AUR helper
#!/bin/bash
# Source: https://github.com/Morganamilo/paru/issues/707#issuecomment-1116491359
# e.g. paru or yay
AUR_HELPER="paru"
$AUR_HELPER -Sy
g='/Version/{print $3}'
@brettinternet
brettinternet / package.json
Last active December 24, 2021 19:21
Cross-platform method to pipe Create React App stdout in order to prevent scripts from clearing the console
{
"scripts": {
"start": "ts-node scripts/start-cra"
}
}
@brettinternet
brettinternet / no_afk.ahk
Last active April 5, 2022 20:23
anti afk for games
; Ocassionally moves mouse to a random location
; Use Win+z to enable/disable
Pause On ; Start paused
Loop
{
Random, x, -10, 10
Random, y, -10, 10
Random, SleepDelay, 600, 18000
@brettinternet
brettinternet / get-values.ex
Last active May 22, 2023 17:37
Accessing values in maps, keyword lists, and structs in Elixir
# Accessing values in maps, keyword lists, and structs
# 1. using . they key can’t be missing, works with structs or maps, but not with keyword lists
# 2. using […] works on maps and keyword lists, but not structs. Key can be missing and i’ll return nil
# 3. Map.get(…) works on maps and structs, but not keyword lists. will return nil if key is missing