Wednesday, March 25, 2009

How to: Check login name availability in ASP.NET MVC using jQuery Validation plug-in



I need to write comments for the below code, bcoz of lack of time i am posting only abstract things,if you want to know something, write comment, i will reply.


HTML login control

< input type="text" name="txtUserName" id="txtUserName" class="textBoxes" />


jQuery Rule: Add the below rule into script tag in header & add reference to jquery-1.2.6.js,jquery.validate.js in Head Element

 
$(document).ready(function() {

         $("#frmSelfRegister").validate({
             rules: {
   txtUserName:
                     {
                         required: true,
                         remote: { type: "post", 
                                   url: "Register/IsLoginAvailable" }
                    },
    messages:{

txtUserName: { required: "User Name is Required.",
                                remote: jQuery.format("{0} is not available.")}
     }
   });
     });


The above validation code executed when the focus changes from txtUserName to some other, it will call IsLoginAvailable method available in the RegisterController, as specified in the url.




Controller Code :

Below code is the one which checks for availability of a username & returns the status to above jQuery Method. The following methods return type is JsonResult because remote method of jQuery accepts the JsonResult object only.

        
[AcceptVerbs(HttpVerbs.Post)]
        public JsonResult IsLoginAvailable(FormCollection collection)
            {
                JsonResult result = new JsonResult();

                try
                {
                       ilogIn.Text = this.GetLoginByUsername(collection.Get("txtUserName").ToString().Trim());
                       
                }
                catch (Exception ex)
                {
                    Helper.ErrLogger(ex.Message);
                }

                if (ilogIn.Text == collection.Get("txtUserName").ToString())
                {
                    result.Data = false;
                }
                else
                {
                    result.Data = true;
                    
                }
                return result;
            }

Interface Inheritance Naming Conflicts



Suppose you have two interfaces, lets say Interface-IA, Interface-IB & in both you have declared Name as a property as follows.

public interface IA
{

string Name { get; set; }
String Adress { get; set; }

}

public interface IB
{

string Name { get; set; }

}

Now, you write an interface -IC which derives from above 2 Interfaces as below,


public interface IC : IA, IB
{

int Id { get; set; }

}


When you are try to do the following, you will get an error saying 'Ambiguity between IA.Name and IB.Name'. 

class Test
{

    public void GetSomething()
     {
       IC objIc = new IC();
       Textbox1.Text =  objIc.Name();
     }

}

It can be solved by upcasting as below.

class Test
{

  public void GetSomething()
  {
      IC objIc = new IC();
      Textbox1.Text =  ((IA)objIc).Name();
  }

}

Monday, March 23, 2009

23 March 1931

Today would mark 78 years of the sacrifice three young men gave for the nation. Bhagat Singh- Raj Guru- Sukh Dev.

So today no one in news would talk about Bhagat Singh, Sukh Dev and Raj Guru the three young men who were hanged on this day near Ferozpur near the present India-Pakistan border. These men never cared about religion and fought for the freedom of the nation.

bhagat-singh-sukh-dev-raj-guru-20050323-091841

Indians seem to have forgotten the sacrifice and keep remembering Gandhi. It is definitely an unfortunate thing that people who were not in congress and worked for India's freedom never got the credit they deserve.Bhagat Singh, Sukhdev and Rajguru shall remain in my heart till I die. These are the people whom the young generation should have as idols. Their sacrifice, their patriotism & their principles, we should never forget them.


Fix Google Chrome (Crash) Error, The application failed to initialize properly (0xc00005)

I have Windows Machine with Symantec Anti Virus software,whenever I used to open Google Chrome,I used to get, "The application failed to initialize properly (0xc00005)" error.

After some exploration i found the way to bypass this error.

Here are the steps to follow to get rid of the error.

1. Close Chrome
2. Right click on the Chrome Shortcut and add "--no-sandbox" or "--in-process-plugins" switch as shown in the image below.

"--no-sandbox" switch instructs Chrome not to use Sanbox Security, Sanbox security mode prevents malware from getting installed into computer.

"--in-process-plugins" switch instructs Chrome to run the plug-ins inside the browser process itself. By default Chrome runs plug-ins in seperate process to avoid browser crashing when a plug-in crashes.

Hope it helps.

Saturday, March 21, 2009

Hunt for Indian Secret Societies

I am involved in finding the Indian Secret Societies. Recently I had a chat with one of my friend who is also invovled.Here is the chat transcript.

7:17 PM Rahul: Hello one questen
7:18 PM me: hi
  yeah tell me
7:19 PM Rahul: Like Priory of Sion is more famous for its members like Issac Newton have u ever heard ne prominent person of India of this team?/
7:21 PM me: u mean in the group of priory of sion?
 Rahul: yes
7:22 PM me: no
  i don't think any body has associated with it
7:23 PM Rahul: but it must be.....I mean more brillaint people are very obvius to be attracted to their philosophy
7:24 PM me: yeah, but religion was the main criteria, so people didn't associated with it
7:25 PM if u see the history of Priory, it started around 11th century
7:26 PM Rahul: it is more ancient than that isnt it??
 me: and that time, foreign invasion was happening in India
7:27 PM it might be ancient but existed in some other name
  so during crusades they might have changed the name
7:28 PM Rahul: may be the Manuscripts of their details have gone to the distant far off land like that of Illumiati and will resurface in some time
 me: u can recall that, Knights templar also came on the scene at that time
  
7:29 PM Rahul: that righ for their lives they went underground??
 me: yeah
  they operated under different names just to avoid the church
7:30 PM Rahul: u think National Library might help??
 me: u can say, they were diverting the attention
  our National Library?
  Raja Ram Mohan Roy library?
7:31 PM Rahul: In Kol
  here I've herd they contain manuscripts
  but one problem
 me: yeah
 Rahul: i dnt know where to look into
7:32 PM I mean there must be a key
  where the search should be starting from
7:33 PM me: hmm, one minute
7:34 PM sorry i was on call
  i believe old temples of India and their manuscripts might help
7:35 PM but we can't directly check those things bcoz of religious restrictions
 Rahul: how the hell Dan Brown gets all his info then??
 me: and also, there may be some traps, we dont know how to avoid those things
7:36 PM that info was available from other writers
  he just put it in a nice novel
 Rahul: but here s no clue
  they r just tremendous brillaint
  bt some thing tells me the path is alive
7:37 PM me: here the chances of finding clues is almost impossible, if u recall that, there was no book on veda & all things, all those things passed from Teacher to student verbally
7:38 PM so you can't expect the clues, as in Davinci Code
  or National Treasure
 Rahul: yeah thats why decrepency crreped in on regarding the description of Krishna ...........or Mahabharata
 me: s
7:39 PM but, the clues are there but they are distributed
7:40 PM Rahul: ok I think I need to think but something tells me I am not far from the key...................I will take some days now if I get hand on nething I ll make a contact ok?
 me: yeah
  sure i will be glad
 Rahul: Bye 4 now tk kr dude
 me: to get invlved
  sure, take care

Thursday, March 19, 2009

Logging Errors with NLog a .NET Logging Library

NLog is a .NET Logging Library, 

Official Site mentions it as follows,
NLog is a .NET logging library designed with simplicity and flexibility in mind. With NLog you can process diagnostic messages emitted from any .NET language, augment them with contextual information, format them according to your preference and send them to one or more targets.
Using it is very easy. Following steps helps you to get started.
(For Visual Studio 2008, Web Applications)
1. Download and install NLog Library
2. If you are using Visual Studio 2008, follow this step as mentioned in my earlier post, to fix issue with Intellisense.
3. Add reference to NLog.dll.
4. Add the following Entries to web.config


5. Add  following entries to your code behind file
(for C#)
using NLog;
using NLog.Targets;
using NLog.Config;
using NLog.Win32.Targets;

6.  Create a Logger object as below in your code behind file

catch(Exception ex)
{
    Logger errLogger = LogManager.GetLogger("*");
                    errLogger.Debug(ex.Message);
}


7. If you see, i have passed * as an argument to GetLogger method, please refer web.config entry, i have mentioned logger name as *.

8. This will log exceptions to  /Logs/Log.txt

If you encounter any problems then let me know.

How to : NLog Intellisense issues with Visual Studio 2005/2008

If NLog Intellisense is not working in Visual Studio then copy NLog.xsd into following location

Visual Studio 2008
C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas
Visual Studio 2005
C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas

Wednesday, March 18, 2009

Language Extinction

Today i came across this below image, i was aware that the languages are getting extinct but didn't know that India tops in that, may be its because of dependence on English as a Communicative language. Some how we need to protect our language heritage.

Thursday, March 12, 2009

I support Media Ombudsman

Why We(I) Support the BJP - Because India Deserves Better

Source : Friends Of BJP

We are some of us - young and professionals. Till some time ago, we assumed that our contribution to the 2009 elections and the future of India would be our one vote. But, somewhere along the line, things changed. Maybe it was 26/11 and seeing some of us out on the streets demanding action. Maybe it was seeing Obama become President, and see politics really change in America, bottom-up. Whatever it was, we have woken up to the fact that we have to do more - much more - if we are going to rewrite our future and rebuild our India into the glorious country that it once was.

We know we are on the wrong track when security warnings sent on September 24 for the event that happened on 26/11 are ignored and not acted on. We know we are on the wrong track when we cannot provide adequate electricity 24×7 in our homes and factories - and yet for the sake of votes our political parties offer free power to millions. We know we are on the wrong track when we have schemes like NREGS and bank loan write-offs which create wealth for the entire value chain - except for the one it is supposed to help. We know we are on the wrong track when we can barely add to the highways in five years. We know we are on the wrong track when a mother says that her biggest challenge of parenting is finding a good school for her daughter.

We are on the wrong track. And it is WE who put us there. By our apathy, by not voting, by accepting mediocrity, by not being part of the political process. The best we do is show up at candle-light vigils when we are shocked from our smugness, but don’t we need something more concrete and impactful?

We are India’s educated civil society. If we cannot act individually and as a team, then we forfeit the right to complain. Democracy comes with responsibilities and duties. It also comes with a generation having to make some sacrifices so the Tomorrow for our children can be better than our Today.

We have less than 90 days only to the elections. India has 2 national parties and a multitude of regional parties. We have to make a choice about the party at the Centre. We can wait for a utopian world and the creation of the Perfect Political Party. Or, we can pick the party with the lighter shades of grey.

A week ago, when some of us got together to talk about the elections and the future, we also made our choice. We decided to support the BJP - and work towards ensuring LK Advani becomes Prime Minister. The BJP may not be the Whitest of the parties, but in our view, it is by far, the better, cleaner, more democratic, less feudal and more promising of the two national options. More importantly, we also realised that in the 2009 Elections, the way things stand, unless the BJP gets 50-75 more seats on its own above the 130 it got in the 2004 elections, there is little hope of the BJP forming a government at the centre.

Thus was formed Friends of BJP. We are neither all signed-up members nor agree with everything and everybody in the party has always said. But we firmly believe that, in 2009, the BJP and LK Advani are the best hopes for India. We have a clear short-term goal, and a grander long-term vision for Friends of BJP.

The 90-day goal is to get BJP to 200+ seats - in the 15th Lok Sabha. This will mean a massive outreach programme through all means at our disposal to get the silent supporters to be more vocal, and the undecideds to be swung the BJP way. Bringing about a BJP government at the centre with Advani at the helm will then bring into focus the longer-term vision. That is about a government that is two-way, that listens to us, that we can feel a part of. Technologies like the Internet and mobile give us the tools to self-organise and make our voices heard. The India of 2009 is very different from that of 2004. The 2009 Elections will be the first where urban India can actually make a difference.

We have to become the Voice of India. For 60 years, we have been Led. And for many of those years, Led down a wrong path. The time has now come for us to Lead.

We Support the BJP. Because India Deserves Better.

Wednesday, March 11, 2009

Tips & Tricks to go Green

Tip 1# If you plug your Computer,TV, converter box, DVD player and surround sound stereo system into a power strip, you can eliminate the "phantom" loads they may draw when they appear to be off but are still consuming electricity in standby mode.

Tip 2# Use kitchen towels and cloth napkins instead of paper products. Stop using plastic straws, you know how to drink out of a cup?! Avoid buying/taking plastic utensils. If you must, bring home, wash, and reuse. Most can be washed in dishwasher.

Tip 3# Keep plants around the house.

Tip 4# Don't use cloth dryers, instead, dry your clothes to the sun.

Tip 5# Eat less meat. Cutting red meat and dairy consumption once a week reduces green house gas emissions equivalent to driving a 25 miles/gallon vehicle 1160 miles/yr (1860 km/yr). Cutting consumption altogether is equivalent to 8100 mi/yr (13000 km/yr).

Tip 6# Use LCD monitors instead of CRT,LCD monitors use less electricity and generates less heat than CRT monitors.

Submit your Tips, i will post them here.

Tuesday, March 10, 2009

Quote of the day

 ”If you must choose between two evils, pick the one you’ve never tried before.”

Monday, March 09, 2009

How to : Creat an empty Solution in Visual Studio 2008

1. Open Visual Studio
2. Go to Tools > Options
3. Check Show all setting check box
4. Select Projects and Solutions from the tree
5. Check "Always Show solution" checkbox

6. Click Ok
7. Now Select Create New Project
8. From tree List select Other Project Types
9. Then Visual Studi Soultions, You will see Blank Solution in Templates section.



Wednesday, March 04, 2009

Interviewing a Software Engineer

Imagine the following interview with two interviewees, “Player A” and “Player B”:

Interviewer: “Okay, sir. Let’s say a ball is hit a little bit to your left. How do you field it?”

Player A: “Well, I’d take a few steps to the left and try to get my body in front of the ball. I’d use my left-hand to field the ball, switch the ball over to my right hand, and throw it to first.”

Player B: “I’d take a few steps to the left, keeping my body bent at the knees and the back so I could respond to any strange hops the ball might take. If I can get completely in front of the ball, comfortably, I will, but I might have to field it with one hand to the left of my body, if I can’t get my body in front of it. Depending on the direction I’m moving, the time it took me to get to the ball, and whether I got completely in front of it or not, I might have to throw it on the run.”

Based upon the two player’s answers to this question, Player B gets hired.

This might seem like the right call. The problem is that Player B is a recent college grad that majored in English and played intramural ball. Player A is Derek Jeter (Yankees shortstop) before he was really known as the Derek Jeter.

What if you were the interviewer and you had made this decision? You would’ve just altered the entire course of your team. There’s a good chance that from this decision forward you’d be losing a lot of games to the team that hired the person you let pass by.

The above scenario is analogous to the sad state of interviewing in the software industry. Interviewers ask inane questions that don’t have anything to do with whether the interviewee is a good software engineer. I’m not against a company asking basic questions in an attempt to weed out people that don’t have any idea at all about building software, but I am against getting through that process and then being asked similar questions in the next stage of the interview process. That’s almost always the way it goes, right?

One problem that arises when trying to solve this dilemma is that the software world is littered with posers[1] that don’t have any idea how to build software, and then these people are asked to interview people. It’s not even their fault in some cosmic sort of way: they are asked by management to interview the prospective employees. Uninformed managers asking unskillful developers to do such important activities is not a good way for an organization to operate. Since ignorance is bliss, though, these people have no idea what’s going on. Is it really their fault?

If you’re serious about hiring a good software engineer there is only one, effective way to hire serious candidates:

  1. Conduct a screen interview that weeds out any people that truly don’t belong. In this interview ask relatively basic questions about constructing software. By “relatively basic” I don’t mean totally simple questions; I mean questions that aren’t based on some obscure piece of information you read in the latest technology magazine you subscribe to. Ask questions such as “What is an interface?” or “What problems do you associate with using the ‘static’ keyword?” or “What can you tell me about responsibilities within a software system.” Don’t ask questions such as “How does the compiler optimize a for loop?” Such questions have no relevance toward the creation of software unless you are building software that optimizes for loops. Questions such as this are only asked when the interviewer wants to consciously or unconsciously appear “smart.”[2] There is no time for such silliness if you’re a serious person—and there is certainly no value in such questions for the organization you represent. If your company builds software there are not many more important decisions than hiring good software engineers, so get serious about it or get flattened by the competition. Someone out there is doing things right and they will annihilate you if you don’t clean up your mess.
  2. This is the most important step: sit down with the person you are hiring and develop something together. It doesn’t matter what it is. The goal is to get a feel for what the person is capable of when actually developing software and to see if the candidate can fit somewhere in your team. Before a sports team signs a player to a contract the team watches him play. The team doesn’t talk to the player about playing.[3] It shouldn’t be much different in the software world. Sit down and develop something together. The candidate doesn’t have to do things exactly like you or your organization. For example, if you’re a TDD shop like we are you don’t have to make sure the interviewee fully understands TDD; all you have to do is to see if writing software with her feels right. There isn’t even a perfect definition of “feels right.” It’s all up to you. In the case of TDD you’ll more than likely force the coding to follow TDD principles whether the candidate has ever done TDD or not. Going through this process will uncover a lot about the potential hire: What kinds of questions does she ask? What are her thoughts regarding TDD? Does she really seem willing and able? More answers than you have questions for will come to the forefront. Having answers surface to unasked questions is always a good thing in an interview, and the nuances of a person’s personality will flow through when you work together. You’ll be amazed at what you learn if you learn to pay attention.

If you’re not serious about hiring a good software engineer then you’re a poser. May as well make it easy and flip a coin.

Post Mortem:

In the end, it really doesn’t matter what you do. The outcome of whatever interview process you choose will be directly proportional to how much the interviewee’s abilities reflect your own. If you only ask the candidate questions, the questions you ask will be based upon your skill and experience in the software world--and the answers you seek will reflect your own answers.[4] If you’re not very good you’ll more than likely hire someone that isn’t very good, regardless of what you ask or do. If you do sit down and develop a piece of software with the candidate, you will develop it according to your ability and look for traits in the candidate that match your own traits. But, at least in the case of writing code together, you will get a much, much more accurate assessment of the interviewee than you will get by asking questions. An overriding reason for this is because coding together is a dynamic, exponentially greater reciprocal relationship than asking questions is. Asking questions generally flows in one direction—from the asker to the answerer—instead of equally in both directions.

In the case of an interview, bidirectional transport wins.



[1] A poser is a faker, but worse. A poser is a faker, only a poser doesn’t understand they are faking. Such people are incredibly annoying and boring. In this way one could say that Poser derives from Faker. I’d probably prefer to have Poser implement IFaker, but that is an argument for another day.

[2] Knowing an answer to this kind of question has nothing to do with being smart. There is a lot more to being smart than keeping extraneous information in one’s head. Intelligence has much more to do with how one associates information with other information, not how one collects it.

[3] A team may talk to a potential player about playing, to get a feel about their attitude and personality, but this is a fraction as important as how the player plays the game. Occasionally a team will let a good player pass by, but only if the player has enough personality baggage that it would get in the way of their playing upside.

[4] It is possible that you are very intelligent and very wise, but inexperienced. If so, you will ask questions and look for answers you currently believe are correct, but you might interview a candidate that is just as intelligent as you but much more experienced. In this case--if you are very wise--you would be prepared for and open to the possibility the candidate is actually better at developing software than you. You would hire him or her on the spot. Many people do not set aside their ego well enough to reach this level of maturity.

Source: http://www.thoughtshapes.com/node/67