Archive

Archive for December, 2013

Levenshtein distance

December 27, 2013 15 comments

Imagine a scenario where a single script is deployed to several hundred different locations. Due to various constraints, this script cannot be centralized, so making a change means I’ll need to deploy it to several hundred locations.

But it gets worse. Some of these scripts are customized and include special logic, so I cannot blindly copy the updated script to all locations. In addition to that, most of the existing scripts contain comments such as:

#
# This script was created on 1/1/1970 by John Doe.
#

If these scripts didn’t include their own unique comments, I could have compared the file sizes or generated SHA1 hashes for each script to see which were identical and which contained their own special logic. Since each script contains their own unique comments, generating hashes would mean a different hash for each script.

Instead of reviewing each script individually, I can use the Levenshtein distance to determine how similar the target script is compared to my updated script.

According to Wikipedia, the Levenshtein distance is:

… a string metric for measuring the difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits (insertion, deletion, substitution) required to change one word into the other.

Sorting each script by the Levenshtein distance gives me a good indication of which scripts I can safely copy over and which I need to review manually. Overwriting scripts with a Levenshtein distance close to zero gives me reasonable assurance that I won’t break anything. While it’s not a bullet proof solution, it’s better then reviewing hundreds of scripts manually.

Loading animations using pure CSS

December 26, 2013 3 comments

With the advent of CSS animations, it’s quite easy to create a loading animation using just CSS. Loading animations have traditionally been done using an animated gif. Using CSS animations only requires a single div element and a few lines of CSS:

#loading-image
{
	width: 25px;
	height: 25px;
	border-width: 8px;
	border-style: solid;
	border-color: #000;
	border-right-color: transparent;
	border-radius: 50%;
	animation-name: loading;
	animation-duration: 1s;
	animation-timing-function: linear;
	animation-iteration-count: infinite;
}

@keyframes loading
{
	0% { transform: rotate(0deg); }
	100%   { transform: rotate(360deg); }
}

Here is the result in JSFiddle.

I recently participated in a code review for a website and instead of using animated images, a developer decided to use CSS animations. While this is neat, I believe it’s a mistake to use this on a customer facing website. Perhaps my opinion will change in five years, but there are still too many people using older browsers that don’t support CSS animations.

Using pure CSS does have some merit. For example, a page might load a tiny bit faster because there is one less image it has to download, which reduces the number of http requests and the size of the page. You can also use LESS to dynamically change the animation color to match customer defined themes, background colors, etc….

While there are some reasons to use CSS animations, there are more reasons not to. The most important reason against using CSS animations at this time is avoiding unnecessary complexity. If you decide to use CSS animations in customer facing websites, you’ll still need to include a fallback method for browsers that don’t support it. I don’t see any reason to complicate things when animated gifs work perfectly fine.

Unless a website is highly dynamic with ever changing colors, I don’t see a reason to use CSS animations for loading images. Again, my opinion might change in five years when more browsers support CSS animations.

Enterprise Development with NServiceBus

December 12, 2013 12 comments

I’m in Minneapolis Minnesota this week to attend a course on NServiceBus.  Over the next couple weeks, I intend to post about my experiences and impressions as I start developing a system from the ground up.  Most of the posts won’t be interesting to veteran NServiceBus developers since they’ll be “hello world” type posts for various features.  These posts will mainly be notes for myself to remember what I’ve done and what features are available.  I’m actually quite eager to start using what I’ve learned this week.