Quick notes on things I discover while coding. Inspired by Hashrocket’s TIL.

24 quick tips


Context Managers Clean Up API Clients Automatically

December 2025

Was debugging why some API connections weren’t closing properly in llmswap. Realized I was forgetting to cleanup client resources in error cases.

Read more →

Tags: #python #best-practices #api


MongoDB Crashed Due to Full /var/log Partition

December 2025

Our project UI stopped functioning. Investigation showed MongoDB was down on the RHEL VM. Root cause: /var/log partition was 100% full.

Check di…

Read more →

Tags: #mongodb #linux #troubleshooting #rhel


pip install -e . for Local Package Development

December 2025

While developing llmswap, I was constantly running pip uninstall llmswap then pip install . after every code change to test. Incredibly annoying.

Read more →

Tags: #python #development #pip


Switching LLM Providers Without Rewriting Code

December 2025

Kept switching between OpenAI and Anthropic APIs for different projects. Got annoying having to change imports and API calls each time.

Instead …

Read more →

Tags: #python #llm #api


truncate -s 0 vs rm for Active Log Files

December 2025

MongoDB crashed. /var/log was 100% full. Deleted the huge log file with rm, but disk space didn’t free up. MongoDB was still holding the file open….

Read more →

Tags: #linux #logging #disk-space


December 2025

Needed search functionality but wasn’t sure when to use text indexes vs regular indexes. They’re for different use cases.

Regular index - For exac…

Read more →

Tags: #mongodb #search #indexing


time.time() vs time.monotonic() for Duration Tracking

December 2025

Was tracking API response times in llmswap and noticed some latencies were showing as negative numbers. Turned out my server’s NTP had adjusted the…

Read more →

Tags: #python #performance #timing


MongoDB explain() Shows Why Your Query is Slow

November 2025

Query was taking 12 seconds on our VM search. I knew indexes existed, but why wasn’t MongoDB using them?

explain(“executionStats”) shows exactly w…

Read more →

Tags: #mongodb #performance #database


MongoDB Text Search is Pretty Good Actually

November 2025

Elasticsearch is the standard for search, but for our search feature, we needed to find options and libraries within our tech stack itself. Since w…

Read more →

Tags: #mongodb #search #database


MongoDB Compound Indexes vs Multiple Single Indexes

November 2025

Was building a query filter UI where users search VMs by status AND hostname together. Wasn’t sure if I needed one compound index or two separate i…

Read more →

Tags: #mongodb #database #indexing


sys.getsizeof() to Track Memory Usage in Python

November 2025

Needed to enforce a memory limit for llmswap’s cache. Set it to 100MB, but how do I know how much memory each cached response actually uses?

sys.g…

Read more →

Tags: #python #memory #performance


df -h vs du -sh: When to Use Which

November 2025

Was debugging disk space issues on a server. /var/log showed full in df, but du showed different numbers. Confused me until I understood the differ…

Read more →

Tags: #linux #disk-space #troubleshooting


hashlib.sha256() for Consistent Cache Keys

November 2025

Building llmswap’s cache, I needed a way to generate consistent keys from prompts. Can’t use the prompt itself as the dictionary key - some prompts…

Read more →

Tags: #python #caching #hashing


json.dumps(sort_keys=True) for Reliable Hashing

October 2025

Hit a weird caching bug in llmswap. Same query with same context was creating different cache keys randomly. Caching wasn’t working.

Problem: JSON…

Read more →

Tags: #python #json #hashing


threading.Lock() Saved Me From Race Conditions

October 2025

Building the caching system for llmswap, I hit a nasty bug. When multiple requests came in simultaneously, cache stats were getting corrupted. Turn…

Read more →

Tags: #python #threading #concurrency


xfs_growfs for Online Filesystem Expansion (No Downtime)

October 2025

After the MongoDB disk-full incident, I decided to permanently expand /var/log instead of just truncating logs.

The server used XFS filesystem on …

Read more →

Tags: #linux #xfs #lvm #storage


GraphQL Resolvers Don’t Have to be Complex

October 2025

Used to think GraphQL resolvers needed to be these complex, optimized functions. Turns out simple is often better.

// This works fine const resolv…

Read more →

Tags: #graphql #javascript #api


argparse Subcommands Make CLIs Feel Professional

October 2025

My first version of llmswap CLI was a mess of flags: llmswap –ask “question” or llmswap –chat or llmswap –review file.py. Felt clunky.

Wanted i…

Read more →

Tags: #python #cli #argparse


MongoDB $or Queries Need Indexes on EACH Field

October 2025

Our search was letting users find VMs by UUID, name, or IP address. Used $or for this. Had an index on uuid, but query was still slow.

Assumed one…

Read more →

Tags: #mongodb #indexing #performance


Environment Variable Priority Pattern I Use Everywhere

September 2025

Needed a clean way to configure API keys in llmswap. Users should be able to pass them via CLI argument, environment variable, or config file. But …

Read more →

Tags: #python #configuration #best-practices


Why our UI search was taking forever

September 2025

Users kept complaining about search performance. With customers managing 1000+ VMs, they were constantly searching:

VM by UUID: “550e8400-e29b-…

Read more →

Tags: #mongodb #search #performance #infrastructure


git log –oneline –graph for Visual Branch History

September 2025

Was trying to understand the merge history of llmswap before rebasing. Regular git log was just a wall of text - impossible to see the branch struc…

Read more →

Tags: #git #command-line #productivity


ABC Module Makes Abstract Classes Actually Work

September 2025

Was building llmswap and needed to support multiple AI providers (OpenAI, Anthropic, Gemini, etc.). Started with just class BaseProvider: but subcl…

Read more →

Tags: #python #design-patterns #oop


Extending XFS Filesystem on LVM When Logs Fill Up

August 2025

MongoDB crashed because /var/log hit 100% capacity. Instead of just truncating logs (temporary fix), I extended the filesystem permanently.

Chec…

Read more →

Tags: #linux #xfs #lvm #rhel #storage


More TIL posts coming as I learn new things…