As configured in my dotfiles.
start new:
tmux
start new with session name:
| # This custom matcher can be used to test state machine | |
| # | |
| # Examples | |
| # | |
| # it { should have_event(:status, :event_name, [:state1, :state2] => [:state3, :state4]) } | |
| # it { should have_event(:status, :event_name, { | |
| # :state1 => :state3, | |
| # :state1 => :state4, | |
| # :state3 => :state3, | |
| # :state2 => :state4 |
| # This is a skeleton for testing models including examples of validations, callbacks, | |
| # scopes, instance & class methods, associations, and more. | |
| # Pick and choose what you want, as all models don't NEED to be tested at this depth. | |
| # | |
| # I'm always eager to hear new tips & suggestions as I'm still new to testing, | |
| # so if you have any, please share! | |
| # | |
| # @kyletcarlson | |
| # | |
| # This skeleton also assumes you're using the following gems: |
| # http://gistpages.com/2013/07/15/reset_mysql_root_password_on_mac_os | |
| $ which mysqladmin | |
| /usr/local/bin/mysqladmin | |
| $ mysqladmin -u root -p password | |
| Enter password: | |
| New password: | |
| Confirm new password: |
| class Parent | |
| def say | |
| puts "In Parent" | |
| end | |
| end | |
| module A | |
| def say | |
| puts "In A" | |
| super |
As configured in my dotfiles.
start new:
tmux
start new with session name:
| # a common polymorphic model | |
| class Comment < ActiveRecord::Base | |
| belongs_to :commentable, polymorphic: true | |
| end | |
| class Article < ActiveRecord::Base | |
| has_many :comments, as: :commentable, dependent: :destroy | |
| end | |
| class Collection < ActiveRecord::Base |
| class ActionDispatch::Routing::Mapper | |
| def draw(routes_name) | |
| instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb"))) | |
| end | |
| end | |
| BCX::Application.routes.draw do | |
| draw :api | |
| draw :account | |
| draw :session |
| # source: http://hashrocket.com/blog/posts/bridging-activerecord-and-mongoid | |
| module Extensions::ActiveRecord::HasManyDocuments | |
| extend ActiveSupport::Concern | |
| module ClassMethods | |
| def has_many_documents(association_name, options = {}) | |
| class_eval %< | |
| def #{association_name} | |
| #{association_name.to_s.singularize.classify}.where(#{name.underscore}_id: id) | |
| end |
| $sure = false | |
| t = Thread.new { | |
| begin | |
| # nada | |
| ensure | |
| sleep | |
| $sure = true | |
| # cleanup all the things | |
| end |
| # => 2007-11-19T08:37:48-06:00 Safari下只能Parse这种格式的时间 | |
| Time.now.strftime("%FT%T%:z") |