Monday, 19 March 2012

Full Sized Wallpaper For The Samsung Galaxy S

Setting the wallpaper doesn't seem all that obvious. Initially you look in the Android standard Menu - Wallpaper - Home Screen Wallpaper. Then you can pick a file. This is all fine until you realise that you cannot select the full size of the image. Only a fixed area that doesn't seem to scale.

Instead, I found it easier to resize the image manually to 800x960 and then use the Wallpaper Set and Save App to set the wallpaper.

Samsung GALAXY S Video Conversion

Converting video for the Samsung Galaxy S is as simple as the ffmpeg command below:

 ffmpeg.exe -i %1 -s 800x480 -vcodec mpeg4 -b:v 800k %1.samsung.mp4  

Importantly, the screen and resolution on the AMOLED display require a higher than default quality setting on the converted video. Otherwise you'll end up with a poor result.

As with before, paste the above command into a batch file and use it as a command line utility or as a drop target. You will need ffmpeg installed an on the path. But you knew that already right?

Wednesday, 14 March 2012

IBM ThinkPad X40 Compact Flash hard drive

The IBM ThinkPad X40 has proven to be a stalwart system. Both compact and with reasonable specification it can handle most programming tasks I throw at it. However, of late it has been suffering the slow painful stuttering process of its hard disk aging.

After doing some research it seems there are a number of people who have decided to replace the hard drive with a Compact Flash card. This is something I've been interested in trying for a while.

Components

ThinkWiki provides the starting point for the research along with various blogs. The following components have been selected for the upgrade.

PA-CF18H Adapter - Initially I had selected the Addonics adapter mentioned on the wiki, but it was only available from the US. Instead I found that Amazon UK sold a similar adapter by Sintech. It turns out that this is a product intended to be a replacement for 1.8" drives and is sized to fit into the same space and there was plenty of evidence to indicate that it worked successfully.
Transcend 16 GB 400x TS16GCF400 - This was a much more tricky a choice to make. Importantly for a Windows based Compact Flash installation, it must report to be a fixed drive. All Transcend cards do this automatically which was why I selected this card. Then it was a balance between speed and cost. There is the 600x series, but at almost double the price that put it outside my budget.
Sintech 2.5" to 3.5" adapter ST4044A - This component is not needed for the drive replacement, but it was essential in order for me to get an operating system onto the Compact Flash card. The X40 has no CD Drive so another system will be used to install and test the drive before replacing the laptop hard drive.

Proceedure

The following steps cover the replacement:

Format & Install

I connected the Compact Flash card and adapter to my main PC and ran through the standard Windows XP installation. The BIOS and Windows recognised the card as a hard disk and I was able to start the installation.

Note: I noticed that formatting the drive as NTFS seemed to cause the installation to take a very long time complete. Instead I reverted to FAT32 and found that the process was much faster. It seems the Compact Flash card is better suited to FAT32.

Configure Boot Loader

Once installation is complete, I encountered the somewhat dreaded "NTLDR is Missing" error message which occurs just after the BIOS completes its POST and tries to load the Operating System. Googling for this brings up various results until I found this page.

The reason the NTLDR error appears is because NTLDR looks at the drive geometry of the Compact Flash card, and finds it does not match what it was expecting. To solve this problem I followed the instructions from the article above and replaced the NTLDR boot loader with GRUB4DOS.

In order to complete this, I connected the Compact Flash card to a PC with a Card Reader. This will allow us access to the drive, to put the new bootloader onto it.

  1. Connect the Compact Flash drive a PC using a card reader.
  2. Download MBR Installer
  3. Download GRUB4DOS
  4. Using the Disk Management control to work out which drive the Compact Flash drive is. This is via Start -> Run -> "diskmgmt.msc" then look for the disk number of the Compact Flash drive.
  5. Extracted the grubinst executable from the "grubinst_1.0.1_bin_win.zip" and then from the command line, executed grubinst --pause (hd2) (where hd2 was the Compact Flash card drive number). This completed successfully.
  6. Copy "grldr" from the "grub4dos-0.4.4.zip" to the root folder of the Compact Flash card.
  7. Created a file called "menu.lst" in the root folder of the Compact Flash drive with the contents "chainloader /ntldr".

After these modifications, the Compact Flash drive would successfully boot and allow me to finish off the Windows installation and subsequent configuration.

Installation Into Laptop

The installation of the adapter is fairly straight forward. From the underside of the laptop, the hard drive is located on the left hand side towards the front.

The hard drive has a cover which is clipped onto the drive. This cover is screwed onto the chassis. Remove the marked screw and then carefully use the cover to extract the hard drive from the chassis. The hard drive slides out quite smoothly.

The hard drive screw mounted onto a tray which we will use to hold the Compact Flash adapter as the PA-CF18H fits exactly into the tray and this gives us a bit of extra purchase when slotting it back into the chassis. On my system there was some glue holding the hard drive into the tray, this comes apart with a little persuasion.

Place the adapter into the tray, and reinsert the tray into the chassis. Carefully guide the pins of the adapter into the corresponding connector being careful not to bend any pins. The tray should fit neatly inside the chassis.

Reattach the cover

References

I found the following blogs very useful:

The following articles were helpful:

Adapter Manufacturers:

Tuesday, 13 March 2012

Read a file in Java - oneliner?

Can anyone read a file in Java using the standard libraries in a single line?

This was the best I could do:

1:      public static List<String> readRows(InputStream stream) {  
2:          try {  
3:              byte[] data = new byte[stream.available()];  
4:              new DataInputStream(stream).readFully(data);  
5:              return Arrays.asList(new String(data).split("\\r\\n|\\n|\\r"));  
6:          } catch (IOException e) {  
7:              throw new IllegalStateException(e);  
8:          }  
9:      }  

It has the obvious caveat that stream.available() only returns an estimate for the size of the stream so this isn't suitable for production code.

This is one line longer and the more sensible choice, though I am being deliberately terse with the for loop:

1:      public static List<String> readRows2(InputStream stream) {  
2:          try {  
3:              LinkedList<String> rows = new LinkedList<String>();  
4:              BufferedReader reader = new BufferedReader(new InputStreamReader(stream));  
5:              for (String data = ""; (data = reader.readLine()) != null; rows.add(data));  
6:              return rows;  
7:          } catch (IOException e) {  
8:              throw new IllegalStateException(e);  
9:          }  
10:      }  

I'm aware that Guava and Apache Commons have utilities for this problem, so those would be also good choices.

Monday, 12 March 2012

Thoughts On Estimating Software Engineering

detailed design. Down to the class level in order to define the responsibilities for each component.

Estimate each responsibility. Aggregating small estimates will average out any margin of error.

Factor in risks. New library, interfacing with legacy code, researching a new algorithm etc. All risks should increase your estimates.

Include unit test time. Allocating time for them ensures they get done. Responsibilities of a class and unit tests will closely correlate. TDD will change the way you think about unit testing.

Aggregate and review. Does the number look reasonable? If not, what have you missed. Iterate as required.

Collect metrics and review. Adjust concepts as required. Build up standard estimates for tasks/responsibilities. Enable future estimation effort with metrics.

Saturday, 10 March 2012

Compacting VMWare Virtual Drives

After investigating the amazing MicroXP I was interested in compacting the VMWare Virtual drive.

However after defragging and compacting using the VMWare tools for this I found that the drives were taking up more space than the guest operating system.

After looking into this a little further it seems that when the guest os deletes a file from the drive the VMWare drives don't clear deleted files from the drive, probably as an optimisation.

So i grabbed the flexible ccleaner and used its drive wipe function. This zeros free space on the drive which nulls the space on the VMWare drive.

Then rerunning the drive defrag and compact process produces a much more representative drive size that closely matches the size of the guest os.

And the result, a compressed VMWare image of the MicroXP that weighs in at 170mb. Fantastic and perfectly DropBox friendly. As a bonus, once defragged the os boots amazingly fast.

Thanks go to this chap for his write up of MicroXP.