Debugging Objects in Javascript
There are a lot of good JavaScript debugging tools available out there; FireBug for Firefox comes to mind as one of the best. But when when developing web applications across multiple browsers, particularly browsers like IE which have limited built-in debugging functionality, it's handy to have a function that can be called to debug a specific object on the page.
Here is a JavaScript function that I wrote several years ago. It's a bit of a kludge - I'm sure there is a more elegant approach - but having it available to quickly inspect a single element has saved more than a few hours of painful development:
function debugObject(elem, recurseIntoObjects, elemPropertyName) {
var mesg = "";
if ((elem == undefined) || (elem == null)) {
alert("Passed element is not valid: "+elem);
return;
}
for (var i in elem) {
if ((i == undefined) || (i == null) || (typeof elem[i] == 'function') || (typeof elem[i] == 'undefined') || (elem[i] == null)) {
continue;
}
if (recurseIntoObjects && typeof elem[i] == 'object') {
if ((elemPropertyName != undefined) && (elem[i][elemPropertyName] != 'undefined')) {
mesg += i+": "+elem[i][elemPropertyName]+"\n";
}
else {
var elements = "";
var elementCount = 0;
for (var j in elem[i]) {
if ((j == undefined) || (j == null) || (typeof elem[i][j] == 'function') || (typeof elem[i][j] == 'undefined') || (elem[i][j] == null)) {
continue;
}
if (elementCount != 0) {
elements += ", ";
}
elements += elem[i][j];
elementCount++;
}
mesg += i+"["+elementCount+"]: "+elements+"\n";
}
}
else {
mesg += i+": "+elem[i]+"\n";
}
}
alert(mesg);
return mesg;
}
Java: Reflecting to Get All Classes in a Package
It took me a little while to figure out that Java doesn't provide a way to reflect an entire package. In other words, there is no built-in way for me to dynamically retrieve a list of all the classes in a given package in Java through reflection. So I wrote my own method to do it.
Since it took a bit of googling and effort, I thought it would be nice to share the convenience method I wrote with the world. Enjoy:
/**
* Given a package name, attempts to reflect to find all classes within the package
* on the local file system.
*
* @param packageName
* @return
*/
private static Set<Class> getClassesInPackage(String packageName) {
Set<Class> classes = new HashSet<Class>();
String packageNameSlashed = "/" + packageName.replace(".", "/")
// Get a File object for the package
URL directoryURL = Thread.currentThread().getContextClassLoader().getResource(packageNameSlashed);
if (directoryURL == null) {
LOG.warn("Could not retrieve URL resource: " + packageNameSlashed);
return classes;
}
String directoryString = directoryURL.getFile();
if (directoryString == null) {
LOG.warn("Could not find directory for URL resource: " + packageNameSlashed);
return classes;
}
File directory = new File(directoryString);
if (directory.exists()) {
// Get the list of the files contained in the package
String[] files = directory.list();
for (String fileName : files) {
// We are only interested in .class files
if (fileName.endsWith(".class")) {
// Remove the .class extension
fileName = fileName.substring(0, fileName.length() - 6);
try {
classes.add(Class.forName(packageName + "." + fileName));
} catch (ClassNotFoundException e) {
LOG.warn(packageName + "." + fileName + " does not appear to be a valid class.", e);
}
}
}
} else {
LOG.warn(packageName + " does not appear to exist as a valid package on the file system.");
}
return classes;
}
Removing WinFixer / Virtuamonde / Msevents / Trojan.vundo
I spent a couple hours over the weekend trying to figure out a particularly nasty virus called (among other things) "Virtuamonde" or "Virtumonde". What makes this trojan virus particularly nasty is that it redirects a lot of useful anti-virus and anti-spyware websites to point to localhost (127.0.0.1). The blocked websites include:
- Windows update (windowsupdate.microsoft.com and update.microsoft.com)
- Windows support sites (support.microsoft.com)
- Spybot Search & Destroy website
- AdAware website
- ... and many other forums and support sites that provide solutions.
To help others who have this same issue and do not have the luxury of a second computer running linux, or cannot connect to these sites for other reasons, I am providing the necessary programs here to FIX the problem.
TO FIX:
Download, install, and run Malwarebytes' Anti-Malware. This was the only malware/spyware removal program that actually found and fixed the problem.
You may have to run this program in safe mode (reboot your computer and keep pressing F8 until you see a prompt for "Safe Mode"). If this still doesn't catch your problem you can download and install VundoFix.
(via bleepingcomputer, which is another site that is explicitly blocked by this trojan virus)

It has come to my attention that several readers are experiencing an error when visiting this site. The error will only occur when you are using Internet Explorer, and is most likely due to JavaScript in one of my plugins attempting to write to the DOM before it has finished rendering.