Trim white spaces from ruby string

Let’s play with ruby function to remove all white spaces.
1.9.3p125 :001 > a = “Miasa Pride”
 => “Miasa Pride”
1.9.3p125 :002 > a.strip
 => “Miasa Pride”
1.9.3p125 :006 > a.gsub(/\s+/, “”)
 => “MiasaPride”
1.9.3p125 :007 > b = ” Miasa Pride “
 => ” Miasa Pride “
1.9.3p125 :008 > b.gsub(/\s+/, “”)
 => “MiasaPride”
1.9.3p125 :009 > c = ” Miasa@Pride “
 => ” Miasa@Pride “
1.9.3p125 :010 > c.gsub(/\s+/, “”)
 => “Miasa@Pride”


Install Teamviewer in Ubuntu

1. First we need to download  team viewer. We can do from direct download OR vi terminal .


2.Once we done, We go to download folder and  run the commands below to install

$sudo dpkg -i teamviewer_linux.deb
That’s it, Enjoy……..!!!

Create a branch in github

We always used to create a branch on local system and after verify and ok with code, we merged to master branch. Today i was facing situation, i need to create a branch on remote git repository. Actually my manager wanted to take look to my code before merge to master branch(As he is residing out of country).

1.First create the branch locally:

git branch rspec-test-import

2.List all local branch.

git branch

3.Checkout to local branch.
git checkout rspec-test-import

4.Again list branch and see where we are?
git branch

5.Now create the remote branch and push your code.
git push --all
git push origin rspec-test-import

That's it. Now you able to pull and push your changes to branch repository too. 

Install NetBeans IDE on Ubuntu 11.10

1. Make sure, You Added PPA repository to my Ubuntu.

sudo add-apt-repository ppa:ferramroberto/java

2.After adding PPA, update your system apt:

sudo apt-get update

3.Install the Java Development Kit:

sudo apt-get install sun-java6-jdk

If you have problem with java installation , take a look to install-java-and-java-browser-plugin-ubantu-11-10 .

4. Go to the folder where you want to download NetBeans and download by typing:


5.Give yourself permissions to execute the install script you have just downloaded:

chmod u+x

6. Now run netbeans:


Just do next as window, and click desktop icon to start NetBeans:

That’s it. Enjoy……………

twitter bootstrap rails 3 tutorial

Beginning here, we show how to create the application from scratch over over rails 3.2.3 and ruby 1.9.3.

1. Open a terminal, navigate to a folder where you have rights to create files, and Type: Or  do git clone twitter-bootstrap-rails-3-demo  app and get real time experience with TWITTER BOOTSTRAP.

$ rails new twitter-bootstrap-rails-3-demo

2. Set Up Source Control

If you’re creating an app for deployment into production, you’ll want to set up a source control repository at this point. Type:

$ git init
Initialized empty Git repository in /home/pravinmishra/workSpace/twitter-bootstrap-rails-3-demo/.git/
$ git add .
$ git commit -m “first commmit”
[master (root-commit) ffeb58c] first commmit
37 files changed, 1201 insertions(+)
create mode 100644 .gitignore
create mode 100644 Gemfile

3. Create a Home Page.

$ rails g scaffold blog title:string body:text –skip-stylesheets

Note that we’ve used the --skip-stylesheets option in the scaffold as we want to use Bootstrap’s CSS instead of the scaffolding’s. We’ve also migrated the database so that the products table is created.

$ rake db:create
$ rake db:migrate
==  CreateBlogs: migrating ====================================================
— create_table(:blogs)
-> 0.0026s
==  CreateBlogs: migrated (0.0028s) ===========================================

And Delete the default home page from your application:

$rm public/index.html

Next, set a route to your home page. Edit the file config/routes.rb and replace:

root :to => 'blogs#index'

Now it's time to run server and take a look to blog..........

Here’s what the generated scaffold page looks like. It isn’t very pretty as we don’t have any styling applied.


4. It’s time to add Twitter Bootstrap. Add twitter bootstrap gem in gemfile and do bundle update.

gem “twitter-bootstrap-rails”
$ bundle update
Using sqlite3 (1.3.6)
Using therubyracer (0.10.1)
Using twitter-bootstrap-rails (2.0.7)
Using uglifier (1.2.4)

And we are saw latest version of bootstrap 2.0.7 is install on application.

Now we need to generate some file by using command

$ rails g bootstrap:install
insert  app/assets/javascripts/application.js
create  app/assets/javascripts/
create  app/assets/stylesheets/bootstrap_and_overrides.css.less
gsub  app/assets/stylesheets/application.css
gsub  app/assets/stylesheets/application.css

As we saw it create some css and javascript file for us in assets folder.  One key file that was generated is bootstrap_and_overrides.css.less. This file loads up Bootstrap and it’s a good place to customize the styling to suit your application. After we restart the server and reload the page we can see that the styling is already starting to look better, but there’s still a lot to do.



5. Customize your css.

As we see button having default css we can make it more decent adding bootstrap class properties. Here we adding <%= f.submit :class => “btn btn-primary” %> , class to submit button in page views/blog/_form.html.rb file. Now once more take a look to browser.

Button style has changed as expected. The is a lot more css and javascript features of twitter boostrap. Once take a look and play with it.

That’s it. Enjoy………..!!!!!!!!!!!!!!!!!!!!!

PostgreSQL installation in Ubuntu 12.04

PostgreSQL is a powerful and reliable object-relational database system. It’s a great alternative for MySQL. It is as easy to set up, performs better and offers far more features.

1. Make sure you already have install python-software-properties

$sudo apt-get install python-software-properties

2.Add PPA repository to my Ubuntu.

$sudo add-apt-repository ppa:pitti/postgresql

3. After adding PPA, update your system apt:

$sudo apt-get update

4.Finally install postgresql-9.1:

$sudo apt-get install postgresql

if you having any error, make sure you already install libpq-dev.The libpq-dev package is for compiling wrappers/clients against libpq.

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

5.Now check it out installation is successful or…..

$ locate postgresql

6. If done!!!

Check the install version.

$psql -V

7.Now let’s take look to postgres console

$su postgres

7(a) Setup Root User ‘posrgres’

$sudo passwd postgres

give the postgres user a (unix) password,Now we can switch to the user postgres using command

$ su postgres

8. That’s it for postgers installation. If you want to access postgres from remote, Mean localhost. You need to perform some addition setting to postgres conf file.

First we edit the file postgresql.conf:

$ cd /etc/postgresql/9.1/main

List all file in main folder

$ ls -la

total 80
drwxr-xr-x 2 postgres postgres 4096 2012-05-17 18:05 .
drwxr-xr-x 3 postgres postgres 4096 2012-04-07 12:44 ..
-rw-r–r– 1 postgres postgres 316 2012-04-07 12:44 environment
-rw-r–r– 1 postgres postgres 143 2012-04-07 12:44 pg_ctl.conf
-rw-r—– 1 postgres postgres 4653 2012-05-17 18:05 pg_hba.conf
-rw-r—– 1 postgres postgres 4649 2012-04-09 19:29 pg_hba.conf.bak.original
-rw-r—– 1 postgres postgres 1636 2012-04-07 12:44 pg_ident.conf
-rw-r–r– 1 postgres postgres 19235 2012-04-07 12:44 postgresql.conf
-rw-r–r– 1 postgres postgres 19235 2012-04-09 19:29 postgresql.conf.bak.original
-rw-r–r– 1 postgres postgres 378 2012-04-07 12:44 start.conf

I have already back of config file, you need to make back up for further need

$ cp pg_hba.conf pg_hba.conf.bak.original
$ cp postgresql.conf postgresql.conf.bak.original

9. Make changes to pg_hba.conf (authetification methods).

host    all         all       trust          # md5 -> trust

10.You make change in config file, So once restart you postgres

$sudo /etc/init.d/postgresql restart
*Restarting PostgreSQL 9.0 database server
That’s it. Enjoy………

Devise Authentication in Rails 3

Hi folk, We are writing step by step devise authentication for a sample app over rails 3.2.3 and ruby 1.9.3.


To create the application, you can cut and paste the code from the blog into your console ELSE do git clone rails_3_devise app and get real time experience with device. 

1. Creates a new Rails app named rails_3_devise on your computer. Type the below command.


$ rails new rails_3_devise –d mysql


Use the flag  –d mysql specify mysql as database, As we know rails having default sqlite db.

Now we move to app by typing 

$ cd rails_3_devise –d mysql


2. Finally we have to push our code to github, So doing some basic cammand to initialize git and pushing code to github  .
$ git init
Initialized empty Git repository in /home/maisa/workspace/rails_3_devise/.git/
$ git add .
$ git commit -m “First commint” 


3. Once we make sure our app is working



$ rails s -p 4000 


And check from browser http://localhost:4000/


4. Set Up Authentication, First things first, add “devise” to your rails Gemfile in the root directory of your application And do


$ bundle update

Fetching gem metadata from……&#8230;

Using warden (1.1.1)

Using devise (2.1.0)

Using jquery-rails (2.0.2)

Using rails (3.2.3)

Using sass (3.1.18)


We will see latest devie 2.1.0 has installed


Now following the install docs on the Devise project page. And run


$ rails g devise:install

create  config/initializers/devise.rb

create  config/locales/devise.en.yml



Some setup you must do manually if you haven’t yet:


1. Ensure you have defined default url options in your environments files. Here

is an example of default_url_options appropriate for a development environment

in config/environments/development.rb:


config.action_mailer.default_url_options = { :host => ‘localhost:3000’ }


In production, :host should be set to the actual host of your application.


2. Ensure you have defined root_url to *something* in your config/routes.rb.

For example:


root :to => “home#index”


3. Ensure you have flash messages in app/views/layouts/application.html.erb.

For example:


<p><%= notice %></p>

<p><%= alert %></p>


4. If you are deploying Rails 3.1 on Heroku, you may want to set:


config.assets.initialize_on_precompile = false


On config/application.rb forcing your application to not access the DB

or load models when precompiling your assets.




Alright, based on the install output it looks like we need to do a little setup work… Make sure we are following all above instruction.

After you are finished configuring the application its time to create your user model.

$ rails generate devise User

invoke  active_record

create    db/migrate/20120516110556_devise_create_users.rb

create    app/models/user.rb

invoke    test_unit

create      test/unit/user_test.rb

create      test/fixtures/users.yml

insert    app/models/user.rb

route  devise_for :users


Great, lets take a look at what the generator created starting with the migration.


class DeviseCreateUsers < ActiveRecord::Migration

def change

create_table(:users) do |t|

## Database authenticatable

t.string :email,              :null => false, :default => “”

t.string :encrypted_password, :null => false, :default => “”


## Recoverable

t.string   :reset_password_token

t.datetime :reset_password_sent_at


## Rememberable

t.datetime :remember_created_at


## Trackable

t.integer  :sign_in_count, :default => 0

t.datetime :current_sign_in_at

t.datetime :last_sign_in_at

t.string   :current_sign_in_ip

t.string   :last_sign_in_ip


## Confirmable

# t.string   :confirmation_token

# t.datetime :confirmed_at

# t.datetime :confirmation_sent_at

# t.string   :unconfirmed_email # Only if using reconfirmable


## Lockable

# t.integer  :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts

# t.string   :unlock_token # Only if unlock strategy is :email or :both

# t.datetime :locked_at


## Token authenticatable

# t.string :authentication_token






add_index :users, :email,                :unique => true

add_index :users, :reset_password_token, :unique => true

# add_index :users, :confirmation_token,   :unique => true

# add_index :users, :unlock_token,         :unique => true

# add_index :users, :authentication_token, :unique => true




Now let’s take a look at our User model.

class User < ActiveRecord::Base

# Include default devise modules. Others available are:

# :token_authenticatable, :confirmable,

# :lockable, :timeoutable and :omniauthable

devise :database_authenticatable, :registerable,

:recoverable, :rememberable, :trackable, :validatable


# Setup accessible (or protected) attributes for your model

attr_accessible :email, :password, :password_confirmation, :remember_me

# attr_accessible :title, :body



We don’t need to setup our routes for user because devise has already added devise_for :users to our config/routes.rb for us. If we then run rake routes from the command line we get:


$ rake routes user
              home_index GET    /home/index(.:format)          home#index
        new_user_session GET    /users/sign_in(.:format)       devise/sessions#new
            user_session POST   /users/sign_in(.:format)       devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)      devise/sessions#destroy
           user_password POST   /users/password(.:format)      devise/passwords#create
       new_user_password GET    /users/password/new(.:format)  devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format) devise/passwords#edit
                         PUT    /users/password(.:format)      devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)        devise/registrations#cancel
       user_registration POST   /users(.:format)               devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)       devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)          devise/registrations#edit
                         PUT    /users(.:format)               devise/registrations#update
                         DELETE /users(.:format)               devise/registrations#destroy
                    root        /                              home#index

Finally it’s time to migrate our database and create our user model.

$ rake db:migrate

==  DeviseCreateUsers: migrating ==============================================

— create_table(:users)

-> 0.0175s

— add_index(:users, :email, {:unique=>true})

-> 0.0010s

— add_index(:users, :reset_password_token, {:unique=>true})

-> 0.0012s

==  DeviseCreateUsers: migrated (0.0202s) =====================================


5. Now let’s create a Home Page and add custom message to index page


$ rails generate controller home index –no-controller-specs      create  app/controllers/home_controller.rb

route  get “home/index”

invoke  erb

create    app/views/home

create    app/views/home/index.html.erb

invoke  test_unit

create    test/functional/home_controller_test.rb

invoke  helper

create    app/helpers/home_helper.rb

invoke    test_unit

create      test/unit/helpers/home_helper_test.rb

invoke  assets

invoke    coffee

create      app/assets/javascripts/

invoke    scss

create      app/assets/stylesheets/home.css.scss


And remove default public index page, As we expecting home/index will be our default page.


$ rm public/index.html

And will add root url to routes.rb file  and protect user controller adding  


before_filter :authenticate_user!


At top of index action.


root :to => “home#index”




Now  we almost done. Finally we need to create  an Application Layout with few login, logout,sign links. For that we Create a shared directory under app/views/. Then create the file app/views/shared/_navigation.html.erb and add:


<% if user_signed_in? %>


<%= link_to(‘Logout’, destroy_user_session_path, :method=>’delete’) %>


<% else %>


<%= link_to(‘Login’, new_user_session_path)  %>


<% end %>

<% if user_signed_in? %>


<%= link_to(‘Edit account’, edit_user_registration_path) %>


<% else %>


<%= link_to(‘Sign up’, new_user_registration_path)  %>


<% end %>


Then use these partials in your app/views/layouts/application.html.erb file, like this:


<%= render ‘shared/navigation’ %>
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, :id => “flash_#{name}” if msg.is_a?(String) %>
<% end %>
<%= yield %>


Now Add stylesheet rules to the application.css.scss file:


header nav ul {
list-style: none;
margin: 0 0 2em;
padding: 0;
header nav ul li {
display: inline;
#flash_notice, #flash_alert {
padding: 5px 8px;
margin: 10px 0;
#flash_notice {
background-color: #CFC;
border: solid 1px #6C6;
#flash_alert {
background-color: #FCC;
border: solid 1px #C66;


That all coding part.  


Now it’s time to start our rails server and see what devise has given us. Run rails server from the command line and lets travel to “localhost:4000/


That’s expected. As we protected our home page. Now we need to sign_up and post sign_in. After using right credentials we will see






Thanks, Enjoy……………….

sproutcore introduction

SproutCore is an open source javascript framework. Its basically allow us to create web application with advanced capabilities and a user experience comparable to that of  desktop application.  When developing a SproutCore application, all code is written in JavaScript. With SproutCore, we can build rich, interactive applications in the web in less code than most simple web pages require today.


Node.js Hello world code

Let me write the program and will explain line by line.

http = require(‘http’)
    res.writeHead(200, {‘content-Type’:’text/html’});
    res.write(“<h1>Hello Word!</h1>”)
    res.end(“<h2>This is the end!</h2>”);
}).listen(3000, “”);
console.log(“Server running at;)

Let’s create a new file called hello_world.js.

Now Node comes with a handfull of libraries to make the development of event-based servers easy.

To use one of the available libraries, We simply include its module using the require function.

http_object = require(‘http’)

The require function will return an object representing the module that you pass into it and you can capture that object in a variable.


For running app, we need to create HTTP server.  Node provides the http library. With reference to http_object create server.


The createServer that takes a callback function and returns a new server object.

The callback function is what Node calls a listener function and it is called by the server whenever a new request comes in.

Whenever an HTTP request is made, the listener function will be called and objects representing the HTTP request and response will be passed into the function.


Then first need to write the appropriate HTTP headers.

res.writeHead(200, {‘content-Type’:’text/html’});

The writeHead function takes a couple of arguments. The first is an integer value representing the status code of the request which for us will be 200, in other words,

Then we’ll call the write function and pass in the data that you wish to send.

 res.write(“<h1>Hello Word!</h1>”)

Now that we’ve created our server, we need to set it up to listen for new requests.

listen(3000, “”);

The listen function on our server object and pass in a port number for it to listen on(3000). The listen function also takes an optional second parameter which is the hostname URL(“”),

Finally, let’s print out a message to let us know that our server is running

console.log(“Listening on“).

There we go, now let’s run our app by calling node and passing to it the name of the file we want it to execute.

node hello_world.js and open browser “

That’s it. Enjoy………………..

Install Node.js on Ubuntu System

Let’s take a quick look to install node.js on UBUNTU system.

1. Download node.js from

Then open terminal and go to download folder and extract node.tag file

2. tar xvf .node-v0.6.17.tag.gz

3. Now install libssl-dev

sudo apt-get install libssl-dev

4. Move to extracted node-v0.6.17 folder

cd node-v0.6.17

5. then fire ./configure command from console.


Will do a lot of configuration setting for us.

6. Type make and post sudo install make

7. Make sure node and npm had got install (We not need to install npm seperatly, it’s build in node.js itself)

node -v

npm  -v

That’s it. Enjoy with node.js

Hopefully in next post will write Hello world program.