About 149 results
https://rednafi.com/python/operators-itemgetter/ · 16 Jun 2022
Use operator.itemgetter for faster sorting and element access with graceful KeyError handling via methodcaller for safer operations.
https://rednafi.com/typescript/guard-clauses-and-never-type/ · 22 May 2022
Master TypeScript's never type and Python's NoReturn for exhaustiveness checking. Flatten nested conditionals with guard clauses for cleaner code.
https://rednafi.com/python/return-json-error-payload-in-drf/ · 13 Apr 2022
Fix Django REST Framework to return JSON error responses for 403, 404, 500 errors using middleware instead of default HTML pages.
https://rednafi.com/python/decouple-with-generators/ · 3 Apr 2022
Learn how Python generators decouple data production from consumption, enabling cleaner code for streaming, polling, and pipeline patterns.
https://rednafi.com/python/preallocated-list/ · 27 Mar 2022
Understand CPython list memory allocation: how lists store pointer references, grow dynamically, and when pre-allocation with [None]*n helps.
https://rednafi.com/python/disallow-large-file-download/ · 23 Mar 2022
Prevent excessive file downloads in Python by streaming with HTTPX and limiting file size with chunk-based validation and memory-safe processing.
https://rednafi.com/python/declaratively-transform-dataclass-fields/ · 20 Mar 2022
Leverage Python's __post_init__ hook to declaratively transform dataclass fields. Automatically serialize data with clean, maintainable code.
https://rednafi.com/python/mocking-datetime-objects/ · 16 Mar 2022
Mock chained datetime methods in Python tests using unittest.mock to handle immutable datetime objects without external dependencies.
https://rednafi.com/python/caching-connection-objects/ · 16 Mar 2022
Learn efficient patterns for caching database connection objects in Python without import-time side effects or lru_cache complexity.
https://rednafi.com/python/how-not-to-run-a-script/ · 16 Mar 2022
Fix Python ModuleNotFoundError by using python -m instead of direct script execution to ensure correct sys.path handling for imports.