Showing posts from 2013

Run web server in from any directory as root on the fly using ruby

Many times while testing open source project demos and examples we need to run the html pages on a web-server.
Opening the files directly in browser has it own limitations like while ajax call some browser imposed limitations blah blah...

Instead if putting it in web root directory every time we can use the inbuilt web-server which ruby provides

just go to the directory and run
ruby -rwebrick -e' => 5000, :DocumentRoot => Dir.pwd).start'

-r requires class ( webrick requred here) -e executes code (webserver run on port 5000, with document root as current dir)
enjoy.. :)

Rails performance boost using Passenger/Unicorn Out-Of-Band Work GC

Hello, have u tried Out-Of-Band GC?

Its available in passenger 4 and unicorn its give a very good performance boot to application at cost of some extra memory footprint (in my case 1.6 times than actual memory)

Don't forget to to disable auto gc during requests
GC.disable # Don't run GC during requests is the  main key here

Tune frequency according to application for maximum performance  #unicorn GC_FREQUENCY = 5
#for passenger Trigger out-of-band GC every 5 requests.
use PhusionPassenger::Rack::OutOfBandGc, 5 

Also have your ruby tuned for GC so that it can serve more requests without frequent GC runs

Curb gem Installation problems on Ubuntu

Install the follows libs

sudo apt-get install libcurl4-gnutls-dev libcurl4-openssl-dev

curb gem compiles natively using system libs and it requires curl headers to complile with is not installed by default.

Install the libs and run 

gem install curb

It should install smoothly.. \m/ 

10 tips for securing nginx

truncate and link text helper in rails

snippet to truncate text and link to see more

Code this in application helper.

  def truncate_and_link( text,options ={})
    length = options[:length]
    return text if length.blank?
    url = options[:url] || '#'
    output = raw truncate(text, :length => length)
    output += link_to('more', url) if text.size > length

Useful when eg linking big posts