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 / 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
@brandonhimpfen
brandonhimpfen / docker-debug-container-one-liners.sh
Created January 24, 2026 19:55
Tiny Docker “debug container” one-liners for troubleshooting networks, DNS, HTTP, and containers (docker run -it --rm ...).
# Docker Debug Container One-Liners
# Use these to quickly troubleshoot networking, DNS, HTTP, TLS, ports, etc.
# without installing tools on your host machine.
# ---------------------------------------------------------------------------
# 1) Fast interactive shell in a tiny container
# ---------------------------------------------------------------------------
docker run -it --rm alpine:latest sh
# If you want common networking tools (curl, dig, ping, etc.)
@brandonhimpfen
brandonhimpfen / go-error-wrapping-pattern.go
Created January 17, 2026 00:25
Go custom error wrapping pattern using %w, errors.Is/As, and optional typed sentinel errors (clean, idiomatic, and debuggable).
package main
import (
"errors"
"fmt"
)
// Sentinel errors (useful for high-level classification)
var (
ErrNotFound = errors.New("not found")
@brandonhimpfen
brandonhimpfen / python-progress-bar-no-deps.py
Created January 13, 2026 22:33
A tiny, dependency-free Python progress bar for loops and iterables (supports known totals, unknown totals, and ETA).
#!/usr/bin/env python3
"""
Dependency-free progress bar for Python.
Features:
- Works with a known total OR unknown total.
- Prints ETA when total is known.
- Throttles updates to avoid spamming stdout.
- Safe for long-running loops; finalizes cleanly.
@brandonhimpfen
brandonhimpfen / sql-pagination-patterns.md
Created January 9, 2026 15:46
SQL pagination patterns: LIMIT/OFFSET vs keyset (seek) pagination, with copy-paste queries, indexing tips, and examples for Postgres/MySQL.

SQL Pagination Patterns

Use OFFSET for small datasets and random-access pages. Use keyset/seek for deep paging and stability.

-- SQL Pagination Patterns
-- LIMIT/OFFSET vs Keyset (Seek) Pagination
--
-- OFFSET pagination is simple but can get slow on deep pages and can produce
-- duplicates/missing rows if data changes between requests.
@brandonhimpfen
brandonhimpfen / go-read-file-line-by-line.go
Created January 6, 2026 19:37
Read a file line-by-line in Go using bufio.Scanner (with basic error handling and flags for long lines).
package main
import (
"bufio"
"fmt"
"log"
"os"
)
// Read a file line-by-line using bufio.Scanner.
@brandonhimpfen
brandonhimpfen / js-debounce.js
Created January 2, 2026 08:58
A simple, dependency-free JavaScript debounce utility for limiting how often a function executes.
/**
* debounce(fn, wait)
*
* Delays invoking `fn` until after `wait` milliseconds have elapsed
* since the last time the debounced function was called.
*
* Common use cases:
* - Resize events
* - Scroll handlers
* - Input / search fields
@brandonhimpfen
brandonhimpfen / bash-strict-mode.sh
Created December 30, 2025 15:09
Bash strict mode starter template using set -Eeuo pipefail, with safe defaults, error handling, and argument parsing.
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Bash Strict Mode Starter Template
# -----------------------------------------------------------------------------
# -e : Exit immediately if a command exits with a non-zero status
# -u : Treat unset variables as an error
# -o pipefail : Fail a pipeline if any command fails
# -E : ERR traps are inherited by shell functions
# -----------------------------------------------------------------------------
@brandonhimpfen
brandonhimpfen / functions.php
Created May 28, 2014 18:34
Display the content of one page in another page.
function get_post_page_content( $atts ) {
extract( shortcode_atts( array(
'id' => null,
'title' => false,
), $atts ) );
$the_query = new WP_Query( 'page_id='.$id );
while ( $the_query->have_posts() ) {
$the_query->the_post();
@brandonhimpfen
brandonhimpfen / menu-panel.php
Created February 1, 2014 19:54
Display a WordPress menu as a Twitter Bootstrap list group panel. Make sure to change the panel title, text and on line 2 - change the "menu-id"
echo '<div class="panel panel-default"><div class="panel-heading">Title Goes Here</div><div class="panel-body"><p>Description or whatever you want goes here.</p></div><ul class="list-group nav">';
wp_nav_menu( array( 'container' => false, 'menu_class' => 'list-group-item', 'theme_location' => 'menu-id', 'after' => '', 'items_wrap' => '%3$s' ));
echo '</ul></div>';