Skip to content

Instantly share code, notes, and snippets.

@agners
agners / securetar-extract.py
Created January 23, 2025 20:06
Extract SecureTar encrypted tar.gz files
#!/usr/bin/env python3
import gzip
import io
import os
import tarfile
from pathlib import Path
import hashlib
from securetar import (
SECURETAR_MAGIC,
SecureTarFile,
#!/usr/bin/env python3
import argparse
import asyncio
import logging
from typing import Any, Optional, cast
from zeroconf import IPVersion, ServiceInfo, ServiceStateChange, Zeroconf, ServiceListener
from zeroconf.asyncio import AsyncServiceBrowser, AsyncServiceInfo, AsyncZeroconf
@agners
agners / tlv-parser.py
Last active December 24, 2024 15:02
Thread credentials dataset TLV parser
#!/bin/env python3
import binascii
import sys
MESHCOP_TLV_TYPE = {
"CHANNEL": 0,
"PANID": 1,
"EXTPANID": 2,
"NETWORKNAME": 3,
@agners
agners / CommissioningStage.h
Created January 11, 2024 13:05
enum CommissioningStage with numeric values
// enum CommissioningStage with numeric values
// from
// https://github.com/project-chip/connectedhomeip/blob/v1.2.0.1/src/controller/CommissioningDelegate.h
enum CommissioningStage : uint8_t
{
kError = 0,
kSecurePairing = 1, ///< Establish a PASE session with the device
kReadCommissioningInfo = 2, ///< Query General Commissioning Attributes, Network Features and Time Synchronization Cluster
kReadCommissioningInfo2 = 3, ///< Query SupportsConcurrentConnection, ICD state, check for matching fabric
@agners
agners / prune-corrupted-layer-metadata.sh
Last active November 30, 2023 21:18
Prune corrupted Docker layers in overlayfs2 storage
#!/bin/sh
# (c) 2023 Stefan Agner
# This scripts attempts to clear corrupted Docker overlay2 storage metadata
# which can be left over after a power failure.
# See also: https://github.com/moby/moby/issues/42964
#
# Typically the error message when attempting to pull the image for which
# corrupted layers are in the storage looks like:
# failed to register layer: error creating overlay mount to /mnt/data/docker/overlay2/6ee02298ee75a4f96e77f90551673cb700f29867f9ad1c4e20b8c816bfcf0735/merged: too many levels of symbolic links
@agners
agners / iomonitor.sh
Created August 18, 2023 13:35
Simple IO monitoring script usful on Home Assistant OS
#!/bin/sh
#
# IO monitoring for Linux
#
# Taken from armbianmonitor
# https://github.com/armbian/build/blob/master/packages/bsp/common/usr/bin/armbianmonitor
# Adjusted to rely on diskstats only.
#
MonitorIO() {
@agners
agners / glc006p.py
Created April 29, 2023 07:14
ZHA custom device (quirk) to override GL-C-006P warm-white/cold-white color temperature
"""GLEDOPTO GL-C-006P device."""
from zigpy.profiles import zha
from zigpy.quirks import CustomDevice
from zigpy.zcl.clusters.general import (
Basic,
GreenPowerProxy,
Groups,
Identify,
LevelControl,
OnOff,
@agners
agners / rpi-eeprom-ver.sh
Created January 30, 2023 14:10
Get Raspberry Pi EEPROM version (CM4/RPi4, inspired by https://github.com/raspberrypi/rpi-eeprom/blob/master/rpi-eeprom-update)
#!/bin/sh
DT_BOOTLOADER_TS=${DT_BOOTLOADER_TS:-/proc/device-tree/chosen/bootloader/build-timestamp}
BOOTLOADER_CURRENT_VERSION=$(printf "%d" "0x$(od "${DT_BOOTLOADER_TS}" -v -An -t x1 | tr -d ' ' )")
date -u "-d@${BOOTLOADER_CURRENT_VERSION}"
@agners
agners / elgate-wave3-fix.sh
Created June 5, 2022 12:22
Elgato Wave:3 Pulseaudio "unstuck"
#!/bin/sh
# Getting Elgato Wave:3 Microphone input "unstuck" on Linux & Pulseaudio
# Replace <card-name> with your microphones card name (check "pacmd list-cards")
# It looks something like "usb-Elgato_Systems_Elgato_Wave_3_<serial>-00"
pacmd set-card-profile alsa_card.<card-name> output:analog-stereo
pacmd set-card-profile alsa_card.<card-name> input:mono-fallback
@agners
agners / main.py
Last active May 9, 2022 11:48
asyncio aiohttp timeout
import aiohttp
import asyncio
async def work(i: int):
#print(f"start working on {i}")
for i in range(50):
pass
async def main():
tasks = []