Skip to content

Instantly share code, notes, and snippets.

View casebeer's full-sized avatar

Christopher Casebeer casebeer

View GitHub Profile
@casebeer
casebeer / dhcp121.py
Created January 7, 2014 23:28
Generate DHCP Option 121 hex routing configurations
'''
Generate DHCP Option 121 hex routing configurations
Static routes pushed over DHCP
1) Set option 121.
2) Value is the concatenation of hex route data.
3) Each route has the form:
{prefix_length}{destination_prefix}{router}
@casebeer
casebeer / ema_gen.py
Last active July 6, 2022 07:54
Exponential moving average generator example in Python
def consumer(func):
'''
Decorator taking care of initial next() call to "sending" generators
From PEP-342
http://www.python.org/dev/peps/pep-0342/
'''
def wrapper(*args,**kw):
gen = func(*args, **kw)
next(gen)
@casebeer
casebeer / django-run-dev.sh
Created August 25, 2017 01:29
Start Django and Celery, trapping SIGINT to terminate both daemons cleanly on Ctrl-C
#!/bin/bash
#
# Start Django and Celery, trapping SIGINT to terminate both daemons cleanly on Ctrl-C
#
PYTHON=venv/bin/python
DJANGO_DEV_SERVER_PORT=8000
$PYTHON ./manage.py runserver $DJANGO_DEV_SERVER_PORT "$@" &

Last updated: 2017-03-18

Searching for Files

Find images in a directory that don't have a DateTimeOriginal

exiftool -filename -filemodifydate -createdate -r -if '(not $datetimeoriginal) and $filetype eq "JPEG"' .

###Output photos that don't have datetimeoriginal to a CSV### Note this can take a long time if you have a lot of jpgs

'''
TUF-2000m
Module to test TUF-2000m ultrasonic flow meter
via a Modbus RTU to Modbus TCP bridge (eByte NA111-A)
'''
import csv
import sys
import os
@casebeer
casebeer / kf.py
Last active November 13, 2023 23:03
Parse ffprobe keyframe output
'''
# Parse ffprobe keyframe output
Run with
ffprobe -loglevel error -show_entries packet=pts_time,flags -of csv=print_section=0 -i <input file or stream> | python kf.py
See https://stackoverflow.com/a/18088156
'''
@casebeer
casebeer / configuration.yaml
Last active November 16, 2023 23:18
Home Assistant configuration using the REST Switch integration to control the white supplemental lights on Hikvision/Annke ColorVu or NightChroma color night vision cameras.
#
# # REST Switch configs for toggling the white "Supplemental Lights" on Hikvision/Annke cameras
#
# Note that we must hit the cameras' ISAPI endpoints directly, not through the NVR,
# since (at least the Annke N88PCH) NVR does not seem to support getting nor setting the
# `/ISAPI/Image/channels/<ID>/supplmentalLight` API endpoint. This also implies that
# we must use the NVR's "integration password," i.e. the username and password used by the
# NVR to automatically config the cameras, NOT a user of the NVR itself.
#
# ## Camera Settings
@casebeer
casebeer / :etc:netplan:01-macvlan-bridge.yaml
Last active November 24, 2023 21:59
Macvlan bridge for host connectivity in Netplan and Networkd-dispatcher
network:
version: 2
renderer: networkd
ethernets:
mvlan-bridge:
addresses:
- 192.168.0.10/32
routes:
- to: 192.168.0.128/28 # docker macvlan address range
via: 192.168.0.10
@casebeer
casebeer / picture-elements-card.yaml
Created November 29, 2023 22:22
Hikvison PTZ and white light from Home Assistant dashboard
type: picture-elements
title: Hik PTZ Control
elements:
- type: icon
icon: mdi:arrow-up
tap_action:
action: call-service
service: rest_command.hik_ptz_up
hold_action:
action: call-service
@casebeer
casebeer / random-normal.md
Last active March 3, 2024 21:28
Random normal variables in Home Assistant automations/Jinja templates

Random normal variables in Home Assistant/Jinja

Via Iwrin-Hall/uniform sum distribution.

μ = n / 2, σ = sqrt(n / 12)

where n = # of summed uniform U(0, 1) random variables

Scale and shift Irwin-Hall to provide μ and σ as needed.