Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am tserong on github.
  • I am tserong (https://keybase.io/tserong) on keybase.
  • I have a public key whose fingerprint is 9409 2010 12EC F0E3 F918 B284 DB7E 03BB B43C 2BA9

To claim this, I am signing this object:

@tserong
tserong / node_is_active.sh
Last active December 19, 2015 22:19
Check if current node in a Pacemaker cluster is currently running any resources (new and improved thanks to lge on #linux-ha).
#!/bin/sh
[ -n "$(crm_mon -1 -n 2>/dev/null | sed -ne '/^Failed actions:/ q; /^Node '$(crm_node -n)':/,/^Node/ { /^Node/ d; p }')" ] \
&& echo 'this node is hosting resources' \
|| echo 'this node is slacking off, doing nothing'
@tserong
tserong / vote-analysis.rb
Last active December 22, 2015 19:39
Spit out the percentage of first preference votes a given political party got in the senate, by division.
#!/usr/bin/env ruby
#
# Go to http://vtr.aec.gov.au/SenateDownloadsMenu-17496-csv.htm and get
#
# * First Preferences by Division by Vote Type
# http://vtr.aec.gov.au/Downloads/SenateFirstPrefsByDivisionByVoteTypeDownload-17496.csv
#
# * Votes by Division
# http://vtr.aec.gov.au/Downloads/SenateVotesCountedByDivisionDownload-17496.csv
#

Hommus

Ingredients

  • 2 cloves garlic, chopped
  • 1/4 cup water
  • 1/4 cup lemon juice
  • 1 400g can chickpeas, drained & rinsed
  • 1/2 cup tahini
  • 1 tsp salt
@tserong
tserong / zcell-warnings.sh
Created April 27, 2022 06:16
Log ZCell voltage, bus voltage and warning indicator status
#!/bin/bash
#
# Polls the ZCell BMS REST API once per second and prints the
# voltage, bus voltage and warning indicator status if they've
# changed since the last poll. Runs indefinitely.
# Requires `curl` and `jq`.
#
# Note: this only looks at the first battery in the system
# (".list[0]" in the `jq` invocation).
#
@tserong
tserong / zcell-contactor-state.sh
Last active April 27, 2022 06:21
Log ZCell contactor state
#!/bin/bash
#
# Polls the ZCell BMS REST API once per second and prints the
# state of the Charge, Discharge and Energy Extrator (Strip)
# contactors if they've changed since the last poll. Will
# run forever, or until all three contactors are open at the
# same time, whichever comes first.
# Requires `curl` and `jq`.
#
# Note: this only looks at the first battery in the system
@tserong
tserong / zcell-soc.sh
Last active April 27, 2022 06:22
Log ZCell state of charge
#!/bin/bash
#
# Polls the ZCell BMS REST API once per minute and prints the
# current state of charge. Runs indefinitely.
# Requires `curl` and `jq`.
#
# Note: this only looks at the first battery in the system
# (".list[0]" in the `jq` invocation).
#
@tserong
tserong / sched.py
Created July 1, 2022 02:59
Set scheduled charges on a single ZCell, to generally keep the battery full except for peak electricity usage times, and maintenance cycle days
#!/usr/bin/env python3
#
# Set scheduled charges on a single ZCell, to generally keep the
# battery full except for peak electricity usage times, and maintenance
# cycle days. Peak electricity usage times are 07:00-10:00 and
# 16:00-21:00 per Aurora Energy in Tasmania. This will need adjusting
# by one hour if used during daylight savings time.
#
# This script is designed to be run on the GX from cron at 07:00 each
# day (just as peak electricity starts), because that makes the scheduled
@tserong
tserong / rc.local
Created July 1, 2022 04:10
/data/rc.local script for Victron Cerbo GX to install custom crontab entry to run /home/root/sched.py
#!/bin/sh
if ! grep -q 'sched\.py' /etc/crontab; then
mount | grep -q 'on / .*ro'
is_ro=$?
if [ $is_ro -eq 0 ]; then
mount -o remount,rw /
fi
cat >> /etc/crontab <<EOF
# Set scheduled charges based on zcell maintenance cycle
#!/usr/bin/env python3
#
# This script sets the osdspec_affinity (i.e. drive group) for the given OSDs
# on the host on which it is executed.
#
# For example, to set osdspec_affinity=foo for OSDs 1, 2 and 3, you'd run:
#
# ./set-osdspec-affinity.py foo 1 2 3
#
# For each OSD specified, it will: