Migrating to Kamal

When I created SnippetStash I did some research on the easiest way to deploy a new Rails app. The default answer used to be Heroku but times have changed. Based on my research, Heroku had become expensive and there were a few viable alternatives. Many suggested Fly.io or Render with various tradeoffs.

I decided that Render would be the easiest to set up, and automatic deploys were ideal for a hobby project. This was mostly true but I ran into some issues.

Sleeping Policeman

The Problem

There are a plethora of articles and discussion on the pernicious effects of news feeds. They are so pervasive now that it’s easy to forget they’re even there. But time and time again they quietly suck you into a tightly controlled feedback loop design to “maximize user engagement.”

Limiting their effects can be difficult. Designed and perfected through millions of man hours over the last decade or so, these infinitely scrolling, attention draining nightmares are so effective at pulling you in that you often waste time - sometimes hours - before waking up from your daze of consumption.

SnippetStash: Extract highlights from photos and view them in context

I’m not sure exactly where I picked it up but I have a habit of highlighting books that I read. It’s easy to forget some key insights after reading a book and highlighting provides a way to mark something that I want to revisit. The issue is I don’t revist. At best I might remember some connection a few months later and flip through the entire book looking for the section I was thinking of.

After repeating this process several times it was clear that I was wasting my time. This shouldn’t be so difficult. I realized that if I could digitize these highlights I could search, organize, and easily reference them whenever I wanted - No more flipping pages! I figured I should be able to build an app where I submit a photo and the text is OCR’d and any highlighted texts are extracted (that is at least once I learned the term OCR).

Irb's Easter Egg

If you’ve used Ruby for more than 5 minutes, you’ve probably come across the IRB gem or it’s popular counterpart Pry. Both of these provide a REPL to explore and execute Ruby code.

IRB is old - nearly as old as the language itself in fact. For a mature library like this, I would expect a slow development cycle mostly comprised of incremental improvements, bug fixes, and performance enhancements. Imagine my surprise then when I stumbled on the following Easter egg that was added in 2020:

Index with

Rail’s Enumerable module provides a number of time saving methods for dealing with array-like structures. The one that’s provided the most utility (for me at least) is index_with. I often find myself with an array of items I’d like to use as keys for a new nested hash. With index_with this is as simple as:

months = ['Jan', 'Feb', 'Mar']
months.index_with({})
=> { 'Jan' => {}, 'Feb' => {}, 'Mar' => {} }

This pattern has generally served me quite well, but there is a bug hidden in plain sight.