Friday, April 24, 2009

Outcome vs Activity

http://gigaom.com/2007/06/06/outcomes-vs-activity/

Thursday, February 26, 2009

A quick solution to producer consumer problem. I am sure this can be
improved..(and might even have bugs)..


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Algorithms
{

class ProducerConsumer
{
private static Queue<int> buffer = new Queue<int>();
static AutoResetEvent producerEvent = new AutoResetEvent(false);
static AutoResetEvent consumerEvent = new AutoResetEvent(false);
public static void Producer()
{
while (true)
{
lock(buffer)
{
if (buffer.Count == 0)
{
buffer.Enqueue(1);
Console.WriteLine( Thread.CurrentThread.Name + "has produced");
consumerEvent.Set();
}
}
}
}

public static void Consumer()
{
while(true)
{
lock(buffer)
{
if (buffer.Count == 1)
{
buffer.Dequeue();
Console.WriteLine(Thread.CurrentThread.Name + "has consumed");
}
}
consumerEvent.WaitOne();
}
}


public static void Main(string[] args)
{
Console.WriteLine("hello");
Thread producer = new Thread(Producer);
producer.Name = "producer0";
Thread producer1 = new Thread(Producer);
producer1.Name = "producer1";
Thread producer2 = new Thread(Producer);
producer2.Name = "producer2";
Thread consumer = new Thread(Consumer);
consumer.Name = "Consumer0";
Thread consumer1 = new Thread(Consumer);
consumer1.Name = "Consumer1";
Thread consumer2 = new Thread(Consumer);
consumer2.Name = "Consumer2";
producer.Start();
producer1.Start();
producer2.Start();
consumer.Start();
consumer1.Start();
consumer2.Start();

}
}
}

Tuesday, January 20, 2009

Obama's Inaugural Speech

- Barack Obama was sworn in as the 44th president of the United States
and the nation's first African-American president Tuesday. This is a
transcript of his prepared speech. (Reference CNN)

My fellow citizens:I stand here today humbled by the task before us,
grateful for the trust you have bestowed, mindful of the sacrifices
borne by our ancestors. I thank President Bush for his service to our
nation, as well as the generosity and cooperation he has shown
throughout this transition.

Forty-four Americans have now taken the presidential oath. The words
have been spoken during rising tides of prosperity and the still
waters of peace. Yet, every so often, the oath is taken amidst
gathering clouds and raging storms. At these moments, America has
carried on not simply because of the skill or vision of those in high
office, but because We the People have remained faithful to the ideals
of our forebearers, and true to our founding documents.

So it has been. So it must be with this generation of Americans.

That we are in the midst of crisis is now well understood. Our nation
is at war, against a far-reaching network of violence and hatred. Our
economy is badly weakened, a consequence of greed and irresponsibility
on the part of some, but also our collective failure to make hard
choices and prepare the nation for a new age. Homes have been lost;
jobs shed; businesses shuttered. Our health care is too costly; our
schools fail too many; and each day brings further evidence that the
ways we use energy strengthen our adversaries and threaten our planet.

These are the indicators of crisis, subject to data and statistics.
Less measurable but no less profound is a sapping of confidence across
our land -- a nagging fear that America's decline is inevitable, and
that the next generation must lower its sights.

Don't Miss

Video coverage of Obama's inauguration
Monumental expectations for Obama's address

Today I say to you that the challenges we face are real. They are
serious and they are many. They will not be met easily or in a short
span of time. But know this, America: They will be met.

On this day, we gather because we have chosen hope over fear, unity of
purpose over conflict and discord.

On this day, we come to proclaim an end to the petty grievances and
false promises, the recriminations and worn-out dogmas, that for far
too long have strangled our politics.

We remain a young nation, but in the words of Scripture, the time has
come to set aside childish things. The time has come to reaffirm our
enduring spirit; to choose our better history; to carry forward that
precious gift, that noble idea, passed on from generation to
generation: the God-given promise that all are equal, all are free,
and all deserve a chance to pursue their full measure of happiness.

In reaffirming the greatness of our nation, we understand that
greatness is never a given. It must be earned. Our journey has never
been one of shortcuts or settling for less. It has not been the path
for the fainthearted -- for those who prefer leisure over work, or
seek only the pleasures of riches and fame. Rather, it has been the
risk-takers, the doers, the makers of things -- some celebrated, but
more often men and women obscure in their labor -- who have carried us
up the long, rugged path toward prosperity and freedom.

For us, they packed up their few worldly possessions and traveled
across oceans in search of a new life.

For us, they toiled in sweatshops and settled the West; endured the
lash of the whip and plowed the hard earth.

For us, they fought and died, in places like Concord and Gettysburg;
Normandy and Khe Sahn.

Time and again, these men and women struggled and sacrificed and
worked till their hands were raw so that we might live a better life.
They saw America as bigger than the sum of our individual ambitions;
greater than all the differences of birth or wealth or faction.

This is the journey we continue today. We remain the most prosperous,
powerful nation on Earth. Our workers are no less productive than when
this crisis began. Our minds are no less inventive, our goods and
services no less needed than they were last week or last month or last
year. Our capacity remains undiminished. But our time of standing pat,
of protecting narrow interests and putting off unpleasant decisions --
that time has surely passed. Starting today, we must pick ourselves
up, dust ourselves off, and begin again the work of remaking America.

For everywhere we look, there is work to be done. The state of the
economy calls for action, bold and swift, and we will act -- not only
to create new jobs, but to lay a new foundation for growth. We will
build the roads and bridges, the electric grids and digital lines that
feed our commerce and bind us together. We will restore science to its
rightful place, and wield technology's wonders to raise health care's
quality and lower its cost. We will harness the sun and the winds and
the soil to fuel our cars and run our factories. And we will transform
our schools and colleges and universities to meet the demands of a new
age. All this we can do. And all this we will do.

Now, there are some who question the scale of our ambitions -- who
suggest that our system cannot tolerate too many big plans. Their
memories are short. For they have forgotten what this country has
already done; what free men and women can achieve when imagination is
joined to common purpose, and necessity to courage.

What the cynics fail to understand is that the ground has shifted
beneath them -- that the stale political arguments that have consumed
us for so long no longer apply. The question we ask today is not
whether our government is too big or too small, but whether it works
-- whether it helps families find jobs at a decent wage, care they can
afford, a retirement that is dignified. Where the answer is yes, we
intend to move forward. Where the answer is no, programs will end. And
those of us who manage the public's dollars will be held to account --
to spend wisely, reform bad habits, and do our business in the light
of day -- because only then can we restore the vital trust between a
people and their government.

Nor is the question before us whether the market is a force for good
or ill. Its power to generate wealth and expand freedom is unmatched,
but this crisis has reminded us that without a watchful eye, the
market can spin out of control -- and that a nation cannot prosper
long when it favors only the prosperous. The success of our economy
has always depended not just on the size of our gross domestic
product, but on the reach of our prosperity; on our ability to extend
opportunity to every willing heart -- not out of charity, but because
it is the surest route to our common good.

As for our common defense, we reject as false the choice between our
safety and our ideals. Our Founding Fathers, faced with perils we can
scarcely imagine, drafted a charter to assure the rule of law and the
rights of man, a charter expanded by the blood of generations. Those
ideals still light the world, and we will not give them up for
expedience's sake. And so to all other peoples and governments who are
watching today, from the grandest capitals to the small village where
my father was born: Know that America is a friend of each nation and
every man, woman and child who seeks a future of peace and dignity,
and that we are ready to lead once more.

Recall that earlier generations faced down fascism and communism not
just with missiles and tanks, but with sturdy alliances and enduring
convictions. They understood that our power alone cannot protect us,
nor does it entitle us to do as we please. Instead, they knew that our
power grows through its prudent use; our security emanates from the
justness of our cause, the force of our example, the tempering
qualities of humility and restraint.

We are the keepers of this legacy. Guided by these principles once
more, we can meet those new threats that demand even greater effort --
even greater cooperation and understanding between nations. We will
begin to responsibly leave Iraq to its people, and forge a hard-earned
peace in Afghanistan. With old friends and former foes, we will work
tirelessly to lessen the nuclear threat, and roll back the specter of
a warming planet. We will not apologize for our way of life, nor will
we waver in its defense, and for those who seek to advance their aims
by inducing terror and slaughtering innocents, we say to you now that
our spirit is stronger and cannot be broken; you cannot outlast us,
and we will defeat you.

For we know that our patchwork heritage is a strength, not a weakness.
We are a nation of Christians and Muslims, Jews and Hindus -- and
nonbelievers. We are shaped by every language and culture, drawn from
every end of this Earth; and because we have tasted the bitter swill
of civil war and segregation, and emerged from that dark chapter
stronger and more united, we cannot help but believe that the old
hatreds shall someday pass; that the lines of tribe shall soon
dissolve; that as the world grows smaller, our common humanity shall
reveal itself; and that America must play its role in ushering in a
new era of peace.

To the Muslim world, we seek a new way forward, based on mutual
interest and mutual respect. To those leaders around the globe who
seek to sow conflict, or blame their society's ills on the West: Know
that your people will judge you on what you can build, not what you
destroy. To those who cling to power through corruption and deceit and
the silencing of dissent, know that you are on the wrong side of
history; but that we will extend a hand if you are willing to unclench
your fist.

To the people of poor nations, we pledge to work alongside you to make
your farms flourish and let clean waters flow; to nourish starved
bodies and feed hungry minds. And to those nations like ours that
enjoy relative plenty, we say we can no longer afford indifference to
suffering outside our borders; nor can we consume the world's
resources without regard to effect. For the world has changed, and we
must change with it.

As we consider the road that unfolds before us, we remember with
humble gratitude those brave Americans who, at this very hour, patrol
far-off deserts and distant mountains. They have something to tell us
today, just as the fallen heroes who lie in Arlington whisper through
the ages. We honor them not only because they are guardians of our
liberty, but because they embody the spirit of service; a willingness
to find meaning in something greater than themselves. And yet, at this
moment -- a moment that will define a generation -- it is precisely
this spirit that must inhabit us all.

For as much as government can do and must do, it is ultimately the
faith and determination of the American people upon which this nation
relies. It is the kindness to take in a stranger when the levees
break, the selflessness of workers who would rather cut their hours
than see a friend lose their job which sees us through our darkest
hours. It is the firefighter's courage to storm a stairway filled with
smoke, but also a parent's willingness to nurture a child, that
finally decides our fate.

Our challenges may be new. The instruments with which we meet them may
be new. But those values upon which our success depends -- hard work
and honesty, courage and fair play, tolerance and curiosity, loyalty
and patriotism -- these things are old. These things are true. They
have been the quiet force of progress throughout our history. What is
demanded then is a return to these truths. What is required of us now
is a new era of responsibility -- a recognition, on the part of every
American, that we have duties to ourselves, our nation and the world;
duties that we do not grudgingly accept but rather seize gladly, firm
in the knowledge that there is nothing so satisfying to the spirit, so
defining of our character, than giving our all to a difficult task.

This is the price and the promise of citizenship.

This is the source of our confidence -- the knowledge that God calls
on us to shape an uncertain destiny.

This is the meaning of our liberty and our creed -- why men and women
and children of every race and every faith can join in celebration
across this magnificent Mall, and why a man whose father less than 60
years ago might not have been served at a local restaurant can now
stand before you to take a most sacred oath.

So let us mark this day with remembrance, of who we are and how far we
have traveled. In the year of America's birth, in the coldest of
months, a small band of patriots huddled by dying campfires on the
shores of an icy river. The capital was abandoned. The enemy was
advancing. The snow was stained with blood. At a moment when the
outcome of our revolution was most in doubt, the father of our nation
ordered these words be read to the people:

"Let it be told to the future world ... that in the depth of winter,
when nothing but hope and virtue could survive... that the city and
the country, alarmed at one common danger, came forth to meet [it]."

America. In the face of our common dangers, in this winter of our
hardship, let us remember these timeless words. With hope and virtue,
let us brave once more the icy currents, and endure what storms may
come. Let it be said by our children's children that when we were
tested, we refused to let this journey end, that we did not turn back,
nor did we falter; and with eyes fixed on the horizon and God's grace
upon us, we carried forth that great gift of freedom and delivered it
safely to future generations.

Saturday, November 22, 2008

ASP.net request lifecycle


  • IIS gets the request
  • Looks up a script map extension and maps to aspnet_isapi.dll
  • Code hits the worker process (aspnet_wp.exe in IIS5 or w3wp.exe in IIS6)
  • .NET runtime is loaded
  • IsapiRuntime.ProcessRequest() called by non-managed code
  • IsapiWorkerRequest created once per request
  • HttpRuntime.ProcessRequest() called with Worker Request
  • HttpContext Object created by passing Worker Request as input
  • HttpApplication.GetApplicationInstance() called with Context to retrieve instance from pool
  • HttpApplication.Init() called to start pipeline event sequence and hook up modules and handlers
  • HttpApplicaton.ProcessRequest called to start processing
  • Pipeline events fire
  • Handlers are called and ProcessRequest method are fired
  • Control returns to pipeline and post request events fire
  • Thursday, November 06, 2008

    Obama's victory speech transcript

    IF there is anyone out there who still doubts that America is a place where all things are possible; who still wonders if the dream of our founders is alive in our time; who still questions the power of our democracy, tonight is your answer.

    It's the answer told by lines that stretched around schools and churches in numbers this nation has never seen; by people who waited three hours and four hours, many for the very first time in their lives, because they believed that this time must be different; that their voice could be that difference.

    It's the answer spoken by young and old, rich and poor, Democrat and Republican, black, white, Latino, Asian, Native American, gay, straight, disabled and not disabled – Americans who sent a message to the world that we have never been a collection of Red States and Blue States: we are, and always will be, the United States of America.

    It's the answer that led those who have been told for so long by so many to be cynical, and fearful, and doubtful of what we can achieve to put their hands on the arc of history and bend it once more toward the hope of a better day.

    It's been a long time coming, but tonight, because of what we did on this day, in this election, at this defining moment, change has come to America.

    I just received a very gracious call from Senator McCain. He fought long and hard in this campaign, and he's fought even longer and harder for the country he loves. He has endured sacrifices for America that most of us cannot begin to imagine, and we are better off for the service rendered by this brave and selfless leader. I congratulate him and Governor Palin for all they have achieved, and I look forward to working with them to renew this nation's promise in the months ahead.

    I want to thank my partner in this journey, a man who campaigned from his heart and spoke for the men and women he grew up with on the streets of Scranton and rode with on that train home to Delaware, the Vice President-elect of the United States, Joe Biden.

    I would not be standing here tonight without the unyielding support of my best friend for the last sixteen years, the rock of our family and the love of my life, our nation's next First Lady, Michelle Obama. Sasha and Malia, I love you both so much, and you have earned the new puppy that's coming with us to the White House. And while she's no longer with us, I know my grandmother is watching, along with the family that made me who I am. I miss them tonight, and know that my debt to them is beyond measure.

    To my campaign manager David Plouffe, my chief strategist David Axelrod, and the best campaign team ever assembled in the history of politics – you made this happen, and I am forever grateful for what you've sacrificed to get it done.

    But above all, I will never forget who this victory truly belongs to – it belongs to you.

    I was never the likeliest candidate for this office. We didn't start with much money or many endorsements. Our campaign was not hatched in the halls of Washington – it began in the backyards of Des Moines and the living rooms of Concord and the front porches of Charleston.

    It was built by working men and women who dug into what little savings they had to give five dollars and ten dollars and twenty dollars to this cause. It grew strength from the young people who rejected the myth of their generation's apathy; who left their homes and their families for jobs that offered little pay and less sleep; from the not-so-young people who braved the bitter cold and scorching heat to knock on the doors of perfect strangers; from the millions of Americans who volunteered, and organized, and proved that more than two centuries later, a government of the people, by the people and for the people has not perished from this Earth. This is your victory.

    I know you didn't do this just to win an election and I know you didn't do it for me. You did it because you understand the enormity of the task that lies ahead. For even as we celebrate tonight, we know the challenges that tomorrow will bring are the greatest of our lifetime – two wars, a planet in peril, the worst financial crisis in a century. Even as we stand here tonight, we know there are brave Americans waking up in the deserts of Iraq and the mountains of Afghanistan to risk their lives for us. There are mothers and fathers who will lie awake after their children fall asleep and wonder how they'll make the mortgage, or pay their doctor's bills, or save enough for college. There is new energy to harness and new jobs to be created; new schools to build and threats to meet and alliances to repair.

    The road ahead will be long. Our climb will be steep. We may not get there in one year or even one term, but America – I have never been more hopeful than I am tonight that we will get there. I promise you – we as a people will get there.

    There will be setbacks and false starts. There are many who won't agree with every decision or policy I make as President, and we know that government can't solve every problem. But I will always be honest with you about the challenges we face. I will listen to you, especially when we disagree. And above all, I will ask you join in the work of remaking this nation the only way it's been done in America for two-hundred and twenty-one years – block by block, brick by brick, calloused hand by calloused hand.

    What began twenty-one months ago in the depths of winter must not end on this autumn night. This victory alone is not the change we seek – it is only the chance for us to make that change. And that cannot happen if we go back to the way things were. It cannot happen without you.

    So let us summon a new spirit of patriotism; of service and responsibility where each of us resolves to pitch in and work harder and look after not only ourselves, but each other. Let us remember that if this financial crisis taught us anything, it's that we cannot have a thriving Wall Street while Main Street suffers – in this country, we rise or fall as one nation; as one people.

    Let us resist the temptation to fall back on the same partisanship and pettiness and immaturity that has poisoned our politics for so long. Let us remember that it was a man from this state who first carried the banner of the Republican Party to the White House – a party founded on the values of self-reliance, individual liberty, and national unity. Those are values we all share, and while the Democratic Party has won a great victory tonight, we do so with a measure of humility and determination to heal the divides that have held back our progress. As Lincoln said to a nation far more divided than ours, "We are not enemies, but friends…though passion may have strained it must not break our bonds of affection." And to those Americans whose support I have yet to earn – I may not have won your vote, but I hear your voices, I need your help, and I will be your President too.

    And to all those watching tonight from beyond our shores, from parliaments and palaces to those who are huddled around radios in the forgotten corners of our world – our stories are singular, but our destiny is shared, and a new dawn of American leadership is at hand. To those who would tear this world down – we will defeat you. To those who seek peace and security – we support you. And to all those who have wondered if America's beacon still burns as bright – tonight we proved once more that the true strength of our nation comes not from our the might of our arms or the scale of our wealth, but from the enduring power of our ideals: democracy, liberty, opportunity, and unyielding hope.

    For that is the true genius of America – that America can change. Our union can be perfected. And what we have already achieved gives us hope for what we can and must achieve tomorrow.

    This election had many firsts and many stories that will be told for generations. But one that's on my mind tonight is about a woman who cast her ballot in Atlanta. She's a lot like the millions of others who stood in line to make their voice heard in this election except for one thing – Ann Nixon Cooper is 106 years old.

    She was born just a generation past slavery; a time when there were no cars on the road or planes in the sky; when someone like her couldn't vote for two reasons – because she was a woman and because of the color of her skin.

    And tonight, I think about all that she's seen throughout her century in America – the heartache and the hope; the struggle and the progress; the times we were told that we can't, and the people who pressed on with that American creed: Yes we can.

    At a time when women's voices were silenced and their hopes dismissed, she lived to see them stand up and speak out and reach for the ballot. Yes we can.

    When there was despair in the dust bowl and depression across the land, she saw a nation conquer fear itself with a New Deal, new jobs and a new sense of common purpose. Yes we can.

    When the bombs fell on our harbor and tyranny threatened the world, she was there to witness a generation rise to greatness and a democracy was saved. Yes we can.

    She was there for the buses in Montgomery, the hoses in Birmingham, a bridge in Selma, and a preacher from Atlanta who told a people that "We Shall Overcome." Yes we can.

    A man touched down on the moon, a wall came down in Berlin, a world was connected by our own science and imagination. And this year, in this election, she touched her finger to a screen, and cast her vote, because after 106 years in America, through the best of times and the darkest of hours, she knows how America can change. Yes we can.

    America, we have come so far. We have seen so much. But there is so much more to do. So tonight, let us ask ourselves – if our children should live to see the next century; if my daughters should be so lucky to live as long as Ann Nixon Cooper, what change will they see? What progress will we have made?

    This is our chance to answer that call. This is our moment. This is our time – to put our people back to work and open doors of opportunity for our kids; to restore prosperity and promote the cause of peace; to reclaim the American Dream and reaffirm that fundamental truth – that out of many, we are one; that while we breathe, we hope, and where we are met with cynicism, and doubt, and those who tell us that we can't, we will respond with that timeless creed that sums up the spirit of a people:

    Yes We Can. Thank you, God bless you, and may God Bless the United States of America