{
 "list": "AI Scripts",
 "slug": "scripts",
 "url": "https://ai.justout.today/scripts/",
 "publisher": "JustOut Today",
 "tagline": "Tidy, copy-ready scripts and prompts for AI agents and humans: bash, Python, JavaScript, automation, data, web, DevOps.",
 "categories": [
  "Bash",
  "Python",
  "JavaScript",
  "Automation",
  "Data",
  "Web",
  "DevOps",
  "Prompts for agents"
 ],
 "built": "2026-11-20T00:17:41-08:00",
 "last_walkthrough": "2026-11-20T00:03:30-08:00",
 "entries": [
  {
   "id": "dated-backup-of-a-folder",
   "name": "Dated backup of a folder",
   "category": "Bash",
   "description": "Creates a timestamped .tar.gz of any folder.",
   "url": "https://www.gnu.org/software/bash/manual/bash.html",
   "lang": "bash",
   "run": "./backup-dated.sh ~/projects/site ~/backups",
   "code": "#!/usr/bin/env bash\n# backup-dated.sh <dir> [dest]  -> dest/<name>-YYYYmmdd-HHMMSS.tar.gz\nset -euo pipefail\nsrc=\"${1:?usage: $0 <dir> [dest]}\"; dest=\"${2:-.}\"\nmkdir -p \"$dest\"\nstamp=\"$(date +%Y%m%d-%H%M%S)\"\nout=\"$dest/$(basename \"$src\")-$stamp.tar.gz\"\ntar -czf \"$out\" -C \"$(dirname \"$src\")\" \"$(basename \"$src\")\"\necho \"wrote $out ($(du -h \"$out\" | cut -f1))\"\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "find-the-biggest-files",
   "name": "Find the biggest files",
   "category": "Bash",
   "description": "Lists the N largest files under a folder (GNU find).",
   "url": "https://www.gnu.org/software/bash/manual/bash.html",
   "lang": "bash",
   "run": "./big-files.sh /var/log 20",
   "code": "#!/usr/bin/env bash\n# big-files.sh [dir] [count]\nset -euo pipefail\ndir=\"${1:-.}\"; n=\"${2:-20}\"\nfind \"$dir\" -type f -printf '%s\\t%p\\n' 2>/dev/null \\\n  | sort -rn | head -n \"$n\" \\\n  | awk -F'\\t' '{printf \"%8.1f MB  %s\\n\", $1/1048576, $2}'\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "retry-with-exponential-backoff",
   "name": "Retry with exponential backoff",
   "category": "Bash",
   "description": "Re-runs a flaky command up to N times, doubling the wait each time.",
   "url": "https://www.gnu.org/software/bash/manual/bash.html",
   "lang": "bash",
   "run": "./retry.sh 5 curl -fsS https://example.com",
   "code": "#!/usr/bin/env bash\n# retry.sh <attempts> <command...>\nset -uo pipefail\nmax=\"${1:?usage: $0 <attempts> <command...>}\"; shift\ndelay=1\nfor ((i = 1; i <= max; i++)); do\n  if \"$@\"; then exit 0; fi\n  echo \"attempt $i/$max failed; sleeping ${delay}s\" >&2\n  sleep \"$delay\"; delay=$((delay * 2))\ndone\nexit 1\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "is-a-port-open",
   "name": "Is a port open?",
   "category": "Bash",
   "description": "Checks a TCP port using only bash and coreutils.",
   "url": "https://www.gnu.org/software/bash/manual/bash.html",
   "lang": "bash",
   "run": "./port-check.sh example.com 443",
   "code": "#!/usr/bin/env bash\n# port-check.sh <host> <port> [timeout-seconds]\nhost=\"${1:?host}\"; port=\"${2:?port}\"; t=\"${3:-3}\"\nif timeout \"$t\" bash -c \"</dev/tcp/$host/$port\" 2>/dev/null; then\n  echo \"open   $host:$port\"\nelse\n  echo \"closed $host:$port\"; exit 1\nfi\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "remove-duplicate-lines-keep-order",
   "name": "Remove duplicate lines, keep order",
   "category": "Bash",
   "description": "Dedupes a file or stdin without sorting.",
   "url": "https://www.gnu.org/software/bash/manual/bash.html",
   "lang": "bash",
   "run": "./dedupe.sh urls.txt > unique.txt",
   "code": "#!/usr/bin/env bash\n# dedupe.sh [file]  (reads stdin if no file)\nawk '!seen[$0]++' \"${1:--}\"\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "safe-file-renamer-slugify",
   "name": "Safe file renamer (slugify)",
   "category": "Bash",
   "description": "Renames files to lowercase-dashes. Dry-run unless you pass --apply.",
   "url": "https://www.gnu.org/software/bash/manual/bash.html",
   "lang": "bash",
   "run": "./slugify-names.sh ~/Downloads --apply",
   "code": "#!/usr/bin/env bash\n# slugify-names.sh [dir] [--apply]\nset -euo pipefail\ndir=\"${1:-.}\"; apply=\"${2:-}\"\nfor f in \"$dir\"/*; do\n  [ -f \"$f\" ] || continue\n  base=\"$(basename \"$f\")\"\n  new=\"$(printf '%s' \"$base\" | tr '[:upper:]' '[:lower:]' \\\n        | sed -E 's/[^a-z0-9.]+/-/g; s/-+/-/g; s/^-|-$//g')\"\n  [ \"$base\" = \"$new\" ] && continue\n  if [ -e \"$dir/$new\" ]; then echo \"skip (exists): $new\"; continue; fi\n  if [ \"$apply\" = \"--apply\" ]; then mv -- \"$f\" \"$dir/$new\"; echo \"renamed: $base -> $new\"\n  else echo \"would rename: $base -> $new\"; fi\ndone\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "watch-a-log-for-a-pattern",
   "name": "Watch a log for a pattern",
   "category": "Bash",
   "description": "Prints timestamped lines matching a regex as they are written.",
   "url": "https://www.gnu.org/software/bash/manual/bash.html",
   "lang": "bash",
   "run": "./watch-log.sh /var/log/syslog 'error|fail'",
   "code": "#!/usr/bin/env bash\n# watch-log.sh <file> <regex>\nset -euo pipefail\nfile=\"${1:?file}\"; pat=\"${2:?regex}\"\ntail -Fn0 \"$file\" | grep --line-buffered -E \"$pat\" | while IFS= read -r line; do\n  printf '[%s] %s\\n' \"$(date +%T)\" \"$line\"\ndone\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "csv-to-json",
   "name": "CSV to JSON",
   "category": "Python",
   "description": "Converts a CSV with a header row into a JSON array.",
   "url": "https://docs.python.org/3/library/csv.html",
   "lang": "python",
   "run": "python3 csv2json.py data.csv > data.json",
   "code": "#!/usr/bin/env python3\n\"\"\"csv2json.py input.csv > out.json\"\"\"\nimport csv\nimport json\nimport sys\n\nwith open(sys.argv[1], newline=\"\", encoding=\"utf-8\") as f:\n    rows = list(csv.DictReader(f))\njson.dump(rows, sys.stdout, indent=2, ensure_ascii=False)\nprint()\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "find-duplicate-files",
   "name": "Find duplicate files",
   "category": "Python",
   "description": "Groups identical files by size, then SHA-256. Read-only.",
   "url": "https://docs.python.org/3/library/hashlib.html",
   "lang": "python",
   "run": "python3 dupes.py ~/Pictures",
   "code": "#!/usr/bin/env python3\n\"\"\"dupes.py [root] - prints groups of identical files. Deletes nothing.\"\"\"\nimport hashlib\nimport os\nimport sys\nfrom collections import defaultdict\n\nroot = sys.argv[1] if len(sys.argv) > 1 else \".\"\nby_size = defaultdict(list)\nfor d, _, files in os.walk(root):\n    for n in files:\n        p = os.path.join(d, n)\n        try:\n            by_size[os.path.getsize(p)].append(p)\n        except OSError:\n            pass\n\ndef sha(p):\n    h = hashlib.sha256()\n    with open(p, \"rb\") as f:\n        for chunk in iter(lambda: f.read(1 << 20), b\"\"):\n            h.update(chunk)\n    return h.hexdigest()\n\nfor size, paths in by_size.items():\n    if size == 0 or len(paths) < 2:\n        continue\n    groups = defaultdict(list)\n    for p in paths:\n        groups[sha(p)].append(p)\n    for same in groups.values():\n        if len(same) > 1:\n            print(f\"{size} bytes x{len(same)}:\")\n            for p in same:\n                print(\"  \" + p)\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "get-json-with-retries-stdlib",
   "name": "GET JSON with retries (stdlib)",
   "category": "Python",
   "description": "Fetches JSON with a timeout, a polite User-Agent and retries.",
   "url": "https://docs.python.org/3/library/urllib.request.html",
   "lang": "python",
   "run": "python3 get_json.py https://api.github.com/repos/python/cpython",
   "code": "#!/usr/bin/env python3\n\"\"\"get_json.py <url> - prints pretty JSON.\"\"\"\nimport json\nimport sys\nimport time\nimport urllib.request\n\ndef get_json(url, tries=3, timeout=10):\n    req = urllib.request.Request(url, headers={\"User-Agent\": \"example-script/1.0\", \"Accept\": \"application/json\"})\n    for i in range(tries):\n        try:\n            with urllib.request.urlopen(req, timeout=timeout) as r:\n                return json.load(r)\n        except Exception as e:\n            if i == tries - 1:\n                raise\n            print(f\"retry {i + 1}: {e}\", file=sys.stderr)\n            time.sleep(2 ** i)\n\nprint(json.dumps(get_json(sys.argv[1]), indent=2))\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "check-required-env-vars-without-printing-them",
   "name": "Check required env vars (without printing them)",
   "category": "Python",
   "description": "Fails fast if secrets are missing, never echoing their values.",
   "url": "https://docs.python.org/3/library/os.html#os.environ",
   "lang": "python",
   "run": "python3 envcheck.py OPENAI_API_KEY DATABASE_URL",
   "code": "#!/usr/bin/env python3\n\"\"\"envcheck.py NAME [NAME...] - exit 1 if any are unset or empty. Values are never printed.\"\"\"\nimport os\nimport sys\n\nmissing = [n for n in sys.argv[1:] if not os.environ.get(n)]\nfor n in sys.argv[1:]:\n    print(f\"{n}: {'MISSING' if n in missing else 'set'}\")\nsys.exit(1 if missing else 0)\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "rate-limiter-decorator",
   "name": "Rate limiter decorator",
   "category": "Python",
   "description": "Limits how often a function (like an API call) can run.",
   "url": "https://docs.python.org/3/library/functools.html",
   "lang": "python",
   "run": "python3 ratelimit.py",
   "code": "#!/usr/bin/env python3\n\"\"\"ratelimit.py - @rate_limited(calls, per_seconds) for API clients.\"\"\"\nimport functools\nimport time\nfrom collections import deque\n\ndef rate_limited(calls, per):\n    stamps = deque()\n    def deco(fn):\n        @functools.wraps(fn)\n        def wrapper(*a, **kw):\n            now = time.monotonic()\n            while stamps and now - stamps[0] > per:\n                stamps.popleft()\n            if len(stamps) >= calls:\n                time.sleep(per - (now - stamps[0]))\n            stamps.append(time.monotonic())\n            return fn(*a, **kw)\n        return wrapper\n    return deco\n\n@rate_limited(calls=2, per=1.0)\ndef ping(i):\n    print(f\"{time.strftime('%X')} call {i}\")\n\nif __name__ == \"__main__\":\n    for i in range(5):\n        ping(i)\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "chunk-text-for-rag",
   "name": "Chunk text for RAG",
   "category": "Python",
   "description": "Splits text into overlapping word chunks ready for embedding.",
   "url": "https://en.wikipedia.org/wiki/Retrieval-augmented_generation",
   "lang": "python",
   "run": "python3 chunk.py notes.txt 200 40 > chunks.jsonl",
   "code": "#!/usr/bin/env python3\n\"\"\"chunk.py <file> [words=200] [overlap=40] -> JSON Lines {id, text}\"\"\"\nimport json\nimport sys\n\npath = sys.argv[1]\nsize = int(sys.argv[2]) if len(sys.argv) > 2 else 200\noverlap = int(sys.argv[3]) if len(sys.argv) > 3 else 40\nif overlap >= size:\n    sys.exit(\"overlap must be smaller than chunk size\")\nwords = open(path, encoding=\"utf-8\").read().split()\nstep = size - overlap\nfor n, start in enumerate(range(0, max(len(words) - overlap, 1), step)):\n    print(json.dumps({\"id\": n, \"text\": \" \".join(words[start:start + size])}))\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "rough-token-estimate",
   "name": "Rough token estimate",
   "category": "Python",
   "description": "Estimates tokens (~4 characters each in English) to budget prompts. An estimate, not exact.",
   "url": "https://platform.openai.com/tokenizer",
   "lang": "python",
   "run": "python3 tokens.py prompt.txt",
   "code": "#!/usr/bin/env python3\n\"\"\"tokens.py <file> - rough English token estimate (chars/4). Use a real tokenizer for billing.\"\"\"\nimport sys\n\ntext = open(sys.argv[1], encoding=\"utf-8\").read()\nprint(f\"chars={len(text)} words={len(text.split())} est_tokens~{round(len(text) / 4)}\")\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "status": "bot-blocked"
  },
  {
   "id": "debounce",
   "name": "Debounce",
   "category": "JavaScript",
   "description": "Runs a function only after input stops for N ms (search boxes).",
   "url": "https://developer.mozilla.org/en-US/docs/Web/API/setTimeout",
   "lang": "javascript",
   "run": "Import and wrap your handler: input.addEventListener('input', debounce(search, 250))",
   "code": "// debounce.js\nexport function debounce(fn, ms = 250) {\n  let t;\n  return (...args) => {\n    clearTimeout(t);\n    t = setTimeout(() => fn(...args), ms);\n  };\n}\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "fetch-with-timeout",
   "name": "fetch with timeout",
   "category": "JavaScript",
   "description": "Aborts a fetch that takes too long (browser or Node 18+).",
   "url": "https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static",
   "lang": "javascript",
   "run": "const res = await fetchWithTimeout('https://example.com', {}, 5000)",
   "code": "// fetch-timeout.js\nexport async function fetchWithTimeout(url, options = {}, ms = 8000) {\n  const res = await fetch(url, { ...options, signal: AbortSignal.timeout(ms) });\n  if (!res.ok) throw new Error(`HTTP ${res.status} for ${url}`);\n  return res;\n}\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "copy-to-clipboard-buttons",
   "name": "Copy-to-clipboard buttons",
   "category": "JavaScript",
   "description": "Adds a working Copy button to every <pre><code> block.",
   "url": "https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText",
   "lang": "javascript",
   "run": "Include on any page with <script src=\"copy.js\" defer></script>",
   "code": "// copy.js\ndocument.querySelectorAll(\"pre > code\").forEach((code) => {\n  const btn = document.createElement(\"button\");\n  btn.type = \"button\";\n  btn.textContent = \"Copy\";\n  btn.addEventListener(\"click\", async () => {\n    await navigator.clipboard.writeText(code.innerText);\n    btn.textContent = \"Copied!\";\n    setTimeout(() => (btn.textContent = \"Copy\"), 1500);\n  });\n  code.parentElement.before(btn);\n});\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "localstorage-with-expiry",
   "name": "localStorage with expiry",
   "category": "JavaScript",
   "description": "Caches a value in the browser that expires after a set time.",
   "url": "https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage",
   "lang": "javascript",
   "run": "setCached('feed', data, 3600e3); getCached('feed')",
   "code": "// cache.js\nexport function setCached(key, value, ttlMs) {\n  localStorage.setItem(key, JSON.stringify({ value, exp: Date.now() + ttlMs }));\n}\nexport function getCached(key) {\n  const raw = localStorage.getItem(key);\n  if (!raw) return null;\n  const { value, exp } = JSON.parse(raw);\n  if (Date.now() > exp) { localStorage.removeItem(key); return null; }\n  return value;\n}\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "instant-list-filter",
   "name": "Instant list filter",
   "category": "JavaScript",
   "description": "Filters list items as you type, no framework.",
   "url": "https://developer.mozilla.org/en-US/docs/Web/API/Element/input_event",
   "lang": "javascript",
   "run": "Add <input id=\"q\"> above a <ul id=\"list\"> and include this script.",
   "code": "// filter.js\nconst q = document.getElementById(\"q\");\nconst items = [...document.querySelectorAll(\"#list li\")];\nq.addEventListener(\"input\", () => {\n  const term = q.value.trim().toLowerCase();\n  for (const li of items) {\n    li.hidden = term !== \"\" && !li.textContent.toLowerCase().includes(term);\n  }\n});\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "cron-job-that-can-t-overlap",
   "name": "Cron job that can't overlap",
   "category": "Automation",
   "description": "A crontab line that skips a run if the last one is still going.",
   "url": "https://man7.org/linux/man-pages/man1/flock.1.html",
   "lang": "bash",
   "run": "crontab -e, then paste the line (edit the paths).",
   "code": "# m h dom mon dow  command  (runs 6:00 every day; flock -n skips if still running)\n0 6 * * * flock -n /tmp/daily-job.lock /home/me/bin/daily-job.sh >> /home/me/logs/daily-job.log 2>&1\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "auto-commit-a-snapshot-if-anything-changed",
   "name": "Auto-commit a snapshot if anything changed",
   "category": "Automation",
   "description": "Commits a git repo only when files changed. Good for notes and configs.",
   "url": "https://git-scm.com/docs/git-status",
   "lang": "bash",
   "run": "./git-snapshot.sh ~/notes",
   "code": "#!/usr/bin/env bash\n# git-snapshot.sh [repo]\nset -euo pipefail\ncd \"${1:-.}\"\nif [ -n \"$(git status --porcelain)\" ]; then\n  git add -A\n  git commit -qm \"snapshot $(date -Iseconds)\"\n  echo \"committed\"\nelse\n  echo \"no changes\"\nfi\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "run-a-command-when-a-folder-changes",
   "name": "Run a command when a folder changes",
   "category": "Automation",
   "description": "Uses inotifywait to react to new or changed files.",
   "url": "https://man7.org/linux/man-pages/man1/inotifywait.1.html",
   "lang": "bash",
   "run": "./on-change.sh ./inbox 'echo changed: '",
   "code": "#!/usr/bin/env bash\n# on-change.sh <dir> <command-prefix>   (needs inotify-tools)\nset -euo pipefail\ndir=\"${1:?dir}\"; cmd=\"${2:?command}\"\ninotifywait -m -e close_write,moved_to --format '%w%f' \"$dir\" | while IFS= read -r path; do\n  $cmd \"$path\"\ndone\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "post-to-a-webhook",
   "name": "Post to a webhook",
   "category": "Automation",
   "description": "Sends a JSON message to a webhook URL kept in an env var.",
   "url": "https://curl.se/docs/manpage.html",
   "lang": "bash",
   "run": "WEBHOOK_URL=... ./notify.sh 'Backup finished'",
   "code": "#!/usr/bin/env bash\n# notify.sh <message>   (WEBHOOK_URL must be set; never hard-code it)\nset -euo pipefail\n: \"${WEBHOOK_URL:?set WEBHOOK_URL}\"\nmsg=\"${1:?message}\"\npayload=\"$(python3 -c 'import json,sys; print(json.dumps({\"text\": sys.argv[1]}))' \"$msg\")\"\ncurl -fsS -X POST -H 'Content-Type: application/json' -d \"$payload\" \"$WEBHOOK_URL\" >/dev/null\necho \"sent\"\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "systemd-timer-instead-of-cron",
   "name": "systemd timer instead of cron",
   "category": "Automation",
   "description": "A service + timer pair that runs a script daily and logs to the journal.",
   "url": "https://www.freedesktop.org/software/systemd/man/latest/systemd.timer.html",
   "lang": "ini",
   "run": "Save both files in ~/.config/systemd/user/, then: systemctl --user enable --now daily-job.timer",
   "code": "# ~/.config/systemd/user/daily-job.service\n[Unit]\nDescription=Daily job\n\n[Service]\nType=oneshot\nExecStart=%h/bin/daily-job.sh\n\n# ~/.config/systemd/user/daily-job.timer\n[Unit]\nDescription=Run daily-job every morning\n\n[Timer]\nOnCalendar=*-*-* 06:00:00\nPersistent=true\n\n[Install]\nWantedBy=timers.target\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "load-a-csv-into-sqlite",
   "name": "Load a CSV into SQLite",
   "category": "Data",
   "description": "Creates a SQLite table from any CSV so you can query it with SQL.",
   "url": "https://docs.python.org/3/library/sqlite3.html",
   "lang": "python",
   "run": "python3 csv2sqlite.py sales.csv sales.db sales",
   "code": "#!/usr/bin/env python3\n\"\"\"csv2sqlite.py <csv> <db> <table>\"\"\"\nimport csv\nimport sqlite3\nimport sys\n\nsrc, db, table = sys.argv[1:4]\nwith open(src, newline=\"\", encoding=\"utf-8\") as f:\n    reader = csv.reader(f)\n    header = next(reader)\n    cols = \", \".join(f'\"{h}\"' for h in header)\n    marks = \", \".join(\"?\" for _ in header)\n    con = sqlite3.connect(db)\n    con.execute(f'CREATE TABLE IF NOT EXISTS \"{table}\" ({cols})')\n    con.executemany(f'INSERT INTO \"{table}\" VALUES ({marks})', reader)\n    con.commit()\n    print(con.execute(f'SELECT COUNT(*) FROM \"{table}\"').fetchone()[0], \"rows\")\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "jq-one-liners-for-json-lists",
   "name": "jq one-liners for JSON lists",
   "category": "Data",
   "description": "Turn a JSON array into CSV, count by a field, or filter.",
   "url": "https://jqlang.org/manual/",
   "lang": "bash",
   "run": "Run each line in a shell with jq installed.",
   "code": "#!/usr/bin/env bash\n# Assumes data.json is an array of objects with name, url, category.\njq -r '.[] | [.name, .url] | @csv' data.json                      # to CSV\njq 'group_by(.category) | map({category: .[0].category, n: length})' data.json  # counts\njq '[.[] | select(.category == \"Coding\")]' data.json             # filter\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "validate-a-json-lines-file",
   "name": "Validate a JSON Lines file",
   "category": "Data",
   "description": "Reports the line number of any bad JSON line.",
   "url": "https://jsonlines.org",
   "lang": "python",
   "run": "python3 jsonl_check.py data.jsonl",
   "code": "#!/usr/bin/env python3\n\"\"\"jsonl_check.py <file> - exit 1 on the first invalid line.\"\"\"\nimport json\nimport sys\n\nbad = 0\nwith open(sys.argv[1], encoding=\"utf-8\") as f:\n    for n, line in enumerate(f, 1):\n        if not line.strip():\n            continue\n        try:\n            json.loads(line)\n        except json.JSONDecodeError as e:\n            print(f\"line {n}: {e}\")\n            bad += 1\nprint(\"ok\" if not bad else f\"{bad} bad line(s)\")\nsys.exit(1 if bad else 0)\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "top-n-per-group-sql",
   "name": "Top N per group (SQL)",
   "category": "Data",
   "description": "Window-function query: best 3 items in each category.",
   "url": "https://www.sqlite.org/windowfunctions.html",
   "lang": "sql",
   "run": "Run in SQLite 3.25+, PostgreSQL or MySQL 8+.",
   "code": "-- top 3 products by sales in each category\nSELECT category, product, sales\nFROM (\n  SELECT category, product, sales,\n         ROW_NUMBER() OVER (PARTITION BY category ORDER BY sales DESC) AS rn\n  FROM product_sales\n) ranked\nWHERE rn <= 3\nORDER BY category, sales DESC;\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "normalize-dates-to-iso-8601-with-time-zone",
   "name": "Normalize dates to ISO 8601 with time zone",
   "category": "Data",
   "description": "Parses common date formats and prints ISO timestamps in a chosen zone.",
   "url": "https://docs.python.org/3/library/zoneinfo.html",
   "lang": "python",
   "run": "python3 iso_dates.py America/Los_Angeles '11/19/2026 23:48'",
   "code": "#!/usr/bin/env python3\n\"\"\"iso_dates.py <tz> <date> [date...]\"\"\"\nimport sys\nfrom datetime import datetime\nfrom zoneinfo import ZoneInfo\n\nFORMATS = [\"%Y-%m-%d %H:%M\", \"%Y-%m-%d\", \"%m/%d/%Y %H:%M\", \"%m/%d/%Y\", \"%d %b %Y\"]\ntz = ZoneInfo(sys.argv[1])\nfor raw in sys.argv[2:]:\n    for fmt in FORMATS:\n        try:\n            print(datetime.strptime(raw, fmt).replace(tzinfo=tz).isoformat())\n            break\n        except ValueError:\n            continue\n    else:\n        print(f\"unparsed: {raw}\", file=sys.stderr)\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "broken-link-checker-for-one-page",
   "name": "Broken link checker for one page",
   "category": "Web",
   "description": "Finds links on a page and reports any that fail (stdlib only).",
   "url": "https://docs.python.org/3/library/html.parser.html",
   "lang": "python",
   "run": "python3 linkcheck.py https://example.com",
   "code": "#!/usr/bin/env python3\n\"\"\"linkcheck.py <page-url> - HEAD each link, falls back to GET.\"\"\"\nimport sys\nimport urllib.request\nfrom html.parser import HTMLParser\nfrom urllib.parse import urljoin\n\nUA = {\"User-Agent\": \"linkcheck-example/1.0\"}\n\nclass Links(HTMLParser):\n    def __init__(self):\n        super().__init__()\n        self.found = set()\n    def handle_starttag(self, tag, attrs):\n        href = dict(attrs).get(\"href\")\n        if tag == \"a\" and href and href.startswith((\"http\", \"/\")):\n            self.found.add(href)\n\ndef status(url):\n    for method in (\"HEAD\", \"GET\"):\n        try:\n            req = urllib.request.Request(url, method=method, headers=UA)\n            with urllib.request.urlopen(req, timeout=10) as r:\n                return r.status\n        except Exception as e:\n            err = getattr(e, \"code\", str(e))\n    return err\n\npage = sys.argv[1]\nhtml = urllib.request.urlopen(urllib.request.Request(page, headers=UA), timeout=10).read().decode(\"utf-8\", \"replace\")\np = Links()\np.feed(html)\nfor href in sorted(p.found):\n    url = urljoin(page, href)\n    s = status(url)\n    if s != 200:\n        print(s, url)\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "sitemap-xml-from-a-folder-of-html",
   "name": "sitemap.xml from a folder of HTML",
   "category": "Web",
   "description": "Builds a sitemap for a static site folder.",
   "url": "https://www.sitemaps.org/protocol.html",
   "lang": "python",
   "run": "python3 sitemap.py ./site https://example.com > site/sitemap.xml",
   "code": "#!/usr/bin/env python3\n\"\"\"sitemap.py <site-dir> <base-url>\"\"\"\nimport pathlib\nimport sys\nfrom datetime import datetime, timezone\nfrom xml.sax.saxutils import escape\n\nroot, base = pathlib.Path(sys.argv[1]), sys.argv[2].rstrip(\"/\")\nprint('<?xml version=\"1.0\" encoding=\"UTF-8\"?>')\nprint('<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">')\nfor f in sorted(root.rglob(\"*.html\")):\n    rel = f.relative_to(root).as_posix()\n    rel = rel[:-10] if rel.endswith(\"index.html\") else rel\n    mod = datetime.fromtimestamp(f.stat().st_mtime, timezone.utc).date().isoformat()\n    print(f\"  <url><loc>{escape(base + '/' + rel)}</loc><lastmod>{mod}</lastmod></url>\")\nprint(\"</urlset>\")\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "robots-txt-that-welcomes-ai-crawlers",
   "name": "robots.txt that welcomes AI crawlers",
   "category": "Web",
   "description": "Allows search and AI crawlers and points them to your sitemap and llms.txt.",
   "url": "https://developers.google.com/search/docs/crawling-indexing/robots/intro",
   "lang": "text",
   "run": "Save as /robots.txt at your site root.",
   "code": "# robots.txt\nUser-agent: *\nAllow: /\n\nUser-agent: GPTBot\nAllow: /\n\nUser-agent: ClaudeBot\nAllow: /\n\nUser-agent: PerplexityBot\nAllow: /\n\nUser-agent: Google-Extended\nAllow: /\n\nSitemap: https://example.com/sitemap.xml\n# AI-friendly summary: https://example.com/llms.txt\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "json-ld-itemlist-for-a-list-page",
   "name": "JSON-LD ItemList for a list page",
   "category": "Web",
   "description": "Structured data so search engines understand your list.",
   "url": "https://schema.org/ItemList",
   "lang": "html",
   "run": "Paste inside <head> and fill in your items.",
   "code": "<script type=\"application/ld+json\">\n{\n  \"@context\": \"https://schema.org\",\n  \"@type\": \"ItemList\",\n  \"name\": \"Best AI tools\",\n  \"itemListElement\": [\n    {\"@type\": \"ListItem\", \"position\": 1, \"name\": \"Tool A\", \"url\": \"https://example.com/a\"},\n    {\"@type\": \"ListItem\", \"position\": 2, \"name\": \"Tool B\", \"url\": \"https://example.com/b\"}\n  ]\n}\n</script>\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "check-a-site-s-security-headers",
   "name": "Check a site's security headers",
   "category": "Web",
   "description": "Shows which common security headers a URL sends.",
   "url": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers",
   "lang": "bash",
   "run": "./headers.sh https://example.com",
   "code": "#!/usr/bin/env bash\n# headers.sh <url>\nset -euo pipefail\nurl=\"${1:?url}\"\nhdrs=\"$(curl -sSI -L \"$url\" | tr -d '\\r')\"\nfor h in strict-transport-security content-security-policy x-content-type-options referrer-policy permissions-policy; do\n  if grep -qi \"^$h:\" <<<\"$hdrs\"; then echo \"OK      $h\"; else echo \"MISSING $h\"; fi\ndone\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "minimal-python-dockerfile",
   "name": "Minimal Python Dockerfile",
   "category": "DevOps",
   "description": "Small, non-root image for a Python app.",
   "url": "https://docs.docker.com/reference/dockerfile/",
   "lang": "dockerfile",
   "run": "docker build -t myapp . && docker run --rm -p 8000:8000 myapp",
   "code": "FROM python:3.12-slim\nENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1\nWORKDIR /app\nCOPY requirements.txt .\nRUN pip install --no-cache-dir -r requirements.txt\nCOPY . .\nRUN useradd -m app\nUSER app\nEXPOSE 8000\nCMD [\"python\", \"-m\", \"http.server\", \"8000\"]\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "github-actions-python-tests-on-every-push",
   "name": "GitHub Actions: Python tests on every push",
   "category": "DevOps",
   "description": "CI that installs dependencies and runs pytest.",
   "url": "https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions",
   "lang": "yaml",
   "run": "Save as .github/workflows/ci.yml in your repo.",
   "code": "name: ci\non: [push, pull_request]\njobs:\n  test:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      - uses: actions/setup-python@v5\n        with:\n          python-version: \"3.12\"\n      - run: pip install -r requirements.txt pytest\n      - run: pytest -q\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "disk-space-alert",
   "name": "Disk space alert",
   "category": "DevOps",
   "description": "Warns when any mounted filesystem passes a usage threshold.",
   "url": "https://man7.org/linux/man-pages/man1/df.1.html",
   "lang": "bash",
   "run": "./disk-alert.sh 85",
   "code": "#!/usr/bin/env bash\n# disk-alert.sh [percent=90] - exit 1 if any filesystem is above the threshold\nset -euo pipefail\nlimit=\"${1:-90}\"; alert=0\nwhile read -r use mount; do\n  pct=\"${use%\\%}\"\n  if [ \"$pct\" -ge \"$limit\" ]; then echo \"WARN $mount at ${pct}%\"; alert=1; fi\ndone < <(df -P -x tmpfs -x devtmpfs | awk 'NR>1 {print $5, $6}')\nexit \"$alert\"\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "docker-cleanup-dry-run-first",
   "name": "Docker cleanup (dry-run first)",
   "category": "DevOps",
   "description": "Shows what Docker would reclaim, then prunes only with --apply.",
   "url": "https://docs.docker.com/reference/cli/docker/system/prune/",
   "lang": "bash",
   "run": "./docker-clean.sh   # then ./docker-clean.sh --apply",
   "code": "#!/usr/bin/env bash\n# docker-clean.sh [--apply]\nset -euo pipefail\ndocker system df\nif [ \"${1:-}\" = \"--apply\" ]; then\n  docker container prune -f\n  docker image prune -f\n  docker builder prune -f\n  docker system df\nelse\n  echo \"dry-run: re-run with --apply to prune stopped containers, dangling images and build cache\"\nfi\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "tls-certificate-expiry-check",
   "name": "TLS certificate expiry check",
   "category": "DevOps",
   "description": "Prints when a site's certificate expires and days left.",
   "url": "https://docs.openssl.org/master/man1/openssl-s_client/",
   "lang": "bash",
   "run": "./cert-days.sh example.com",
   "code": "#!/usr/bin/env bash\n# cert-days.sh <host> [port=443]\nset -euo pipefail\nhost=\"${1:?host}\"; port=\"${2:-443}\"\nend=\"$(echo | openssl s_client -servername \"$host\" -connect \"$host:$port\" 2>/dev/null \\\n      | openssl x509 -noout -enddate | cut -d= -f2)\"\ndays=$(( ( $(date -d \"$end\" +%s) - $(date +%s) ) / 86400 ))\necho \"$host expires $end ($days days)\"\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "minimal-tool-calling-agent-loop",
   "name": "Minimal tool-calling agent loop",
   "category": "Prompts for agents",
   "description": "A tiny agent loop for any OpenAI-compatible chat API with one safe tool. Stdlib only.",
   "url": "https://developers.openai.com/api/docs/guides/function-calling",
   "lang": "python",
   "run": "API_BASE=https://api.openai.com/v1 API_KEY=... MODEL=<model> python3 agent_loop.py 'What time is it in Tokyo?'",
   "code": "#!/usr/bin/env python3\n\"\"\"agent_loop.py <question> - env: API_BASE, API_KEY, MODEL. Key is read from env, never printed.\"\"\"\nimport json\nimport os\nimport sys\nimport urllib.request\nfrom datetime import datetime\nfrom zoneinfo import ZoneInfo\n\nTOOLS = [{\"type\": \"function\", \"function\": {\n    \"name\": \"now_in\", \"description\": \"Current time in an IANA time zone\",\n    \"parameters\": {\"type\": \"object\", \"properties\": {\"tz\": {\"type\": \"string\"}}, \"required\": [\"tz\"]}}}]\n\ndef now_in(tz):\n    return datetime.now(ZoneInfo(tz)).isoformat(timespec=\"minutes\")\n\ndef chat(messages):\n    body = json.dumps({\"model\": os.environ[\"MODEL\"], \"messages\": messages, \"tools\": TOOLS}).encode()\n    req = urllib.request.Request(os.environ[\"API_BASE\"].rstrip(\"/\") + \"/chat/completions\", data=body,\n                                 headers={\"Authorization\": \"Bearer \" + os.environ[\"API_KEY\"],\n                                          \"Content-Type\": \"application/json\"})\n    with urllib.request.urlopen(req, timeout=60) as r:\n        return json.load(r)[\"choices\"][0][\"message\"]\n\nmessages = [{\"role\": \"user\", \"content\": sys.argv[1]}]\nfor _ in range(5):  # hard cap on loop turns\n    msg = chat(messages)\n    messages.append(msg)\n    calls = msg.get(\"tool_calls\") or []\n    if not calls:\n        print(msg.get(\"content\"))\n        break\n    for c in calls:\n        args = json.loads(c[\"function\"][\"arguments\"])\n        result = now_in(**args) if c[\"function\"][\"name\"] == \"now_in\" else \"unknown tool\"\n        messages.append({\"role\": \"tool\", \"tool_call_id\": c[\"id\"], \"content\": result})\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "agent-brief-template",
   "name": "Agent brief template",
   "category": "Prompts for agents",
   "description": "A bounded task brief that keeps agents on track.",
   "url": "https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/overview",
   "lang": "text",
   "run": "Paste into any agent and fill in the brackets.",
   "code": "GOAL: <one sentence>\nCONTEXT: <files, links, what already exists>\nDO:\n  1. <step>\n  2. <step>\nDON'T: delete anything, send messages, spend money, or touch <x> without asking.\nDONE WHEN: <a check anyone can run>\nREPORT: what changed (paths), what you verified and how, what's left or blocked.\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "structured-extraction-prompt",
   "name": "Structured extraction prompt",
   "category": "Prompts for agents",
   "description": "Gets clean JSON out of messy text, with nulls instead of guesses.",
   "url": "https://developers.openai.com/api/docs/guides/structured-outputs",
   "lang": "text",
   "run": "Paste with your text; parse the reply as JSON.",
   "code": "Extract the fields below from the text. Rules:\n- Output ONLY a JSON object, no prose.\n- Use null when the text does not state a value. Never guess.\n- Dates as YYYY-MM-DD.\nFields: {\"name\": string, \"company\": string, \"email\": string, \"date\": string, \"amount\": number}\n\nTEXT:\n<<<\n<paste text here>\n>>>\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "code-review-prompt-with-severities",
   "name": "Code-review prompt with severities",
   "category": "Prompts for agents",
   "description": "Consistent, skimmable review output.",
   "url": "https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/overview",
   "lang": "text",
   "run": "Paste with a diff.",
   "code": "Review the diff below as a senior engineer.\nFor each issue output one line: [HIGH|MED|LOW] file:line - problem - suggested fix.\nCheck: correctness, security (injection, secrets, auth), error handling, tests, naming.\nEnd with: VERDICT: approve | request changes, and one sentence why.\n\nDIFF:\n<paste diff>\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  },
  {
   "id": "verify-before-done-prompt",
   "name": "Verify-before-done prompt",
   "category": "Prompts for agents",
   "description": "Makes an agent prove its work before claiming success.",
   "url": "https://aistudio.google.com/docs/prompting-strategies",
   "lang": "text",
   "run": "Append to the end of any agent task.",
   "code": "Before you report done:\n1. Restate the goal in one line.\n2. List every requirement and, for each, the evidence it is met (command output, file path, URL + status).\n3. List anything you could not verify and why.\n4. If any requirement is unmet, say \"NOT DONE\" first.\n",
   "first_seen": "2026-11-19T23:58:13-08:00",
   "last_verified": "2026-11-20T00:03:30-08:00",
   "verified_by": "verify.py",
   "status": "verified"
  }
 ]
}
