Skip to content

Instantly share code, notes, and snippets.

@t-animal
t-animal / oucher.sh
Last active May 26, 2025 08:04
Oucher for dreame robots
!/bin/sh
# Installation:
# Requires `strace`, best installed as statically built binary using soar https://soar.qaidvoid.dev/
# Encode ouch-sounds with `ffmpeg -i <infile> -b:a 80k -ar 16000 -f ogg <outfile> `
# Add ouch-sounds to ./ogg
#
# Run by adding this to /data/_root_postboot.sh
#
# if [[ -x /data/oucher/oucher.sh ]]; then

As per [MDN][1] when using a regular expression for splitting a string and the regex contains groups, the groups are included in the result (whereas the matched part would normally be discarded). I.e. you get ['before-match', 'matched group', after-match']. Also, matches at the beginning of a string result in an empty string as first entry in the results array.

[emptyBecauseMatchAtStart, group, rest] = '<=asdf'.split(/(<=|>=|<|>)/)

The second is a bit counter-intuitive:

'<=asdf'.split(/(<=)|(>=)|<|>/) // results in ["", "<=", undefined, "asdf"]

The empty string, "<=" and "asdf" are clear. The undefined is a result of the second group (>=) not matching anything.