Archive for the ‘techdetails’ Category.

Expanding A VMWare Client Disk

I’ve become a big fan of vmware, but if you undersize a virtual disk and need to expand it on Linux, brace yourself for about an hours worth of work (at minimum.)

Here’s the process I eventually followed (this seems way too hard/complicated)

  • BACKUP up your virtual machine!!!
  • expand the virtual disk:
    vmware-vdiskmanager -x 16GB myDisk.vmdk
    

for instance this will size myDisk to 16GB (this size isn’t additive it’s an absolute size)

  • Now you must boot your virtual machine into DOS or some OS that will recognize your disk, I went the BartPE route and added the vmware scsi driver so it would recognize the
    scsi disk. I couldn’t find the actual scsi driver on the web fotunately I had a copy of the VMWare Converter which
    contains a copy of the drivers. You can follow the instructions at this site but the driver that is offered is incomplete.
  • Once you’ve booted BartPE start diskpart and issue the following commands:

    • diskpart> list disk
    • diskpart> list volume
    • diskpart> select volumen=n
    • diskpart> extend
    • diskpart> exit
  • Reboot the virtual machine, restarting Fedora (or your brand of Linux)
  • Start the Linux Volume Manager (lvm)

    • Find the physical volume with lvm> pvscan
    • Resize the physical volume lvm> pvresize /dev/sda?
    • Resize the logical volume lvm>  lvresize -L 14G /dev/VolGroup01/LogVol00
    • lvm> exit
  • Finally resize your filesystem with (on Fedora, other brands of linux may have a different command):

root# resize2fs /dev/mapper/VolGroup00-LogVol00

  • Sheesh, that was a lot of work, the procedure for windows seems slightly easier, but I couldn’t find all this information
    easily in one place for Fedora/Linux, good luck.

Converting epoch to date and vice versa

I’ve been doing a lot of date related things in Java recently, and having an independent tool to generate sane test data is very handy.

Try it here: http://www.esqsoft.com/javascript_examples/date-to-epoch.htm 

Also includes free Javascript, nice.

Also check out thisother java script date library.

http://www.ajaxian.com/archives/mad-cool-date-library 

The original reference is good for near dates but seems to drift quite a bit for dates way in the future. The following link seems to do a very good job of date caclulations, plus it includes a number of rather unusual calendars and things like MS-Excel date serial numbers, very handy.

http://www.fourmilab.ch/documents/calendar/

Toronto Demo Camp 16

Tonight is Toronto Demo Camp 16, there are still free seats available:

http://democamp.eventbrite.com/ 

Location
Toronto Board of Trade
1 First Canadian Place
Toronto, Ontario M5X 1C1
Canada

An awesome customer service experience!

It is so rare to have an awesome customer service experience; I have to share this one.

I came home Friday night to find my computers in my office all shut off and the damn replace battery alarm beeping every five seconds on my UPS (highly annoying.) So it was time to order some new batteries, I went to APC(Canada) and ordered the replacement batteries via CDW, and then tried to figure out how to stop the infernal beeping (which took nearly 3 hours and 2 bourbons.) On Monday morning I got a call from a very nice person Natashe informing me that I had placed my order with the CDW US and not CDW Canada, but that she had canceled my order in the US and placed a new order here in Canada and that my batteries would arrive tomorrow. This is jaw dropping amazing service as far as I’m concerned, and my batteries arrived around 10am on Tuesday.

Three cheers for CDW the left hand really knows what the right hand is doing and thanks again.

Esoteric Ant Hacks

When debugging ant build scripts (fun wow,) sometimes you want to view the contents of a path reference, this handy hack does just the trick:

<echo message="${toString:pathref}"/>

It probably also works for other “classes” as well.

After a little more digging around (my ant is a little rusty) the proper way to do this is to convert your path reference to a property:

<property name="class.path" refid="class.path.ref"/>

Finally a little sugar to print out your classpath in a human readble form:

<!-- pretty print the class path so it is human readable -->
<macrodef name=\"print_classpath\">
 <attribute name=\"path\"></attribute>
 <attribute name=\"description\" default=\"=== CLASSPATH ===\"></attribute>
 <sequential>
    <echo>@{description}</echo>
    <for list=\"@{path}\" param=\"pathitem\" delimiter=\";\">
       <sequential>
          <echo>pathitem == @{pathitem}${line.separator}</echo>
       </sequential>
    </for>
    </sequential>
</macrodef>

Note you will need the for loop from ant contrib to use this macro/task

<<taskdef resource=\"net/sf/antcontrib/antlib.xml\" classpathref=\"ant.classpath.tools.lib\">

Coding Horror

Given the rate that I’m running accross these little horrors, this may become a regular post.

public static String trimLeadingZeros( String trimString )
{
         String retVal = trimString;
         boolean nonZeroFound = false;
         StringBuffer rtnString = new StringBuffer();
         if ( trimString != null ) {
                  for ( int index = 0; index < trimString.length(); index++ ) {
                                char c = trimString.charAt( index );
                                if ( c == '0' && nonZeroFound == false ) {
                                         // skip all leading zeros
                                } else {
                                         nonZeroFound = true;
                                         rtnString.append( c );
                                }
                  }
         }
         if ( rtnString.length() > 0 ) {
                  retVal = rtnString.toString();
         }

         return retVal;
}

Obviously this person doesn’t have a degree in computer science or they failed out.

  • The have an empty if statement, what you’re not capable of doing the necessary boolean algebra in your head to invert the conditional, give me a break
  • Hey lets scan every character whether you need to or not, making this O(n) where n is the total number of charaters in all strings being scanned (sheesh)
  • How many damn variables do you need to do this 5! Could we make this any more complex
  • The real shame is that the JDK doesn’t have a general strip/trim function, they have a trim whitespace, so why not generalize it.

So in about 5 minutes I put a more general  version together which O(f(x)) << O(n), in the general case my version is 2.5 times faster than the horror. For the pathalogical case my versio is only.8 time faster, and for the ideal case we’re 3 times faster. This was all done over 1 million iterations using the same string that was 20 characters long.

public static String trimLeadingChar( String trimString, char trimChar )
{
        try {
                String tempString = trimString;
                int offset = 0;
                while( tempString.indexOf( trimChar, offset ) == offset )
                        offset++;

                tempString = tempString.substring( offset );

                if( tempString.length() == offset )
                        return trimString;

                return tempString;
        } catch( NullPointerException ex ) {
                return trimString;
        }
}

I’m using a very Pythonic idom here, which is to not care about the NullPointerException, so instead of explicitly checking
for trimString == null, we just catch the excetption and do no harm. I could have made the while loop empty, but frakly I find
that a little bit vulgar.

Coding Horror

I ran across this gem today…

static public Date getYesturdaysDate() {
        Date yesterday = new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24);
        return yesterday;
}

All I can say is WTF? How does something like this get through and then hang around without being cleaned up.

WebSiteGrader is pretty handy

This is a great site for getting the measure of your site via a series of very common metrics all in one place. What I really like, is that WebSiteGrader red flags omissions in your page content and design.

If covers:  google, alexa, technorati, yahoo, delicious

See it here: http://www.websitegrader.com/ 

Seen via Social Media Today

YUI why do you tempt me so?

I’ve been trying to use the YUI web tools and I have to say it isn’t easy. So far I haven’t been able to get one of their menu examples to work inside my web app. They work fine in their simple example files, but I haven’t been able to incorporate one of the examples so far. Deeply frustrating, anyways I’ll poke around to see if I can find a simpler toolkit or perhaps role my own if I get desperate enough.

One thing that would be nice, is to have an integration guide for YUI, with emphasis on CSS and Javascript gotcha’s. Also almost every example I look at has a different group of CSS/JS files, and I know that YUI is a quickly evolving toolkit and that segmenting CSS and JS files makes for better download performance, but both of these factors really steepen the learning curve.

Handy CPU benchmark tool

When upgrading machines it always handy to know what your options are. This is the best benchmark comparison tool I’ve seen, you can select two processes from an extensive list of CPUs. Of course you can find it at Tom’s Hardware: CPU Chart 2007