Fork me on GitHub

Saturday, December 29, 2012

The End. (or is it?)

Despair


The September 2010 issue of the Scientific American ran with the cover page 'the end. or is it?'. The edition was full of articles that explored, in the words of Michael Moyer, 'why we are suckers for stories of our own demise'. In his article, he says,
 "The desire to treat terrible events as the harbinger of the end of civilization itself also has roots in another human trait: vanity. We all believe we live in an exceptional time, perhaps even a critical moment in the history of the species. Technology appears to have given us power over the atom, our genomes, the planet—with potentially dire consequences. This attitude may stem from nothing more than our desire to place ourselves at the center of the universe. "

Other articles discuss the various consequences that would result if the human race does end. But I was fascinated by this insight. We want to believe that we are at the core of something special. But why? Why do we have to think that? Moyer answers,
 "Our pattern-seeking brains and desire to be special help explain our fears of the apocalypse. Our fears of the apocalypse may in the end mirror the most fundamental fear of all: fear of our own mortality. "
I hear adults claim that the world was a much better place when they were kids. Its a terrible lie! Just look at how the world was ten or even twenty years ago: There were no mobile phones for instance!, the diseases that we are able to cure now outnumber those we were able to cure twenty years ago, the ease of living has improved rapidly. We have instant access to vast quantities of information because of the internet. Agricultural methods have improved to yield more and better crops.. the list goes on..

Hope


 The strange thing is, most of the above statements would have applied had this essay been written twenty years ago. They will still apply after another twenty years!! Except that 'phones and internet' will be replaced by something new - a new technology(ies).

Conclusion: Every generation has progressed from its predecessors towards a better world. Every generation has added something new and better. In fact, the more modern the generation, the happier it is.( If you doubt this, just try and think of the era when human beings were being traded as slaves. We are lucky to be born now instead of in those times. Or consider all the 'religious' customs that were practiced barely a 100 years ago.. some were just cruel and now are considered  heinous crimes.)

 Still, why do people claim and even believe that we are headed for a cliff? I don't know.
I remember reading somewhere: Prices will rise, politicians will philander, you will grow old and when you do, you'll imagine that when you were young, prices were reasonable, politicians noble and children listened to their elders!. Its probably some psychological reaction or a story that our brain makes up when we grow old so that we don't feel like we are missing anything when its time for us to depart. (I am no expert on human psychology or for that matter on most things :) ) I may be a hundred percent wrong but that's my best guess  currently.

 One plausible argument for the view that we are headed for a cliff is the climate change and the depletion of fossil fuels and other natural resources. These are problems that we have not encountered before and its quite possible that the changing climate may end our rule on this planet. Just like it ended the Dinosaurs' rule 65 million years ago. 

But I am not too worried about that. Again, to explore whether the fossil fuels will continue taking us where we want to go, scientists studied all the claims made by doomsday prophets and concluded  that our current reserves will last for at least another hundred years. By then I am confident that people will have found an alternative fuel. Hopefully, something that reduces the carbon footprint.

More importantly, we must remember that humans are not governed by natural selection alone! We are now talking about 'personalized medicine'. That is: a drug that is tailored to your needs, your genes. That may take another century to mature or two centuries. Time does not matter. What matters is eventually we will get there. We may even get to grow our organs to replace the ones we have if they wear out by using the stem cells present in the blood that's present in our own umbilical cords.

 The future looks bright to me. The next twenty years will be much better than the present. And two decades after that will be better still. The world is not coming to an end anytime soon. And I personally believe that if such a time does come, the human race will have mastered space travel and we will all be living comfortably on some new planet. A new home. Just forget the crazy notions you have about the end or the future... forget the past too. Live and enjoy the present!. Its the best time in the history of the earth yet!

Wish you a Happy New Year 2013!!


Sunday, December 16, 2012

Python Script to Download XKCD webcomics (Code sample)

 I am a fan of XKCD webcomics. I decided to write a python script that will let you download the entire XKCD archive. You are free to use my code to download the comics for yourself. You can run this code periodically by specifying the number of the comic from which you want the download to begin. Just save this code with a .py extension and run it from a command line or a python interpreter. (Your python machine must have httplib2 to run this. Else you will have to download it from here. Enjoy!)

CODE:





import httplib2

import os



h = httplib2.Http('.cache')

html = "<html><head></head><body><div id=\"comic\">"
end_html = "</div></body></html>"
i = raw_input("Enter the comic number from which you want the download to begin:")
i = int(i)
if (i < 1):
i = 1

if not os.path.exists("xkcd_archive"):
os.makedirs("xkcd_archive")

if not os.path.exists("xkcd_archive/images"):
os.makedirs("xkcd_archive/images")

while True:
url = "http://www.xkcd.com/"
url = url + str(i)
response, content = h.request(url)
if response.status == 404:
  break;
index   = content.find("<div id=\"comic\"",0)
src = content.find('src=',index)
end_src = content.find('title',src)
comic = content[index : index + 1000]
start_index = comic.find('alt=')
end_index = comic.find('/>',start_index)
alt = comic[start_index + 5 : end_index - 2]
img_body =  "<h2> " + alt + "</h2>" +"<img " + "src =\"images/" + alt  + ".jpg\""

caption = comic[comic.find("title",0):comic.find('alt',0)]
image_url = content[src + 5:end_src]
content = html + img_body + caption + " />" + end_html
print "Downloading " + str(i) + "th comic --> " + alt,"\n"
content = bytes(content)
with open('xkcd_archive/' + alt + '.html','wb') as f:
    f.write(content)
print "\n"
i += 1
image_url = image_url[0:-5] + "jpg"
response, image = h.request(image_url,headers = {'type' : 'text/html'})
print response
print "\n",image_url
if response.status != 200:
image_url = image_url.replace(".jpg",".png")
print image_url,"\n"
response, image = h.request(image_url,headers = {'type' : 'text/html'})
print "png" + "\n"
print response
with open("xkcd_archive/images/" + alt + ".png", 'wb') as I:
   I.write(image)
with open("xkcd_archive/" + alt + ".html",'r+') as f:
   contents = f.read()
   contents = str(contents)
   temp = contents.find(".jpg")
   contents = contents[:temp] + ".png" + contents[temp+4:]
   print contents
   f.seek(0)
   f.write(contents)
   f.close()
else:
with open("xkcd_archive/images/" + alt + ".jpg", 'wb') as I:
   I.write(image)




   



Saturday, December 15, 2012

Princess and the Frog - (Short Story)

Once upon a time there lived a prince named Nemo. He was a very handsome and generous prince.(His facebook profile picture had over a thousand 'likes'). The people of his kingdom loved him. He was raised in a luxurious castle with his every whim fulfilled. As he grew up, he remained as generous as ever (though he would never part with his ipad). He liked to go hunting on his horse often (and not just in The Age of Empires). He was a fine young man and was looking forward to succeeding his father as king. (He still had to beat his father at Mafia wars before he could become king.)

An evil witch lived in the jungle. She was very beautiful but also very evil.(She had evaded tax and had served two terms in prison for embezzlement of funds when she had worked for the king).
She was feared by the people of the kingdom and when her antics became too twisted and dark (hacking into paypal accounts, spamming the news feeds of people), news of her reached the palace. The King sent Nemo to hunt down the witch. 

Nemo went to the jungle along with his trusted soldiers (not just the ones he had in Call of Duty. real soldiers.). The witch was soon found. She cast strange spells that made the soldiers sleepy (An FBI enquiry later revealed that it was mainly induced by their diet. The witch had no such power). Nemo evaded her spells and took out his sword.  She drew her sword and they began to duel. The duel lasted for hours. Both were equally skilled at warfare (They had played Mortal Combat online under aliases in the past). The witch was cunning. She cast a spell on Nemo that made his muscles brittle. But before his muscled stiffened, he plunged the sword into the witch's stomach. The witch let out a shriek and all her spells broke (BOFH excuse #24: Tachyon emissions caused the system overload). Before dying she cursed him, "You shall turn into an ugly frog and lose all your beauty!"

Hearing this, the prince was alarmed and begged her to undo the curse. She laughed wickedly and said, "Sure, I will undo the curse. You will become a handsome young prince if any fair princess in the world kisses you. If such a thing does happen, you both will live happily ever after as a couple.(And get featured on    AFV).  I don't think there is much chance of that. Do you?" She mocked him and breathed her last.

The soldiers who had fallen under her spell began to wake up. Once they were fully conscious, they saw the witch's dead body and concluded that Nemo must have defeated and killed her. But the prince was nowhere to be found. They searched till dusk and returned to the palace with the news that the prince had gone missing. They even searched for him  on Google and were greeted with "Your search - prince Nemo - did not match any documents.)

The king sent out search parties to find Nemo.(They even used Yahoo! and Bing).The soldiers searched for him everywhere. No trace of his was ever found. Not even his digital fingerprint.(His twitter account was suspended sometime later). The king went into a severe depression and handed over the kingdom to his nephew. He spent the last of his days mourning the loss of his prince.

Meanwhile, the frog jumped from one pond to another. It thought, "The only way that a princess can kiss me is if I am near to her in the first place." The frog hopped and hopped till it reached the neighboring kingdom.
There it met an other frog which showed it the way to sneak into the palace through the firewall. Once our frog reached the palace, it needed a place to stay. It took shelter in the fountain that was in the princess' private lawn. The princess' chamber opened directly into the lawn. It waited for its chance.

One day, when the princess was walking alone a midst the plants, the frog hopped onto the rim of the fountain and spoke her name aloud. The princess was taken aback. (At first she thought it was some crazy stalker who had made his way into the lawn). Then, she leaned forward towards the frog. It said her name aloud again.

The beautiful princess was mesmerized by the talking frog. She asked it it's tale. Once the frog revealed what it really was, she was even more surprised. When it told her about the curse and that it would once again be a handsome prince if the lady kissed it, she wondered if it was trying to make out with her using false pretenses.

She asked a question to her followers on facebook if she should kiss the frog. The overwhelming majority of her friends and subscribers answered 'yes'. Others said 'no' and there were a few people who voted 'can't say' and there were a few who thought it was a joke and answered 'LOL'. She decided to go with the facebook poll on this situation and agreed to kiss the frog. But her father was a conservative and forbade her. She was a teenager. So she was determined to kiss the frog now that her parents disapproved.

One evening, when she was alone in the palace, she went to the fountain and called out, "Nemo. Come out. I want to kiss you.". Upon hearing this, Nemo leapt out of the water and dropped the food he was eating. He rinsed his mouth with the fountain's water and eagerly held out his face. The princess said, "No tongue."
Nemo reluctantly agreed. They kissed deeply.

And the curse was lifted. Nemo became a handsome young prince again. And Nemo and the princess got married after dating for a year. The prince and the princess then became king and queen and  they lived happily ever after in their little pond by the river.