-
The REPL: Issue 88 - December 2021
Programmers Should Stop Celebrating Incompetence
DHH is well known for kicking up a storm. I don’t always agree with him. In this case, I do. We can strive for competence and embrace newcomers to programming. Software challenge us to learn new things all the time, but that doesn’t mean that we don’t know anything.
Against my better judgement to never look at the comment section, I glanced at some of the reaction on Twitter. A lot of the objections seem to be saying “Stop telling people they can’t look up things on the internet”. Example:
You must have everything you need to know to do your job memorized You know, like doctors and lawyers and mechanical engineers Riiiight
DHH didn’t say any of that. He said that you should be working to improve your knowledge in the areas that you choose, and not pretend like no one knows anything.
Be Curious, Not Judgmental
It is tempting to trash others work and belittle it. It can make us feel bigger, smarter, better. It is not conducive to learning and deep insight. If instead we adopt a curios mindset, the results can be quite different. The post illustrates the point well.
How to rest well
This post by Alex Soojung-Kim Pang reinforces my belief that rest is a competitive advantage. Being well-rested improves cognition. Downtime, and time for hobbies is important and should be prioritized. “All work” is a terrible mindset.
-
Gotcha using Oj to generate JSON
Oj is a Ruby gem that bills itself as a faster way to generate JSON, mainly through the use of a C extension. I recently found it was generating unexpected results.
I was looking through a report that one of our endpoints was generating unusually large JSON payloads. In particular, timestamps where being serialized to a very verbose (and not very useful format):
{ "created_at": { "^o": "ActiveSupport::TimeWithZone", "utc": { "^t": 1639339673.031328000 }, "time": null, "time_zone": { "^o": "ActiveSupport::TimeZone", "name": "UTC", "utc_offset": null, "tzinfo": { "^o": "TZInfo::DataTimezone", "info": { "^o": "TZInfo::ZoneinfoTimezoneInfo", "identifier": "Etc/UTC", "offsets": { "^#1": [0, { "^o": "TZInfo::TimezoneOffset", "utc_offset": 0, "std_offset": 0, "abbreviation": ":UTC", "utc_total_offset": 0 }] }, "transitions": [], "previous_offset": { "^o": "TZInfo::TimezoneOffset", "utc_offset": 0, "std_offset": 0, "abbreviation": ":UTC", "utc_total_offset": 0 }, "transitions_index": null } } }, "period": null } }
I quickly saw that the controller was invoking
Oj
directly, and that is the root of the problem. The library has a Rails compatibility mode, that is not the default:ts = Time.zone.now ts.to_json # => "\"2021-12-12T20:10:56Z\"" Oj.dump(ts) # => "{\"^o\":\"ActiveSupport::TimeWithZone\",\"utc\":{\"^t\":1639339856.001998000},\"time\":{\"^t\":1639339856.001998000},\"time_zone\":{\"^o\":\"ActiveSupport::TimeZone\",\"name\":\"UTC\",\"utc_offset\":null,\"tzinfo\":{\"^o\":\"TZInfo::DataTimezone\",\"info\":{\"^o\":\"TZInfo::ZoneinfoTimezoneInfo\",\"identifier\":\"Etc/UTC\",\"offsets\":{\"^#1\":[0,{\"^o\":\"TZInfo::TimezoneOffset\",\"utc_offset\":0,\"std_offset\":0,\"abbreviation\":\":UTC\",\"utc_total_offset\":0}]},\"transitions\":[],\"previous_offset\":{\"^o\":\"TZInfo::TimezoneOffset\",\"utc_offset\":0,\"std_offset\":0,\"abbreviation\":\":UTC\",\"utc_total_offset\":0},\"transitions_index\":null}}},\"period\":{\"^o\":\"TZInfo::TimezonePeriod\",\"start_transition\":null,\"end_transition\":null,\"offset\":{\"^o\":\"TZInfo::TimezoneOffset\",\"utc_offset\":0,\"std_offset\":0,\"abbreviation\":\":UTC\",\"utc_total_offset\":0},\"utc_total_offset_rational\":null}}" Oj.dump(ts, mode: :rails) # => "\"2021-12-12T20:10:56Z\""
Adding
mode: :rails
to theOj
call fixed the unexpected payload size issue.The fact that we had a production endpoint generating unexpected JSON for months lets me know two things:
- There is no test coverage that checks the generated JSON against a known schema
- Consumers of this internal endpoint have no use for the timestamps that were being sent down: There is no code that recognizes that data structure.
-
The REPL: Issue 87 - November 2021
A terrible schema from a clueless programmer
A very experienced engineer tells a story about a horrible database design. The kicker is that the terrible design was hers, when she was younger and didn’t know any better.
We’ve all been there. This is how we learn. Especially when a lot of software engineers don’t have the opportunity to be mentored and guided by more experienced engineers.
RegexLearn
This is a step-by-step tutorial for learning regular expressions. Well explained, plenty of examples and feels like a smooth on-ramp to regex.
The History of Command Palettes: How Typing Commands Became The Norm Again
So much this: Typing commands is better than clicking your mouse. Command palettes help with discoverability.
In fact, one of my “must-have” Alfred extensions is Menu Bar Search. It adds the command-p behavior to any program, by searching the text of all the menus (using accessibility access). I use it a lot, in all sorts of programs that don’t include such functionality natively (e.g. Quickbooks, Firefox).
One thing not mentioned is that a shell typically also stores history, which helps you discover commands you’ve already typed before. I use my history all the time and use a fuzzy finder to search through it.
-
Conditionally setting your gitconfig, or not
In Conditionally setting your gitconfig, Marcus Crane solves a problem that many of us have: Different
git
configuration for personal and work projects. His solution includes adding conditional configuration, like so:[includeIf "gitdir:~/work/"] path = ~/.work.gitconfig
I’ve been taking a different approach. According to the git-scm configuration page,
git
looks for system configuration first, the the user’s personal configuration (~/.gitconfig
or~/.config/git/config
), and then the project’s specific configuration.In my personal configuration, I typically set my name, but don’t set my email.
[user] name = Ylan Segal
On first interaction with a repository,
git
makes it evident that an email is needed:$ git commit Author identity unknown *** Please tell me who you are. Run git config --global user.email "you@example.com" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: no email was given and auto-detection is disabled
I then use
git config user.email "ylan@...."
to set a project-specific email. I don’t use the--global
option. I want to make that choice each time I start interacting with a new repo.As they say, there are many ways to skin a cat.
-
The REPL: Issue 86 - October 2021
Bitcoin is a Ponzi
I’ve been thinking about this a lot: Bitcoin (and other crypto) seem like a Ponzi scheme. Is it? Jorge Stolfi make the argument that it is, and I find it compelling.
Understanding How Facebook Disappeared from the Internet
Interesting explanation of how BGP and DNS work, and how it it possible for a company like Facebook disappeared completely off the internet, and what it looked like for Cloudflare, one of the biggest content-delivery networks on the internet.
We Tried Baseball and It Didn’t Work
An allegory? Sarcasm? Humorous pastiche? You decide.
I call it satire. Like most funny ones, it resonates because it has a kernel of truth, exaggerated to absurdity. Squarely aimed at those that criticize Agile, TDD, or any other discipline without actually understanding it.