Tidy, copy-ready scripts and prompts for AI agents and humans: bash, Python, JavaScript, automation, data, web, DevOps.
π’ Last checked Nov 20, 2026, 12:03 AM PT44 entries43 links verifiedDaily walkthrough Β· last run Nov 20, 2026, 12:03 AM PT
Every script is original, short and safe by default (dry-run first where it changes things). Each says what it does and how to run it, and has a copy button. The daily walkthrough syntax-checks every script and re-checks every docs link.
Groups identical files by size, then SHA-256. Read-only.
Run:python3 dupes.py ~/Pictures
python
#!/usr/bin/env python3
"""dupes.py [root] - prints groups of identical files. Deletes nothing."""
import hashlib
import os
import sys
from collections import defaultdict
root = sys.argv[1] if len(sys.argv) > 1 else "."
by_size = defaultdict(list)
for d, _, files in os.walk(root):
for n in files:
p = os.path.join(d, n)
try:
by_size[os.path.getsize(p)].append(p)
except OSError:
pass
def sha(p):
h = hashlib.sha256()
with open(p, "rb") as f:
for chunk in iter(lambda: f.read(1 << 20), b""):
h.update(chunk)
return h.hexdigest()
for size, paths in by_size.items():
if size == 0 or len(paths) < 2:
continue
groups = defaultdict(list)
for p in paths:
groups[sha(p)].append(p)
for same in groups.values():
if len(same) > 1:
print(f"{size} bytes x{len(same)}:")
for p in same:
print(" " + p)
#!/usr/bin/env python3
"""envcheck.py NAME [NAME...] - exit 1 if any are unset or empty. Values are never printed."""
import os
import sys
missing = [n for n in sys.argv[1:] if not os.environ.get(n)]
for n in sys.argv[1:]:
print(f"{n}: {'MISSING' if n in missing else 'set'}")
sys.exit(1 if missing else 0)
Estimates tokens (~4 characters each in English) to budget prompts. An estimate, not exact.
Run:python3 tokens.py prompt.txt
python
#!/usr/bin/env python3
"""tokens.py <file> - rough English token estimate (chars/4). Use a real tokenizer for billing."""
import sys
text = open(sys.argv[1], encoding="utf-8").read()
print(f"chars={len(text)} words={len(text.split())} est_tokens~{round(len(text) / 4)}")
A crontab line that skips a run if the last one is still going.
Run:crontab -e, then paste the line (edit the paths).
bash
# m h dom mon dow command (runs 6:00 every day; flock -n skips if still running)
0 6 * * * flock -n /tmp/daily-job.lock /home/me/bin/daily-job.sh >> /home/me/logs/daily-job.log 2>&1
Commits a git repo only when files changed. Good for notes and configs.
Run:./git-snapshot.sh ~/notes
bash
#!/usr/bin/env bash
# git-snapshot.sh [repo]
set -euo pipefail
cd "${1:-.}"
if [ -n "$(git status --porcelain)" ]; then
git add -A
git commit -qm "snapshot $(date -Iseconds)"
echo "committed"
else
echo "no changes"
fi
#!/usr/bin/env python3
"""jsonl_check.py <file> - exit 1 on the first invalid line."""
import json
import sys
bad = 0
with open(sys.argv[1], encoding="utf-8") as f:
for n, line in enumerate(f, 1):
if not line.strip():
continue
try:
json.loads(line)
except json.JSONDecodeError as e:
print(f"line {n}: {e}")
bad += 1
print("ok" if not bad else f"{bad} bad line(s)")
sys.exit(1 if bad else 0)
Window-function query: best 3 items in each category.
Run:Run in SQLite 3.25+, PostgreSQL or MySQL 8+.
sql
-- top 3 products by sales in each category
SELECT category, product, sales
FROM (
SELECT category, product, sales,
ROW_NUMBER() OVER (PARTITION BY category ORDER BY sales DESC) AS rn
FROM product_sales
) ranked
WHERE rn <= 3
ORDER BY category, sales DESC;
Finds links on a page and reports any that fail (stdlib only).
Run:python3 linkcheck.py https://example.com
python
#!/usr/bin/env python3
"""linkcheck.py <page-url> - HEAD each link, falls back to GET."""
import sys
import urllib.request
from html.parser import HTMLParser
from urllib.parse import urljoin
UA = {"User-Agent": "linkcheck-example/1.0"}
class Links(HTMLParser):
def __init__(self):
super().__init__()
self.found = set()
def handle_starttag(self, tag, attrs):
href = dict(attrs).get("href")
if tag == "a" and href and href.startswith(("http", "/")):
self.found.add(href)
def status(url):
for method in ("HEAD", "GET"):
try:
req = urllib.request.Request(url, method=method, headers=UA)
with urllib.request.urlopen(req, timeout=10) as r:
return r.status
except Exception as e:
err = getattr(e, "code", str(e))
return err
page = sys.argv[1]
html = urllib.request.urlopen(urllib.request.Request(page, headers=UA), timeout=10).read().decode("utf-8", "replace")
p = Links()
p.feed(html)
for href in sorted(p.found):
url = urljoin(page, href)
s = status(url)
if s != 200:
print(s, url)
Warns when any mounted filesystem passes a usage threshold.
Run:./disk-alert.sh 85
bash
#!/usr/bin/env bash
# disk-alert.sh [percent=90] - exit 1 if any filesystem is above the threshold
set -euo pipefail
limit="${1:-90}"; alert=0
while read -r use mount; do
pct="${use%\%}"
if [ "$pct" -ge "$limit" ]; then echo "WARN $mount at ${pct}%"; alert=1; fi
done < <(df -P -x tmpfs -x devtmpfs | awk 'NR>1 {print $5, $6}')
exit "$alert"
Run:Paste into any agent and fill in the brackets.
text
GOAL: <one sentence>
CONTEXT: <files, links, what already exists>
DO:
1. <step>
2. <step>
DON'T: delete anything, send messages, spend money, or touch <x> without asking.
DONE WHEN: <a check anyone can run>
REPORT: what changed (paths), what you verified and how, what's left or blocked.
Gets clean JSON out of messy text, with nulls instead of guesses.
Run:Paste with your text; parse the reply as JSON.
text
Extract the fields below from the text. Rules:
- Output ONLY a JSON object, no prose.
- Use null when the text does not state a value. Never guess.
- Dates as YYYY-MM-DD.
Fields: {"name": string, "company": string, "email": string, "date": string, "amount": number}
TEXT:
<<<
<paste text here>
>>>
Review the diff below as a senior engineer.
For each issue output one line: [HIGH|MED|LOW] file:line - problem - suggested fix.
Check: correctness, security (injection, secrets, auth), error handling, tests, naming.
End with: VERDICT: approve | request changes, and one sentence why.
DIFF:
<paste diff>
Makes an agent prove its work before claiming success.
Run:Append to the end of any agent task.
text
Before you report done:
1. Restate the goal in one line.
2. List every requirement and, for each, the evidence it is met (command output, file path, URL + status).
3. List anything you could not verify and why.
4. If any requirement is unmet, say "NOT DONE" first.