Skip to content

Instantly share code, notes, and snippets.

@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 / massflash.py
Created June 21, 2016 08:03
automated ESP8266 programming station to mass flash large quantity of devices quickly
#!/usr/bin/env python
#
# automated ESP8266 programming station
# monitors for inserted serial devices and calls esptool to flash them
# written to mass flash entire batches of ESP8266 devices quickly
# $ pip install esptool pyudev
#
# 2016.06.16 darell tan
#
@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 / parse_keybag.py
Created March 3, 2017 17:58
extract & parse the BackupKeyBag from an iTunes Backup
#!/usr/bin/env python
#
# extracts and parse BackupKeyBag
#
# 2017.02.04 darell tan
#
from plist import *
import struct
import sys
@geekman
geekman / ida-analysis.py
Last active March 10, 2022 08:31
simple IDAPython script for scripting automated binary analysis
#
# ida-analysis.py
# a simple IDAPython binary analysis script
# 2020.05.24 darell tan
#
# invoke with:
# idat64 -c -A -S"ida-analysis.py $HOME/analysis.txt" <file.bin>
#
import sys
@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 / jffs2.py
Created October 26, 2015 16:30
JFFS2 scripts
#!/usr/bin/env python
#
# tool to parse JFFS2 images
# and more importantly, guess the erase block size
#
# 2015.10.19 darell tan
#
from struct import unpack
from argparse import ArgumentParser