Sunday, December 28, 2008

Ajax, live comments (http://www.gmail.net/)

Something strange, live comments on gmail.net domain.

Try, http://www.gmail.net/ and view the source code here

Monday, December 22, 2008

Out of my diary: Fitna

Just another rant that was flowing over my empty skull...

..::Fitna::..
sir phiron kay deys mein
pagalon kay bheys mein

zer zamee ki daud mein
thak bhi ja ab to bas

zan parast saber bhi ker
ruk zara tthaher bhi ja

idher udher nazar bhi ker
kharay hain teray jaan jigar

yarab ye kaisee hai dagar?
vo fikr-e-imtehaan kidher?

kaisa hia ye khair-o-sher
lut gaya hai ye basher

ehd-e-vafa ka vo saffar
Allah meray... maaf ker

sun... aye paiker-e-shar
takallum tujh say hai basher

ye lazaval nematein....
inka kuch... shuker to ker?

ye bay misaal kehkashaan
zara tu inpay ghor ker?

in chehchahun kay saaz per
khudavand pay naaz ker?...

rang barang titliyaan...
ye jaltarang bijliyaan...

ye neelay aasmaa ko dekh
falak kay uss talak bhi dekh

aye basher chala kidher?
fikr-e-aakhirat bhi ker?

karb-e-dozakh'aan say der
hamd-e-mustufa hi ker?

aye naaz... kuch to dar...
khauf-e-khuda hi ker!
(0:

Tuesday, December 16, 2008

How to make an external non editable DTD

While preparing xml schema document(xsd) and their document type definitions(dtd), I encountered a situation where I wanted:

- The XML files to be editable
- And DTD files to be readonly

Obviously this means, avoid using the internal dtd and even external editable dtd.

So, after several googles/xml documentations/msdn searches, I thought of putting my dtd document on a public domain; So I am posting this for if I need this in future.

One way of achieving this, is to post the dtd document on a domain with system keyword.
< !DOCTYPE rootElementName SYSTEM "http://MyDomain.pk/MyDefinitions.dtd" >

or if you must use PUBLIC keyword then adding the optional string that would describe the data structure that dtd defines.
< !DOCTYPE rootElementName PUBLIC "-//Any_Name_for_the_dtd//" "http://MyDomain.pk/MyDefinitions.dtd" >

  • Click here for a very nice resource.
  • When authoring your web documents here is the list of w3c recommended dtds.
  • And if you do not have any idea about DTD, and go here.

Wednesday, December 10, 2008

True environment for a software developer

Came across following while surfing... (0: So true,

A programmer is most productive with a quiet private office, a great computer, unlimited beverages, an ambient temperature between 68 and 72 degrees (F), no glare on the screen, a chair that’s so comfortable you don’t feel it, an administrator that brings them their mail and orders manuals and books, a system administrator who makes the Internet as available as oxygen, a tester to find the bugs they just can’t see, a graphic designer to make their screens beautiful, a team of marketing people to make the masses want their products, a team of sales people to make sure the masses can get these products, some patient tech support saints who help customers get the product working and help the programmers understand what problems are generating the tech support calls, and about a dozen other support and administrative functions...
http://www.fogcreek.com/About.html

Sunday, December 7, 2008

Out of my diary: Quotes for life

Here are a few quotes that I have experienced/learned during my small span:

1. If you know where do you want to go, any road will take you there.
(Anonymous)

2. Having knowledge doesn't mean having wisdom.
(KMan)

3. Never, neither underestimate nor over estimate anyone.
(KMan)

4. Never do fall in love, it spoils you in either cases
(KMan)

5. Inspiration with perspiration is what that matters
(Dad)

6. Be flexible always by yourself, and never by force.
(KMan)

7. Act humble, be humble and you'll rule the world.
(KMan)

8. Time has a good thing and a bad thing, that it passes by.
(Anonymous)

9. Fight for your right and the right, until you succeed.
(KMan)

10. Never test a friend, you may lose him
(Mustansar Hussain Tarar)

11. Must have aim in life, broad and achievable.
(Anonymous)

12. Friends are like bank balance, never use them very often; Otherwise you'll get bankrupt.
(Mustansar Hussain Tarar)

13. Respect is not demanded, its commanded.
(Imran Khan Niazi)

14. There exists no such thing as "try"; because its either you do it or you do not do it.
(Shariq Mirza, CEO Assurety Consulting)

What is success?

While I was stuck thinking, a thought that flashed in and I was somewhat compelled to write down so that I may decide what exactly is it that I want? Following are few questions that you might ask yourself as well, and see what you want?

What is success?

1. Living low(financially), but a satisfied life?
2. Drawing high amount (financial), living in posh locality, having membership of vvips clubs, etc?
3. Living a love life/marriage?
4. Praying 5 times a day?
5. Helping people in any way in all walks of life?

Success, I believe is what we call satisfaction. So what gives you satisfaction?

Wednesday, December 3, 2008

What does Thread.Join() mean?

Couple of days ago I came across the following question over our local web blog, and following is what I replied.

Question:


[Discuss]: A Threading Query…
Consider the following block of code…

//Csharp code snippet..
Line 1: Thread t = new Thread (Go); // Assume Go is some static method
Line 2: t.Start();
Line 3: t.Join(); // Wait (block) calling thread until thread t ends
//End


- In calling thread at line 1 we created a thread object.
- On Line 2 we started the thread t.
- Then on line 3 we are calling Join() method of Thread t which serves the other way around.
I mean if you think logically t.Join() causes the calling thread to wait untill thread T completes.
The join() method is a busy waiting technique… i.e. The main thread is engaged in a continuous
loop checking for thread t.IsAlive property to be false. t.Join() syntax is also an invalidation of an
important OOP concept, “Encapsulation”… i.e. in t.Join() we are actually blocking Main thread
instead of working on Thread t.

I don’t know how many of you agree that logically it should be the other way around (i.e. One
should be calling Thread.CurrentThread.Join(t) instead of t.Join()).

Any one thinks of a reason why the Thread.Join() method was implemented like this??


ANSWER:

1. t.Join() doesnt block the app, it actually waits for the thread to terminate, the message pumping continues; Does something like waits for IsAlive for the given time span as you said.

2. Thread.Join() is used to assure that the thread has terminated successfully. Join() tells the thread object to wait for some time and see if it has ended. This method changes the state of the calling thread to include ThreadState.WaitSleepJoin, which further means this thread is blocked and no work is going to be done.


http://www.digcode.com/Data/DigCode/Attachments/fbf261b2-4ca7-4459-96fd-ae1046b50b4e/threadstate%5B1%5D.png

3. See following loc.

1. Thread t = new Thread(new ThreadStart(ThreadMethod));
2. t.Start();
3.
4. // Wait for foreground thread to end, for good.
5.
6. t.Join(); //wait, until thread ends.
7.
8. //Cursor at this loc would mean that thread t has terminated successfully.
9. //but what if thread t malfunctions and never ends?

Cursor would come to line 7 only if thread t terminates gracefully.

4. Thread.CurrentThread is used to access the application's main thread.

1. Thread.CurrentThread.Join();//Wait, whole life

The above loc would mean, wait for the application thread to finish, which in most cases it would never occur; Unless for a user interface based app, user closes the app manually.

In fact the following two lines of code are almost same:

1. Thread.CurrentThread.Join (); //calling main thread, the app, wait for good.
2. Thread.Sleep (1000); //static method call, wait for 1 sec.

While cursor would never be able come to the line 2 in the above code; But if we provide the Join(secs) with some time span it would come to line 2 after 5 secs (see following locs).

1. Thread.CurrentThread.Join (5000); //calling main thread, the app.
2. Thread.Sleep (1000); //static method call

With Thread.CurrentThread.Join(1000) message pumping continues while Thread.Sleep(1000) hangs the app since its a static method call.

5. Thread.Join() is more preffered with timeout. And using Join() without a timeout may lead to unexpected results; Most common concern you would come across is what if thread t never ends?

So I prefer using Join() to report un/successful thread termination.

1. //Wait for 10 secs and then report the status.
2. if(!t.Join(10000))
3. Log.Error("Couldnt end thread even after 10 seconds");
4. else
5. Log.Info("Thread terminated successfully");

I believe one would use Thread.CurrentThread.Join(1000) for the application to wait for some time, but I do not see the need, or I should say I have yet to come across a situation where I could use Thread.CurrentThread.Join() without any timeout.

6. Since it is written:
"it should be the other way around (i.e. One should be calling Thread.CurrentThread.Join(t) instead of t.Join())."

I am assuming that the word Join() is somewhat not really self explanatory - and is confusing. It should have been something like t.WaitForThreadToQuit() or t.WaitForThreadEnd() or t.WaitForEnd() or wait for some time and then report; Well... I am not sure about a generic name for that method probably thats why MS came up with the Join() thingy. Just thinking... out loud.

I use to refer to an helpful resource whenever I am stuck into the threads (pun intended). (0:
http://www.albahari.com/threading/ there is also a pdf available there.

I am not sure if this answers the question, I would suggest checkout msdn for more precise information/articles/helps.

Tuesday, December 2, 2008

Washington Post - Abysmal Reporting

We all know that The Washington Post is the largest and most circulated newspaper in Washington, D.C. and is the city's oldest newspaper, founded in 1877. It is widely considered to be one of the most important newspapers in the United States due to its particular emphasis on national politics, and international affairs, and being a newspaper of record.

Following is a snapshot, that I was reading couple of minutes ago from WashintonPost website.

Ref: http://www.washingtonpost.com/wp-dyn/content/article/2008/12/01/AR2008120102439.html
"Pakistan's Task
Peace in South Asia requires a crackdown on terrorists
Tuesday, December 2, 2008; Page A20

... A captured terrorist has reportedly confessed to Indian officials that he received training in Pakistan from Lashkar-i-Taiba, a guerrilla organization that was nurtured by Pakistani military intelligence to fight India in the disputed Kashmir region. It has previously been linked to murderous attacks within India; Lashkar-i-Taiba was behind an assault on the Indian Parliament in 2001 that killed more than a dozen people and almost triggered all-out war on the subcontinent."

It is sad to see that truth drivers are now fabricating statements without authentic records/facts. It seems that TWP is propagating news with abysmal/false reasoning, that smells more like personal thoughts.

It would be good if TWP provides links to references/clues in future. For instance, that Lashkar did the 2001 assault on the Indian Parliament (Ref: WashingtonPost.Com/Lashkar_Evidence).

Mumbai terror related news should not contain false propagation unless the clues are known to general public or TWP has genuine information to share with the reader.

Unless having references, It would be better if WP write "Lashkar-i-Taiba was accused" rather than "Lashkar did this/that".

Certainly WP has provided references to the personalities discussed in the subject, but it did not provide the reference to the context. It would be good if TWP that rather than assuming/presuming the context, as a better practice provide references for the reader to understand and judge the situation, and so that the reporter shall not be able to 'Manufacture' the news.

Since India did not provide the evidence that Lashkar did the 2001 assault on the Indian Parliament. So is the case of Mumbai terror. No evidence known to-date.

Monday, December 1, 2008

Quick Launch: Lost Show Desktop Button

Quick Launch: Lost Show Desktop Button

Somehow I lost my show desktop button from launch, and couldn’t get it back even after google’ing for it for hours.

Well, following is what I did to get it back.

Create a file with .SCF extension using notepad.exe, and provide following details in it.

[Shell]
Command=2
IconFile=explorer.exe,3
[Taskbar]
Command=ToggleDesktop


Save the file as "Show Desktop.SCF" and then drag and drop the file icon to quick launch bar. Btw, the shortcut for jumping to desktop or clearing the screen is WinKey + D.

Related Posts

Popular Posts