Sep 7, 2007

The Eleven Rules of Life - not by Bill Gates!

A list of eleven things you did not learn in school, directed at high school and college grads:
(An excerpt from the book "Dumbing Down our Kids" by educator Charles Sykes)

Life is not fair - get used to it.

The world won't care about your self-esteem. The world
will expect you to accomplish something BEFORE you feel
good about yourself.

You will NOT make 40 thousand dollars a year right out
of high school. You won't be a vice president with
car phone, until you earn both.

If you think your teacher is tough, wait till you get a
boss. He doesn't have tenure.

Flipping burgers is not beneath your dignity. Your
grandparents had a different word for burger flipping
they called it Opportunity.

If you mess up, it's not your parents' fault, so don't
whine about your mistakes, learn from them.

Before you were born, your parents weren't as boring as
they are now. They got that way from paying your bills,
cleaning your clothes and listening to you talk about
how cool you are. So before you save the rain forest
from the parasites of your parent's generation, try
delousing the closet in your own room.

Your school may have done away with winners and losers,
but life has not. In some schools they have abolished
failing grades and they'll give you as many times as
you want to get the right answer. This doesn't bear the
slightest resemblance to ANYTHING in real life.

Life is not divided into semesters. You don't get
summers off and very few employers are interested in
helping you find yourself. Do that on your own time.

Television is NOT real life. In real life people
actually have to leave the coffee shop and go to jobs.

Be nice to nerds. Chances are you'll end up working for

Aug 11, 2007

Faster .Net applications startup - Tips and Tricks

There is this dim end user expectation, which says: "I want to launch my application and see its first user interface as soon as I double click on its icon in my Windows system".

For Native Win32 GUI applications, this is the way it has been for many years (except for very large applications that need to load hundreds of libraries...), but for .Net forms, this might be a developer's nightmare.

You design your Form, add some controls to it. Then run the application. Well, you become disappointed when you see that even on fastest machines the whole process of controls painting themselves into view is visible to the user's eyes with flickers. This is a certain drawback for your application. It makes you and the end user to think that .Net GUI applications are just bloated, heavy and useless.

Good news is that it is not like that at all. There are certain tricks in any development environment and language that improves application performance by orders of magnitude.

For me, I have used 3 simple tricks to get that speed:

1- Use Delayed Initialization:

You want your managed application to come into view just as fast as a native application does. But it is not like that in most managed cases. Although for an empty form in most cases "it is". So, what I do is to avoid the CPU and RAM overhead caused by initialization of controls at the start-up time for my application.

By default, Visual Studio inserts the "InitializeComponent();" call in the constructor for each form. If your form is going to be the start-up form (Main Form), this method will really have an impact on its display delay.

As a matter of fact, we can remove this call and insert it somewhere so that the main form wont delay its display because of this method call. I have done this in "Application.Idle" event.

So, instead of this code:
public Form1()

I use this code for faster start up:

public Form1()
/* Preventing a very ugly fact of Managed applications, and that is
avoiding the user from seeing the controls (TextBox, Labels,...) painting themselves and their backgrounds when we run applications:

this.Text = "Initializing...";

this.Size = new Size(687, 406); /* We do this to avoid form's resizing upon its initialization. */

Application.Idle += new EventHandler(Application_Idle);

bool isInitilized = false;
void Application_Idle(object sender, EventArgs e)
if (isInitilized)
/* Even avoiding this method call in the application start up will be great! */

// Now is the time to initialize all components.


// Avoid re-initialization:

isInitilized = true;

This simple trick will really boost the start-up time and display of your application even in cold start up scenarios. It might not always work, but in most cases it is just a matter of cutting and pasting some start up codes.

2- Use Ngen.exe

This is going to really help. I try to use it in most of my release assemblies and combined with tip #1, it makes your application to perform almost like its native equivalents.

3- Use a splash screen:

Finally, if your application is so heavy and bloated that you cannot avoid displaying its first form without performing heavy disk, network, or databases I/O operations, then try using a very lightweight splash form generated from a separate thread.

Do never forget that the main idea of how your application performs lies in the way your main first forms show up on the screen after a user execution of your software. For many, just a fast start-up application means a fast application overall, like .

Hope this article has helped you a little in your .Net application development.

Download sample assemblies...

Jul 11, 2007

Why Firefox is the best browser?

Firefox browser from Mozilla organization has been out for about four years and till now many have downloaded and used it and actually loved it. I remember the time first i read about Firefox, and the first thing i said was "come on! it is just another Opera!". However news and ads all talked about a new open source browser that could just put people away from the insecure IE for a while. Finally i downloaded Firefox ver. 1.1 and loved it. Wow! what a speed! The time that took IE to load a web page Firefox would load 3-4 pages and under the same connection speed. And you know, i never went back to IE again. It is four years i am using Firefox and i just can't think of web without it.

Let see what things we have in Firefox that we miss in IE 6.0:

1- Tabbed Browsing:

Are you just crazy about those many IE windows that have just opened and messed up your taskbar? Then you really miss tabbed browsing.
In Firefox, you can open each link in a new tab and all tabs work under the same browser window. You can organize tabs, rearrange them and just close them if you want.

2 - Find & Replace is so cool:

The new find and replace just at the bottom of your browser window will be the greatest tool you might need while browsing pages with so many sub items and text. Just like Google tool-bar, you can type and as you type Firefox highlights matching text in your browser.

3- Zoom in/Out

You can now easily zoom in/out and increase the text size by simply using Ctrl++ or Ctrl-- on a web page:

4- Session Management:

A big addition to a browser and you all miss this in IE. Session manager simply saves the state of the open tabs, their URL s and the cursor position in each page. Shocked with a power outrage? Computer shutdown? or anything else that has just crashed your browser? No need to worry! The next time you launch Firefox, you will be able to restore your previous crashed session and navigate to the place you were browsing before the crash happened.
You can also manually save sessions and later open them in your browser.

5- Auto update:

I know. IE just look and works the same even after 7 years since it was first released on Windows XP! And you are just tired of it.
Remember, Firefox is an open source browser and it is secure because all new flaws and bugs are fixed in less than a weak and is updated frequently.

The browser has a self-update feature that looks like this :

6- Add-on manager:

Yes, you have it in IE, but Firefox is just different. You can add "add-ons" to this browser from an online resource of more than 2000 items. And they are easily downloaded, installed and automatically updated from within the browser. Besides, if you don't like an add-on, you can easily disable or uninstall it from the inside of the add-ons manager.

7- Themes!

Want to add a new look and feel to your Firefox? Want your browser look like IE 7? Just download from an online resource of more than 1000 themes and change the entire look of your browser within seconds!

8- Tab mix plus ( a powerfully add-on):

Firefox has built in support for tabbed browsing. However, if you are not content with the default tab handling, you can download Tab mix plus and let this powerful extension handle everything in your browser.

Tab Mix Plus has support for session handling too and you can choose among many of its features just for free.

9- Built-in RSS support

We know that we miss this in IE. With Firefox built in RSS support, you can just subscribe to an atom feed and have updated bookmarks in your browser second by second.

10- Security:

I don't want to talk a lot about it. However, Firefox is a winner here. Unlike IE, Firefox is not integrated with your operating system, which means harmful add-ons cannot do anything to your operating system or do harmful I/O disk operations. We see also some phishing support and the ability of browser in handling your login information with an acceptable level of security.

11- Privacy protection:

This one is just the feature i really like and use a lot. You have visited just those private websites today, and don't want anyone else know about it? Well, if you have done it with IE, then you cannot do anything about it. Deleting history and Files and cookies wont do so much. Others can just find out a cash of your website on your hard disk easily!

Firefox has a new approach to this. The "Clear Private Data" section will shred just all those bad pieces of data you want to lose, simply by click of a button:

12- Clipmarks integration:

Clipmarks is a new evolution in web clipping. And with Firefox you will really enjoy its integration because of the speed and flexibility of this extension.

You can simply select sections of web pages you like, they are marked with a green rectangle on them as clipped.

And then you can save, blog or email the web parts you have selected very easily:

Just clicking the "Post to Blog" will do all the thing you would need for blogging. This really saves you time and money and is a big challenge for other browsers.

And Firefox is not just what i said here. You have to discover it yourself and feel how the web looks different with this great open-source browser from

Jul 6, 2007


clipped from

AJAX:Getting Started

From MDC

This article guides you through the AJAX basics and gives you two simple hands-on examples to get you started.



[edit] What's AJAX?

Ajax stands for Asynchronous JavaScript and XML. In a nutshell, it is the use of the nonstandard XMLHttpRequest object to communicate with server-side scripts. It can send as well as receive information in a variety of formats, including XML, HTML, and even text files. Ajax's most appealing characteristic, however, is its "asynchronous" nature, which means it can do all of this without having to refresh the page. This allows you to update portions of a page based upon user events.

The two features in question are that you can:

  • Make requests to the server without reloading the page
  • Parse and work with XML documents

[edit] Step 1 – say "Please!" or How to Make an HTTP Request

In order to make an HTTP request to the server using JavaScript, you need an instance of a class that provides this functionality. Such a class was originally introduced in Internet Explorer as an ActiveX object, called XMLHTTP. Then Mozilla, Safari and other browsers followed, implementing an XMLHttpRequest class that supports the methods and properties of Microsoft's original ActiveX object.

As a result, in order to create a cross-browser instance (object) of the required class, you can do:

var httpRequest; if (window.XMLHttpRequest) { // Mozilla, Safari, ...     httpRequest = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE     httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } 

(For illustration purposes, the above is a bit simplified version of the code to be used for creating an XMLHTTP instance. For a more real-life example, see step 3 of this article.)

Some versions of some Mozilla browsers won't work properly if the response from the server doesn't have an XML mime-type header. To satisfy this, you can use an extra method call to override the header sent by the server, just in case it's not text/xml.

httpRequest = new XMLHttpRequest(); httpRequest.overrideMimeType('text/xml'); 

Next, you need to decide what you want to do after you receive the server response to your request. At this stage, you just need to tell the HTTP request object which JavaScript function will do the work of processing the response. This is done by setting the onreadystatechange property of the object to the name of the JavaScript function you plan to use, like this:

httpRequest.onreadystatechange = nameOfTheFunction;

Note that there are no brackets after the function name and no parameters passed, because you're simply assigning a reference to the function, rather than actually calling it. Also, instead of giving a function name, you can use the JavaScript technique of defining functions on the fly (called "anonymous function") and define the actions that will process the response right away, like this:

httpRequest.onreadystatechange = function(){     // do the thing }; 

Next, after you've declared what will happen as soon as you receive the response, you need to actually make the request. You need to call the open() and send() methods of the HTTP request class, like this:'GET', '', true); httpRequest.send(null); 
  • The first parameter of the call to open() is the HTTP request method – GET, POST, HEAD or any other method you want to use and that is supported by your server. Keep the method capitalized as per the HTTP standard; otherwise some browsers (like Firefox) might not process the request. For more information on the possible HTTP request methods you can check the W3C specs
  • The second parameter is the URL of the page you're requesting. As a security feature, you cannot call pages on 3rd-party domains. Be sure to use the exact domain name on all of your pages or you will get a 'permission denied' error when you call open(). A common pitfall is accessing your site by domain.tld, but attempting to call pages with www.domain.tld.
  • The third parameter sets whether the request is asynchronous. If TRUE, the execution of the JavaScript function will continue while the response of the server has not yet arrived. This is the A in AJAX.

The parameter to the send() method can be any data you want to send to the server if POST-ing the request. The data should be in the form of a query string, like:


Note that if you want to POST data, you have to change the MIME type of the request using the following line:

httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 

Otherwise, the server will discard the POSTed data.

[edit] Step 2 – "There you go!" or Handling the Server Response

Remember that when you were sending the request, you provided the name of a JavaScript function that is designed to handle the response.

httpRequest.onreadystatechange = nameOfTheFunction; 

Let's see what this function should do. First, the function needs to check for the state of the request. If the state has the value of 4, that means that the full server response is received and it's OK for you to continue processing it.

if (httpRequest.readyState == 4) {     // everything is good, the response is received } else {     // still not ready } 

The full list of the readyState values is as follows:

  • 0 (uninitialized)
  • 1 (loading)
  • 2 (loaded)
  • 3 (interactive)
  • 4 (complete)


The next thing to check is the status code of the HTTP server response. All the possible codes are listed on the W3C site. For our purposes we are only interested in 200 OK response.

if (httpRequest.status == 200) {     // perfect! } else {     // there was a problem with the request,     // for example the response may be a 404 (Not Found)     // or 500 (Internal Server Error) response codes } 

Now after you've checked the state of the request and the HTTP status code of the response, it's up to you to do whatever you want with the data the server has sent to you. You have two options to access that data:

  • httpRequest.responseText – will return the server response as a string of text
  • httpRequest.responseXML – will return the response as an XMLDocument object you can traverse using the JavaScript DOM functions

[edit] Step 3 – "All together now!" - A Simple Example

Let's put it all together and do a simple HTTP request. Our JavaScript will request an HTML document, test.html, which contains the text "I'm a test." and then we'll alert() the contents of the test.html file.

<script type="text/javascript" language="javascript">     function makeRequest(url) {         var httpRequest;          if (window.XMLHttpRequest) { // Mozilla, Safari, ...             httpRequest = new XMLHttpRequest();             if (httpRequest.overrideMimeType) {                 httpRequest.overrideMimeType('text/xml');                 // See note below about this line             }         }          else if (window.ActiveXObject) { // IE             try {                 httpRequest = new ActiveXObject("Msxml2.XMLHTTP");                 }                  catch (e) {                            try {                                 httpRequest = new ActiveXObject("Microsoft.XMLHTTP");                                }                               catch (e) {}                           }                                        }          if (!httpRequest) {             alert('Giving up :( Cannot create an XMLHTTP instance');             return false;         }         httpRequest.onreadystatechange = function() { alertContents(httpRequest); };'GET', url, true);         httpRequest.send('');      }      function alertContents(httpRequest) {          if (httpRequest.readyState == 4) {             if (httpRequest.status == 200) {                 alert(httpRequest.responseText);             } else {                 alert('There was a problem with the request.');             }         }      } </script> <span     style="cursor: pointer; text-decoration: underline"     onclick="makeRequest('test.html')">         Make a request </span> 

In this example:

  • The user clicks the link "Make a request" in the browser;
  • This calls the makeRequest() function with a parameter – the name test.html of an HTML file in the same directory;
  • The request is made and then (onreadystatechange) the execution is passed to alertContents();
  • alertContents() checks if the response was received and it's an OK and then alert()s the contents of the test.html file.

Note: The line httpRequest.overrideMimeType('text/xml');bug 311724 if the page retrieve by XMLHttpRequest is not valid XML (e.g., if it is plain text). This is actually correct behavior; this article will be revised soon to address this change. above will cause JavaScript Console errors in Firefox 1.5 or later, as documented in

Note 2: if you are sending a request to a piece of code that will return XML, rather than to a static XML file, you must set some response headers if your page is to work in Internet Explorer in addition to Mozilla. If you do not set header Content-Type: application/xml, IE will throw a JavaScript error, 'Object Expected', after the line where you try to access an XML element. If you do not set header Cache-Control: no-cache the browser will cache the response and never re-submit the request, making debugging "challenging."

Note 3: if the httpRequest variable is used globally, competing functions calling makeRequest() may overwrite each other, causing a race condition. Declaring the httpRequest variable local to the function and passing it to the alertContent() function prevents the race condition.

Note 4: To register the callback function onreadystatechange, you cannot have any arguments. That's why the following code does not work:

httpRequest.onreadystatechange = alertContents(httpRequest); // (does not work) 

So, to register the function successfully, you can either pass the arguments indirectly via the anonymous function or use httpRequest as a global variable. Examples follow:

httpRequest.onreadystatechange = function() { alertContents(httpRequest); };  //1 (simultaneous request) httpRequest.onreadystatechange = alertContents;  //2 (global variable) 

Method 1 lets you have several requests processed simultaneously, while method 2 is used if httpRequest is a global variable.

Note 5: In the event of a communication error (such as the webserver going down), an exception will be thrown in the onreadystatechange method when attempting to access the .status variable. Make sure that you wrap your if...then statement in a try...catch. (See:

function alertContents(httpRequest) {          try {             if (httpRequest.readyState == 4) {                 if (httpRequest.status == 200) {                     alert(httpRequest.responseText);                 } else {                     alert('There was a problem with the request.');                 }             }         }         catch( e ) {             alert('Caught Exception: ' + e.description);         }      } 

[edit] Step 4 – "The X-Files" or Working with the XML Response

In the previous example, after the response to the HTTP request was received we used the responseText property of the request object, which contained the contents of the test.htmlresponseXML property. file. Now let's try the

First off, let's create a valid XML document that we'll request later on. The document (test.xml) contains the following:

<?xml version="1.0" ?> <root>     I'm a test. </root> 

In the script we only need to change the request line to:

... onclick="makeRequest('test.xml')"> .. 

Then in alertContents(), we need to replace the line alert(httpRequest.responseText); with:

var xmldoc = httpRequest.responseXML; var root_node = xmldoc.getElementsByTagName('root').item(0); alert(; 

This code takes the XMLDocument object given by responseXML and uses DOM methods to access some of the data contained in the XML document. You can see the test.xml here and the updated test script here.

For more on DOM methods, be sure to check Mozilla's DOM implementation documents.

Get Clipmarks - The easiest way to email text, images and videos you find on the web. It's free!
Sent with Clipmarks


Although it is a world out there, all with new Firefox releases, many of my friends do not even know what Firefox is. If you are still using IE, then i have to call you a loser.
Just go to to learn how web browsing can taste with Firefox!
Once you download and install Firefox, you wont go back to the old mal-ware in your windows OS.
clipped from

Firefox has won awards from PC Magazine for Technical Excellence and Best Software, and was a CNET Editor's Choice

Enjoy a Better Web Experience

Firefox 2 delivers helpful new features to make your online experience more productive.

Stay Secure on the Web

Firefox continues to lead the way in online security, and now includes active protection from online scams to keep you safer.

Personalize Your Browser

Choose from over a thousand useful add-ons that enhance Firefox. It’s easy to personalize Firefox to make it your own.

The award-winning Web browser is now faster, more secure, and fully customizable to your online life. With Firefox 2, we’ve added powerful new features that make your online experience even better.

Firefox 2
blog it