Skip to content

Instantly share code, notes, and snippets.

View rnorth's full-sized avatar

Richard North rnorth

View GitHub Profile
@rnorth
rnorth / update_device_areas.py
Last active May 2, 2024 05:14
Home Assistant pyscript to mass-update device areas
import homeassistant
@service
def update_device_areas():
devreg = homeassistant.helpers.device_registry.async_get(hass)
entreg = homeassistant.helpers.entity_registry.async_get(hass)
areareg = homeassistant.helpers.area_registry.async_get(hass)
area_ids = []
#!/bin/bash
set -euo pipefail
COMBINED_BRANCH=combined-pr-branch
BODY_FILE=/tmp/.combined-pr-body.md
LIMIT=50
echo -n > $BODY_FILE
@rnorth
rnorth / gh-notification-cleaner
Created June 17, 2021 12:51
Script to clean up GitHub notifications by marking all notifications for merged/closed Dependabot PR as read
#!/bin/bash
gh api notifications --paginate --jq '.[] | [.subject.url,.url] | @tsv' | while read -r URL THREAD_URL; do
ITEM=$(gh api $URL)
NUMBER=$(jq -r .number <<< ${ITEM})
TITLE=$(jq -r .title <<< ${ITEM})
STATE=$(jq -r .state <<< ${ITEM})
echo "$NUMBER $TITLE $STATE"
#
# Python
#
export PYENV_ROOT=${PYENV_ROOT:-$HOME/.pyenv}
# Usage:
# Add to .envrc file:
# use python 3.7.5
use_python() {
# Install pyenv for management of Python versions
@rnorth
rnorth / tips.md
Created March 13, 2020 16:12
Machine Relevance Show and Tell - staying sane and being effective while working from home
richardnorth@mbp ~/g/t/testcontainers-java> while true
./gradlew couchbase:clean couchbase:test --tests "org.testcontainers.couchbase.*" -i --no-build-cache | tee /dev/fd/2 | tail -n10 | ~/personalbin/nfy
sleep 1; clear
end
Initialized native services in: /Users/richardnorth/.gradle/native
Found daemon DaemonInfo{pid=56918, address=[00bfe441-56b5-4f8f-9ce6-0b7dd6e736f1 port:59163, addresses:[/0:0:0:0:0:0:0:1, /127.0.0.1]], state=Idle, lastBusy=1573844859729, context=DefaultDaemonContext[uid=cbb29f0d-797d-4a3a-bc17-fc477d02c3a9,javaHome=/Users/richardnorth/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/193.5096.12/IntelliJ IDEA 2019.3 EAP.app/Contents/jbr/Contents/Home,daemonRegistryDir=/Users/richardnorth/.gradle/daemon,pid=56918,idleTimeout=10800000,priority=NORMAL,daemonOpts=-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-agentlib:jdwp=transpo
import com.github.dockerjava.api.command.InspectContainerResponse;
import eu.rekawek.toxiproxy.Proxy;
import eu.rekawek.toxiproxy.ToxiproxyClient;
import eu.rekawek.toxiproxy.model.ToxicDirection;
import eu.rekawek.toxiproxy.model.ToxicList;
import org.junit.Rule;
import org.junit.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;

Testcontainers general principles

Tips for developing/maintaining Testcontainers forks:

  • Some general tips (most important at the top):
    • Have an easy-to-use API that is simple for people to use and read
    • Make common tasks intuitive and nice to use. Make less common tasks possible, but not at the expense of the common tasks. It's better not to support a niche feature than to degrade the common features.
    • Guide people towards doing sensible things, rather than letting them fall into traps.
    • Be idiomatic for the language and framework
  • Give users coarse-grained tools rather than a fine-grained bag of components to figure out how to assemble
@rnorth
rnorth / agenda
Last active January 17, 2022 06:56
agenda: exports today's calendar entries from Mac Calendar.app into a markdown file to enable note-taking
#!/usr/bin/swift
//
// agenda: exports today's calendar entries from Mac Calendar.app into a markdown file to enable note-taking
//
// Example usage:
// agenda > agenda-$(date +%Y-%m-%d).md
//
import EventKit
cat cp.txt | grep /Users | while read line 115ms
tr ":" "\n"
end | sort | uniq | sed 's/.jar/-sources.jar/g' | while read jar
unzip -p $jar
end | wc -l