Use Ruby Metrical Gem for reviewing your rails code and find the rails best practises with rails_best_practices gem

Install the metrical gem first to run metrical.

$ gem install metrical

If the output showing an error like: Gem::DependencyError, then install the gem metric_fu first, which installs all the dependencies required.

$ gem install metric_fu

Then try to install the metrical gem

I got the following error:

vnet6@ubuntu:~/projects/grouptable$ gem install metrical
ERROR:  While executing gem ... (Gem::DependencyError)
    Unable to resolve dependencies: metric_fu requires sexp_processor (~> 3.0.3); churn requires sexp_processor (~> 3.0); reek requires sexp_processor (~> 3.0); ruby2ruby requires sexp_processor (~> 3.0); ripper_ruby_parser requires sexp_processor (~> 3.0); flog requires sexp_processor (~> 3.0); ruby_parser requires sexp_processor (~> 3.0)

In my system sexp_processor version was (4.2.1)

I uninstalled the version,

$ gem uninstall sexp_processor

and installed the version 3.0.3

$ gem list sexp_processor -v '3.0.3'

and installed the metrical gem by

$ gem install metrical

run metrical gem by

$ metrical

But this is also giving me error! It has a lot of dependencies. It is asking again the sexp_processor version (4.2.1). So Installed two versions so the error gone and got another error!

So I tried the rails_best_practices to see the warnings.

$ gem install rails_best_practices
$ rails_best_practices
$ rails_best_practices -f html # to see the warnings in html

Its working fine!

How to create a remote branch and fetch the code in Git

Type the command below to see, what all branches are there in remote.

$ git branch -r
  origin/HEAD -> origin/master
  origin/master
  origin/optimize-cities
  origin/optimize-merchants
  origin/release-dec-30
  origin/sso
  origin/staging

Create the remote Staging branch in local and fetch code:

 $ git checkout --track origin/staging

Install PostgresSQL in Ubuntu 12.04

Install the postgres software by

$ sudo apt-get install postgresql postgresql-contrib libpq-dev

Set up your password

Goto the postgres prompt

$ sudo -u postgres psql

Inside that you can set the password for the DB user postgres

ALTER USER postgres PASSWORD 'YourPassword';

References:
xtremekforever.blogspot
postgresql-password-authentication-failed-for-user-postgres

mongodb connection issue: `connect’: Failed to connect to a master node at localhost:27017 (Mongo::ConnectionFailure)

You just try to start the mongodb by

service mongod start

or

start mongod

And check mongodb process is running by checking

ps aux | grep mongo

You can see the status by

service mongod status

If it is not starting then try to remove the mongod lock file by,

rm /var/lib/mongodb/mongod.lock

Then start the mongodb server again.

Install RVM, Ruby on CentOS

First download the Ruby Version Manager (RVM) installer as follows

$ sudo bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )

RVM requires to add relevant users to itโ€™s group. Open the file like so:

$ sudo vim /etc/group

Edit the ‘rvm’ group (likely the last entry) to look like:

rvm:x:503:your_username
Run the install:

$ cd /usr/local/rvm/bin
$ sudo ./rvm-installer
...

“Upgrade of RVM in /usr/local/rvm/ is complete.”

I needed to reload the RVM to continue, this might not be required:

$ rvm reload

If it shows -bash: rvm: command not found

please close the terminal and start it again to load the RVM.

Now we can install the Ruby version. This will also install rubygems which is always usefulโ€ฆ

$ rvm install 1.9.3 --with-openssl-dir=/usr
$ ruby -v
$ rvm use ruby-1.9.3-p327 --default

If you are getting nokogiri error like:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

checking for libxslt/xslt.h… no

libxslt is missing.

then install

$ sudo yum install -y gcc ruby-devel libxml2 libxml2-devel libxslt libxslt-devel

Reference:
http://jamesmcfadden.co.uk/installing-ruby-on-rails-on-centos-5-8/

Remove and reset jQuery token input drop down values through ajax

If you have a requirement for reloading the token input drop down values, you can remove the token input by

$(".token-input-list-facebook").remove();

and add token input to the selector by

$("#demo-input-local").tokenInput([
                {id: 7, name: "Ruby"},
                {id: 41, name: "C"},
                {id: 43, name: "C++"},
                {id: 47, name: "Java"}
            ], {
      propertyToSearch: "name",
      theme: "facebook",
      preventDuplicates: true});

How to get haml support in netbeans 6.9

By default netbeans 6.9 is not providing the support for haml. We need to download the netbeans haml plugin and add to your netbeans.
Download the haml plugin from here:
http://postcomment.googlecode.com/files/org-netbeans-modules-haml.nbm

then go to your netbeans Tools/plugins/ and go to Downloaded tab, click on add plugin select the drop down and give your downloaded plugin path. Click on ‘OK’ button. Click on ‘Install’. Thats it!