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
To redirect stdout in bash, overwriting file | |
cmd > file.txt | |
To redirect stdout in bash, appending to file | |
cmd >> file.txt | |
To redirect both stdout and stderr, overwriting | |
cmd &> file.txt | |
To redirect both stdout and stderr appending to file |
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
# AR | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
# Redis | |
$redis.client.logger = Rails.logger |
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
# Time.local returns time in Time zone of your machine: | |
Time.local(2012,8,31) | |
# => Fri Aug 31 00:00:00 +0400 2012 | |
# Time.zone.local returns time in Time zone of your application | |
Time.zone.local(2012,10,31) | |
# => Wed, 31 Oct 2012 00:00:00 EET +02:00 |
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 User < ActiveRecord::Base | |
after_save :queue_welcome_email, :on => :create | |
private | |
def queue_welcome_email | |
Resque.enqueue(WelcomeEmailJob, Marshal. | |
dump({ :email => self.email, :full_name => "#{self.first_name} #{self.last_name}" })) | |
end | |
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
SELECT create_time FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'schema' AND table_name = 'name'; | |
SHOW ENGINE INNODB STATUS; | |
SHOW CREATE TABLE foo; |
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
http://robots.thoughtbot.com/post/27985816073/the-hitchhikers-guide-to-riding-a-mountain-lion | |
REE | |
====== | |
https://rvm.io/packages/iconv/ | |
rvm pkg install iconv | |
export CPPFLAGS=-I/opt/X11/include | |
rvm reinstall ree --with-iconv-dir=$rvm_path/usr | |
gem uninstall nokogiri |
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
Order.paid.joins(:user).merge(User.blue_eye) | |
# => SELECT "orders".* FROM "orders" INNER JOIN "users" ON "users"."id" = "orders"."user_id" WHERE "orders"."status" = 3 AND "users"."eye_color" = 'blue' AND "users"."status" = 1 |
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
def to_hash | |
@reports.map(&:to_hash).reduce({}, :merge) | |
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
http://stackoverflow.com/questions/341143/can-rails-routing-helpers-i-e-mymodel-pathmodel-be-used-in-models | |
In Rails 3: | |
Rails.application.routes.url_helpers | |
Rails 2 | |
include ActionController::UrlWriter |
NewerOlder