Useful Moq Extension Method

I have been working with ASP .NET MVC and I use the Moq mocking library to help test the code I write.   Often in ASP MVC anonymous objects are passed around as function arguments.  This is especially common in calls to RouteUrl.  Since I want to be able to test this and verify that it…

0

Converting RTF to HTML

Have you ever had the desire to convert some RTF text into HTML? Probably not. But if you do, then you are in luck! I recently had the need to do this conversion and after some searching found out a way to do it by enhancing a sample distributed in the MSDN library.  The sample…

2

I finally got fed up with Enum.Parse

I don’t know why I didn’t do this long ago, but I am done writing this: var val = (SomeEnum)Enum.Parse(typeof(SomeEnum),”someString”); I have typed this too many times and it annoys me.  I wrote a small extension method on the string type to make this better: public static class StringExtensions { public static T ToEnum<T>(this string…

4

DRY and Unit Tests don’t mix well

When reading source code, I sometimes come across unappealing code(sometimes even my own).  However, there is one kind of “bad code” I see quite frequently.  It is a set of unit tests which have had the DRY (Don’t Repeat Yourself) principle unduly forced upon them.  DRY is the idea that you shouldn’t have to write…

0

How to teach your girlfriend Hexadecimal?

It is an age old question: How do you teach your girlfriend hex? I encountered this problem when I was a web developer in college for a late night student activities program aptly named  Late Nite Binghamton.  My co-worker and girlfriend Mallory was a graduate assistant for the program and had many ideas for how…

1

Snippet Designer in April’s MSDN Magazine!

I am excited to announce that the Snippet Designer is featured in the April issue of MSDN Magazine.                    It is featured in the Toolbox column where they highlight useful tools and blogs. Here is a snippet of what it says: Creating Code Snippets is a lot…

1

A functional take on console program loop in F#

Often when learning a new technology I start with a simple console application in which the program is run in a loop it continues to prompt you for more input until you give some command like quit or exit or whatever you choose: Enter input: someInput someOutput Enter input: otherInput someoutPut Enter input: quit Thanks!…

1

Synchronizing Scrollbars using JQuery

I just wrote this simple plugin for JQuery which lets you synchronize the scroll bars of any collection of elements.  This lets you move the scrollbar of one div it have the scrollbars’ of the rest of the divs move the same exact amount. Here is the code: 1: jQuery.fn.synchronizeScroll = function() { 2:  3:…

1

Prime Factorization using Unfold in Haskell

I randomly yesterday started thinking about the unfoldr function in Haskell while working out at the gym (how nerdy is that, I am lifting iron but thinking of functional programming). Unfoldr take a single and an unfolding function and turns it into a list (the opposite of fold).  At the gym I was thinking about…

3