Skip to content

Instantly share code, notes, and snippets.

John Bachir jjb

Block or report user

Report or block jjb

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
jjb / gist:7389552
Last active Mar 27, 2020
Ruby 2.1 memory configuration
View gist:7389552

This all applies to Ruby 2.1. In some cases a setting is not available in 2.0, this is noted. There is also a different with 1.9, 1.8, and REE --- these are not noted.

All the relevant code is in


default: 10000

The number of heap slots to start out with. This should be set high enough so that your app has enough or almost enough memory after loading so that it doesn't have to allocate more memory on the first request (althogh this probably isn't such a big deal for most apps).

(todo: figure out how big a slot is. i think the answer can be infered from this code.)

jjb / gist:6928376
Last active Feb 13, 2020
Installing ruby on MacOS with rbenv / ruby-build using readline from macports
View gist:6928376
RUBY_CONFIGURE_OPTS="--with-readline-dir=/opt/local" rbenv install 2.2.0
# this gist previously also specified the openssl dir,
# but these days ruby-build downloads and builds its own openssl for you
jjb /
Created Feb 4, 2018
Active Record Connection Management in Rails 5.1 or lower
View check the syntax in a tree of files.rb
lines = `find . -name '*.rb'`.split("\n")
problems = []
lines.each_slice(100) do |slice|
threads = []
slice.each do |l|
threads << do
result = `ruby -c #{l}`
if "Syntax OK" == result.strip
print "."
View How to install ruby and gitsh on macOS with
sudo port selfupdate
sudo port install ruby26 # will include readline
sudo port select ruby ruby26

### >>> OPEN A NEW TERMINAL!!! <<<
### otherwise, the configuration won't point to the correct version of readline, no matter what you do.
### not sure if this is "through" the ruby binary, or something else in the environment
### i just saved you 17 hours of your life, you're welcome
View how to instrument graphql ruby with scout.rb
class GraphqlController < ApplicationController
def create
ScoutApm::Transaction.rename("Graphql/" + params["_json"].first["operationName"])
View delete all branches on a github page.js
buttons = document.getElementsByClassName("js-branch-delete-target text-red");
for(var i = 0; i < buttons.length; i++)
jjb / concat.rb
Last active Mar 8, 2019
Ruby String Interpolation vs. Concatenation performance benchmark
View concat.rb
t =
a = []
10_000_000.times do
a << "a" + " " + "b"
puts - t.to_f
View rails 5.0 vs 5.1 default primary key in

5.0, no id specified

class SerialIdTest < ActiveRecord::Migration[5.0]
  def change
    create_table "test" do |t|
      t.integer "foo_id"
      t.string "foo_role"
View how to make a handy dandy alert

alert shell function

I keep mine in .zshrc. It could probably also be a standalone script named "alert" with chmod 755 (i think?) in ~/bin

# examples:
#   git push heroku master ; alert
#   bundle install ; alert
function alert {
  if (( $? == 0 )) then
You can’t perform that action at this time.