Friday, March 16, 2012

Install Mongodb on ubuntu / fedora 11 to 16

Easy installation of mongodb on ubuntu and fedora

Ubuntu

   1. Add Repo Key as
        sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

   2. Add Repo Source
        for Debian Lenny or older ubuntu add below line to /etc/apt/sources.list
     
        deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen


      for recent ubuntu add below line to /etc/apt/sources.list

      deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen 

   3. Install mongo-db

       
       sudo apt-get install mongodb-10gen

 Fedora

  1. logged in as root user by su -
  2. Add below part to /etc/yum.repos.d/10gen-mongodb.repo


10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
gpgcheck=0

    3.  yum install mongo-10gen mongo-10gen-server
    4.  Configure MongoDB Database Server as below
         1.  nano -w /etc/mongod.conf
         2. Set or check the basic setting before start mongodb

             make sure that this below things are available in mongodb.conf
 
                  logpath=/var/log/mongo/mongod.log
                  port=2701
                  dbpath=/var/lib/mongo
     5. /etc/init.d/mongod start

   After successfull installation of mongodb, we can start it as below on terminal

   1. mongo
   2. use database_name  # default
  

Tuesday, September 20, 2011

change table column name in Rails validation message

class Vendor < ActiveRecord::Base
validate_uniqness_of :gid, :message => "should be uniq"
HUMANIZED_ATTRIBUTES = {
    :gid => "vendor"
  }

  def self.human_attribute_name(attr)
    HUMANIZED_ATTRIBUTES[attr.to_sym] || super
  end

end

Friday, July 8, 2011

Collect all child elements javascript

For all first level children
var children = document.getElementById('id').childNodes;

For all descendants 
var children = document.getElementById('id').getElementsByTagName('*');

For some particular  element children
var childNodeArray = document.getElementById(tbody).getElementsByTagName('tr');

Monday, March 28, 2011

find process id for the port

Find port by following way

lsof -w -n -i tcp:8080
fuser -n tcp 8080

Now you have some integer value which is the process of the port
Now kill it by
kill -9 XXXX

Saturday, March 26, 2011

Debuging Technique with Ruby on Rails

There are multiple debug techniques are available with RoR,  Please use the
below techniques as much as you can,  while you do programming in RoR.

1. install ruby-debug
   then need to start application by ruby script/server --debugger
   And place word 'debugger' anywhere in your code and once you run your
application, it stops running from where you have placed 'debugger'. We
can say that debugger is the breakpoint

  Then you can use following commands
  n - move next line
  l - display the current line after the debugger
  c - continue
  You can also check the readme of the ruby-debug

2. You can use puts,exit etc.

3. You can use  logger.debug "The object is #{@object}" or  
  RAILS_DEFAULT_LOGGER.debug @object

4. In view, you can also use <%=debug @object %>

5. You can simultaneously check your log by running tail -f lod/development.log in the another terminal or you can also use tail -n log/development.log where n is any numeric number

6. We can use Exception Notifier plugin in our production environment so that we gets an notification mail if any error occurs on production

Monday, January 24, 2011

Call Rake task from migration

 You can call the rake task in migration by writing following

Rake::Task[this_is_rake_task'].invoke

Is the string has numeric value?

for check the string has numeric value or not then you can do it by below
s = "123cs"

then call method as below
is_numeric?(s)

and the method is as below
 def is_numeric?(s)
    s.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
  end

Contact Me for any help regarding rails/nodejs/php/mysql

Name

Email *

Message *