Length vs Size vs Count

arr = [1, 2, 3] arr.length # => 3 arr.size # => 3 arr.count # => 3 h = { a: 1, b: 2 } h.length # => 2 h.size # => 2 h.count # => 2 str = ‘name’ str.length # => 4 str.size # => 4 # str.count doesn’t work.  

Mysql tricks

# HOW TO INSTALL MYSQL SERVICE sudo apt-get install mysql-server # HOW TO START MYSQL SERVICE sudo service mysql restart # HOW TO CONNECT TO MYSQL SERVICE sudo mysql -u [user_name] [database_name] -p # HOW TO DISCONNECT FROM MYSQL SERVICE exit # HOW TO CHANGE USER PASSWORD SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘root’); update user…

HOW TO IMPLEMENT ACTS AS STATE MACHINE (AASM)

# DO IT INTO YOUR MODEL # INCLUDE include AASM # DECLARE ATTRIBUTE TO USE aasm.attribute_name :status # DECLARE WORKFLOW OF AASM aasm do state :[state_name], :initial => true state :[state_name], :initial => true, :before_enter => :[do_something] end  

RoR tricks

# HOW TO RUN A RAILS CONSOLE bundle exec rails c # HOW TO DISPLAY MODEL NAMES ActiveRecord::Base.connection.tables # HOW TO DISPLAY MODEL COLUMN NAMES [model_name].column_names # HOW TO DISPLAY ALL MODEL & MODEL COLUMN NAMES ActiveRecord::Base.connection.tables.each do |table_name| puts « \n » + table_name ActiveRecord::Base.connection.columns(table_name).each { |c| puts « –  » + c.name + « :  » +…

Ruby Tricks

## AVERAGE OF ARRAY a = [1,0,2,.,.,.,n] a.instance_eval { reduce(:+) / size.to_f } # HOW TO REMOVE NULL VALUES FROM ARRAY arr = [‘foo’, 0, nil, ‘bar’, 7, ‘baz’, nil] arr.compact arr.compact! arr #=> [‘foo’, 0, ‘bar’, 7, ‘baz’]

RVM Installation

# HOW TO SEE THE CURRENT RUBY VERSION ruby -v # HOW TO INSTALL RVM STABLE VERSION \curl -sSL https://get.rvm.io | bash -s stable –ruby source ~/.rvm/scripts/rvm # HOW TO INSTALL REQUIRE ELEMENTS rvm requirements # HOW TO LIST VERSION KNOWN rvm list known # HOW TO INSTALL RUBY rvm install ruby # HOW TO…