Wednesday, November 10, 2010

Blogs Moved!!!!!!!!!

Blogs have been moved to here

No specific reasons though :)

Sunday, October 24, 2010

C# google image search

Need not much of an explanation I guess.
The title has it all....
....a C# API for searching images from google.
Works on Regex for matching the image URL from the HTML returned for the image tag search.This might stop working anytime google changes the formatting.
Even the current regex is not returning all the images from a page.Working on that though..would be fixed in the next release*.
I started this to try the AsynEnumerator from PowerThreading Library by Wintellect.
I guess i've not understood it fully and there is an overuse of it in this version..that too would be looked into the next release*.


Download VS2010 source code (rename to .rar)
Download VS2008 source code (rename to .rar)

*Conditions Apply: might be there :)

Wednesday, September 1, 2010

Callbacks in WCF

Quite often in the client-server model,the requirement of getting notified of certain changes in the server pops up.Say for example in the movie ticket booking system.When a person selects a seat for booking,the selected seat should become disabled for all the users currently logged in,so that you can avoid the message 'Sorry the seat you were trying to book is already booked'.
In such scenarios polling the server for changes might be one way to go about it.
Another way might be the server calling back to all the clients when a seat selection happens.
This post is about the second way and when the booking system is developed using WCF :)
The WCF framework provides a easy way to achieve this.....Callbacks

The whole concept is simple.The server keeps track of all the active clients and knows how to call them when the required change happens in the server.
Again its all about certain interfaces that you have implement and some attributes that you have to specify.
The ServiceContract that the client exposes also specifies the CallbackContract type.This is again another interface that the client needs to implement so that the server knows the type of client it is serving and can call back the functions on that interface.
This is much more like the eventing model.All functions in the CallbackContract would be like your event handlers,which would be invoked by the server on a particular event happening in the server.
You can go ahead and create a Publisher-Subscriber framework itself so that any future requirements of such nature would be easy to implement
This article by Juval Lowy suggest a good way to implement a publisher-subscriber framework in WCF using callbacks.

The code provided below shows a quick example of Callbacks.Run minimum of two clients,so you get to understand what it is all about :)

Code Download

Wednesday, August 25, 2010

Replace 'Introduce Local Extension' With 'Extension Methods'

Introduce Foreign Method(IFM) and Introduce Local Extension(ILE) are two refactoring techniques that comes handy when you need to add functionality to an exisiting class,source code of which is beyond your control.
IFM is used when its just one or two functions that you need to add to the class.When the number of functions,that are to be added are more,then ILE is used.Not a rule though :)
But now with Extension Methods the whole process is much more simpler.
You need not do the subclassing or wrapper technique of ILE.
This can be a third way of implementing ILE :).Thanks to the framework team for keeping it simple.
The same date example using the 'Extension Methods' way of refactoring
  public static class MyExtensionMethods
{
public static DateTime NextDay(this DateTime date)
{
return new DateTime(date.Year, date.Month, date.Day+1);
}
}
The function NextDay is now available on any DateTime object,just as if you have written if you had access to the source code. It's the usage of ILE and IFM that has paved way for the inclusion of Extension Methods in the framework I guess.Thanks to Fowler for that.

Monday, August 23, 2010

TDD and Refactoring

Over the days I have been reading on Test Driven Development(TDD) and it seems really interesting methodology to go with as per development is concerned.
Basic of TDD is that the development process relies on 'tests', that are written prior to code.
Sounds astonishing!!!!
It might to someone into the normal development mode,where tests are usually written after code, so as to match the code that is written.
But TDD says just the opposite.
Code to make the tests pass...Just pass..Nothing more and Nothing less.
Thats where the catch is where most of we developers might find it difficult and needs getting used to.Not getting more into it as I would not be the best to comment on it :)
So whats refactoring got to do here.
Refactoring plays an integral part of TDD,so that the code is elegant and conveys just what it needs to,avoiding duplication.
The TDD approach also assists in refactoring as you have tests readily available to assure that the functional behaviour is not affected while changing the code design.You are just click of a button away if you are having a automated test scripts (like nUnit) in veryfying refactoring.
So both TDD and Refactoring goes hand in hand and helps in greatly improving the overall code quality.
There are quite a lot resources out there on these.
The best for refactoring would be of Fowler's.
For TDD this would be a good start and also the one by Kent Beck

Friday, August 13, 2010

Mission ASP.net

Its been high time I have been into windows developing..wpf mostly..I think its long enough to get a taste of the web too..thats whats hot and cooking...i guess..coz everyone is asking that.So I think I should take the plunge into it...the sooner the better.
Bluffing away @ interviews saying i have theoretical knowledge in jsp(was trained in Java quite a while ago) blah blah blah... doesn't seem to work I guess...they say why U when I have someone having work ex in ASP itself :)
Good Question!!!

So I am on this mission...to learn ASP.net..hopefully :)
edit:
Got hold of some books..let's see how it goes

Wednesday, July 7, 2010

Seek the problem, Not the Solution

It’s not uncommon to have problems in life, and so in the application/code that you write. I am not being too techie here.
It’s just I am relating my thoughts to something technical.
Being a software engineer, writing code is inevitable in my day-to-day life and so comes bugs :)
I spend a lot of time sitting on to solve bugs(of late it’s been eating away my head) and so do I see people around me, at my workplace, doing the same.

I always go in seek of the problem that caused the bug, rather than to find a solution for the bug.
Certain others go in seek of the solution for the bug, rather than the problem that caused the bug.
So am I not saying the same thing in two different ways….solving the bug!!!!
But they are not…at least for me :)

Seeking for the problem gives you the solution for the bug and also a better understanding of the code that you have written. You seek for the problem because you feel the mistake is at your part, maybe a implementation one or a logical one.
Seeking for the solution too solves the bug but does not give you a better understanding of that you have done. Mostly the solution might be a workaround to cover up some of your own mistakes, which went unnoticed, as you were too concerned of the solution for the bug and not the problem for the bug. This might really not solve the bug too, it might just be a temporary fix or a specific scenario fix.

This is just an example.
Same goes in the day to day life. Whenever you go in seek for solutions you are actually creating more problems for yourself.
Maybe a real life example(non technical :)) would do good.
Say you are a spendthrift and you keep spending away all what you get.
Need money urgently?? Solution is to borrow from your friend. Does it really solve the problem??
Nope !! The problem here is that you are spendthrift. So try to change that and not keep borrowing :).

Don’t be happy with the solution, hunt down the problem.
Happy hunting :)

Saturday, July 3, 2010

Hero or a Cheat????


Luis Suárez....that name would be said few more times, at least till Uruguay's fate is decided in FIFA WC 2010.
Early Saturday morning(IST),witnessed some dramatic moments of WC 2010.With the game about to be pushed into the shootout,which it did end up eventually,Ghana was to score a goal of substitute Dominic Adiyiah's header which was denied by Suárez with his 'hands'.The drama ended as Asamoah Gyan struck the crossbar for the penalty awarded and the match moved on to shootout,which saw Uruguay through to the best 4....shattering the African hopes.
Is he a Hero or a Cheat????
Wasn't it something anyone would have done?
Wasn't that a reaction rather than a response to a situation?
Ghana could have scored in the penalty awarded.But is just a penalty enough instead of a sure shot goal?

Would it be the next 'Hand Of God'??

Hero Or Cheat,fouls are committed knowingly and unknowingly in any game,as in football,as in this dramatic game.

So the play goes on says referee and so does Uruguay without him into the final 4

edit: Not too far says Netherlands,putting an end to the Uruguay's tale of WC 2010

Thursday, July 1, 2010

Synchronize SQL Server database objects


Updating an old database, with newly created/modified database objects(mostly stored procedures,views,functions and table value parameters), from a new database was a very common,tedious,error prone task that was performed at my workplace for the past few months.This came up with the client requesting to retain their existing data and just make updates to their old database from our development database(which of course is the new/latest one), whenever a deliverable was made.
When the very work I do is to automate peoples work,I felt perturbed seeing this being done manually.So decided on to automate it :)
Writing SQL scripts would be db expert way I guess.But I am no expert in that so decided to do it in my way.
The .Net way :)
Thanks to the whole concept of .Net and Microsoft for having exposed such complex functionalities in the most elegant way ..... SMO(SQL Server Management Objects).
You have to add a reference to Microsoft.SqlServer.Smo and a few other assemblies(Check the source code for more details).
Rest everything the API provides.

Code quality might not be that good.Just did it in an hour :)
A help is there within the app.

Thanks to .Net once more :)

Download the source code (rename to .rar)

Wednesday, June 30, 2010

Role Based Access Control

RBAC(Role Based Access Control) is something that is very common in the day-to-day world.
So what is this all about.It is just about a authorization check on whether you have the access to a particular resource or not.
When faced with scenarios like this when developing applications, where you have to implement Role based access for the different users that are to use the system you might be confused on how to implement this.
Say you have a WCF service exposing a set of services.You have a WPF thick client consuming this service.Say for example you are exposing a service to Add/Delete/View Employees.Based on the various roles you need to allow/disallow the access to the functionality.The easiest way would be enable/disable the controls that would be used invoke the corresponding functionality,based on the user role.
So am I done?
What if tomorrow you are exposing this service to some other client of yours,who is to develop his on User Interface(UI) for the service.
Do I have a problem here?
Yes of course!!!
What if he does not make the same check on the UI to enable/disable the controls that would act as his inputs.So here exactly is where you have a access break.Any user will be able to perform all functions irrespective of the access specified for him.
So how do I go about?
Make this check at the service level itself.Check for access and throw a NoAccess exception if not authorized.What exactly happens when you try to enter a no-access area in your office :)
UI synchronization is an added level to this,so that you can stop unnecessary service calls.

Will soon post a implementation sample :)

Wednesday, May 26, 2010

.....confused

Its been a long time since I have last blogged.Ask me for the reason,the only one I would have is 'no time'.
But is it the truth?
Not sure..but still I don't have one good reason.So then what I am writing about.Am I trying to discover it through writing....hopefully yes.
One thing is sure but, life for the past few months have been monotonous,which makes me repeat 'no time' again and again for many a things including blogging.
Office has been quite boring,tiring and a bit irritating for the last few months.Hey but IT was your favorite ,which made you choose Computer Science stream.
It still is.
Then what?Is it the environment?the nature of work?is it the people?... thats bugging you.
Won't this be the same anywhere you end up,after your 3 months notice period.Oh yeah I have put my papers,currently into the second month of notice period.So whats the big deal in all this switching if it would be back to square one in an alien place.
Am I saying don't switch your job.love the company.stay there as long as they don't push you out.
No.Never.
Then what.
Am I confusing you..Can't be sorry for that.

Already I am....


....Confused

Saturday, March 6, 2010

Not Able to "Start Debugging" in Visual Studio


Quite a few days back,I faced a peculiar problem :).Visual Studio was not having the green play button(the one for Start Debugging) enabled.No way was I able to start debugging.
Google gave many suggestions,none was of help.
I soon found out that,in Startup Projects(From the menu Project -> Properties),the option multiple was selected and all the projects were set to an action None)(Setting this to Start Without debugging also creates this same problem) :)

Yet to find out how this happened automatically but still setting up the startup project,made the green button glow :)

Be sure to check this the next time if the green button doesn't glow :)

Wednesday, January 27, 2010

The Building block

Since this comes under the 'WF' tag it would not be difficult for anyone to understand what I am talking about.
Yes its 'Activity'.
Activity is nothing but a piece of re-usable component performing a specified task.When I say re-usable it means across multiple workflows and thats where the catch is.Write Once ,Test Once and there you have something which works fine wherever put into.
WF ships with many activities,a list of which you will find here.The real power of WF is not in the out-of-the-box activities it ships with..it lies within you..Custom Activities.

My first question to such a statement would be,WHY?
WF is nothing but organizing activities in a logical manner addressing the requirement at stake.So the more of custom built activities you have the more easier and faster it is to address your needs.It all becomes the drag'n'drop funda microsoft boasts about and the reason why more developer turn towards it.The same reason why a GUI developer would go for a custom control rather than tweaking existing controls in every page he needs a similar look'n'feel.

Activities are of 2 type
1. Basic/Simple Activity
2. Composite Activity

Put everything in the code activity(the best example for a simple activity) and get done with the work assigned would be another approach amongst us.A definite YES keeping in mind the short term task at hand.But a big NO on the long run.
Code Activities ends within the current workflow.Re-usability across workflows is the key factor that is at stake in this approach,which should makes us think twice before using one.CodeActivities,mostly would be fully dependent on the instance properties of the workflow,which makes testing of something performed within the activity require the full workflow to be executed.
On the other hand a Custom Activity has its own properties on which it depends,can be tested individually and above all can be re-used across workflows.

So the next time you drag'n'drop a Code Activity from the toolbox think twice :)

Will catch you on developing a custom activity soon :)
CodeProject

Tuesday, January 26, 2010

A newbie to WF

With WPF(Windows Presentation Foundation), we saw the complete designer-developer separation,making it one of the best presentation technologies available at present.
Windows Workflow Foundation(WF) brings about the separation of the 'when-and-what',says Bruce Bukovics,author of Pro WF.You get to change the when without touching the what.All the business logic are packed into components,activities rather(in WF terms) and the control flow is between the activities is 'declaratively' controlled.Don't be surprised,its XAML again.

Though being newbie on WF,I got to take a session on WF,at my workplace, which made me dive little more deeper into it(so that I don't bluff my way through the 1 hour session :) ).All I could explore was the overview of the features,which seems promising and interesting.
This book I got hold of seems to clear the way ahead and make it easy.

More on WF soon :)

Saturday, January 16, 2010

the Nokia Monster


Of all the mobiles I have used till date this one goes top on my rating.With its elegant design,built quality and power packed features,the N95 8GB was worth every penny spent.8GB was not much of an attraction though, but definitely it being internal memory,boosted the performance.No longer I felt the time lag in apps opening,as in the previous models of Nokia.
Though its been a long time this big monster has been released it demands this piece of space here.
Not going into the specs of the phone,for there are sites which gives them in and out like this one here.
The 5 mega pixel camera is definitely a lookout feature,for you no more need a dedicated camera,if all you want is a snap of the moment.
The two way slide feature with dedicated music keys makes it to be on the race with pmp's out in the store,with the battery lasting pretty enough for an average music lover.
With the wide range of apps available for the symbian os , this definitely was the king of its times.....Nokia N95 8GB

edit:
here goes a list of must have apps in the n95

Monday, January 11, 2010

HP DV4



With all banks stopping on EMI(Equated Monthly Installment),with recession at its high,I was left with no choice for a long time,but to depend on internet cafe's,as my compaq V2624TU got some hardware problems and wouldn't start up.Blogging was on the verge of stopping.....thanks to my brother,Sagar,who turned my new banker for the brand new HP DV4.

Thanks a lot bro :)

Got to start saving though,for always bankers might not be there nor will EMI's(they really helped for my previous purchases).
Hoping to make it a resolution(you always want something's to be broken),for the year 2010.

Happy New Year :)