Thursday, October 18, 2012

GIT rebasing and pull request processing

Minor explanation with example

Checkout to master

$ git pull --rebase origin master

Create a new branch for each feature. Say we are implementing a new feature => feature1, create a branch

$ git checkout -b feature1 

Now we have a copy of master in feature1 branch. Now you can work on this branch. It will be better to commit all changes at last before pushing the branch. If we have created this branch long time ago, by the time the master would have got updated from other developers. So, checkout to master and run $ git pull --rebase origin master and then checkout to feature1.

$ git rebase master
If merge conflict occurs in our rebase then resolve the conflict and stage the files, please dont commit them and run $ git rebase --continue or abort the rebase by $ git rebase --abort.

Commit and push the new branch

$ git push origin feature1

When its done, after accessing the branch through browser initiate the pull request. On initiating pull request we can set the base merge branch. The pull request can be accepted and merged if a link below called Merge is shown in green (ready to go).

If we need to merge multiple commits to one 

Now use git log, which lists the commits. If we want to merge the last 2 commits then use

$ git rebase -i HEAD~2 

Update the commits to be squashed and picked. On squashing the commit will be merged to a the picked one then, save the commit and push the branch using 

$ git push -f origin feature1 


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.


Friday, March 2, 2012

PHP 5.4 Released Providing Built-in webserver

Key Features

  • New syntax like Traits.
  • <?= is now always available, regardless of the short_open_tag ini option
  • Class member access on instantiation has been added, e.g. (new Foo)->bar()
  • Class::{expr}() syntax is now supported.
  • The keyword 'insteadof' is introduced with PHP 5.4 (Traits)
  • Built-in webserver in CLI mode to simplify development workflows and testing
  • Cleaner code base (removal of multiple deprecated language features)

Traits :: mechanism for code reuse in single inheritance languages

Built-in webserver

Added for development purpose only. 

Start Webserver

# php -S localhost:8000

To get a specific document root use

# php -S localhost:8000 -t folder_name/

If a PHP file is given on the command line when the web server is started it is treated as a "router" script for the web server. The script is run at the start of each HTTP request. If this script returns FALSE, then the requested resource is returned as-is. Otherwise the script's output is returned to the browser.



Tuesday, January 10, 2012

Zend Pagination

Get the results in controller and assign to view.

Inside controller 

$users = $user->getAllUsers();

$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($users));

$page = $this->_getParam('page');
if( $page == null || $page == ""){
$page = 1;
$this->view->paginator = $paginator;

Inside View

<?php echo $this->paginator; ?>
//Will render first, page numbers, and last anchor tags
<?php foreach ($this->paginator as $item): ?>
<input type="checkbox" />
<?php echo $item['name'] ?>
<?php echo $item['email'] ?>
<?php endforeach; ?>

Inside Pagination_controller.phtml

<?php if ($this->pageCount): ?>
<div class="pagination">
<?php if (isset($this->previous)): ?>
< a href="<?php echo $this->url(array('page' => $this->previous)); ?>" title="Previous Page">« Previous</a>"<?php else: ?>
<span class="disabled">« Previous</span>
<?php endif; ?>

<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
< a href="<?php echo $this->url(array('page' => $page)); ?>" class="number" title="1"> <?php echo $page; ?></a>
<?php else: ?>
<?php echo $page; ?>
<?php endif; ?>
<?php endforeach; ?>

<?php if (isset($this->next)): ?>
< a href="<?php echo $this->url(array('page' => $this->next)); ?>" title="Next Page">Next »</a>
<?php else: ?>
<span class="disabled">Next »</span>
<?php endif; ?>
<?php endif; ?>

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 ::