Set Difference Minus Operation with LINQ in C#

Sometimes you want to use a Difference (or Minus) set operation which goes like this: Give me all elements from set A that do not exist in set B.  Or simply put A – B.  The LINQ Except method does this if both sets A and B are of the same type, but frequently the…

4

Eject or Undock a Laptop PC from Command Line or C#

Took me awhile to find this, so it is worth sharing.  If you have a computer (usually laptop, notebook, etc) with a docking station and want to tell the PC to undock itself from the station from the command line, this is it.  For me the scenario is that I frequently undock my system to…

5

Delegate Type Inference in C#

Today I saw some C# language syntax that made me think, "hey, wait a minute, I didn’t know you could do that!", so perhaps it’ll be new to someone else too.  Honestly, I don’t know how I missed this memo. Let’s start off with the code, then we’ll talk about it.  I’ll including some additional…

2

Pull Web Service Data into Excel

Visual Studio 2008 has great Office 2007 integration with the ability to essentially open an Excel worksheet from within VS and add C# code as if it was a Windows Forms application.  Just today an acquaintance asked how to pull data off the web and bring it into Excel.  There are many different techniques, but…

14

A Little LINQ

LINQ is out in strength and I’ve got to admit, even though I talked to Anders Hejlsberg over three years ago about it, I’ve just recently started using it in my own code.  There’s a lot out on the net about it, but here’s my 2c to help people get started.Console.WriteLine(“MS-DOS 6.21”.Sum(a => (int)a)); LINQ…

5

String.Equals Performance Comparison

I recently had an app that I used the VSTS Profiler on to find that a significant portion of time was spent comparing some long strings.  I was using String.Equals(string a, string b, StringComparison.InvariantCultureIgnoreCase) since I didn’t care about case or culture.  I switched to using OrdinalIgnoreCase and got a huge 5x performance gain!  So…

8

Amazon Short URL RegEx

When you search amazon.com, it takes you to product pages that have a real long URL.  It can be nice and short, so here’s a little regular expression to shorten it. Long URL: http://www.amazon.com/Professional-Visual-Studio-System-Programmer/dp/0764584367/ref=sr_1_1/104-4732806-7470339?ie=UTF8&s=books&qid=1179873697&sr=8-1 Short URL:  http://amazon.com/dp/0764584367 // Shorten an Amazon.com URL RegEx:    (?:http://(?:www\.){0,1}amazon\.com(?:/.*){0,1}(?:/dp/|/gp/product/))(.*?)(?:/.*|$) Replace:  http://amazon.com/dp/$1 A little code to change the URL in the clipboard. string…

6

HTML Applications (HTAs)

HTML Applications (HTAs) are DHTML pages that have full local privileges.  They’ve been around for a long time, but a colleague recently inquired so it was worth remembering.  They’re frequently used for splash screens on CD autoruns or as frontends to Windows Scripting Host (WSH) scripts. HTAs are suited to many uses, whether you are…

1

Rolling Up Status on Work Items

Say you have a work item type (WIT) that represent a big task, like a Feature, then you have individual Task work items that make up that feature.  You want to update the work completed and remaining of the tasks, and have that roll into the corrosponding feature. Today TFS doesn’t support work item heiarchy or…

2

Get a Web Page’s Title from a URL (C#)

I was creating an app that saves URLs copied to the clipboard into an XML file.  This little bit of code came in handy so I thought I’d be worth sharing. This code checks to make sure the URL is to a valid HTML page by first checking the type of request, then checking the…

13