MacOS Ventura firewall repeatedly asks to accept incoming connections when reinstalling a Ruby version with rbenv

On my Intel iMac on macOS Ventura 13.4 I ran into this annoying issue when reinstalling the same version of Ruby (3.2.2 for example) with rbenv. When running rails test:system the firewall’s “Accept incoming connections” dialog would pop every time, no matter whether you Denied or Allowed the connection to go through previously, making testing quite painful.

I couldn’t find a working solution through googling, but ChatGPT was able to help. It’s as simple as:

sudo codesign --force --sign - $HOME/.rbenv/versions/3.2.2/bin/ruby

Simply find the ruby bin version you’re having problems with inside your .rbenv folder and instruct macOS to re-sign it. The expected output should be something like:

/Users/klevo/.rbenv/versions/3.2.2/bin/ruby: replacing existing signature

After that, you’ll need to confirm or deny the “Accept incoming connections” Firewall dialog when running something like system test suite, but afterwards the Firewall should remember your choice.

Lastly, this only seems to affect Intel Macs. At least for me, no such issue occurred when reinstalling ruby with rbenv on an ARM MacBook.

Thanks AI 🙂

navigator.clipboard does not work under plain HTTP in latest Safari (on .test domains)

I just noticed that on the latest MacOS Ventura 13.3.1 with Safari 16.4, the navigator.clipboard API is not accessible under plain HTTP .test domains, used with puma-dev for example. It returns “property is undefined” type of error.

The solution is to switch to HTTPS. With puma-dev this is simple, as it comes out of box with support for secure connections.

I haven’t had a chance to test it with plain old localhost yet, but I figured to post this, in case it trips you too.

Solution: Some Mac OS Mail Favourites are grayed out and cannot be deleted

I encountered the issue of a grayed out folder that can’t be deleted, in MacOS Mail app today. The discussion on Apple’s forums does not provide any actionable answers. After a while I figured out a solution myself and it’s very simple:

  1. Create a new mailbox (Mailbox -> New Mailbox…). For Location, choose “On My Mac” and name it the same as the grayed out folder in Favourites that you’re struggling with.
  2. Once you add this new mailbox, the one in Favourites should become accessible again. You can now right click on it and hit “Remove from Favourites”.
  3. You can now also delete the empty local (On My Mac) mailbox folder that you created in step 1.

Hope that helps.

How I run puma-dev alongside Rails’ bin/dev

The bin/dev script Ruby on Rails ships with, if you for example init the app with --css=tailwind or --css=bootstrap is great. It comes with auto-generated Procfile that will launch the web server and the Tailwind CSS (or other) preprocessors. In addition bin/dev will install the foreman gem if it does not exist on your system.

At some point however, you’ll want to run multiple Rails applications on your developer machine. Doing that with localhost:3000 will get annoying at some point (cookie sharing, changing ports, everyone in the team handling it differently, no HTTPS to test with…).

puma-dev has been around for a long time to solve this. However while it takes care of running the web server part for you (in the background), you still want to see the logs, run your CSS (or JS) preprocessor or compiler, job workers, etc. I figured out it’s simply about adjusting the Procfile and bin/dev slightly and one can use the familiar approach in conjunction with all the puma-dev features.

This is what I do:

My looks like this:

web: tail -f log/development.log
css: bin/rails tailwindcss:watch

The change is in the web: stanza. Instead of launching puma server, we simply tail the logs, as puma will be run by puma-dev in the background for you, as soon as you visit your local .test domain.

My bin/dev looks like this:

#!/usr/bin/env bash

if ! command -v foreman &> /dev/null
  echo "Installing foreman..."
  gem install foreman

if ! command -v puma-dev &> /dev/null
  echo "Installing puma-dev..."
  brew install puma/puma/puma-dev
  echo ""
  echo "To finish puma-dev setup run:"
  echo "sudo puma-dev -setup"
  echo "puma-dev -install"
  echo "puma-dev link -n myapp ."
  echo ""

foreman start -f

I’ve added a section that installs puma-dev (if your team is using Homebrew) and prints out instructions on how to complete the setup.

For your use case, simple replace “myapp” above with the name of your app.

This feels like sticking to the Rails way and is easily extensible if you also want to launch other services in development, like job workers, by simply adding a stanza in the Neat.

Scaffolding in Rails 7 is amazing

I’m continuously being impressed by the productivity and ease of use enhancements Rails keeps making after all these years it has been around.

Today I discovered that scaffolds generated in brand new --css=tailwind enabled Rails 7 codebase, is generating basic, beautiful Tailwind markup out of the box.

rails g scaffold_controller User username:string


Index of a freshly generated model.
Edit view. Notice the Tailwind markup.

Further I have this in my config/application.rb to prevent generating files that I don’t use for every single resource until they are needed:

config.generators do |g|
  g.assets false
  g.helper false
  g.jbuilder false

That’s a damn good job Rails community. ❤️

Easily switch or experiment with different databases in Rails

I just learned about rake db:system:change task that Rails provides, to speed up switching between different database engines. If you’re experimenting with something, or benchmarking things, this is super useful.

I had a simple PostgreSQL app and running rake db:system:change --to=sqlite3 and afterwards rake db:setup got me going with my task in seconds.

Small detail I noticed, rake -T which should list all available tasks, does not show anything about db:system for some reason.

Starting new Rails applications

It’s been a while since I reviewed the documentation for rails new console command. There are a few useful features that I didn’t know about:

Most of the times, for database engine, PostgreSQL is my choice. This is easily accomplished with the -d switch, but even more convenient is adding this as a preset to your environment, using the .railsrc dotfile. Configuring such on your system will allow you to just stick to rails new appname without having to add switches.

The second useful thing I didn’t know exists is the Rails Application Templates which makes it faster to start new Rails applications with the same set of gems and configuration that you might be reusing across your apps.

Speeding up office work with Ruby and IRB

I was just paying taxes 😅. One of the steps involved was copying and pasting a few long reference numbers from a PDF into my banking app. The thing is, when copied, the reference number would contain extra spaces, after each character, making it invalid where I needed to paste it.

Now there are myriad of different solutions for this I’m sure, but as a programmer, let’s take a look at how to speedily create a makeshift tool in Ruby to do this.

space_eater = ->(text) { text.gsub(' ', '') }

We launched into the interactive shell, and defined a lambda we can call on strings we want to sanitize. Like so:'2 3 9 2 9 9 A 8 2 8 0 0 0 1')
=> "239299A8280001"

And we’re done. ❤️ Ruby.

Who is this feature for?

In software development, when thinking about and designing new features, or trying to solve existing issues, it’s important to, early, ask the question: Who is this feature for?

That applies to writing tools intended for your developer colleagues, web application features for customers or anything in between.

I found, that the result only tends to be good, if the feature or solution was actually designed for a specific person, doing specific task and this solution allows them to improve the way they do this task considerably.

For example when deciding for a Content Management System for a website, developers often jump to first evaluating various offerings out there, based on features, APIs and supported languages. Instead of first identifying the person that is going to be working with such a system and establishing what their workflow is going to be. What’s important for them, what’s not important and only based on that then look for a solution, or build a custom one.

Tools that are build for a very specific need and for a real person that can tell you, this helps, or not; tend to end up being simpler, more pleasurable to use, last longer and require less maintenance and generally tend to achieve the goal set out for them at the beginning.