Welcome to The Idea Bucket
I had to come up with a name and this seemed like a natural fit for what I plan on using this site for - a catchall bucket to put my ideas online... I've not been great about updating things, lately - but hopefully the new year will bring new updates. test
Code WTF? - 2011 edition
So today I was helping another developer who was running into some issues in production code - there is a file import that works fine up to a point, but for some reason, a particular file causes it grief.
As of this posting, we still haven’t found the problem - but during lunch, I had to post what we DID find!
As we were debugging through the parsing library, I ran into a bit of code written by Random Developer. At first caught it me off guard, then left me quite literally, Laughing Out Loud.
It starts out simple enough - even has a comment:
1:
2: /// <summary>Parses a String to a bool</summary>
3: public static bool Bool<T>(this T value)
4: {
Not bad - I think that for this particular process, the Generic is probably overkill - but we will go with it:
Next, lets parse this thing up:
1: if (value == null || value.ToString().Length == 0) return false;
2: try { return Convert.ToBoolean(value); }
3: catch { }
First, if you are using Generics, you have a .NET framework that supports TryParse on all the types **. Yes, a TryParse is a bit more convoluted and requires the use of a generally misunderstood Out parameter - Oh, and a HUGE performance increase if you are parsing a value that fails.
But I’ll over-look that for now, because it is just a sign of what is to come…
So, assuming that the above parse didn’t actually return a properly parsed value, Random Developer decided to add a extra bit of code:
1: string testValue = value.ToString();
2: if (testValue.Empty()) return false;
Uh, OK - seems a bit redundant to me - but we haven’t gotten to the best (and LOL) part yet:
Our friend, Random Developer decided to check this value that didn’t parse into a Boolean against a list of 'Yeses' - Huh? List of Yeses?
1: var yeses = new List<string> { "1", "true", "yes", "y", "yeah",
2: "yea", "ya", "yo", "yesh", "indeed",
3: "uhuh", "yep", "yah", "damnstraight",
4: "valid", "damn skippy", "you betcha",
5: "bobs your uncle", "all right", "ok",
6: "sure", "why not", "of course", "agreed",
7: "fair enough", "absolutely", "right",
8: "if i have too" };
9: return yeses.Contains(testValue.ToLower());
Yep, Bob’s your Uncle, You Betcha, Damn Skippy - if it is one of these values, it must mean it is TRUE!
At least they used ToLower().
So, Random Developer - you officially made my year on my random code WTF?!
** It also supports String.IsNullOrEmpty - but that’s just a personal preference - instead of individually checking for Null and no Length…
Granting Admin rights to SQL Express (When you don’t have sysadmin rights)
I ran into an issue where I’ve been trying to get my local SQL Express instance setup so I would be able to do a bit of local development.
What stopped me is that for some reason, my local account did not have sysadmin rights and in SQLExpress, the sa account is disabled… I guess I did the original install under a different account and when I cleaned up some of the profiles, I nuked it…
After messing around way too long trying to figure it out, MSDN to the rescue: http://archive.msdn.microsoft.com/addselftosqlsysadmin/
As long as you have admin rights on your machine, you can run this and give your current account full access to the SQL instance you choose, from there, I was able to get back on track…
Note To Self: Outlook 2010 Features
Submitted by Craig on Thu, 07/29/2010 - 09:36I really needed to archive my messages in Outlook - I’d hit the wall on my Exchange mailbox limit and needed to get some of the cruft out of my (freshly filed, almost empty) inbox.
So it used to be really easy to archive things (because I knew where it was) - but I get into Outlook 2010 and I’m bumbling around like a nearsighted, slightly drunk sailor in the hold of a ship in a Class 2 hurricane.
Well, I did a little searching on the ‘nets and found this, that came in handy: http://www.howto-outlook.com/faq/locatefeature.htm
Very useful to me, getting over the hump of learning the new Ribbon on Outlook.
How To Use Visual Studio 2008 with Team Foundation Server 2010
Submitted by Craig on Thu, 07/08/2010 - 12:20I had all kinds of fun getting this to work - so I'm going to record it in case I have to do it again.
1: Make sure TFS2008 Explorer is Installed
2: Install VS2008 SP1 (this Updates VS2008 & TFS2008 Explorer)
3: Install TFS2010 Forward Compatibility Fix (must have SP1 installed or it will refuse to do anything)
When you connect to the server, you will have to use the full URL to VS2010, for example:
http://teamServer:8080/tfs/<collectionname>
If SP1 and the Forward compatibility tool aren't installed, you'll get an error about the server name cannot contain "://" or similar. Make sure you don't have a trailing '/' either.
Useful Links:
Most of this is better explained in Jason Barile's blog post (which, of course, I didn’t find until I almost had it working but this got me over the URL hump):
http://blogs.msdn.com/b/jasonba/archive/2009/08/10/how-to-connect-to-a-tfs-2010-server-from-a-2008-team-explorer-client.aspx
Visual Studio Team System 2008 Service Pack 1 Forward Compatibility Update for Team Foundation Server 2010 (Installer)
http://www.microsoft.com/downloads/details.aspx?FamilyID=CF13EA45-D17B-4EDC-8E6C-6C5B208EC54D&displaylang=en
