Skip to content

Instantly share code, notes, and snippets.

View brandonhimpfen's full-sized avatar
:octocat:

Brandon Himpfen brandonhimpfen

:octocat:
View GitHub Profile
@brandonhimpfen
brandonhimpfen / node-read-large-file-line-by-line.js
Created February 25, 2026 18:08
Read a large file line-by-line in Node.js using streams + readline (memory efficient, backpressure-friendly).
#!/usr/bin/env node
/**
* Read a large file line-by-line (streams) in Node.js.
*
* Usage:
* node node-read-large-file-line-by-line.js ./bigfile.txt
*
* Notes:
* - Uses streams to avoid loading the entire file into memory.
* - readline provides a clean async iterator interface.
@brandonhimpfen
brandonhimpfen / python-sqlite-migrations-no-deps.py
Created February 22, 2026 20:07
Dependency-free SQLite migrations for Python: migrations table + apply migrations in order with transaction safety.
#!/usr/bin/env python3
"""
Basic SQLite migrations runner (no dependencies).
Pattern:
- Keep a list of migrations (id, name, sql)
- Store applied migrations in a table: schema_migrations
- Apply missing migrations in order inside a transaction
Good for:
@brandonhimpfen
brandonhimpfen / python-sqlite-helper.py
Created February 22, 2026 20:05
Basic SQLite helper for Python: connect with sensible defaults, execute/query helpers, and dict-like rows (no deps).
#!/usr/bin/env python3
"""
Basic SQLite helper (no dependencies).
Features:
- Context-managed connection
- Row results as dict-like objects (sqlite3.Row)
- Helpers for execute / executemany / fetchone / fetchall
- Optional pragmas for better defaults
@brandonhimpfen
brandonhimpfen / bash-retry-with-jitter.sh
Created February 15, 2026 21:05
Bash retry helper with exponential backoff + random jitter (useful for distributed systems and flaky network calls).
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Bash retry helper with exponential backoff + jitter
# -----------------------------------------------------------------------------
# Why jitter?
# - If many clients retry at the same fixed interval, they can synchronize and
# cause thundering herds. Jitter spreads retries out randomly.
#
# Usage:
# retry_jitter <attempts> <base_delay_seconds> <max_delay_seconds> <command...>
@brandonhimpfen
brandonhimpfen / bash-retry.sh
Created February 15, 2026 21:03
Bash retry helper to retry a command N times with delay and optional exponential backoff (strict-mode friendly).
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Bash retry helper
# -----------------------------------------------------------------------------
# Usage:
# retry <attempts> <delay_seconds> <command...>
#
# Example:
# retry 5 2 curl -f https://example.com
#
@brandonhimpfen
brandonhimpfen / html-responsive-images-srcset-sizes.html
Created February 8, 2026 23:00
Responsive image patterns using srcset + sizes (with WebP/AVIF via <picture>), plus practical examples for width- and density-based images.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Responsive Images: srcset + sizes</title>
<style>
/* Demo-only styling */
.container { max-width: 900px; margin: 2rem auto; padding: 0 1rem; }
img { max-width: 100%; height: auto; display: block; border-radius: 12px; }
@brandonhimpfen
brandonhimpfen / html-accessible-modal-minimal.html
Created February 8, 2026 22:59
Minimal accessible HTML modal markup (ARIA + focus target) with a tiny JS controller (open/close + Escape + backdrop click).
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Minimal Accessible Modal</title>
<style>
/* Minimal styling just to make the demo usable */
.modal-backdrop[hidden] { display: none; }
.modal-backdrop {
@brandonhimpfen
brandonhimpfen / go-http-post-json-context.go
Created February 1, 2026 21:09
Go POST JSON with context + timeouts, decode JSON response, and safe body limits (idiomatic net/http).
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"log"
"net"
@brandonhimpfen
brandonhimpfen / go-http-client-timeout-context.go
Created February 1, 2026 21:08
Go HTTP client example with context cancellation + sensible timeouts, returning response body safely (idiomatic net/http).
package main
import (
"context"
"fmt"
"io"
"log"
"net"
"net/http"
"time"
@brandonhimpfen
brandonhimpfen / bash-extract-archive.sh
Created January 24, 2026 19:56
Bash extract() helper to extract most archive formats (.zip, .tar.gz, .7z, .rar, etc.) with safe checks and readable errors.
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Extract any archive (zip, tar.gz, tgz, tar.bz2, tar.xz, 7z, rar, etc.)
# -----------------------------------------------------------------------------
# Usage:
# ./bash-extract-archive.sh file.tar.gz
# source this file and call: extract "file.zip"
#
# Requirements (depending on format):
# - tar, unzip, gzip/bzip2/xz, 7z, unrar, cabextract