15 November 2014

Merging branches on two different remotes GIT

Steps to merge branches located on two different remotes.

In this example lets consider we have a repo on both and Github & BitBucket :

Step 1: Clone the repo which you want finally to hold all the changes.

I will choose Github
git clone <repo URL>

Step 2: Add remote for Bitbucket or other repo into the cloned repo
git remote add origin_bitbucket <url>

Step 3: Checkout the branch from Bit Bucket remote 
git checkout origin_bitbucket/<branch name>

Step 4: Check out the branch you want to merge into
git checkout origin/master

Step 5: Merge BitBucket branch into it
git merge origin_bitbucket/<branch name>

08 June 2014

Git fatal reference error on deployment or submodule update

Sometimes we face this issue with GIT
fatal: reference is not a tree: d80ee5f27b06e84d40a7d2758525b682aaba7d72
This is because the module has not been pushed to the main repo or the branch has not been pulled on the machine the command is being executed.

Branch issues 
git checkout master
git fetch origin

Submodule issues

git submodule update

Best Jenkins Plugins I use !


1. Compress Artifacts Plugin

Keeps build artifacts compressed to save disk space on the master. 

2. Copy To Slave Plugin

This plugin allows copying files located somewhere on the master node into the jobs' workspaces, whether their builds take place on the master node or on slave nodes. 

3. Cucumber Reports Plugin

This plugin creates pretty cucumber-jvm html reports on jenkins 

4. Delete log

This plugin add action delete log to build page. If the build is build of matrix job, the action delete log for all its configurations too. 

5. Green Balls

Because green is better than blue! For color blind support configure user property. 

6. HTML Publisher plugin

This plugin publishes HTML reports. 

7. Jenkins disk-usage plugin

This plugin counts disk usage. 

8. Jenkins Gravatar plugin

This plugin shows Gravatar avatar images for Jenkins users. 

9. Timestamper

Adds timestamps to the Console Output. 

10. embeddable-build-status

This plugin adds the embeddable build status badge to Jenkins so that you can easily hyperlink/show your build status from elsewhere. 

Using Frank with Rubymotion

Writing acceptance tests for iOS application in Rubymotion

Steps involved

1) Add the motion-frank gem to the Gemfile
2) Run the initializer rake frank:init_features
3) Now you have the features directory.
4) Write a sample test

eg: 
Feature: Navigating around the app / smoke test
  As a user
  I want to be able to get to all parts of the app
  So I can use it and not get confused or lost
Background:
  Given I launch the app
  Given I am on the search Screen with empty search
Scenario: Search
  Given I am on the search screen
  Then I should see a navigation bar with label text "Search"
  When I fill in a search term
  Then I should see a navigation bar with label text "Results"
5) Save this as a xyz.feature file
6) Run rake frank to see this test fail
7) Add the step definition file in the features/step_definitions named something like xyz_steps.rb
8) Add step methods describing the steps and what should happen on the simulator to match the test. 

eg.
Given(/^I am on the search Screen with empty search$/) do
  wait_for_element_to_exist_and_then_touch_it("textField placeholder:'Search by name'")
end

Given(/^I am on the search screen$/) do
  check_element_exists("textField placeholder:'Search by name'")
end 

and go on ....

Go through the sameple steps and implementation in the frank-cucumber library to get hold of more methods to test the UI.

Also you can use rake frank:symbiote to get the list of UI elements accessible for testing in a simulator.

Run "rake frank:symbiote" in the Rubymotion directory and once the simulator is up with the application open the browser and navigate to "localhost:37265" 


Quick Tips : 

1) For ruby code which like occurs in multiple step file , write ruby files in the support folder such as
def check_search_bar
  check_element_exists("textField placeholder:'Search by name'")
end
Now you can use this check_search_bar method in any step definition file & reduce the amount of code you write to get your code working.


Happy Testing with cucumber !! Its fun. 











30 April 2013

Starting With Rubymotion



Rubymotion

 RubyMotion is a revolutionary toolchain for iOS.
It lets you quickly develop and test native iOS applications for iPhone or iPad, all using the awesome Ruby language you know and love.

29 March 2013

TCS RSS Feed Reader 123


TCS RSS Feed
This is an iOS application build using

Running on Simulator/Device

You will need Rubymotion installed on your Mac.
  1. Clone repo git clone git@github.com:upadhyay-ashish/TCSRssReader.git
  2. Bundle gems bundle install
  3. Setup cocoapods pod setup
  4. Setup Developer license reference in the Rakefile
  5. To run on simulator rake else to run on a Device rake device
  6. To create a distribution IPA rake archive:distribution

25 February 2013

Replacing master with a branch GIT



This will help us to overwrite the master branch with a new branch incase the new branch is in a better state than the master


  • git checkout seotweaks
  • git merge -s ours master
  • git checkout master
  • git merge seotweaks



Thanks

08 January 2013

Using Oracle JDBC with JRuby on Mac OSx

Please follow the below steps to create a jruby library to connect to any oracle database on Mac OS x using Java ODBC drivers.


STEP 1: Create the Library folder and the Ruby file. eg Sample.rb
Step 2 : Add Gemfile to enable using jruby to connect to the database

Step 3 :  add the following gems to the Gemfile
gem 'activerecord'
gem "activerecord-jdbc-adapter"

Step 4 : In the ruby file Sample.rb here please use the following lines and then write appropriate  code to access the data.

class Person < ActiveRecord::Base

    establish_connection(
      :adapter  => 'jdbc',
      :driver   => 'oracle.jdbc.driver.OracleDriver',
      :url      => 'jdbc:oracle:thin:@server:port/sid',
      :username => 'ors',
      :password => 'ors'
      )

      self.table_name = :table_name_here

        def self.all

          connection.select_all <<-SQL
                  select * from table_name_here
             SQL
        end
 end

Step 5 : Go to terminal , run


bundle install 
jruby Sample.rb

Step 6 : If there is a driver not found error please download the driver from oracle site here 
and place it in /Library/Java/Extensions/ on your mac.

Have Fun !










22 October 2012

Cloning a specific GIT branch from a repository


Step 1 : Clone the master branch
git clone <repo master>
Step 2 : Clone the specific GIT branch
git fetch origin +branchname:branchname
Step 3 : Switch to the branch
git checkout branchname
Step 4 : Check the file difference between the master and the branch 
git diff --name-status master..sibos

28 September 2012

Migrating code from SVN to GIT

Install git-svn on ubuntu or linux

Simple command to begin with
$ git-svn clone <svn repo link> --no-metadata -s my_project

You need to do a bit of post-import cleanup. For one thing, you should clean up the weird references that git svn set up. First you’ll move the tags so they’re actual tags rather than strange remote branches, and then you’ll move the rest of the branches so they’re local.

To move the tags to be proper Git tags, run

$ cp -Rf .git/refs/remotes/tags/* .git/refs/tags/
$ rm -Rf .git/refs/remotes/tags

This takes the references that were remote branches that started with tag/ and makes them real (lightweight) tags.

Next, move the rest of the references under refs/remotes to be local branches:

$ cp -Rf .git/refs/remotes/* .git/refs/heads/
$ rm -Rf .git/refs/remotes

Now all the old branches are real Git branches and all the old tags are real Git tags. The last thing to do is add your new Git server as a remote and push to it. Here is an example of adding your server as a remote:

$ git remote add origin git@my-git-server:myrepository.git

Because you want all your branches and tags to go up, you can now run this:

$ git push origin --all

11 August 2012

Fix Readline error Ubuntu

Fix readline error with Ruby

sudo apt-get install libreadline-dev

cd ~/.rvm/src/ruby-1.8.7-p249/ext/readline

ruby extconf.rb && make && make install


Thanks

10 August 2012

Capistrano + GIT : Too many arguments while deployment

Issue : shell command failed with return code 33024

It's a ruby + git clone + windows issue.

If I chain commands with && while calling system(cmd) from ruby, chaining "git clone" with other commands is not fine. Git clone perceives the chained commands as its own continuation, i.e. as a destination directory, unless I run it from the command line.
As I couldn't find any references or solutions to this problem on the internet, I put a hack to capistrano code, so "git clone" is executed separately. 

In <ruby directory>\lib\ruby\gems\1.8\gems\capistrano-2.5.18\lib\capistrano\recipes\deploy\strategy\base.rb after the line 53 (cmd = cmd.split...)
add the following lines:
if cmd =~ /\s\&\&\s/ && cmd =~ /^git\s+clone/
   cmd1, cmd = cmd.split(" && ", 2)
    super(cmd1)
end

it checks if it's a chained command and the first command is "git clone", and if such it executes it separately. It may not work for all possible cases.

Also you can try using ubuntu from your local.

 

09 August 2012

Installing RMagick with Imagemagic on Windows 7/Vista


2. Install Imagemagick
Use the 32 bit version, 64bit is not working.
http://www.imagemagick.org/download/binaries/ImageMagick-6.7.6-1-Q16-windows-dll.exe (2012-03-22)
Install dev headers (Check!)
Install into C:\opt\

3. Restart the console/cmd prompt/IDE/.. or just restart windows to make Imagemagick commands available

4. Install rmagick
gem install rmagick --platform=ruby -- --with-opt-lib=C:/opt/ImageMagick-6.7.6-Q16/lib --with-opt-include=c:/opt/ImageMagick-6.7.6-Q16/include

13 June 2012

Installing Ruby on Mac OS

STEP 1 Installing XCode


Please install XCode + Developer Tools from the App Center.
XCode is needed to install the Developer tools used in compilation of the Ruby packages for installation on the system.

STEP 2 Install RVM


Install RVM using the command
  • curl -L get.rvm.io | bash -s stable
This will install RVM on your system.
Please close and open the terminal again to load RVM.
To verify the RVM installation , open Terminal and type
  • rvm requirements
This will show a help doc.

Step 3 Installing required RVM packages before installing Ruby


Open Terminal and run the below mentioned commands one after the another
  • rvm pkg install zlib
  • rvm pkg install openssl
  • rvm pkg install iconv
  • rvm pkg install readline
  • rvm pkg install autoconf

Step 4 Installing Ruby


Open the Terminal and type the following command
  • rvm install 1.8.7 --with-gcc=clang
Here 1.8.7 reflects the Ruby version 1.8.7 and the latest patch, so to install any specific version or path you specify it by altering the above mentioned command eg.
  • rvm install 1.8.7-p334 --with-gcc=clang
  • rvm install 1.9.3 -C --with-gcc=clang

Step 5 Verify the installation


Open a new Terminal window and type
  • rvm list This will display the list of the different rubies installed on the system.
    To use a specific Ruby version use the following command
  • rvm use 1.8.7
  • rvm use 1.8.7-p334
  • rvm use 1.9.3 To make a Ruby version default for the system use the command
  • rvm alias create default 1.8.7
  • rvm alias create default 1.8.7-p334
  • rvm alias create default 1.9.3
This Ruby version will be the default version of Ruby on the system , to change to other versions of Ruby use the above mentioned commands.
To use default incase of switching use
  • rvm use default
To remove RVM from the system use the command
  • rvm implode

Installing Ruby on Ubuntu

Step 1 Verifying


Verify the system is update and then run a sudo apt-get update on the terminal.

Step 2 Installing RVM on Ubuntu


Open terminal and type
  • curl https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable
This will install RVM on your system.
Please close and open the terminal again to load RVM.
To verify the RVM installation , open Terminal and type
  • rvm requirements
This will show a help doc.

Step 3 Installing required RVM packages before installing Ruby


Open Terminal and run the below mentioned commands one after the another
  • rvm pkg install zlib
  • rvm pkg install openssl
  • rvm pkg install iconv
  • rvm pkg install readline
  • rvm pkg install autoconf

Step 4 Installing Ruby


Open the Terminal and type the following command
  • rvm install 1.8.7 -C --with-openssl-dir=$rvm_path/usr --with-zlib-dir=$rvm_path/usr
Here 1.8.7 reflects the Ruby version 1.8.7 and the latest patch, so to install any specific version or path you specify it by altering the above mentioned command eg.
  • rvm install 1.8.7-p334 -C --with-openssl-dir=$rvm_path/usr --with-zlib-dir=$rvm_path/usr
  • rvm install 1.9.3 -C --with-openssl-dir=$rvm_path/usr --with-zlib-dir=$rvm_path/usr

Step 5 Verify the installation


Open a new Terminal window and type
  • rvm list This will display the list of the different rubies installed on the system.
    To use a specific Ruby version use the following command
  • rvm use 1.8.7
  • rvm use 1.8.7-p334
  • rvm use 1.9.3 To make a Ruby version default for the system use the command
  • rvm alias create default 1.8.7
  • rvm alias create default 1.8.7-p334
  • rvm alias create default 1.9.3
This Ruby version will be the default version of Ruby on the system , to change to other versions of Ruby use the above mentioned commands.
To use default incase of switching use
  • rvm use default
To remove RVM from the system use the command
  • rvm implode

Installing Ruby on Windows

Step 1 :

Download Ruby from http://www.ruby-lang.org/en/.

Versions Available :
  • Ruby 1.8.6
  • Ruby 1.8.7
  • Ruby 1.9.1
  • Ruby 1.9.2
  • Ruby 1.9.3 *Recommended
Run the installer to install Ruby like any other windows application.
After install verify the installation by opening the command prompt
( Win Key + R : Type CMD : Press Enter )
Type
  • ruby -v
This should display the Ruby version which has been installed

Step 2


Extract the Devkit in a directory.
Open command prompt and navigate to the the directory where you extracted Devkit.
Type
  • ruby dk.rb init
  • ruby dk.rb install
    Now Devkit is configured on your system.

Step 3

Download Mysql/any other DB installer and install it on the machine to be used as a database for your Rails application

Creating a native iOS application !

Step 1 Installing XCode on the system

  • Download and install XCode from the App Center alongwith the Developer Tools

Step 2 Download the Phonegap SDK

  • Download and unzip the Phonegap SDK.
  • Now navigate to the iOS directory in the extracted source and run the Cordova-1.7.0.dmg and install it.

Step 3 Creating a XCode Project

Run XCode and create a new Project
Select the template
  • Cordova-based Application
This will create the a new project and include the neccesary Phonegap API Files.

Step 4 Changing the default compiler

  • Click on the application name and select BUILD SETTINGS tab in the center pane
  • Change the compiler in the BUILD OPTIONS from APPLE LLVM COMPILER to LLVM GCC

Step 5 Build and Run the Project

  • Click on the left top of the XCode window selecting the default device as iPad/iPhone Now run the Project. This would invoke the simulator and run the application on it.
  • Once the application runs a error will Popup stating the index.html is not found. Close the simulator and return back to the XCode project window.

Step 6 Include www folder in the project to start with application development

  • Right click the project name and select Show in Finder
  • Drag the www folder from the Finder to the Project
  • A window pop's up , select to create references to the files.

Step 7 Again BUILD & RUN

  • Now again build and run the project in an iPad/iPhone simulatore
  • This time it would show up the index.html which is located in the www folder. Also it would show up the Dialog stating that Phonegap was successfully integrated in the application

Step 8 Download JQuery Mobile bundle

Download the latest build of JQuery Mobile from http://jquerymobile.com/ Unzip the contents and add the files in the www folder categorizing the folders as
  • javascripts
  • stylesheets
  • `images'

Step 9 Including the JQuery mobile in the application

  • Open index.html and create references to the javascript and css files located in the www folder using the html tags

Step 10

Add a few lines of HTML to the index page and use the JQuery classes and the Phonegap api function calls to implement the features of the native application as desired
More Documentation available at

Step 11 * not tested though

  • Once the application is complete or for on Device testing a Apple's Developer License is required to sign the applications.
  • After signing it , push the application to PhoneGap Build https://build.phonegap.com/.
  • Download the build package and deploy to th Device.

11 February 2012

Setting up RHODES with an Android Emulator

Setting up the system

1. Installing Ruby. Please follow the sequence of commands given below to install ruby on ubuntu using RVM.

$ sudo apt-get install git
$ sudo apt-get install curl
$ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
$ rvm pkg install zlib
$ rvm pkg install openssl
$ rvm install ruby-1.8.7-p334
$ rvm alias create default ruby-1.8.7-p334
2. Download Android-sdk for linux
Android SDK Download
3. Download Android-ndk for linux
Android NDK Download
4. Extract both the zip files in two different folder's.

5. Java is needed to be installed in the system.If not then download the Java SDK zip files from
Java SDK 7 Download
6. Open the terminal and install the rhodes gem.
 gem install rhodes 
the installation of the gem will take time as the size of the gem is < 50 MB

7. After the gem installation ,type
$ rhodes-setup

at the terminal .The screen should come up something like this ..


Now type in the directories where you extracted the
1.Java SDK
2.Android SDK
3.Android NDK
8. Setting up the environment is complete.


Now we will generate a demo application using rhodes to test the emulator.


1.Setting up Android SDK to host an emulator of a specific android version.

2.Go to the directory where you extracted the sdk .Then go into the tools folder in the sdk and click on a file name "android".A window opens up :

3. Click on the checkbox Android 3.0 , this selects all the checkboxes in this group.Now click on install wait for a few minutes.

4. Now open your terminal and generate a new rhodes application.
rhogen app Demo
cd Demo
5. Edit the built.yml file in any text editor to change the android version to 3.0 instead of default 2.1 and add an emulator name.


6. Now go back to the terminal and type :
rake run:android
7. The android emulator will show up in a few minutes and load the rhomobile application .


Now we can go forward designing the mobile application.Happy coding :)



30 November 2011

Export to Excel in Rails 3 without a Gem

Export to Excel in Rails 3 without a Gem


Creating Demo project

 rails new xcel_demo –d mysql

Creating a User model

rails g scaffold User name:string email:string content:string

Add a MIME type in \config\initializers\mime_type.rb

Mime::Type.register 'application/vnd.ms-excel', :xls

Add a xls format output to the method in the Controller

  def index
    @users = User.all

    respond_to do |format|
      format.html # index.html.erb
      format.xls
      format.xml  { render :xml => @users }
    end
  end

Creating the view for the XLS


Now create a view to render the xls file. Here as we have modified the index method we will create a view index.xls.erb for the same in the views for Users
<h1>Listing users</h1>

<table>
  <tr>
    <th>Name</th>
    <th>City</th>
    <th>Gender</th>
    <th>Phone</th>
    <th>Address</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<% @users.each do |user| %>
  <tr>
    <td><%= user.name %></td>
    <td><%= user.city %></td>
    <td><%= user.gender %></td>
    <td><%= user.phone %></td>
    <td><%= user.address %></td>
  </tr>
<% end %>
</table>

<br />
The text in the <th> tags are the headers and <td> tags are the data for the specified columns

Adding the link to export excel on the Index page


 <%= link_to 'Export XLS', url_for(:format => 'xls') %>
This will allow the data on index page to be exported in Excel Format.