Skip to content

Instantly share code, notes, and snippets.

View sleekweasel's full-sized avatar

TimBav sleekweasel

  • Badoo
  • Luton/London UK
View GitHub Profile
@sleekweasel
sleekweasel / diffpoller.sh
Created May 25, 2024 15:22
Polls a command and presents diffs
#!/bin/bash
# Poll command and display diffs. e.g. diffpoller.sh lsusb
BASE=/tmp/$(whoami)-$(basename $0)
trap "rm -f $BASE-A $BASE-B ; exit" SIGINT
echo -n > $BASE-B
while true ; do
"$@" > $BASE-A 2>&1
diff -wu $BASE-B $BASE-A || date
mv $BASE-A $BASE-B
@sleekweasel
sleekweasel / planets.html
Created June 2, 2024 11:35
Planet orbit thing for Max
<html>
<head>
<script>
var next_tick = null;
var ease = 0.05;
var body = [
{ l: 's', x: 0, y: 0, vx: 0, vy: 0, m: 10000 },
{ l: 'o', x: 0, y: 120+5, vx: 50+2, vy: 0, m: 20 },
{ l: 'm', x: 0, y: 120-5, vx: 50-2, vy: 0, m: 1 },
];
@sleekweasel
sleekweasel / mutex.sh
Created December 21, 2024 01:19
bash-based mutex sort of thing, for MacOS which doesn't have flock or lockf or BASHPID
#!/usr/bin/env bash
set +m # No noisy background report
(
set -m # New process group, please - It should survive teamcity finishing its step
(
PIDS=$HOME/lockpids
state=looking
while true ; do
t=$(mktemp -tpid); bash -c "while [[ -f $t ]] ; do sleep 1 ; done" & p=$(ps -p $! -o 'ppid=') ; rm $t
@sleekweasel
sleekweasel / overlapping-sets.json
Last active February 26, 2025 14:57
Vega script - unrolled recursion to analyse records with overlapping keyword sets. Run on https://vega.github.io/editor/#/edited
{
"$schema": "https://vega.github.io/schema/vega/v4.json",
"title": "Recursive Doughnut Chart by Most Common Keyword",
"autosize": "pad",
"signals": [
{ "name": "width", "init": "containerSize()[0]", "on": [] },
{ "name": "height", "init": "containerSize()[1]", "on": [] },
{ "name": "size", "init": "width > height ? height : width"}
],
"data": [
@sleekweasel
sleekweasel / api.chopped.json
Created March 17, 2025 14:45
Section of the GitHub OpenAPI definition that produces empty data classes for Kotlin.
{
"openapi": "3.0.3",
"info": {
"version": "1.1.4",
"title": "GitHub v3 REST API",
"description": "GitHub's v3 REST API.",
"license": {
"name": "MIT",
"url": "https://spdx.org/licenses/MIT"
},
#!/bin/bash
yesno() {
while true ; do
echo "--> $1"
read
case "$REPLY" in
y*) return 0 ;;
n*) return 1 ;;
*) echo "Please answer y or n" ;;