Skip to content

Instantly share code, notes, and snippets.

View groman-me's full-sized avatar

Roman Gusev groman-me

View GitHub Profile
@groman-me
groman-me / sample
Created September 21, 2012 04:58
Bash redirects
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
@groman-me
groman-me / sample.rb
Created September 13, 2012 06:46
Loggers
# AR
ActiveRecord::Base.logger = Logger.new(STDOUT)
# Redis
$redis.client.logger = Rails.logger
@groman-me
groman-me / time.rb
Created September 3, 2012 22:13
Get time in current time zone
# 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
@groman-me
groman-me / example.rb
Created August 22, 2012 15:16
Avoid DB and Queue race
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
@groman-me
groman-me / meta_info.sql
Created August 22, 2012 08:33
MySQL meta info (table create time)
SELECT create_time FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'schema' AND table_name = 'name';
SHOW ENGINE INNODB STATUS;
SHOW CREATE TABLE foo;
@groman-me
groman-me / ree_mountain_lion_tip
Created August 2, 2012 09:10
Install REE and 1.9.3 on Mountain Lion
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
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
@groman-me
groman-me / gist:1990236
Created March 7, 2012 01:13
English-y to_hash
def to_hash
@reports.map(&:to_hash).reduce({}, :merge)
end
@groman-me
groman-me / named_path_from_model
Created August 2, 2011 14:11
get _path from model
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