Skip to content

Instantly share code, notes, and snippets.

@cantin
cantin / deploy for delayed_job_mongoid
Created August 17, 2012 02:22
delayed_job_mongoid cap/deploy
namespace :delayed_job do
task :setup do
puts capture %Q(cd #{deploy_to}/current/ && RAILS_ENV=production script/rails runner 'Delayed::Backend::Mongoid::Job.create_indexes')
end
task :start do
puts capture %Q(cd #{deploy_to}/current/ && RAILS_ENV=production script/delayed_job start)
end
task :stop do
namespace :book_item do
task :free_all_if_due => :environment do
Book.free_book_items_if_due
puts 'Free the due book_item successfully'
end
end
@cantin
cantin / gist:3891279
Created October 15, 2012 07:54
vim search and replace in multi files
args **/*.txt
argsdo %s/oldword/newword/gc
/oldword/newword/# to disable the ignorecase options
@cantin
cantin / gist:3936965
Created October 23, 2012 05:43 — forked from zernel/gist:3749856
Logger
file = File.join(Rails.root, 'log/markdown.log')
File.new(file, 'w+') unless File.exist?(file)
logger = Logger.new(file)
logger.info("#{Time.now}: Share##{_id}'s price is from #{latest_price} to #{new_price}")
logger.close
@cantin
cantin / mysql
Created November 8, 2012 04:10
msyql dump
--export
mysql -u user -p password database_name > export.sql
mysql -u user -p password database_name table_name > export.csv
--import
mysql -u user -p password
source export.sql
@cantin
cantin / default params for block.rb
Created November 8, 2012 09:55
lambda default params
f = lambda {|x, y=1| puts(x+y) }
f = ->(x, y =1) { puts(x+y) }
@cantin
cantin / forwardable.rb
Created November 9, 2012 09:45
ruby-stb-lib forwardable
require 'forwardable'
class A
extend Forwardable
def initialize
@arr = Array.new
end
def_delegator :@arr, :push, :add
@cantin
cantin / dump_sql.rb
Created November 20, 2012 08:10
dump sql and reload
> DB_STRUCTURE=db/null_schema.sql rake db:structure:dump
class NullMigration < ActiveRecord::Migration
def up
file_data = File.read('db/migrate/null_schema.sql')
ActiveRecord::Base.connection.execute file_data
end
def down
@cantin
cantin / how_it_works.md
Created December 3, 2012 03:12 — forked from rubiii/how_it_works.md
MacVim-Formatter for RSpec
$ rspec --format MacVimFormatter --color spec
@cantin
cantin / downgrade_rubygem.md
Created December 10, 2012 06:49
downgrade rubygem

Due to the rails2.x is not compatible wtih RubyGem > 1.6, need downgrade RubyGem if run rails2.x app

gem uninstall rubygems-update
gem install rubygems-update -v 1.4.2
update_rubygems