Today I Learned ~D[2025-12-19]

When I work in Ruby, I really miss the pattern matching of Elixir. Today I discovered a few restructuring tricks for hashes that recreate some of that pattern matching goodness from Elixir. The TLDR is that you can use forward assignment.

options = {one: 1, two: 2, optional: false}
# then later 
options => {one:, two:, optional:}

$> one
1
$> optional
false

Note the => rightward operator, aka Ruby’s old friend the hashrocket, this is called forward assignment. You can make the above more robust with a rescue clause:

options => {one:, two:, optional:} rescue nil 

In the event that somebody passes in an options hash like {one: 1, two: 2} this will prevent things from blowing up. When destructuring Ruby will return nil for optional.

Looking through my zsh configs today, all sorts of hidden and forgotten gems. Notably clobberass for recompiling Rails assets: alias clobberass="rails assets:clobber && rails tmp:clear && rails assets:precompile"

You would think the name would have made this unforgettable!

Rails: Monkey patching TimeZone logic

I’ve been working with a third party API to import some data, but only if one of the fields effective_date is today or in the past. So with

[ {
    data: {...},
    effective_date: now
  },
  {
    data: {...},
    effective_date: tomorrow
   }
]

the first record will be imported while the second record will be skipped. This is fairly easy to write a spec for, but for a project manager, or a tester who is manually doing experience testing it’s kind of hard to know if the record with an effective date tomorrow is going to import when tomorrow comes.

I’m sure there are libraries for this and strategies but I put together a little monkey patch for this scenario:

module ActiveSupport
	class TimeZone
		def now 
			Time.now + 1.day
		end 
	end 
end

I sent that over to the PM with instructions on where to put it (essentially, anywhere). Now, I realize this is not a good idea, and will likely mess up all kinds of stuff in Rails but for a one off test it worked perfectly and is still faster than signing into the service (which we may or may not have access to) and updating the effective_date.

Every year I get pumped for Advent of Code. Then however long the first day or two takes me I start to think of all the other things I could/should be doing with my time and it peters from there. Sigh, I love the idea of it, maybe sometime I’ll take a sabbatical in December and dedicate myself to it.

My wife and I have started painting our Christmas cards. I’m a big fan of Owen Pomery’s style, it kind of reminds me of Hergé. I copied this from Victory Point

I was telling my wife about the raccoon who broke into a liquor store, got drunk, then passed out in the bathroom. She said, “Sounds like an American racoon”, I guess he truly was living the American Dream.

If your worried, they sobered him up in the drunk tank and released him safely into the wild a few hours later.

No More Tears

Finished reading: No More Tears: The Dark Secrets of Johnson & Johnson by Gardiner Harris 📚

I love a good expose on unchecked corporate greed. I’d say I’m not surprised because there are no depths to which unchecked capitalism won’t sink to but there were a few takeaways in this book that shocked me:

  1. J&J was conducting tests on black prisoners up to at least 1971, that’s nearly 30 years after the Nuremberg Trails!
  2. I was breathing in asbestos anytime I used J&J baby powder. Years ago I heard that talc was not good for the lungs, but I didn’t realize that all talc has trace amounts of asbestos due to their similar chemical makeup and co-location.
  3. J&J actively sold unapproved drugs in the optimistic hope that the FDA would approve them and thereby give a retroactive taciturn approval.
  4. Although Purdue and the Sackler family are the public face of the opioid epidemic; J&J has, outsold Purdue with subsequent opioids running the same marketing playbook that “this time it’s not addictive!” Not only that, but all the opium Purdue used to manufacture their opioids was supplied by… J&J.

My daughter really wanted to watch “A Charlie Brown Christmas” for our November movie night, you can’t rent it you have to subscribe to Apple TV to get it. This gives me at least 1 month to binge all the Apple shows people talk about. We are working our way through Severance.