Skip to content

Instantly share code, notes, and snippets.

@ariera
ariera / README.markdown
Created August 11, 2011 09:41
A keyboard shortcut to run tests with watchr

A keyboard shortcut to run tests with watchr

When developing in rails I use watchr to run the tests each time a file is saved, but lots of times I find my self adding a whitespace or a newline and saving just to trigger watchr and run the tests.

I wanted to have is a simple keyboard shortcut (like F15) to tell watchr to run the last spec, and mpartel (thx! : ) gave me an idea on how to do it, so here it is:

Dependencies

Obviously you need watchr, but we're also going to need pgrep that will help us find out the pid of the watchr process. So go ahead and do

sudo port install proctools

function cdgems() {
/usr/bin/osascript -e "tell application \"System Events\" to tell process \"Terminal\" to keystroke \"t\" using command down"
/usr/bin/osascript -e "tell application \"Terminal\" to do script with command \"cd $GEM_HOME/gems\" in window 1"
/usr/bin/osascript -e "tell application \"System Events\" to tell process \"Terminal\" to keystroke \"k\" using command down"
return 0
}
alias cdgems=cdgems
@RISCfuture
RISCfuture / validates_uniqueness_of.rb
Created May 2, 2009 02:01
Reimplementation of validates_uniqueness_of that works optimally with MySQL.
module ActiveRecord::Validations::ClassMethods
def validates_uniqueness_of(*attr_names)
configuration = { :case_sensitive => true }
configuration.update(attr_names.extract_options!)
validates_each(attr_names,configuration) do |record, attr_name, value|
# The check for an existing value should be run from a class that
# isn't abstract. This means working down from the current class
# (self), to the first non-abstract class. Since classes don't know
# their subclasses, we have to build the hierarchy between self and
@RISCfuture
RISCfuture / find_in_batches.rb
Created May 1, 2009 23:30
Reimplementation of find_in_batches that fixes bugs and works with composite_primary_keys
module ActiveRecord::Batches
def find_in_batches(options = {})
relation = self
unless arel.orders.blank? && arel.taken.blank?
ActiveRecord::Base.logger.warn("Scoped order and limit are ignored, it's forced to be batch order and batch size")
end
if (finder_options = options.except(:start, :batch_size)).present?
raise "You can't specify an order, it's forced to be #{batch_order}" if options[:order].present?