Use a tree when the problem has:
- hierarchy
- parent/child relationships
- root, leaf, depth, height
- nested data
| #!/usr/bin/env bash | |
| # ai-status.sh | |
| # Quick diagnostic for the four major AI providers plus the shared layers underneath. | |
| # Separates an edge failure (CDN/DNS) from an inference failure (provider status page). | |
| # | |
| # Usage: | |
| # ./ai-status.sh # run once, everything | |
| # ./ai-status.sh edge # run once, edge only | |
| # ./ai-status.sh --watch # loop every 300s (default) | |
| # ./ai-status.sh --watch 60 # loop every 60s |
| #!/usr/bin/env bash | |
| # fix-bluetooth-quality.sh | |
| # | |
| # Purpose | |
| # ------- | |
| # Recover the high-quality Bluetooth A2DP audio profile when Ubuntu reconnects | |
| # a headset/earbuds using only the low-quality HSP/HFP "Handsfree" profile. | |
| # | |
| # This is intended for Ubuntu 24.04 systems using BlueZ + PipeWire + |
| # . save-path.sh | |
| # . save-path.sh save | |
| SAVE_PATH_FILE=$1 | |
| OPTION=$2 | |
| if [ "$OPTION" = "save" ]; then | |
| echo $PWD > $SAVE_PATH_FILE | |
| elif [ "$OPTION" = "create" ]; then | |
| touch $SAVE_PATH_FILE |
| # Source: https://code.mendhak.com/simple-bash-prompt-for-developers-ps1-git/ | |
| function parse_git_dirty { | |
| [[ $(git status --porcelain 2> /dev/null) ]] && echo "*" | |
| } | |
| function parse_git_branch { | |
| git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/ (\1$(parse_git_dirty))/" | |
| } | |
| export PS1="\n\t \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ " |
| // map for list-like things | |
| // mmap(document.querySelectorAll('a'),console.log) | |
| function mmap (listLike, lambda){ for(let i of listLike){lambda(i)} } |
| // Edit on https://gist.github.com/jotafeldmann/c3129225ba5d0c26b5fb32273752e8fc | |
| // Test on https://replit.com/@jotafeldmann/typescript-method-decorator#index.ts | |
| // "experimentalDecorators": true | |
| function log(target: any, propertyName: string, descriptor: PropertyDescriptor) { | |
| const originalMethod = descriptor.value; | |
| descriptor.value = function (...args: any[]) { | |
| const result = originalMethod.apply(this, args); | |
| console.log(`${propertyName}(${args}) = ${result}`); |
| -- Generate query to sort cols (PostgreSQL) | |
| -- https://gist.github.com/jotafeldmann/5eeca544c8e86afe546c794636d27ebf | |
| drop function if exists get_sorted_cols_from_table; | |
| CREATE OR REPLACE FUNCTION get_sorted_cols_from_table(_tbl regclass, OUT result text) | |
| LANGUAGE plpgsql AS | |
| $func$ | |
| BEGIN | |
| EXECUTE format(' | |
| select |
| # Docker solution for "removal of container X is already in progress" | |
| # driver "zfs" failed to remove root filesystem: exit status 1: "/usr/sbin/zfs fs destroy -r rpool/" | |
| # Based on https://github.com/moby/moby/issues/40132#issuecomment-570000174 | |
| docker ps -a | grep Removal | cut -f1 -d' ' | xargs -rt docker rm 2>&1 >/dev/null | grep "dataset does not exist" | awk '{print $(NF-4)}' | sed "s/'//g" | cut -f1 -d':' | xargs -L1 sh -c 'for arg do sudo zfs destroy -R "$arg"; sudo zfs destroy -R "$arg"-init ; sudo zfs create "$arg" ; sudo zfs create "$arg"-init ; ...; done' _ ; docker ps -a | grep Removal | cut -f1 -d' ' | xargs -rt docker rm 2>&1 >/dev/null |