Redowan's Reflections — Page 12
Recent writing
Longer articles, short notes, and things I'll probably need to look up again.
Browse the archiveUse Python's urlsplit instead of urlparse for faster URL parsing by skipping the rarely-needed params component in URL decomposition.
Emulate Python's random.choice in SQLite using JSON arrays and the random() function. Populate tables with realistic test data efficiently.
Master Python's ExitStack for managing multiple context managers, conditional callbacks, request rollbacks, and avoiding nested with statements.
Combine session and function-scoped pytest fixtures to avoid expensive test setup while maintaining test isolation and preventing state coupling.
Master Python mocking: patch objects at their import location, not where they're defined, to avoid common unittest.mock pitfalls.
Assert specific mock call arguments while ignoring others using unittest.mock.ANY for flexible test assertions without brittle checks.
Fix divergent branch errors with git pull --rebase. Learn when to rebase local commits on top of remote changes for cleaner Git history.
Use Python assert statements to apply runtime constraints more succinctly than raising ValueError. Learn the trade-offs and best practices.
Automatically merge Dependabot pull requests using GitHub Actions. Configure branch protection and status checks for safe automated dependency updates.
Process large CSV files without OOM errors by streaming content line-by-line with HTTPX and concurrent.futures for parallel processing.
Speed up Django bulk operations with ProcessPoolExecutor while preserving signals and hooks that bulk_create/bulk_update bypass.
Download and process S3 CSV files in memory using boto3 and tempfile.NamedTemporaryFile without cluttering disk with temporary files.
View git commit history for a single file with git log --follow. Learn to track multiple files with xargs and concatenate their commit logs.
Use operator.itemgetter for faster sorting and element access with graceful KeyError handling via methodcaller for safer operations.
Master TypeScript's never type and Python's NoReturn for exhaustiveness checking. Flatten nested conditionals with guard clauses for cleaner code.