Image of Lucian Ghinda writing for notes.ghinda.com
Short posts mostly about Ruby and Ruby on Rails. You can find me at : Linkedin, Mastodon, Twitter or for longer posts at allaboutcoding.ghinda.com
Subscribe via RSS here

Three Ruby Links #4

If I were to recommend three articles published last week to read, here is what I would recommend:

1️⃣  What’s New in Ruby on Rails 8 by Damilola Olatunji

Screenshot of a paragraph from the article What’s New in Ruby on Rails 8 by Damilola Olatunji
Excerpt from "What’s New in Ruby on Rails 8"

This article offers a concise summary of the key features coming to Rails 8. Damilola provides an excellent high-level overview, while also delivering detailed insights into each feature.

You might also want to check out the Hacker News discussion related to this article. It has a great vibe about Ruby on Rails 8.

2️⃣ How CDNs Work (Propshaft / Static Assets Pt. 2) by Jon Sully

Excerpt from "How Propshaft Works: A Rails Asset-Pipeline (Visual) Breakdown"
Excerpt from "How Propshaft Works: A Rails Asset-Pipeline (Visual) Breakdown"

In this article, Jon provides a visual and clear explanation of Propshaft's work when serving the assets files. This is a continuation of a previous article about How Propshaft Works: A Rails Asset-Pipeline (Visual) Breakdown, which is also a very good article with explanation and explanations of Ruby code samples.

3️⃣ B-trees and database indexes by Benjamin Dicken

Excerpt from "B-trees and database indexes"
Excerpt from "B-trees and database indexes"

While this article isn't about Ruby, it is an excellent and well-written resource for understanding B-trees and database indexes. It deep dives into details explaining how indexes work and includes animations that help you feel the concepts.


You can find a lot more articles to read in the full edition of Short Ruby Newsletter at https://newsletter.shortruby.com/p/edition-109

Short Ruby Newsletter - edition 109 published

Short Ruby Newsletter - edition 109 highlights

🚀 Launches

  • Andy Croll launched usingrails.com - a directory to gather all organizations that are using Ruby on Rails
  • Prabin Poudel launched Zero Config Rails - Generators - a single command to add any Ruby gem
  • Greg Molnar launched an MVP of a Gumroad alternative
  • Alexandre Ruban launched an ebook about Cookie-based authentication with Rails

📅 Events:

  • RubyConf is one month away, happening on 13-15 November and Error Schmidt is organising a private dinner with leaders from Ruby community
  • Tropical.rb announced tickets will go on sale on October 30th
  • Ruby Banitsa announced Ruby Banitsa Conf happening on 7th December
  • 18 Ruby and Ruby on Rails meetups are happening this week around the world

👉 All about Code and Ruby:

  • Ruby 3.4.0-preview2 was launched having Prism as the default parser
  • Xavier Noria announced release of Zeitwerk 2.7 and wrote a super nice explanation of namespacing in Ruby
  • You can find code samples about updating to Kamal 2, about the new ignoring counter cache columns in Rails, using Rails runner with heredocs, merging queries, Turbo mount code samples, debugging Devise and much more.

Remember to read the Thinking about Code section and Around Code, where there are engaging discussions about moving variables out of views, using kamal-proxy with more than one server, a big discussion about how Hotwire can simplify UI development and when to reach for React and many more insights from coding with Ruby and Ruby on Rails

🧰 Gems, Libraries, Tools and Updates

  • Kamil Nicieja announced the release of lammy - an LLM library for Ruby
  • Christoph Lipautz announced release of test-map, a Rubygem to identify associated test-files for any code-file
  • Janko Marohnić announced a new gem rodauth-openapi: Generate OpenAPI documentation for your Rodauth endpoints
  • Paweł Strzałkowski open sourced the repo for RubyEurope
  • Kristján Oddsson announced a new project koddsson/eslint-config-stimulus: A set of ESLint rules for authoring Stimulus controllers

As always, we have links to newsletters, videos, podcasts, and articles.

Read the full newsletter for free at https://newsletter.shortruby.com/p/edition-109

Short Ruby Newsletter - edition 108 highlights

Short Ruby Newsletter - edition 108 highlights

🚀 Launches

  • Landon Gray (pre)launched Dashi - a Streamlit-like Framework for Rubyists
  • Justin Bowen launched activeagents - The AI framework for Rails with less code & more fun
  • Josef Strzibny announced the release of the Kamal Handbook, 2nd edition for Kamal 2

👉 All about Code and Ruby:

  • News: Ruby Central is looking for new board members, DragonRuby version 6 is released and Eileen Uchitelle is the newest Ruby Core Committer
  • Xavier Noria shares how to get a sense of progress when switching to Zeitwerk
  • Jean Boussier shares how they discovered a parser bug
  • Ufuk Kayserilioglu shared a code sample about how to make the private method public for playing in IRB or testing
  • Joel Drapper shared a code sample for a private server-side fetched async Gravatar component using Flecks
  • Vitaly Gambala shared a benchmark result using Rails 8 behind kamal-proxy and found a reduction in memory usage between traefik and kamal-proxy
  • There are a lot of code samples and ideas of what you can do with Ruby and Ruby on Rails inside the newsletter

Remember to read the Thinking about Code section and Around Code, where there are interesting discussions about UI components in Rails, a Japanese discussion about Ruby and types, and much more.

🧰 Gems, Libraries, Tools and Updates

  • New gems discovered last week: phlex-variants: Compose your Phlex component with style variants, basic user registration generator for Rails 8 and a repo with Kamal Github Actions
  • You can also find updates for Avo, RubyLSP, apicraft-rails, lennarb, Sequel, Trix, Rubygems and more in the updates section.

As always, we have a variety of links to newsletters, videos, podcasts, and a good selection of articles to choose from.

Read the full newsletter for free at https://newsletter.shortruby.com/p/edition-108

Moving to Beehiiv

This is a post that I will update this weekend with all the steps I am doing to move the newsletter.



05 October 2024 - 07:00 AM
First thing, I put the newsletter on private on Substack:

Screenshot of how the git commit looks like
How does it look like while being on private


05 October 2024 - 10:00 AM
Second, I need to manually unsubscribe people who unsubscribed from Substack between the first import (20 September) and now. I seem not to have found a way to delete all subscribers in Beehiiv and start from scratch.

I could have deleted everything and started from scratch, but I also have some imports running so I don't want to force my newsletter into a state where it has some errors (like I delete some subscribers and the imports are still running). Maybe it is just my developer brain that thinks about this :)



05 October 2024 - 11:56 AM
Third thing, I did a small PR to change how citation is displayed in our internal source:

Screenshot of how the git commit looks like
Git commit

A shoutout to Kevin Chambers, who quickly replied to all my questions, good or stupid, that I had. This helped me a lot with the migration.



05 October 2024 18:35 (06:35 PM)
After finalizing all the imports, I noticed there is a difference in the total number of subscribers between Beehiiv and Substack: Beehiiv has less than Substack.

I wrote a short script in Ruby to compare them and found: 

Total missing lines: 118

🙃 - I am not sure why this difference exists.

I tried to import them manually, but Beehiiv reports back 0 imported. They are not found to be imported into the interface.


06 October 2024 - 00:04 AM
A ticket has been created after Kevin tried to help me debug this. We will probably have to consider announcing that some people will not receive the newsletter until this issue is solved.
06 October 2024 - 06:00 AM
I continue to edit the newsletter and add content to it

Screenshot of how the git commit looks like
The newsletter editor at Beehiiv

The editor is super good. I discovered that it allows markdown so I will do some PRs to my Rails app where I have the content and create the citations to generate some markdown ready to copy/paste in the editor.

I also want to play a bit with the API - the first thing I think is probably an integration between LemonSqueezy and updating the subscriber status on Beehiiv if possible.  I will probably use https://developers.beehiiv.com/api-reference/subscriptions/put to add a custom field to the subscription and then create a dynamic segment from that. I will figure this out next week. But I am pretty excited to have an API and thus will be able to automate more stuff.

Just figured out a new task for today: export the paying subscribers in LemonSqueezy and cross-reference them with the subscribers marked as paid in Beehiiiv.


07 October 2024 - 06:30
I discovered that by default, Beehiiv does not have an RSS feed via a question on Ruby.social, where someone noticed that the newsletter feed is gone.

Found a way to generate one via Settings -> Publication -> RSS Feed, but the generated URL is not good: https://rss.beehiiv.com/feeds/X67SCnFvlW.xml

I haven't been able to find a way to add an RSS feed button to the main website using the website builder.

I made a quick fix to https://feed.newsletter.shortruby.com and this will be the way to go for anyone that wants to add the newsletter feed. This reinforces my idea that whatever you build you should own the URLs. It allows you to add features that are missing or fix bugs even if the platform does not have support for them. 


8 October 2024 06:23 
Beehiiv support reviewed all the non-imported email addresses and confirmed that all of them are invalid. And I agree that it does not make any sense to import them. I don’t want to have subscribers just for numbers but I want people that are reading the newsletter. 

So this issue is solved!

Preparing to import subscribers

Continuing my updates about the migration of shortrubynews to Beehiiv, at the end of the day today or tomorrow morning (Saturday morning), I will put the newsletter on Substack on private. This means any new subscription needs to be approved and the purpose is to ensure there are no new subscriptions to the newsletter during the migration. 

Next on my list is to add a visible notice in the next edition with a clear Unsubscribe button just in case someone unsubscribed during the export/import but is still imported as active. 

The new newsletter layout will take a couple of iterations to work, but I look forward to customizing it and making it a bit more readable.

This move to Beehiiv opens multiple possibilities: 

  • Maybe start doing the 3 Ruby Links project as a weekly project under the umbrella of 
  • They have an API, so maybe I can automate the content editing more, shorten the time spent arranging items on the page, and do proper citations. 
  • The possibility of having more ads or offering boosts for other IT-related newsletters

In general, this move will help make the newsletter sustainable and, in the long run, afford to pay someone to fully help with content editing. It also opens up the possibility to focus can of automation and allow more time to be spent on better curation. 

Moving the newsletter to Beehiiv

I am currently migrating Short Ruby Newsletter to Beehiiv

I hope to finalize the move by Sunday, 6 October, so the next edition can be sent via Beehiiv. 

What is keeping me busy with this migration?

Roadblock: The imported content does not have image captions

The current roadblock is that the migration of old content did not import the image captions, where I was writing the citation ("Source: @name") with a link to the post in the screenshot.

I wrote to their support, and it seems like this is not supported so far.

So it seems my only decision is to manually add all those citations - which is a lot of work: there are 108 editions (and around 160 posts, because I experimented in the early days with various formats).

Unclear: What should I do with the content on Substack?

Once the migration is finished, what should I do with the content on Substack?

First, the content cannot remain there as there will be duplicates with the one being hosted on Beehiiv.

After the switch the main domain: newsletter.shortruby.com will point to Beehiiv and the Substack one will remain at shortruby.substack.com

Also, the subscribers should only be in a single place, so the list of subscribers on Substack should be deleted. 

I am thinking about a couple of options:

  1. Remove all the posts and unsubscribe everyone on Substack, but keep the subdomain there with a message stating that the newsletter is now hosted there.

  2. Close the publication: this will delete all content and all subscribers

Over the weekend I have to take a decision also about this. 


How do you know if a git commit message is good?

How do you know if a git commit message is good?

If you can browse your git history and understand why those changes were made and why/how that technical decision happened without needing to refer to tickets, issues, or requirements, then you likely have an excellent git history.

If your git history looks like: 

commit 04796b39d364b6c580bbe17ecf3f0160b5c8877d
Author: John Snow
Date:   Sun Jul 7 12:03:51 2024 +0300

    Fix PRJ-5623

commit 828394c2864ea98003491e17b2562ad24bada653
Author: John Snow
Date:   Sun Jul 7 12:03:51 2024 +0300

    Implement PRJ-6523

commit f64299c822a7cd38557eb935f074f18eed5719a2
Author: Jane Dane
Date:   Mon Aug 15 17:41:23 2022 +0300

    Refactor User authentication

commit abbd91854acce973ec662b0f2b75e89a4ceb3261
Author: Jane Dane
Date:   Mon Aug 15 15:30:08 2022 +0300

    Move parse_with_options to Team

Then, you might want to reconsider how you write your commits. 

An example of a goodish git commit message

Here is an example of a git commit message that is good enough: 

Commit 234a85f59da9c81edfa981dd56a1d97795a7d1c9
Author: Lucian Ghinda
Date:   Sun Aug 25 07:56:07 2024 +0300

    Add new tag formats to improve the speed of tagging

    This commit introduces new tag formats in the TagTypeMap and updates
    ContentTypeIdentifier tests for compatibility.

    These changes ensure that the ContentTypeIdentifier can correctly
    identify content types using the new tag formats, maintaining
    the system's flexibility and reliability.

    Why these changes?

    (1) We want to allow users to tag content using shorter tags
        eg: `stype` instead of `section:type`

    (2) Automatically fix typos in tag formats:
        eg: typing `a` instead of `s` in `s:type` => `a:type`

    (3) Duplicate tag letter replaces `:`
        eg: `aatype` is the same as `a:type`
            `sstype` is the same as `s:type`

    Changes:

    1. Updated TagTypeMap to include new formats:

    - 's:type' (e.g., 'a:code', 'a:article')
    - 'stype' (e.g., 'scode', 'sarticle')
    - 'sstype' (e.g., 'sscode', 'sstarticle')
    - 'a:type' (e.g., 'a:code', 'a:article')
    - 'aatype' (e.g., 'aacode', 'aaarticle')
    - 'Aatype' (e.g., 'Aacode', 'Aaarticle')

    2. Updated ContentTypeIdentifier tests to cover new tag formats
    for all existing content types:

    - Code, Articles, Videos, Library, Newsletter, Podcasts
    - Related, Community, Events, Books, Launch, Slides

A better example

Here is an example of a git commit message shared by Zlatko Alomerovic via Linkedin. The message is written by Jean Boussier (@byroot) in a commit for Rails  and it looks like this (here is just the first part of it)

Screenshot of a commit message
Screenshot of the first part of the message

The full message looks like this: 

commit 8c7e69b79b63a88a170a9b9004a906db00161a3b
Author: Jean Boussier 
Date:   Mon Jan 8 18:43:37 2024 +0100

    Optimize Hash\#stringify_keys

    Using Symbol\#name allows to hit two birds with one stone.

    First it will return a pre-existing string, so will save
    one allocation per key.

    Second, that string will be already interned, so it will
    save the internal `Hash` implementation the work of looking
    up the interned strings table to deduplicate the key.

    ```
    ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin21]
    Warming up --------------------------------------
                    to_s    17.768k i/100ms
                    cond    23.703k i/100ms
    Calculating -------------------------------------
                    to_s    169.830k (±10.4%) i/s -    852.864k in   5.088377s
                    cond    236.803k (± 7.9%) i/s -      1.185M in   5.040945s

                    cond    236.803k (± 7.9%) i/s -      1.185M in   5.040945s

    Comparison:
                    to_s:   169830.3 i/s
                    cond:   236803.4 i/s - 1.39x  faster
    ```

    ```ruby
    require 'bundler/inline'

    gemfile do
      source 'https://rubygems.org'
      gem 'benchmark-ips', require: false
    end

    HASH = {
      first_name: nil,
      last_name: nil,
      country: nil,
      profession: nil,
      language: nil,
      hobby: nil,
      pet: nil,
      longer_name: nil,
      occupation: nil,
      mailing_address: nil,
    }.freeze

    require 'benchmark/ips'

    Benchmark.ips do |x|
      x.report("to_s") { HASH.transform_keys(&:to_s) }
      x.report("cond") { HASH.transform_keys { |k| Symbol === k ? k.name : k.to_s } }
      x.compare!(order: :baseline)
    end
    ```

Short Ruby Newsletter - edition 107 published

Short Ruby Newsletter - edition 107 is published. Here are some highlights: 

🚀 Launches

  • Ruby Europe launched their community and presented the plans for the rest of 2024
  • Obie Fernandez launched the book "The Rails 8 Way"
  • Pragmatic Programmers are running a 40% discount on all Ruby and Rails eBooks
  • John Pigford launched Revise - an AI Code Correction Tool
  • RoRvsWild launched their one-on-one personalized performance advice

📢 News from Rails World

  • This edition contains an entire section dedicated to Rails World where I curated a couple of the many photos, ideas and talk summaries shared online last week from the conference.

👉 All about Code and Ruby:

  • Seth Horsley shared a thread about how to implement method overloading in Ruby using class methods
  • Samuel Wiliams shared how to use with_connection
  • Deepak Mahakale shared how to create aliases in Kamal 2
  • Julian Rubisch shared how they upgraded BetterStimulus.com to Kamal 2
  • Joel Drapper shared a couple of videos and code samples showing how to support async rendering in Rails using Phlex
  • In Around Code you will find the results of the Ruby on Rails community survey by Planet Argon where there are a lot of interesting updates.
    And much more code samples and Ruby ideas.

🧰 Gems, Libraries, Tools and Updates

  • Mike Delassio launched tailwindcss-ruby: A self-contained tailwindcss executable, wrapped up in a ruby gem
  • Chris Oliver launched ferrum_pdf: A PDF generator for Rails using Ferrum & headless Chrome
  • Stanislav Katkov published a couple of gems about making Jekyll work with nobuild Tailwind CSS: jekyll-tailwind-cli, jekyll-heroicons and a template jekyll-tailwind-cli-template
  • Joel Drapper published a new gem called Flecks - Render IO-bound content asynchronously and stream it into a wrap-around shell in a single HTTP response with Phlex
  • Ben Sheldon started working on Spectator Sport - Record and replay browser sessions in a self-hosted Rails Engine
  • Thomas Marshall published a new gem called minitest-verify - A minitest plugin to prevent false negative tests
    And like there are a bunch of gem updates that we included in the newsletter.

Like always we have a lot of newsletters, videos, podcasts and a good selection of articles to choose from.

Read the full newsletter for free at https://newsletter.shortruby.com/p/edition-107

Post live updates from conferences

I am not at Rails World, and I have huge FOMO at home. I look at almost all the people going there and already have a great time even before the conference starts. 


Enjoy the conference and make some new friends!

With this occasion, I'd like to invite you all to share/post online what you are learning during the conference.  It would be good for the community to post live updates on social media during all conferences. 


Here’s the structure of a good social media post:

  1. Take a screenshot of a slide, ensuring the speaker is included.
  2. Highlight the most important idea the speaker mentioned
  3. Add your own thoughts about it.
  4. Publish the post, then reply with the next interesting point from the presentation.

In case you want to see some examples, I did something like this from my own account during EuRuKo (see a list of posts here) and did the same from the Friendlyrb account on Twitter and Mastodon during Friendly.rb conference


I got very good feedback about doing this kind of live posting. 

I know that usually all videos and slides are posted online, but creating a buzz during the conference and sharing the ideas that YOU find interesting is also an important contribution. 
It helps show how active our community is and how many ideas are shared. 

Later on, the series of posts that you shared could be transformed into a blog post about how it was at that conference, and in the process, you will get the side effect of doing a recap of what you learned from that experience. 

Happy #RailsWorld! 

See you at EuRuKo 2024

This week, I'll be at EuRuKo 2024 , where I'll speak on two subjects close to my heart:

  1. Systematically writing tests to cover more business logic with fewer test cases - Thursday at 14:00, Third Track

  2. Keeping Ruby relevant by using new language features - Friday at 15:20, Main Track

Screenshot describing the two talks that I will deliver at EuRuKo 2024
Talks at EuRuKo 2024

If you are there, let's meet and talk about Ruby, the future, and how to attract new people to learn Ruby and Rails. Looking forward to hearing your ideas. 

Find me on social media at: 

Short Ruby Newsletter - edition 106 published

The one about Rails performance benchmarks, new Array#fetch_values method and Rails launched an official video series with tips and best practices. 

🚀 Launches

  • Ruby on Rails launched a new video series called Rails in Focus created by Emmanuel Hayford
  • Alexandre Ruban is working on a new tutorial about the New Rails Authentication Generator (similar with the hotwired.dev)
  • Events: Friendly.rb shared the latest update about speakers and outdoor activities and Ahmed Nadar with AppSignal launched the AppSignal's Guide to Toronto for Rails World


👉 All about Code and Ruby: 

  • Takashi Kokubun announced Ruby 3.3.5 is published and Charles Nutter published an article about his plans and vision for the future of JRuby
  • DHH announced that Solid Cache and Solid Queue are now defaults for Rails 8
  • Xavier Noria shared about type aliases in Ruby and Kevin Newton shared some interesting Ruby grammar examples, while Jean Boussier did a deep dive into accessing a hash via an object key
  • There is a wide range of discussions about code design and I picked some of the posts shared last week about Ruby on Rails performance. 
  • There are also many more inspiring and useful code samples. Don't forget to read the section "❤️ Why Choose Ruby and Rails," where people share why they chose Ruby or Ruby on Rails. 


PS: Remember to read Nick Schwaderer's thread about how the RubyGems homepage changes over time.  

🧰 Gems, Libraries, Tools and Updates 
There are a bunch of gem updates that we included in the newsletter:

  • Avo launched some big changes like DateTime filter, new custom components and many Dynamic Filters improvements and Joel Drapper announced Phlex 2.0 alpha 
  • Nate Berkopec announced a new benchmark-ips release with a new syntax while Akira Matsusa announced a new release of simplecov-html after 4 years. 

I also highlighted 3 discussions from the latest Ruby Dev Meeting about the Namespace on read, optimized instructions for frozen literal Hash and Array and the new Array#fetch_values method.

As always, we have a large number of newsletters, videos, podcasts, and a good selection of articles to choose from.

Read the full newsletter for free at https://newsletter.shortruby.com/p/edition-106

Friendly.rb Ruby Conference updates

In case you have missed the social media announcement let me share here the ✨ Two weeks before Friendly.rb 2024 Update ✨

👩🏼‍🦰 Speaker announcements

We're happy to announce three new speakers for this year's edition: 

They are going to speak about building the community, complexity and legacy code, and about the day in the life of 2,000 developers at Stripe.

🎟️ Nearing sold-out

We are nearing the sold-out mark so if you were on the fence, you should act now 😬

https://friendlyrb.com/tickets

🏕️ Outdoor activities

We have confirmed the Friday trip: 

🗻 back to the mountains (like actually into the mountains)

✅ different location from last year

🏰 seeing a castle

🧗 visit a natural cave

🐑 eat from the local shepherds

🌁 beautiful vista of the mountains

🫱🏼‍🫲🏾 unforgettable friendships

See you soon!

What tests would you write for these two simple Ruby objects

Imagine you wrote this simple PORO in your Ruby on Rails app:

class CreditCard::AgeValidator
  def initialize(age)
    @age = age
  end
  
  def valid?
    return true if @age >= 18 
    
    false
  end
end

What tests would you write for it? 

What cases would you cover with your tests? How many tests would you write?

What about this update_required? method. 

What cases would you cover when testing Account#update_required? 

What cases would you cover with your tests? How many tests would you write?

class Account < ApplicationRecord
  \# t.date "expires_at"
  \# t.string "website"
  
  def update_required?
    website.blank? || expired?
  end
  
  def eternal? = expires_at.nil?
  
  def expired?
    return false if eternal?

    expires_at < Date.current
  end
end

Three Ruby Links #3

If I were to recommend three articles published last week to read, here is what I would recommend:

1️⃣ The Thread API : Concurrent, colorless Ruby by JP Camara

Screenshot from a part of the article "Ruby shebang behavior"
Excerpt from "The Thread API : Concurrent, colorless Ruby"

JP Camara continues their series about concurrency, parallelism, and async programming  and this one is about threads. It is a deep dive into Ruby threads with a lot of code samples.

2️⃣ Ruby shebang behavior by Ashok Gautham Jadatharan

Screenshot from a part of the article "Ruby shebang behavior"
Excerpt from "Ruby shebang behavior"

Ashok found an interesting allowed behavior from CRuby interpreter that allows to create scripts that can run both bash and Ruby commands. The article shows code samples about how to do this.

3️⃣ How to test graphql-ruby responses by Dmitry Tsepelev

Screenshot from a part of the article "Ruby shebang behavior"
Excerpt from "How to test graphql-ruby responses"

Dmitry is writing a good tutorial about how to test GraphQL using RSpec, but the ideas presented here can be applied also to Minitest. The code samples are clear, with comments to understand pros and cons.


You can find a lot more articles to read in the full edition of Short Ruby Newsletter at https://newsletter.shortruby.com/p/edition-105

Check out the schedule for https://friendlyrb.com - a conference I co-organize in September this year in Bucharest, Romania. We will have exciting talks and a relaxing atmosphere to meet new Ruby developers. 

Written by Lucian Ghinda - Senior Ruby Developer by day, Curator of Short Ruby Newsletter during weekends