- It is not obvious what data you have access to. Your code appears to have access to the user object, but most of the data is missing.
- Similar to #1, other helpers/decorators/etc. that you have in your codebase may have model requirements that are not obvious as well. You pass along this partial object, and you may have some unintended consequences.
- If you use any kind of caching, you may accidentally expose this partial object to completely unaware parts of your app
pluck- As suggested in the article, you may be giving up some of your model niceties. Still, it is usually a worthwhile trade-off if the amount of data returned warrants optimization. It can also help expose some code that should not live directly within your model.
Struct- when using pluck gets too messy, you can always take the data returned and load it into a struct (or a PORO).
The CodingFont game is excellent, but what if you want to do a quick test drive?
Well, here you go Programming Fonts.
CodingFont is a fun bracket game that helps you pick a coding font.
I recommend checking the
Hide Font Names option.
My winner was Azeret Mono. A younger me would have picked a smaller font, but I will give this one a shot for a couple weeks.
A decent suggestion by Patel Urbanek - Easy to Miss Way to Optimize ActiveRecord SQL Memory Usage in Rails.
Urbanek recommends using
select in your ActiveRecord queries to limit the fields returned and thus save memory. While this certainly will work, I find it messy long term.
I typically use two approaches:
I have not spent any time with Hanami, but I am hoping to change that.
I like Sinatra when your goal is to respond to requests and do not need the full Rails functionality and ecosystem.
Hanami looks like it fits somewhere between the two.
We needed to find duplicate characters in multiple arrays for Saturday’s Advent of Code.
In the first part of the problem, it was among two arrays, so I did something quick like this:
This worked as expected, but in part 2, you needed to perform a similar search across three arrays.
I could have chained a second
select or duplicated the line entirely, but I figured there was a more straightforward way…and of course, in Ruby, there is almost always a more straightforward way.
I do not have a traditional comp sci background, so my mind rarely jumps to Bitwise operators, but in this case, this is the Bitwise
& operator is exactly what we needed.
@scott pointed this is not Bitwise when dealing with strings:
It is the unary and operator. On arrays, #& is a method that returns the set union of two arrays. On integers, it is indeed implemented as a bitwise and.
Even better, this easily scales across N arrays.
I have not had much use for Sizzy in while, but fired it up today and was instantly re-impressed. One of the more indispensable tools for frontend web development.
If I were deploying this somewhere, I would lean towards something that looks more like the
But for the sake of the challenge:
If this were a one-liner competition, I would like my chances. 😄