JTable column headers

A JTable’s column headers are not shown when you add a JTable to the container.

To show the headers, add the table into a JScrollPane before adding it into the container.

If for whatever reason the scroll pane is not desired, use JTable.getTableHeader() to get the column header component, which you can add to the NORTH side of a BorderLayout for example.

JUnit addons

JUnit-addons is a useful library that extends JUnit asserting features. To name a few:

junitx.framework.ArrayAssert: If you’ve written test cases long enough you’ll know that assertEquals won’t work on arrays, and you’ll repeatedly write a loop to assert so. This class takes care of it all.

junitx.util.PrivateAccessor: I’ve always written utility classes to help me set private fields when mocking test objects. Looks like I’m not the only one with the problem.

junitx.framework.Assert.assertNotEquals(): Might be useful in certain cases. Not really recommended because you really want to match the value you’re asserting. It’s too easy to pass a NotEquals() test.

javax.crypto.Mac not threadsafe

Although not explicit, the usage of the class quite obviously shows that multiple threads shouldn’t use the same instance to calculate a hash.

In particular, even if the update() methods were not used and multiple threads call the doFinal() method together, you are likely to get a bad result (which is worse than an Exception).

Something unit test cases cannot catch.

PHP XML XPath

The problem with the simple XML-RPC wordpress solution was that it did not have feedback whether the post was successful. I knew I could get the response from curl_exec, but I have to figure out the XPath part. Similarly I was hoping for some ready-made function to do that, but it seems things were not so straightforward. Furthermore, being on PHP4 means I didn’t have the luxury of the newer XML functions such as SimpleXML.

After some fiddling, this was the simplest I could go:


$dom = domxml_open_mem($response);
$faultString = xpath_eval(xpath_new_context($dom), 
	  "/methodResponse/fault/value/struct/member[name='faultString']/value/string/text()");
return $faultString->nodeset[0]->content;

The XPath expression was also a level-up: I had to select a node based on the child data of its sibling.

WordPress XML-RPC

I wanted a stripped-down “mobile” version of the WP admin interface for posting, but I couldn’t find a suitable one. So while I thought about writing my own, I looked for ready made XML RPC solutions.

Indeed, as I expected, one function is all it takes.


function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories=array(1)){
	$categories = implode(",", $categories);
	$XML = "$title".
	"$categories".
	$body;
	$params = array('','',$username,$password,$XML,1);
	$request = xmlrpc_encode_request('blogger.newPost',$params);
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
	curl_setopt($ch, CURLOPT_URL, $rpcurl);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 1);
	curl_exec($ch);
	curl_close($ch);
}

I made a small HTML form and submitted it to this PHP function, and that’s it! 15 minutes worth of work.

VirtualBox remote access

VirtualBox supports RDP (Remote Desktop Protocol), which can be enabled by the following steps.

  1. Power off the Guest machine (doesn’t work in saved state).
  2. Click “Settings” to configure the settings for the VM.
  3. Select the Remote Display tab, check “Enable VRDP Server”.
  4. If you’re on Windows you might need to change the server port because it may conflict with the Remote Desktop for Windows.
  5. Click “OK”.

Start the VM, and run “mstsc /v:hostname:port” from another box to Remote Desktop into the VM.

What I’ve experienced is that the mouse speed is not synchronized, so it becomes difficult to navigate even when I change the mouse sensitivity to be approximately the same. I also haven’t figure out how to have authentication with this method.

Another possible way I’ve yet to succeed is to use Ubuntu’s built in vnc server.

Oracle lightweight client

I needed an Oracle client to do some quick tests on a database server (see the next post), something like SQL Plus. But it felt too heavy for me to install the official client. So I went out looking for an alternative, something that’s standalone, very light to install and use. Of course it should be free.

http://www.sqlpal.com/

SQLPal is a perfect match – it’s free (for use), it’s standalone, just unzip and use (no install), works just like SQLPlus. In addition it has a schema browser to dig into the database easily, supports command history, and happens to be implemented in Java. The Java part has no added advantage though, it wouldn’t make a difference if it were in C++ or Python.

EDIT: I just realized the last update to the program was in 2004, evident from the website as well as the files extracted from the zip. Is it bad that there are no updates? Or it’s just a good program that needs no updates?