lsof Demystified: Unveiling a Process's Open Files

2025-06-06

This code snippet uses the command `lsof -p $(echo $$)` to list all open files for the current zsh process. The output reveals details such as process ID, user, file descriptor type, device, size, and path, providing a clear picture of the process's interactions with the filesystem. This is invaluable for understanding process behavior and debugging file handle leaks.

Read more
Development file descriptors

Cookie-Based Authentication in Axum: From Extractors to Middleware

2025-06-05

This article explores two approaches to implementing cookie-based user authentication in the Rust Axum framework. Initially, the author demonstrates using a custom extractor, `CookieJwt`, to retrieve JWT tokens from requests, conditionally rendering a 'Profile' or 'Login' button based on JWT validity. However, this approach proves less clean and scalable for complex authentication scenarios. The article then refactors the solution using Axum middleware, providing a cleaner, more reusable, and flexible approach to handling authentication logic. This middleware efficiently validates JWTs, manages refresh tokens, and gracefully handles various request types, ultimately resulting in a more robust and adaptable user authentication system. The author details the middleware's implementation, highlighting its advantages over the extractor-based approach.

Read more
Development

Why You Should Ditch Query Builders and Embrace Raw SQL

2025-01-25

This article champions writing database queries directly in SQL instead of relying on query builders. Through several examples, the author demonstrates how SQL features (like `IS NULL`, `COALESCE`, `ARRAY_REMOVE`, `STRING_TO_ARRAY`) elegantly handle optional parameters, arrays, pagination, and batch updates, reducing complex Rust logic. This approach simplifies code, improves readability and testability, and enables easier database testing and debugging. The author argues that raw SQL is often cleaner and more efficient than complex builder patterns.

Read more
Development Database Queries