This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# show how class methods can be wrapped to intercept and manage their return values without code changes in their clients. | |
class MyClass | |
class << self | |
def method_one | |
"result from method one" | |
end | |
def method_two | |
"result from method two" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'awesome_print' | |
class Error < StandardError; end | |
class SpecificError < Error ; end | |
class Tester | |
def self.run | |
raise SpecificError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'get_process_mem' | |
def mem_usage(label) | |
Process.fork do | |
m_before = mem_size | |
yield | |
m_after = mem_size | |
$stderr.printf "%30s: delta: %+3d MB total: %5d MB\n", label, (m_after - m_before), m_after |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# top-committers [NUMBER] | |
count=${1:-200} | |
git log --pretty=format:"%ae %at" | | |
awk 'BEGIN { FS=" "; OFS="," } | |
!seen[$1]++ { first[$1]=$2 } | |
{ last[$1]=$2; count[$1]++ } | |
END { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 <[email protected]> | |
PROG="${0##*/}" | |
DIR="${0%/*}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
❯ ./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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'awesome_print' | |
class Foo | |
def test(**kwargs) | |
ap kwargs | |
end | |
def self.tester(label, &block) | |
STDERR.printf "%12s: ", label | |
begin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# add ssh keys | |
PROG=${0##*/} | |
KEY_DIR=~/.ssh | |
PUB_SFX='.pub' | |
# on non-MacOS systems, comment this line out |
NewerOlder