Skip to content

Instantly share code, notes, and snippets.

@undergroundwires
undergroundwires / revert-privacy-sexy-firefox-prefsjs-0.12.2.sh
Created September 8, 2023 15:02
Revert privacy.sexy `prefs.js` changes in done between v0.12.0 and v0.12.2
#!/usr/bin/env bash
# https://privacy.sexy — v0.12.2 — Fri, 08 Sep 2023 14:58:37 GMT
if [ "$EUID" -ne 0 ]; then
script_path=$([[ "$0" = /* ]] && echo "$0" || echo "$PWD/${0#./}")
sudo "$script_path" || (
echo 'Administrator privileges are required.'
exit 1
)
exit 0
fi
@undergroundwires
undergroundwires / fix-encoding.sh
Created June 8, 2022 15:50
Fix encoding of files to target format
#!/usr/bin/env bash
readonly TARGET_ENCODING='UTF-8' # unicode
readonly FILE_EXTENSION='srt'
# readonly TARGET_ENCODING='UTF-16'
files=$(find . -type f -iname "*.$FILE_EXTENSION")
for file in $files
do
echo "Processing \"$file\"."
@undergroundwires
undergroundwires / inline-comments-stackoverflow.ts
Created November 2, 2021 19:45
inline-comments-stackoverflow.ts
function replaceHashComment(line: string): string {
const makeInlineComment = (comment: string) => {
const value = comment?.trim();
if (!value) {
return '<##>';
}
return `<# ${value} #>`;
};
const parts = line.split('#');
if (parts.length === 1) { // No hash
@undergroundwires
undergroundwires / clear-all-empty-dirs-on-windows.ps1
Created September 10, 2021 18:55
clear-all-empty-dirs-on-windows
$tdc="D:\uncategorized\"
do {
$dirs = Get-ChildItem $tdc -Directory -Recurse | Where { (Get-ChildItem $_.FullName).count -eq 0 } | Select -ExpandProperty FullName
foreach($dir in $dirs) {
Remove-Item "$dir" # Use -Force for removing hidden items
}
} while ($dirs.count -gt 0)
@undergroundwires
undergroundwires / set-vim-line-wrapping.sh
Created September 2, 2021 11:20
Seet line wrapping for git commits in vim
echo 'setlocal textwidth=72' > ~/.vimrc
# For troubleshooting, open up git commit message edior and run: ":verbose set tw?"
@undergroundwires
undergroundwires / remove-path-length-limitation.bat
Created August 31, 2021 15:21
Remove path length limitation in Windows
reg add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v "LongPathsEnabled" /t REG_DWORD /d 1 /f
@undergroundwires
undergroundwires / gpg-cheatsheet.sh
Last active September 9, 2021 12:19
gpg cheatsheet
# -------------
# -- Create ---
# -------------
# Generate a key
gpg --gen-key
# Generate a key with full wizard
gpg --full-generate-key
@undergroundwires
undergroundwires / git-aliases.sh
Last active May 20, 2024 07:34
Helpful git aliases
#!/usr/bin/env bash
# bash: `bash ./alias.sh` (requires sudo in macOS)
# zsh: `zsh ./alias.sh`
main() {
local -ra aliases=(
# gitgo : Alias for git add, commit with amend, update commit date and force push
"alias gitgo='git add . && git commit --amend --no-edit --reset-author && git push -f'"
# gitc : Alias for counting total characters in last commi heading
"alias gitc='git log --pretty=format:%Creset%s --no-merges -1 | wc -c'"
git remote set-url origin "ssh://[email protected]/USERNAME/REPOSITORY.git"
# Verify new remote URL
git remote -v
#!/usr/bin/env bash
# We parse parameter to ensure middleman.sh can be called using:
# 1. Double quoted parameter value chains
# E.g. "--parameter value" "--parameter2 value"
# Designed for GitHub actions as action.yml args is sent this way.
# Parameter value chains are parsed to send in unquoted format
# 2. Parameter value chain
# This is the normal usage, parameters are sent through as they are
# E.g. --parameter value --parameter2 value