Skip to content

Instantly share code, notes, and snippets.

View copyleftdev's full-sized avatar

Don Johnson copyleftdev

View GitHub Profile
@copyleftdev
copyleftdev / linux-tac.sh
Created May 25, 2026 20:44
tac — reverse line order of any file or stream
# tac — cat backwards: last line first
# (tac is cat spelled backwards)
tac logfile.log # reverse entire file
tac logfile.log | head -20 # last 20 lines, newest-first
tac logfile.log | grep -m1 'ERROR' # last occurrence of ERROR
# Process a JSONL file newest-first:
tac data.jsonl | head -5 | python3 -c "
import sys, json
@copyleftdev
copyleftdev / linux-comm.sh
Created May 25, 2026 20:44
comm — compare two sorted files: unique to each and shared
# comm — line-by-line comparison of two sorted files
# Input must be sorted. Use: sort file | sponge file
comm a.txt b.txt # 3 columns: only-A | only-B | both
comm -23 a.txt b.txt # only in A (suppress cols 2 and 3)
comm -13 a.txt b.txt # only in B (suppress cols 1 and 3)
comm -12 a.txt b.txt # in both (suppress cols 1 and 2)
# Sort on the fly with process substitution:
@copyleftdev
copyleftdev / linux-column.sh
Created May 25, 2026 20:44
column — format delimited text into aligned tables
# column — align delimited input into a readable table
# TSV file:
column -t -s $'\t' models.tsv
# CSV:
column -t -s ',' data.csv
# Colon-separated:
column -t -s ':' /etc/passwd
@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):