This file contains hidden or 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
| initializer :after => :initialize_dependency_mechanism do | |
| ActiveSupport::Dependencies.mechanism = :load | |
| end |
This file contains hidden or 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
| gem 'geokit' |
This file contains hidden or 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
| def random | |
| find(:first, :offset => (count * rand).to_i) | |
| end |
This file contains hidden or 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
| def tip(msg); puts; puts msg; puts "-"*100; end | |
| # | |
| # 30 Ruby 1.9 Tips, Tricks & Features: | |
| # http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/ | |
| # | |
| tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2" | |
| tip "Ruby 1.9 supports named captures in regular expressions!" |
This file contains hidden or 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
| class LockFile | |
| attr_accessor :path | |
| def initialize(path="/tmp/lockfile.lock") | |
| @path = path | |
| if block_given? | |
| lock! | |
| yield | |
| unlock! | |
| end |
This file contains hidden or 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
| function getParam(key) | |
| { | |
| var regex, values; | |
| regex = new RegExp("[\\?&]" + key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]") + "=([^&]*)", "i"); | |
| values = regex.exec(unescape(window.location.href)); | |
| return (values == null) ? "" : values[1]; | |
| } |
This file contains hidden or 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
| # Before: | |
| @avatars = Avatar.order("avatars.name ASC, avatars.name ASC") | |
| @avatars = @avatars.where(["avatars.name like ? or users.email like ? or users.name like ?", params[:term], params[:term], params[:term]]) unless params[:term].blank? | |
| @avatars = @avatars.paginate(:page => params[:page], :per_page => 25) | |
| # After | |
| class Avatar | |
| def self.find_by_something(something, order="name ASC") | |
| ['avatars.name LIKE ?', 'users.email LIKE ?', 'users.name LIKE ?'].inject(self.order(order).includes(:user)) do |assoc, cond| |
This file contains hidden or 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
| module ExceptionCatcher | |
| def with_exception_handling(silent=false, &block) | |
| begin | |
| yield block | |
| rescue => e | |
| unless silent | |
| # send to hoptoad | |
| puts "sending error somewhere" | |
| end |
This file contains hidden or 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
| module IntegerAssertions | |
| def negative? | |
| self < 0 | |
| end | |
| def positive? | |
| self > 0 | |
| end | |
This file contains hidden or 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
| var destination = document.getElementById("destinationTextbox"); | |
| var source = document.getElementById("sourceTextbox"); | |
| var destinationHandler = function(value){ | |
| return destination.value = value; | |
| } | |
| source.onchange = function(){ | |
| destinationHandler(this.value); | |
| }; |