Skip to content

Instantly share code, notes, and snippets.

@jbodah
jbodah / rails_file_diff.rb
Last active August 29, 2015 14:04
One-liner to get a diff between two strings and write it to a file
require 'diffy'; File.open(Rails.root.join('diff'), 'w') {|f| f.write Diffy::Diff.new event_json, expected_json}
@jbodah
jbodah / bypass_rails_routing.rb
Created August 6, 2014 18:10
Bypassing Rails routing
should 'support custom read only mode handler methods' do
controller = CustomReadOnlyHandlerTestController.new
controller.params = HashWithIndifferentAccess.new
controller.request = ActionController::TestRequest.new
controller.response = ActionController::TestResponse.new
controller.expects(:my_read_only_handler).at_least_once
controller.process :foo
end
@jbodah
jbodah / rails_test_routes.rb
Created August 6, 2014 18:13
Dynamically add controller routes
setup do
# Setup a route for our fake controller
Rails.application.routes.draw do
get "/readonlymodetest/foo" => "DOMAIN/read_only_mode_test#foo"
get "/readonlymodetest/foo_with_write" => "DOMAIN/read_only_mode_test#foo_with_write"
root :to => 'pages#show', :id => 'home'
end
end
@jbodah
jbodah / Guardfile
Last active August 29, 2015 14:07
my guardfile
# require 'guard/plugin'
#
# module ::Guard
# class BackupifyTest < ::Guard::Plugin
# def run_all
# end
#
# def run_on_changes(paths)
# paths.each do |path|
# raise :task_has_failed unless system "ruby -Itest #{path}"
@jbodah
jbodah / rubocop.yml
Created October 16, 2014 20:39
my rubocop.yml
# Inherits everything else from defaul Rubocop config
Metrics/LineLength:
Max: 100
Style/SpaceBeforeBlockBraces:
Enabled: false
Style/SpaceInsideBlockBraces:
Enabled: false
@jbodah
jbodah / base_wrapper_exception.rb
Created October 20, 2014 23:20
Ruby exception wrapping
# A generic error that implementations can use to wrap their exceptions with
class BaseWrapperException < StandardError
def initialize(e = nil)
super e
return self unless e.present? && e.is_a?(Exception)
# Preserve the original exception's data
set_backtrace e.backtrace
message.prepend "#{e.class}: "
end
end
@jbodah
jbodah / kill_pg_listeners
Last active August 29, 2015 14:07
kill all postgres listeners
ps xa | grep postgres: | grep "backupify_development" | grep -v grep | awk '{print $1}' | xargs kill
@jbodah
jbodah / pidfile kill
Created October 22, 2014 17:31
kill from pid file
kill $(cat tmp/pids/server.pid)
@jbodah
jbodah / gist:2811d7d8f5ba1f15fcb9
Created October 22, 2014 22:14
ruby ctags gen
ctags -R --languages=ruby --exclude=.git --exclude=log . $(bundle list --paths)
@jbodah
jbodah / gist:2dd6e0e6dd5e1b7b5f94
Created October 23, 2014 19:02
recursive subdirectory grep
# grep all files in this directory (and subdirectories) that end in .rb and contain 'guests = self.guests'
grep -r 'guests = self.guests' . --include \*.rb