Skip to content

Instantly share code, notes, and snippets.

View DavesCodeMusings's full-sized avatar

Dave Horton DavesCodeMusings

  • Planet Earth
View GitHub Profile
@DavesCodeMusings
DavesCodeMusings / auto-inc-property.py
Created April 3, 2025 14:19
An 8-bit number as a class property that increments itself each time it's read.
# Auto-incrementing property
class Test:
_packet_id = -1
@property
def packet_id(self):
self._packet_id += 1
self._packet_id &= 0xFF # Truncate to 8-bit max
return self._packet_id
@DavesCodeMusings
DavesCodeMusings / ip-sort.js
Last active January 10, 2025 21:56
Sort IP addresses by octet order rather than the usual string sorting
#!/usr/bin/env node
function ipv4Compare(a, b) {
let aOctets = a.split('.');
let bOctets = b.split('.');
if (aOctets.length !== 4 || bOctets.length !==4) {
throw("InvalidIPv4Address");
}
if (parseInt(aOctets[0]) > parseInt(bOctets[0])) {
@DavesCodeMusings
DavesCodeMusings / containers.conf
Created January 7, 2025 18:54
Monit alerts for down Docker containers
check program containers with path "/usr/bin/docker ps --format '{{ .Names }}' --filter 'status=exited'"
every 120 cycles
if content != "" then alert
@DavesCodeMusings
DavesCodeMusings / fstab_align.sh
Created December 3, 2024 02:05
/etc/fstab field aligner
# Create order from chaos
awk '{ printf "%-42s %-16s %-8s %-12s %2s %2s\n", $1, $2, $3, $4, $5, $6 }' /etc/fstab > /etc/fstab.new
@DavesCodeMusings
DavesCodeMusings / random_complex_password.sh
Created November 24, 2024 05:49
Random Complex Password
#!/bin/sh
# Generate a random complex password on a Linux system.
tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' </dev/urandom | head -c 32; echo
# Reference:
# https://owasp.org/www-community/password-special-characters
# https://www.gnu.org/software/coreutils/manual/html_node/tr-invocation.html
@DavesCodeMusings
DavesCodeMusings / VirtualBox_Ventoy_USB_Boot.md
Last active December 31, 2024 20:05
Ventoy VirtualBox Boot

Ventoy Flash Drive as VirtualBox Boot Device

This document shows how to use a Ventoy formatted USB device (instead of an optical disk) to boot an ISO image in VirtualBox. There are other HowTo documents on the internet that explain this procedure (one is mentioned in the References section below), but most use a deprecated VBoxManage sub-command to create the raw device. This document uses the preferred createmedium sub-command. It also uses PowerShell rather than cmd.exe.

The generic form of the command that makes the Ventoy USB drive available to VirtualBox is as follows:

.\VBoxManage createmedium disk --filename=PATH --format=VMDK --variant=RawDisk --property RawDrive=DEVICE_NAME

But, there are some prerequisites...

@DavesCodeMusings
DavesCodeMusings / s31.yaml
Last active October 7, 2024 03:26
Configuration for Sonoff S31 flashed with ESPHome
esphome:
name: s31-1
friendly_name: s31-1
esp8266:
board: esp01_1m
early_pin_init: False # Mitigate relay flipping on reboot.
# Disable logging (UART is used by cse7766 power sensor.)
logger:
@DavesCodeMusings
DavesCodeMusings / configuration.yaml
Created September 25, 2024 12:59
Stupid simple highlight theme for Home Assistant dashboard
# Add this to configuration.yaml and you can select a theme for navigation buttons,
# and possibly other cards, that will show the text and icon in the accent color
# for the overall theme. For example, in dark mode the accent color is orange, so
# any card having this theme will show in orange.
frontend:
themes:
accent:
primary-text-color: "var(--accent-color)"
paper-item-icon-color: "var(--accent-color)"
@DavesCodeMusings
DavesCodeMusings / Dockerfile
Last active June 1, 2024 21:24
Cooperative Python on code-server Docker Container
FROM lscr.io/linuxserver/code-server:latest
# Add Python support
RUN apt-get update \
&& apt-get install -y \
python3 \
pylint \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
@DavesCodeMusings
DavesCodeMusings / update-dep-pkgs.bat
Created December 17, 2023 13:54
Update dependent packages for VS Code extensions you've created
REM Shamelessly lifted from StackOverflow.
REM https://stackoverflow.com/questions/16073603/how-can-i-update-each-dependency-in-package-json-to-the-latest-version
REM Change directory to your extention's code directory and run the commands below.
REM `npm install -g npm-check-updates` installs the ncu utility and only needs to be run once per system.
REM Repeat ncu -u and npm install as needed for each extension's code directory.
npm install -g npm-check-updates
ncu -u
npm install