Small Programming Tricks
The Power of Small Programming Tricks
A significant portion of an engineer's daily productivity isn't derived from massive architectural shifts, but from small nuggets of knowledge. These are high-leverage bits of information—like knowing a specific language feature, understanding that a TCP lag is likely due to Nagle's algorithm (and thus requires TCP_NO_DELAY), remembering the exact git command to fix a mistake, or mastering a sed trick for file editing.
While it's obvious that all knowledge is built from smaller parts, some "nuggets" are uniquely valuable because they provide immediate utility without requiring a massive amount of supporting mental infrastructure.
Example: You don't need to be a Python expert to run
python3 -m http.serverto instantly host a directory; the effort is minimal, but the convenience is high.
🛠️ The Technical Toolkit
Below is a collection of these high-leverage tricks across different domains.
Terminal & Shell Optimization
The evolution of command history can drastically change your workflow:
- Basic:
Ctrl + rfor searching history. - Better: Install
fzfto turnCtrl + rinto a fuzzy search. - Best: Use
atuinto replace your history with a searchable SQLite database. - Niche:
per-directory-historyallows you to toggle between global history and commands specific to your current folder.
Use standard grep Use rg (ripgrep) for significantly faster searching.
| Feature | Command/Tool | Purpose |
|---|---|---|
| Recursive Globs | **/*.md | Find all Markdown files recursively |
| Bash Globbing | shopt -s globstar | Enables ** patterns in Bash |
| Git Pickaxe | git log -S pattern | Find commits that added/removed a string |
| Git Move Search | git log -G pattern | Similar to -S, but includes line moves |
| Git Toggle | git checkout - | Switch back to the previous HEAD |
Database & Regex
- Query Tuning: Both MySQL and PostgreSQL offer
EXPLAIN ANALYZE. Unlike a standard explain, this actually executes the query to provide real-world performance metrics. - Regex Boundaries: Use
\b(the word boundary assertion) to precisely target the start or end of words.
JavaScript & Node.js
Modern JS has introduced several quality-of-life methods:
Array.flatMapObject.entriesPromise.withResolvers
In Node.js, you can maintain persistent connections to external resources by utilizing an https.Agent:
fetch(url, {method, agent})
When dealing with metrics, using logarithms helps visualize the distribution of values:
const bucket = Math.log10(val); increment("my_metric", { bucket });
Zsh Configuration
To unlock advanced autocompletion in Zsh (especially when using Homebrew), you can add this to your config:
if type brew /dev/null; then
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
fi
autoload -Uz compinit
compinit
🏢 Knowledge in the Workplace
In a corporate environment, these "nuggets" are often organizational rather than technical. They take the form of:
- "To debug DATA_SOURCE."
- "AREA; they are happy to help."
- "The documentation for OVER_HERE."
The "Trick a Day" Strategy
Inspired by the writing of Julia Evans, I previously implemented a system where I shared one technical or company-specific trick on Slack every day.
Why this works:
- It avoids overwhelming the team.
- Even if someone knows 90% of the tricks, the 10% they didn't know can save hours of work.
- It encourages a culture of continuous, small-scale learning.
If you are a senior engineer, consider adopting this practice. As Julia Evans suggests, small bits of knowledge are powerful!