Elegant SQLite Multitenancy in Rails

2025-04-27

This article details the experience of building a multi-tenant application with Rails, where each tenant has its own isolated SQLite database. The author initially used traditional database connection management, leading to connection errors under high load. After much exploration, the author finally used the Rails 6+ `connected_to` method combined with a custom middleware to achieve safe and efficient tenant database switching, cleverly solving the problems of multithreading and connection pool management, and sharing tips for handling Rack streaming response bodies. This article is valuable for building high-performance, scalable multi-tenant applications.

Read more
Development Multitenancy

Tailwind CSS 4 and the FOMO Trap: A Developer's Cautionary Tale

2025-04-07

This article recounts the author's frustrating experience with Tailwind CSS 4, which relies on Bun.js and crashed on their older Mac Pro due to a lack of AVX2 instructions. Debugging this issue consumed several days, forcing the author to buy a new machine and abandon Tailwind CSS 4. The author reflects on the tech industry's 'fear of missing out' (FOMO) and the pitfalls of blindly chasing new technologies. The experience highlighted the importance of careful technology selection, prioritizing personal needs and project realities, rather than being swept along by trends.

Read more
Development

Elegant UI Undo Stack Algorithm: Avoiding Indexing Errors

2025-03-26

This article presents a clever implementation of a UI undo stack algorithm. Instead of the traditional index-based approach, it uses two stacks (undoStack and redoStack) to manage undo and redo operations, neatly avoiding common indexing errors and off-by-one issues. The code is concise and easy to understand. The author addresses the pass-by-reference problem in JavaScript using `structuredClone()`, ensuring idempotency. A complete code example is provided.

Read more

Supercharge SQLite with Ruby Functions

2025-01-27

This article demonstrates how to enhance SQLite's capabilities by integrating Ruby functions. The author creates User-Defined Functions (UDFs) to directly call Ruby code within SQL queries, enabling features like generating time-ordered UUIDs, performing regex matching, and calculating statistical measures (e.g., standard deviation and percentiles). The article also explores using the SQLITE_DIRECTONLY flag to prevent issues when accessing custom functions outside the application's process. Overall, this provides a powerful way to boost SQLite's flexibility and functionality, particularly useful for data exploration and analysis.

Read more
Development