Skip to content

Instantly share code, notes, and snippets.

View copyleftdev's full-sized avatar

Don Johnson copyleftdev

View GitHub Profile
@copyleftdev
copyleftdev / linux-sponge.sh
Created May 25, 2026 20:43
sponge — buffer stdin before writing: safe in-place pipeline transforms
# sponge — soak up all stdin, then write (from moreutils)
# sudo apt install moreutils
# THE PROBLEM: this destroys the file before sort reads it
sort file.txt > file.txt # ⚠ race condition — file truncated on open
# THE FIX:
sort file.txt | sponge file.txt # reads all input, then writes atomically
# In-place JSON formatting:
@copyleftdev
copyleftdev / linux-ts.sh
Created May 25, 2026 20:43
ts — prepend a timestamp to every line of stdin
# ts — timestamp every line of stdin (from moreutils)
# sudo apt install moreutils
command | ts # May 25 13:01:02 <line>
command | ts '[%H:%M:%S]' # [13:01:02] <line>
command | ts '[%Y-%m-%dT%H:%M:%S]' # [2024-05-25T13:01:02] <line>
command | ts -s '%.s' # relative: seconds since last line
# The full AI logging pattern — timestamp, merge stderr, save + display:
agent-command 2>&1 | ts '[%H:%M:%S]' | tee run.log
@copyleftdev
copyleftdev / linux-pv.sh
Created May 25, 2026 20:43
pv — pipe viewer: progress bar and throughput for any pipeline
# pv — add a progress bar to any pipeline
pv input.jsonl > /dev/null # bytes + throughput
pv --line-mode input.jsonl | process-tool # line count mode
# Drop into any pipeline — transparent pass-through:
cat input.jsonl | pv | python3 process.py
# ETA with known total:
LINES=$(wc -l < input.jsonl)
@copyleftdev
copyleftdev / linux-tee.sh
Created May 25, 2026 20:43
tee — split stdout to terminal and file simultaneously
# tee — write to stdout AND a file at the same time
<command> | tee output.log # overwrite
<command> | tee -a output.log # append
<command> | tee file1 file2 # fan out to multiple files
# The AI workflow pattern — log + timestamps + live view in one pipeline:
agent-command 2>&1 | ts '[%H:%M:%S]' | tee run-$(date +%Y%m%d-%H%M%S).log
# Process and preserve the original simultaneously:
@copyleftdev
copyleftdev / linux-watch.sh
Created May 25, 2026 20:43
watch — monitor any command output on a repeating interval
# watch — repeat a command every N seconds with a live-updating view
# Basic: refresh every 2 seconds
watch -n2 <command>
# Highlight what changed since last refresh
watch -n1 -d ls -lh outputs/
# Monitor GPU memory during inference
watch -n1 nvidia-smi --query-gpu=memory.used,memory.free --format=csv
@copyleftdev
copyleftdev / git-archaeology.md
Created May 25, 2026 20:32
git-archaeology Claude Code skill — reasoning chains for when to use advanced git commands

git-archaeology

Reason through git workflow problems and surface the right advanced git command. Each section maps a real situation to a specific tool with concrete commands to run.

TRIGGER

Invoke this skill when the user:

  • Needs to find when or where a bug was introduced
  • Needs to work on more than one branch at the same time
@copyleftdev
copyleftdev / git-bundle.sh
Created May 25, 2026 20:21
git bundle — pack an entire repo into a single portable file
# git bundle — the git sneakernet
# No network. Air-gapped machine. USB drive. It still works.
# Pack everything — every ref, every object:
git bundle create repo.bundle --all
# Verify the bundle is self-contained:
git bundle verify repo.bundle
# Clone from the bundle (it's a valid git remote):
@copyleftdev
copyleftdev / git-blame-copy.sh
Created May 25, 2026 20:21
git blame -C — follow code that moved between files
# git blame -C — follow moved code across files
# Standard blame breaks when code moves. -C detects copies.
# Without copy detection — everything attributed to the refactor commit:
git blame src/freq.py
# With copy detection — attribution follows the original author:
git blame -C -C -C src/freq.py
# Three -C flags:
@copyleftdev
copyleftdev / git-fixup-autosquash.sh
Created May 25, 2026 20:21
git commit --fixup and git rebase --autosquash
# git commit --fixup + git rebase --autosquash
# Fix any past commit cleanly — no painful interactive rebase editing.
# Spot a typo in the third commit back:
git add the-fix.rs
git commit --fixup HEAD~2
# creates: "fixup! <original commit message>"
# Let autosquash reorder + squash automatically:
git rebase -i --autosquash main
@copyleftdev
copyleftdev / git-sparse-checkout.sh
Created May 25, 2026 20:20
git sparse-checkout — materialize only the paths you need
# git sparse-checkout — check out only what you need
# Monorepo with 40 packages? Only materialize the two you work in.
git sparse-checkout init --cone
git sparse-checkout set packages/auth packages/api
# Everything else vanishes from disk — still in history, just not on disk.
# Add more paths any time:
git sparse-checkout add tests