Skip to content

Instantly share code, notes, and snippets.

@h3po
h3po / measure.lua
Last active July 7, 2016 08:45
Distance and Volume measuring tool for an OpenComputers Tablet (Minecraft)
local event = require("event")
local term = require("term")
local component = require("component")
gpu = component.gpu
local w, h = gpu.getResolution()
local prevX = nil
local prevY = nil
local prevZ = nil
@h3po
h3po / sink-switcher.py
Last active April 11, 2021 10:53
Simple python script to switch pulseaudio streams between available sinks
#!/usr/bin/python3
from pulsectl import Pulse, pulsectl
from collections import Counter
import logging
from systemd import journal
log = logging.getLogger("sink-switcher")
log.setLevel(logging.DEBUG)
@h3po
h3po / Asus-Z170-Deluxe.conf
Last active November 19, 2022 15:53
My lm_sensors config for the Nuvoton NCT6793D on my Asus Z170-Deluxe Motherboard. Haven't figured out the voltages yet. To get the nct6775 driver working with the monitor chip, you need to boot with acpi_enforce_resources=lax to ignore the ACPI address space conflict with the EFI.
chip "nct6793-isa-0290"
label in0 "CPUVCORE"
compute in0 @*2, @/2
label in1 "VIN0"
label in2 "AVCC"
label in3 "3VCC"
label in4 "VIN1"
label in5 "VIN2"
label in6 "VIN3"
label in7 "3VSB"
@h3po
h3po / onSataHotplug.py
Last active July 7, 2016 16:07
I have a Sata Hotplug Bay with a rather loud fan hotwired to the back of it. To keep the noise down, I use a udev rule in combination with this python script to only turn on the fan while there is one or more disks attached to the controller card that services the ports.
#!/usr/bin/python
"""
turn the fan to dc mode and off when the fan controller is initialized
/etc/udev/rules.d/97-hwmon.rules:
ACTION=="add", SUBSYSTEM=="hwmon", DRIVERS=="nct6775", ATTR{pwm5_mode}="0", ATTR{pwm5_enable}="1", ATTR{pwm5}="0"
declare the disk as hotpluggable and run the script
/etc/udev/rules.d/98-sata.rules:
ACTION=="add", SUBSYSTEM=="scsi_host", DRIVERS=="sata_sil24", ENV{UDISKS_SYSTEM_INTERNAL}="0"
@h3po
h3po / python-scandir-Makefile
Created February 18, 2017 23:28
Makefile for building python-scandir package on openwrt, v1.3 as dependency for octoprint
include $(TOPDIR)/rules.mk
PKG_NAME:=scandir
PKG_VERSION:=1.3
PKG_RELEASE:=1
PKG_SOURCE:=v$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://github.com/benhoyt/scandir/archive/
PKG_BUILD_DIR:=$(BUILD_DIR)/scandir-$(PKG_VERSION)
@h3po
h3po / lspci_by_iommu.py
Created May 2, 2017 04:31
Quick wrapper script for lspci that lists devices by IOMMU group. Arguments (except -s and -d) are passed through to lspci.
#!/usr/bin/env python3
import os, subprocess, sys
from contextlib import suppress
if "-h" in sys.argv:
with suppress(subprocess.CalledProcessError):
print(subprocess.check_output(["lspci", "-h"], universal_newlines=True))
exit(0)
@h3po
h3po / prometheus-urbackup-exporter.py
Last active August 1, 2021 21:05
Simple proof of concept script for exporting urbackup status to prometheus, using prometheus_client and urbackup-server-web-api-wrapper packages
#!/usr/bin/env python3
import urbackup_api
def floatWithDefault(x, default=0.0):
try:
return float(x)
except ValueError:
return default
@h3po
h3po / snmp.yml
Created June 13, 2017 11:33
Config for prometheus-snmp-exporter polling the most important metrics (mtu, bandwith, packet/byte counters, plug status) from a cisco switch stack, with static port properties (index, descr, type, mac, name, alias) as labels
#http://www.oidview.com/mibs/0/IF-MIB.html
#http://www.net-snmp.org/docs/mibs/interfaces.html
cisco_custom:
version: 2
auth:
community: public
walk:
- 1.3.6.1.2.1.2.2.1
- 1.3.6.1.2.1.31.1.1.1
metrics:
@h3po
h3po / snmp.yml
Last active April 28, 2024 14:30
snmp.yml for monitoring pfsense (BEGEMOT-PF-MIB) with prometheus' snmp_exporter
pfsense:
version: 2
auth:
community: public
walk:
- 1.3.6.1.4.1.12325.1.200.1.1 #SNMPv2-SMI::enterprises::BEGEMOT-PF-MIB::pfStatus
- 1.3.6.1.4.1.12325.1.200.1.2 #SNMPv2-SMI::enterprises::BEGEMOT-PF-MIB::pfCounter
- 1.3.6.1.4.1.12325.1.200.1.3 #SNMPv2-SMI::enterprises::BEGEMOT-PF-MIB::pfStateTable
#not interesting
#- 1.3.6.1.4.1.12325.1.200.1.4 #SNMPv2-SMI::enterprises::BEGEMOT-PF-MIB::pfSrcNodes
@h3po
h3po / prometheus-corsairpsu-exporter.py
Created October 8, 2017 13:18
Simple prometheus exporter for temperature and power sensor data from a Corsar HX750i (and possibly other HXi and RMi series) power supply. Based on OpenCorsairLink by audiohacked
#!/usr/bin/python3
"""
2017-10 by mail@h3po.de
using protocol reverse engineered by audiohacked: https://github.com/audiohacked/OpenCorsairLink
"""
import usb1, struct, threading
from http.server import HTTPServer
from client_python.prometheus_client.core import Metric, REGISTRY