Category Archives: Useful Tricks

Power Up Your Enumerations

One of the patterns I follow a lot is creating enumerations in my code for certain reference data.  I usually have tables in my SQL database to back up this data, essentially just to give myself the benefit of referential integrity.  But it’s a pain to refer to data based on an arbitrary ID in the database, so enumerations are a way to ensure my code isn’t littered with “magic numbers.”

Enumerations by themselves are powerful, but pretty plain.  Since 95% of my development work is in ASP.NET MVC these days, I wanted an easy way to render the options an enumeration provides as a drop-down or radio button list.  I could do this manually, and it’s not a lot of code, but I felt like there needed to be an easier, more generic way to handle things.

Continue reading

Mocking Rob Conery’s ISession

Recently at work, we’ve really started to embrace TDD (and BDD).  As a team, it helps us write much cleaner, more efficient code.  I’m not going to preach forever about the benefits of TDD.  There are thousands of other blog posts out there beating this topic to death.  One of the ways that we communicate with our databases at work is by using Rob Conery’s ISession interface.  We have an implementation of this interface for Entity Framework 4, and it works beautifully.  However, given that this interface is super generic, it’s less than obvious how you would mock such a thing.  Here’s the ISession interface in all its glory:

Continue reading

Windows + Ruby Native Gems (1.9.1)

A few weeks back I posted about getting the ruby-debug-ide gem installed in Windows under Ruby 1.8.6.  In that post I outlined how hacking a header file and using the Visual C++ 2008 compiler could be leveraged to get the gem built and installed properly.  Well, after a helpful comment from a reader and watching a few screencasts over on TekPub, I actually found a way to do this with Ruby 1.9.1 from RubyInstaller.org.

As you know, I swapped my Windows development environment for Mac OSX, and so far learning Rails has been a great pleasure thanks to Agile Web Development with Rails (Third Edition) from The Pragmatic Programmers.  When I found this alternate method for installing ruby-debug-ide I decided to fire up my Windows 7 VM and give it a go.  Here are the gems I have currently installed on my VM:

Continue reading

MySQL Password Hashing in .NET

As I was surfing through StackOverflow today, I noticed a question that got me thinking. This developer had been working with a classic ASP application that used MySQL for it’s backend database. The project on his plate was to convert this application to ASP.NET with MS-SQL as the database. The only problem he encountered was the fact that passwords were stored in the database using a MySQL-specific hashing algorithm called via the PASSWORD() function. He needed a way to convert these passwords to .NET.

Given that I have a MySQL database laying around, I decided to poke around in the source code to see exactly how MySQL’s PASSWORD() function really works. It didn’t take me long to find inside the file “libmysql/password.c” this little gem:

Continue reading

Delicious Toolbar Icon Woes

Recently I’ve begun using the popular bookmarking service Delicious. One of my favorite features of this service is that I can install the associated Firefox add-on, and this enables a handy bookmarks toolbar that stays synchronized between my home and work computers. Recently, however, I’ve noticed a strange incompatibility with the theme I use in Firefox. For some reason, while using the my FireFox theme, the icons placed in the favorites bar are sometimes improperly sized which makes for a relatively ugly experience:

Continue reading