October 2005 Entries
Eric Gunnerson is starting a series of posts entitled “Regex 101” which, judging by the first installment, looks to be an excellent introduction to regular expressions in C#. Eric is a very smart dude who understands this stuff at a base level and also seems to know how to teach effectivley (so far). A rare combination, and highly recommended. Go, read, learn... but try not to proliferate, for there tends to be a High Bus Factor where regular expressions are concerned...
"My coding has become a constant dialog with IntelliSense" Truer words could not previously have been uttered. So, “Does Visual Studio Rot the Mind?” (via Hannes Pavelka). Before long we may sit down at our computers, much like the brainwashed drones of 1984, to find that Visual Studio has already started itself, generated the code we were just thinking about, and made us a latte’. Nothing left to do but press F5 and enjoy the ride. Anyways, I have only read the part on IntelliSense...
I like to keep a folded piece of paper containing a few post-it notes in my pocket. You never know when you are going to need to leave someone a message or take notes for a phone conversation. It’s nice to have the post-its that you can stick on a wall while you write, and the folded paper for longer term notes. I have a PDA but I’ve found that while it’s great for scheduling, it sucks for taking quick notes... especially when you have a cell phone in one hand! Behold the little...
My rental car smells like someone switched the can of “New Car Smell” with “Essence of Yak”
One of the reasons I want to get a bike: The Zen of the Ride
Say you want to find every instance of a specific type of tag in an HTML or XML document. The following code is one way to do that. It is, of course, not the most efficient way but its straight-forward and it works. I like that. So anyways, the first version of this code used the string.IndexOf (string, int) method to find image tags by searching for the static string “<img” but that ignores such aberrations as “< img” and this could cause you to miss some tags if the...
I want to find out what day-of-week the first day of the month falls on. For example, the first of October falls on a Saturday. DayOfWeek firstDayOfMonth = DateTime.Now.AddDays((DateT... - 1) * -1).DayOfWeek; It seems to me like there should be a better (built-in) way to do this. Am I just missing something obvious...
So, it happens often – too often – that when I am coming into the building in the morning, the elevator doors will open up before I press the button. In fact, the doors open as I am walking towards the elevators not yet even thinking about the button. Thus, I don’t think I can claim this remarkable ability as a super power. It’s like the elevators themselves know. They’re watching. Weird. Back to technical posting soon… I promise
There are two doors in this stairwell with this sign (the red one). Complete nonsense
This is not, by any means, the most accurate way to measure the execution time of a block of code. That said, it’s very simple and it works great when a rough idea is close enough. I think I originally got this code off CodeProejct. If I can find the article again, I’ll credit the original author here. public class DebugTimer : IDisposable{ private DateTime start; private string label; private static int level = 0; /// <summary> /// Start a new DebugTimer which will run until disposed...
Programming by side effect is a practice I generally dislike with and tend to avoid when there’s a choice. What I mean is creating functions that take no parameters and return no value. The only way for these functions to accomplish anything is through side-effect. I will almost invariably choose the more explicit option, especially for public functions. In the example below, I would definitely use the GetGreenishColors function. I feel that the first function, LoadGreenishColors, is too ambiguous....
So, one of my little side projects involves getting images from websites. Surprisingly, one of the easiest parts is actually requesting and receiving the Image. (note: exception handling code removed for your viewing pleasure.) private Image GetImage(string url){ HttpWebRequest req = (HttpWebRequest)WebRequest.... HttpWebResponse resp = (HttpWebResponse)req.GetRes... Image image = Image.FromStream(resp.GetRe... resp.Close(); return image;} Now, you can just as easily get...
It was pointed out to me last night that an integer is, in fact, a value type and not an object. Well, yes and no. In C#, an int is an integral type that gets you a System.Int32 structure, as you can see [here]. Further, a System.Int32 structure derives from System.ValueType which, in turn derives from System.Object. As they say, “This is the ultimate base class of all classes in the .NET Framework; it is the root of the type hierarchy.” Everything is an object. Ha! Additionally, any...
I just read a very good article (chapter from a book, actually) on project management. I'd highly recommend this article to everyone, especially to the developers out there, who have ever worked on a software project. If you're lucky enough to have a good project manager, this might just help you get inside their head a bit better. Read on: The Art of Project Management: How to Make Things Happenby Scott Berkun...
So I was reading this long and enlightening article, written by someone waaay smarter than myself, about variance for generics and I encountered a cool new feature in C# 2.0. Simply put, when you define a Generic method, you can apply restrictions (constraints) to the kinds of types that client code can use when it calls your method. For example, you run into a problem if you want to copy a List<int> into a List<object>. This seems like a reasonable thing to do because an int is an object,...