Wednesday, January 31, 2007

Writing generic enumerators in C# (.NET 2.0)

The MSDN documentation is sort of lacking on how to write up a class that implements an Enumerator that can return a specific type of an object using Generics. So I wrote up a test class and here it is for your programming convenience.
using System;
using System.Threading;
using System.Collections;
using System.Collections.Generic;

public class MyEnumerable <T> : IEnumerable<T>, IEnumerator<T>
    public MyEnumerable( List<T> items ) {
        this.items = items;

    public IEnumerator<T> GetEnumerator() 
        return this;

    IEnumerator IEnumerable.GetEnumerator() 
        return GetEnumerator();

    public T Current 
        get { return items[index]; }
    object IEnumerator.Current 
        get { return Current; }
    public bool MoveNext() 
        if( index < items.Count ) 
            return true;
        } else 
            return false;

    public void Reset() 
        index = -1;

    public void Dispose() 
    private int index = -1;
    private List<T> items;

public class GenericEnumeratorsTest
    static void Main() 
        List<string> stringList = new List<string>();

        MyEnumerable<string> stringEnumerator = new MyEnumerable<string>( stringList );
        System.Console.WriteLine("using foreach");
        foreach(string s in stringEnumerator)
        System.Console.WriteLine("using MoveNext");

The Finalizer - IDispatch the Fury!

The Finalizer - IDispatch the Fury! Robot in .NET

Tuesday, January 30, 2007

Determining the build date of a Managed executable/dll

// Assumes that in AssemblyInfo.cs, // the version is specified as 1.0.* or the like, // with only 2 numbers specified; // the next two are generated from the date. // This routine decodes them. private static DateTime DateCompiled() { System.Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; // v.Build is days since Jan. 1, 2000 // v.Revision*2 is seconds since local midnight // (NEVER daylight saving time) DateTime t = new DateTime(v.Build * TimeSpan.TicksPerDay +v.Revision * TimeSpan.TicksPerSecond * 2).AddYears(1999); return t; }

Here are a list of commands that can help you debug network issues on Windows Machines

How to Troubleshoot Basic TCP/IP Problems (from JongHa Kim's Blog) Network TCP/IP 1. Connect to an IP address Ping Ping –a 2. Unable to connect to a specific IP address Check TCP/IP configuration Ipconfig /all 3. Ping the loopback address Ping Fail -> TCP/TP reinstallation 4. Ping computer’s IP address Ping Fail -> network adapter driver reinstallation (Not good) 5. Clear the address resolution protocol(ARP) cache Arp –a Arp –d : remove any incorrect entries in the ARP cache, clear all 6. Verify the default gateway 7. Verify persistent route table entries Route print 8. Use the tracert command (trace the hops between Tracert 9. Host file %SystemRoot%\System32\Drivers\Etc 10. LMHost file %SystemRoot%\System32\Drivers\Etc

Monday, January 29, 2007

Excellent book on writing quality code

Here is a great book that I came across on Microsoft Australia's website. Its got some great information about writting quality code. You can download the book from here (its free). Interestingly it uses a new format "DNL" and you need the reader which you can download from (The DNL format makes for an interesting electronic reading experience). Topics include: Test-driven development Performance tuning managed applications Code quality tools for native development Application Threat Modeling Code analysis with FXCop Web application load test Customising check-in policies

Visual Studio 2005 Keyboard Shortcut Posters

Visual Studio 2005 Keyboard Shortcut Posters

from Microsoft WebBlogs

Visual Studio 2005 keybaord shortcuts help make you more productive by giving quick access to common and not-so-common functions within the IDE. I've had wall posters designed for each of the popular langauges in Visual Studio 2005 for you to print out locally. Best when printed on paper sized A3 or larger.

Print ready poster PDFs are now available at the Microsoft download center. Happy coding.

Visual Basic 2005, Visual C# 2005 and Visual C++ 2005

Friday, January 26, 2007

Computer Languages History

A graphical look at the history of computer languages. (this is a truly interesting graph) Computer Languages History

Thursday, January 25, 2007

Unable to install KB923275 and KB923272 - Windows Update to Office

Recently, Windows update was having trouble updating my Office 2003 installation. There was one OneNote update that was failing and 4 Office updates (Specifically KB923275 and KB923272). Though I am sure this problem might affect other office updates as well. After a lot of searching and performing tasks that I saw on other websites, of which none worked, I was almost ready to uninstall and reinstall Office (which I did not want to do as it just takes too long!). And then I happened on a website that had the steps that worked for me: Check to see that the OSE (office source engine) service is running. 1. Goto Start->Control Panel->Administrative Tools->Services. 2. Run through the list and find Office Source Engine service. 3. In the column status, if it says "Started", then you are out of luck and this fix will not help you. 4. If there column is blank or has some other text, then double click on the service. 5. Click the button Start. 6. Now try and update your system. (My system was successfully updated at this point) 7. Windows update should be able to update your Office installation. If not look up other websites to see if there are other reasons for this problem. (this page may help : 8. If all else fails - reinstall Office. The one weird thing about this step is that my other computer does not have OSE service running and I have never had a failed office update. Which is why I believe this might not solve everybody's problem.

Wednesday, January 17, 2007

Schneier on Security: Choosing Secure Passwords

Schneier on Security: Choosing Secure Passwords: "Choosing Secure Passwords" An interesting essay that will give you insights into how to choose a better password by understanding how some of the password recovery programs work.

Tuesday, January 16, 2007

InfoQ: How to Design a Good API & Why it Matters

InfoQ: How to Design a Good API & Why it Matters Here is a video on good API design by Joshua Bloch (Joshua Bloch is a Principal Engineer at Google) The crux: 1. Easy to learn 2. Easy to use, even without documentation 3. Hard to misuse 4. Easy to read and maintain code that uses it 5. Sufficiently powerful to satisfy requirements 6. Easy to extend 7. Appropriate to audience

Tuesday, January 09, 2007


UNDERSTANDING NanoTechnology: "This site is dedicated to clearly explaining the concepts behind nanotechnology applications in areas such as energy, medicine, and consumer goods. It attempts to make the concepts of nanotechnology understandable by anyone." An interesting read.

Kristoffer's tidbits : Debugging memory usage in managed code using Windbg

Kristoffer's tidbits : Debugging memory usage in managed code using Windbg Another page about debugging memory in managed code. Some very cool techniques are discussed here.

Rico Mariani's Performance Tidbits : Memory leaks 101: Objects anchored by event generators

Rico Mariani's Performance Tidbits : Memory leaks 101: Objects anchored by event generators Some good information about managed memory leaks occuring due to objects having a root at an event generator.

Monday, January 08, 2007

Parse-O-Matic - Welcome

Parse-O-Matic Here is a really useful tool that allows you to reformat a text file using scripts. There is a free version of the tool, that you can use to take the software for a spin. The easiest method is to open one of the sample files and tweak it to do something you need it to do. Still looking for other tools which might be simpler that P-o-matic. Untill then this will safetly be tucked into my toolbox.

Windows Installer Error Messages

Windows Installer Error Messages on MSDN and some useful information about deciphering the error codes and messages in MSI logs:

Windows Installer Error Code Reference

Recently, I was trying to debug an installer problem for one of our customers. The MSI log file came back with a list of error codes, but I could not find out what they meant, until I happened on the following site: Its an invaluable reference : Windows Installer Error Code Reference Also, if you dont know how to enable logging, here is an easy way through the registry: Add the following keys and values [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Installer] "Logging"="voicewarmup" "Debug"=dword:00000007

Thursday, January 04, 2007

Textron commerative coins

In April of 2006, the company that I work for, Visual Learning Systems, got acquired by Overwatch Systems. Then in November of 2006, we got bought out by Textron Systems, a division of Textron, which is a Fortune 500 company. This coin was given to us as a commeration of this event (which I think is a testament to the great work done by us at this company).
Posted by Picasa