Skip to content

Instantly share code, notes, and snippets.

Avatar

John Bachir jjb

View GitHub Profile
View dns.rb
#!/usr/bin/ruby
# save in ~/bin/dns and chmod 755
unless ARGV[0]
print `networksetup -getdnsservers Wi-Fi`
exit
end
servers = case ARGV[0]
View Safely setting NOT NULL on a column in Postgres 12+.md

This recipe is a work in progress and has never been run as-is.

  • timeouts are in ms
  • lock timeout: in postgres, when a statement that wants a restrictive lock waits on another lock, other statements that want locks can't jump the queue. so even though the statement that is waiting might only take a very short amount of time, when it starts running, while it is waiting no other statements can begin. So we set the lock timeout pretty low and retry if we don't get it.
  • statement timeout: we set a short statement timeout before statements which do lock and which we expect to take a short amount of time, just in case something about our assumptions/understanding is wrong and the statement ends up taking a long time. if this happens the statement will bail early without causing harm, and we can investigate what is wrong with
@jjb
jjb / 1update.md
Last active May 8, 2020
How to install ruby 1.9.3 on OS X with macports
View How to deal with ruby and postgres segmentation fault on MacOS when using macports or homebrew.md

Here's something I spent a long time debugging, so I'm making this gist to help others find the solution when searching.

Summary

postgres 12 on MacOS will cause crashes when forking. The solution is to do one of these two things:

  • add gssencmode: "disable" to database.yml
  • if using homebrew: uninstall postgres, update homebrew, reinstall postgres

Here's some discussion:

View How to install ruby and gitsh on macOS with macports.sh
sudo port selfupdate
sudo port install ruby27 # will include readline
sudo port select ruby ruby27
### >>> 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
curl -OL https://github.com/thoughtbot/gitsh/releases/download/v0.14/gitsh-0.14.tar.gz
View gist:d65bc10bb55fed7e4cafb07be035c10a
test results for https://github.com/puma/puma/pull/2228
run 1 - nothing
273.3 MB
27.4 MB
27.3 MB
27.3 MB
27.3 MB
27.3 MB
@jjb
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 https://github.com/ruby/ruby/blob/master/gc.c

RUBY_HEAP_MIN_SLOTS

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
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
jjb / file.md
Created Feb 4, 2018
Active Record Connection Management in Rails 5.1 or lower
View file.md
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 << Thread.new do
result = `ruby -c #{l}`
if "Syntax OK" == result.strip
print "."
You can’t perform that action at this time.