Time manipulation in ruby

A Time is a number of seconds since an epoch whereas a DateTime is a number of days since an epoch which is why adding 1 to a DateTime adds a whole day. You can however add fractions of a day, for example d = DateTime.now d + Rational(10, 86400) Will add 10 seconds to … Read more

Ruby – getting value of hash

Convert the key from a string to a symbol, and do a lookup in the hash. hash = {:key1 => “value1”, :key2 => “value2”} k = ‘key1′ hash[k.to_sym] # or iow, hash[:key1], which will return “value1” Rails uses this class called HashWithIndifferentAccess that proves to be very useful in such cases. I know that you’ve … Read more

How to get exit status with Ruby’s Net::SSH library?

I find the following way of running processes with Net::SSH much more useful. It provides you with distinct stdout and stderr, exit code and exit signal. require ‘rubygems’ require ‘net/ssh’ require ‘etc’ server=”localhost” def ssh_exec!(ssh, command) stdout_data = “” stderr_data = “” exit_code = nil exit_signal = nil ssh.open_channel do |channel| channel.exec(command) do |ch, success| … Read more

Installing Ruby 2.0.0 using RVM

Your rvm is probably not up to date, and by doing so the list of installable rubies also. Rvm probably took the best match, that was Rubinius 2 When you do rvm list known You obtain the list of known rubies that you can install This list is updated at the same time you update … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)