rss
logo Home Articles Themes Win32 Archives About
Email Yahoo: pravinparatey Orkut Profile Facebook Profile Google Talk: pravinp[at]gmail[dot]com MSN: pravinp[at]gmail[dot]com

Euclidean Distance Calculator

The following snippet returns the euclidean distance between two places on the globe using the Yahoo Maps API. Replace API_KEY with your Yahoo Maps API key.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
# Distance Module
# by Pravin Paratey (pravinp at gmail dot com)
# Code is licenced under Creative Commons Attribution-Noncommercial-Share Alike 2.5 India
# http://creativecommons.org/licenses/by-nc-sa/2.5/in/
 
import urllib2, cgi, re
from math import sqrt
 
class Distance:
    """
    Using yahoo maps api (http://developer.yahoo.com/maps/rest/V1/geocode.html), 
    this class is responsible for returning the euclidean distance between
    two places
    """
    def getDistance(self, start, end):
        """ Gets the euclidean distance between start and end """
        (start_x, start_y) = self.getCoords(start)
        (end_x, end_y) = self.getCoords(end)
        # 1 degree = 111.12 kms or 69.047 miles
        return sqrt((start_x - end_x) ** 2 + (start_y - end_y) ** 2) * 111.12
 
 
    def getCoords(self, location):
        """ Gets the co-ordinates for the given location """
        url = 'http://local.yahooapis.com/MapsService/V1/geocode?appid=' + 
                API_KEY + '&street=' + urllib2.quote(location)
        response = urllib2.urlopen(url)
        (x, y) = self._parseXML(response.read())
        return float(x), float(y)
 
 
    def _parseXML(self, xml):
        """ Parses XML and returns latitude and longitude """
        m = re.findall('<Latitude>(\d+.\d+)</Latitude><Longitude>(\d+.\d+)</Longitude>', xml)
        # In case of multiple matches, return 1st match
        return m[0]
 
if __name__ == '__main__':
    d = Distance()
    print 'Distance in kms: '
    print d.getDistance("Hiranandani, Powai, Mumbai", "Dadar Station, Mumbai")

An Origami Tale

By day, he was your average teenager in geeky glasses and by night, he was SooperDee - fighter of crime and upholder of justice. Like all superheroes, SooperDee had his own set of super powers. He could lift small objects, swim real fast and flick his tail in an enticing manner - which always caused the merchicks to get weak in their knees.

This story begins one fine day when SooperDee was out with the other merboys sitting atop the rock to watch the merchicks go by. He would wait on this rock every day after school until Muriel arrived. Muriel, daughter to King Neptune, was not the fairest of the merchicks, which explains why SooperDee had fallen deeply in love with her younger sister, Ariel.

Now, SooperDee had worked up a deal with Muriel. In exchange for a pebble, she’d tell him something new about Ariel every day. “She likes listening to the Beatles,” Muriel had remarked the day before. And SooperDee had spent the whole day humming, Yellow submarine. After it became annoyingly repetitive he had switched to Lovely Rita.

Today, SooperDee again found himself trading a shiny pebble for another tidbit about Ariel. “She loves coconuts,” said Muriel. “What in the world is a coconut?” wondered SooperDee, but he was out of pebbles and Muriel would tell no more. “Oh well,” thought SooperDee, “Perhaps Kitty Kaht the fortune un-teller would know about such things.”

“Peanuts,” said Kitty while staring into the crystal ball and simultaneously gyrating to Stereophonics. “Er no, Coco-nuts,” corrected SooperDee. “I meant,” Kitty replied, “Pass me the peanuts.” “Oh,” said SooperDee and handed her a bowl of peanuts.

“I see a little merchild. Boy, you sure were cute as a kid!” said Kitty. “Well,” blushed SooperDee, “I still am.” “Of course Dahling,” said Kitty and rolled her eyes, “Okay, about the coconut - It’s big, it’s green and it’s found on trees.”

“Wew, those trees sure are tall. And the coconut is waaay up there,” thought SooperDee from the shallow waters, “I wonder how I’ll get to it”. And SooperDee swam towards the tree. Just as he reached the tree, a coconut fell on his head and knocked him out.

Meanwhile, the author of this little tale got distracted and lost his train of thought. He decided to skip directly to the part where SooperDee and Ariel get married and live happily ever after.

Moral - If you get too close to a tree, the coconut is bound to fall on your head.

Hilfe mich

One merger
Two acquisitions
Two splits

It’s been a gruelling two weeks. And I’m tired. Very tired. But then, a whole new world awaits. B-)

New year greetings!

What was 2007 like?

And there’s no need to hurry
Take your time I’ll still be here

- Dido - Closer

For the most part, it was laid back. I didn’t do much, but I did accomplish a fair bit for myself. I crossed a bridge that I thought uncrossable, and in doing so, I re-discovered myself.

I met some amazing people along the way and made some awesome friends. I broke a couple of hearts too. And I didn’t do a good job patching up. But then I believe it was for the best.

Oh and I fell in love *wink*. On an unrelated note, I’d like to add that Nitin rocks.

What will 2008 look like?

And you go dancing through doorways
Just to see what you gonna find there

- Dire Straits - Love over gold

I expect this year to be a lot more dynamic. I’ve marked 2008 as a year of preparation. Lots of things have been planned on both a personal and a professional front. I hope to accomplish what I’ve planned and set the stage for 2009.

I guess time is the most precious resource you can give a person. I plan to spend more time with people who matter to me - my little ones, my close friends and members of my family.

Here’s wishing you all an awesome and happy 2008. May the force be with you.

Point of life

Point of life

I couldn’t have said it any better! Showing Tongue

8 things

I’ve been tagged 8-things by Aditi and Amy.

  1. I happen to like Fridays more than Tuesdays. I also happen like cake more than ice-cream. I also happen to have four fingers. And a thumb. On either hand.
  2. Don’t let the dorky exterior fool you. I’m a superhero in disguise - I can lift small objects, jump up and down, yodel at the top of my voice and type without looking at the keyboard. Also I’m awfully cute. Really!
  3. I like being at the heart of things. I love people fussing over me and I love attention. But when I don’t get any, I tend to sulk and throw tantrums. Apart from other objects.
  4. When I was much younger I wanted a dog for a pet. I read all about keeping dogs, stocked myself with books on pet care. But we never got a dog. The closest I got to it was when my mum got me a stuffed dog for my 14th birthday. Oh but my parents did get me a pair of love birds, a parrot, a sparrow, a tweety bird and a kitten. And a set of encyclopedias.
  5. Then I grew older and wanted a girlfriend. They gifted me a computer. And the internet. So I spent my teenage years with people called janine_sells_dope, hottie_4_u, tammy1985, yukoncrazygirl, miss_broadback, weenylozar.
  6. Point 5 isn’t true. I didn’t have an internet friend called yukoncrazygirl. Or weenylozar.
  7. Then I grew still older and wanted to be a sportsman. I tried my hand at various sports. I’m not very proud of the results of that experiment.
  8. I typed this while munching on a pear.

Another day

Have you ever walked along the beach and caught your foot in sea weed? Only to realize it was dog poo. But then to save face made up a story about an electric eel, a chocolate bunny and a jug of precariously balanced milk?

No? I thought as much. You guys sure live boring lives!

Blogroll

Gallery

Titan Pink me-tall me-hadbad VK Korean Phone I can cook 09.Pune Yellow Lantana hand pump Deer chewing on leaves Haemanthus Multiflorus Dragonflies
This page and its contents are copyright © 2008, Pravin Paratey.