Short Ruby Newsletter

Share this post

πŸ‘‹ Short Ruby News - edition #21

newsletter.shortruby.com

πŸ‘‹ Short Ruby News - edition #21

Briefly about everything in Ruby world

Lucian Ghinda
Dec 5, 2022
7
Share this post

πŸ‘‹ Short Ruby News - edition #21

newsletter.shortruby.com

This edition was created with the help ofΒ @adrianthedev/@adrian@ruby.socialΒ fromΒ Avo for Ruby on Rails (a friendly full-featured Rails admin panel) and @jcsrb.

You can jump directly to one of the following sections if you like:

πŸ‘ Our Community

πŸ‘‰ All about Code and Ruby

🧰 Gems, Libraries, and Updates

🀝 Related (but not Ruby-specific)

More content: πŸŽ₯ 🎧 πŸ—ž (articles, podcasts, videos, and newsletters)


πŸ‘ Our Community

Source: @fxn

πŸ‘ Ruby On RailsΒ shared about Ruby scales:

Rails scales. From HELLO WORLD to The Entire World.
Source: @rails onΒ Twitter

πŸ‘ Someone asked the following question on /r/ruby:

Source: /r/ruby

I think it is worth considering if we want to create more contents that is not only for people coming to Ruby from other languages but also learning Ruby as their first programming language.

πŸ‘‰ All about Code and Ruby

πŸ‘‰Β Jason SwettΒ asked a question about their pain points:Β 

Rails devs: Over the years, what are some things that you've been consistently unhappy with about your OWN code? For example, for years I couldn't figure out how to fix my nasty 800-line models...in a way that was actually an improvement. What about you?
Source: @JasonSwett onΒ Twitter

Here is a summary of the answers:

  • β€œover investing in interactors” (@dpaola2)

  • β€œPolicies + permissions sneaking into multiple places across the codebase.” (@joemasilotti)

  • β€œHandling API validation without leaning too much on AR validations.” (@timcheadle)

  • β€œControllers with too many complex options and custom methods” (@Diragor)

  • β€œHow to break down code which feels like it should belong in the model. That and callbacks.” (@bmozza)

  • β€œFront-end code organization. Asset management. Deployment. Automating accessibility testing. HTML emails” (@TALlama)

  • β€œFile structure, mostly when there si multiple features and country conditions” (@barroetald)

  • β€œI often find myself having to create custom serializers if i dont want to .includes multiple relations that im not using” (@bc2rieg)

  • β€œnested serializers and field selection is the absolute worst” (@eleslovaco)

πŸ‘‰Β Eric BerryΒ shared a sample code in replit about creating a color palette in Ruby:

Need a color palette for your charts/graphs in Rails? I wrote up a class that will generate the colors for you with the following code: ColorPalette.generate(30) Try it out at
Source: @coderberry onΒ Twitter

πŸ‘‰Β Shopify Engineering shared a thread about how they handled Black Friday and Cyber Monday:

πŸ“ˆWe served 75.98 Million requests per minute to our commerce platform at peak. That’s 1.27 Million requests per second!
Source: @ShopifyEng

You should read the entire thread for more impressive stats. When people ask if Ruby scales show them this.

πŸ‘‰ Dave Copeland shared a piece of code in Ruby showing how to have a method accept multiple blocks:

Source: @davetron5000@ruby.social

I think the conversation between Peter Solnica, James Adam, Ryan Bates, Dave Copeland, and Brandon Weaver about methods of accepting multiple blocks is worth reading on ruby.social.

If you don’t want to read it all, at least look at this code snipped by Brandon Weaver, where he implemented function objects with stack and compose blocks showing the flexibility and beauty of Ruby.

πŸ‘‰Β Matt SwansonΒ shared a view component concept: Fallback slots

ViewComponent pattern/concept: "Fallback slots" It's really powerful for building components that can support an excellent 'happy path' but also still be ergonomic for dropping down to lower-levels Small detail is naming the slot and argument the same ("title")
Source: @_swanson onΒ Twitter

πŸ‘‰Β Emmanuel HayfordΒ shared a code sample about Active Record for async queries:

Rails 7.1 will give you a lot of possibilities: Active Record added an API for general async queries. Soon, you’ll be able to run aggregates and `find_by_sql` asynchronously. So you can do stuff like:
Source: @siaw23 onΒ Twitter

πŸ‘‰ Noel Rappin asked how the community feels about static typing in Ruby:

Source: @noelrap@ruby.social

Here are some answers:

β€œI'm hard-pressed to think of it as significantly better than documenting the type or using a convention around naming UNLESS the entire codebase uses it and opting out is not an option. In that case, "lean on the compiler" refactoring is awesome and the only thing I miss from Java.” (@davetron5000@ruby.social)

β€œit’s the future. Having a compiler tell you about a type bug BEFORE your users do is a lifesaver. I’ve tried using Sorbet with mixed results. Leaning more on dry-types and dry-schema these days, as they’ll give runtime type validations. The code that uses these gems _feels_ safer” (@Ryanbigg@ruby.social)

β€œI want to write YARD and have it checked, but if I have to spend time trying to figure out the incantation needed to convince the typing system what I’m doing is correct, it’s too intrusive. If I need to add boilerplate, it’s too intrusive.

I think YARD + sord + steep is potentially a good synergy but I wish it were more automatic than it is.” (@ZiggyTheHamster@ruby.social)

β€œfor me it's far more bound to the domain complexity, a lot of which self inflicted through polymorphism or polymorphic associations among other things. I find it to be very useful at boundaries, and less useful in the inner domains. Boundaries, like packs / Packwerk might provide, are domain gates where context is more easily lost on how to interact.” (@baweaver@ruby.social)

These were just a few replies, but the conversation is bigger and worth reading it all. People share a lot of experiences and cases from both sides.

πŸ‘‰Β AyushΒ shared that the book they are working on is almost ready:

At long last, The Rails and Hotwire Codex is complete and will drop on 15th December, 2022. It's funny how my deadlines went from mid summer, to late summer, to early Q4, to before the end of the year πŸ˜‚. Complications arose, ensued, were overcome.
Source: @ayushn21 onΒ Twitter

πŸ‘‰Β ΠΏΠ°Π½ ZverokΒ shared a code sample about unpacking numbers into binary order of magnitude and prefixes:

A small excercise in modern (3.2-pre 😁) Ruby, inspired by https://t.co/wQora4Iidj Helper module for "unpacking" numbers into binary orders of magnitude + prefixes
Source: @zverok onΒ Twitter

πŸ‘‰Β Jakob SkjerningΒ shared a sample code showing how to alias attributes in Active Record:

#TIL You can alias attributes in ActiveRecord, and it will even work for database queries #ruby #rails #activerecord
Source: @mentalizer onΒ Twitter

πŸ‘‰Β Drew BraggΒ shared a code sample showing how Ruby can work with emojis:

I blame @schwad_rb for this cursed #ruby code
Source: @DRBragg onΒ Twitter

πŸ‘‰ Joel Drapper shared a preview of what might be included in the phlex-markdown:

Source: @joeldrapper@ruby.social

πŸ‘‰Β Greg NavisΒ shared a thread about Ruby tips about partitioning and grouping arrays:

1️⃣ partition returns two arrays: items that meet and don't meet the condition passed in via a block In the example below, we classify clients on whether they have a free or paid account. There's also group_by for more complex cases ...
Source: @gregnavis onΒ Twitter

Please read the thread, as it has an example also about group_by.

πŸ‘‰Β Ryan BatesΒ sharedΒ that it is hard following and reading Ruby code with mixins:

Anyone else have difficulty reading Ruby code that makes heavy use of modules? I have no idea where a given method is defined or what methods are available in a given context.
Source: @rbates onΒ Twitter

It would be good to read the replies because many people share why the code is complex to read when using many modules as mixins.

πŸ‘‰ FlavioΒ sharedΒ a thread about various Heroku alternatives:

Source: @flaviocopes onΒ Twitter

Here are some alternatives proposed:

  • replit.com - like a playground suitable for test projects. Each app gets a repl.co subdomain

  • glitch.com - a playground for Nodejs apps and simple sites

  • vercel.com - a hosting option for Nodejs with a generous hobby plan

  • netlify.com - for hosting static sites, they have a great free plan. No backend

  • CloudFlare Pages - similar to Netlify, no backend but with unlimited bandwidth

  • render.com - have a free plan, static site hosting can run Node/Python/Rust/Go/Ruby and much more with a free database

  • railway.com - free started plan, can add multiple apps, with database and support for SvelteKit, Next, Vite, Rails, Nuxt …

  • supabase.com - with a free plan of up to 2GB bandwidth and 1GB file storage for the database, it also has some support for functions using Deno. They have a migration tool for data from Heroku to supabase

  • fly.io - has a free plan great for experimenting and support for entirely hosting your web app, including database, load balancing, monorepos, and more

  • dokku - transforms a server/VPS into a Heroku clone

πŸ‘‰ Sandi Metz announced a 40% discount for the 99 Bottles book, which seems to end on Monday night:

The 99 Bottles of OOP 40% off Half-Birthday Sale ends tomorrow night! Next sale in June on our birthdays--that's a long wait. πŸŽ‰ now
Source: @sandimetz on Twitter

If you have read so far and you like the content, maybe you take into consideration sharing this and subscribing:


🧰 Gems, Libraries, and Updates

🧰 Marc Anguera Insa shared a new project Tonic - Self meta-described collections framework. It takes a collection defined in an YAML or JSON and automatically generates a beautiful website build with Middleman, Ralix and Tailwind.

🧰 Alexandre Ruban shared a new gem action_markdown that helps to work/displaying markdown content:

I love @github's Markdown editor when writing issues/pull requests. 😍 I would love to have this feature out of the box for Ruby on Rails applications. This is why I released my first gem action_markdown which aims to reproduce GitHub's editor.
Source: @alexandre_ruban onΒ Twitter

If you are looking to use markdown, here are some other possible options markdown-rails or html-pipeline or phlex-markdown

🧰 Nate Hopkins published hopsoft/reflex_behaviors: Pre-built easy-to-use reactive TurboReflex behaviors for Rails/Hotwire apps.

🧰 Gurbaaz Singh Nandra published a code in Ruby to create an interpreter for λ-calculus implemented in ruby

🧰 Vladimir Dementyev shared a new EvilMartians gem activerecord-slotted_counters.

Slotted counters help to reduce contention on a single row update in case you have many concurrent operations (like updating a page views counter during traffic spikes)

Source: https://github.com/evilmartians/activerecord-slotted_counters

🧰 Ngan Pham shared a PR that was merged to Rails and fixes the deadlock caused by using a fiber inside a transaction: Make AbstractAdapter#lock thread local by default

🧰 Jeremy Evans shared a new version for Sequel 5.63.0 Released Read the changelog

🧰 Aaron Patterson shared a PR they created and merged to Ruby that will Speed up IV writes

🧰 Lewis Youl shared a PR for Turbo that allows it to respond with turbo streams to GET requests Allow Turbo Streams with GET via data-turbo-stream


🀝 Related (but not Ruby specific)

🀝 Rose W shared small things that can have a lot of impacts in our daily work:

A few little things that can have a lot of impact at work: - Remember to say thank you - Highlight other people’s good ideas and work for them (after checking they are ok with public praise) - When someone helps you tell their boss you appreciated it
Source: @rose_w onΒ Twitter

🀝 Jason Swett shared a programming tip:

Programming tip: Try to use as few conditionals as possible. They often make code harder to understand.
Source: @JasonSwett onΒ Twitter

🀝 Bijan shared a tip about submitting an html form tag without Javascript from outside the form. I know this is not something new but I think it is good to remind ourselves about this:

Did you know that you can submit an html form without javascript from outside the form tag by referencing the form="dom_id"?
Source: @BijanRahnema onΒ Twitter

🀝 Celso De Sa shared an explanation for Liskov Substitution in Ruby explained by ChatGPT:

Ever struggled to grasp what Liskov Substitution Principle really mean? I asked #GPT3 to explain it with an analogy and code: "The Liskov Substitution Principle is like a recipe. If a recipe calls for butter, you can substitute it for margarine and still get the same results.
Source: @CelsoDeSa onΒ Twitter

🀝 Adam Hess shared a new project to explore Ruby WASI:

I built a Ruby Explorer using Ruby WASI https://t.co/e3VTQIcagw
Source: @theHessParker onΒ Twitter

More content: πŸŽ₯ 🎧 πŸ—ž

Slides

Jeremy EvansΒ shared their slides from RubyConf 2022 aboutΒ Helping Redistrict California with Ruby

Benoit DalozeΒ shared their slides from RubyConf 2022 about Splitting: The Crucial Optimization for Ruby Blocks

Noel Rappin shared their slides from RubyConf 2022 about In Defense of Metaprogramming

Newsletter

πŸ—ž Any CableΒ published a new editionΒ Any Cables Monthly #5 – November, 2022

πŸ—ž Ruby on Rails published a new edition of This Week in Rails curated this week by Wojciech WnΔ™trzak

πŸ—ž Ruby Radar published a new edition: Ruby Radar #79

πŸ—žοΈ Ruby Weekly published a new edition: Let's create a basic (useful) Ruby C extension

πŸ—žοΈ Ruby LibHunt published a new edition of the Awesome Ruby Newsletter

πŸ—ž Women on Rails published a edition Newsletter #40

Podcasts

🎧 Jason Swett published a new episode about 165 - Upgrading Rails with Ernesto Tagwerker

🎧 Remote Ruby published a new episode about New Ruby versions, the Pay gem, and the new GitHub file browser

🎧 The Ruby on Rails Podcast published a new episode about The Rubyconf Mini Podcast Panel

🎧 Remote Ruby published a new episode about New Ruby versions, the Pay gem, and the new GitHub file browser

Videos

πŸŽ₯ Andrew Culver shared a video from Rails SaaS conference by Nadia Odunayo: Getting to One Million Users as a One-Woman Dev

πŸŽ₯ Drifting RubyΒ published the video version of Β This Week in Rails - Dec 2nd, 2022

πŸŽ₯ Tom Stuart shared a video where they show they could replace Struct with Data.define without incidents: Making a WebAssembly interpreter in Ruby, part 17: Ruby 3.2, branch targets and function calls

Articles

Avo published the second part of their series of articles about How Successful Agencies Ensure Dev Happiness Part 2

Andrei KaleshkaΒ published a new article aboutΒ Keep DB schema clean and consistent between branches

Ryan Bigg published a new blog post about Hanami 2.0

David CopelandΒ published an article aboutΒ Dealing with Flaky Tests

Ruby Lib HuntΒ shared an article aboutΒ Pending migrations now show path instead of filename

Β Kevin NewtonΒ published the second article about YARV, the virtual machine of CRuby: Β Advent of YARV: Part 2

AvoΒ published an article aboutΒ Nested records when creating

Ryan DavisΒ sharedΒ an article showing Correct Delegation with Ruby 2.6, 2.7 and 3.0

Rob Mc CormickΒ sharedΒ their article about Know Rails? How to get started with Bridgetown

The Ruby DevΒ sharedΒ an article written by David Santangelo Ruby multithreaded crawler


Thanks for reading Short Ruby Newsletter! If you enjoyed this and want to receive the newsletter weekly in your inbox, consider subscribing:

Share this post

πŸ‘‹ Short Ruby News - edition #21

newsletter.shortruby.com
Previous
Next
Comments
TopNewCommunity

No posts

Ready for more?

Β© 2023 Lucian Ghinda
Privacy βˆ™ Terms βˆ™ Collection notice
Start WritingGet the app
SubstackΒ is the home for great writing