Skip to content

Instantly share code, notes, and snippets.

# ユーザーの入力が1ならBarから、そうでなければBazから派生する
class Foo < (user_input == "1" ? Bar : Baz)
end
@keitaj
keitaj / schedule.rb
Created March 12, 2015 03:15
wheneverでのスケジュール設定サンプル。/config/schedule.rb。crontabを更新するコマンド。bundle exec whenever --update-crontab
every 1.day, at: '15:01 pm' do
runner 'Tasks::CreateSummaryReport.execute', output: 'log/cron.log'
end
every(1.day, at: '0:07 am') { runner 'Tasks::CreateDetailReports.new.execute', output: 'log/cron.log' }
every 1.hours do
runner 'Tasks::CreateSummaryReport.execute', output: 'log/cron.log'
end
6018 Books
6000 Business
6022 Catalogs
6017 Education
6016 Entertainment
6015 Finance
6023 Food and Drink
6014 Games
6013 Health and Fitness
6012 Lifestyle
@keitaj
keitaj / ar_innodb_row_format.rb
Created March 7, 2015 01:21
utf8mb4で動かすために必要。create_tableメソッドで'ROW_FORMAT=DYNAMIC'がデフォルトで指定されるようにしておく。http://qiita.com/kamipo/items/101aaf8159cf1470d823
ActiveSupport.on_load :active_record do
module ActiveRecord::ConnectionAdapters
class AbstractMysqlAdapter
def create_table_with_innodb_row_format(table_name, options = {})
table_options = options.merge(:options => 'ENGINE=InnoDB ROW_FORMAT=DYNAMIC')
create_table_without_innodb_row_format(table_name, table_options) do |td|
yield td if block_given?
end
end
alias_method_chain :create_table, :innodb_row_format
@keitaj
keitaj / database.yml.sample
Created March 7, 2015 00:12
database.yml.sample
development:
adapter: mysql2
enccoding: utf8mb4
charset: utf8mb4
collation: utf8mb4_general_ci
reconnect: false
database: app_db
pool: 5
username: root
password: admin