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 February 14, 2024 16:22
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.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 / 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 / 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
@nateberkopec
nateberkopec / repro_script.rb
Created August 14, 2017 15:51
Sentry repro script for rails
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
as scraped by @cjlarose
5.0.0 - Spoony Bard
4.3.0 - Mysterious Traveller
4.2.0 - Distant Airhorns
4.1.0 - Fourth and One
4.0.0 - 4 Fast 4 Furious
3.12.0 - Llamas in Pajamas
3.11.0 - Love Song
3.10.0 - Russell's Teapot