Tuesday, July 31, 2007

Split letters and numbers

using System;
using System.Text;
using System.Text.RegularExpressions;

namespace Program
    public class App
        static void Main(string [] args)
            string strtemp ="AB324hgdf89dfg";
            string strpart;
            Nullable<int> npart;
            SplitLettersAndNumbers(strtemp,out strpart,out npart);
            Console.WriteLine("{0} : {1} - {2}",strtemp,strpart,npart);

        /// <summary>
        /// This method extracts all numerals and alphabets from a given string
        /// </summary>
        /// <param name="instr">String input</param>
        /// <param name="strpart">all alphabets as string</param>
        /// <param name="intpart">all numerals as string</param>
        /// <returns>return if success else false<returns>
        public static bool SplitLettersAndNumbers(string instr, out string strpart, out Nullable<int> intpart)

            string strtemp = null; //buffer to hold letters
            string nstrtemp = null;//buffer to hold numbers

            if (instr == null) // invalid option
                strpart = null;
                intpart = null;
                return false;

            string[] m1 = Regex.Split(instr, @"\d");//All letters
            string[] m2 = Regex.Split(instr, @"\D");//All numbers

            //Concatenate all strings
            StringBuilder sb = new StringBuilder(instr.Length);
            foreach (string si in m1)
                //Do extra processing if needed
            strtemp = sb.ToString();

            //Concatenate all Numbers.
            foreach (string si in m2)
                //Do extra processing if needed
                nstrtemp += si;

            //Update out parameter for letters
            if (strtemp != "")
                strpart = strtemp;
                strpart = null;

            //Update out parameter for numbers
            if (nstrtemp != "")
                intpart = int.Parse(nstrtemp);
                intpart = null;

            return true;

IronRuby Math patch and Release build

Teaching IronRuby math tricks

And find my comment for release build option.

Friday, July 27, 2007

First Look at Working IronRuby

Got IronRuby

Build.cmd got this %frameworkdir%\%frameworkversion%\msbuild.exe /p:Configuration=Release /t:Rebuild IronRuby.sln

For some reason I don't have frameworkdir and frameworkversion environment variables set.

I just used

msbuild.exe /p:Configuration=Release /t:Rebuild IronRuby.sln.

I will mention my environment in a bit detail. Go through this if you got similar errors, else skip this part.

I don't have Visual Studio 2005 installed on my
OS Name: Microsoft(R) Windows(R) Server 2003, Standard Edition
OS Version: 5.2.3790 Service Pack 1 Build 3790

I use web install of "Microsoft® Windows® Software Development Kit Update for Windows Vista™"

Here is the Build Log
Setting SDK environment relative to C:\Program Files\Microsoft SDKs\Windows\v6.0.Targeting Windows Server 2003 x86 DEBUG C:\Program Files\Microsoft SDKs\Windows\v6.0

C:\IronRuby$\\msbuild.exe /p:Configuration=Release /t:Rebuild IronRuby.sln
The filename, directory name, or volume label syntax is incorrect.

C:\IronRuby$msbuild.exe /p:Configuration=Release /t:Rebuild IronRuby.sln
Microsoft (R) Build Engine Version 2.0.50727.42[Microsoft .NET Framework, Version 2.0.50727.42]Copyright (C) Microsoft Corporation 2005. All rights reserved.
Build started 7/27/2007 5:06:24 PM

Project "C:\IronRuby\IronRuby.sln" (Rebuild target(s)):
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:06.79

Here are some sample tests with "Hello, World"


Windows Command Prompt Customization

Now and then we happen to work on Windows Command Prompt. What makes me annoyed is its lengthy prompt. It becomes so irritating when you work deep inside hierarchy.

Here is an option to have path for ready reference as well as space to enter long commands.

To get this check for following registry settings

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor]
"AutoRun"="prompt $P$_$$"

Here I added registry settings for path completion too.

Also I customized my title, you can see that in pic.


This is from author of Beyond Code, Rajesh Shetty.

I attended his session sometime back. Here is the link for these points.

1. //Focus on ROII.(Return on Investment for an Interaction)
Time is precious for everyone. Ensure that you provide the highest value for anyone investing time in an interaction with you.

2. //Keep the promises you make to yourself.
Making promises to yourself is easy. Keeping them is very hard!

3. //Set right expectations
The first step in trying to exceed the expectations is to set them right in the first place.

4. //Set higher standards
Raise your standards higher than the general norm and watch miracles unfold!

5. //Avoid complacency at all costs!
There is nothing like maintaining the status quo. You are either falling or rising.

6. //Commodotize your work at regular intervals
You don't have to wait for someone else to commodotize your work.

7. //balance home runs with small wins
Home runs are great. But small wins are important too!

8. //Think!
Set aside time to "Think." Most often thinking is done in parallel to other activities.

9. //Never take people for granted
Would it be any fun if someone took you for granted?

10. //Ask the right questions
Answers help. But, it's not always the answers that matter.

Wednesday, July 25, 2007

Collections Best Practices

This is referenced form an article in August issue of CLR Inside Out. Link

The basic purpose of collections is to tie certain objects together as a group because they have some logical connection to each other.

General criteria to select a particular collection object goes like this

  1. Are you going to be adding all the elements at once?
  2. Are you going to be dynamically adding and removing elements?
  3. Do you only need to iterate over the entire collection, or do you also need to locate and use specific elements?
  4. Are you exposing your collection through a public API?
  5. What are the performance characteristics and requirements of your application?

If you’re using the .NET Framework 2.0 or later, using the old non-generic collections is strongly discouraged. Following table shows the mapping between

.NET 1.0 Collection classes and .NET 2.0 Generic collection classes

Non-GenericGeneric Replacement
BitArrayNo replacement exists
SortedListSortedList<TKey, TValue>

Pros and Cons of each type:

When you want additions(fast), removals(fast), and lookups(average) to be very quick, and when you are not concerned about the order of the items in the collections, your first inclination should be to use a System.Collections.Generic.Dictionary<TKey, TValue>.

If your usage pattern requires few deletions and mostly additions, and if it is important for you to keep the collection in order, you may want to choose a List<T>. If you do not care about sorting or inserting items in the middle, nor do you care about looking up individual items in the list but want to iterate over complete list.

to implement a first-in-first-out (FIFO) order

to implement a last-in-first-out (LIFO) order

when you need to maintain order yet still achieve fast inserts. But increases increased activity by the garbage collector. While the actual act of inserting an item into a LinkedList<T> is much faster than doing so into a List<T>, finding the particular location at which you want to insert a new value still requires traversing the list to find the correct location.

uses a balanced tree implementation as the underlying data store; this provides relatively fast lookups and maintains items in a sorted order, but insertions will most likely be slower.

which uses two separate arrays to maintain the keys and the values separately and to maintain them both in order

Extending Collections
The System.Collections.ObjectModel.Collection<T> class implements all of the standard collection interfaces, and your custom collection type can simply derive from Collection<Double> in order to provide the additional overload methods. You could also use extension methods in C# 3.0 to achieve the same.

Gist on Collection Interfaces

GetEnumerator - returns IEnumerator


ICollection - extends IEnumerable
CopyTo - copies items to an array
Count - Readonly count
IsReadOnly - items cannot be removed or added
(mutable items can be modified even if the collection is read-only).

IList - extends ICollection
indexer: allows to get and set any item in the collection, just as you can when using arrays

IDictionary - extends ICollection
Add - overload that associates a key with the item that is added
ContainsKey - method will check for the existence of a particular key
Keys - returns an ICollection of all the keys
Values - returns an ICollection of all the values
remove - overload based on the key instead of the value
indexer: using the key.

Tuesday, July 24, 2007

Type forwarding in .NET 2.0 - TypeForwardedToAttribute

Type forwarding is a feature added in .NET 2.0. But I guess it was not publicized as much as Generics or any other new feature that was added. TypeForwardedToAttribute is about forwarding calls to methods in a type from one assembly to another assembly. Here goes its story.

Assume that you are developing a library, mylib.dll,  with some helper functions. And one of the types in that library is named FindText. FindText is a class with two member functions. Apart from FindText there are so many other classes and structures in that class. And an application named AppProjectA that consumes this dll.

But while implementing mylidb.dll you found that FindText is  becoming too complex with lot of Internationalization code and other stuff. So you thought of you can moving whole of FindText to a new library called strsearchlib.dll.

As application AppProjectA  is already distributed you are hesitant to recompile it. But you want to consume strsearchlib.dll for FindText instead of mylib.dll.

This is possible using TypeForwardedToAttribute in .NET 2.0.

Here goes Step by Step Guide.

1) Build mylib.dll

[Source] mylib.cs

namespace ProjectA
    public class FindText
        public bool Find(string inputstr)
            System.Console.WriteLine("In mylib");           
            return (inputstr=="text1");
        public string Add(string inputstr)
            System.Console.WriteLine("In mylib");           
            return (inputstr+=" end of line");

Launch VS2005 Command Prompt and build mylib.dll

$csc /t:library strsearchlib.cs

2) Build AppProjectA.exe

[Source] AppProjectA .cs:

using System;

namespace ProjectA
    public class App
        static void Main()
            string str1 = Console.ReadLine();
            FindText ft = new FindText();
            if (ft.Find(str1))
                Console.WriteLine("Not Found");


$csc /r:mylib.dll AppProjectA.cs

3) Test AppProjectA.exe

Enter text "text1" and observe result Found.

4) Now build strsearchlib.dll 

Copy code for FindText from mylib.cs to strsearchlib.cs. Dont change anything, just copy.

[Source] strsearchlib.cs:

namespace ProjectA
    public class FindText
        public bool Find(string inputstr)
            System.Console.WriteLine("In strsearchlib");
            return (inputstr=="Search");
        public string Add(string inputstr)
            System.Console.WriteLine("In mylib");           
            return (inputstr+=" end of line");

$csc /t:library strsearchlib.cs

5) Rebuild mylib.dll

Add TypeForwardedToAttribute in mylib.cs and remove type FindText. You must comment/remove it.

[Source] mylib.cs:

[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(ProjectA.FindText))]
namespace ProjectA
/*    public class FindText
        public bool Find(string inputstr)
            System.Console.WriteLine("In mylib");           
            return (inputstr=="text1");
        public string Add(string inputstr)
            System.Console.WriteLine("In mylib");           
            return (inputstr+=" end of line");


Some other types


$csc /r:strsearchlib.dll /t:library mylib.cs

6) Test AppProjectA.exe again and observe that calls to Find and Add methods are redirected to strsearchlib.dll

7) Observe change in manifest of mylib.dll

$ildasm mylib.dll

open manifest and observe forwarder

.class extern forwarder ProjectA.FindText
  .assembly extern strsearchlib

8) Metadata and IL Assembly syntax for Type forwarding in .NET 2.0

Metadata presentation of type forwarders
    ExportedType table
        Flags        | tdForwarder (0x00200000)
        Implementation    = mdAssemblyRef

IL Assembler syntax
    .class extern public forwarder ProjectA.FindText
        .assembly extern strsearchlib

Wednesday, July 18, 2007

Add-ins Plug-ins Extensions

I cant find any reference which explains how Add-ins, Plug-ins and Extensions differ from one other. I just cant accept them to be synonyms.

Here is an account of how I interpret each one. Please correct me or point me to appropriate source.

I guess add-ins are those modules which bring-in a specific fuctionality, at runtime, for such requirements which are unknown at build time. That mean Application is unaware about source of Add-ins. Normally they are chosen from list to add. eg.Excel Ad-Ins

I guess Plug-ins are those modules for which an adapter is built inside the application at build time. Thus a trust relation ship exists between application and Plug-In at Runtime.

I guess Extensions are those modules which are added to bring in additional functionality by installation and probably with a restart of main application. Extensions operate in isolation with build time functionality.

FreeMind - Mind mapping tool

About Mind Mapping

Mind mapping is considered as most convenient method to capture ideas analyze them. Other uses include to visualize,classify,structure,generate ideas,aid in study,problem solving,decision making etc.. As such it is a generic tool and can be used for any purpose at any level. In simple terms it is a structured notes taking tool. It offers much more than a flat hierarchy, more than a tree structure. And it is inline with xml but in pictorial form.

It starts with a central concept which will be placed in the middle of background of a map. Then ideas around it projects in radial direction around it. Tony Buzan is considered as father of modern mind mapping technology.

Get Tool

Commercial tool Mind Mapper costs around 175 USD. You can find other tools in this category in wiki site. But Free Mind is an open source tool (GPL v2 licensed).

Other Links

Here are some links User's Guide, Main Page , Review, WikiLink, Getting Things Done.

Ease of use

I found it so easy to use. It took me 2 hours to get a hold on it. Prior to this I don't have any background about it. I read 60 page user's document in just 45 minutes. And then in no time it changed the way I think and work. Most attractive thing about this tool is its speed and keyboard short cuts. That ensures that you don't need to pause from thinking mode to editing mode to take notes. It just flows without any dampness.


It offers three modes of operation.

MindMap (~edit) editor Alt+1
Browse(~read only) mind map files or web Alt +2
Files(~view files on local computer Alt + 3


Node is a key word that makes up a think stream. To create a node just press insert and type the keyword. Each node can be represented as a Fork or bubble. I use fork if I think that I can add more down to that node. And I use bubble if the node is the last one in that thought process. This gives some sort of closed feeling. You can also join nodes from two streams.

Formatting node

Each node can be marked with icons. This is very useful. Just highlight node and then press Shift+I. You can assign an icon.

Each node can be named with html. And that can include images <img src="">

Physical Layout

Physical layouts are about text format and background format of each node. Its is not about shape. Sample layouts are like, OK, Not OK, Needs action, Larger topic etc.. You can add additional physical layouts by editing "C:\Program Files\FreeMind\atterns.xml".


You can cloud around nodes to form a set or group and then color them. I found it very useful.

Some quick keyboard shot cuts I adopted

Insert,delete to insert and delete nodes at selected level
Ctrl+K to insert hyperlink manually
Ctrl + Shift + K for inserting link from local disk
Ctrl + Up/Down to move nodes up and down among siblings
In non editing mode esc brings to root and Auto adjusts to fit the page
Toggle fold unfold using space bar
Renter on node to create siblings below it and shift+enter to create above it
Long note editor-Alt+enter
Editing node with F2/Home/End
Press Alt=I to insert icon

Some more pleasure with mouse

Click on any node to toggle between fold and unfold
Point at node to see extra bubble to move up and down
Just right click on surface to access other windows

Import/Export - You just need to name it

Its import/export offering is extraordinary. Html, applet, jpg, svg etc..

Couple of aspects that I don't like with this tool

1) You cant pin selection of node. While trying to access menu bar selection changes. On mouse over event need to be handled with more delay to make automatic selection.

[You can do this by just holding down Alt or Ctrl]

2) Automatic layout option doesn't offer much. I guess some kind of alignment options would have solved this problem. Like Right align, left align Top, distribute etc..

Friday, July 13, 2007

Why Net DDE

Last week some one tried to make a joke about usage of Net DDE in WW products. Actually I was also not so convinced why WW still supports DDE and SuiteLink (DDE+ avatar). Since then I was trying to collect some information to educate myself on DDE.

I have been using DDE since 1998. Then I used it to create some custom report formats for customers. I used to collect information from DCS Systems to populate excel sheets. Those were the times OPC (OLE for Process Control) is stabilizing. OPC is COM based as the name itself contains OLE. Every DCS system is offered with DDE support for connectivity to excel. A simple formula in excel to access data made is quite a suitable approach. Like Application!Topic.Item for local DDE. and \\server\ndde$|share_name!tag_name for Net DDE. This is simplified by WW to be \\nodename\application_name|topic!'tag'.

WW DAServers offer all the three protocols. DDE, Suitelink and OPC. Older IO servers offers prior two and DAServers offer last one too. Thus the question about why Net DDE sounded quite logical.

Couple of reasons can be quoted here. a) It is developed by WW and then incorporated into Microsoft Windows. So importance of this protocol differs from WW to Microsoft. 2) InTouch primary understands Suitelink and DDE only. But some questions here.

What is DDE

Dynamic Data Exchange is developed by Microsoft during 1989. Its based on Windows Messages. It offers simple infrastructure to communicate between processes. So it is an IPC. Yes it is an IPC.

What is Net DDE

Net DDE is an extension for DDE for IPC across hosts.

Where is it used

Copy Paste. Everyone uses it. Copy Paste is achieved by DDE. Start Menu is populated with DDE. And in Industrial Automation sphere, it is used extensively.

What is the architecture

 DDE operates in Client Server mode. But unlike COM it doesn't have any broker service. It uses windows infrastructure to queue up Windows Messages. When client want to communicate with server it posts a message and then carries on with its work. Then System processes this and sends it to Server. Server receives it as a message and processes request. From then on Server post messages to client about the information requested periodically.

So it is different from COM

Yes it is different from COM in many aspects. DDE operates in advise mode and it is more suitable for continuous communication rather than transaction based communication. Industrial Automation relies on continuous communication. COM is best suited for transactions. COM is synchronous where as DDE is asynchronous. So for continuous communication DDE eliminates frequent poll requests.

In COM,  client can interact with object in server's address space. There the need is to operate on objects via interfaces. Mean data access is restricted. Where as DDE exchanges current state of data. So predominantly COM is more suitable for state transition whereas DDE is suitable for State monitoring.

COM client can not decide timeout for connection with  server, where as DDE clients can.

COM requires supporting runtime infrastructure, whereas DDE applications are light weight and easy to develop.


So I feel that using Net DDE based protocols is advantageous in some scenarios. But as world moves ahead with new technologies one need to convince upon continuing with old ones.

Every technology got a span. Beyond which either it should go to museums or or take a new avatar and contest for acceptance in new world.

Microsoft clarified that Net DDE will not be supported from Vista.  Rather not distributed with Vista. But WW can still distribute the Net DDE installer and install on Vista machines. So from now on Net DDE becomes a WW product than Microsoft product.

Hope WW will find some new avatar for it to continue selling their start product InTouch !

GUIs from Microsoft

There are so far 14 versions of Windows operating Systems.

UI of these operating systems improved from time to time. Following Website collected screen shots of these version. Its fun to have a look at them


It covers following Windows operating Systems.

1983  Windows 1.0 is announced
1985  Windows 1.0 (30 screenshots)
1987  Windows 2.0 (32 screenshots)
1990  Windows 3.0 (35 screenshots)
1992  Windows 3.1 (74 screenshots)
1993  Windows NT 3.1 (41 screenshots)
1994  Windows NT 3.5 (48 screenshots)
1995  Windows 95 (98 screenshots)
1996  Windows NT 4.0 (102 screenshots)
1998  Windows 98 (102 screenshots)
2000  Windows 2000 (103 screenshots)
 Windows Millennium Edition (51 screenshots)
2001  Windows XP (108 screenshots)
2003  Windows Server 2003 (50 screenshots)
 Windows Vista, the successor of Windows XP, is announced (under the code name Longhorn)
2007  Windows Vista (50 screenshots)

Tuesday, July 10, 2007

From Windows Live Writer

Just testing a post from Windows Live Writer. It looks good, it offers editing in a rich text editor as well as in plain html.

One definite advantage is we don't need to type in those funky pictured letters. And spell check is handy.

But cant add a picture!

Changing SQL Server 2005 sa password

Changing the password in SQL Server

for Sql Server 2000.

sp_password 'Old','New', Account

for Sql Server 2005.

PASSWORD = 'New_Password'
OLD_PASSWORD = 'Old_Password';

Monday, July 09, 2007

Over Pay - Reverse Offshoring

Basic rule of the game is to encourage key performers to deliver more. But what to do when they reach their saturation point? If it is the case of a ship or an aircraft they will be decommissioned and probably sent to a museum. But what could happen to a human resource in a high profile job. They need to treated with dignity but at the same time
they need to be informed to clear the slot. Easiest way to do that is to over pay him. Then make him realise that he is no more economically feasible. Another one is post him to some least preferred authority line.

As we started reading about reverse offshoring, it makes an interesting point to observe the career graph of this kind of people who were key performers but reached their saturation. Hope I get to read some articles about this subject in the near future!

Thursday, July 05, 2007

Swindon Trip

I had been to Swindon (80 miles from London) last month. Its an official trip for a week. Some snaps from this trip ..

Trying to keep up again

Many times I promise myself to update blog regularly. But for some reason I just skip it.

Here is one another attempt to restart.

Hope I do better this time.