Skip to content

Instantly share code, notes, and snippets.

@jjb
jjb / code.rb
Last active September 23, 2024 23:59
Script to delete old git branches
require 'time'
branches = `git for-each-ref --format '%(refname:short) %(committerdate)' refs/heads/`
months_ago = 12
threshold = Time.now - (months_ago * 30 * 24 * 60 * 60)
branches_to_delete = {}
branches.each_line do |line|
@jjb
jjb / colors.md
Created June 27, 2024 19:17
Monokai Pro Colors
  • #2c292d $\textcolor{#2c292d}{\texttt{█ black}}$
  • #fdf9f3 $\textcolor{#fdf9f3}{\texttt{█ white}}$
  • #ff6188 $\textcolor{#ff6188}{\texttt{█ red}}$
  • #fc9867 $\textcolor{#fc9867}{\texttt{█ orange}}$
  • #ffd866 $\textcolor{#ffd866}{\texttt{█ yellow}}$
  • #a9dc76 $\textcolor{#a9dc76}{\texttt{█ green}}$
  • #78dce8 $\textcolor{#78dce8}{\texttt{█ blue}}$
  • #ab9df2 $\textcolor{#ab9df2}{\texttt{█ purple}}$

@jjb
jjb / .gitconfig
Last active July 8, 2024 01:12
Git log and stash log aliases with colors and other enhancements
[alias]
l = log --pretty=format:'%C("#ff6188")%h%Creset -%C("#ffd866")%d%Creset %C("#a9dc76")(%cr)%Creset %C("#78dce8")<%an>%Creset%n%s%n%n%b' --abbrev-commit --date=relative
sl = stash list --pretty=format:'%C("#ff6188")%h%Creset -%C("#ffd866")%d%Creset %C("#a9dc76")(%cr)%Creset %C("#78dce8")<%an>%Creset%n%s%n%n%b' --abbrev-commit --date=relative
# colors from: https://gist.github.com/jjb/366bed1d5f099a42f0da0f64b5b52798
@jjb
jjb / install.sh
Created April 25, 2024 04:15
Installing psych gem with macports
sudo port install libyaml yaml-cpp
bundle config build.psych --with-opt-include=/opt/local/include --with-opt-lib=/opt/local/lib
bundle
# OR, standalone
gem install psych -- --with-opt-include=/opt/local/include --with-opt-lib=/opt/local/lib
@jjb
jjb / code.rb
Created April 18, 2024 00:40
Hacking ruby patterns to be first-class objects that can be passed around
# need to "pin" the variable, but this only works with the lambda because
# pattern matching falls back to case matchint (=== on any object in ruby,
# which is NOT "identical object" as in JS)
def matches1(pat,x)
case x
in ^pat
puts true
else
puts false
end
@jjb
jjb / .gitconfig
Created February 6, 2024 16:36
git cleanup
[alias]
delete-squashed = "!f() { local targetBranch=${1:-master} && git checkout -q $targetBranch && git branch --merged | grep -v \"\\*\" | xargs -n 1 git branch -d && git for-each-ref refs/heads/ \"--format=%(refname:short)\" | while read branch; do mergeBase=$(git merge-base $targetBranch $branch) && [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == \"-\"* ]] && git branch -D $branch; done; }; f"
@jjb
jjb / file.md
Created January 26, 2024 00:35
trying to get github markdown note highlight things to work in indents

Note

here is some important info

  1. item 1

    [!NOTE] here is some important info

  2. item 2
@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 / 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