Sunday, July 12, 2009

He is unstoppable!!!

Office 2010 - checkout this video, this is really funny. Brilliant!!!

Saturday, July 04, 2009

WCF Sessions

In WCF, sessions are seen as group of ordered conversation in oppose to object centric behavior in ASP.NET. If the messages are exchange with same contract and contract specifies the session, a session is established for these messages. Following are the major differences between asp.net session and WCF session.

ASP.NET

WCF

Session is initiated by the server.

Session is initiated and terminated by the client.

Ordered processing (Messages are processed in sequence).

Unordered Processing

Provides general data storing mechanism

No such mechanism


In simplest form, we can specify session in following way:

[ServiceContract(SessionMode.SessionModeRequired)]

Public interface ICalculator { …}


WCF session has resemblance with local object. So by default, all subsequent requests are handled by same service instance.

Initiating operations are like constructors and Terminating operations are like destructors and requests between these two are like operation called on object.

[ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples", SessionMode=SessionMode.Required)]

public interface ICalculatorSession

{

    [OperationContract(IsOneWay=true, IsInitiating=true, IsTerminating=false)]

    void Clear();

    [OperationContract(IsOneWay = true, IsInitiating = false, IsTerminating = false)]

    void AddTo(double n);

    [OperationContract(IsOneWay = true, IsInitiating = false, IsTerminating = false)]

    void SubtractFrom(double n);

    [OperationContract(IsOneWay = true, IsInitiating = false, IsTerminating = false)]

    void MultiplyBy(double n);

    [OperationContract(IsOneWay = true, IsInitiating = false, IsTerminating = false)]

    void DivideBy(double n);

    [OperationContract(IsInitiating = false, IsTerminating = true)]

    double Equals();

}


For detail: WCF Sessions.


Monday, June 08, 2009

C# 4.0 – the features I like most.

C# 4.0 is coming up with following new features as of its documentation on MSDN now:

  1. Dynamic lookup (You don't need to worry about type of target; Runtime figures out what exactly the operation means to the object)
  2. Runtime lookup (Operation is dispatched through reflection at runtime)
  3. Named and Optional Parameters (default values can be set to function argurments)
  4. New features in COM Interop – Compiling without PIAs, Omitting Refs, Dynamic Import
  5. Variance (Automatic assignments where it is safe in case of Generics)
  6. Covariance (The new IEnumerable and IEnumerator interfaces, now sequence of strings is also sequence of objects; very useful in Linq queries)
  7. Contravriance (Type parameters can be declared as "in" in Generics; IComparer<object> can be used where we are expecting IComparer<string>)

Though I have been using dynamic languages like python and perl, I really need to explore features of Dynamic lookup. As of developer of so many APIs, I can say that Named and Optional Parameter feature is really cool. It will provides enormous flexibility to API developers as well as API users. Last one is Compiling without PIAs. The developers who have worked on PIA can only know how useful this feature is. It gives big relief from versioning and loading large assemblies.

Wednesday, May 27, 2009

Regular Expression - using back reference in javascript

Following code snippet shows how can we use back reference to remove duplicate word from string.

var test = "personal personal computers and super computers computers";
test = test.replace(/(\w+)\s+\1/g,"$1");
alert(test);

Thanks to Cracki for pointing out difference between back reference and back tracking.

Friday, March 27, 2009

Sixth sense technology

Checkout this link. This is amazing.

Technology Breakthrough by an Indian !!!!

http://www.ted.com/index.php/talks/pattie_maes_demos_the_sixth_sense.html

Friday, March 20, 2009

.NET String comparison benchmarking

I was just going through http://msdn.microsoft.com/en-us/library/ms973919.aspx on string comparison. My finding is little different. If you are comparing strings with the combination of Equals() and ToUpper(), it is much faster than the Equals() and Enum StringComparison. I have profiled the code using Ants profiler and below is the screenshot.

Sunday, March 15, 2009

Regular Expression Cookbook


I have been waiting for this Regex cookbook for long time. I will make sure that I am the first person to get this book from store as soon as it is available.
http://www.amazon.com/gp/product/0596520689?ie=UTF8&tag=slfb-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=0596520689

Thursday, March 05, 2009

IE 8 - New Ajax and DOM storage Features

Following are few new cool features in IE8:

  1. New Ajax Navigation
  2. DOM storage upto 10 MB
  3. Online/Offline detection in Javascript
  4. XmlHttpRequest Timeout
Check out this url for detail:
http://msdn.microsoft.com/en-us/magazine/dd458804.aspx#id0100180

Wednesday, March 04, 2009

Perl - Find and replace without Regex

Perl doesn't have built-in string replace function as we have in C# but using \Q operator you can achieve same effect.



my $pattern = '[lerp]+';
my $target = 'this is [lerp]+ perl';
(
my $output1 = $target) =~ s/${pattern}//g;
(
my $output2 = $target) =~ s/\Q${pattern}//g;
print $output1 , "\n";
print $output2 , "\n";




Ouput:
this is []+
this is perl

Becoming a great writer !!!

There was once a young man who, in his youth, professed a desire to become a "great" writer.

When asked to define "great" he said "I want to write stuff that the whole world will read, stuff that people will react to on a truly emotional level, stuff that will make them scream, cry, wail, howl in pain, desperation, and anger!"

He now works for Microsoft writing error messages.

Friday, January 09, 2009

Some common regexs

set COMMENT {/\*[^*]*\*+([^/*][^*]*\*+)*/} # regex to match a comment
set COMMENT2 "//\[^\n]*" # regex to match a C++// comment
set DOUBLE {"(\\.|[^"\\])*"} # regex to match doublequoted string
set SINGLE {'(\\.|[^'\\])*'} # regex to match singlequoted constant