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…

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’]