Wednesday, August 17, 2011

VirtualBox Guest OS Window Automatic Resizing

Install guest additions if you don't have it already.  Make sure that "Auto-resize Guest Display (Host+G)" under the machine menu is checked.  My Guest Windows XP stopped resizing the window, and it turned out that I accidentally turned this off, so it's just something to verify.


Friday, August 12, 2011

Sharing Files Through Microsoft Remote Desktop Connection (RDC)

Context:

Mac OS X
Microsoft Remote Desktop Connection Client for Mac, Version 2.1.1
Windows Server

Problem:

I want to share and transfer files between my Mac and the remote Windows server.

Solution:

Under RDC menu, choose Preferences...
Once you're there, choose Drives.  There, you can choose which folder you want to share.  After that, you can remote desktop into the server.  On the server, you will see the folder available as a drive.  That's it.

Saturday, August 6, 2011

XSLT 1.0/XPath 1.0 Case-Insensitive String Match

With XPath 2.0, you can use fn:matches('My TeSt String','test', 'i') to do case-insensitive.

With XPath 1.0, here's how:

contains(translate('My TeSt String','ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'test')

This translate function maps letters and essentially turns uppercase letters into lowercase letters.

Friday, August 5, 2011

Java printf Percent (%) Sign

To put the percent sign '%' in as a literal,

System.out.printf("\nTested %d reports.  Found differences in %d reports.  %2.2f%% passed.  %2.2f%% failed.\n", 7, 1, ((float)(7-1)/7)*100, ((float)1/7)*100);
%[argument_index$][flags][width][.precision]conversion
 
The optional argument_index is a decimal integer indicating the position of the argument in the argument list. The first argument is referenced by "1$", the second by "2$", etc. 
The optional flags is a set of characters that modify the output format. The set of valid flags depends on the conversion. 
The optional width is a non-negative decimal integer indicating the minimum number of characters to be written to the output. 
The optional precision is a non-negative decimal integer usually used to restrict the number of characters. The specific behavior depends on the conversion. 
The required conversion is a character indicating how the argument should be formatted. The set of valid conversions for a given argument depends on the argument's data type.

Wednesday, August 3, 2011

Packet for query is too large...setting the 'max_allowed_packet' variable.

Context:

MySQL
Hibernate
Sequel Pro

Problem:

Tried to save a blob, but evidently, the size was larger than the allowed size by MySQL.  For me, the max_allowed_packet size was 1M.  One way that you can find this out is by running: 
SHOW VARIABLES LIKE 'MAX_ALLOWED_PACKET'; 

Solution:

To fix this, I simply increased the size to 5M by running 
SET GLOBAL MAX_ALLOWED_PACKET=5*1024*1024;

Footnote:

I was using Sequel Pro.  After I ran the set query to increase the size, I ran the show variable query.  I expected to see the new size; however, I did not see that.  When I ran the show variable query through mysl at the shell, I saw the new size.  Not sure why.  Anyway, it worked and I don't have time to investigate.  Need to move on to other stuff.

Tuesday, August 2, 2011

Parse HTML To Extract Certain Values Out With Java

Problem:

I needed to parse and extract some values from an html page.  I tried using JTidy, dom4j, JDOM, and the JDK built-in parser.  They gave me errors and refused to work.   They were overly complicated for what I wanted to do.  I wanted something simple and easy to parse some html to get some values from it by some queries on the elements.

Solution:

I found what I was looking for:  Jsoup!  http://jsoup.org/   It's exactly what I wanted.  I could even connect to a web site and get the Document back.

Document doc = Jsoup.connect("some url here").get();

I must say that I really like it!