Skip to content

Instantly share code, notes, and snippets.

@gchait
gchait / s3-sizes.sh
Last active March 27, 2026 15:46
List S3 bucket sizes and object counts via CloudWatch
#!/bin/bash -eu
set -o pipefail
START=$(date -u -d "3 days ago" +%FT%TZ)
END=$(date -u +%FT%TZ)
get_metric() {
local bucket="${1}"
local region="${2}"
local metric="${3}"
@gchait
gchait / ruamel_comments.py
Created March 27, 2026 11:45
Preserve comments in a YAML file
# type: ignore
def append_move_comment_list(li, item):
"""Appends an item to a commented list, moving the last comment to the new last item."""
comment = None
i = len(li) - 1
li.append(item)
if i in li.ca.items:
comment = li.ca.items[i][0]
@gchait
gchait / rds-audit-logging.md
Last active March 23, 2026 21:04
RDS PostgreSQL audit logging: log_statement vs pgaudit

What both methods answer equally well

Both methods, with log_line_prefix configured, produce log lines that answer:

  • Who%u (authenticated session user at connect time)
  • When%m (timestamp with ms)
  • What — full SQL text
  • From where%h (client IP)

Both write to the same PostgreSQL log stream. Both require enabled_cloudwatch_logs_exports = ["postgresql"] to ship

@gchait
gchait / inspect-docker-server.sh
Last active March 19, 2026 20:25
Quickly analyze basic stats of a Docker Server
#!/bin/bash -eu
sudo fastfetch --logo none -s \
'Separator:LocalIp:OS:Host:Kernel:Uptime:Separator:CPU:CPUUsage:Loadavg:Separator:Memory:Disk:Separator:Processes'
printf "Docker Volumes: "
sudo docker volume ls -q | wc -l
echo
sudo docker stats --no-stream --format \
@gchait
gchait / android-debloat.sh
Last active March 15, 2026 19:06
Debloat matching packages via ADB without root
#!/bin/bash -eu
set -o pipefail
readonly USER_ID=0
list_packages() {
local flags="${1:-}"
local cmd=(adb shell cmd package list packages --user "${USER_ID}")
[[ -n "${flags}" ]] && cmd+=("${flags}")
@gchait
gchait / spark-cpu-ms.sh
Last active March 15, 2026 19:06
Sum the CPU time an Apache Spark Application took
curl -s https://xxx.yyy.com:18080/api/v1/applications/app-zzz-123/stages |
jq '[ .[] | .executorCpuTime // 0 ] | add / 1e6'
@gchait
gchait / aws-profile-from-acc.sh
Last active March 23, 2026 21:16
Set AWS profile given an account ID
# shellcheck disable=SC2155
export AWS_PROFILE=$(grep -B20 "${ACCOUNT_ID}" ~/.aws/config |
grep "^\[" | tail -1 | tr -d "[]" | awk '{print $NF}')
@gchait
gchait / git-dl.sh
Last active March 23, 2026 21:04
Download a Git repository at a specific commit
mkdir -p xxx
# shellcheck disable=SC2164
cd ./xxx
git init -q
git remote add origin git@aaa.zzz.com:yyy/xxx.git
git fetch origin "${SHA}"
git checkout -q FETCH_HEAD
@gchait
gchait / inline-java.sh
Last active March 15, 2026 19:06
Run Java stdlib from Bash without JShell
echo 'public class X{public static void main(String[]a)throws Exception{System.out.println(java.net.InetAddress.getLocalHost().getCanonicalHostName());}}' > X.java &&
javac X.java && java X && rm X.java X.class
@gchait
gchait / provision-with-sudo.sh
Created December 13, 2025 12:50
Run many functions as root with injected environment variables
provision() {
xx() {
:
}
yy() {
:
}
zz() {