Skip to content

Instantly share code, notes, and snippets.

View frederickding's full-sized avatar

Frederick Ding frederickding

View GitHub Profile
@frederickding
frederickding / find-what.md
Created April 18, 2025 21:00
Replace hyphen in number ranges in Word with en dash
  1. Ctrl+H to launch Find and Replace dialog.
  2. Check "Use wildcards".
  3. Type <([0-9]@)-([0-9]@)> in the "Find what:" box. This pattern represents a search for whole words that have one number, a hyphen, and another number.
  4. Type \1^=\2 in the "Replace with:" box. This maintains the numbers found in the find, while substituting the hyphen with an en dash.
  5. Click the "Find Next" button to step through each instance and replace. I do not recommend using Replace All.
@frederickding
frederickding / k0s-etcdctl
Created April 9, 2025 00:57
etcdctl wrapper for k0s controllers
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "Please run as root."
exit 2
fi
PKI_DIR=/var/lib/k0s/pki/etcd
export ETCDCTL_CACERT=$PKI_DIR/ca.crt
export ETCDCTL_CERT=$PKI_DIR/peer.crt
@frederickding
frederickding / crictl
Created February 9, 2025 23:01
etcdctl wrapper for rke2 nodes
#!/bin/bash
export CRI_CONFIG_FILE=/var/lib/rancher/rke2/agent/etc/crictl.yaml
/var/lib/rancher/rke2/bin/crictl "$@"
@frederickding
frederickding / CHANGELOG.md
Last active March 26, 2025 15:54
copr frederickding/haproxy version history
@frederickding
frederickding / 01-cockpit.sh
Created June 19, 2024 19:02
certbot cockpit deploy script
#!/usr/bin/env bash
DOMAIN=`basename "$RENEWED_LINEAGE"`
case $DOMAIN in
host.example.com)
echo "Host certs renewed"
cp $RENEWED_LINEAGE/fullchain.pem /etc/cockpit/ws-certs.d/$DOMAIN.crt
cp $RENEWED_LINEAGE/privkey.pem /etc/cockpit/ws-certs.d/$DOMAIN.key
chown cockpit-ws:cockpit-ws /etc/cockpit/ws-certs.d/$DOMAIN.crt /etc/cockpit/ws-certs.d/$DOMAIN.key
echo "Restarting Cockpit"
@frederickding
frederickding / .footer.html
Last active May 11, 2024 21:42
Apache fancyindex for PKI files
@frederickding
frederickding / mbuffer.md
Created May 7, 2024 01:47
mbuffer to LTO tape over network

On the tape server

Using 5567 as an example TCP port

sudo mbuffer -I 5567 -m 8G -P 80 -s 262144 -o /dev/nst0

On the file server

This also writes out a plaintext file in the local directory (filelist.txt) logging the files transferred.

@frederickding
frederickding / veeam-tape-escpos-receipt.ps1
Created August 12, 2023 23:59
Veeam Tape Backup post-job receipt script for ESC/POS
Import-Module Veeam.Backup.PowerShell
$outputBuilder = New-Object System.Text.StringBuilder
[void]$outputBuilder.AppendLine('ESC "@"')
[void]$outputBuilder.AppendLine('ESC "2"')
$job = Get-VBRTapeJob -Name ExampleJobName
$lastjob = (Get-VBRTapeBackupSession -Job $job | Sort-Object EndTime | Select-Object -Last 1)
# get the tape name
$tape = (Get-VBRTapeMedium -MediaPool $job.Target | Sort-Object LastWriteTime | Select-Object -Last 1)
#!/usr/bin/env python3
from escpos import *
import argparse
import os
import sys
import datetime
cli_parser = argparse.ArgumentParser(description='Print to a network ESCPOS receipt printer.')
cli_parser.add_argument('file', help='text file to print')
cli_parser.add_argument('--printer', '-p', default="192.168.1.253", help='IP address or hostname of printer')
@frederickding
frederickding / find.sh
Created July 9, 2022 20:55
Find command for excluding annoying directories
#!/bin/sh
find /mnt/isos -type f -not \( -path '#recycle' -o -name '.DS_Store' -o -path '*@eaDir*' \) 2>/dev/null | sort