Table of contents:
- migration tasks
- new change syntax
- using models in a migration
- reversible migrations
- revert command
| #! /usr/bin/ruby | |
| LBRACE = '{' | |
| RBRACE = '}' | |
| LBRACKET = '[' | |
| RBRACKET = ']' | |
| COMMA = ',' | |
| COLON = ':' | |
| WHITESPACE = /\s/ |
| # Input | |
| events = [ | |
| event(status: 'IDLE', job: 1, date: '2014-01-01'), | |
| event(status: 'BUSY', job: 1, date: '2014-01-02'), | |
| event(status: 'BUSY', job: 1, date: '2014-01-03'), | |
| event(status: 'BUSY', job: 2, date: '2014-01-04'), | |
| event(status: 'BUSY', job: 2, date: '2014-01-05'), | |
| event(status: 'BUSY', job: 2, date: '2014-01-06'), | |
| event(status: 'IDLE', job: 2, date: '2014-01-07'), | |
| event(status: 'BUSY', job: 3, date: '2014-01-08'), |
| # PROMPT | |
| # ========== | |
| PS1="\[\e[33m\]\h\[\e[0m\]:\[\e[4m\]\W\[\e[0m\] \$ " | |
| # ALIASES | |
| # ========= | |
| alias ls="ls -lh" |
| require 'benchmark' | |
| a = Array.new(10_000) { rand } | |
| Benchmark.bm(20) do |bench| | |
| bench.report('sort <=>') { 10.times { a.sort { |x,y| y <=> x } } } | |
| bench.report('sort.reverse') { 10.times { a.sort.reverse } } | |
| bench.report('sort_by.reverse') { 10.times { a.sort_by(&:to_f).reverse } } | |
| end |
| $ which ruby | |
| > /Users/timuruski/.rvm/rubies/ruby-2.0.0-p353/bin/ruby | |
| $ time ~/.rvm/rubies/ruby-2.0.0-p353/bin/ruby -e "1 + 1" | |
| > ~/.rvm/rubies/ruby-2.0.0-p353/bin/ruby -e "1 + 1" 0.03s user 0.01s system 93% cpu 0.034 total | |
| $ time /usr/bin/ruby -e "1 + 1" | |
| > /usr/bin/ruby -e "1 + 1" 0.00s user 0.00s system 73% cpu 0.005 total |
| class Address | |
| include ActiveResource::Attributes | |
| string :street_address, :street_address_2, :street_address_3, :leave_location, | |
| :city, :province_state, :country, :name, :phone_number, :special_instructions, | |
| :postal_zipcode, :leave_location, :company, :special_instructions, :attention_name | |
| boolean :is_residential, :addressable | |
| end |
| # PROMPT | |
| # ========== | |
| # This doesn't work? | |
| status () { | |
| if [[ $? -gt 0 ]]; then | |
| printf "\[\e[31m\]\$\[\e[0m\]" | |
| else | |
| printf "\$" | |
| fi |
| class CustomerList | |
| def initialize(account, filter = nil) | |
| @account = account | |
| @filter = filter | |
| end | |
| # That's right, attributes after initializer. | |
| attr_reader :account, :filter | |
| end |