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
############################################################# | |
# Application | |
############################################################# | |
set :application, "" #your app's name here | |
set :server_ip, "" #your server's ip here | |
set :deploy_to, "/home/rails/#{application}" #the path to your rails app here | |
############################################################# | |
# Servers |
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
named_scope :with_keywords, lambda {|q| | |
fields = %w(title information items.sku) | |
tokens = q.split.collect {|c| "%#{c.downcase}%"} | |
clause = (["(" + fields.map {|f| "#{f} LIKE ?" }.join(" OR ") + ")"] * tokens.size).join(" AND ") | |
{ :include => [:items], :conditions => [clause, *(tokens * fields.size).sort] } | |
} |
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
# If you ever needed an array of all ActiveRecord models in your Rails app (+ Session): | |
Dir["app/models/**/*.rb"].each {|r| require r} | |
subclasses_of(ActiveRecord::Base).map(&:class_name) | |
# Or *all* models: | |
ActiveRecord::Base.connection # Preloads driver constants | |
constants_before = Object.constants | |
Dir["app/models/**/*.rb"].each {|r| require r} | |
Object.constants - constants_before |
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
class ActivityEntry < ActiveRecord::Base | |
belongs_to :target, :polymorphic => true | |
belongs_to :user | |
# Target Scopes | |
named_scope :for, lambda {|obj| {:conditions => {:target_id => obj.id, :target_type => obj.class.name}} } | |
named_scope :for_listings, {:conditions => {:target_type => 'Listing'} } | |
named_scope :manageable_by, lambda {|user| | |
case | |
when user.can_manage_company? then {} |
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
indigosun:vim-fu bhughes$ rake preinstall | |
(in /Users/bhughes/Workspace/Source/vim-fu) | |
Usage: /usr/local/git/bin/git-submodule [--quiet] [--cached] [add <repo> [-b branch]|status|init|update|summary [-n|--summary-limit <n>] [<commit>]] [--] [<path>...] |
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
# Bad: | |
1.upto(10) do |i| | |
puts "X" * i | |
end | |
# Good: | |
((nil.object_id - 3)..(2**3 + 2)).map do |i| | |
lambda { "X" * i } | |
end.collect {|i| i.send(:call)}.tap do |a| | |
puts a.class.instance_method(:join).send(:bind, a).call("\n") |
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
module ApplicationHelper | |
def tree_options_from_collection_for_select(objects, value = :id, name = :name, selected = nil, options = {}) | |
options[:indent_with] ||= '- ' | |
options[:level] ||= 0 | |
objects.inject([]) do |entries, object| | |
entries << [options[:indent_with] * options[:level] + object.send(name), object.send(value)] | |
entries += tree_options_from_collection_for_select(object.children, value, name, selected, options.merge(:level => options[:level] + 1)) | |
entries | |
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
### Don't you wish you could use this if-nil idiom? | |
first_name || "Joe" | |
# Well you can't if you expect first_name to be blank instead of nil, so Ruby will short-circuit. | |
# Enter deblank: | |
class Object | |
def deblank | |
self.blank? ? nil : self | |
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
### Don't you wish you could use this if-nil idiom? | |
first_name || "Joe" | |
# Well you can't if you expect first_name to be blank instead of nil, so Ruby will short-circuit. | |
# Enter deblank: | |
class Object | |
def deblank | |
self.blank? ? nil : self | |
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
## Concatenates a subset of columns in Excel amongst multiple sheets into one dump | |
require "rubygems" | |
require "active_support" | |
require "roo" | |
require "faster_csv" | |
COLUMNS = ["A", "B"] # Column names of whatever you want | |
[].tap do |o| |
OlderNewer