Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Wednesday, December 3, 2014

Copy all the lines from a file using vim to another

First open the file using 'vim'.

e.g. vim testfile.txt

Then to copy use "ggVGy" or ":%y a", now the content is in the clipboard.

Open a new terminal and open a new file with 'vim' where you are going to paste it.

Then use "p" or "P" to put the content in the file from the clipboard.

Tuesday, April 3, 2012

Installing Ruby on Rails using RVM in Ubuntu

Please follow the commands given in the steps
Step 1 :: Install RVM
$ bash -s stable < <(curl -s

$ rvm get latest

$ rvm reload

$ rvm -v
e.g. rvm 1.10.2 by Wayne E. Seguin <>, Michal Papis <> []

Step 2 :: Install Ruby 1.9.3

rvm installation notes for your operating system version

$ rvm requirements

$ rvm install ruby-1.9.3-p125

Set default
$ rvm --default use ruby-1.9.3-p125
$ ruby -v
e.g. ruby 1.9.3p125 (2012-02-16 revision 34643) [i686-linux]

Step 3 :: Check for gem installation
$ gem -v
e.g. 1.8.21

If gem is installed, update gem system
$ gem update --system

Step 4 :: Update Rake

$ gem update rake
$ rake --version

Step 5 :: Create rails gemset

$ rvm ruby-1.9.3-p125@rails32 --create --default

Step 6 :: Update Bundler

$ gem update bundler
$ bundle --version

Step 7 :: Install Rails 3.2.3

$ gem install rails
$ rails -v

Step 8 :: JavaScript Runtime for Ubuntu

$ sudo apt-get install nodejs

Step 9 :: Create a Rails app

$ rails new app_name


Thursday, March 29, 2012

Ruby on Rails First Application

create a new project :: rails new app_name
By default the db adapter will be sqlite. To change that update in the config/database.yml

for mysql use
 adapter: mysql2
 encoding: utf8
 database: db_name
 pool: 5
 username: root
After that update Gemfile in the project route to mysql2 from sqlite
run in command :: bundle install
If the mysql adapter is not found needs to install mysql2

for that please follow the steps

sudo apt-get install libmysql-ruby libmysqlclient-dev
gem install mysql2

After bundle install

create db by

rake db:create

start rails server :: rails server
stop :: ctrl+c

Simple application for blog

Create controller action and views using generate

rails generate controller home index

You need to remove the default page from public, then add route to home controller

rm public/index.html

got to config/routes.rb find “root :to” edit the file to have

Blog::Application.routes.draw do
root :to => "home#index"

Create post table using scaffolding

rails generate scaffold Post name:string title:string content:text

Now a migration file will be created inside db/migrate

rake db:migrate

Now check the db table will be created

Through scaffolding, all the option add, edit, delete, view actions will be added automatically. Now the link to the post can be added inside the home/index.html.erb

<h1>Hello, Rails!</h1>
<%= link_to "My Blog", posts_path %>

link_to create the href link with the post path.

Please check your url debug your self. e.g.

Note :: When ever scaffolding or generate or any rails command is executed stop the rails server before that.


Wednesday, January 4, 2012

Openshift with MySQL PHPMyAdmin

Click here to set up the Openshift server with Ubuntu.

Install Mysql for Openshift

/var/lib/gems/1.8/bin/rhc-ctl-app -a APPNAME -e add-mysql-5.1 -l EMAILID -p PASSWORD

Now Mysql is installed and access details will be obtained after running the above command.

Install PHPMyAdmin 

Download PHPMyadmin 


Go to application folder (local) and unzip the downloaded file

cd APP_FOLDER_NAME/phpunzip ../../

Rename the folder (name will be used to access the mysql [domainname/phpmyadmin_foldername])

mv phpMyAdmin-3.4.8-all-languages phpmyadmin

Update Configuration file for phpmyadmin

cd phpmyadmincp$cfg['blowfish_secret']     = 'some value'; //COOKIE AUTH$cfg['Servers'][$i]['host'] = 'hostadress'; //host address obtained on mysql installation

Add files to be pushed to the server, and commit the changes

git add -Agit commit -m 'phpmyadmin setup'git push 

After pushing the changes to server, mysql can be accessed through

Then login using the credentials obtained on MySql installation

Openshift with Ubuntu

Step 1 :: Install rubygems and openssh

sudo apt-get install git-core openssh-client ruby-full  sudo apt-get install rubygems1.8

Step 2 :: Install gems

sudo gem install --source --source rhc

Step 3 :: Create domain using RHC command

/var/lib/gems/1.8/bin/rhc-create-domain -n DOMAIN_NAME -l EMAILID -p PASSWORD

RHLogin is required
Domain name :: doesnt support non-alphanumeric characters
EMAILID :: registered login id for Redhat or Openshift which has express access
PASSWORD :: Login password 

Step 4 :: Create application ( with valid application type [raw-0.1, php-5.3, jbossas-7.0, rack-1.1, jenkins-1.4, perl-5.10, wsgi-3.2])

/var/lib/gems/1.8/bin/rhc-create-app -a APP_NAME -t php-5.3 -l EMAILID -p PASSWORD

Step 5 :: Repo folder will be created in the local machine also, now the application can be updated and commited to the server using git commands (git push).

Ref Adding Zend Application ::

Thursday, April 28, 2011

Sonar for PHP code coverage

Sonar is quality management platform, checking code quality based on certain rules and custom rules.

Sonar runs on java so requires JDK v1.5 or later.

After that download latest version of sonar from 

Starting sonar server

[PATH_TO_SONAR]/bin/[OS]/ console


/usr/local/sonar/linux-x86-32/ console/start

Now the sonar has been started at http://localhost:9000 by default, config details of sonar can be updated
at inside conf.

For running php code coverage

Sonar is basically used for Java projects which can be extended for php using maven plugin.
So download latest maven from


Now for adding project to sonar pom.xml file has to be created in the root folder of the project.

<?xml version="1.0"?> <project > <modelVersion>1.0.0</modelVersion> <groupId>Group_name</groupId> <artifactId>name</artifactId> <name>Project</name> <version>1.0</version> <packaging>pom</packaging> <build> <directory>build</directory> <sourceDirectory>application</sourceDirectory> <testSourceDirectory>tests</testSourceDirectory> </build> <properties> <sonar.language>php</sonar.language> </properties> </project>


For running php code coverage it requires phpunit to be configured.
Then coverage report is created using phpunit.


phpunit --coverage-clover build/logs/phpunit.coverage.xml --log-junit build/logs/phpunit.xml

According to the pom.xml file the reports are created inside build/logs folder.

Some of the additional plugins are required for maven to run for PHP.


  1. Install PHP runtime with the corresponding xdebug extensions. Version 5.2.6 or newer is required.
  2. Install PEAR. Version 1.8.0 or newer is required
  3. Install PHPUnit version 3.5.5 (strictly)
  4. Install phpcpd version 1.3.0 (strictly)
  5. Install PHPDepend PHPMD version 0.2.5
  6. Install PHP_CodeSniffer version 1.3.0

After running PHPUnit, it ready for sonar to run with maven from project root folder.

[PATH_TO_MAVEN]/bin/mvn sonar:sonar

with -e option it lists the trace errors. After Build is success the web is updated with the new build reports. 


Wednesday, November 10, 2010

XHProf PHP Profiler

apt-get install php5-common
pecl config-set preferred_state beta
pecl install xhprof
If it was not possible from the above steps please use this
tar xvf xhprof-0.9.2.tgz
cd ./xhprof-0.9.2/extension/
./configure --with-php-config=/usr/local/bin/php-config
make install
make test
After installation add to the php.ini file
Now you need to create 2 files header.php and footer.php
if (extension_loaded('xhprof')) {
include_once '/usr/local/lib/php/xhprof_lib/utils/xhprof_lib.php';
include_once '/usr/local/lib/php/xhprof_lib/utils/xhprof_runs.php';
if (extension_loaded('xhprof')) {
$profiler_namespace = 'myapp'; // namespace for your application
$xhprof_data = xhprof_disable();
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, $profiler_namespace);
// url to the XHProf UI libraries (change the host name and path)
$profiler_url = sprintf('', $run_id, $profiler_namespace);
echo '<a href="'. $profiler_url .'" target="_blank">Profiler output</a>';
Now the files are ready we have to include in all pages 
of our website. We can do that by adding it to the .htaccess file.
php_value auto_prepend_file /var/www/xhprof/header.php
php_value auto_append_file /var/www/xhprof/footer.php