Skip to content

Instantly share code, notes, and snippets.

@jjb
jjb / code.md
Last active Jan 22, 2022
single-line process restarter without systemd
View code.md

example program being monitored - sleep.sh

while [ 1 ]
do
  sleep 1
  echo hello
done
@jjb
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("example.com", 443, connect_timeout: 1).close
@jjb
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
jjb / file.md
Last active Oct 15, 2021
How to start, stop, or restart postgres installed with macports
View file.md
sudo port unload postgresql12-server
sudo port load postgresql12-server
@jjb
jjb / code.sh
Created Sep 29, 2021
How to stop and start Postgres installed from Macports on MacOS
View code.sh
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
Created Sep 11, 2021
Exploring the default behavior for signals in ruby
View file.md

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:

# https://github.com/ruby/ruby/blob/master/signal.c#L1331-L1358
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
jjb / gist:979da7562e3b46ea456bbe38e350cc72
Created Jul 12, 2021
Blocking Outbrain and Taboola in /etc/hosts
View gist:979da7562e3b46ea456bbe38e350cc72
127.0.0.1 paid.outbrain.com traffic.outbrain.com www.outbrain.com outbrain.com vrt.outbrain.com amplify.outbrain.com outbrainimg.com widgets.outbrain.com taboola.com
@jjb
jjb / file.sh
Last active Feb 7, 2022
How to build a Dockerfile and open a shell in it
View file.sh
# "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 macports.sh
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/freedesktop.org.xml /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 'https://rubygems.org/'
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
end
end