Skip to content

Instantly share code, notes, and snippets.

jjb /
Last active Jan 22, 2022
single-line process restarter without systemd

example program being monitored -

while [ 1 ]
  sleep 1
  echo hello
jjb / code.rb
Last active Nov 12, 2021
Use ruby to test if a port is available on a host, similar to telnet foo 123
View code.rb
require 'socket'
Socket.tcp("", 443, connect_timeout: 1).close
jjb / code.rb
Created Nov 2, 2021
How to work with raw compressed cache data in Rails
View code.rb
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 /
Last active Oct 15, 2021
How to start, stop, or restart postgres installed with macports
sudo port unload postgresql12-server
sudo port load postgresql12-server
jjb /
Created Sep 29, 2021
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 /
Created Sep 11, 2021
Exploring the default behavior for signals in ruby

Ruby doesn't let you inherit default behavior when writing a signal trap

Here's a beginning of an exploration of what default behavior is for each signal:

reserved = %w[SEGV BUS ILL FPE VTALRM]
reserved += %w[KILL STOP] # not listed in code but reserved via some other mechanism i was too lazy to find

Signal.list.keys.each do |signal|
jjb / gist:979da7562e3b46ea456bbe38e350cc72
Created Jul 12, 2021
Blocking Outbrain and Taboola in /etc/hosts
View gist:979da7562e3b46ea456bbe38e350cc72
jjb /
Last active Feb 7, 2022
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
View How to install mimemagic >= 0.3.7 with
sudo port selfupdate
sudo port install shared-mime-info
sudo mkdir -p /usr/local/share/mime/packages/
sudo ln -s /opt/local/share/mime/packages/ /usr/local/share/mime/packages
# minimal test to see if it's working - if it is, now include in Gemfile like normal
gem install mimemagic -v '0.3.7' --source ''
View How to list all currently open files in ruby.rb
ObjectSpace.each_object(File) do |f|
unless f.closed?
printf "%s: %d\n", f.path, f.fileno