January 19th, 2009

permalink Exporting Opera email to mbox format

The following snippet combines the various opera mbs into one mbox format which can be used by other email clients like Evolution to import mail

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/python
# Quick hack to merge all opera mbs files into mbox format which can 
# then be used by other email clients to import Opera email.
# by Pravin Paratey (January 19, 2009)
 
import os
 
# Change this value
folder = '/home/pravin/.opera/mail/store/account1/'
 
fp = open('combined.mbox', 'a')
 
for d0 in os.listdir(folder):
	p0 = os.path.join(folder,d0)
	if os.path.isfile(p0): continue
	for d1 in os.listdir(p0):
		p1 = os.path.join(p0, d1)
		for d2 in os.listdir(p1):
			p2 = os.path.join(p1, d2)
			for f in os.listdir(p2):
				fp2 = open(os.path.join(p2, f), 'r')
				fp.write(fp2.read())
				fp2.close()
fp.close()
November 19th, 2008

permalink Gaping Wounds

gaping wounds
Photographer: Sonaa
August 7th, 2008

permalink Feeding

feeding

April 3rd, 2008

permalink 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")
August 27th, 2007

permalink 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.
August 6th, 2007

permalink Antiquated

hand pump

You feel there's no tomorrow
As you look into the water below.
Its only your reflection
And you still aint got no place to go.
-- Deep Purple (Sail Away)

(Yes, I took the pic)

March 20th, 2007

permalink Twitter Timeline Javascript

This snippet draws a bar graph that tells you your twitter posting frequency per hour in the last 24 hours.

Screenshot

Twitter timeline javascript 0.2

Instructions

  1. Download Twitter Timeline Javascript v0.2 (Requires PlotKit and MochiKit).
  2. Edit TwitterTimeline.js and change the userid variable to your user-id. You'll find your user-id at http://twitter.com/account/badge.
  3. You will need to include the javascript files:
    <script type="text/javascript" src="/js/MochiKit/MochiKit.js"></script>
    <script type="text/javascript" src="/js/PlotKit/Base.js"></script>
    <script type="text/javascript" src="/js/PlotKit/Layout.js"></script>
    <script type="text/javascript" src="/js/PlotKit/Canvas.js"></script>
    <script type="text/javascript" src="/js/PlotKit/SweetCanvas.js"></script>
    <script type="text/javascript" src="/js/TwitterTimeline.js"></script>
  4. Next, add the following lines where you want the Timeline to appear:
    <script type="text/javascript" src="/js/TwitterTimeline.js"></script>
    <div><canvas id="graph" height="200" width="400"></canvas></div>
    

For your reference, TwitterTimeline.js:

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<script type="text/javascript">
<!--
/*
 * Twitter Timeline Javascript v0.2 (March 20, 2007)
 * Pravin Paratey (http://www.dustyant.com)
 * Andrei Virlan  (http://its.squeak.in)
 *
 * Released under Creative Commons Attribution 2.5 Licence
 * http://creativecommons.org/licenses/by/2.5/
 *
 * Changelog:
 * 0.2 (Mar 20, 2007) - Moved to PlotKit to draw graphs
 * 0.1 (Feb 23, 2007) - Initial Release
 */
 
var userid = '754023'; // Change this value to your user-id
 
var timelineArray = new Array();
function drawGraph() {
    var layout = new PlotKit.Layout("bar", {});
    layout.addDataset("sqrt", timelineArray);
    layout.evaluate();
    var canvas = MochiKit.DOM.getElement("graph");
    var plotter = new PlotKit.SweetCanvasRenderer(canvas, layout, {});
    plotter.render();
}
 
function twitterCallback(obj) {
	// Create an array to hold the 24 hours of the day
	var hourArray = new Array(24);
 
	// Initialize array
	for(var i=0; i<24; i++) {
		hourArray[i] = 0;
	}
 
	for (var i=0; i<obj.length; i++) {
		// Get date
		var created_at = new Date(obj[i].created_at);
		if(obj[i].user.id == userid) {
			// Increment the hour
			hourArray[created_at.getHours()]++;
		}
	}
 
	// Construct the timeline
	for(var i=0; i<24; i++) {
		timelineArray[i] = new Array(i, hourArray[i]);
	}
	MochiKit.DOM.addLoadEvent(drawGraph);
}
// Makes the twitter call
document.write('<scr'+'ipt type="text/javascript"' +
	'src="http://twitter.com/statuses/friends_timeline/' +
	userid + '.json?callback=twitterCallback"></scr'+'ipt>');
-->
</script>
February 28th, 2007

permalink Spider nesting in flower

Spider nesting in flower

February 21st, 2007

permalink Wordless Wednesday

Deer

February 3rd, 2007

permalink Say what?

When Dee was little, crew cuts weren't the "in thing". Which, translated, meant that his parents thought their handsome *cough* sonny boy had been blessed with hair that'd even make the Gods turn green with envy. And so every morning Dee' mama would apply a liberal amount of coconut oil and then neatly part his hair with a fine-toothed comb before packing him off to school.

Now, I have hair that's straight and mostly flat. I say mostly cause a part of it refuses to follow the rules. Every time you comb it down, it just springs back up. Like some of those annoying kids in the street who refuse to pipe down. Or my little brother.

Speaking of whom, I recently learnt he likes tomboys. And Russians. Hmm, Russian tomboys. Wonder what that'd be like. "Sapi! Poshlaja svenja! Go clean your room!"

Haha. Me, I prefer the french. Sorta like Audrey Tautou.

There was going to be a point to this post. But I lost it along the way. Really.

About Me Pravin Paratey icon

Pravin Paratey Foto I'm your average, everyday chap who enjoys chocolate, free food and the occasional, dirty picture of Terry Farell. [ more ]

Navigation

Popular Posts

Blogroll