The Most Beautiful Seatbelt Advocacy Commercial

I know it isn’t dev related, but couldn’t help but pass this on. So many PSA commercials are terrible. Either over the top crash videos, or a droll announcer, droning on.

This one, with no words, expresses so much emotion. It’s worth the watch regardless of the message.

http://www.autoblog.com/2010/02/05/video-the-most-beautiful-seatbelt-advocacy-commercial-ever/

And if you’re one of those people that don’t wear your seatbelt, here’s a great quote from the comments on this post

You wouldn’t get on a roller coaster without a seatbelt or harness right? Why would you get on the road with a bunch of touchscreen pushin’, cell phone tweetin’, navigation glancin’ oversized SUVs without a seatbelt? Seatbelts. Wear em’.

mnmlist

A Little Groovy Goodness

Ever since attending the SpringOne 2GX conference, I’ve been intrigued by Groovy. I’ve finally had a bit of time to start working with it, and decided to share some of the niceties of Groovy. This post is a very simple example of the differences in coding between Java and Groovy, so expect to see more as time, and my knowledge permits.

The first thing I really liked about Groovy was the removal of explicit setters and getters. I’ve always hated the clutter, and especially since it makes it harder to see if any getter/setter is doing something ‘special’, or if there are methods that aren’t setters/getters.

So, a simple bean defined like so in Java to support easier setting of variables

public class Bean {
    private long numberOfCompanies;
    private long numberOfUsersPerCompany;
    private long numberOfSecureMessages;

    public long getNumberOfCompanies() {
        return numberOfCompanies;
    }
    public Bean setNumberOfCompanies(long numberOfCompanies) {
        this.numberOfCompanies = numberOfCompanies;
        return this;
    }

	// code snipped here
}	

//used like this
    growthRequest
       .setNumberOfCompanies(1L)
       .setNumberOfUsersPerCompany(1L)
       .setNumberOfSecureMessages(2L);

becomes this in Groovy

public class bean {
    long numberOfCompanies
    long numberOfUsersPerCompany
    long numberOfSecureMessages
}

 // and gets used like this
growthRequest.identity {
   numberOfCompanies = 1L
   numberOfUsersPerCompany = 1L
   numberOfSecureMessages = 2L
}

// or like this, without defining a constructor...
	GrowthRequest gr = new GrowthRequest("numberOfCompanies:1L", "numberOfSecureMessages:2L", "numberOfUsersPerCompany:1L")

Groovy also supports the concept of a read-only property. It uses the final keyword, which is a little confusing to us Java devs, as the field isn’t final in the Java sense. A getter will be defined in the public interface of the Groovy object, but the object can still modify the value internally.

Another case that is very nice is long strings, or strings that are concatenated with variables. In Java, we have

String s = "some text that is long " +
	"and some more text that goes here" +
	someVar + " more text and more";

whereas Groovy would have

String s = """some text that is long
	and some more text that goes here
	${someVar} more text and more"""

If your string is just a regular string (i.e. no variable replacement), you can use apostrophes. If you use a single quotation mark, or triple quotation marks, then Groovy will parse the string to search for replacements. So, for performance reasons, unless you need a variable replacement, use apostrophes for strings.

The heredoc format allows for much easier test string generation. For example

String s = """
	<xml>
		<entities>
			<entity>1</entity>
			<entity id="idValue">2</entity>
		</entities>
	</xml>

Keep in mind that I’m intentionally typing variables. Groovy allows for no typing as well, so the previous example could merely def s.

TortoiseHg – The Next Version

It is available from here. From the downloads.

The latest will always be marked as unstable, as it’s still being worked on, but I’ve been using it the past month or so with no issues. Some features are hidden, or have been moved, but the pace of development is very good.

The nicest thing is the integration. Everything can be done from the workbench, and an action flows nicely through a set of dialogs, and ends up at the workbench.

Multiple repositories can also be opened.

An example of the nice touches. This morning, I did a fold. Up pops a dialog with the merged commit message, a list of the patches being folded, and a checkbox to control whether the patch files are kept afterwards. Modify the commit message and press finish. All in one step.

Another major addition is around the patch queue, and its functionality. In the past, if you wanted to move a file from one patch to another, it involved a few obscure, and potentially dangerous commands.

Now, there’s an integrated MQ manager. It allows for easy movement of files from one patch queue to another, but ALSO allows for movement of portions of a file from one changeset to another.

So, if you do a refactor, and then start on other work, but have it in one patch, you can now create 2 patches out of it. Personally, I like to commit refactors and actual new dev work separately, and with the new MQ utility, this is feasible.

Bottom line, if you’re using HG, checkout the new workbench.

Lengthen the Life of Your Dishwasher – DIY Life

Lengthen the Life of Your Dishwasher – DIY Life
Like most appliances, dishwashers often get neglected (until, of course, they suddenly stop doing their job). With a bit of routine maintenance, though, you can prolong the life of your dishwasher long after its sticker date. Here are a few easy tips for keeping your dishwasher in tip top shape:

1. Keep your hot water heater set to the temperature recommended by your dishwasher’s manufacturer; you can locate this info in your user manual. Forgotten where you stashed that old manual? Try Google-ing the model of your appliance; many manufacturers post their product manuals online.

2. Run a monthly cleanse cycle on your dishwasher. Simply empty a packet of sugar-free lemonade where you normally place detergent and run the dishwasher through a normal cycle.

3. Check the interior racks of your dishwasher. If the paint is wearing off, consider investing in a dishwasher repair kit to prevent scratches on your pots and pans.

4. Soak the spray arm with diluted vinegar monthly to clean off any scum build-up.

5. Be sure to regularly check the food trap for any residue that may have been acquired in a few weeks time.

So go ahead, show your dishwasher a little TLC — and avoid those dreaded prune hands!

Mercurial Eclipse plug-in news

The company Intland has begun using Mercurial for their own internal development (they produce CodeBeamer as well as other products). They obviously use Eclipse for their development, so they started using the MercurialEclipse plugin, and discovered its shortcomings.

As a result, they devoted a full time developer to creating a fork of MercurialEclipse. They announced the release of RC1 a few days ago, so I decided to install it.

Well, all I can say is ‘Wow!’. MercurialEclipse was ok, but in one release, Intland has taken it to very useable. They’re calling their version HGEclipse to differentiate from MercurialEclipse.

2 big highlights. They synchronize view is now very useful, as it shows uncommitted changes, incoming and outgoing changesets.

They’ve also fixed the history/compare view. Mercurial tracks file copies, but MercurialEclipse would create an error if you tried to compare a file version with the current name to one with the old name.

HGEclipse resolves it correctly, and shows the differences.

This bodes well for the Eclipse plugin for Mercurial, and I look forward to seeing what other things they enhance/fix.

Mercurial – Finding old changes made easy

The other day, I wanted to find out if a function had ever existed in a file I was looking at. So, I brought up the history view, and started browsing through the various versions.

After the 3rd one, I figured there must be a better way…. then I remembered the DataMine feature of TortoiseHG (which I imagine is using Mercurial’s grep command).

So, enter my search criteria, and a file search patter. Do a search and up pops a list of files, lines and changesets that contain that information, throughout the entire history.

Obviously, this could be slow with a really broad search, but generally, it’s quite quick. Definitely much faster than manually searching throough all the revisions of a file.

SpringOne 2GX 2009, New Orleans, LA

The conference was excellent.

The VMWare acquisition seems like it will be good for SpringSource. They want it to broaden their product offerings, and don’t have anything that directly competes. Beginning entry into Cloud computing with Cloud Foundry. You can either use it hosted by them, or install it in your own server room. All attendees will receive 48 hours of credit for use of Cloud Foundry, so I will definitely be experimenting.

Rolling out more developer editions of tools to entice us developers to use their tools. SpringSource Tool Suite is now free, and incorporates additions for their entire line. It even has a deployment tool for Cloud Foundry.

They are actively developing the Groovy/Grails Eclipse plugin as well, and are making great headway here. At the conference, the developer had a very interesting presentation on the difficulties of integrating the Groovy compiler with the Eclipse JDT compiler.

tc Server now has a developer’s edition too. In combination with the SpringSource Tool Suite, and Spring Insight, allows for digging into the actions an app took, and how long each step took. Have to do some investigation to see how well this works with a minimally Spring based app, as they used a Grails app for the demo.

Spent most of my time on the 2GX side of the conference. Decided to take the opportunity to learn more about this. Very interested in Groovy, especially since it interacts very nicely with Java. Several presentations on using Groovy to write tests for Java code, and some of the benefits possible as a result. Groovy (like other languages that are dynamic, and support closures and meta-programming) are very powerful and flexible. Groovy also requires less typing to achieve the same result as Java.

Attended 2 sessions on Gradle. The developers of Gradle developed it because of frustrations with the limitations of Maven. The developer presenting was obviously very familiar with Maven, as evidenced by his responses to questions by attendees that knew Maven very well. It leverages Maven and its central repository, and adopts Maven’s philosophy of convention over configuration BUT if you don’t like it’s convention, or want to extend it’s definitions, it is easily accomplished. Yay to a distinct integration test task, with its own classpath and dependencies!

Overall, an excellent conference, and I will post additional details as time permits.

SpringOne 2GX Conference – Day 1

Day 1 was mostly about registration, checking-in and the keynote. Here’s a great summary of what was covered in the keynote. KeyNote summary.

I’ve mostly been looking at Groovy sessions, and can see a lot of potential here. Will keep providing updates as the conference progresses.

Definitely want to look more at the tc Server. SpringSource/VMWare are hopeful companies will use it instead of Jboss/Websphere/…

They demo’d the new developer’s edition with Groovy and Grails, and were able to dig into all the queries. Great way to find bottlenecks when performance isn’t working well. Don’t know if it can do it with Java/Tapestry/Hibernate, but likely no reason it can’t. Obviously they’re leveraging the HtpericHQ acquisition for aspects of this.

Managing Version Control

In a previous post, a colleague was venting about having to manage the version control system with a commit token. Basically, the token is held by someone while they’re doing there commit, so that no other developer is supposed to commit, and potentially create conflicts. As a number of us are using CVS, this is a real issue. CVS handles each file individually, so it may stop the commit of only 1 file, thus leaving the repository in a broken state.

But this is only one of the reasons for having the commit token. The other major reason is ensuring that developers have tested their code with the latest version in the repository before committing. A process is in place once a developer recieves the token.

  • update
  • fix conflicts
  • run tests
  • commit

This is done to reduce the chances that broken code ends up in the central repository, thus impacting the other developers, and their productivity.

To reduce queue sizes, various guidelines can be used, such as no retrieving the token unless you’ve recently done an update and run the tests.

Bottom line, it can be managed….. BUT as others have said, is there a better way? Do we need an artificial, external locking mechanism?

The answer would appear to be no, as long as you’re willing to move to a new VCS. Of course, this has it’s own potential issues, but I’m currently spearheading an initiative on my team to start using Mercurial for our development.

Mercurial is a distributed VCS. It uses atomic commits (Subversion was one of the early implementors of this feature), and tracks renames. It also makes branching AND merging very easy.

Doing a quick experiment, if 2 developers were to commit, one would succeed, and the other would be warned that they’re attempting to create a new head. So, developer 2 would know someone else committed, and that they need to do the update/merge/test/commit cycle. So, theoretically, there would no longer be a need for an explicit commit token.

Even if the token concept is persisted, or I’m waiting for other developers to complete a large commit, I can commit my changes locally, do some more work, do another commit, and then when I’m allowed to ‘commit’ to the central repository, I merely update, test and push.

If I’m in the middle of something, I can shelve my outstanding changes to update/test/push, and then unshelve to return to where I was at.

There are many more advantages of Mercurial, and as my team starts using it next iteration, I’ll keep posting updates.

JMock and return Values

A colleague was working on a unit test the other day, and couldn’t figure out why it wasn’t working correctly. At a high level, here’s the testing code.

List<String> strings = new ArrayList<String>();
strings.put("value");

ListLikeAPIObject mockObject = mock(ListLikeAPIObject.class);

context.checking(new Expectations() {{
	exactly(2).of(mockObject).iterator();
		will(returnValue(strings.iterator());
}}

and this is the code in the class under test:

ListLikeAPIObject listObject = apiCallToGetList();
for(Iterator iter = listObject.iterator(); iter.hasNext();) {
	doSomething();
}

and the above method gets called twice during execution of the method being tested.

On the second call to listObject.iterator(), the for loop doesn’t do anything.

JMock ‘caches’ the result of the returnValue option, and returns the same object each time that method expectation is reached. The first time it’s called, strings.iterator() is at the beginning.

The next time it’s called, the iterator is now at end, so the for loop doesn’t process anything.

JMock2 has a built-in return Action for handling this case. There are several others defined (look at implementors of Action), and shortcut methods defined on Expectations. Taking advantage of this results in the following:

context.checking(new Expectations() {{
exactly(2).of(mockObject).iterator();
	will(returnIterator(strings));
}}

The returnIterator constructs a ReturnIteratorAction. The ReturnIteratorActions stores the collection, and then calls strings.iterator() everytime the mocked method is called.

Javascript performance in IE and FF

I was working on a page recently that displayed a number of items for a user to choose. Visually, it displays as a long list, with checkboxes and descriptive text.

The user has the option to select/deselect all items on the page. I was doing stress testing of the page, as the client had told us there could be up to 4000 entries on the page. Don’t worry, this page will be re-designed, but for now…

I was testing in Firefox, and selecting/deselecting all items was very quick. I then tested in Internet Explorer, as our client’s mandated browsers are Internet Explorer 6 and 7 and Firefox 2.

I have IE 8 installed, and it was taking 10-12s to select/deselect all. I then asked one of my co-workers to attempt it with IE6. IE6 timed out!

Needless to say, this is unacceptable performance.

Time to dig into the javascript.

Here’s the original code:

var count = 0;
var checkboxes = document.getElementsByTagName("input");
for (var i = 0; i < checkboxes.length; i++) {
    var element = checkboxes[i];
    if (element.type == 'checkbox') {
        ++count;
    }
}

The page doesn’t have much code outside of the long list, but I had to do something, so the only thing I could see was getting the ul that contains the list items, rather than searching the entire document. So, here’s the modified code

var ulField = document.getElementById("permission.list");
var checkboxes = ulField.getElementsByTagName("input");
for (var i = 0; i < checkboxes.length; i++) {
    var element = checkboxes[i];
    if (element.type == 'checkbox') {
        ++count;
    }
}

Basically, retrieve the ul, and then search within it.

That one minor change made it so that even in IE6, the select/deselect all on 3000 items has a negligible delay.

Moral: Be as specific as possible as soon as possible, even if it doesn’t seem like it should make a difference.
Moral2: Internet Explorer’s javascript engine is slow….

Javascript is functional…

When browsing through some code on one of our pages, I noticed the following:

function selectAllCheckboxes() {
    var count = 0;
    var checkboxes = document.getElementsByTagName("input");
    for (var i = 0; i < checkboxes.length; i++) {
        var element = checkboxes[i];
	if (element.type == 'checkbox') {
	    element.checked = true;
            ++count;
	}
    }
    updateSelectedCheckboxCount(count);
}

function unselectAllCheckboxes() {
    var checkboxes = document.getElementsByTagName("input");
    for (var i = 0; i < checkboxes.length; i++) {
        var element = checkboxes[i];
	if (element.type == 'checkbox') {
	    element.checked = false;
	}
    }
    updateSelectedCheckboxCount(count);
}

function updateSelectedCheckboxCount() {
    var count = 0;
    // count the number of checkboxes selected on the page
    var checkboxes = document.getElementsByTagName("input");
    for (var i = 0; i < checkboxes.length; i++) {
        var element = checkboxes[i];
	if (element.type == 'checkbox') {
	    if (element.checked == true) {
	        ++count;
	    }
	}
    }
    updateSelectedCheckboxCount(count);
}

There’s a lot of duplication there, and only 1 or 2 lines unique to each function. So I refactored the code to take advantage of the fact that Javascript supports passing functions.

Here’s the modified code.

function selectAllCheckboxes() {
    processCheckboxes( function(checkbox) { checkbox.checked = true; ++count;} );
}

function unselectAllCheckboxes() {
    processCheckboxes( function(checkbox) { checkbox.checked = false;} );
}

function updateSelectedCheckboxCount() {
    processCheckboxes( function(checkbox) { if(checkbox.checked) { ++count; } );
}

function processCheckboxes(checkboxProcessFunction) {
    count = 0;
    var ulField = document.getElementById("permission.list");

    var checkboxes = ulField.getElementsByTagName("input");
    for (var i = 0; i < checkboxes.length; i++) {
        var element = checkboxes[i];
	if (element.type == 'checkbox') {
	    checkboxProcessFunction(element);
	}
    }
    setSelectedCount();
}

This way, if the process of getting checkboxes can be improved, the code only has to be changed in one place.

So, don’t forget that javascript is a functional language…

Bing is alive…

Microsoft has re-re-re-re-released their search engine, and now they’re calling it Bing. Some people have joked it stands for ‘But it’s not Google’, but who knows?

It appears Bing has a decision engine behind it to attempt to improve the results. Of course, the user has no control over the decisions/filtering, so…

One blogger, after watching the promo, wondered if this might be the end of smaller stores for searches (although Google suffers from the same issue anyway). If you search for Home Depot, Bing will also put up links for Lowes and Wal-Mart on the side.

Anyway, the point of this post is someone has created a webpage that allows you to enter a search criteria, and it will pass it to both Bing and Google, and display the results in a split screen on your browser.

Compare Bing to Google

If you’re on Windows and use Firefox, look for this

Just read that a recent update pushed out by MS adds a serious vulnerability to Firefox. The Microsoft .NET Framework 3.5 Service Pack 1 also installs an add-on in Firefox. You may have noticed the add-on if you’ve recently looked in your Firefox add-ons dialog.

Just read an article that I unfortunately don’t have difficulty believing. This add-on adds ‘One-Click support and the ability to report installed .NET framework versions to the web server’.

Reading the article linked below, it appears this really means ‘a web page can install something without notifying the user’.

Here’s the article explaining the risks, and how to uninstall the add-on.

And I found an interesting comment at the bottom of the article…

(And if you’re thinking, “Why not just use a Mac,” may I remind you of the MobileMe junk recently installed on so many Windows machines without their owners’ permission!)

Batch files and portions of file parameter

The following table outlines how you can modify the passed parameter.

Parameter Description
%1 The normal parameter.
%~f1 Expands %1 to a fully qualified pathname. If you passed only a filename from the current directory, this parameter would also expand to the drive or directory.
%~d1 Extracts the drive letter from %1.
%~p1 Extracts the path from %1.
%~n1 Extracts the filename from %1, without the extension.
%~x1 Extracts the file extension from %1.
%~s1 Changes the n and x options’ meanings to reference the short name. You would therefore use
%~sn1 for the short filename and %~sx1 for the short extension.

The following table shows how you can combine some of the parameters.

Parameter Description
%~dp1 Expands %1 to a drive letter and path only.
%~sp1 For short path.
%~nx1 Expands %1 to a filename and extension only.

Guest Mode for Windows

Windows 7 will be building this functionality in, but it is currently available for XP and Vista.

Microsoft has made available SteadyState. This program allows you to create a user, and control what they have access to. It also allows the user’s changes to be rolled back when they logoff.

Great for the kids, or guests that want to use your machine to check their email, but you don’t want them making any accidental changes to your system.

DVD and Video conversion for the iPod

Updated Mar 19, 2009.

I’ve found a very good donateware program for converting video for the iPod. It’s called iPodMe, and it works very well. Select videos you want to convert, select a profile and screen size. Can add additional files to be converted while it is currently converting.

Well worth checking out

============== original below ====================

I recommend DVDFab for ripping DVDs. Just download the installer, and when it starts, it will ask which version you want to run.

A 30 day trial to the full-blown version, which has built-in functionality for splitting and merging dvds in various ways. There is also an option that never expires that allows for copying of the dvd to your hard-drive. Either then entire DVD or just the main title.

Once it’s on your hard drive, you have to convert it.

If you have Nero, Nero Recode is very good for taking a dvd and converting it to iPod format. Also works for most data files.

I imagine Roxio has tools that are similar to this, but have no personal experience.

If you don’t have Nero, then Super is a very good free converter. It doesn’t handle dvd files ‘elegantly’, but works very well for everything else. The interface is a bit tough to work with initially, so expect a learning curve.

Super will convert DVD files, but a movie is broken into 1GB files on the DVD. So, you’ll end up with 4 or 5 files/movie, instead of one file.

I haven’t looked for other free options that will convert a DVD nicely, so don’t have any suggestions.

Also, if you do decide to purchase Nero, don’t buy it directly. Right now, the Nero site is showing $79.99 US for download, but you can buy it boxed at Future Shop/Best Buy for $69.99.

If you’re really comfortable with computers, then Super will work, and there are likely programs around that will convert a DVD nicely. If you’re willing to invest a little money to have an easier to use experience, I would suggest Nero or Roxio.

Also note that this conversion is very CPU intensive. If you have a relatively new dual-core computer, expect the conversion to take about 1/3 of the length of the movie. i.e. a 1 hour movie would take 20 minutes to convert. If you have a really fast machine, it will obviously be faster.

For television shows, I recommend uTorrent for downloading, and EZTV for finding show downloads. If you’re interested in this as well, I can provide more specific information.