Friday, November 13, 2015

Deal with Ruby


Install Ruby

http://stackoverflow.com/questions/26595620/how-to-install-ruby-2-1-4-on-ubuntu-14-04
https://www.brightbox.com/docs/ruby/ubuntu/

There is a PPA with Ruby 2.0, 2.1, and 2.2 even for Ubuntu 12.04:
$ sudo apt-add-repository ppa:brightbox/ruby-ng
$ sudo apt-get update
$ sudo apt-get install ruby2.2

$ ruby2.2 -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux-gnu]

Md5

1. Install the gem
sudo gem install digest

2. In your RUBY script file at top
require 'digest/md5' 

3. Use md5 file
md5 = Digest::MD5.file('path_to_file').hexdigest 

Kill process

http://www.cyberciti.biz/faq/linux-pidof-command-examples-find-pid-of-program/
kill -9 `pidof -s ruby`

http://stackoverflow.com/questions/9509102/how-to-get-pid-of-current-rake-task


Mysql

using Ruby 2.2 ... sudo apt-get install ruby2.2-dev

sudo apt-get install libmysqlclient-dev

sudo gem install mysql

    mysql = Mysql.new(db_host, db_user, db_pass, db_name, db_port)
    @moderated_num = mysql.query("SELECT ...").fetch_row[0]      
    mysql.close


http://www.kitebird.com/articles/ruby-mysql.html
http://zetcode.com/db/mysqlrubytutorial/


Constructor & Deconstructor

http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/


Exceptions Handling

http://www.skorks.com/2009/09/ruby-exceptions-and-exception-handling/
http://stackoverflow.com/questions/10048173/why-is-it-bad-style-to-rescue-exception-e-in-ruby


Chunked encoding

http://stackoverflow.com/questions/9837421/ruby-chunked-encoding-client
http://docs.ruby-lang.org/en/2.0.0/Net/HTTP.html
http://seamusabshere.github.io/2014/07/14/how-to-stream-https-chunks-with-ruby-net-http/

http://stackoverflow.com/questions/27763928/how-does-yield-a-file-like-response-from-a-web-server-work


1 comment:

  1. http://paramitech.com/passing-arrays-using-net-http-in-ruby/

    ReplyDelete