Nov 14
Moving on
icon1 Darrell Mozingo | icon2 Misc. | icon4 November 14th, 2011| icon3No Comments »

I’ve been at Synergy Data Systems for over 7 years now (I know, the site is horrible). I’ve worked with a lot of great people on some very interesting projects, and learned a boat load during that time. Unfortunately, they can’t offer the one thing my wife and I wanted: living abroad.

To that end, we’re moving to London and I’ll be starting at 7digital in early January. I’m super excited about both moves. 7digital seems like a great company working with a lot of principals and practices that are near and dear to me, and c’mon, it’s London. For two people that grew up in small town Ohio, this’ll be quite the adventure!

I’m looking forward to getting involved in the huge developer community over there, playing with new technologies, and working with fellow craftsmen!

May 24
Code Katas
icon1 Darrell Mozingo | icon2 Misc. | icon4 May 24th, 2011| icon3No Comments »

I added a page listing a bunch of code katas, mostly for my own reference, but I guess you guys can mooch off of it too.

Let me know if I’m missing any. I’ll expand the page as I stumble across more.

Nov 18
How *not* to hash passwords
icon1 Darrell Mozingo | icon2 Misc. | icon4 November 18th, 2010| icon3No Comments »

We were stupid back in the day (OK, a year or two, but who’s counting?). When we started our latest project it was a given that we’d be hashing passwords for storage. The most obvious and easiest way to do it was the good ‘ol (password + hash).GetHashCode(). Done and done. We moved on to the next feature and never gave it a second thought.

As it turns out though, using GetHashCode() for password hashing purposes is, well, pretty stupid and irresponsible. GetHashCode() was never intended to be stable across .NET versions or even architectures (x86 vs x64), and apparently the framework spec documents call this out. In fact, its results have changed slightly between .NET 3.5 and 4.0, which is what we were just upgrading to when I noticed this. Similar changes aparently occurred between 1.1 and 2.0 too.

For example, the GetHashCode() hash of the string “password” from .NET 3.5 is -733234769, while the hash from that exact same string in .NET 4.0 is -231203086. Scary, huh?

In light of that, we switched to using the SHA512Managed class to generate our hashes. Switching our code over wasn’t an issue (DRY for the win!), but having to email our customers to enter new passwords and security questions, which we also hashed the same way, wasn’t exactly fun. Not knowing their passwords apparently does have a downside! Here’s how we’re generating our hash codes now:

private const string _passwordSalt = "some_long_random_string";
 
public static string CalculateSaltedHash(string text)
{
	var inputBytes = Encoding.UTF8.GetBytes(text + _passwordSalt);
	var hash = new SHA512Managed().ComputeHash(inputBytes);
 
	return Convert.ToBase64String(hash);
}

Yay? Nay?

Aug 26
Controlling IIS7 remotely with PowerShell
icon1 Darrell Mozingo | icon2 Misc. | icon4 August 26th, 2010| icon31 Comment »

Our deployment script needed to do some basic IIS administrative tasks remotely on a Windows 2008 (non-R2) server, which runs IIS7, recently. Finding the information and fiddling around with it took me a good day and a half, so I thought I’d post the steps here to help someone else (more than likely myself) in the future:

  1. Download the Windows Management Framework Core package for your setup
  2. If your machine is something older than Windows 7 or Server 2008 R2, you’ll need to get the PowerShell IIS7 Snap-In
  3. If your workstation/build server and target web servers happen to be on different Windows domains, you’ll need to run this one time on each client machine:
    Set-Item WSMan:\localhost\Client\TrustedHosts *
  4. Run this command once on each server:
    winrm quickconfig
  5. You’ll need to load the PowerShell Snap-In once on each client, which differs depending on which version of Windows you’re running. Anything older than Windows 7 or Server 2008 R2:
    Add-PSSnapin WebAdministration

    Windows 7 and Server 2008 R2 run:

    Load-Module WebAdministration
  6. Check if it’s working properly by running this command on any version of Windows (you should see the IIS7 Snap-In listed):
    Get-Module -ListAvailable
  7. Get credentials for accessing the remote server
  8. Start running some remote commands on your web servers:
    Invoke-Command -ComputerName "webserver_computerName" -Credential $credentials_from_last_step -ScriptBlock { Add-PSSnapin WebAdministration; Stop-Website IIS_Site_Name }

It’s not really that hard once you get the proper packages installed and the permissions worked out, and since it’s so powerful and useful for scripting purposes it’s well worth the trouble. The available commands are awesome for use in automated deployment scripts.

You can learn more about the PowerShell Snap-In provider here, and at its download site here.

Jan 16
Downtime
icon1 Darrell Mozingo | icon2 Misc. | icon4 January 16th, 2010| icon3No Comments »

downtime

My home-ran Linux server crashed shortly after the first of the year. I’ve gotten really good up time with it since I started using it 6 years ago, with only a power supply dieing on me once, and other than that having gone years at a time without having to do a single thing – even rebooting. Well, I’m thinking the motherboard gave out this time, and I really don’t feel like messing with the server any more between software updates and hardware issues (plus it was hosted in my company’s data center, and with a few of the ideas I’m hoping to bring to fruition this year, I don’t want to overstay my welcome there!).

So I moved to an actual hosted solution with Site5. I never realized it’d be so hard to find a freakin’ provider! I understand it’s probably the nature of the beast, but it seems like there’s no single provider out there that damn near everyone just loves, even as you move up the price scale. For every story about someone being with a host for years without a single problem, there’s one where they guy’s site was down every other day and he lost half of his data in a crash. Eek! I’ve have heard good things about Site5’s Ruby on Rails hosting and their uptime in general, however, plus they provide SVN & Git on all their servers so I don’t have to worry about hosting that separately with GitHub or Unfuddle, so I took the plunge for a year to try them out. Pretty good so far, though there were a few hiccups such as having to move my DNS hosting to them and at least one server outage. Guess I’ll see how it goes.

Anyway, that’s why the site was done for two weeks or so. Hopefully it shant happen again any time soon.

Oct 23
Ideas
icon1 Darrell Mozingo | icon2 Misc. | icon4 October 23rd, 2009| icon3No Comments »

My recent lack of posts aren’t so much because I don’t have the time or desire to do them, I just don’t have any ideas left to post about. Nothing terribly exciting going on at work and no time for development stuff at home. I tried getting my company to open source an old ASP.NET page I wrote (actually, my first “professional” one) that was quite successful but has since been replaced for a new direction, but they unfortunately turned it down. I was hoping to walk through it step by step in a huge refactoring series of posts, adding tests, getting rid of the huge amounts of inline SQL, etc. Maybe I’ll work on getting them to do that again.

In the mean time it’s back to the drawing board for post ideas. I prefer series and actual code/concrete posts, so maybe a small app? That seems over done though, not to mention the odds of me actually seeing it the whole way through are pretty slim. Hmmmmmm.

Sep 15
Injecting all instances of a given type
icon1 Darrell Mozingo | icon2 Misc. | icon4 September 15th, 2009| icon35 Comments »

I’m sure I’m a little late to the game here, but I recently stumbled across how to do collection injection with Structure Map. I’ve known it was possible, and have seen it hinted at in other blogs posts for a while, but I just didn’t know how exactly it was done.

Why would you want to do this? Lets take an actual situation from our system. We rolled a small scheduled task framework (sorry Quartz.NET and Topshelf, you just didn’t fit the bill for our needs). I wanted us to just drop a POCO object in the project and implement an ITask interface, which had exactly one method: Run(). I also wanted these objects to be pulled from the container so they could have services/repositories injected in as needed.

To make it easy for our network admins to schedule these tasks, I wrote the application to take a single /run <taskName> parameter. So if you wanted to run the EmailUsersTask, you’d simply run the app with /run EmailUsers. I also added a TaskDescription attribute so task authors could add a single sentence letting everyone know what it did, which would be displayed when the user ran the app with no parameters in a list with all the available tasks and a description of each.

Simple enough, right?

My first stab at it, and it actually ran for a while like this, took in Structure Map’s IContainer to retrieve the task with all its dependencies satisfied, and to display all the available tasks it would just loop through all types in the assembly (filtered for only those implementing ITask), and get the needed display information.

Worked fine and dandy, but testing it was slow. I had to scan all the types in the assembly, even if I knew I was looking for a single test dummy class. I didn’t like it, so I began tinkering with Structure Map. I wanted the fully initialized objects (from the container) injected in as an IEnumerable<ITask>, so I could just pluck the needed one to run, and loop through that list to build up the small display when needed. It would be easier to read and also make testing quicker and simpler. Here’s what I ended up with:

public static void BootstrapStructureMap()
{
	ObjectFactory.Initialize(y =>
	                         {
	                         	y.Scan(x =>
	                         	       {
	                         	       	x.TheCallingAssembly();
						x.WithDefaultConventions();
						x.AddAllTypesOf<ITask>();
	                         	       });
 
					y.ForRequestedType<IEnumerable<ITask>>()
	                         		.TheDefault.Is.ConstructedBy(x => ObjectFactory.GetAllInstances<ITask>());
	                         });
}

This is called while our app is boot strapping (though we use separate Registries for each area of the app, I just simplified it for posting). Pretty self explanatory – the AddAllTypesOf tells Structure Map to gather up all implementors of ITask in the assembly, and we then tell Structure Map to get all instances of that interface to pass it in whenever IEnumerable<ITask> is requested. Without that, you’d have to take in an array of ITask's. Same difference, I just prefer enumerables.

So there you go – get a collection of fully constructed types injected into your objects. We did this assembly type looping in one or two other system startup areas of the app, and I was able to kill them all off with this technique while shaving a good 4 seconds off our unit test suite. Pretty neato.

As a moral, of sorts, for this story, I also learned after doing all this to always RTFM when you have a question. It’ll save you a lot of time tinkering on your own 🙂

Apr 16
Introduction
icon1 Darrell Mozingo | icon2 Misc. | icon4 April 16th, 2008| icon3No Comments »

So I’ve finally done it: a development blog. This sure was a long time in the making.

So what’s up with the title? “Taller Code”? Well, it derives from two sources:

  1. I’m on a personal journey of self betterment (relating to software development anyway). I want my code to get bigger, better, and “taller” in the metaphorical sense, and I want to drag as many of my peers as I can along with me.
  2. I’m a bit over 6’4″, so some would say I’m pretty tall myself.

Retarded? Perhaps. Cheesy? Sure. The result of picking a name first and trying to think up an explanation for it afterwards? Definitely.

It works though, and I’m hoping it sets a tone for my future posts and gives me a bit of a goal to keep in mind while working on them.