Skip to content

Instantly share code, notes, and snippets.

@jjb
jjb / code.rb
Created October 4, 2023 16:28
How to set sidekiq options for ActionMailer / ActiveJob / MailDeliveryJob
# in default config, ActionMailer will use sidekiq wrapped in ActiveJob
# This makes it so there is no obvious/direct place to specify configuration
# It's easy to do with the below method, which can be placed in an initializer
Rails.application.config.after_initialize do
ActionMailer::MailDeliveryJob.class_eval do
sidekiq_options retry: 2
end
end
@jjb
jjb / code.rb
Created September 26, 2023 18:09
benchmark ruby rand vs rand(100)
require 'benchmark/ips'
require "benchmark/memory"
Benchmark.ips do |x|
x.report("rand") do
rand
end
x.report("rand(100)") do
rand(100)
@jjb
jjb / gist:2347804
Created April 10, 2012 01:30
How to build the pg gem on os x with macports

First, install your preferred version of postgres

sudo port install posgresql84

Now you have psql84 available, which rolls right off your fingers. Even better, your pg_config is buried in a postgresql84 namespace. Fix both of these with:

sudo port select --set postgresql postgresql84

Now you can intall the gem

@jjb
jjb / shipyard-shell.sh
Created June 22, 2023 17:48
Shipyard Shell
#!/usr/bin/env sh
# usage
# shipyard-shell PRNUMBER SERVICENAME
# shipyard-shell 6187 postgres
# shipyard-shell 6187 api
pr=$1
service=$2
identifier=`shipyard get environments | grep pr$pr | xargs | cut -w -f1` # xargs to remove leading and trailing whitespace
@jjb
jjb / apt-file.sh
Last active June 13, 2023 17:41
The equivalent of redhat/centos yum whatprovides for debian/ubuntu
apt update
apt install -y apt-file
apt-file update
apt-file find psql
apt-file find bin/psql
apt-file find postgresql.conf
apt-file find --fixed-string convert # equivalent of .*convert.*, way too much
apt-file find --fixed-string /usr/bin/convert # need to know exact path
apt-file find --regexp '.*bin/convert$' # bingo. would also pick up .../sbin/
@jjb
jjb / file.rb
Created May 13, 2023 01:36
in MacOS, temporarily set the clipboard to something, and then set it back, using ruby
old=`pbpaste`
`echo '#{ENV['THE_TEXT']}' | pbcopy`
3.downto(0) do |second|
`osascript -e 'display notification "Reseting clipboard in #{second} seconds" with title "TMP Clipboard"'`
sleep 1
end
`echo '#{old}' | pbcopy`
@jjb
jjb / 1 intro.md
Last active March 7, 2023 05:15
wrapper script for starting ruby with configured jemalloc 5.md
@jjb
jjb / file.md
Created September 25, 2022 02:44
markdown indentation demo
  1. hello
  2. hello
    1. nested
    2. nested
      1. more
      2. more
        1. and again
          puts "hello"
@jjb
jjb / gist:7175694
Last active September 24, 2022 20:54
How to configure Textmate to use the rbenv ruby and gems
  1. Preferences -> Variables
  2. add this to the front of PATH: $HOME/.rbenv/bin:$HOME/.rbenv/shims:
  3. set TM_RUBY to this: $HOME/.rbenv/shims/ruby
  4. populate RBENV_VERSION with your version. example: 2.1.0-preview1
  5. (and make sure the checkboxes for each of those variables is selected)
  • runner does not use executor in <7, does use it in >=7
  • console does not use executor in <7, not sure about >=7