Skip to content

Instantly share code, notes, and snippets.

@jbodah
jbodah / simple_callbacks.rb
Created March 17, 2016 17:41
simple callbacks mixin
# To use, simply define @__callbacks as a hash where the keys are events
# and the values respond to #call (e.g. lambdas, procs, methods)
#
# This implementation assumes you only have one callback per event, but
# you could use an array instead if you wanted
module SimpleCallbacks
def run_callback(type, *args)
@__callbacks[type].call(*args) if @__callbacks.has_key?(type)
end
end
@jbodah
jbodah / .rubocop.yml
Created February 29, 2016 05:53
backupify rubocop.yml
AllCops:
DisabledByDefault: true
Style/IndentationConsistency:
Enabled: true
AutoCorrect: true
Style/CommentIndentation:
Enabled: true
AutoCorrect: true
@jbodah
jbodah / pre-push
Created January 13, 2016 20:58
syntax check
##
# Run syntax checks before pushing
#
# Installation:
# 1. Copy this gist to .git/hooks/pre-push
# 2. chmod +x .git/hooks/pre-push
#
# NOTE: you can also just call `bundle exec rubocop --auto-correct` if you would rather
#! /usr/bin/env sh
@jbodah
jbodah / list_overrides.rb
Created January 7, 2016 18:48
list undocumented overrides
require 'method_source'
require 'set'
def load_environment!
load 'config/environment.rb'
end
BASE_DIR = File.expand_path('../', Dir.pwd)
pre_objects = Set.new(ObjectSpace.each_object(Module))
@jbodah
jbodah / delete_git_tags.sh
Created August 20, 2015 17:45
delete git tags
git tag -d 12345
git push origin :refs/tags/12345
@jbodah
jbodah / find-replace.sh
Created August 17, 2015 17:13
find/replace in multiple files
ag -G '(test|lib)' Backupify::Office365 -l | xargs sed -i '' 's/Backupify::Office365/Office365/g'
@jbodah
jbodah / text_on_futex.sh
Created August 6, 2015 14:32
text on futex
while true; do ps -elf |\grep -q 'futex.*assenger.*[R]ack' && curl http://textbelt.com/text -d number=$PHONE_NUMBER -d "message=FUTEX" && break || sleep 30; done
@jbodah
jbodah / assert_completed_in.rb
Created July 17, 2015 19:58
assert_completed_in
# @example
# assert_completed_in 3.seconds do
# MyJob.perform
# end
def assert_completed_in(seconds, message: nil, strategy: :timeout)
case strategy
when :timeout
begin
Timeout.timeout(seconds) { yield }
rescue Timeout::Error
class String
def black; "\033[30m#{self}\033[0m" end
def red; "\033[31m#{self}\033[0m" end
def green; "\033[32m#{self}\033[0m" end
def brown; "\033[33m#{self}\033[0m" end
def blue; "\033[34m#{self}\033[0m" end
def magenta; "\033[35m#{self}\033[0m" end
def cyan; "\033[36m#{self}\033[0m" end
def gray; "\033[37m#{self}\033[0m" end
def bg_black; "\033[40m#{self}\033[0m" end
if ENV['FG_STATS']
at_exit { require 'rubygems'; require 'pry'; binding.pry }
end
# Normal test helper code w/ Minitest
if ENV['FG_STATS']
class TestInefficiencyAnalyzer
def initialize(adapter)
case adapter