Monday, December 9, 2013

Comparing 2 files


If you wanted to know whether 2 files is having same content or not, you need not to compare two files line by line, instead you can compare checksums of each file.

For this, you need to use Apache common-codec_1.7.jar file.




Example:


package com.kk;

import java.io.FileInputStream;
import java.io.IOException;

import org.apache.commons.codec.digest.DigestUtils;

public class CompareFiles {

public static boolean compare(String oldFile, String newFile) throws IOException {
FileInputStream fis1 = new FileInputStream(oldFile);
String oldmd5 = DigestUtils.md5Hex(fis1);// old file checksum
FileInputStream fis = new FileInputStream(newFile);
String latestmd5 = DigestUtils.md5Hex(fis); // new file checksum
return oldmd5.equals(latestmd5);
}
public static void main(String[] args) {
String oldFile = "D:\\Work\\test\\js\\kklibrary.js";
String newFile = "D:\\Work\\test\\kklibrary.js";
try {
boolean compare = compare(oldFile, newFile);
System.out.println("Both files are: "+ compare);
} catch (IOException e) {
e.printStackTrace();
}
}
}

Tuesday, November 26, 2013

Eclipse Mac: Cocoa SWT

Recently I started working on Mac eclipse, and i was trying to understand what is the underlying SWT library.

They are using Cocoa SWT.

Cocoa is Apple's native object-oriented application programming interface (API) for the OS X operating system.

More @ http://en.wikipedia.org/wiki/Cocoa_(API)


SWT will have 2 plugins:

org.eclipse.swt  => swt core plugin
org.eclipse.swt.cocoa.macosx => Native interface calls to Mac OS X


Seems to be cocoa is supported from eclipse 3.5 version
More @ http://www.eclipse.org/swt/cocoaport.php

Download @ http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops4/R-4.3-201306052000/swt-4.3-cocoa-macosx.zip

Android SDK tools Windows registry keys

Below are the keys registered in windows registry, if you have installed through android sdk exe file.

For 32 bit machines
HKEY_LOCAL_MACHINE\Software\Android SDK Tools

For 64 bit machines
HKEY_LOCAL_MACHINE\Software\Wow6432Node\Android SDK Tools




Eclipse Plugin spy for menu items

All we know that (Alt+shift+F1) is used to identify the class which is used in the eclipse workbench based on the active selection.

I recently realized that, (Alt+shift+F2) can be used with menu items.
Press Alt+shift+F2, then click on menu item that you want to identify.

Download from @ http://www.eclipse.org/pde/incubator/spy/

Opening eclipse in debug console mode


1.        If you have specified java in in vm arguments, modify javaw.exe to java.exe
Javaw.exe is a window process
Java.exe is a console process

-vm
C:/KK/jdk1.6.0_32/bin/java.exe

Eclipse by default make use of javaw.exe process.

2.       You can find directly eclipsec.exe in your eclipse folder, this will open up a console to print all console level messages. By default this will invoke java.exe process.

To get the debug statements, add –debug parameter in the command prompt.

Example:
Ø  eclipsec –debug

     You can also try this.
Ø  eclipse –debug -consolelog

To understand more about java.exe and javaw.exe @ http://javapapers.com/core-java/java-vs-javaw-vs-javaws/






Friday, November 22, 2013

E325: ATTENTION Found a swap file by the name ".git/.MERGE_MSG.swp"

I was facing this issue while pulling the code from the git central server.

Basically error says, 2 things.

(1) Another program may be editing the same file.
    If this is the case, be careful not to end up with two
    different instances of the same file when making changes.
    Quit, or continue with caution.

(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r .git/MERGE_MSG"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file ".git/.MERGE_MSG.swp"
    to avoid this message.



I have verified (1), could not find any other terminal which was accessing this file.

I am not sure about (2), so I went ahead and deleted directly '.git/.MERGE_MSG.swp' file.

Yes, Now it worked without any issues!!!



Thursday, November 14, 2013

Ampersand (&) is not shown on tooltips in Eclipse

To show '&' as part of tooltip information, You need to follow the rules of doubling an ampersand when you want a single ampersand for tool tip text.  All platforms follow this rule and strip out the underscore.

Example:
String tooltip = "Hello & World"; => Hello && World"

Look at the code below.

import org.eclipse.jface.window.DefaultToolTip;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;


public class MyToolTip extends DefaultToolTip {

public MyToolTip(Control control) {
super(control);
}

@Override
protected String getText(Event event) {
int x = event.x;
int y = event.y;

String tooltip = "Hello & World"; //only for test
//TODO: build tooltip info here.
if (tooltip.contains("&")) {
tooltip = tooltip.replace("&", "&&"); //without double ampersand replacement tooltip info will be shown as 'Hello _World' by replacing & by _.
}
return tooltip;
}
}