Skip to content

Instantly share code, notes, and snippets.

@jjb
jjb / gist:6928376
Last active May 6, 2022 20:33
Installing ruby on MacOS with rbenv / ruby-build using readline from macports
sudo port -v selfupdate
sudo port install rbenv
sudo port install ruby-build
sudo port install readline
RUBY_CONFIGURE_OPTS="--with-readline-dir=/opt/local" rbenv install 2.7.1
# this gist previously also specified the openssl dir,
# but these days ruby-build downloads and builds its own openssl for you
# --with-openssl-dir=/opt/local
@jjb
jjb / gist:996510
Created May 28, 2011 02:00
How to set the certificate file for Net::HTTP library-wide

In my previous post I described how to securely acquire the Mozilla list of root certificates and convert them to a form usable by curl and various libraries which don't ship with them.

Next, I want to point Net:HTTP at this file library-wide, so that it is used by all invocations of methods accessing https resources (in particular, Kernel#open, which in ruby 1.8.7 does not have a ca_file option and is therefore unusable with https). I hunted around the ruby standard library for a couple hours and came up with this:

require 'open-uri'
require 'net/https'

module Net
 class HTTP
@jjb
jjb / file.md
Created February 4, 2018 16:27
Active Record Connection Management in Rails 5.1 or lower
@jjb
jjb / file.sh
Last active February 7, 2022 07:04
How to build a Dockerfile and open a shell in it
# "foo" is not a placeholder, it's a name that needs to be given
# this exact command will work if a Dockerfile is present
docker build -t foo . && docker run -it foo
# if you want to force creation of an amd64 image when on an M1/arm64 Mac
docker build --platform linux/amd64 -t foo . && docker run -it foo
# if your container doesn't have a shell as an entrypoint
# e.g. node:@latest
docker build --platform linux/amd64 -t foo . && docker run -it --entrypoint bash foo
@jjb
jjb / code.md
Last active January 22, 2022 01:26
single-line process restarter without systemd

example program being monitored - sleep.sh

while [ 1 ]
do
  sleep 1
  echo hello
done
@jjb
jjb / code.rb
Last active November 12, 2021 14:10
Use ruby to test if a port is available on a host, similar to telnet foo 123
require 'socket'
Socket.tcp("example.com", 443, connect_timeout: 1).close
@jjb
jjb / code.rb
Created November 2, 2021 00:36
How to work with raw compressed cache data in Rails
raw = Rails.cache.redis.get( Rails.cache.redis.keys.first)
Marshal.load raw
Marshal.load(raw).instance_variable_get :@value
Zlib::Inflate.inflate Marshal.load(raw).instance_variable_get :@value
Marshal.load Zlib::Inflate.inflate Marshal.load(raw).instance_variable_get :@value
@jjb
jjb / file.md
Last active October 15, 2021 18:25
How to start, stop, or restart postgres installed with macports
sudo port unload postgresql12-server
sudo port load postgresql12-server
@jjb
jjb / code.sh
Created September 29, 2021 10:33
How to stop and start Postgres installed from Macports on MacOS
sudo -u postgres pg_ctl -D /opt/local/var/db/postgresql12/defaultdb stop
sudo -u postgres pg_ctl -D /opt/local/var/db/postgresql12/defaultdb start
@jjb
jjb / file.md
Last active September 13, 2021 17:46
Trying to figure out performance impact of RUBY_GC_HEAP_GROWTH_FACTOR