Sunday, September 28, 2014

Coding and Chatting- How they affect each other.

Today I choose to write this article based on my experience in past few years. Social networking sites are popular and people like to spend most of their time meeting new people and talking to them. One of the main thing people like to do is chatting, one of the easiest way to communicate with new and old friends. But the thing I am interested is how it affects the software professionals who write code.

Chatting may refer to any kind of communication over the Internet that offers a real-time transmission of text messages from sender to receiver. Its a wonderful technology to communicate with people. Most of us use a lot of jargon and short form of words to make it happen. There is nothing wrong in it, but we generally get habituated with this short form of worlds (like Please -Pls etc).  This short form of words become annoying for a software professional when they write such words in software code. I personally have done the same mistake while writing log messages in professional code. As we are habituated with such words, they get a place in our logs messages/documentations. Also being familiar with such words, it become difficult to review such code errors.

The conclusion is we stop using social networks. I am joking- That cant be true. But we need to be extra careful while writing code and should omit those newly created words. Being a software professional we may avoid using short forms of words while chatting and make our mind familiar with the correct words.


Sunday, July 3, 2011

Win Vista PE+usb not recognized+ VMWARE

Hi,

This is a solution i tried to make ghost copies with winPE in VMWare.
Problem-
It recognizes on the hard drive and not the USB devices. So I was unable to make the save the image from the ghost copy.

Solution-
Make a copy of the vmdk file in the wmware folder and name it as xxxx_1.vmdk. In the vmware setting add a new Hard Drive with the new vmdk file(xxxx_1.vmdk). Boot the image with windows PE. Now it will show up 2 hard drives. So the image of the one hard drive can be saved to the other one. Once done shutdown the VM. Rename the two vmdk files. Boot the operating system with the new vmdk. Then the image can be transfered using FTP(or copying).

Hope this may be helpful.

Saturday, June 25, 2011

Updating/Refreshing a dojo Tree

A dojo tree can be reloaded or refreshed with the below code.

<html>
<head>
<link rel="stylesheet" type="text/css" href="dojo-release-1.6.0/dojo/resources/dojo.css" />
<link rel="stylesheet" type="text/css" href="dojo-release-1.6.0/dijit/themes/tundra/tundra.css" />
<script src="dojo-release-1.6.0/dojo/dojo.js" language="javascript"></script>
<script language="javascript" type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.form.Button");
dojo.require("dijit.Tree");
dojo.require("dijit.tree.ForestStoreModel");
dojo.require("dojo.data.ItemFileWriteStore");
var treeModel;
</script>
<script>
function reload(){
if(dijit.byId("treeOne")){
// Destroy the widget
dijit.byId("treeOne").destroyRecursive();
}
var store = new dojo.data.ItemFileWriteStore({
url: "./json/files.json"
});

treeModel = new dijit.tree.ForestStoreModel({
store: store,
query: {
"type": "Folder"
},
rootId: "server",
rootLabel: "ROOT",
childrenAttrs: ["children"],
});
document.getElementById("treespan").innerHTML="<div id='treeOne'></div>"
new dijit.Tree({
model: treeModel,
},
"treeOne");
}
</script>
</head>
<body class="tundra">
<button dojoType="dijit.form.Button" type="button" onClick="reload()" >Load Tree</button>
<span id="treespan"></span>
</body>
</html>



Back Track a dojo Tree

If we have a tree node of dojo tree we can back track the tree using the below code.

Once we get a tree node of the dojo tree(for Right click/click), we can find out the root node of the tree .
We get the values of the nodes from the datastore that was used to create the tree.


var tn =dijit.getEnclosingWidget(e.target);

while(parent.indent >0){
// get the value from the nodes from the data store
console.debug(store.getValue(parent.item, 'name'));
parent=parent.getParent();
}



Tuesday, September 14, 2010

Running JBOSS Programmatically from java

Please find below code to run JBOSS Programmatically from JAVA. Please include jboss jars in your classpath.

I tested the following code for JBOSS-6.0.0.M2


package com.sudipta.jboss.conf;

import org.jboss.Main;

public class JbossOperation {
public static Main ob;
static Class jbossMain;
static{
try {
jbossMain=Class.forName("org.jboss.Main");
ob = (Main)jbossMain.newInstance();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}

}

/**
* START JBOSS SERVER
* @return true if started successfully
*/
public static boolean startServer(){
boolean status=true;

String str[]={"-c","default"};
try {
ob.boot(str);

} catch (Exception e) {
e.printStackTrace();
return false;
}
return status;
}

/**
* STOP JBOSS SERVER
* @return true if started successfully
*/
public static boolean stopServer(){
boolean status=true;
try {
ob.shutdown();
} catch (Throwable e) {
e.printStackTrace();
}

return status;
}

/**
* Main method
* @param args
*/
public static void main(String args[]){
System.out.println("---------------------Strating the server------------------");
startServer();
System.out.println("---------------------Stoping the server------------------");
stopServer();
System.out.println("---------------------SERVER STOPPED------------------");
}
}



Tuesday, June 8, 2010

Java Program to List the Directories,SubDirectories and Files in them

import java.io.File;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;


/**
* List the Directories, SubDirection and Files in them
* @author Sudipta Kumar Laha
*
*/
public class FileStructure {
/**
* Print Directories, SubDirection and Files in them
* @param str
*
*/
public void getFiles(String str){
System.out.println("[D]\t"+str);
File f=new File(str);
File ss[]=f.listFiles();


if(ss!=null){
Arrays.sort(ss, new sortStructure());
for(int i=0;i<ss.length;i++){
if(ss[i].isDirectory()){
String currDir=ss[i].getAbsolutePath();
System.out.println("Total File & Directory "+ss.length);
this.getFiles(currDir);
}else{
System.out.println("[F]\t"
+getPermissions(ss[i].canRead(),ss[i].canWrite(),ss[i].canExecute())+
"\t"+
ss[i].getName());
}
}
}else{
System.out.println("Unable to read");
}

}
/**
* Checks for the access in files
* @param canRead
* @param canWrite
* @param canExecute
* @return
*/
private String getPermissions(boolean canRead, boolean canWrite,
boolean canExecute) {
StringBuffer buff=new StringBuffer();
if(canRead)
buff.append("r");
else
buff.append("-");
if(canWrite)
buff.append("w");
else
buff.append("-");
if(canExecute)
buff.append("e");
else
buff.append("-");
return buff.toString();
}

/**
* Start of Program
* @param args
*/
public static void main(String args[]){
FileStructure obj=new FileStructure();
obj.getFiles(args[0]);

}

}


/**
* Class extends comparator to sort files and directories
* @author Sudipta Kumar Laha
*
*/
class sortStructure implements Comparator<File>{
@Override
public int compare(File o1, File o2) {
// TODO Auto-generated method stub
if(o1.isDirectory() && o2.isDirectory()){
return o1.getName().compareTo(o1.getName());
}else if(o1.isFile() && o2.isFile())
return o1.getName().compareTo(o1.getName());
else if(o1.isDirectory())
return 1;
else
return 0;
}
}



Saturday, May 8, 2010

Seraching in Arrays in JAVA

We can search in a array for a value using the method binarySearch of Arrays class.
The search result will give correct output if the array is sorted.
If the array is not sorted the result is unpredictable.
Note: For predictable result array must be sorted before searching an element.

The following code explains this behavior:


Integer[] intArr={2,5,3,4,1};
for(Integer s: intArr)
System.out.print(s+",");

System.out.print(System.lineSeparator());
System.out.print("Searching 5:"+Arrays.binarySearch(intArr,5)); // Will return -6 which is incorrect
System.out.print(System.lineSeparator());
System.out.print("Searching 2:"+Arrays.binarySearch(intArr,2)); // will return correct result 0, but not for every search

Arrays.sort(intArr); //Sorting the Array
System.out.print(System.lineSeparator());
for(Integer s: intArr)
System.out.print(s+",");
System.out.println(System.lineSeparator()+Arrays.binarySearch(intArr,2)); // Always gives the correct result


About Me