Skip to content

Instantly share code, notes, and snippets.

View nateberkopec's full-sized avatar

Nate Berkopec nateberkopec

View GitHub Profile
@nateberkopec
nateberkopec / correction.md
Last active June 6, 2025 19:24
A Simple Correction

In yesterday's post I said, in relation to "how does .present? work on ActiveRecord::Relation", I said that present? performs an existence check SELECT 1 AS one FROM ... LIMIT 1 because it calls exists? underneath. This is actually wrong - it loads the relation.

Jonathan Mast corrected me on Twitter. It turns out, I should have paid closer attention! Here is the actual implementation of blank? on ActiveRecord::Relation on Rails master:

# Returns true if relation is blank.
def blank?
  records.blank?
end
@nateberkopec
nateberkopec / 0_roadmap.md
Last active March 31, 2025 19:35
Speedshop Retainer Roadmap + Changelog

Speedshop Retainer Roadmap

This is the roadmap for the Speedshop Ruby on Rails performance retainer service. It was last updated March 28th, 2025. Items are in rough priority order.

In-Progress:

  1. Alerting and dashboard scorecards: We want everyone to be on the same footing with SLOs for queues and tracking our core set of 20 metrics, plus your app's specific key metrics (see next bullet). The output will be a scorecard page that's pass/fail on each point.
  2. Formalizing key metrics with everyone: Since we started the retainer, we learned it's helpful to have a set of 3 or fewer key metrics to monitor and improve upon over the course of the retainer. If we haven't already formalized these with you, we'll do so.
  3. Automated checks: jemalloc, YJIT, RMP, SQL comments, bcrypt version. We have a few automated checks that can be implemented just by reading your source code and doing a couple of static checks. We'll also ship some detailed guides for
@nateberkopec
nateberkopec / changelog.md
Last active March 28, 2025 03:37
Speedshop Retainer Changelog

Speedshop Retainer Changelog

This is the changelog for the Speedshop Ruby on Rails performance retainer service. For what we're doing in the future, see the roadmap. This was last updated March 28th, 2025.

March 2025

  1. Office Hours. You can now sign up for regular office hours, 30 minutes every 2 weeks.
  2. Retainer Roadmap and Changelog. We're working on more services and extensions to the retainer service. You can keep up with stuff yet to come in the Roadmap, and stuff done already in the Changelog.
  3. Free Ongoing Education/Workshops. We started a book club for The Rails Performance Apocrypha.
@nateberkopec
nateberkopec / gcstat.md
Created March 8, 2017 18:25
A Guide to GC.stat

Most Ruby programmers don't have any idea how garbage collection works in their runtime - what triggers it, how often it runs, and what is garbage collected and what isn't. That's not entirely a bad thing - garbage collection in dynamic languages like Ruby is usually pretty complex, and Ruby programmers are better off just focusing on writing code that matters for their users.

But, occasionally, you get bitten by GC - either it's running too often or not enough, or your process is using tons of memory but you don't know why. Or maybe you're just curious about how GC works!

One way we can learn a bit about garbage collection in CRuby (that is, the standard Ruby runtime, written in C) is to look at the built-in GC module. If you haven't read the docs of this module, check it out. There's a lot of interesting methods in there. But for right now, we're just going to look at one: GC.stat.

GC.stat outputs a hash with a bunch of different numbers, but none of th

@nateberkopec
nateberkopec / 0.result.md
Last active January 18, 2024 11:20 — forked from tomfuertes/0.result.md
De-'Async Inject'ing Universal Analytics

De-'Async Inject' Universal Analytics

This gist applies the theory from Ilya Grigorik's Script-injected "async scripts" considered harmful on the default Universal Analytics snippet. TLDR place this above the CSS in the <head> of your document

<!-- Google Analytics Part 1: Creates window.ga, sets account, and queues pageview-->
<script>
  !function(n,t){n.GoogleAnalyticsObject=t,n[t]=n[t]||function(){(n[t].q=n[t].q||[]).push(arguments)},n[t].l=1*new Date}(window,"ga");
  ga('create', 'UA-XXXX-Y', 'auto'); // REPLACE UA-XXXX-Y w/ YOUR ACCOUNT
 ga('send', 'pageview');
@nateberkopec
nateberkopec / homebridge.hcl
Created March 28, 2021 01:06
Pihole and homekit HCLs for Nomad
job "homebridge" {
datacenters = ["dc1"]
group "server" {
network {
port "http" {
to = 8581
}
}
@nateberkopec
nateberkopec / gist:11dbcf0ee7f2c08450ea
Last active March 24, 2023 21:59
RubySpec is dead, long live RubySpec!

Last night, Brian Shirai unilaterally "ended" the RubySpec project, a sub-project of Rubinius (the alternative Ruby implementation which Brian was paid to work on full-time from 2007 to 2013). The blog post describing his reasons for "ending" the project led to a big discussion on Hacker News.

When a single, competing Ruby implementation tells that you its test suite is the One True Way, you should be skeptical. Charles Nutter, Ruby core committer and JRuby head honcho, spent a lot of time last night on Twitter talking to people about what this decision means. He's probably too busy and certainly too nice of a guy to write about what is a political issue in the Ruby community, so I'm going to do it on behalf of all the new or intermediate Rubyists out there that are confused by Brian's decision and what it me

@nateberkopec
nateberkopec / Gemfile
Last active March 17, 2022 08:21
ActionCable isn't *really* a Rails 5 dependency.
# gem 'rails'
gem "activerecord"
gem "actionpack"
gem "actionview"
gem "actionmailer"
gem "activejob"
gem "activesupport"
gem "railties"
gem "sprockets-rails"
gem 'sqlite3'
/nix/store/9j0c1bk7rq7fkc7bcf4q25wk6rjm1z3d-gnumake-4.3/bin/make install target_prefix=
/nix/store/1qw1shw2a163h45rhr5pay488nbzfi6y-coreutils-9.0/bin/install -c -m 0755 puma_http11.so /host/nateberkopec/Documents/Code/upstream/puma/lib/puma
cp tmp/aarch64-linux/puma_http11/3.0.2/puma_http11.so tmp/aarch64-linux/stage/lib/puma/puma_http11.so
/host/nateberkopec/Documents/Code/upstream/puma/test/test_config.rb:70: warning: assigned but unused variable - bind_configuration
/host/nateberkopec/Documents/Code/upstream/puma/test/test_config.rb:71: warning: assigned but unused variable - app
ruby 3.0.2p107 (2021-07-07) [aarch64-linux]
RUBYOPT: -r/nix/store/6jdmjqw9m3n3n76z5dsig3d4anh091fm-ruby-3.0.2/lib/ruby/3.0.0/bundler/setup
Puma::MiniSSL OpenSSL
OPENSSL_LIBRARY_VERSION: OpenSSL 1.1.1l 24 Aug 2021 OpenSSL 1.1.1l 24 Aug 2021
@nateberkopec
nateberkopec / git-autocomplete.sh
Created October 3, 2019 16:32
git auto completion
cd ~
wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
mv git-completion.bash .git-completion.bash
source ~/.git-completion.bash
echo "source ~/.git-completion.bash" >> ~/.bash_profile