Skip to content

Instantly share code, notes, and snippets.

View knickers's full-sized avatar

Nick Cox knickers

  • The Desert
View GitHub Profile
@knickers
knickers / layered-links.html
Last active October 9, 2025 19:56
Expand a link to cover an area, making it appear to have nested links.
@knickers
knickers / format_metric_prefix.py
Last active October 11, 2025 01:42
Pretty print numbers with metric prefixes
import enum
import typing
class Unit(enum.Enum):
bit = 'b'
byte = 'B'
calorie = 'C'
gram = 'g'
joule = 'j'
meter = 'm'
@knickers
knickers / audiobook-chapters.sh
Created November 17, 2022 23:54
Split an m4b audiobook into separate files for each chapter.
#!/bin/bash
set -e
if [ -z "$1" ]; then
echo "USAGE: $0 <input.file>"
echo
echo 'Split an m4b audiobook into separate files for each chapter.'
exit 1
fi
@knickers
knickers / wedge.scad
Created June 7, 2022 21:33
OpenScad 2D Wedge
module wedge(radius, start_angle, end_angle) {
// https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#.24fa.2C_.24fs_and_.24fn
fragments = $fn > 0
? ($fn >= 3 ? $fn : 3)
: ceil(max(min(360/$fa, radius*2*PI/$fs), 5));
angle = end_angle - start_angle;
step = angle / fragments / (abs(angle)/360);
polygon([
@knickers
knickers / headless-pi.sh
Last active July 5, 2021 02:26
Headless Raspberry Pi Setup Script
#!/bin/bash
set -e
if [ ! -f cmdline.txt -o ! -f kernel.img -o ! -f bootcode.bin ]; then
echo 'This script must be run inside the /boot partition'
exit 1
fi
enableWIFI() {
echo -n 'Enter 2 letter ISO country code (https://www.iso.org/obp/ui/#search): '
@knickers
knickers / Headless Raspberry Pi pre-boot setup.md
Created February 18, 2020 19:04
Headless Raspberry Pi pre-boot setup

All operations done in the /boot partition.

Enable WIFI

$ cat > wpa_supplicant.conf <<EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=«your_ISO-3166-1_two-letter_country_code»
EOF
@knickers
knickers / ffmcat.sh
Last active December 7, 2020 06:02
Use ffmpeg to concatinate videos
#!/bin/bash
set -e
usage() {
echo "Usage: $0 infile1.ext [infile2.ext ...] outfile.ext"
echo
exit 1
}
confirm() {
@knickers
knickers / whatismyip.sh
Last active December 7, 2020 06:03
Print current public IP address to the console
#!/bin/bash
set -e
dig +short @resolver1.opendns.com myip.opendns.com
<html>
<head>
<style>
frac {
top: 0.75em;
margin: -1em 0 0.5em;
display: inline-block;
position: relative;
}
num, den {
@knickers
knickers / rands.php
Created January 22, 2018 06:10
PHP Command Line Random String Generator
<?php
$fp = @fopen('/dev/urandom','rb');
if ($fp === FALSE) {
trigger_error('Can not open /dev/urandom.');
die();
}
$len = isset($argv[1]) && is_numeric($argv[1]) ? (int) $argv[1] : 32;