---
title: "Entropy"
publication: "Ruby Weekly"
issue: 588
published_at: "2022-01-27"
canonical_url: "https://rubyweekly.com/issues/588"
---

Plus a nice freebie, Sidekiq concurrency control, and a new tip of the week. |        

#​588 — January 27, 2022 

[Read on the Web](https://rubyweekly.com/issues/588)   

✍️ [Last week's issue](https://rubyweekly.com/issues/587) had so many interesting bits of news that it was a hard act to follow, so while this _is_ a quieter week in the Ruby world, be sure to check [last week's issue](https://rubyweekly.com/issues/587) too if you skipped it at all :-)
__
_Peter Cooper — Editor_  

Ruby Weekly 

[![\](https://res.cloudinary.com/cpress/image/upload/w_1280,e_sharpen:60/gijk5pdwf7uixavaszuj.jpg)](https://github.com/rpush/rpush)   

[RPush 7.0: The Push Notification Service](https://github.com/rpush/rpush) — An abstraction over numerous push notification systems, including those from Apple, Google, Amazon, and more. This 7.0 release adds Ruby 3.1 and Rails 7.0 support. 

Ian Leitch   

[Building GraphQL APIs in Rails](https://www.honeybadger.io/blog/graphql-apis-for-rails/) — GraphQL is a flexible, strongly-typed query language, and while it doesn’t naturally mesh directly to Rails' typically REST-oriented approach, there are ways to make it possible, and if you don’t even know _why_ you might use GraphQL, David does a good job of explaining it all here. 

David Sanchez   [![\](https://copm.s3.amazonaws.com/e35f4b7f.png)](https://buttercms.com/ruby-cms/?utm_source=rubyweekly&utm_medium=email&utm_campaign=numberone) 

[ButterCMS Melts into Your Ruby App. #1 Rated Headless CMS](https://buttercms.com/ruby-cms/?utm_source=rubyweekly&utm_medium=email&utm_campaign=numberone) — ButterCMS is your content backend. Enable your marketing team to update website + app content without needing you. Try the #1 rated Headless CMS for Ruby today. Free for 30 days. 

ButterCMS sponsor   

[Spree Commerce 4.4: The Open Source Rails Ecommerce System](https://spreecommerce.org/spree-commerce-4-4-is-even-more-composable-and-customizable) — Spree is a long standing ecommerce system built on top of Rails and 4.4 is a big release for them including using Hotwire for a smoother dashboard experience, features for selling digital downloads, wishlist functionality, and more. [Solidus](https://github.com/solidusio/solidus) is another option in this space; it began life as a fork of Spree. 

Spree Commerce   

**IN BRIEF:** 

- The [DragonRuby Game Toolkit](https://dragonruby.org/toolkit/game) has been made [free for the next two weeks](https://itch.io/s/64619/dragonruby-jam-time-sale-100-discount) to encourage Rubyists to enter some forthcoming game jams and increase Ruby's representation in the game dev space.
- Eight years after his famous [video about learning Vim in a week](https://www.youtube.com/watch?v=_NUO4JEtkDw), Mike Coutermarsh [is _still_ using Vim](https://mikecoutermarsh.com/i-still-use-vim/) and sharing [his up to date dotfiles](https://github.com/mscoutermarsh/dotfiles).
- [RubyGems 3.3.6](https://blog.rubygems.org/2022/01/26/3.3.6-released.html) has been released.
- There was a (very) [brief discussion on Hacker News](https://news.ycombinator.com/item?id=30022185) about whether Rails is worth learning as a solo founder in 2022. Spoiler: _Yes_.     

Jobs  

[Go Engineer](https://buildkite.com/careers/site-reliability-engineer) — Help us scale one of the biggest Postgres-powered Rails majestic monoliths in the world. 
Buildkite   

[Senior Rails Developer @ Wherefour (100% Remote)](https://wherefour.com/careers-developer/) — Curious how stuff gets made? Come build great software that makes great products. 
Wherefour   

[Find Ruby Jobs Through Hired](https://hired.com/join/?utm_source=newsletter&utm_medium=sponsor&utm_campaign=%28b2c%29%28l-all%29%28r-all%29%28cooper-rubyweekly%29&utm_content=find-your-next-job) — Create a profile on Hired to connect with hiring managers at growing startups and Fortune 500 companies. It's free for job-seekers. 
Hired    

📕 Articles & Tutorials  

[Using Entropy for User-Friendly Strong Passwords](https://planetscale.com/blog/using-entropy-for-user-friendly-strong-passwords) — A look at the approach database platform PlanetScale took with their signup form to enforce strong passwords while also playing nicely with password managers. 

Mike Coutermarsh (PlanetScale)   

[Build Your Own Concurrency Control in Sidekiq](https://longliveruby.com/articles/build-your-own-concurrency-control-in-sidekiq) — If you’ve got background jobs you _want_ to perform sequentially, a locking system may be useful. [Sidekiq::Sequence](https://github.com/joelmoss/sidekiq-sequence) or [SidekiqUniqueJobs](https://github.com/mhenrixon/sidekiq-unique-jobs) may also be useful if you need similar functionality out of the box. 

Mihai Colceriu   

[Enqueue Jobs Quickly with Sidekiq’s Bulk Features](https://andycroll.com/ruby/enqueue-jobs-quickly-with-sidekiq-bulk/) — What if you have the opposite problem.. _lots_ of jobs you want to cram into Sidekiq as fast as possible? Andy Croll has your back, and can get you down from lots of trips across the network to just one. 

Andy Croll   

[Free eBook: Efficient Search in Rails with Postgres](https://pganalyze.com/ebooks/efficient-search-in-rails-with-postgres?utm_source=RubyWeeklySecondary01272022) — Speed up a search query from seconds to milliseconds and learn about exact matches, trigrams, ILIKE, and full-text. 

pganalyze sponsor   

[Upgrading Rails from 6.1 to 7.0: Things to Consider](https://www.fastruby.io/blog/rails/upgrades/upgrade-rails-6-1-to-7-0.html) — A tactical upgrade guide from the company that makes a business around upgrading Rails. 

Cleiviane Costa (FastRuby.io)   

[Switching from Webpacker 5 to jsbundling-rails with webpack](https://github.com/rails/jsbundling-rails/blob/main/docs/switch_from_webpacker.md) — Since there will be no Webpacker 6, you might want to be aware of this. 

Rails Contributors   

[Test and Optimize Your Rails App's Database Performance](https://blog.appsignal.com/2022/01/26/test-and-optimize-your-ruby-on-rails-database-performance.html) — Quickly covers three ways to investigate problems and then seven ways to mitigate said problems. 

Milap Neupane   

[Working with Ruby C Extensions on a MacBook](https://medium.com/klaxit-techblog/working-with-ruby-c-extensions-on-a-macbook-639c068a9815) — While some of this is Mac-focused, there are loads of linked resources that dive deeper, so if you’re interested in Ruby and C, this is a fine place to start. 

Ulysse Buonomo   

[Rails 7's Support for Postgres' Generated Columns](https://blog.saeloun.com/2022/01/25/rails-7-postgres-support-for-generated-columns.html) 
Swaathi Kakarla  

🛠 Code & Tools  

[Que 1.0: A Ruby Job Queue That Uses Postgres's Advisory Locks](https://github.com/que-rb/que) — A perfect use for Postgres’s built in advisory locking mechanism to bring more reliable job queue functionality to Ruby by using said locks to protect the state of the jobs. 

Chris Hanks   

[Puma 5.6 Released: A Rack Web Server Built for Concurrency](https://github.com/puma/puma) — This [particular release](https://github.com/puma/puma/releases/tag/v5.6.0) shares a nickname with Nate Berkopec’s daughter! :-) 

Puma Team   

[Shortcut Puts the Agile in Agile and the “Can” in Kanban](https://shortcut.com/?utm_source=cooperRubyWeekly&utm_medium=spon_nl&utm_campaign=prospecting&utm_content=kanban) 

Shortcut (formerly Clubhouse.io) sponsor   

[Wasabi: A Simple WSDL Parser](https://github.com/savonrb/wasabi) — Web Services Description Language is an XML-based language for defining web service functionality (frequently used with SOAP). 

Daniel Harrington   

[Sidekiq 6.4: Simple, Efficient Background Processing for Ruby](https://github.com/mperham/sidekiq) — We've mentioned it a few times already in this issue, but there's a new release too ;-) 
Mike Perham   

[rails_param: Parameter Validation and Type Coercion for Rails](https://github.com/nicolasblanco/rails_param) 
Nicolas Blanco   

[MemoWise 1.6: A Modern Choice for Ruby Memoization](https://github.com/panorama-ed/memo_wise) — Now officially supports Ruby 3.1. 
Panorama Education   

[React on Rails: Bringing React, Webpack, and Rails Together with Webpacker](https://github.com/shakacode/react_on_rails) 
ShakaCode   

[Counter Culture 3.2: 'Turbo-Charged' Counter Caches for Rails Apps](https://github.com/magnusvk/counter_culture) 
Magnus von Koeller       

💡**Tip of the Week** 

   

## `File` Methods: Part Two 

In [last week's tip](https://rubyweekly.com/issues/587), we learned about `__FILE__`, which gives us the path to the current file, and `File.expand_path` which gives us the full absolute filepath. 

### [`File.dirname`](https://ruby-doc.org/core-3.1.0/File.html#method-c-dirname) 

As the name implies, [`File.dirname`](https://ruby-doc.org/core-3.1.0/File.html#method-c-dirname) will give us the path to the directory of a file. Combining this with what we learned last week, this means that if we had a file at `ruby_weekly/sample.rb` with the following contents: 

```
puts File.dirname(__FILE__)
``` 

..we could run it and see the directory: 

```
$ ruby ruby_weekly/sample.rb
ruby_weekly
``` 

Interestingly, in Ruby 3.1, `File.dirname` introduced an optional second parameter, an integer which represents how many levels to go up the directory tree. So for instance, if the full path to the above file is `/Users/jemmaissroff/ruby_weekly/sample.rb`, and we edit the file slightly to use the full path, and a second argument: 

```
puts File.dirname(
       File.expand_path(__FILE__), 2
     )
``` 

we'll see the path to the directory two up the directory tree from our file: 

```
$ ruby ruby_weekly/sample.rb
/Users/jemmaissroff/
``` 

### [`File.join`](https://ruby-doc.org/core-3.1.0/File.html#method-c-join) 

Last up in `File` methods (I promise we're getting there!), [`File.join`](https://ruby-doc.org/core-3.1.0/File.html#method-c-join) joins its arguments with a "/" to create a filepath. For instance: 

```
File.join("app", "controllers", "file_name.rb")
# => "app/controllers/file_name.rb"
``` 

Notice this is exactly the same as if we'd run: 

```
["app", "controllers", "file_name.rb"].join("/")
# => "app/controllers/file_name.rb"
``` 

This can be useful to construct a file path from a relative file. Before Ruby 3.1 introduced the second argument to `File.dirname`, it was often used to join `".."` which takes us one directory up the tree. 

Why are all of these file methods relevant? Some gems or Ruby applications often use a combination of them to load the appropriate files. 

Take a look at this code (split across multiple lines for email formatting reasons) and see if you now can decipher exactly what it's doing! 

```
File.expand_path(
  File.join(
    File.dirname(__FILE__, 2), 'lib'
  )
)
```    

This week’s tip was written by [Jemma Issroff](https://twitter.com/jemmaissroff).          

Curated by [Peter Cooper](https://twitter.com/peterc), [Glenn Goodrich](https://twitter.com/ruprict) and [Cooperpress](https://cooperpress.com/). 

[Change your email address](https://rubyweekly.com/edit_subscription/*|UID|*) or[Stop getting this newsletter](https://rubyweekly.com/leave/*|UID|*) 

© Cooper Press Ltd · Fairfield Enterprise Centre, Louth, LN11 0LS, United Kingdom
