Jim Jackson

Character Counts.
Do the right thing.


February 2009 - Posts

Beyond Compare 3

A substantial part of a developer’s job seems to be the logistical details of getting ‘it’ from here to there. When you run a team the problem becomes larger. Even with source control, there are documents that should be updated that aren’t and things that should be done that are missed. The two tools that I use these days are Beyond Compare from Scooter Software for files and folders and Red Gate’s SQL Compare for databases. The former is dirt cheap, the later has gotten more expensive over the years.

I’ve used Beyond Compare for a number of years now and have always been impressed with the comprehensive but simple nature of the software. You can open the UI for the first time and stumble around for about 5 minutes and know what you’re doing. In addition, the support is truly outstanding. Getting upgrade keys and information about the product reminds me of working with the the auto shop I have been going to for 10 years or more. I walk in and they know me by name even if I haven’t been around for 6 months. They give me exactly the services I need, listen carefully to any concerns I have and refuse to charge me when out of the ordinary things happen. Scooter Software’s licensing model is very straight forward for a single developer: As long as I’m using it personally, I can put it wherever I want. I have it on my personal dev box, my wife’s machine and my company dev box. If I ever get rid of the company box, I’ve got a note-to-self to remove it. Simple model based on trusting your client.

I also use Beyond Compare to keep my local backups up to date. In all the time that I have been taking digital photographs, I think I’ve actually deleted a half dozen. Needless to say I have thousands. Before I set up with carbonite.com, I used a rotating system of 2 external hard drives. I keep one attached to my local machine and one in the fireproof safe. I put all new images on my local internal media drive and then do a compare on the external, moving anything that doesn’t exist over. Then, every week or so, I swap the drives in the safe and do another compare. It takes a minute or two and I know that all the pictures and movies my family has are protected in the safe. My wife’s machine also gets an occasional copy of all images and movies so she can show off when she’s out and about doing FCC related stuff.

I wish I had done that for my Silverlight program. If I had I wouldn’t have lost 3 months of work due to sheer stupidity and a WD drive that went thud…

At any rate, I highly recommend both of these companies and their products.

WCF Services in a Shared Hosting Environment

I’m currently using a relatively well known hosting service for my Silverlight 2 application. The problem that I’ve had in getting the app up and running is that in a shared hosting environment, I have no control over host headers and most of the other settings in IIS. So since my url is https://www.singletrax.com, the ops people also added https://singletrax.com to the host headers for my site.

The problem is the order in which they added them. The www address is the second in the list so when I try to link to my services, I get an exception: Exception has been thrown by the target of an invocation. This is because the service is trying to load the host header index of 0 and there ain’t nuthin’ you can do about it that I’ve been able to find!

Except this:

First, add an AppSetting to your web project:
    <add key="HostIndex" value="1" />

Next, create two new objects:

using System;
using System.Collections.Generic;
using System.Web;
using System.Configuration;
using System.ServiceModel;
using System.ServiceModel.Activation;

namespace MyNamespace.Web.Objects
   class CustomHostFactory : ServiceHostFactory
      protected override ServiceHost 
CreateServiceHost(Type serviceType, Uri[] baseAddresses)
int hostIndex = 

         CustomHost customServiceHost = 
            new CustomHost(serviceType, baseAddresses[hostIndex]);

         return customServiceHost;

   class CustomHost : ServiceHost
      public CustomHost(Type serviceType,
params Uri[] baseAddresses) : base(serviceType, baseAddresses)
{ }

      protected override void ApplyConfiguration()

Then, in your .svc file, reference the custom host this way:

<%@ ServiceHost Language="C#" Debug="true"
 Factory="MyNamespace.Web.Objects.CustomHostFactory" %>

This works well for me. I’d be interested in what other hosting services do. Incidentally, I made the index an app setting because I hope that as traffic increases I’ll be able to afford a dedicated or virtual hosting environment.

Posted: Feb 13 2009, 12:37 PM by axshon | with 1 comment(s)
Filed under: ,
Calculating Distances Between Latitude and Longitude – T-SQL – Haversine

I’ve got lots of lat/long information for my Silverlight 2 application and I’m now tinkering with getting the elevation view working in my spare time. The problem is that the distances are very small and the haversine formulae I’ve located on the internet are all either miles or kilometers. Not going to work when your next position is only 50 feet away. So I wrote the simple SQL function below based directly on Seth Long’s version here.

Now, since I’m storing positional latitude, longitude and intersection information in my database, it’s simple to just calculate the numbers. The input and output values are of course immutable, so I added the columns to the appropriate table and will update them during the data entry phase of normal operations.

The haversine formula is also known as the ‘great circle formula’ that gives you a distance across the surface of a sphere based on an average curvature value for that sphere. The actual pear shape of the earth is a calculated max diff of only about 20 km so I’m not particularly worried about the error in two points that are literally spitting distance from each other.

By the way, the constant value 20,890,584 is the earth’s average radius in miles (3,956.55) multiplied by 5,280 feet per mile. The wikipedia article on haversine states that the average radius of the earth is 6,367.45 Km and I’m assuming it’s correct. I’m defaulting to feet since my Garmin GPS’ standard output for relative elevation is in feet.

@R is the radius of the earth.

This kind of begs for a discussion of whether it is more appropriate to calculate these values on the client and save the bandwidth or do the work on the server and pass it over. I chose the server because I’m still trying to figure out if I can market this application in the SAAS category. In that light, it seems better to keep as much data instantly available as I can.

Here’s the function:

Create Function [dbo].[fnGetDistance]
      @Lat1 Float(18), 
      @Long1 Float(18),
      @Lat2 Float(18),
      @Long2 Float(18),
      @ReturnType VarChar(10)

Returns Float(18)



      Declare @R Float(8);
      Declare @dLat Float(18);
      Declare @dLon Float(18);
      Declare @a Float(18);
      Declare @c Float(18);
      Declare @d Float(18);

      Set @R = 
            Case @ReturnType 
            When 'Miles' Then 3956.55 
            When 'Kilometers' Then 6367.45
            When 'Feet' Then 20890584
            When 'Meters' Then 6367450
            Else 20890584 -- Default feet (Garmin rel elev)

      Set @dLat = Radians(@lat2 - @lat1);

      Set @dLon = Radians(@long2 - @long1);

      Set @a = Sin(@dLat / 2) 
                 * Sin(@dLat / 2) 
                 + Cos(Radians(@lat1))
                 * Cos(Radians(@lat2)) 
                 * Sin(@dLon / 2) 
                 * Sin(@dLon / 2);
      Set @c = 2 * Asin(Min(Sqrt(@a)));

Set @d = @R * @c;
      Return @d;


Looking for the Groove Again

I spent quite a bit of time working SharePoint both in an independent project and bug-fixing other people’s work over the last six or seven months. Once you get the paradigm down, it’s not too bad but not exactly a barrel of laughs either. You spend equal thirds of your time developing, debugging and tinkering with the xml files that make up the belly of the beast. I believe that after some old-school SQL work finishes up I’ll be back in that groove. Yippee… I need to noodle around with those certifications too but that’s another story.

My reason for not blogging recently has been that a new toy caught my eye and I’ve been goofing around with Silverlight 2 for the last few months in pretty much all of my spare time. I’ve spent no less than 30 minutes and sometimes upwards of 2 hours a night tinkering out my new application. This is something that I suppose is possible with flash but I’m not a flash guy so I can’t say for sure. The idea of this hit me a few years ago and I was trying to implement it with ajax with limited results. SL makes it relatively easy.

About 2 months ago the hard drive on my personal machine crashed and fried the controller. It might have been the other way around but I ended up losing a load o’ code and had to start from scratch with the original images and the requirements docs I had emailed to myself. Now I’ve got carbonite.

So the application is free for now and I’m going to replace all images with updates from my spankin’ new DSLR. The buttons need templates, the colors of the controls stink and the images take far too long too long to load. That said I think it’s a pretty rich experience. Check it out if you have SL2 installed.


I’d be interested in any input from the peanut gallery…

Posted: Feb 06 2009, 02:21 PM by axshon
Filed under:
More Posts