Thursday, January 15, 2015

Error installing rb-gsl gem on ubuntu

While installing rb-gsl gem on my gemset from ruby 2.1.0 got an error trailed like below

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /home/praveen/.rvm/rubies/ruby-2.1.5/bin/ruby -r ./siteconf20150115-4389-1qh8ghv.rb extconf.rb
extconf.rb:6: warning: Insecure world writable dir /opt/android-sdk in PATH, mode 040777
*** ERROR: missing required library to compile this module: No such file or directory - gsl-config
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/home/praveen/.rvm/rubies/ruby-2.1.5/bin/ruby
    --with-gsl-version

extconf failed, exit code 1

Gem files will remain installed in /home/praveen/.rvm/gems/ruby-2.1.5/gems/rb-gsl-1.16.0.2 for inspection.
Results logged to /home/praveen/.rvm/gems/ruby-2.1.5/extensions/x86_64-linux/2.1.0/rb-gsl-1.16.0.2/gem_make.out


there is one system dependency that is required to pursue further in ubuntu install libgsl0-dev package, install it like..
sudo apt-get install libgsl0-dev
That's it now retry installing rb-gsl gem.. it worked for me :)





Monday, January 5, 2015

How to access rails application routes in rails models

With the newer version of rails, application itself is an engine which is the initialized format of abstract class Rails::Application and to access routes of any (host) engine the code is

SomeRailsApplicationName::Application.routes.url_helpers.named_route_path
SomeRailsApplicationName::Application.routes.url_helpers.named_route_path(parameter: 'something')

and for a (mountable) engine the code is

SomeMountableEngineName::Engine.routes.url_helpers.named_route_path
SomeMountableEngineName::Engine.routes.url_helpers.named_route_path(parameter: 'something'

Example:

rails console > Helloworld::Application.routes.url_helpers.about_path
 => "/about"

rails console > BambooUser::Engine.routes.url_helpers.login_path
 => "/users/login"

Saturday, December 13, 2014

Error installing nokogiri gem in ubuntu: Solved

If something resembling below is the output of nokogiri gem install in ubuntu 14.10 or so

/home/praveen/.rvm/rubies/ruby-2.1.0/bin/ruby -r ./siteconf20141213-9698-1nhm3s1.rb extconf.rb
Building nokogiri using packaged libraries.
checking for iconv.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/home/praveen/.rvm/rubies/ruby-2.1.0/bin/ruby
    --help
    --clean
    --use-system-libraries
    --enable-static
    --disable-static
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --enable-cross-build
    --disable-cross-build
/home/praveen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /home/praveen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:587:in `try_cpp'
    from /home/praveen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:1067:in `block in have_header'
    from /home/praveen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:918:in `block in checking_for'
    from /home/praveen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:351:in `block (2 levels) in postpone'
    from /home/praveen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:321:in `open'
    from /home/praveen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:351:in `block in postpone'
    from /home/praveen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:321:in `open'
    from /home/praveen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:347:in `postpone'
    from /home/praveen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:917:in `checking_for'
    from /home/praveen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:1066:in `have_header'
    from extconf.rb:103:in `have_iconv?'
    from extconf.rb:148:in `block (2 levels) in iconv_prefix'
    from extconf.rb:90:in `preserving_globals'
    from extconf.rb:143:in `block in iconv_prefix'
    from extconf.rb:120:in `each_iconv_idir'
    from extconf.rb:137:in `iconv_prefix'
    from extconf.rb:428:in `block in
'

    from extconf.rb:161:in `block in process_recipe'
    from extconf.rb:154:in `tap'
    from extconf.rb:154:in `process_recipe'
    from extconf.rb:423:in `
'


extconf failed, exit code 1

Install libgmp-dev package with command
sudo apt-get install libgmp-dev

That should solve the problem

Saturday, July 26, 2014

Amazon VPC's NAT not doing its job! SOLVED

Hi,

If you have ever bumped into this situation where a good chap VPC from Amazon is at your help and as per expectation NAT machine in Public subnet is not able to route traffic (even if all the security group and NAT rules are in place) and worst, no one has posted anything on this.. then you are at my situation :)

What i have done seems all correct. Am able to ssh in NAT and also able to log into destination instances(ssh-ing them from NAT), NAT rules even though all look good syntacticly and as per the requirement, is not working at all.

So what i have done wrong? Here is the answer

Was trying to make a typical Scenario 1 VPC on amazon and with the help of NAT machine was trying to forward traffic on other two instances (available in public subnet itself) so that can save myself on buying EIPs for instances created (Trying to be [over]smart).

To laugh back on me Amazon has made all proper arrangements and this is what they say
We use the term NAT instance; however, the primary role of a NAT instance is actually port address translation (PAT). We chose to use the more widely known term, NAT. For more information about NAT and PAT, see the Wikipedia article about network address translation.

The main route table sends the traffic from the instances in the private subnet to the NAT instance in the public subnet. The NAT instance sends the traffic to the Internet gateway for the VPC. The traffic is attributed to the Elastic IP address of the NAT instance. The NAT instance specifies a high port number for the response; if a response comes back, the NAT instance sends it to an instance in the private subnet based on the port number for the response.  

So in a nutshell a NAT machine(in Amazon VPC) can work (of routing traffic) as per expectation if only the instances its connecting-to, is in private subnet and not in public subnet.

If it helped you anywhere am glad (am not the only one)

Friday, December 13, 2013

ActiveRecord::ConnectionTimeoutError

If one is getting or started getting error like this
ActiveRecord::ConnectionTimeoutError (could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)):
  activerecord (4.0.0.rc1) lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `block in wait_poll'
  activerecord (4.0.0.rc1) lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `loop'
  activerecord (4.0.0.rc1) lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `wait_poll'
  activerecord (4.0.0.rc1) lib/active_record/connection_adapters/abstract/connection_pool.rb:136:in `block in poll'

Then it is something that is missing in your database.yml
{environment_name}:
  adapter: mysql2
  encoding: utf8
  database: {product_name}_environment_name
  username: username
  password: password
  socket: /var/run/mysqld/mysqld.sock

Add correct values for 'reaping_frequency' and 'pool' in connection parameter and it might look like
{environment_name}:
  adapter: mysql2
  encoding: utf8
  database: {product_name}_environment_name
  pool: 15
  reaping_frequency: 3
  username: username
  password: password
  socket: /var/run/mysqld/mysqld.sock
Options descriptions
  • pool: number indicating size of connection pool (default 5)
  • checkout_timeout: number of seconds to block and wait for a connection before giving up and raising a timeout error (default 5 seconds).
  • reaping_frequency: frequency in seconds to periodically run the Reaper, which attempts to find and close dead connections, which can occur if a programmer forgets to close a connection at the end of a thread or a thread dies unexpectedly. (Default nil, which means don't run the Reaper).
  • dead_connection_timeout: number of seconds from last checkout after which the Reaper will consider a connection reapable. (default 5 seconds).

Knowledge base taken from http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html

Friday, December 6, 2013

Ctrl + Alt + F1 for TTY window

To open a console window and fix Ubuntu if it anywhere halts, command is press
Ctrl + Alt + F1
and a TTY prompt appears and now it is all yours.

Friday, November 29, 2013

Rails: redirect_to with flash

Hi,

In rails one can provide(not in older versions) flash messages directly in redirect_to method while residing in controller's action to redirect to different path like
redirect_to login_path, :notice => 'Please login'

But one thing needs attention here is, it works only for named routes and not for routes without names like

redirect_to {controller: 'session', action: 'login'}, :notice => 'Please login'

Small but this point should be taken in consideration.