Skip to content

Instantly share code, notes, and snippets.

@geekman
geekman / query.js
Created August 13, 2023 13:59
copy-paste snippet to un-download all unwatched episodes in DuckieTV
// un-download any unwatched episodes
// this problem was created during initial Trakt.TV sync and it added everything to the "collection"
CRUD.Find('Episode', {}, {'limit': 100000}).then(function(eps) {
eps.map(function(ep) {
if (ep.hasAired() && !ep.isWatched() && ep.isDownloaded()) {
console.log(ep.ID_Serie, ep.getFormattedEpisode(), ep);
ep.markNotDownloaded(/*pairing:*/ false);
}
})
})
@geekman
geekman / mpv-rtsp.sh
Created August 1, 2023 17:30
mpv stream RTSP command
mpv --no-cache --profile=low-latency --rtsp-transport=tcp rtsp://192.168.0.1/stream
@geekman
geekman / funcptr_obj.go
Created April 10, 2023 10:25
golang function pointer with object instance (or whatever it's called) https://go.dev/play/p/RsPDtGf_DJe
//
// does assigning a function pointer carry with it the associated object?
//
package main
import "fmt"
// a "function pointer" and its implementation (well, one of it)
var FuncPtr func(v string)
func a(v string) {
@geekman
geekman / opt3001_test.c
Created March 17, 2023 17:43
Arduino code for reading OPT3001 sensor values
//
// Arduino test code to read OPT3001 sensor values
// https://www.ti.com/product/OPT3001
// https://www.ti.com/lit/gpn/opt3001 (datasheet)
//
#include <Wire.h>
void setup() {
// put your setup code here, to run once:
@geekman
geekman / README.md
Created January 20, 2023 12:52
systemd timers for vacation lights via zigbee2mqtt

This setup relies on having Zigbee switches, connected to zigbee2mqtt. systemd timers just publish messages to the MQTT broker and z2m acts on them.

Setup the systemd unit files, service and timers. Remember to daemon-reload afterwards. (The names are a leftover from my 433MHz RF switch)

# head -100 /etc/systemd/system/lightswitch*
==> /etc/systemd/system/lightswitch-off.timer <==
[Unit]
@geekman
geekman / wifi-powersave@.service
Created August 17, 2022 08:10
systemd unit to disable WiFi power-save
# /etc/systemd/system/wifi-powersave@.service
[Unit]
Description=Disables power-save on WiFI interface %I
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device
[Service]
Type=oneshot
ExecStart=/usr/bin/iw %i set power_save off
@geekman
geekman / itunes-migrate-files.js
Last active July 11, 2023 13:52
WSH script to perform string replacement on iTunes Library media file paths
//
// 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 January 3, 2022 16:41
Telegraf configuration to ingest Zigbee2MQTT messages
#
# 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 October 9, 2021 10:23
strip out SRT metadata, leaving only subtitle text
#
# 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 09:36
a minimal Scrollspy implementation in vanilla JavaScript
//
// 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^="#"]');