TIL;

Interesting stuff I find along the way.

How to include all files in a folder in .gitignore except a few

I was wondering how to do this, when I saw that the .gitignore file autogenerated by Rails already does it:
/log/*
!/log/.keep
With that we are ignoring all files in the log folder except the .keep file.

A better way to loop from a number to a lower number in Ruby

I wanted to iterate from a higher number (hi) to a lower number (lo), passing a block.
First I tried:
(lo..hi).to_a.reverse.each { |n| puts n }
But then I noticed the downto method
hi.downto(lo) { |n| puts n }
🙂
Of course, there is also the related upto method.

A fast way to check if Rails ActionMailer is sending emails

To check if our mail sending configuration in Rails is configured properly, just fire up a Rails console and paste the following snippet:
ActionMailer::Base.mail(
  from: "[email protected]",
  to: "[email protected]",
  subject: "Test",
  body: "Test"
).deliver_now