Skip to content

Instantly share code, notes, and snippets.

View aks's full-sized avatar

Alan Stebbens aks

  • Procore
  • Carlsbad, CA
  • 05:56 (UTC -07:00)
View GitHub Profile
aks / specs-for.rb
Created December 5, 2023 20:20
Ruby script to produce the spec files corresponding to the ruby file arguments.
#!/usr/bin/env ruby
# specs-for file ...
# Don't you just hate having to find the corresponding spec file for some files
# you just updated? And, you're not using Guard (for reasons)?
# pass all the files you touches as arguments into this script, and it will
# issue all the corresponding spec files.
# If you have "ag" installed, it will be used to find the files, otherwise, the
aks / exception-class-test.rb
Created October 20, 2023 19:48
Ruby script to show sub-class exceptions rescued before parent class exceptions
#!/usr/bin/env ruby
require 'awesome_print'
class Error < StandardError; end
class SpecificError < Error ; end
class Tester
raise SpecificError
aks / ar-mem-size.rb
Created June 27, 2023 00:07
ActiveRecord memory size usage (minimal and all)
#!/usr/bin/env ruby
require 'get_process_mem'
def mem_usage(label)
Process.fork do
m_before = mem_size
m_after = mem_size
$stderr.printf "%30s: delta: %+3d MB total: %5d MB\n", label, (m_after - m_before), m_after
aks /
Created June 22, 2023 22:08
# Git helpers
alias gadd='git add'
alias gci='git commit'
alias gco='git checkout'
alias gdiff='git diff'
alias gpull='git pull'
alias gpullhead='git pull origin $(git rev-parse --abbrev-ref HEAD)'
alias gphd='gpullhead'
alias gpush='git push'
aks / top-committers
Last active April 8, 2023 01:52
Bash script to show the top-committers in a repo, in descending frequency of commits
#!/usr/bin/env bash
# top-committers [NUMBER]
git log --pretty=format:"%ae %at" |
awk 'BEGIN { FS=" "; OFS="," }
!seen[$1]++ { first[$1]=$2 }
{ last[$1]=$2; count[$1]++ }
aks /
Last active February 17, 2023 00:11
Script to help manage, create, list, and cycle Rails environment credentials and their keys
#!/usr/bin/env bash
# rails-cred [show|edit|cycle|init|check|list] [env|all]
# Makes showing, editing, checking, and cycling Rails credentials
# and their secrets easier
# Copyright 2023 Alan K. Stebbens <>
aks / ruby-rescue-ordering-test-run.out
Last active December 16, 2022 19:50
Show that rescue ordering determines exception handling
❯ ./ruby-rescue-ordering-test.rb
Next? [eis] e
StandardError handler # Encoding is a subclass of StandardError
this is an encoding error
Next? [eis] i
StandardError handler # IOError is also a subclass of StandardError
this is an IO error
Next? [eis] s
ScriptError handler # ScriptError is NOT a subclass of StandardError
this is a script error
require 'awesome_print'
class Foo
def test(**kwargs)
ap kwargs
def self.tester(label, &block)
STDERR.printf "%12s: ", label
# add ssh keys
# on non-MacOS systems, comment this line out
aks / git-copy
Created June 29, 2021 04:00
Bash script to copy a file in a git repo with history preservation
#!/usr/bin/env bash
# git-copy [options] SOURCEFILE NEWFILE
usage() {
cat 1>&2 <<USAGE
usage: git-copy [options] SOURCEFILE NEWFILE
Copies a SOURCEFILE within a git repo to a NEWFILE in a way
that preserves the change history so that changes in SOURCEFILE
are still viewable in NEWFILE.