January 2012
3 posts
I Love PowerShell / I Hate PowerShell
Here’s a wonderful little tool called grep in Linux. It’s crazy easy to use. % grep 'search string' filename And here’s an example: % grep 'Html.ActionLink' *.cshtml And it works exactly the way you would expect it to work. Run this from the root of an MVC project, and you’ll find all of the links in your application. Here’s the equivalent line in PowerShell. ...
Jan 30th
What Was I Thinking?
Although I was quite tired from laying tile on Saturday and Sunday, I got up and went to the gym this morning. I swam 1000m – the furthest I have swam in a long, long time. I am exhausted. What was I thinking when I signed up for a Half Ironman? I’ll be required to swim 1,931 meters for the first leg of my race. July 7, 2012 is not so far away. Only 179 days to go. Ack!
Jan 9th
Oh, The Places You'll Go
Here it is, the complete list of everything I’ve read in 2011. Meaghan got me a Kindle for our anniversary this year, and just started devouring fiction, a few biographies, and just about anything else that interested me. I don’t think I’ve ever read that much in my life as what I read this past year. Watership Down by Richard Adams A Dog’s Purpose by W. Bruce Cameron Ender’s Game by Orson...
Jan 2nd
December 2011
6 posts
Fuck You, Printer
I don’t care if you’re out of color ink. I just want to print a black and white document! And it’s not even good grammar. <sigh/>
Dec 22nd
My Winter Project
Between Christmas and New Year’s, I plan to start learning Windows PowerShell. I love my command line, so getting a more powerful command line seems like an ideal thing for me. I usually write little Ruby scripts for the little one-off things that I need to do that a just a little more complicated than a *.bat file. It would be nice to have a native Windows option when it comes to this type of...
Dec 20th
3 tags
Getting Raw (and Copying Rails)
Ever run into problems where you really want to see exactly what the user submitted to your web application? I do, especially when I lack a one-to-one relationship between the view and model. This seems like something an action filter should be able to do for me. And as you might have gathered from the title, logging posted form values is something that Rails does out of the box. There’s a...
Dec 17th
4 notes
Accessing Application State Information
In every application I’ve every written, I’ve had to deal with state values in some way. At the simplest level, you’ll usually need to know the answer to three questions. Is there currently an authenticated user? Who is the current user? What is the current user allowed to do? Just about every web application needs to solve these three problems. In fact, this very question...
Dec 14th
3 tags
Easy Audit Information in Entity Framework
Another pretty common problem – we have a lot of tables that have the same 4 columns to track simple audit information. I’m sure you’ve all seend something like this before. CreatedAt DATETIME NULL, CreatedBy VARCHAR(256) NULL, UpdatedAt DATETIME NULL, UpdatedBy VARCHAR(256) NULL When inserting or updating records, we really don’t want to mess around with...
Dec 13th
7 notes
The Horror Of The Code Sample
I have written before that I have to interview incoming developer candidates. It is not my favorite part of my job. Sure, I love geeking out with other developers, but that happens so rarely. It’s embarrassing, really. I didn’t make this up on my own. There’s plenty of other people out there who do this. Why A Code Sample? Because just having one tells us a lot about you. No,...
Dec 12th
November 2011
4 posts
Why Delegates?
The more code I write, the more I find myself using delegates. Take this part of our Curiosity.Common.Mvc library, just added today. Behold, the power of delayed execution.return new FormHandlerResult<Logon>(form, () => RedirectToAction("Index", "Home"), () => View(form)) { SuccessNotification = () => "Welcome, " + Session["display_name"] } I...
Nov 28th
1 tag
Indianapolis Monumental Half Marathon Race Report
It’s been a long, long time since I ran a half-marathon. It’s November, and this is my first one this year. But I’ve also learned that I’m capable of much faster times than what I’ve submitted in the past. It’s really just a matter of making your legs go faster. Mile 1 - 9:18. Seems like a fast start. That’s OK. I know I’ll slow down, and I know I have problems pacing myself. Fast is OK. Mile 2...
Nov 6th
21 notes
Child's Play
I don’t play a lot of video games. That’s not terribly upsetting, since I was never a real hard-core gamer anyway. I like video games, but I’m not really that good at them. I’m more of the turn-on-God-mode-to-see-what-the-end-is-like type of gamer. No, that’s not for everyone, but it works for me. So even though I don’t play them, I do like to read about the games. One of the feeds in my reader...
Nov 3rd
WTF, Wednesday Edition
It’s too early to find crap like this in your inbox. I can forgive the poor grammar. I am familiar with graduate school engineering programs, so I am used to working with people whose first language is not English. My bigger problem is: who does this? I mean, people got problems. Helping people solve those problems has turned into a decent business for several people. Lots of...
Nov 2nd
October 2011
4 posts
Common Class Libraries-Now on Github & NuGet
In January of this year, I finally had enough side business coming in to justify forming my own company. It’s not a huge amount of side business, but enough to warrant forming an LLC and getting separate bank accounts. You know, the important stuff that you do if you at least want to look legitimate. So, without further ado, allow myself to introduce myself me to introduce… No, this is not one...
Oct 27th
1 tag
Deleting a Folder that You Can’t Delete
This is a fairly common scenario. I need to delete a folder, but Windows will not let me delete it. I get a nasty message like this. Well isn’t that annoying. Especially so because I am an Administrator on my own machine. The actual Administrator account has been disabled, and I really don’t want to have to re-enable the account to figure this out. There’s got to be a remedy for this. Have no...
Oct 25th
4 notes
1 tag
Aliases in Windows Command Line
A few weeks back, Rob Conery posted on how to setup aliases in the Mac terminal. Guess what! It’s also quite easy to do the exact same thing in Windows. You can tell that the command is old, just because of the name: doskey. If you want your settings to always load, you’ll need to create a startup script. I’ve named mine autorun.cmd, and I’ve placed in C:\util. The file (shortened) looks like...
Oct 17th
16 notes
Oct 6th
September 2011
2 posts
Updates to VS 2011
I don’t write a lot of desktop applications, but I do write enough to dislike having both VS and Blend open at the same time. Then I read this post from Gabriel Schenker. The new XAML editor in VS 2011 If you have worked with WPF or Silverlight in Visual Studio 2010 or 2008 you know that the XAML editor was extremely slow and limited in its functionality. Now that has changed...
Sep 17th
Refactoring a Controller Action
This is a response to Writing Maintainable Code by Michael Williamson. First off, I believe 100% in everything the author wrote. My only problem with his example is that he didn’t go nearly far enough down the refactoring rabbit hole. Original Code So let’s start with this original code, as presented by the author. I’ll warn you a couple of things. It is quite...
Sep 14th
August 2011
7 posts
3 tags
MVC Action Result To Redirect To Return URL
It doesn’t take too many MVC applications before you’ll see something like this in your URL bar. The default MVC project shows you a way to handle it, but it violates DRY if you use the idea of ReturnUrl in more than one place in your application. In my case, I’ve got just that problem. I’ve got an application where you can perform a single activity from...
Aug 29th
5 notes
3 tags
Creating and Testing a Custom NHibernate User Type
I’m writing a new application on top of an existing Oracle database. The current program doesn’t have proper domain classes and just sends raw SQL statements to the database server. Being the good developer that I am, I have decided to write proper models and then use NHibernate to map those models to the database tables. I have 3 conditions where a User Type becomes very...
Aug 23rd
5 notes
2 tags
Pluralization in C#
My response to Phil Haack’s post on singular and plural phrasing. public static class Pluralization { private static readonly ConcurrentDictionary dictionary; private static Func<string, string> defaultPluralizationRule = (s) => s.EndsWith("s") ? "es" : "s"; static Pluralization() { dictionary = new ConcurrentDictionary(); } public...
Aug 18th
2 notes
2 tags
Server-Side Sorting with Dynamic LINQ
Before I even start, this article applies to any LINQ provider. This includes LINQ-to-SQL, Entity Framework, and NHibernate.Linq. It even works with LINQ-to-objects. In one of my applications, I have a paged list. I’ve been using jQuery’s tablesorter plugin for the last 2 years. It’s been great, right up until the users figured out the difference between a client-side...
Aug 17th
3 tags
Back to Basics: State Machines, part 2
We already covered the basic of state machines in my last post. Now, we’re going to grow the concept to something a little bit bigger. Polymorphic State Objects As our domain grows, defining state can become more complicated, and more things need to happen when state changes. Suppose we’re not only setting a boolean flag or an enum state value. Maybe we’re also going to...
Aug 16th
4 notes
Back to Basics: State Machines
A state machines is one of the Gang of Four design patterns. State machines are used to track activities or workflows. These workflows may be sequential, or they may fork, or they may even loop back on themselves. Tracking the workflow may be as easy as having an enum property on your object, or it could take an entire domain aggregate to determine an object’s state. Depending on the...
Aug 12th
All About the Interview
It’s that time again at my company: we’re looking for a new developer. I’ve been assisting with the technical interviews, and let’s just say that we continue to be incredibly disappointed in the quality of candidates we receive. So what do we look for? Here are the “official” requirements for a junior position. Experience with Visual Studio...
Aug 11th
July 2011
2 posts
Jul 14th
1 tag
SQL Server: Get Last Week Days
I’m sure we’ve all run into this kind of problem at one point in time or another. In this case, I needed to perform a cross join of financial data against the days of the week. Write a SQL function to return the last N week days. Here’s what I was able to come up with. alter function GetLastNWeekDays ( -- Add the parameters for the function here @n...
Jul 5th
May 2011
2 posts
2 tags
Just How Much to Mock?
Are you mocking me? Let’s suppose that you’re starting a new application. Big. Little. Medium. Doesn’t matter. Just how much do you want to be able to test? What kinds of things are really important to you? The good news is that you’re thinking about TDD from the get go, and you’re really interested in the architecture of the application. There’s a...
May 18th
3 notes
Python Paradox
In a recent talk I said something that upset a lot of people: that you could get smarter programmers to work on a Python project than you could to work on a Java project. The original article on the Python paradox can be found here. I came across the Python paradox from Rob Conery. The rest of the article is included at the bottom of this post. The Python paradox seems really...
May 2nd
April 2011
4 posts
Apr 27th
In The Beginning...
Initial Code # of queries: 3322 Duration: 3229 ms First Iteration # of queries: 981 Duration: 1879 ms Second Iteration # of queries: 68 Duration: 363 ms Last Iteration # of queries: 1 Duration: 232 ms This post, and my now-more-performant application, was brought to you by NHProf. Thank you, NHProf!
Apr 25th
How I Learned To Stop Worrying and Set Up Oracle...
This was a big deal for me last week. Oracle on Windows is not the friendliest of environments, and you don’t always have the choice of where and what your database is going to be. For a lot of smaller, line-of-business application, SQLExpress is the way to go. But sometimes, you’re dealing with things that are big. And when things are big, the Enterprise has a say. So...
Apr 18th
1 tag
Pro Cyclists with Broken Collarbones
[BMC Racing’s] Brent Bookwalter and Karsten Kroon are each recovering from broken collarbones. Bookwalter underwent surgery in Utah last Wednesday to repair his left collarbone. The American suffered the injury in a crash at the Volta a Catalunya on March 26. Bookwalter said he hoped to be on the bike in another two weeks. … “We’ll take another X-ray [of Kroon] in the next 7-10...
Apr 10th
March 2011
5 posts
Why?
Just found this little gem from a project that went into production a week ago… public MemoryStream GetReportBytes(string reportLocation, IEnumerable<Report> reportParameters) { var report = new ReportDocument(); var location = new StringBuilder(); location.Append(reportLocation); report.Load(location.ToString()); // etc... } You would think that this would be...
Mar 24th
1 tag
'System.String.this' Has No Setter
I was working on a little project this morning, and I typed this into Visual Studio… Fd1YesNo[1] = (value) ? 'Y' : 'N'; The Fd1YesNo variable is a string, and value is a boolean. So, of course, that little bit of code came with this ugly little message. I don’t want to get too much into the design of this application, or why I have to do a move like this. ...
Mar 23rd
Mar 20th
4 tags
Order By Random with NHibernate QueryOver Syntax
If you’ve not checked out NHibernate 3’s QueryOver syntax, I highly recommend you do so. When the queries start getting complicated, I find it even more readable than LINQ. Plus, since you can create detached criteria with QueryOver, it opens the door for even more query-piece reuse. That can help keep your code dry. For those who don’t know, the QueryOver syntax uses...
Mar 11th
Obsession
One of the podcasts I listen to is This Developer’s Life. It’s an outstanding production put on by Rob Conery and Scott Hanselman. It’s like NPR’s This American Life, but it’s for software developers. But you should have been able to figure that out by the title. Their last podcast was on Obsession. It’s fun to hear about other people like me....
Mar 10th
February 2011
2 posts
Custom Rules in a Shared Application
I’ve got a web application with multiple clients. For the most part, everyone plays in the same application working against the same database. But now I’ve got a problem. I have a really good client that has a custom business rule. It’s a rule that just does not apply to any other customer. It’s really important, and I don’t want to lose this customer. As a bonus,...
Feb 16th
2 tags
Ruby is not C# So Don't Code That Way
I’ve recently been checking out Albacore. It’s a build system written in Ruby. I’ve gotten pretty good at MSBuild in the last year, but even the best MSBuild script is still really ugly. Albacore certainly looks promising, and I would love the opportunity to secretly introduce some Ruby sauce into my professional work life. COMPILE_TARGET = ENV['config'].nil? ? "debug" :...
Feb 1st
January 2011
8 posts
3 tags
Nested Collection Models in ASP.NET MVC 3
Scenario: We want to create form where I can save information about a person. That person has zero or more phone numbers and zero or more email addresses. The customer would like to edit everything about a person all at once, on a single form. This is a dynamic nested model problem. Suppose our person object looks like this: public class Person { public string FirstName { get; set; } ...
Jan 29th
12 notes
1 tag
Via EcoVelo: 10 Facts from America Bikes →
Here are 10 facts from America Bikes. Both gratifying and a little bit sad at the same time.
Jan 28th
1 tag
Simplifying Assignment in C#
From the Twitter… karlseguin dear c#…why new []{“it’s”, “over”, “9000”}; why not just [“it’s”, “over”, “9000”];  ?? The man makes a wonderful point. Karl jumped from the .NET ship a while back. He sought greener pastures in the Ruby playground. We have the var keyword in...
Jan 27th
Capistrano, Windows & Rackspace Cloud
First, a disclaimer… This is not an ideal setup. If I’m really going to be working this much with Ruby and Linux servers, I should probably do what everyone else is doing and start using a Mac at home. But that costs $$$, and until I’ve got enough income to really warrant that side expenditure, I’ll continue working in a Windows environment at home. There are...
Jan 20th
Why, Jif Peanut Butter?
Meaghan and I went to the grocery store this weekend, and I stopped to look at the Jif Peanut Butter. I was completely taken aback by the variety of Jif PB. No, not the various brands, etc. Just the amount of Jif varieties. And I’m not even going to turn this into a creamy vs. crunchy thing, because that’s like a whole new war on terror. (Although if you really want to know, I...
Jan 16th
Date.parse_us
Ruby 1.9+ is going to use international date formats (dd-mm-yyyy), and there’s not a damned thing you can do about it. So let’s do something about it. While you can easily output a date in any format you can imagine, have a date as input is a bit more tricky. class Date def self.parse_us(value) if value =~ /(\d{1,2}).(\d{1,2}).(\d{4})/ # puts "#{$3}-#{$1}-#{$2}" ...
Jan 6th
1 tag
Rails Deprecation Warning
DEPRECATION WARNING: Using form_for(:name, @resource) is deprecated. Please use form_for(@resource, :as => :name) instead. That seems like a fairly important deprecation warning, especially since most web examples show that as the way to use the form_for helper.
Jan 5th
1 note
Setting Up My Ruby on Rails Environment in Windows...
Have you tried setting up decent Ruby on Rails development environment in Windows? It’s really not as easy as people make it out to be. Sure, it’s easy enough to grab the installer and get ruby -v and irb to work from the command line. Still getting a decent working Rails development setup is tricky. Here’s all of my steps (accurate and working as of December 31, 2010). ...
Jan 3rd
December 2010
4 posts
1 tag
Ruby Mixins and SRP
Hadi Hariri put together a good post on the Single Responsibility Principle (SRP) earlier this week. Honestly, it’s the one thing that I kinda fret about when working with Ruby on Rails. The ActiveModel pattern. Let’s consider a mundane domain model in Rails. class Product < ActiveRecord::Base belongs_to :category has_many :order_lines validates_presence_of :name ...
Dec 22nd