logo
  • Jobs
  • About Me
  • Contact
  • Home

Archive for March, 2005

« Previous Entries

Windows 2003 SP1

Looks like the Windows 2003 Service Pack 1 just made it to the MSDN subscriber downloads. Everyone should take a minute and install this to take advantage of the security upgrades provided. I understand this is the server equivalent of XP SP2.

I imagine that it will be generally available (via Windows Update) shortly.

No Comments

An attempt to recapture my youth

Early on in my teens, I was introduced to Motley Crue. Some of their early songs made quite an impression on me and that style of music was a significant part of my teenage years. Tonight, in an attempt to try and recapture days gone by, I went to see the Motley Crue show as it rolled through Boise, Idaho. I was not really sure what to expect… Although once the lights went down and the circus tent became visible, I knew what I was in for…

The first thing I need to say that I was completely surprised by the average age of the attendees. It had to have been at least 35. Clearly, Motley Crue has not gained any new fans since their last significant studio album (Dr. Feelgood) almost 16 years ago.

All told, the show was what I hoped it would be: a big party and a wonderful time.

It was unexpected to see these guys growing older, slower and fatter (as we all do). In my mind, they were timeless. I was expecting to see these 20-something party-animals running around stage like I did when I last saw them in 91.

Mick Mars (the guitar player) had recently had a hip replacement surgery and his battle with Ankylosing Spondylitis resulted in his inability to move his neck as the joints and bones in his spine are fusing together. This guy looked like he was 80 years old out on stage. I half expected to see a wheelchair to take him off.

Vince Neil (the singer) was so old and out of shape that he could not put an entire vocal line together during the whole set. What you got was the first and fourth word of the line and that was it. Thankfully for him, the audience knew virtually every word to every song and picked up where he left off.

Watching these guys on stage, combined with the energy in the crowd did take me back to my youth, if only for a couple of hours. That alone was worth the $45 admission. Thanks guys, for a great time and giving me something I never thought Id see again… the original Motley Crue, live and on stage.

No Comments

The importance of CultureInfo

The latest issue of the MSDN magazine offers a wonderful article by Michael Kaplan entitled “Make the .NET World a Friendlier Place With the CultureInfo class“. In this article Michael shows the many possible uses of this class, as well as how to choose the correct one.

I think that CultureInfo is one of the more important, and yet less understood classes in the .NET framework.

Let me give an example of its importance. In a project that Im working on, we have a tiny data object that just holds some information about a specific piece of data. One piece of this information is a DateTime that details when this data should expire.

The requirement was that for any new pieces, we want them to expire on a specific date, allowing the user the capability to change this date. What we did was something similar to this:

class MyDataObject
{
    private DateTime expireDate;
 
    public MyDataObject()
    {
        expireDate = DateTime.Parse("12/31/2099");
    }
}

Ok. Granted, I could have done this differently by using one of the DateTime constructors. However, Im kind of glad I didn’t, because otherwise I would not have discovered how important the CultureInfo class is.

This class was working great. It passed all of our testing with flying colors. We deployed and no issues. One day our support staff received a phone call from a client. Every time they attempted to create a new piece of data, the application would throw an exception about an invalid date format.

I had looked through the code and could see nothing out of the ordinary, and of course was unable to reproduce this on my development environment. After some more troubleshooting, I found out that this client happened to be in the United Kingdom. For those of you unfamiliar, the United Kingdom (and most European nations) have a DateTime format of DD/MM/YYYY.

Given my code above, it was attempting to parse the 12th day of the 31st month, because that Parse method was using the current culture. Clearly this should throw an error. The resolution to the issue was to pass CultureInfo.InvariantCulture to the Parse method.

When you’re taking a string that is purely data, rather than written words in the default culture, you need to be careful to treat it with the invariant culture. Most routines that have culture dependent behavior (String.ToUpper, String.ToLower, String.Compare, DateTime.Parse) will give you the opportunity to pass in the culture directly. Passing in CultureInfo.InvariantCulture is the way to make sure that your data parsing and comparison operations are correct.

CultureInfo.InvariantCulture should be used by methods that require culture independent results. Otherwise, it produces results that may be culturally inappropriate or linguistically incorrect.

No Comments

The Specification Pattern: A Primer

The Specification pattern is a very powerful design pattern which can be used to remove a lot of cruft from a class’s interface while decreasing coupling and increasing extensibility. It’s primary use is to select a subset of objects based on some criteria, and to refresh the selection at various times.

For example, I’ve seen a lot of classes that have interfaces that look something similar to this:

public class User
{
    public string Company;
    public string Name;
    public string City;
}
 
public class UserProvider
{
    public User[] GetUserByName(string name)
    {
    }
 
    public User[] GetUsersByCity(string name)
    {
    }
 
    public User[] GetUsersByCompany(string company)
    {
    }
}

Using this model, you can see that every time you want to add a new condition for user retrieval, you have to add a method to the UserProvider class which obfuscates the interface.

Now, lets look at the same example using the specification pattern.

public class User
{
    public string Company;
    public string Name;
    public string City;
}
 
public class UserSpecification
{
    public virtual bool IsSatisfiedBy(User user)
    {
        return true;
    }
}
 
public class UserProvider
{
    public User[] GetBySpecification(UserSpecification spec)
    {
        ArrayList list = new ArrayList();
 
        UserCollection coll = SomeMethodToPopulateTheUserCollection();
        foreach (User user in coll)
        {
            if (spec.IsSatisfiedBy(user))
            {
                list.Add(user);
            }
        }
 
        return (User[])list.ToArray(typeof(User));
    }
}
 
class UserCompanySpecification : UserSpecification
{
    private readonly string companyName;
 
    public UserCompanySpecification(string companyName)
    {
        this.companyName = companyName;
    }
 
    public override bool IsSatisfiedBy(User user)
    {
        return user.Company.Equals(companyName);
    }
}

Using the specification pattern, we have removed all of the specialized methods from the UserProvider class. Also, because of the loose coupling, any time we want an additional condition for user retrieval, we need to only implement a new UserSpecification and pass this instance off to the GetBySpecification method, rather than polluting the existing interface.

This allows the calling code to determine exactly how it wants to filter any given collection, rather than the provider code assuming that it knows how the user wants it.

Of course, there is nothing preventing an API designer from putting a few commonly used specifications into the API itself.

This pattern is very powerful, but like anything can be overused. Make sure to review the consequences in the linked description of the pattern for when you should and shouldnt use this pattern.

4 Comments

AJaX: The latest buzzword

The latest buzzword du jour is AJaX (Asynchronous Javascript and Xml). I’ve been reading a lot of posts lately that sound like this concept is brand new and will be singlehandedly responsible for migrating applications from the desktop to the browser.

Let me clear a few things up. First off, this technology is far from new. The XMLHttpRequest object has been around since Internet Explorer 5.0. I know that I’ve personally used this technique as long as 2 years ago. Secondly, AJaX will in no way be responsible for replacing desktop applications. An implementation like GMail or Google Maps is ridculously difficult to implement properly.

The latest round of AJaX enabled applications (Google Maps and GMail) are quite impressive. I’m not going to take anything away from these applications, especially considering that they are running in a web browser. However, what is the user experience when compared to a desktop application such as Thunderbird or Outlook.

For the developer’s toolbelt, AJaX is just like anything else. You wouldnt use a brand new screwdriver to drive a nail. A good developer will keep AJaX in their toolbelt and use it when appropriate.

I’m afraid whats going to happen here is that every non-technical manager-type person is going to hear ‘AJaX’ and start asking the development staff how to leverage this technology. If the requirements call for it, then use it. However, do *not* make the requirements fit the technology.

All this being said, there are some good resources available on the web, including:

* Ajaxian.com (the AJaX blog)
* Very Dynamic Web Interfaces (xml.com)
* AJaX and ASP.NET resources

No Comments

Virtual PC Default Paths

As stated in previous entries, I do all of my development work inside of Virtual PC images. This has suited me quite well. One of the grumblings that I had with Virtual PC was that it did not remember your last used path, and always defaulted to \My Documents\My Virtual Machines.

In some scenarios this would be just fine. However, I store all of my VPC images on a large USB drive, so every time I want to load up a new VM or point to an existing VM, I always had to navigate to my external drive first.

Earlier today I was forwarded a tip that solves this problem. Set an environment variable (My Computer | Advanced | Environment Variables) called MyVirtualMachines with the path you wish to use (F:\vms, in my case).

1 Comment

Changes

Some major changes have occurred here at mattberther.com in hopes of making this a better place. I want to take a minute and discuss them.

First and probably foremost: comments and trackbacks have been turned off. I had implemented a CAPTCHA solution a while back, but started noticing comments start trickling through again. It’s not going to be long before these spammers realize that they can use other mechanisms to post comments without even visiting the site. Trackbacks are completely unmoderated, and when I wake up in the morning to several hundred trackbacks that involve any possible fetish you might have, all the prescriptions medication you could possibly want and any number of online Texas Hold’em sites, I just have to say enough is enough.

That said, its been a really tough decision to make. I completely enjoy the bi-directional nature of the weblog. There comes a point though that when the cost of the upkeep takes over. However, I still want to hear from my readers and to make that easier, I have placed a contact link on every single page on this site. Please drop me a line and let me know what I can do better and what you’d like to see more of. Your feedback is *very* important to me.

I’ve also scaled down the site’s UI significantly. It was starting to become incredibly overwhelming and content was being hidden for other things. I’ve removed the google ads and all the extra sidebar stuff in hopes of recapturing the clean crisp layouts that I really like. To be honest, the google ads and search box will probably come back to the individual pages as soon as I can find a good way to put them on there that doesn’t detract from the actual content.

With version 3.1, MovableType has supported a dynamic templating model which Ive also now adopted. The previous version of this site consisted of each page being an actual HTML file on the filesystem. Honestly, this was the only thing that bugged me about MovableType’s implementation. I’ve finally taken some time to make this change and I’m elated about this. No longer will I need to rebuild every single page on the site for a simple change to the navigation module.

Some things are being removed, including all comment feeds and rdf feeds. Since comments and trackbacks have been turned off, this feed is now useless. After reviewing my access logs for this year, I had only 700 hits to the index.rdf feed. It seems like everyone is now using the atom or rss2 feeds. I will be modifying the above items to provide notice that the items will be going away. I imagine that the feeds will be removed after a weeks time.

This blog started out almost two years ago and has been a great outlet for me to share tidbits of knowledge with you and I hope to continue on in the future.

Thanks to my readers. Your support means a lot to me.

No Comments

Creating a FormsAuthentication compatible MD5 hash

A very common question that Ive seen come up in the ASP.NET newsgroups is how to make an MD5 hash that is compatible with FormsAuthentication.HashPasswordForStoringInConfigFile.

A typical example for this is when you want to create a hash as part of an installer, where you dont want to include a reference to system.web (to gain access to the FormsAuthentication class).

using System;
using System.Security.Cryptography;
using System.Text;
 
class PasswordGenerator
{
    public static string GenerateHash(string plainText)
    {
        MD5 md5 = MD5.Create();
        byte[] hashBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(plainText));
 
        StringBuilder result = new StringBuilder(32);
        foreach (byte b in hashBytes)
        {
            result.Append(b.ToString("x2").ToUpper()); // used to convert each byte to a hex string
        }
 
        return result.ToString();
    }
}
 
[TestFixture]
class PasswordGeneratorFixture
{
    [Test]
    public void TestEqual()
    {
        string expected = FormsAuthentication.HashPasswordForStoringInConfigFile("myTestPassword", "md5");
        string actual = PasswordGenerator.GenerateHash("myTestPassword");
 
        Assert.AreEqual(expected, actual);
    }
}

Currently, this only works with the MD5 password format, although the PasswordGenerator class could easily be updated to also support the SHA1 algorithm supported by FormsAuthentication.

2 Comments

Preparing for your ski trip

This came through in my email the other day and I found it funny enough to share.

The following is a list of excercises to help you prepare for your ski trip:

  • Soak your gloves and store them in the freezer after every use.
  • Fasten a small, wide rubber band around the top half of your head before you go to bed each night.
  • If you wear glasses, begin wearing them with glue smeared on the lenses.
  • Throw away a hundred dollar bill – now.
  • Find the nearest ice rink and walk across the ice 20 times in your ski boots carrying two pairs of skis, accessory bag and poles. Pretend you are looking for your car. Sporadically drop things.
  • Place a small but angular pebble in your shoes, line them with crushed ice and then tighten a C-clamp around your toes.
  • Buy a new pair of gloves and immediately throw one away.
  • Secure one of your ankles to a bed post and ask a friend to run into you at high speed.
  • Go to McDonald’s and insist on paying $8.50 for a hamburger. Be sure you are in the longest line.
  • Clip a lift ticket to the zipper of your jacket and ride a motorcycle fast enough to make the ticket lacerate your face.
  • Drive slowly for five hours – anywhere – as long as it’s in a snowstorm and you’re following an 18 wheeler.
  • Fill a blender with ice, leave the lid off, hit the pulse button and let the spray blast your face. Leave the ice on your face until it melts. Let it drip into your clothes.
  • Dress up in as many clothes as you can and then proceed to take them off because you have to go to the bathroom.
  • Slam your thumb in a car door. Don’t go see a doctor.
  • Repeat all of the above daily until it’s time for the real thing.
2 Comments

Fail Fast

If software is going to blow up, Jim Shore explains in this article why it should fail as fast as possible. Definately worth reading.

[via martinfowler.com]

1 Comment
« Previous Entries
flag
Favorite Charity
wounded warrior project
Search
Social
  • mattberther on twitter
  • mattberther on linkedin
Syndication
Archives
  • January 2010
  • September 2009
  • July 2009
  • June 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • September 2008
  • August 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • December 2004
  • November 2004
  • October 2004
  • September 2004
  • August 2004
  • July 2004
  • June 2004
  • May 2004
  • April 2004
  • March 2004
  • February 2004
  • January 2004
  • December 2003
  • November 2003
  • October 2003
  • September 2003
  • August 2003
  • July 2003
  • June 2003
  • May 2003
  • April 2003
  • March 2003
mattberther.com © 2003 - 2010