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 / 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 / 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 / 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 / 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 / bin-shed
Created May 8, 2024 11:22
A copy-pasteable shell-based interactive line editor, for when I don't have vim in a container and don't want to install it for some reason.
#!/bin/bash
if ! [[ -f "$1" ]] ; then echo "Usage: $0 file-to-edit" ; exit 42 ; fi
FILE=$1
if [[ -f "$FILE~" ]] && ! diff -u $FILE $FILE~ ; then
echo Resolve or ignore above diffs. Quitting. ; echo rm $FILE~ ; exit 42
fi
cp $FILE $FILE~
help() { echo "Try" ; grep -E ') *#' $0 ; echo "And ^d to abort" ; }
help
while echo -n ": " ; read ; do
@sleekweasel
sleekweasel / xmlformat.pl
Created March 25, 2020 23:32
Format XML - quick bodge
perl -ple 'while (/>(<.*?>)/) {
s{>(<.*?>)([^<]*)}{
$i++;
$i-=1 if substr($1,0,2) eq "</";
$s=">\n".(" "x$i).$1.$2;
$i-=1 if substr($1,0,2) eq "</" or $2 ne "";
$i-=2 if substr($1,0,2) eq "</" and $2 ne "";
$i-=1 if substr($1,-2) eq "/>";
$s
}e
@sleekweasel
sleekweasel / avd-prepare-first-time.sh
Created March 11, 2020 17:02
Bash/adb automation for setting up avds
#!/bin/bash
uidump=/tmp/${0##*/}.$$
unsyncd_uidump_matching_lines() {
adb shell 'rm -f /sdcard/dump.* && uiautomator dump /sdcard/dump.xml 2>/sdcard/dump.err && cat /sdcard/dump.xml' |
tr '<' "\n" |
tee $uidump.full |
grep -Ei "$1" |
xargs -rn1 |
@sleekweasel
sleekweasel / adb.cpp
Last active February 13, 2020 10:52
Patch for adb - prevent automatic server launch, if adb server is not running.
diff --git a/adb/adb.cpp b/adb/adb.cpp
index 6b30be884..e05b707ed 100644
--- a/adb/adb.cpp
+++ b/adb/adb.cpp
@@ -664,7 +664,13 @@ static void ReportServerStartupFailure(pid_t pid) {
while (static_cast<size_t>(i) < lines.size()) fprintf(stderr, "%s\n", lines[i++].c_str());
}
+const char* env_adb_server_autostart = "ADB_SERVER_AUTOSTART";
int launch_server(const std::string& socket_spec) {
@sleekweasel
sleekweasel / w11
Created June 26, 2019 12:50
Apparent deadlock while requriing modules for 100 appium server instances.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
[09:18:58]node 6635 root cwd DIR 254,1 12288 14943924 /local/buildAgent/work/dcce385aab59e3da/bma-calabash
[09:18:58]node 6635 root rtd DIR 0,188 4096 75761720 /
[09:18:58]node 6635 root txt REG 0,188 29055080 36438248 /usr/bin/node
[09:18:58]node 6635 root mem REG 254,1 36438248 /usr/bin/node (path dev=0,188)
[09:18:58]node 6635 root mem REG 254,1 36176220 /lib/x86_64-linux-gnu/libc-2.24.so (path dev=0,188)
[09:18:58]node 6635 root mem REG 254,1 36176248 /lib/x86_64-linux-gnu/libpthread-2.24.so (path dev=0,188)
[09:18:58]node 6635 root mem REG 254,1 3409779 /lib/x86_64-linux-gnu/libgcc_s.so.1 (path dev=0,188)
[09:18:58]node 6635 root mem REG 254,1 36176228 /lib/x86_64-linux-gnu/libm-2.24.so (path dev=0,188)
[09:18:58]node 6635 root mem REG
@sleekweasel
sleekweasel / diff.sh
Last active June 13, 2019 11:56
diff in oldish bash!
#!/bin/bash
#
# Implementation of https://en.wikipedia.org/wiki/Longest_common_subsequence_problem in old-ish BASH
# because my Android emulator doesn't have diff on it.
# Seriously bogs down on files >100 lines
# Could implement the common head and tail trimming efficiency.
XL=()
XC=()
while IFS= read -r line || [[ "$line" ]] ; do XL+=("$line") ; XC+=($(echo "$line" | cksum | tr ' ' -)) ; done < ${1?First filename required}