About Me

My photo
जिंदगी की परीक्षा में कोई नम्बर नहीं मिलते है लोग आपको दिल से याद करे तो समझ लेना आप पास हो गए....

Thursday 25 October 2012

Know process id by port number


Some time we want to know the process id using port number.Following is the command to use

Syntax:  $ lsof -i tcp:PORT_NUMBER

Example: lsof -i tcp:3000

Output:
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
firefox-b        1837  ravi     46u   IPv4  87572      0t0    TCP localhost:51945->localhost:3000 (ESTABLISHED)
ruby             2846  ravi     8u     IPv4  49836      0t0    TCP *:3000 (LISTEN)
ruby             2846  ravi     9u     IPv4  78566      0t0    TCP localhost:3000->localhost:58605 (CLOSE_WAIT)

In output we can see 2846 is the ruby server id.


Saturday 20 October 2012

readline error for ruby

Following is the error:
`require': cannot load such file -- readline (LoadError)

Solution:


sudo apt-get install libreadline-dev libncurses-dev libreadline5 libreadline5-dpg
cd <ruby source directory>/ext/readline
ruby extconf.rb
make
sudo make install
rvm pkg install readline

Solved Open ssl load error with rvm

Step 1 : Install openssl package

rvm pkg install openssl

Step 2: remove ruby

rvm remove 1.9.3

Step 3:

rvm install 1.9.3 --with-openssl-dir=$HOME/.rvm/usr

Thursday 11 October 2012

How to use will paginate with array of hashes




Suppose we have an object  which is having value as array of hashes (In example @student['results'] is an array of hashes which is returned from some API call)

so the is given below

  @students = WillPaginate::Collection.create(@page, @page_size) do |pager|
        # inject the result array into the paginated collection:
        pager.replace(@student['results'])
        unless pager.total_entries
          # the pager didn't manage to guess the total count, do it manually
          pager.total_entries = (@student['total_pages'] * @page_size)
        end
      end