Skip to content

Instantly share code, notes, and snippets.

@geekman
geekman / itunes-migrate-files.js
Created Apr 23, 2022
WSH script to perform string replacement on iTunes Library media file paths
View itunes-migrate-files.js
//
// WSH script to replace all paths in iTunes after moving media files.
// iTunes will prompt you to locate missing files, but you need to do them
// one by one, which is not humanly feasible.
//
// run using: cscript.exe itunes-migrate-files.js
//
// 2022.04.23 darell tan
//
@geekman
geekman / telegraf_mqtt.conf
Created Jan 3, 2022
Telegraf configuration to ingest Zigbee2MQTT messages
View telegraf_mqtt.conf
#
# configuration for zigbee2mqtt ingestation
# monitors all exposed devices, while ignoring the z2m bridge
#
[[inputs.mqtt_consumer]]
servers = ["tcp://localhost:1883"]
topics = ["zigbee2mqtt/#"]
data_format = "json"
@geekman
geekman / strip_srt_timings.py
Created Oct 9, 2021
strip out SRT metadata, leaving only subtitle text
View strip_srt_timings.py
#
# strip out SRT timing information, leaving only the text
# separated by a single line
#
# 2021.10.09 darell tan
#
import sys
with open(sys.argv[1], 'r') as f:
@geekman
geekman / scrollsync.js
Created May 13, 2021
a minimal Scrollspy implementation in vanilla JavaScript
View scrollsync.js
//
// a minimal Scrollspy implementation written in pure JS
// not widely tested, may have bugs
//
// 2020.05.13 darell tan
//
function scrollSync(tocSel, headingsSel) {
var offset = 0;
var tocElems = document.querySelector(tocSel).querySelectorAll('a[href^="#"]');
@geekman
geekman / get-password.ps1
Last active Apr 8, 2021
minimal PowerShell code to retrieve passwords from Windows Credentials
View get-password.ps1
#
# PowerShell script to read out generic Windows Credentials
# this is kinda like macOS Keychain, but for Windows
#
# darell tan 2021.04.08
#
[String] $CredNativeCode = @"
using System;
@geekman
geekman / decrypt-pdf.cmd
Created Jan 18, 2021
permanently decrypts PDFs with qpdf
View decrypt-pdf.cmd
:: permanently decrypts PDFs and places them into the parent directory
for %f in (C:\dir\encrypted\*.pdf) do ^
qpdf.exe --decrypt --password=secretdoc "%f" "%~dpf..\%~nxf"
@geekman
geekman / normalize-f32le.go
Created Nov 4, 2020
Normalizes a float32 LE raw file
View normalize-f32le.go
//
// Normalizes a float32 little-endian raw file to the first few averaged values.
// The averaged values will be treated as the baseline and all values in the
// file will be relative to that.
//
// 2020.11.04 darell tan
//
package main
@geekman
geekman / qrcode.min.js
Created Oct 16, 2020
printable QR WiFi credentials generator (self-contained & offline)
View qrcode.min.js
/*! qrcode-svg v1.0.0 | https://github.com/papnkukn/qrcode-svg | MIT license */
function QR8bitByte(t){this.mode=QRMode.MODE_8BIT_BYTE,this.data=t,this.parsedData=[];for(var e=0,r=this.data.length;e<r;e++){var o=[],n=this.data.charCodeAt(e);n>65536?(o[0]=240|(1835008&n)>>>18,o[1]=128|(258048&n)>>>12,o[2]=128|(4032&n)>>>6,o[3]=128|63&n):n>2048?(o[0]=224|(61440&n)>>>12,o[1]=128|(4032&n)>>>6,o[2]=128|63&n):n>128?(o[0]=192|(1984&n)>>>6,o[1]=128|63&n):o[0]=n,this.parsedData.push(o)}this.parsedData=Array.prototype.concat.apply([],this.parsedData),this.parsedData.length!=this.data.length&&(this.parsedData.unshift(191),this.parsedData.unshift(187),this.parsedData.unshift(239))}function QRCodeModel(t,e){this.typeNumber=t,this.errorCorrectLevel=e,this.modules=null,this.moduleCount=0,this.dataCache=null,this.dataList=[]}function QRPolynomial(t,e){if(void 0==t.length)throw new Error(t.length+"/"+e);for(var r=0;r<t.length&&0==t[r];)r++;this.num=new Array(t.length-r+e);for(var o=0;o<t.length-r;o++)this.num[o]=t[o+r]}functi
@geekman
geekman / ax3600_led_show.sh
Created Jul 29, 2020
"runway lights" for the Xiaomi AX3600 router
View ax3600_led_show.sh
#!/bin/sh
PREV=
while :; do
for a in led_blue net_blue led_ant led_yellow net_yellow led_ant; do
[ -n "$PREV" ] && echo 0 > /sys/class/leds/$PREV/brightness
echo 1 > /sys/class/leds/$a/brightness
PREV=$a
sleep 1
done
@geekman
geekman / fixup-posts.py
Created Jun 10, 2020
script to fix up blog post markdown files
View fixup-posts.py
#
# rewrite blog posts front matter to fix date format and title
# 2020.05.26 darell tan
#
import re
import os
import sys
import time