Skip to content

Instantly share code, notes, and snippets.

View AfroThundr3007730's full-sized avatar
🔧
Hacking all the things...

Eddie Carswell AfroThundr3007730

🔧
Hacking all the things...
View GitHub Profile
@AfroThundr3007730
AfroThundr3007730 / dmsetup-vdo
Last active October 17, 2022 03:07
Automount a VDO device at boot (useful when root is on the VDO)
#!/bin/bash
[[ $1 == start && ! -b /dev/mapper/$2 ]] && {
[[ -d /sys/module/kvdo ]] || modprobe kvdo
target=$(readlink -f $(awk -v dev=$2 '$1~dev && $4~"vdo" {print $6}' /etc/dmsetup.table))
[[ $target =~ /dev/dm- ]] && target=$(find /dev/mapper -type l -lname "*${target##*/}")
table=$(awk -v dev=$2 -v target=$target '$1~dev && $4~"vdo" {sub($1FS,""); sub($5,target); print $0}' /etc/dmsetup.table)
echo dmsetup create $2 --table "$table"
[[ -b /dev/mapper/$2 ]] || exit 1
}
@AfroThundr3007730
AfroThundr3007730 / get_stream_stats.sh
Last active August 18, 2023 17:13
Parses chatterino logs to get stream income from bits and subscriptions
#!/bin/bash
# Parses chatterino logs to get stream income from bits and subscriptions
get_stream_stats() {
local f=${1##*/}; f=${f%.*}
printf 'Channel: %s Date: %s\n' "${f%%-*}" "${f#*-}"
awk '/[Cc]heer/ {
for (i = 1; i <= NF; i++) {
if ($i ~ /^[Cc]heer$/) {
j = i + 1
token = $i $j
@AfroThundr3007730
AfroThundr3007730 / Resolve-DnsRecordAllDCs.ps1
Last active March 31, 2024 18:24
Resolves a DNS record on all active DCs in a domain
function Resolve-DnsRecordAllDCs {
<# .SYNOPSIS
Resolves a DNS record on all active DCs in a domain #>
[Alias('nslookup_all')]
Param(
# Name to resolve
[Parameter(Mandatory, ValueFromPipeline)]
[string]$Name,
# Type of record
[Parameter(ValueFromPipelineByPropertyName)]
@AfroThundr3007730
AfroThundr3007730 / split_music_compilation.sh
Created September 14, 2022 05:50
Splits an audio file based on timestamps in a cuesheet
#!/bin/bash
# Splits an audio file based on timestamps in a cuesheet
split_music_compilation() {
[[ -f $1 ]] || { echo 'Audio file not found:' "$1"; return 1; }
[[ -f $2 ]] || { echo 'Cuesheet file not found:' "$2"; return 1; }
local source=$1 cuesheet=$2 count=0 pstamp='0:00' stamp title album
while read -r line; do
[[ $line =~ ([0-9]+:[0-9]+:[0-9]+).-.(.*).\[(.*)\] ]] && {
stamp=${BASH_REMATCH[1]}
title=${BASH_REMATCH[2]}
@AfroThundr3007730
AfroThundr3007730 / mc_generate_map.sh
Last active December 18, 2024 06:38
Generates a coordinate grid to move a player to generate a Minecraft map
#!/bin/bash
# Generates a coordinate grid to move a player and generate a Minecraft map
# Can run commands live via screen or RCON, or generate a command list
# SPDX-License-Identifier: GPL-3.0-or-later
# For issues or updated versions of this script, browse to the following URL:
# https://gist.github.com/AfroThundr3007730/a3a01297705d65ed8c327539b5a55c46
# Dependencies: screen python3(rcon) journalctl tail pkill
@AfroThundr3007730
AfroThundr3007730 / Get-SMSManagementPoint.ps1
Last active March 31, 2024 18:24
Finds SCCM management point in AD based on site code
function Get-SMSManagementPoint {
<# .SYNOPSIS
Finds SCCM management point based on site code #>
Param(
# The site code to search
[Parameter(Mandatory)]
[string]$SiteCode
)
return [adsisearcher]::new(
@AfroThundr3007730
AfroThundr3007730 / wg-auto.sh
Created June 17, 2022 00:40
Wrapper and service to start and stop wireguard interfaces
#!/bin/bash
# Wrapper to start and stop wireguard interfaces
wg_start() {
echo "Setting up Wireguard interface $2..."
ipv4=$(awk '$1 ~ /Address/ && $3 ~ /\./ {print $3}' /etc/wireguard/"${2}".conf)
ipv6=$(awk '$1 ~ /Address/ && $3 ~ /:/ {print $3}' /etc/wireguard/"${2}".conf)
ip link add dev "$2" type wireguard
[[ -n $ipv4 ]] && ip addr add dev "$2" "$ipv4"
[[ -n $ipv6 ]] && ip addr add dev "$2" "$ipv6"
@AfroThundr3007730
AfroThundr3007730 / HelperFunctions.psm1
Last active April 17, 2025 23:33
Collection of helpful bash and powershell functions (most are in my other gists).
# Last updated 20240913 by AfroThundr
# SPDX-License-Identifier: GPL-3.0-or-later
Set-StrictMode -Version Latest
#region Internal Variables
$DefaultPSProfileContent = @'
# Note: This profile stub is automatically overwritten, make changes instead in profile_local.ps1
# Always use strict mode
Set-StrictMode -Version Latest
@AfroThundr3007730
AfroThundr3007730 / Get-StringPermutations.ps1
Last active March 31, 2024 19:45
Gets recursive unique combinations of characters in a string
function Get-StringPermutations {
<# .SYNOPSIS
Calculates the permutations of an input string #>
[Alias('permutate')]
Param(
# String to calculate permutations from
[Parameter(Mandatory)]
[String]$String,
# Return only unique permutations
[Parameter()]
@AfroThundr3007730
AfroThundr3007730 / Get-SSLServerCertificate.ps1
Last active March 31, 2024 18:25
Powershell function similar to openssl -s_client to retrieve a certificate
function Get-SSLServerCertificate {
<# .SYNOPSIS
Retrieves the X509 certificate by connecting to a SSL enabled server #>
[Alias('s_client')]
Param(
# Hostname or IP address to connect to
[Parameter(Mandatory)]
[String]$Hostname,
# Port to connect to
[Parameter()]