Saturday, December 17, 2011

String To charArray Java


package stringReduction;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
 * author manish
 * This program will take a String and Convert to char array
 * remove/replace the package name for it to work
 * */
public class Solution {
public static void main(String[] args) {
System.out.print("Hello");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
String inputString=br.readLine();
//System.out.print(inputString);
char[] cArray = inputString.toCharArray();
     
       for (char c : cArray)
           System.out.println(c);

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

Tuesday, September 20, 2011

Extracting File Name , Extension , File Name Without Extension In Shell Script


First, get file without path:
filename=$(basename $fullfile)
extension=${filename##*.}
filename=${filename%.*}

Friday, June 24, 2011

Compare command in case of linux


Found this Good article as a part of book Advance Shell Scripting Guide


To compare 2 files, we use the diff command. How do we compare 2 directories? Specifically, we want to know what files/subdirectories are common, what are only in 1 directory but not the other.

Unix old-timers may remember the dircmp command. Alas, that command is not available in Linux. In Linux, we use the same diff command to compare directories as well as files.

$ diff  ~peter ~george
Only in /home/peter: announce.doc
diff /home/peter/.bashrc /home/george/.bashrc
76,83d72
<
< # Customization by Peter
< export LESS=-m
< export GREP_OPTIONS='--color=always'
< shopt -s histappend
< shopt -s cmdhist
< export PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
< #echo keycode 58 = Escape |loadkeys -
Only in /home/george: .mcoprc
Only in /home/peter: .metacity
Only in /home/george: .newsticker-images
Only in /home/peter: .notifier.conf
Only in /home/george: targets.txt
Only in /home/peter: .xsession-errors


Without any option, diffing 2 directories will tell you which files only exist in 1 directory and not the other, and which are common files. Files that are common in both directories (e.g., .bashrc in the above listing) are diffed to see if and how the file contents differ.

If you are NOT interested in file differences, just add the -q (or--brief) option.

diff -q ~peter ~george  |sort
Files /home/peter/.bashrc and /home/george/.bashrc differ
Only in /home/george: .mcoprc
Only in /home/george: .newsticker-images
Only in /home/george: targets.txt
Only in /home/peter: .metacity
Only in /home/peter: .notifier.conf
Only in /home/peter: .xsession-errors
Only in /home/peter: announce.doc


diff orders its output alphabetically by file/subdirectory name. I prefer to group them by whether they are common, and whether they only exist
in the first or second directory. That is why I piped the output of diff through sort in the above command.

Note that by default diff does not reach into the subdirectories to compare the files and subdirectories at that level. To change its behavior to recursively go down subdirectories, add-r.

diff -qr ~peter ~george  |sort

Thursday, June 23, 2011

Usefull copy commands in Linux


To make a copy of a file in the current directory, enter:
$ cp file.doc file.doc.bak


To copy a file in your current directory into another directory, enter:
$ cp filename /tmp
$ ls /tmp/filename
$ cd /tmp
$ ls
$ rm filename


To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:
$ cp -p filename /path/to/new/location/myfile

To copy all the files in a directory to a new directory, enter:
$ cp * /home/tom/backup

To copy a directory, including all its files and subdirectories, to another directory, enter (copy directories recursively):
$ cp -R * /home/tom/backup

Script to compare and Print Difference between two Directories recursively


#!/bin/bash

# cmp_dir - program to compare two directories and subDirectiories
# Manish
#Please remove Echo statements i had added them for debugging
# this is the Function part of it
# Expects two argument as Source directory and target Directory now bachalo is folder which does not exhist in destination
# so it says folder does not exhist - just copy  but test is in source and dest so it gets in to that
#**********************************

searchF()
{
file=$1
args=$2
  #echo "in function Search"
# Process each file in directory_1, comparing it to directory_2

for filename in $file/*; do
    fn=$(basename "$filename")
arg="$args/$fn"
   
#echo "Hellooooo"$fn
   
if [ -f "$filename" ]; then # Checking the File and Comparing the Diff
        if [ ! -f "$arg" ]; then
            echo "$fn is missing from $arg"
            let "missing+=1"
#sleep 1
#echo $missing "is the current missing count"
        fi
    elif [ -d "$filename" ]; then # i need to make it recursive here for directories inside-- i think
#echo "HelloBidu"$filename
arg= "$2/$fn"
let "missing+=1"
#sleep 1
#echo $missing "is the current missing count"
searchF $filename $arg #recusrion
    fi
done

}
#****************************
# Main Block Starts Here
# Check for required arguments

missing=0
[ $# -ne 2 ] &&  echo "usage: $0 directory_1 directory_2" 1>&2 &&
    echo "usage: $0 directory_1 directory_2" 1>&2
   
fi

# Make sure both arguments are directories
if [ ! -d $1 ]; then
    echo "$1 is not a directory!" 1>&2
    exit 1
fi

if [ ! -d $2 ]; then
    echo "$2 is not a directory!" 1>&2
    exit 1
fi

#function call
searchF $1 $2
echo "$missing files missing"

Sunday, June 19, 2011

CHM reader on linux UBUNTU

Need Internet Service on your system

Type this sudo apt-get install xchm
and it shoudl do the rest 
Happy Reading :)

Sunday, May 22, 2011

How to Build/Clean a RFT project from command Line

Use these commands to compile (build) and run an individual script called "Script1":

set RFT_PROJECT_LOCATION="C:\Path_to_root_of_project"

"%IBM_RATIONAL_RFT_ECLIPSE_DIR%\jdk\jre\bin\java" -classpath "%IBM_RATIONAL_RFT_INSTALL_DIR%\rational_ft.jar" com.rational.test.ft.rational_ft -datastore %RFT_PROJECT_LOCATION% -compile Script1

"%IBM_RATIONAL_RFT_ECLIPSE_DIR%\jdk\jre\bin\java" -classpath "%IBM_RATIONAL_RFT_INSTALL_DIR%\rational_ft.jar" com.rational.test.ft.rational_ft -datastore %RFT_PROJECT_LOCATION% -playback Script1 -log Script1_log

Or you can combine the two commands into one:

set RFT_PROJECT_LOCATION="C:\Path_to_root_of_project"

"%IBM_RATIONAL_RFT_ECLIPSE_DIR%\jdk\jre\bin\java" -classpath "%IBM_RATIONAL_RFT_INSTALL_DIR%\rational_ft.jar" com.rational.test.ft.rational_ft -datastore %RFT_PROJECT_LOCATION% -compile Script1 -playback -log Script1_log

Wednesday, May 18, 2011

Helios for C++

A small Article on how to use your pre exhisting Helios Ecllipse for C++ Dev

here you need to put Helios - http://download.eclipse.org/releases/helios in work with option and 
it will give you the list o all the available update for hellios as shown in image

As marked in Red
And your Ecllipse will need Internet to  to downlaod it from CDT site just choose the c++ development option and your Helios is  ready for c++ :)  

Wednesday, April 27, 2011

Script facing Class Not Found Exception while running from RQM

If your script has dependency on External (third party jar or your own Created Jars) The place to keep them before running them from RQM is okay hold on 
before that 
RQM As a product actually gives you two options 
1.Simple Option 
2.very Simple option :)

Now let me stop beating around the Bush and get to the point 
 
Say your Script name is myname.java and your Script uses a method printMyName() which is part of External1.Jar,and printyourName which is part of External2.jar . One way to execute script is to put every thing(External1 and External2.jar) in the machine which has RFT installed at location 
C:\Documents and Settings\All Users\Application Data\IBM\RFT\customization








And test will go fine
as this is the default location we look for while executing the test 

The next option is where you want to keep all teh dependency at a shared location 
That you can do by giving a switch at RQM UI under Execution Argument option 
like -projectPath c:\ExernalJar_Location 
where External jar location is the place where i have put the 
External1.jar and External2.jar

Shoot Questions if you did not find it working:)



Sunday, April 17, 2011

4. Transform the Expression




Transform the algebraic expression with brackets into RPN form (Reverse Polish Notation). Two-argument operators: +, -, *, /, ^ (priority from the lowest to the highest), brackets ( ). Operands: only letters: a,b,...,z. Assume that there is only one RPN form (no expressions like a*b*c).

Input

t [the number of expressions <= 100]
expression [length <= 400]
[other expressions]
Text grouped in [ ] does not appear in the input file.

Output

The expressions in RPN form, one per line.

Example

Input:
3
(a+(b*c))
((a+b)*(z+x))
((a+t)*((b+(a+c))^(c+d)))

Output:
abc*+
ab+zx+*
at+bac++cd+^*
Basic Algorithm:

the algorithm is pretty simple Every operation has a binding weight, with + and - being the lowest. There are two rules:
  • print out numbers immediately
  • never put a lighter item on a heavier item
  • left parentheses go on the stack
  • right parentheses pop off the stack until you hit a left parentheses, and then remove the left parentheses

Code based on that:
A
PS: i have solved it for any given expression as per sun you need to take input and iterate it as per the user want it to and then get the output 


import java.util.Stack;


public class reversePolishExp
{

public static String Infix2(String input)
{
char[] in = input.toCharArray();
Stack<Character> stack = new Stack<Character>();
StringBuilder out = new StringBuilder();
for (int i = 0; i < in.length; i++)
switch (in[i]) {
case '+':
case '-':
while (!stack.empty() && (stack.peek() == '*' || stack.peek() == '/')) {
out.append(' ');
out.append(stack.pop());
}
out.append(' ');
stack.push(in[i]);
break;
case '*':
case '/':
out.append(' ');
stack.push(in[i]);
break;
case '(':
stack.push(in[i]);
break;
case ')':
while (!stack.empty() && stack.peek() != '(') {
out.append(' ');
out.append(stack.pop());
}
stack.pop();
break;
default:
out.append(in[i]);
break;
}
while (!stack.isEmpty())
out.append(' ').append(stack.pop());

return out.toString();
}

public static void main (String args[])
{
// reversePolishExp exp = new reversePolishExp();
String man=reversePolishExp.Infix2("(a+b)*(c+d)");
System.out.print(man);
}
}








Life, the Universe, and Everything


Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.

Example

Input:
1
2
88
42
99

Output:
1
2
88
My approach to this problem 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
    public static void main (String args[])
    {
     int i=0;
  int []anArray;
  String line=null;
  anArray = new int[100];
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     while (true) 
     {
      try {
       line=br.readLine();
   anArray[i] = Integer.parseInt(line);
   } catch (IOException e) {
    e.printStackTrace();
   }
      if((anArray[i])==42)
      {
       break;
      } 
      i++;
     }  
     for (int pos=0;pos<i;pos++)
     {
      System.out.println(anArray[pos]);
     }    
    }
}

Counting Cells in a Sector


Problem Statement - Counting Cells in a Sector

Consider a two-dimensional grid of cells, each of which may be empty or filled. The filled cells  that are connected form a sector. Two cells are said to be connected if they are adjacent to each other horizontally, vertically or diagonally. There may be several sectors on the grid. Your job is to find the largest sector (in terms of number of cells) on the grid. 

The following figure illustrates a grid with 3 sectors (the largest contains 5 cells).



Problem
Write a program that determines the size of the largest sector for a given grid. 

Input
The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs. The grid is given as a set of string, each composed of 0s and 1s. The 1 indicates that the cell is filled and 0 indicates an empty cell. The strings should be converted into the grid format. The largest grid that should be considered is a 25x25 grid.

Output
For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line. The output is the size of the largest sector found on the grid. 

Sample Input
2

11000
01100
00101
10001
01011 

1011
1010

Sample Output
5
3
Solution to this problem 

package test;

import java.util.Scanner;

public class CountMax {

/**
* author manish
* @param args
*/
private static int grid[][];
// static int[][] grid=new int[25][25];
private static int rows;
private static int cols;
private static final int MARKED = -1;
public static int count()
{
int maxCount=0;
int count=0;
for(int i=0;i<rows;i++)//  i
{
for(int j=0;j<cols;j++) // j
{
count=countMatrix(i,j);
//this if block to make sure that maximum node connection is returned
if(count>maxCount)
{
maxCount=count;
unmarkGrid();
}
}//for j
} //for i
return maxCount;
}
public static int countMatrix(int row,int col)
{
//if row is going out of bound
if(row<0 || row>=rows)
return 0;
//if column is going out of bound
if(col<0 || col>=cols)
return 0;
// no point looking for relations if value is not 1
if(grid[row][col]!=1)
return 0;
// if it is none of the case above then we need to check and figure out
grid[row][col]=MARKED;
int sizeofObj=1 + countMatrix(row - 1, col - 1)
+ countMatrix(row - 1, col) + countMatrix(row - 1, col + 1)
+ countMatrix(row, col - 1) + countMatrix(row, col + 1)
+ countMatrix(row + 1, col - 1) + countMatrix(row + 1, col)
+ countMatrix(row + 1, col + 1);
return sizeofObj;
}
//make it unmarked so that next time a fresh iteratio will happen and -1 will be removed from array
public static void unmarkGrid()
{
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
if (grid[i][j] == MARKED)
grid[i][j] = 1;

}
public static void main(String[] args) {
// TODO Auto-generated method stub
// INPUT PART OF IT 
System.out.print("Enter the no of rows and columns\n");
Scanner scannerObject = new Scanner(System.in); 
rows=scannerObject.nextInt();
cols=scannerObject.nextInt();
grid = new int[rows][cols];
for(int i=0;i<rows;i++)
for(int j=0;j<cols;j++)
{
try {
// System.out.print("Enter the Digits in terms of 1 and 0\n");
grid[i][j]=scannerObject.nextInt();
// System.out.print(grid[i][j]);
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
System.out.print(grid[i][j]+"\t");
}
System.out.print("\n");
}
//  CALCULATION PART OF IT 
int val=count();
   System.out.print(val);
}
}



Sunday, March 13, 2011

Why Public Static Void Main (String args[])


The public keyword is an access specifier, which allows the programmer to control the visibility of class members. When a class member is preceded by public, then that member may be accessed by code outside the class in which it is declared.In this case, main( ) must be declared as public, since it must be called by code outside of its class when the program is started. The keyword static allows main( ) to be called without having to instantiate a particular instance of the class. This is necessary since main( ) is called by the Java interpreter before any objects are made. The keyword void simply tells the compiler that main( ) does not return a value. As you will see, methods may also return values.
As stated, main( ) is the method called when a Java application begins. Keep in mind that Java is case-sensitive. Thus, Main is different from main. It is important to understand that the Java compiler will compile classes that do not contain a main( ) method. But the Java interpreter has no way to run these classes. So, if you had typed Main instead of main, the compiler would still compile your program. However, the Java interpreter would report an error because it would be unable to find the main( ) method.
Any information that you need to pass to a method is received by variables specified within the set of parentheses that follow the name of the method. These variables are called parameters. If there are no parameters required for a given method, you still need to include the empty parentheses. In main( ), there is only one parameter, albeit a complicated one. String args[ ] declares a parameter named args, which is an array of instances of the class String. Objects of type String store character strings. In this case, args receives any command-line arguments present when the program is executed.

Say if you are trying to pass a word "A QUICK BROWN FOX JUMP OVER A LAZY DOG" as a String from command Line and get a sorted out put the code will look something like 

Class Sort {
public static void main (String [] words)
{
        sort (word,0,word.Length-1);
        print(word)
}
/*  This is Going to sort the words which were taken as input*/
static void sort(String[] A , int L ,int U );
static void  print (String [] A);
}

Now as you see in Statement 
public static void main (String [] words)
i have chosen words as argument rather than Usual String [] args 
here word become the String array which will take in put form command prompt
 

Wednesday, February 23, 2011

VS 2003 prerequisite CD missing - error Not able to Install

lately i faced this issue where i do not had VS 2003 prerequisite CD and after downloading
en_vs.net_2003_enarch_full.exe from MSDN (i have a legal license to download ) i was constantly getting this
error wher it said pre requisite not met
i google and try to look for pre requisite and answer was there are basically 3 prerequisite

to obtain .NET 1.1:
.NET Framework 1.1 SP1:
J# 1.1 redistributional package:
 
Alas i had all 3 of them on my System (Control panel will tell u ) but still i couldnt get through
then i come through a tech note from MS which suggested that
for such problems
the solution is to
Locate till the SetUp.exe
and Use this Switch to Run setup.exe

"setup.exe /NO_BSLN_CHECK"




And Magic !!!!
my VS 2003 started installing 


i did put some effort in understanding what BSLN switch actually does but couldnt get a very good ad shareable answer 
if you know please do share 




So the first thing came in my mind was to share this trick 



Saturday, February 19, 2011

Connecting RFT And RQM andworking as a Single product



Here I am writing first time about what I work upon.
Read http://startattechnologystop.blogspot.com/2011/01/top-ten-reasons-for-why-you-should-use.html  to know what RFT (Rational Functional Tester) is and read http://qualitymanager.wordpress.com/  to know about another great product from IBM Rational. Now here is where I come in to picture. My responsibility at IBM Rational is to get these two products working together as one product so I basically work on integration of RFT – RQM
     If you care to read the first blog link given at starting of my blog you would know RFT as a product has wide coverage on Domain , Application for Automation testing and the second blog is about the Testing management which seems to be pain at the wrong place for innumerable number of companies and most discussed topic inside companies.
How to test what to test and how fast and effective testing can be.

  Now consider you shave started automating your Application with the RFT and you have learned to manage your test as well with RQM now the challenge is to arrange automated tests as RQM is more focused on Manual testing. Here is where RFT Adapter comes in to picture.
 Adapter allows you to keep your tests at a Shared location/Locally and arrange the Tests at RQM GUI side and you can plan and Run your tests at RQM side and see it running (if you wish to ) at the side where RFT is installed.if I sound Greek and Latin let me take you through one complete cycle of running a RFT Script  from RQM .

if you allow me, I am going to assume that you know how to record a Script at RFT if not?? even better - no worries here is how you can do that
Download the trial version of product from www.ibm.com/developerworks/downloads/r/rft/ and the help which will get install with it will take you through the step by step process of recording. Else go through “pubbuilder site RFT IBM “ and you will get loads of video which will illustrate and take you through the process.
And you can get RQM Trial version from http://jazz.net/
And there you are ready with a combination which can help you using your resources
Optimally and give your testing a coverage which you had only though about but never have been able to achieveJ

What is Adapter ??

It’s a small tool which help you to connect two most amazing product from rational labs and enable you to use them as a single product

What does it looks like ??

So here is how Architecture wise it works



PS that this is very very basic presentation of what Adapter can actually do .

  So this is where I stop for this blog in my next blog I will take you through the one complete execution of a RFT Script from RQM side