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 / 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}
@sleekweasel
sleekweasel / huh.txt
Last active March 6, 2019 09:21
Duplicated Android device id?!
#!/bin/bash
usbreset_serials() {
echo Resetting.. May cause devices to move - files to ioctl/vanish.
xargs -t |
sed 's/\/serial/\/uevent/g' |
xargs -tr grep -h DEVNAME= |
sed 's/DEVNAME=/\/dev\//' |
xargs -trn1 sudo $(dirname $0)/usbreset
}
@sleekweasel
sleekweasel / README.md
Last active February 10, 2019 11:44
Hooks for recording video of cucumber tests
@sleekweasel
sleekweasel / bounds.rb
Last active July 6, 2018 16:26
More advanced Android Calabash system notifications handling, per https://techblog.badoo.com/blog/2015/06/01/testing-android-notifications-with-calabash/
# Indices for int[4] rectangles.
X0 ||= 0
Y0 ||= 1
X1 ||= 2
Y1 ||= 3
# Calculate clipped and obscured areas based on lists of orthogonal rectangles.
class Bounds
def initialize(r)
@sleekweasel
sleekweasel / xdotool tile matching windows
Last active February 21, 2018 15:42
Tile X11 windows from the command-line with xdotool
tile_emulators() {
DGEO=$(xdotool getdisplaygeometry)
index=0
for p in $( xdotool search 'enymotion' getwindowpid %@|sort |uniq ) ; do
GEOM=$(perl -le "
%A=(tot=>$EMULATORS, ix=>$index, dx=>${DGEO% *}, dy=>${DGEO#* });"'
$sq = int(sqrt($A{tot})); $sq++ if sqrt($A{tot}) > $sq;
$sx=$A{dx}/$sq; $sy=$A{dy}/$sq;
print "windowsize $sx $sy windowmove ",($A{ix} % $sq) * $sx," ",int($A{ix} / $sq) * $sy'
);
@sleekweasel
sleekweasel / patch
Last active January 2, 2018 16:33
Patch for adb usb bus and vid-pid based segregation (multiple, comma separated), boosting simulataneous emulators, and a bodgy mechanism for remote access to this adb. See https://badoo.com/techblog/blog/2016/07/21/segregating-android-devices-for-docker-containers/
diff --git a/adb/client/usb_linux.cpp b/adb/client/usb_linux.cpp
index f9ba7cbc2..f805ab9b4 100644
--- a/adb/client/usb_linux.cpp
+++ b/adb/client/usb_linux.cpp
@@ -120,6 +120,71 @@ static inline bool contains_non_digit(const char* name) {
return false;
}
+static int iterate_numbers(const char* list, int* rejects) {
+ const char* p = list;