Saturday, August 11, 2007

Regular Expressions - Part3

In previous post Regular Expressions - Part2, we discussed about regular expression engines and concept of backtracking. In this post we will discuss about the basis constructs of regular expressions , how to use them t o match simple words and lines.

Meta Characters

Meta characters are a sub-set of ASCII character set which take part in building a regular expression. e.g. +,$,^ etc.. Thus these characters instruct regex engines to perform specific operations. If we want to instruct regex engine to deal with thm as normal characters instead of meta characters we need to escape them with backward slash '\'.e.g regex "firstname\.lastname" instructs the engine to ignore special meaning of '.' and to consider as a '.' character.

Following list gives overview of mostly used meta characters.

. Dot - any character in a line

In normal search we use ? to specify a single wildcard character and * to specify sequence characters till next character. e.g. to search a file we use IAdb*.dll But in regex * is used for repetition. Also note that in a line phrase. This mean that the behavior of ‘.’ can be altered using mode settings like SingleLine or MultiLine mode to notify regex engine whether to match a newline (\n or \r\n) with a ‘.’ or to stop at new line. e.g:

Search String:
using System;
using System.IO;
using System.Text;
RegEx: “System.*”
Explanation: In MultiLine mode this matches all references with System and its decedents till end of line.
Matches in non-Single Line mode:
a)System;
b)System.IO;
c)System.Text;
Matches in Single Line mode:
a)System;System.IO;System.Text;

Note that semicolon is also matched in each line

\ - back slash
It is already mentioned that these are used to instruct regex engine to consider them as
normal characters. And when used with a number like \1 or \2, this specifies a back reference number. Back references will be covered seperately.

[ ] - opening and closing square bracket

Any group of characters to be matched are specified within these brackets. Examples are mentioned below.

( ) - round brackets
These are used to ho sub-expressions or back references. Back references will be covered later. Sub-expressions are similar to programming language sub expressions.

{ } curly brackets
These are used with iterators. We have seen this in Part 2 for five digit length. Its format is like {x,y}. where specifier is anything that need to repeated. Here x is
mandatory and can contain values from 0 to value of y. And y is optional to specify. and has to be any integer.

* Iterator to iterate for zero or more times. (0 or more times)

? Iterator to iterate for zero or one time only. (0 or 1 times)

+ Iterator to iterate for at least once or more times. (1 ore more times)

\w alphanumeric character including underscore

\W non-alphanumeric

\d numeric character

\D non-numeric

\s any white space; include , , and


\S non white space

| - pipe character
This is used to match alternatives. We used this in Part to test regex engine. Its syntax goes like [matcha | matchb]

\b - word boundary
We used this in part2 .

\B - any non- word boundary
example:
Search String:
ITSHUFFormAbc.htm
ITSCorporateFormBcd.htm
ITSSelfEmployedFormCde.htm

regex: ^[A-Z]{3}\B[a-zA-Z0-9]+\B

Match:
ITSHUFFormAb
ITSCorporateFormBc
ITSSelfEmployedFormCd


^ - beginning of a line

It matches from start of the line. In MultiLine mode it matches at the beginning of each new line. e.g.

Search String:
thisofLine1 of thisstring100
thisofLine2 of thisstring200
thisofLine3 of thisstring300
RegEx: ^this[a-zA-Z0-9]+
This matches this from the start of each line.
Matches in MultiLine Mode:
a) thisofLine1
b) thisofLine2
c) thisofLine3
Matches in SingleLine Mode:
thisofLine1

f you take out initial caret(^) in above regex, it will match both instances of this in each line

^ got a meaning of inversion when used within square brackets []. We will cover this in character classes.

$ - end of line
It matches at the end line. In MultiLine mode it matches at the end of each new line. e.g.
Search String: Let us the same string as above
thisofline1 of thisstring100
thisofline2 of thisstring200
thisofline3 of thisstring300
RegEx: this[a-za-z0-9]+.$
note '.' before $.
Matches in MultiLineMode:
thisstring100
thisstring200
thisstring300
Matches in SingleLineMode:
thisstring300

\A - start of text
Start of text matches only at the start of string irrespective mode setting

\Z - End of text
End of text matches only at the end of string irrespective mode setting

Thursday, August 09, 2007

Regular Expressions - Part2

In my last post Regular Expressions - Part1, I gave some introduction about regular expressions and presented code to build a tool that can be used to test basic regex constructs.

In this part I will discuss about how regular expression engines work. Before going there I just want to make a point about non-printable characters. Just have a look at ASCII chart once. Look for control characters, printable characters, non- printable characters etc..

Brief on Regex Engines

Regex engine is a library that can process regular expressions for search and replace operations. These engines operate on each character and thus composed of complex algorithms.

Editors supporting regex provide front end for this library. You can use this library with programming languages. As such there is a native support for regular expressions in some languages like Pearl, Ruby etc.. Microsoft got regex support from vbscript days. vbscript supports regular expressions with RegExp object. And look for class library reference of System.Text.RegularExpressions namespace for regex support in .Net. We used this in last example.

As these engines operate on each character and try to match with patterns; performance plays a major role. There are two kinds of engines to chose from. One is called Text Directed Engine while other one is Regex Directed. I will describe them in brief.
Of course no programming language offers a choice to select a particular regex engine. Its matter of what it supports.

In case of editors there is a simple way to test what kind of engine it is. Just apply regular expression "regex | regex not" on string regex not. If search result is regex then it is regex engine otherwise if the search result is regex not then it is text directed engine. There are couple of points to note here.

  • Expression you applied tries to match string "regex" or "regex not". '|' is a meta character in regular expressions character set. You can think this as an instruction for 'or' operation.
  • When you apply this regex on string regex not it got option to chose just the first word or both words. Regex engines characterizes eagerness, mean they are eager to return results to be quick and faster. Where as text based engines look for longest possible match. Thus former returns regexregex not.
Thus one of the differences between regex engine and text engine is eagerness.

In simple terms, one can categorize them based on search time. Say that with text directed engines, search time depends on length of the search string. And with regex directed engines search time depends on length of the regex.

Back Tracking

Another important concept is back tracking. As the name suggests back tracking is about tracking how we traversed while coming back. Did I confuse you? That is not intentional; let us see this with an example.

Suppose you are looking at financial report. And you are interested in values between 10K to 99K.

Now let us take figure "INR75063.37" . You know that it starts with INR and it is in the format of INR(x).(y) where x >= 0 and y = (00 to 99).

So you are looking for five digits before paise separator '.' This can be expressed as

"\bINR[0-9]{5}\.[0-9]{2}\b"

Let us apply this regular expression on following text

The amounts are Auto INR30.00 Onward Flight INR450454.34
Taxi INR435.65 and Return Flight INR34543.43 etc.

Observe result with five digits INR34543.43 the figure in desired range.

Now let us walk through what happened here.

First with regular expression - \bINR[0-9]{5}\.[0-9]{2}\b. Outer \b at the beginning and at the end specify word boundary.

Obviously all amounts are within a word boundary. (To check about word boundary click at the start of search string, then press Ctrl+[right arrow ->]. Of course this includes space, forget space for this discussion.). So here goes the part wise description of this regex

  1. INR will be matched literally.
  2. Then [0-9]{5} specifies to look for 5 digits(0-9).
  3. Then we have a dot '\.' dot is a meta character in Regular expression character set, thus we need to escape it. It might work without escaping too, but just follow it as a good practice.
  4. Then we have [0-9]{2} which is obvious for two digit of paise. And closing of boundary with '\b'

Ok we understood the regular expression, now let us understand how regex engine might have done this search.

It starts with text string 'T' in The of search string, and looks at part1 of regular expression which is expecting I of INR, it is invalid and thus moves to next word.Then it finds 'a' in amount, which is invalid and moves ahead.

When it comes to INR30.00, it matches INR then moves regex to [0-9]{5}.

Here regex can match it in two ways.

(a) Collect characters till paise separator '.' then verify that each one is a digit(0-9) and number of digits is 5. If paise separator is not found till end of word (\b) skip this word

(b) Collect each character and then check it to be a digit and add to count, if the count is 5 then check for paise separator as sixth digit. If sixth character is a paise separator search passes else search fails am moves to next word.

Here first option (a) assumes that if paise separator is not there, then no need to check each character to be a digit and to add to counter. If it finds a paise separator then it will track back each character and then does necessary operations.

In case of (b) engine anticipates paise separator and does character validation and counter operation for each character.

Assume a case where we are searching for 10 digits. In that case performance penalty with option (b) would be very high.

Option (a) describes case of backtracking. Backtracking is like leaving a pile of bread crumbs at every fork in the road.

If the path we choose turns out to be a dead end, then we can retrace our steps giving up ground until we come across a pile of crumbs that indicates an untried path. Should that path, too, turn out to be a dead end, we can continue to backtrack, retracing our steps to the next pile of crumbs, and so on, until we eventually find a path that leads to our goal or until we run out of untried paths [1].

With text directed engine each character is looked at only once, while with regex directed engines each characters might be looked at many times. Regex directed engines support back tracking and Text Directed engines doesn't.

While at back tracking I should mention about meta character dot '.' in Regular expressions. Dot means any character (except new line). Back tracking plays major role when working with dot. We will look into dot and all other meta characters in next post.

Next -> Regex Meta Characters

Wednesday, August 08, 2007

Regular Expressions - Part1

Regular expressions. Most (u|li)n(i|u)x programmers might have used them with grep. What are they and why they are so different? By this time you might have got a doubt about (u|li)n(i|u)x. If you interpretedit as unix or linux, then you know about Regular expressions.

If you don't know yet you could interpret it; then regular expressions are not difficult for you. It is just a matter of time you pick a book and understand the rules of this new game. If you got puzzled about those words then just think that you are learning a new technique.

What is this all about
Regular expressions can be used to search and replace text patterns in more structure manner. I am not defining the word regex here. But just bringing you to the context of text search / replace and structure. Just remember structured text search and replace.

Some taste and smell
\b[A-Za-z0-9._%\+-]+\@[A-Za-z0-9-]+\.[A-Za-z0-9-]+(\.[a-z0-9-]+)?\b

Above regular expression matches an email id with regular tld like .com or country specific tld like .co.in. DONT try too hard to match it to an email address. I assure you, by end of this session you will find lot many problems with this regex, and you will optimize it with a much better one.

Before we start:

1) It takes time and requires dedicated time of at least 10 hours before you gain momentum with regular expressions. But here I want to make this process simple and easy. Thus I want to stretch these 10 hours over 10 days, one hour on each day.

2) need a regex editor to test. You can pick some from google. But I feel it is better to write your own with minimal effort.

Build MyRegex test tool (Option 2 as mentioned above):

At the core, this tool is going to have three text boxes. (a) to enter text to be searched (b) to enter regex pattern (c) to show results.

Optionally we can have some check boxes to select few options and labels to address text boxes. I used .Net 2.0 and C# windows application.

I attached screen shot here. I used a context menu on regex textbox to avoid a button click.

In designer code just add this.tbRegex.ContextMenuStrip = this.contextMenuStrip1;

I named my regex text box as tbRegex. You can also find two check boxes to select

Singleline mode and Multiline mode. Don't bother about these things now.

Just add them in a frame for better looks. Then just add references for RegEx and event handler on

Find Context menu click. See code below for form.cs.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace RegExApp
{
public partial class Form1 : Form
{
RegexOptions regexoptions;

public Form1()
{
InitializeComponent();
}

private void findToolStripMenuItem_Click(object sender, EventArgs e)
{
tbreults.Text = "";
string results = "";


string txtstr = tbintext.Text;
string regex = @tbRegex.Text;

if (cbSingleLine.Checked)
regexoptions = RegexOptions.Singleline;

if (cbMultiLine.Checked)
regexoptions = RegexOptions.Multiline;

MatchCollection matches = Regex.Matches(txtstr, regex, regexoptions);
foreach (Match m in matches)
results += m.Value + Environment.NewLine;

tbreults.Text = results;
}

}
}

Now we can test this tool. Just copy and paste following text in top text box i.e. serach string box,

my email id is firstname.last@gmail.com online
send me mails to FIRSTNAME.LAST@GMAIL.COM collections
yahoo id is firstname_last@yahoo.com on check
also aliased to Firstname.Last@yahoo.com checked often
and hotmail ID is firstname-last@hotmail.com least
or name@net.co.in is also fine

then copy and paste following regex in regex textbox (use Ctrl+v as right click opens context menu)

\b[A-Za-z0-9._%\+-]+\@[A-Za-z0-9-]+\.[A-Za-z0-9-]+(\.[a-z0-9-]+)?\b

right click on regex text box to trigger context menu and click on Find.

Check following results in results text box

firstname.last@gmail.com
FIRSTNAME.LAST@GMAIL.COM
firstname_last@yahoo.com
Firstname.Last@yahoo.com
firstname-last@hotmail.com
name@net.co.in

Experiment by adding new email ids, extra tld's etc..

Next -> Non printable characters, Regex engines and how it works?

Wednesday, August 01, 2007

Programming assemblies and modules in MSIL

Introduction

This is about building assemblies and modules using MSIL language. To have a reasonable insight about internals of .Net Framework understanding of IL is must. There are many articles that describe how CLR loader loads an assembly how JIT compiler compiles and points the the method to newly created memory block with compiled code etc. But I couldn't find a simple guide to build basic units of execution modules using IL like
  1. a net module

  2. a multi file library

  3. an assembly with library reference

This article describes this process in step by step manner. We are going to create two net modules. Then we link them together to form a library. Then we build an application assembly which refers to methods defined in net modules of library. Before going there I would like to describe some theory in one paragraph describing theoretical aspects of this subject. If you cant bare it, just skip following section. You can always come back to have peep if needed.

Theoretical background

CLR CTS CLS - quick focus. CLS defines minimum set of rules needed to offer interoperatability among .NET application written and compiled in different languages and targetting CLR. In .NET's context IL,MSIL and CIL are synonyms. Intermediate Language (IL) ~= Microsoft Intermediate Language (MSIL) ~= Common Intermediate Language (CIL). CLS compliance ensures interoperatable in terms of naming conventions, the data types, the function types etc. But CLS compliance is not mandatory but a recommendation. CLR doesn't doesn't impose any restrictions for an application even it is non-compliant with respect to CLS. But in such cases interoperatability can not be achieved with modules/assemblies developed in different languages. On the other hand Common Type System enforces its rules on each every construct of any language that is targeted for CLR. For examples assemblies and modules are standard types. Managed .NET application are called assemblied and managed executables are referred as modules. An assembly ca contain many modules. Each module contains MetaData and IL. And an assembly contains a Manifest too. CLR offers a safe execution environment above operating system. Safety is achieved by enforcing type control, structured exception handling, garbage collection etc.

With that let us jump to files and code. Recollect that we are going to create two net modules. Then we link them together to form a library. Then we build an application assembly which refers to methods defined in net modules of library. Copy code for these three source files nm01.il,nm02.il and hello.il. And we will build mylib.dll by linking net modules nm01 and nm02.

Files and Source

net module 01 - [nm01.il]

I could have taken more IL files to build this net modules.
This got just a constructor and two static methods.
There is no need for them to be static, but they are there without any strict reason.

.assembly extern mscorlib{}
.class public mymath01
{
.method public void .ctor()
{
.maxstack 1
ldarg.0 //push "this" instance onto the stack
call instance void [mscorlib]System.Object::.ctor()
ret
}
.method static public int32 mysum(int32 i1,int32 i2)
{
.maxstack 2
ldarg.0
ldarg.1
add
ret
}
.method static public int32 mysub(int32 i1,int32 i2)
{
.maxstack 2
ldarg.1
ldarg.2
sub
ret
}
}
net module 02 - [nm02.il]

.assembly extern mscorlib{}
.class public mymath02
{
.method public void .ctor()
{
.maxstack 1
ldarg.0 //push "this" instance onto the stack
call instance void [mscorlib]System.Object::.ctor()
ret
}

.method static public int32 mymul(int32 i1,int32 i2)
{
.maxstack 2
ldarg.1
ldarg.2
mul
ret
}

.method static public int32 mydiv(int32 i1,int32 i2)
{
.maxstack 2
ldarg.1
ldarg.2
div
ret
}
}

Application - [hello.il]

.assembly extern mscorlib {}
.assembly extern mylib {}
.assembly hello {}
.method static public void main() cil managed
{
.entrypoint
.maxstack 4
.locals init (int32 first,
int32 second,
int32 result)

ldstr "First number:"


call void [mscorlib]System.Console::WriteLine(string)
call string [mscorlib]System.Console::ReadLine()
call int32 [mscorlib]System.Int32::Parse(string)
stloc first


ldstr "Second number:"
call void [mscorlib]System.Console::WriteLine(string)
call string [mscorlib]System.Console::ReadLine()
call int32 [mscorlib]System.Int32::Parse(string)
stloc second

ldloc first
ldloc second
call int32 [mylib]mymath01::mysum(int32,int32)
stloc result

ldstr "{0} + {1} = {2}"
ldloc first
box int32
ldloc second
box int32
ldloc result
box int32
call void [mscorlib]System.Console::WriteLine(string,object,object,object)

ldstr "Hello, World!"
call void [mscorlib]System.Console::WriteLine(string)
ret
}

I guess most of this stuff is pretty obvious except for maxstack.

maxstack

At the IL level, the CLR needs to know the maximum stack depth of each method. This is not a plain arithmetic. It depends on code flow and depends on max number of stack slots required for any operation that is performed within this method. Though it is not simple it is not dynamic too. Compilers targeting for CLR can calculate this before producing executables. Compilers of high level languages like csc (CSharp ) and vbc (VB) does calculate this number embed it before producing executable code. But for some reason ILAsm doesn't do this. If you don't specify .maxstack, stack defaults to 8. But if methods more stack slots program will crash at runtime.

Partial Classes

Some might have thought that why I created a new class in each net module; rather I would have used a partial class. This makes sense because I am actually building an arithmetic class. But this is not possible here. Because IL doesn't know anything about partial classes. This feature is offered by high level language compilers with syntactic sugar. That makes it clear about why partial classes can not be spanned across assemblies. Compilers merge code in partial classes to make a single class while building. Thus all references for that class should be resolved before building the assembly.

Build commands

I guess you have .Net Framework and SDK(or Visual Studio 2003/2005) installed on your machine. The command I am describing here are for local host. If you are building for other targets than build machine, specify flags for respective targets. Now start Visual Studio Command prompt or SDK command prompt. Navigate to location of source files.

  1. Building net modules
    ilasm /dll /output=nm01.netmodule nm01.il
    ilasm /dll /output=nm02.netmodule nm02.il

  2. Building library - we use assembly linker for this purpose
    al /t:lib /out:mylib.dll nm01.netmodule nm02.netmodule

  3. Building application
    ilasm hello.il

  4. IL dis-assembler - ildasm
    For the purpose of this article use command line options of ildasm instead of GUI.
    ildasm /All hello.exe /out=hello.dil
    This produces helo.dil file which contains complete information

  5. dumpbin
    You may also want to use dumpbin if you are interested to see headers and sections of PE files.

    Please note that there is mention of linking mylib.dll while building hello.il. Actually this linking is specified in source; ".assembly extern mylib {}".

Now run hello and check for results like this
$hello
First number:
3
Second number:
7
3 + 7 = 10
Hello, World!

How to Debug

Debugging a managed code itself becomes a separate topic. This is because CLR won't execute IL code , it actually executes native(machine) code compiled by jitter. And any loss of fidelity from IL to Native will confuse the debugger. This entry ran quite long. I will keep Debugging for another entry.

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
                sb.Append(si);
            }
            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;
            }
            else
            {
                strpart = null;
            }

            //Update out parameter for numbers
            if (nstrtemp != "")
            {
                intpart = int.Parse(nstrtemp);
            }
            else
            {
                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$Build.cmd

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"

C:\IronRuby$

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$_$$"
"CompletionChar"=dword:00000040
"DefaultColor"=dword:00000000
"EnableExtensions"=dword:00000001
"PathCompletionChar"=dword:00000009


Here I added registry settings for path completion too.

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

TOP TEN TIPS TO STAND OUT FROM THE CROWD

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
ArrayListList<T>
BitArrayNo replacement exists
CollectionBaseCollection<T>
ComparerComparer<T>
CompatibleComparerComparer<T>
DictionaryBaseKeyedCollection<TKey,TItem>
HashtableDictionary<TKey,TValue>
ICollectionICollection<T>
IDictionaryIDictionary<TKey,TValue>
IListIList<T>
QueueQueue<T>
ReadOnlyCollectionBaseReadOnlyCollection<T>
SortedListSortedList<TKey, TValue>
StackStack<T>

Pros and Cons of each type:

Dictionary
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>.

List
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.

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

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

LinkedList
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.

SortedDictionary
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.

SortedList
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

IEnumerable
methods:
GetEnumerator - returns IEnumerator

IEnumerator
methods:
Reset
Current
MoveNext

ICollection - extends IEnumerable
methods:
Add
Remove
Clear
Contains
CopyTo - copies items to an array
properties:
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
methods:
IndexOf
Insert
RemoveAt
indexer: allows to get and set any item in the collection, just as you can when using arrays


IDictionary - extends ICollection
methods:
Add - overload that associates a key with the item that is added
ContainsKey - method will check for the existence of a particular key
Properties:
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("Found");
            else
                Console.WriteLine("Not Found");


            Console.WriteLine(ft.Add(str1));
        }
    }
}

$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)
        TypeDefId
        TypeName
        TypeNamespace
        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.

Add-ins
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

Plug-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.

Extensions
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.

Modes

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

Nodes

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".

Clouds

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

http://www.guidebookgallery.org/guis/windows

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.

ALTER LOGIN Account_Name WITH
PASSWORD = 'New_Password'
OLD_PASSWORD = 'Old_Password';
GO

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.

Thursday, April 19, 2007

HYSEA Technology Day

Today I attended HYSEA Technology Day event. Just thought of sharing few things from this event.


Chief Guest: Dr.Jayaprakash Narayan of LOKSatta


He expressed his concern about unfulfilled potential and avoidable suffering persisting in great measure in our county. Few other areas that he illustrated are



  • to make technology reach the needed. He said that many people doesn't even know a tool like email exits, even if they know they dont understand the potential value that it can bring to individual's needs. He said that email concept helped him bringing a Govt. policy about contestants with grievous criminal background during 1996

  • He talked about how technology is being underutilised by television media. He said that we tend to hear more about wins and loses rather than problems and solutions.

  • then he spoke about how attitude of bureaucrats hinder good proposals. Basically any long term proposal is approved only when substantial growth is esured by next general elections. He also stressed that Tomorrow will always be better than today, even if no new initiatives are taken by political establishments. Initiatives where the result is dicy and just to make things better than today are of no use in this fast moving times


Apart from this he stressed about few fundamental problems that country is facing today.



  1. Health Care

  2. Urban Transport

  3. Alternative energy systems using Bio waste.


In this regard he appealed to technologists to go behind problems rather waiting for problems to come to them as projects and use cases.


Key Note was presented by Sudin Apt from Forrester Research


He presented on Technology and OutSourcing Trends. He tried to sketch out Fourth Wave Computing trends as following



  1. Digital Business Architecture

  2. Extended Internet and Executable Internet

  3. Innovation Networks


He said that the business objective with which an innovation is made, need to pass through Initiators, Transformers,Financiers and Brokers. He emphasised on perfect harmony among these stages to bring out the best. Talking about Innovation networks, he said a person within four walls of a company or and R&D department of an organiation can't alone solve the complex problems faced by this generation. Innovation networks need to co-operate well to bring out best of customer.Then he spoke about social computing. In this regard he said that customers trust in institutions is failing. Cosumers are becoming less loyal. Then he spoke about how Jack Welch applied Diamond model instead of BowTie model to set right aircraft business.


Then he analysed indutry trends during last year. His version is top three companies TCS, Infosys and Wipro together increasing their share quarter after quarter while new million doller babies like HCL, Satyam etc. and other small size players are losing on pie section. He described this phenomenon as polarisation which he thinks is not good for industry growth. He says that smaller companies cant end up taking what ever comes in their way for long time. They might do this while building up, but cant afford to do this forever. If they dont concentrate on focus areas they may not have many options for sustainable growth after some time.


Venky Chennepragada of Keane spoke about Information Architecture & Rich Internet Applications


He stressed on gaining emotional bonding with customer. In his opinion an SOW/RFP are tough ones which need to pass through legal barriers. Rather he emphasizes on Addendums on existing contracts. He says many end users doesn't understand use cases. Thus asking them to review your use cases for reaching common consensus is not always a good idea. He says that UX design teams need to work closely with BU's, end user and architects to come up with UI applications that can bring emotional bonding. Information Architects, Visual Designers and web Developers need to work closesly to bring out good UX applications.


Anuraag Agrawal (Motorola) about User Experience on Mobile Devices


Anuraag's presentation was like a fiction novel. He was talking about the magic that mobile devices are going to do in furture. His ideas revolved around



  1. voice as input

  2. usage pattern recongnition

  3. identification of gesture


As such trends are quite exciting. Hope coming years will bring more of intelligence by means of gadgets in life style..

Thursday, January 04, 2007

Linux adoption in India

During August last year I heard that around 12500 schools in Kerala adopted Linux[1]. Further Richard Stallman's visit to Kerala boosted enthusiasm in that state[2].

Today I read that ELCOT (Electronic Corporation of Tamilnadu) adopted Open source applications.
All their servers including access control systems are on Red Hat Linux[3].

All along it remained merely a hobby or fun or learning(for most of the users). But now the wave is creeping up from southern states in India.

According to the State Minister for IT and Bio-Technology of Karnataka, Prof. B.K. Chandrashekar, the State is also planning to broach this idea with neighbouring States such as Andhra Pradesh in order to gain wider acceptance for Linux[4].

Hope the day is not far away where Linux skill becomes defacto necessity to excel in software industry in India.

References:
1) http://digg.com/linux_unix/Kerala_Indian_State_to_go_100_Linux
2) http://www.hindu.com/2006/08/22/stories/2006082210770400.htm
3) http://stuff.techwhack.com/archives/2007/01/04/elcot-tamil-nadu-open-source/
4) http://www.thehindubusinessline.com/2002/05/18/stories/2002051801280700.htm

Srisailam

We had been to Srisailam during last week. Though we thought of going to this place since long time, it worked out only last week that too without much planning.

We were under the impression that getting a Punnami guest house (AP Tourism) or any other hotel at Srisailam wont be a problem. But we were wrong. We need to book at least a month ahead of time during new year season.

What we understood from web is that Srisailam is around 220 KM from Hyderabad and it normally takes app. 5+ hours to reach there by road. And many suggested to go by AP Tourism package.
That would have been a more organized trip. But we chose to drive ourself.

We started from Hitech city in Madhapur at 6:30 in the morning. In search of Srisailam road we reached Uppal as suggested in one of the blogs. Then we headed towards LB Nagar Police Station.

For some reason we ended up in Nagarjuna Sagar Road rather than Srisailam Road. But that is not a major problem as both are more or less parallel. In Sagar road we headed up to Kondamallepalli, which is also called as mallepalli(app 80 km from hyderabad). From this place we took a right turn to head towards Devarakonda. Up to this road is good enough to drive at a speed of 80 to 100kmph. But please mid few speed breaks in between.

From Devarakonda the road is under construction and is a single road up to Dindi diversion(app 40 Km from Mallepalli) . Here your average speed will come down to 30KMPH and is really very narrow road. Dindi diversion is main diversion for Srisailam. Even if you take regular srisailam road from Hyderabad, you will head up to Kalwakurthy and then take a left turn towards Dindi.
In a way you can say that Srisailam diversion is between Mallepalli on Sagar road and Kalwakurthy.

From Dindi the road is good enough except for a patch at Dindi(Tributary of river Krishna).
On this road you head up Srisailam Tiger Reserve forest. This stretch is app 20KM long. Then you will reach the last 80KM stretch which completely in forest region and is a Ghat road section.

You need to make an entry at Forest department check post while entering the Reserve forest zone. Drive inside this 80KM is simply awesome. First we will reach Patalaganga. We reached this place by 11:00 AM. This place has an awesome view point with power generation plant, Srisilam dam, AMR SLBC(Srisailam Left Bank Canal) tunnel and clean Krishna river. We enjoyed boat ride here. Those special circular boats offer a splendid experience.

From here Srisailam temple is just 20 KM away. You need to cross a small bridge across the river.

For us the darshan took just 25 minutes. No need to special tokens or anything else. You can just walk in. Please note that the speciality of Srisailam temple is, you can touch the idol.
But this is allowed only after 6 PM in the evening. We had darshan by 1:45 PM.

Then started return journey at 5:00 PM. Thus reached Hyderabad by 9:00.

Tuesday, October 10, 2006

DVB connection with Insat 4A

I got Tata Sky connection today. Overall experience is good.

Buying Hardware:
First I bought a Set Top Box (STB) from local dealer. Its Thomsom DSI3207C with Tata Sky CAS (Conditional Access System) card embedded in it. I cant find any details about this Thomson DSI3207C on web. Probably a special make by Thomson for Tata Sky. It costed INR 2999/-.

Offer:
Apart from this we got to pay INR 1000 towards installation charges. With that offer says connection for first 82 days is free along with 50% discount on installation charges.

Later part of discount and free stuff is simply to fool customers. When you pay that 1000 towards installation charges, dealer gives you a pre paid charge voucher for 1000 bucks. Now when you get connection you need to activate using this 1000 bucks. Out of this 1000, 500 goes towards installation and remaining 500 for 82 days based on 200 per month charges.

Instead of this, they can simply say installation charges as 500 and minimum lease period is 82 days which costs 500. And post 82 days they are offering Rs 200 per month for limited period.
Actual package and cost are not yet revealed.

Registration:
So the dealer gives you STB. Once you get that you need to call up their call center 66006633 or From MTNL/BSNL lines: 1-901-425-6633. Then some newly recruited call center guy picks up the phone. To be very poilte he adds Mr.YourName before and after every sentence. Finally he takes your DigiComp No and Digicard Number which are pasted on STB box. Then he schedules installation and informs customer ID and scheduled date for installation. Installation normally happens with two days. And they mention that it takes approximately 2 hours of time.

Installation:
In my case installation team turned up well in time on second day. They called up and reached home by Maruthi Van. They are professional enough.
They bought a dish, LNB, wire and complete tool kit. Checked the location for clear site at 83 degrees East towards south. That is the location for INSAT 4A in GSO. Tata Sky booked all the 12 Ku band (12 to 18 GHz microwave frequency) transponders on INSAT 4A with DVB capabilities. http://www.lyngsat.com/in4a.html And their dish and LNB by looks appears a standard make. But its just Tata SKY written over them.

Then they routed the cable through best possible way. They are well trained professionals.

And then it is an instant start. You connect cable from LNB to STB and connect RYB cables from STB to TV AV-In port. Start TV and tune to AV channel. Boop... it picks up instantly. Scans all transpoders and updates information in STB.

Quality and Channels:
Picture quality, voice and navigation options are superb. I think SKY plays roles here. Star network which got 20% stake in Tata SKY joint venture, owns and operates SKY services in UK.

Activation:
The test connection is valid for first 24 hours, during that we need to activate using prepaid card of 1000.

Goodie stuff:
Some good options are favourites, ACTIVE menus, Electronic Program Guide for a week etc, option to select language if uploaded in DVD format.. Here is the list of channels offered http://www.lyngsat.com/packages/tatasky.html

Poor/Bad Stuff:
Down side is movie on demand is not in active operation. And you got keep your TV sound full to control it from STB. And Music channels are not yet activated.

To explore:
I still need to explore on how to tune into other free channels using STB.
Is it possible to use the same STB with another service provider.

As per Trai all STB's should be interoperable. But TATA SKY has some objection with DVR capabilites of STB as opposed by other licensee for DTH broadcasting services in India,Dish TV.
http://www.trai.gov.in/recommendations_list_division.asp?j=5&select=

Wednesday, October 04, 2006

medical services

How can we rate medical services? Ok leave away with rating how do we decide upon which hospital/doctor to approach when we are in need of medical help? Traditional concept of "family doctors" is fading away from our society. Medical services are becoming commercialized. Approach for diagnosis has taken an unfortunate course.
Who cares about patients past medical history and treatments? Whom to blame for this? A doctor is mere a cog in the wheel of hospital. A doctor is still considered as a respectable person in India. But what are the factors that are offending their morale.

Just to think about profession of doctors. Many of my school friends, bothers and sisters are doctors.
As on today an MBBS doctor passed out from a reputed Govt. Medical college is unable to earn 10K, whereas a normal graduate could earn more than 15K from call center jobs. And the duration of MBBS course is another factor that discourages an individual from taking up medical science for undergraduate studies. Recently I met few doctors who got MBBS degree in last two years. They are leading impoverished life. They can’t see any road map to earn 25K per month in near feature. Very few can invest money to start their own hospital and run it profitably. Hardly anyone interested in MD or any other higher education options. Of course they constitute only a section of doctor’s community. Though you can be kind enough towards one or two sections majority of them are becoming intolerable.

When looked at this problem on national front, India as a nation is loosing the ability to provide quality medical services to common man. Our medical resources are depleting. Super specialty hospitals are succeeding in providing good infrastructure and one stop service centers but loosing on quality.

Casualty gets lowest preference. It’s pathetic to here about it but that is the reality which we end up facing every now and then. Either inexperienced doctors or doctors who don’t have back to back schedules are placed there. Many of them lack courtesy towards a patient. Sense of urgency doesn't have any role to play there.

I observed diagnose process closely for out-patient cases in so called multi specialty hospitals.
Here is a brief account

First step is to blame on hereditary. Because you can’t change your ancestors its easy to convince you by telling that you are bound to get this problem, if not today some time later in your life time. It’s quite a simple formula to diagnose. And this works out well in most cases.

Second step is to choose package. There are so many pre fed packages to filter out. Here the approach is not to diagnose, but to eliminate non probables. This is because multiple choice questions are quite easy compared to fill in the blanks. So chose which packages to apply upon. And enough care should be taken while selecting so that the reports are not be available for 36 hours of time. For those 36 hours prescribe pain killers and antibiotics. Good when patient collects reports and comes back ask for improvements; obviously pain killers influence him to say "feeling better to some extent".

Third step is dependent on second step. If patient complains that there is no improvement rather its worse, refer to another department. If you are fortunate this is where the actual treatment starts. Else you may go around another round before getting referred to another department or doctor or hospital.

Fourth step is contrary to third step or self diagnosis. When you turn up to hospital to say that you recovered, you got pay fine at pharmacy for recovering so quickly. Probably four to fives doses in a day, a dose before meal a dose after meal. 1 - 1 - 1 or 1 - 0 - 1 or 0 - 0 - 1 or upon suffering. Obviously you can’t meet this dosage particularly when you know that you recovered. So either discontinue that treatment or keep those tablets for self medication at later point in time till they expire.

Are there any such tools to rate hospitals in our locality, write treatment experiences and praise / curse? Are there any web tools where we can log our medical history, search on others for symptoms or experiences? We have so many forums about computer systems where are they for human systems? We got online photos albums, journal for entertaining tidings in life, email for quick communication. We got some forums for discussing about good or bad about a car, camera, phone and etc... We rate them and refer them.

Is there anything www community does in this direction?

Providing online medical services for a free or minimal charge is secondary, but at least are there any sites or forums to bridge patients and good doctors?

Friday, September 29, 2006

New PC

After 6 years I am tired with my P3 and got a new one today.

This time I felt like assembling it.

I was waiting to get a Core 2 since long time. Initially I thought of taking an iMAC. That is coming up with new Core 2 ones. But I felt the cost factor beyond my limit.

Then I went ahead to buy an E6400 (2.13 GHz, 2MB Shared) model Core2 from Intel. And then the motherboard I wanted with Firewire support. Only Intel P865 chipset supports firewire. So I took ASUS TEK P5B Delux WIFI AP board. This costed a bomb. Final configuration came out like this.

1) Intel E6400 - 12.8 K
2) Asus TEK P5B Delux WIFI - 18K
3) RAM 1GB non ECC Trancend - 5.5K
4) SATA 160 GB Hard Disk - 3K
5) ATI X550 256 MB graphics - 4K
6) Microsoft wireless Keyboard and Mouse - 1.5 K
7) Zebronics Cabinet - 2.5 K
8) SONY 17" LCD - 13.9 K
9) LG DVD Writer - 2K

But Motherboard is good with dual LAN and WIFI. Yet the explore the performance.

Can anybody suggest clean tools to test overall system performance.

Community Service!!

There was a good old barber in Bangalore.

One day a
florist goes to him for a haircut.

After the cut, he goes to pay the barber

and the barber replies:

I am sorry, I cannot accept money from you; I am doing
a Community Service.
Florist is happy and leaves the shop.

The next morning when the Barber goes to open his
shop, there is a "Thank You" Card and a dozen roses waiting at his
door.

A Confectioner goes for a haircut and he also goes to
pay the barber he again refuses to take the money. The Confectioner is
happy and leaves the shop.

The next morning when the Barber goes to open his shop, there is another ”Thank you" Card and a dozen Cakes waiting at
his
door.

A Software Engineer goes for a haircut and he also goes to pay the barber
again refuses the money saying that it was a community
service.

The next morning when the Barber goes to open his
shop, guess what he finds there......

Scroll down for answer.................
.
(Believe me it's worth it!!!!!!!!!!)


..


..


..


..


..


..

A Dozen Software engineers waiting for a free
haircut... with Printouts of
forwarded mail mentioning about free haircut

Thursday, August 24, 2006

Reliance Broadband

I took new reliance broadband connection after cancelling Airtel.


Reliance is offering 1000 kbps with 1 GB limit on download for 600 rs rental per month.

Its nice, they give a telephone too with free rental. Call charges are as applicable.

Wednesday, August 16, 2006

Bought new Motorola SLVR L7

Today I bought a new Motorola SLVR L7. Its a gift from Radhi for 6th wedding Anniversary.
So far so good, but today I found a problem with camera. Its gets picture with red patches.
I called up Motorola service center Redington at Somajiguda.
Went there and gave a written complaint. They say it may take three days to get the spare unit.Hope they will call me back.

Thursday, August 10, 2006

Moved into new apartment

Today we moved into new apartment. Its 11A Jayadarsini.
So I lost internet connection for the moment and busy with shifting.
So back from today

Wednesday, August 02, 2006

Influencing Satisfaction - Control to care not to question the dare

Here I want to write about influencing satisfaction on salary hike.
To some extent I want to criticise too, thus some parts of this writing may infer conniption. So please read those parts with a pinch of salt.

I would like to start by citing a known case then the intended case.
Listed companies distribute lot of printed material along with dividend. Companies draft such material with an intention to influence the share holders to deal with prevailing business situation. Here the key is to bring the shareholders under their influence.

Here is the intended case. Employee’s performance is measured as confidential subject. Same goes with Team’s performance, Group’s performance and Business Unit’s performance. But organization’s performance is declared and published. How can an employee relate to million dollar balance sheet? Agreed it gives some fun in discussing about it at coffee table, but seldom influences an individual.

When an employee feels dissatisfied about increment, management convinces by saying that everyone was treated fairly so there is nothing they can do about it. But basis for that fairness will remain a mystery for that employee. And those who express negative feelings are marked as inconsiderate and immature to account for the situation. I know it goes on case to case basis but just hold it for the sake of criticism.

Here is the point of discussion. In first place, why leave the scope to feel dissatisfied and later expect them not to react about it. I guess it’s because of the fact that they were not prepared to deal with the situation. Are there any measures taken to influence the satisfaction level on salary hike. If no, why not. If yes, did they yield benefits so as to influence the majority. And what about improvements.

In traditional businesses performance is quite apparent. But that is not the case in coding workshops (software organizations). Employees seldom get to know about billing, capital expenditure, assets, salary budget etc... Many such details are masked from them. Here the key is to give them a feeling that they are not ‘completely’ masked. It is not too difficult to do this with a presentation. Content may not be descriptive but just need to make some sense.

To conclude following few points can be looked on in this regard.

1) “Prepare/Influence” an employee at every level - as an individual, as part of team, as part of group and as part of business unit to deal with the situation.
2) Discuss about salary budget on “qualitative” figures. Analyze it by performance of groups and teams. Present figures from previous years.
If management got content employees got caliber, they are not dumb they can understand basics of economics.
3) Prepare printed material to publish results at each level. Also handover that material along with hike letter.
4) Help those employees who express difficulty in understanding the content, if needed provide them with further reading material
5) Allow employees to express their dissatisfaction. Privacy is desired about salary but not about satisfaction. Conduct YES/NO kind of satisfaction survey. Publish the result of survey and guide employees to go with majority. If dissatisfaction leads, act on it and substantiate with “Industry Survey”.

Further we get to see mails stating “such acts are not acceptable and disciplinary action can be taken”. I guess every now and then one need not explicitly announce that they are capable of taking disciplinary actions. Just mention that relevant document (like Employee Hand Book) is modified and employees are expected to go through those sections.

Control to care not to question the dare...

Monday, July 24, 2006

Electronic filing of tax returns

Every year we do this. I mean filing tax returns. Is it fun, pleasure, caution, warning or frustration? Typical cycle goes like this. From Jan we keep getting calls for tax saving bonds. We get to hear many discussions around coffee machines about these bonds. Some desire to invest conservatively and few others go with the wind. Those invested go around finance desks to include their new investments. That part ends by end of March.

April is the time to declare the investments for next year. So based on previous year experiences we tend to improve it. But changes in Union budget leave us with lot of confusion. Then we need reviews on budget from finance gurus to make an optimum investment declaration.

End of June is the time for mails, to float around, about tax returns. This exercise is compulsory. Normally organization calls an agency for this sake. Those babus offer this service for hefty price. By Aug 15 we get acknowledged returns. We are expected to keep these papers carefully. Then there won’t be any activity till next Jan.

Year after year we do this job in almost similar manner. I didn't see any change in this process in last seven years. Taxes are for building nation. But lot us got concerns about proper utilization of funds raised from taxes. What I understand is most of the time this money goes to repay the loans we take from worldwide banks. I don’t think we are in a position to plan to do anything with our own money. Surveys reveal that only 10+ % of population pays tax.

There are several kinds of taxes that we pay. But the bulk out of them is income tax.
Take the case of Municipal Corporation or Road Transport Authority. We can pay property tax online as well Road tax. They streamlined their process so much that tax payer need not face bureaucratic hierarchy in their offices.

But what is lacking with income tax department (ITD)? I have following queries
1) ITD operates on much much higher volumes still they are unable to streamline the process. Do they lack money? Of course NO
2) Unlike customers of RTO department majority of tax payers are well educated and can take benefit of advanced means to file tax returns. But still why ITD can’t improve the process of filing returns?
3) Why can’t Income Tax Act be in colloquial language or even in plain English?
Why so much of legal nomenclature? So many inter links within sections?
4) When can we file returns ourselves online and can see the process of the file online?
5) Do we hold PAN card for IT department’s sake or for the sake of a loans from banks? What is the information that a tax payer can access with PAN? If it is mere a number for ITD reference but to be maintained by tax payer
6) There are penalties for those who evade tax, but what are the incentives for regular tax payers? Just because very few people pay taxes we cant expect anything of this sort.
7) Why not the whole process tax-payer friendly?

I think even before expecting our governments to do something productive out of funds collected from taxes, we should ensure that they provide hassle free means to pay it.

Friday, July 21, 2006

getting bits

I just got an Airtel unlimited braodband connection. Though the stated bandwidht is around 256 kbps i am getting a good 200 kbps and 13-23 KBps download speed. But surprisingly when I try to use bittorrent bandwidth falls down to 100 odd. Airtel cutomer care representative simply gave me referece number for a complaint.

Please can someone share some gyan about why it happens so..

Thursday, July 20, 2006

is blog a page 3 on webspace

What is that Govt is concerned about and the huge uproar that blogging community started againt Govt ? Is it mere suspicion ? Something awry here. Typical tendency is - who cares about what I scribble here ? There are many blogs which post messages about last night movie or a photograph of a party. They are more like personalised page3 of daily print media. And ofcourse typically that is the impression blogging held so far.

Government's order to block blogspot and other sites triggered some adverse views. Its unfortunate but heat of the moment played role there. This incident exposed bloggers across geographical sections of this nation. Well I could never ever convince anybody what I get by scribbling rubbish that goes in my mind onto a webspace. However it might be, so far it didn't harm anyone so I guess there is nothing wrong here...

Back

Its exactly three months since I last visited my lj space. For some reason writing rate is ramping down. So I just thought of taking up it agian before I complete loose interest in it.
Actually one of the reasons is time and content. I do update my desklog regularly. But that is internal to office. I am using logahead for that on apache web server. So I have one or other thing to put on every week or so. Similary I scribble about some tech bits on sriharshavardhan.blogspot.com. As such I am not hitting keys explicitly.

Here goes another attempt to restart... Probable reason being, now i can insert images here...

Monday, July 03, 2006

Maximum threads per process – where is the bottleneck??

Recently I was doing an OPC compliance test on one of the IO severs that we developed.
There is a tool for this compliance test from OPCFoundation.org. By default tool tries to test using 10 servers, 10 groups per server and 10 items per group kind of configuration.

But the test case asked for compliance with 100 servers each with 10 groups or 10 servers each with 100 groups. Though the first case doesn’t appeal much, second case definitely does. But this IO server failed to cope up with that kind of load and started crashing after adding around 70 odd servers. Kind soul who logged the bug actually gave me all scripts so that I could recreate the condition at ease.

Suggestions came from many circles to check for resource usage. Isn’t that obvious!!!
A process which is so excessively hungry dies while eating itself. So the idea led to capture memory and thread consumption. All that I could observe is 1980 odd threads and sad demise. So it was not difficult guess to think of magical limit of 2048 as limit on number of threads per process.

Now I started hitting google to substantiate the limit I observed. Google gave me a page from Microsoft site. So here is what Microsoft got to explain about the limit.

Windows operating System allocates one mega bytes of memory as default stack size per thread. So in this case 2048 threads swallowed 2 Gigabytes of memory. Unfortunately that is the limit on user space virtual memory allocation per process. As 4 GB is max per process 2GB goes on user side and remaining 2 GB goes to kernel side.

Isn’t an MB of memory per thread too much!!!!!!

Posix threads can address this situation with stacksize member of pthread_attr_t. But there is catch here too, if you don’t specify this parameter, pthread library tries to assign it with operating system’s default. And Another member of pthread_attr_t is guardsize which has a default value of size of a page (4KB).