Sunday, March 24, 2013

setting "rm" to move files (and folders) to trash-"rm -rf" Undo

Step1. sudo apt-get install trash-cli

Trash-cli:This package provides a command line interface trashcan utility compliant with the FreeDesktop.org Trash Specification. It remembers the name, original path, deletion date, and permissions of each trashed file

Step2sudo gedit /usr/local/bin/trash-rm

in Ubuntu 10.04 i found it to be sbin than bin so command might be 

sudo gedit /usr/local/sbin/trash-rm

Step 3
Paste this content 
#!/bin/bash
# command name: trash-rm
shopt -s extglob
recursive=1
declare -a cmd
((i = 0))
for f in "$@"
do
case "$f" in
(-*([fiIv])r*([fiIv])|-*([fiIv])R*([fiIv]))
tmp="${f//[rR]/}"
if [ -n "$tmp" ]
then
#echo "\$tmp == $tmp"
cmd[$i]="$tmp"
((i++))
fi
recursive=0 ;;
(--recursive) recursive=0 ;;
(*)
if [ $recursive != 0   -a  -d "$f" ]
then
echo "skipping directory: $f"
continue
else
cmd[$i]="$f"
((i++))
fi ;;
esac
done
trash "${cmd[@]}"

Save and Exit

Set Correct executable rights on the created file
Step:4
sudo chmod +x /usr/local/bin/trash-rm


Step 5:
gedit ~/.bashrc


Step 6:
alias rm = "trash-rm"
Step7:$bash
Re run bash on linux terminal to re run the bashrc

Step8:

Try by creating a file and then using rm -rf "createdFile.txt"

find that file in Trash 













Tuesday, March 19, 2013

ECLIPSE Shortcut for converting lower case to upper and vice versa

Just a quick short cut which is very useful for developers to convert the selected lower case text to Upper case and vice versa

Lower case: CTRL+SHIFT+Y (CMD+SHIFT+Y on Mac OS X)
Upper case: CTRL+SHIFT+X (CMD+SHIFT+X on Mac OS X)

The good thing here is you can select one or multiple characters/word/lines by using Using + ->/<-/DownArray and then convert all of it at once.

Sunday, December 2, 2012

Android Installation problem [Can not complete the Install ] Solved


Problem
Cannot complete the install because one or more required items could not be found.
  Software being installed: Android Hierarchy Viewer 18.0.0.v201203301601-306762 (com.android.ide.eclipse.hierarchyviewer.feature.group 18.0.0.v201203301601-306762)
  Missing requirement: Android Hierarchy Viewer 18.0.0.v201203301601-306762 (com.android.ide.eclipse.hierarchyviewer.feature.group 18.0.0.v201203301601-306762) requires 'org.eclipse.core.runtime 3.6.0' but it could not be found

Please note same message for  "Android DDMS","Android Development Tools" and  "Android Traceview"

Or Duplicate Repository problem where as creating the new Android Project option doesnt appear 


Head over to Help -> Install New Software. Click on Available software sites. Delete the Android repo. Uncheck Indigo & Eclipse updates & recheck them. Now head back to Help -> Check for updates. Once done, add the Android repo again. Accept the license & you should be good to go.
(Had to do the same yesterday after getting Indigo)
Source: StackOverFlow: Pasting here as this Solution worked for me after trying a lot of solutions posted over net 

Sunday, August 26, 2012

TCS fiasco and How to keep your account safe while changing mobile no


  24th August and the morning news came out as Techie steals Rs 49L from 3 bank accounts in Chennai. This news was definately worth the attention as while working with multiple service /Product companies techies like me  do get exposed to sensitive information. Here is what heppned in short and how the fraud was done



TCS Fraud protype

















                         

 Now the account and details related to it are in total unsafe hands and is     exposed to the variety of fraud which can be done . Now though the likelihood of having access to Bank DB is very less but even a person in million having access  to bank DB with malicious intention can give any bank a very hard time. The only way for the bank to trace back in these situation is to trace  the user            Machine IP where query was executed and me myself being a techie can say it for sure , its a cake walk to  mask my IP and give the Bank guys even a harder time trying to trace the origin of fraud.
  The point worth mentioning in this TCS fiasco is ,the techie was caught only becasue he/She  gone greedy and started withdrawing large amounts. However if they had kept a little control on their greed, it was close to impossible to figure out . And we will never know if the employee had done small such malicious activity in past and the amount was not big enough to draw attention of bank officials.

  Looking at the pattern however , it exposes the seriousness with which customer's private data is maintained, and the low level of security practises banks follow in order to save their customers hard earned money.this also brings the necessity  of a strong and capable Real Time online fraud monitoring system where multiple such incidents are coded as  a part of online transaction as well as card swipe process and is capable to stop transaction in any of the possible fraud scenario and is part of core banking system . 

  it will be interesting to see in indian market where changing the mobile number  is such a common process , if one gets access to telecom DB and does a intersection and imaginary scenario something like this 

The received out put list is the list of customer whoose transaction should be immideatly blocked until the new number is updated other wise in a matter of second and effort of two software engineers (One working for Bank and one working for Telecom ) is capable of adding multiple zeroes in the 49Lakh amount fraud..
  For customers , they should immediately give standing instruction to bank/Credit card company to stop doing any sort of transaction unless  they have a working number again.The process might look a little cumbersome to follow but as we all know it for a fact that its always  “better to be safe than sorry“.











Sunday, June 24, 2012

Count The No of Inversion in merge Sort

Algo:

 i have followed to do the same


  1. Merge sort array A and create a copy (array B)
  2. Take A[1] and find its position in sorted array B via a binary search. The number of inversions for this element will be one less than the index number of its position in B since every lower number that appears after the first element of A will be an inversion.
    2a. accumulate the number of inversions to counter variable num_inversions.
    2b. remove A[1] from array A and also from its corresponding position in array B
  3. rerun from step 2 until there are no more elements in A.
Here’s an example run of this algorithm. Original array A = ( 14, 8, 12, 3, 2)
1: Merge sort and copy to array B
B = (2,3,8,12,14)
2: Take A[1] and binary search to find it in array B
A[1] = 14
B = (2,3,8,12,14)
14 is in the 5th position of array B, thus there are 4 inversions. We know this because 14 was in the first position in array A, thus any lower value element that subsequently appears in array A would have an index of j > i (since i in this case is 1).
2.b: Remove A[1] from array A and also from its corresponding position in array B (bold elements are removed).
A = ( 14, 8, 12, 3, 2) = (8, 12, 3, 2)
B = (2,3,8,12,14) = ((2,3,8,12)
3: Rerun from step 2 on the new A and B arrays.
A[1] = 8
B = ((2,3,8,12)
8 is now in the 3rd position of array B, thus there are 2 inversions. We know this because 8 was in the first position in array A, thus any lower value element that subsequently appears would have an index of j > i (since i in this case is again 1). Remove A[1] from array A and also from its corresponding position in array B (bold elements are removed)
A = (8, 12, 3, 2) = 12,3,2
B = (2,3,8,12) = 2,3,12
Continuing in this vein will give us the total number of inversions for array A once the loop is complete

Try to code as per Algo , it gives a complete result
i am not sharing code as its against the fair code Stanford rule and will share only once the date for submitting assignment is expired
however am okay if u need any help in completing this exercise and Java is teh language i prefer to code in 


Friday, May 11, 2012

Basic IP Check with Ping using Java



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.UnknownHostException;


public class testIp {

public static boolean checkIp (String sip)
  {
      String [] parts = sip.split ("\\.");
      System.out.println("Parts length is "+parts.length);
      if ( parts.length != 4 )
      {
          return false;
      }
      for (String s : parts)
      {
          int i = Integer.parseInt (s);
          if (i < 0 || i > 255)
          {
              return false;
          }
      }
      if (pingIp(sip))
      return true;
      else
      return false;
  }

private static boolean pingIp(String sip) {
// TODO Auto-generated method stub
try {
InetAddress adr = InetAddress.getByName(sip);
boolean stat= adr.isReachable(2000);
return stat;
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return false;
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Enter the IP to be chacked");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {

String line = br.readLine();
boolean status=testIp.checkIp(line);
System.out.println("Status is "+status);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}




Thursday, May 10, 2012

EMMA Report Comparison Shell Based Utility


Here i am pasting the Symbolic code for comparing two EMMA Reports where Assumptions are
1.before.txt ---> the actual report
2.after.txt----> report after modification

This Script will get in to those twpo reports and show block by Block Comparison
The idea behind sharing this is that using this Logic a Extensive User Utility script can be developed which can be used to compare EMMA Reports



function retLineNobefore()
{
Str=$1
while read Line
do
val=$(grep -n "$Str" | sed -n 's/^\([0-9]*\)[:].*/\1/p')   # this is to Extract just the Line no
break
done < before.txt
}

function retLineNoAfter()
{
Str=$1
while read Line
do
val=$(grep -n "$Str" | sed -n 's/^\([0-9]*\)[:].*/\1/p')
break
done < after.txt
}

rm -fr report.txt

retLineNobefore "OVERALL COVERAGE SUMMARY:"
no1=$val


retLineNobefore "OVERALL STATS SUMMARY:"
no2=$val
echo "----------------Before-------------------------- " > report.txt

awk "{if((NR>"$no1")&&(NR<$no2)) print}" before.txt  >> report.txt



retLineNoAfter "OVERALL COVERAGE SUMMARY:"
no1=$val
echo $no1


retLineNoAfter "OVERALL STATS SUMMARY:"
no2=$val
echo $no2
echo "----------------After-------------------------- " >> report.txt
awk "{if((NR>"$no1")&&(NR<$no2)) print}" after.txt  >> report.txt