<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Rational Pie</title>
	<atom:link href="http://rationalpie.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://rationalpie.wordpress.com</link>
	<description>from NULL to void* and everything in between</description>
	<lastBuildDate>Fri, 20 Jan 2012 04:26:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='rationalpie.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Rational Pie</title>
		<link>http://rationalpie.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://rationalpie.wordpress.com/osd.xml" title="Rational Pie" />
	<atom:link rel='hub' href='http://rationalpie.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Special Cross Domain Restriction In Firefox</title>
		<link>http://rationalpie.wordpress.com/2011/03/02/special-cross-domain-restriction-in-firefox/</link>
		<comments>http://rationalpie.wordpress.com/2011/03/02/special-cross-domain-restriction-in-firefox/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 12:21:19 +0000</pubDate>
		<dc:creator>Shashank</dc:creator>
				<category><![CDATA[Cross-Browser]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://rationalpie.wordpress.com/?p=245</guid>
		<description><![CDATA[The Mystery While working with Iframe and document.domain trick to get around the same-origin policy against cross domain restriction on web-browsers I came across an interesting oddity in Firefox (a hidden security feature if you will!). The reference page for document.domain setting policy here says: A script can set the value of document.domain to a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=245&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2><strong>The Mystery</strong></h2>
<p>While working with <a href="http://madskristensen.net/post/Iframe-cross-domain-JavaScript-calls.aspx">Iframe and document.domain trick</a> to get around the same-origin policy against cross domain restriction on web-browsers I came across an interesting oddity in Firefox (a hidden security feature if you will!).</p>
<p>The reference page for document.domain setting policy <a href="https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript">here</a> says:</p>
<blockquote><p><span style="color:#808080;">A script can set the value of <code><a rel="internal" href="https://developer.mozilla.org/en/DOM/document.domain">document.domain</a></code> to a suffix of the current domain</span></p></blockquote>
<p><span style="color:#333333;">What is obvious that this prefix can go only upto anything below a top-level-domain (TLD). <a href="http://weblogs.mozillazine.org/gerv/archives/2006/10/dns_structure.html">This page</a> provides some more info about this (in the first two paragraphs).</span></p>
<p><span style="color:#333333;">Armed with this info I expected to be able to communicate between two of my apps, both hosted on google appengine (<em>http://app1.appspot.com</em> &amp; <em>http://app2.appspot.com</em>). The idea was to set document.domain to <em>appspot.com</em> in both, the parent page on <em>http://app1.appspot.com</em> and in the child iframe loaded from <em>http://app2.appspot.com</em>.</span></p>
<p><span style="color:#333333;">Works great in Google Chrome! However, true to its spirit of being a pain in an unmentionable, the cross-browser beast rises again and bites me in the same unmentionable: It fails on firefox! On the JS document.domain = <em>appspot.com</em> on the page hosted on <em>http://app1.appspot.com</em>, it throws an error: &#8220;<strong><em>Illegal document.domain value&#8221; code: &#8220;1009</em></strong>.</span></p>
<p><span style="color:#333333;">A little more digging. I test using </span><a href="http://dyndns.org"><span style="color:#333333;">DynDNS</span></a><span style="color:#333333;">. Now with my apps accessible at <em>http://mydomain1.dyndns.org</em> and <em>http://mydomain2.dyndns.org</em> it works! So it has to be a problem specific to appspot! Is firefox handling appspot.com specially? To be honest I found the idea ridiculous when some colleagues suggested this. But I still decided to give it a try: I search for <em>appspot.com</em> through mozilla source code at </span><a href="http://mxr.mozilla.org"><span style="color:#333333;">mxr</span></a><span style="color:#333333;">. Lo and behold!, there is an entry for <em>appspot.com</em> <a href="http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat">here</a>. Looking for <em>effective tld names</em> on google reveals the mystery.</span></p>
<h2><span style="color:#333333;"><strong>The Mystery: Solved<br />
</strong></span></h2>
<p><span style="color:#333333;">As hinted </span><a href="http://weblogs.mozillazine.org/gerv/archives/2006/10/dns_structure.html"><span style="color:#333333;">here</span></a><span style="color:#333333;"> firefox needed to tell that both <em>.com</em> and <em>.co.uk</em> types of names are valid <em>TLD</em>s (top level domains). To do this they have included a special static file with firefox with a list of all <em>TLD</em>s. So for each entry <em>X</em> in this file you can strip document.domain to any sub-domain of <em>X</em> (<em>y1.X</em> or <em>y2.y1.X</em> or <em>y3.y2.y1.X</em> and so on) but not to <em>X</em> (even if <em>X</em> has dots(.) inside it). The evil piece is the appspot.com is also an entry in this file (so that firefox considers <em>appspot.com</em> as a <em>TLD</em>). As a result the <em>Iframe and document.domain trick</em> will not work for any app hosted on app engine.</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rationalpie.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rationalpie.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rationalpie.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rationalpie.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rationalpie.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rationalpie.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rationalpie.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rationalpie.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rationalpie.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rationalpie.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rationalpie.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rationalpie.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rationalpie.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rationalpie.wordpress.com/245/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=245&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rationalpie.wordpress.com/2011/03/02/special-cross-domain-restriction-in-firefox/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/4246c9fd77ce864b702fa11a9d5f8c6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shashank</media:title>
		</media:content>
	</item>
		<item>
		<title>Posting photo to wall using Facebook Graph API</title>
		<link>http://rationalpie.wordpress.com/2011/02/12/posting-photo-to-wall-using-facebook-graph-api/</link>
		<comments>http://rationalpie.wordpress.com/2011/02/12/posting-photo-to-wall-using-facebook-graph-api/#comments</comments>
		<pubDate>Sat, 12 Feb 2011 18:20:43 +0000</pubDate>
		<dc:creator>Shashank</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://rationalpie.wordpress.com/?p=238</guid>
		<description><![CDATA[First post in 8 months! I have been busy (no, really! ) I have been recently working on a small Facebook app FriendGeo, which is on the verge of being finished as I write. One conclusion: Facebook API is cool, the documentation is NOT. I had my full share of frustration trying to deal with hidden [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=238&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>First post in 8 months! I have been busy (no, really! <img src='http://s2.wp.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )</p>
<p>I have been recently working on a small Facebook app <a href="http://apps.facebook.com/friendgeo" target="_blank">FriendGeo</a>, which is on the verge of being finished as I write. One conclusion: Facebook API is cool, the documentation is <strong>NOT</strong>. I had my full share of frustration trying to deal with hidden (or so it seems) features and, more painful, restrictions on Facebook API.</p>
<p>Anyway, coming back to the topic, my app needs to post an image to the user&#8217;s wall. True to its RESTfulness, the graph API allows you to do so by POSTing to the <em>photos </em>connection of the user. In a perfect world, a simple HTTP POST to <em>https://graph.facebook.com/userid/photos </em>with required parameters (the names of which you are left to guess or google!) should do.</p>
<p>A little bit of tinkering with google search query leads to forum posts like <a href="http://forum.developers.facebook.net/viewtopic.php?id=68871" target="_blank">this</a>. Fortunately, the PHP SDK for the Facebook API allows you to upload the photo by using a simple call to <em>setFileUploadSupport</em>. Unfortunately for me, I am using App Engine as my hosting solution and using Python for writing my backend and the <a href="https://github.com/facebook/python-sdk" target="_blank">official Python SDK for Facebook</a> does not seem to be supporting any such provision. Solution: fall back on Python &#8216;batteries&#8217; and use raw Python and HTTP.</p>
<p>To demonstrate how to do this with a self contained example I have written this small script that creates a <em>test</em> <em>user</em> and uploads a photo from disk to the test user&#8217;s account. The comments in the code below should be enough to guide you through the code.</p>
<p><pre class="brush: python;">
import sys
import os
import itertools
import mimetypes
import mimetools
import urllib
import urllib2
import cgi

try:
    import json
except ImportError:
    from django.utils import simplejson as json

# this class allows you to upload a file to a URL
# using pure urllib
class MultiPartForm(object):
    &quot;&quot;&quot;Accumulate the data to be used when posting a form.
       source: http://www.doughellmann.com/PyMOTW/urllib2/#uploading-files
    &quot;&quot;&quot;

    def __init__(self):
        self.form_fields = []
        self.files = []
        self.boundary = mimetools.choose_boundary()
        return

    def get_content_type(self):
        return 'multipart/form-data; boundary=%s' % self.boundary

    def add_field(self, name, value):
        &quot;&quot;&quot;Add a simple field to the form data.&quot;&quot;&quot;
        self.form_fields.append((name, value))
        return

    def add_file(self, fieldname, filename, fileHandle, mimetype=None):
        &quot;&quot;&quot;Add a file to be uploaded.&quot;&quot;&quot;
        body = fileHandle.read()
        if mimetype is None:
            mimetype = mimetypes.guess_type(filename)[0] or 'application/octet-stream'
        self.files.append((fieldname, filename, mimetype, body))
        return

    def __str__(self):
        &quot;&quot;&quot;Return a string representing the form data, including attached files.&quot;&quot;&quot;
        # Build a list of lists, each containing &quot;lines&quot; of the
        # request.  Each part is separated by a boundary string.
        # Once the list is built, return a string where each
        # line is separated by '\r\n'.
        parts = []
        part_boundary = '--' + self.boundary

        # Add the form fields
        parts.extend(
                     [part_boundary,
                     'Content-Disposition: form-data; name=&quot;%s&quot;' % name,
                     '',
                     value,
                     ]
                     for name, value in self.form_fields
                     )

        # Add the files to upload
        parts.extend(
                     [part_boundary,
                     'Content-Disposition: file; name=&quot;%s&quot;; filename=&quot;%s&quot;' % \
                     (field_name, filename),
                     'Content-Type: %s' % content_type,
                     '',
                     body,
                     ]
                     for field_name, filename, content_type, body in self.files
                     )

        # Flatten the list and add closing boundary marker,
        # then return CR+LF separated data
        flattened = list(itertools.chain(*parts))
        flattened.append('--' + self.boundary + '--')
        flattened.append('')
        flattened = map(str, flattened)
        return '\r\n'.join(flattened)

def get_client_access_token(app_id, app_secret):
    #create an access token acting as if we are a
    #desktop client (we in fact are!). app_id and
    #app_secrets are the parameters that you get
    #get when you create a new app
    params = {
        'grant_type': 'client_credentials',
        'client_id': app_id,
        'client_secret': app_secret
    }

    response = cgi.parse_qs(urllib.urlopen(
                &quot;https://graph.facebook.com/oauth/access_token?&quot; +
                urllib.urlencode(params)).read())
    access_token = response[&quot;access_token&quot;][-1]

    return access_token

def create_user(app_id, access_token):
    #create a test user using desktop-client
    #access token. We need 'publish_stream' and
    #'user_photos' extended permissions
    params = {
        'access_token': access_token,
        'installed': 'true',
        'permissions': 'publish_stream,user_photos'
    }

    params = urllib.urlencode(params)
    url = 'https://graph.facebook.com/%s/accounts/test-users'%(app_id)
    request = urllib2.Request(url, headers = {}, data = params)

    response = urllib2.urlopen(request)
    response = response.read()

    response = json.loads(response)
    return response

def upload_pic(uid, access_token, pic_caption, pic_file_name, pic_file):
    #using access_token for the newly created test user upload
    #an image file from disk (or any other file like source) to
    #the user's account.
    #pic_caption: the caption to the pic
    #pic_file_name: name of the file (used only to guess mimetype)
    #pic_file: a file like object representing the file (one can
    #open a url and use the response here if the file to be uploaded
    #is on the web (and not on the disk)
    form = MultiPartForm()
    form.add_field('access_token', access_token)
    form.add_field('caption', pic_caption)

    form.add_file('source', pic_file_name, pic_file)

    request = urllib2.Request('https://graph.facebook.com/%s/photos'%(uid))
    body = str(form)
    request.add_header('Content-type', form.get_content_type())
    request.add_header('Content-length', len(body))
    request.add_data(body)

    return urllib2.urlopen(request).read()

def do():
    if not len(sys.argv) == 5:
        print &quot;usage: python %s &lt;app_id&gt; &lt;app_secret&gt; &lt;caption&gt; &lt;file_path&gt;&quot;%(sys.argv[0])
        return

    app_id = sys.argv[1]
    app_secret = sys.argv[2]
    p_caption = sys.argv[3]
    file_path = sys.argv[4]

    client_access_token = get_client_access_token(app_id, app_secret)
    user_info = create_user(app_id, client_access_token)

    u_id = user_info['id']
    print 'created test user account with id: %s'%(u_id)

    u_access_token = user_info['access_token']
    user_login_url = user_info['login_url']

    p_file_name = os.path.basename(file_path)
    p_file = open(file_path)

    upload_pic(u_id, u_access_token, p_caption, p_file_name, p_file)
    print 'login as the test user and view the uploaded pic: %s'%(user_login_url)

if __name__ == '__main__':
    do()

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rationalpie.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rationalpie.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rationalpie.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rationalpie.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rationalpie.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rationalpie.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rationalpie.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rationalpie.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rationalpie.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rationalpie.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rationalpie.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rationalpie.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rationalpie.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rationalpie.wordpress.com/238/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=238&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rationalpie.wordpress.com/2011/02/12/posting-photo-to-wall-using-facebook-graph-api/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/4246c9fd77ce864b702fa11a9d5f8c6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shashank</media:title>
		</media:content>
	</item>
		<item>
		<title>Python Streaming gzip Decompression</title>
		<link>http://rationalpie.wordpress.com/2010/06/02/python-streaming-gzip-decompression/</link>
		<comments>http://rationalpie.wordpress.com/2010/06/02/python-streaming-gzip-decompression/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 19:14:46 +0000</pubDate>
		<dc:creator>Shashank</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Accept-encoding]]></category>
		<category><![CDATA[crc check failed]]></category>
		<category><![CDATA[decompress]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[hader]]></category>
		<category><![CDATA[IOError]]></category>
		<category><![CDATA[stream]]></category>
		<category><![CDATA[urllib]]></category>
		<category><![CDATA[zlib]]></category>

		<guid isPermaLink="false">http://rationalpie.wordpress.com/?p=223</guid>
		<description><![CDATA[The gzip module in python works with files. It does not have an interface for decompressing a stream of data. This however becomes a problem if you want to work with files that are difficult (or impossible!) to read in memory at once. A small trick using the zlib library (again in standard python distribution), [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=223&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The gzip module in python works with files. It does not have an interface for decompressing a stream of data.<br />
This however becomes a problem if you want to work with files that are difficult (or impossible!) to read in memory at once. A small trick using the zlib library (again in standard python distribution), however, allows one to achieve this. To demonstrate the problem and the solution, take the example of downloading a web page with compression enabled and saving it to a local file:</p>
<p><pre class="brush: python;">
import urllib2

#size of each block we want to read. since we are unable to read all data at once, we will
#read this many bytes at once and write it to a local file then go back again fetch another block
#write to local file and keep doing this till there is data left to read
READ_BLOCK_SIZE = 1024*8

#use a url that will indeed send compressed data when asked for, some servers choose not to
#even if you are willing to accept compressed data
url = 'http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=282935706'

request = urllib2.Request(url)

#let the server know you are ready to accept compressed data
request.add_header('Accept-encoding', 'gzip,deflate')

response = urllib2.urlopen(request)

#make sure the response is compressed
isGZipped = response.headers.get('content-encoding', '').find('gzip') &gt;= 0

#file to write data to
outFile = open(&quot;bible.html&quot;, &quot;w&quot;)

while True:
  data = response.read(READ_BLOCK_SIZE)
  if not data: break
  if isGZipped:
    #make a file like thing of the read bytes
    data = cStringIO.StringIO(data)
    #open the file-like-thing as a gzipped file
    data = gzip.GzipFile(fileobj=data).read()
  outFile.write(data)

</pre></p>
<p>This code, as I hinted above does not work, what one gets is a checksum failure error, something like<br />
<pre class="brush: python;">
IOError: CRC check failed 0x29cd27b0 != 0x21b93d26L
</pre></p>
<p>This happens because gzip interprets the chunk you read as being a full gzip file (with an Alder32 crc at the end) which is obviously not the case (unless of course your whole file is less than your block size or you read the whole file into a string using read()). For more info on gzip format refer to the <a href="http://www.gzip.org/zlib/rfc-gzip.html">RFC</a>.</p>
<p>A simple way around this problem comes from the fact that gzip is little more than a wrapper around zlib (primarily because most of gzip is more or less zlib based compression, except for some format details).<br />
Use of zlib with a little modification does the trick:</p>
<p><pre class="brush: python;">
import zlib

d = zlib.decompressobj(16+zlib.MAX_WBITS) #this magic number can be inferred from the structure of a gzip file
while True:
  data = response.read(READ_BLOCK_SIZE)
  if not data: break
  if isGZipped:
    #make a file like thing of the read bytes
    
    #no need for file-like-thing
    #data = cStringIO.StringIO(data)

    #open the file-like-thing as a gzipped file
    #data = gzip.GzipFile(fileobj=data).read()
    
    data = d.decompress(data)
  outFile.write(data)
</pre></p>
<p>That&#8217;s it, using this you can decompress any gzipped stream of data</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rationalpie.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rationalpie.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rationalpie.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rationalpie.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rationalpie.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rationalpie.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rationalpie.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rationalpie.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rationalpie.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rationalpie.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rationalpie.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rationalpie.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rationalpie.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rationalpie.wordpress.com/223/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=223&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rationalpie.wordpress.com/2010/06/02/python-streaming-gzip-decompression/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/4246c9fd77ce864b702fa11a9d5f8c6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shashank</media:title>
		</media:content>
	</item>
		<item>
		<title>Linux: Get the command that started a process</title>
		<link>http://rationalpie.wordpress.com/2010/03/28/linux-get-the-command-that-started-a-process/</link>
		<comments>http://rationalpie.wordpress.com/2010/03/28/linux-get-the-command-that-started-a-process/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 10:12:12 +0000</pubDate>
		<dc:creator>Shashank</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[argument]]></category>
		<category><![CDATA[kill]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[starting command]]></category>

		<guid isPermaLink="false">http://rationalpie.wordpress.com/?p=211</guid>
		<description><![CDATA[some times on my machine I have a lot of  long running python scripts detached from tty, so that ps or top will list a lot processes with the name python. Now if suddenly realize that I need to kill one of these scripts, it becomes very difficult to identify which process to kill just [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=211&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>some times on my machine I have a lot of  long running python scripts detached from tty, so that <em>ps</em> or <em>top</em> will list a lot processes with the name <em>python</em>. Now if suddenly realize that I need to kill one of these scripts, it becomes very difficult to identify which process to kill just by looking at their process ID. I use <em>ps &#8211;context </em>to get around this.</p>
<p><pre class="brush: bash;">

:~$ ps --context -e | grep python

824 unconfined                      python run.py scripts/naivebayes/run.py

</pre></p>
<p>This gives me the complete command that was used to start the process and it becomes a lot easier to identify the process now <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rationalpie.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rationalpie.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rationalpie.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rationalpie.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rationalpie.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rationalpie.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rationalpie.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rationalpie.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rationalpie.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rationalpie.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rationalpie.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rationalpie.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rationalpie.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rationalpie.wordpress.com/211/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=211&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rationalpie.wordpress.com/2010/03/28/linux-get-the-command-that-started-a-process/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/4246c9fd77ce864b702fa11a9d5f8c6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shashank</media:title>
		</media:content>
	</item>
		<item>
		<title>Count UpperCase Letters using Python</title>
		<link>http://rationalpie.wordpress.com/2010/03/28/count-uppercase-letters-using-python/</link>
		<comments>http://rationalpie.wordpress.com/2010/03/28/count-uppercase-letters-using-python/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 08:57:37 +0000</pubDate>
		<dc:creator>Shashank</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[capital letters]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[upper case]]></category>

		<guid isPermaLink="false">http://rationalpie.wordpress.com/?p=208</guid>
		<description><![CDATA[Just a small tip To count the number of upper case (capital letters) in a given text use this: to count only those that are not the first letters of the corresponding words<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=208&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just a small tip <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>To count the number of upper case (capital letters) in a given text use this:</p>
<p><pre class="brush: python;">

import re

re.findall(&quot;[A-Z]&quot;, text)

</pre></p>
<p>to count only those that are not the first letters of the corresponding words</p>
<p><pre class="brush: python;">

import re

re.findall(&quot;\B[A-Z]&quot;,  text)

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rationalpie.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rationalpie.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rationalpie.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rationalpie.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rationalpie.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rationalpie.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rationalpie.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rationalpie.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rationalpie.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rationalpie.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rationalpie.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rationalpie.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rationalpie.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rationalpie.wordpress.com/208/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=208&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rationalpie.wordpress.com/2010/03/28/count-uppercase-letters-using-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/4246c9fd77ce864b702fa11a9d5f8c6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shashank</media:title>
		</media:content>
	</item>
		<item>
		<title>WinHugs ERROR &#8211; Undefined variable &#8220;isLower&#8221;</title>
		<link>http://rationalpie.wordpress.com/2010/03/18/winhugs-error-undefined-variable-islower/</link>
		<comments>http://rationalpie.wordpress.com/2010/03/18/winhugs-error-undefined-variable-islower/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 12:58:30 +0000</pubDate>
		<dc:creator>Shashank</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Hugs]]></category>
		<category><![CDATA[isLower]]></category>
		<category><![CDATA[isUpper]]></category>
		<category><![CDATA[undefined]]></category>
		<category><![CDATA[WinHugs]]></category>

		<guid isPermaLink="false">http://rationalpie.wordpress.com/?p=202</guid>
		<description><![CDATA[just a newbie note: a lot of common Haskell functions are defined in the module Prelude (e.g. isLower, isUpper).The default module for WinHugs however is Hugs, hence if you try to access these functions directly (which every newbie does )..you get errors like this . To correct load the module Hugs.Prelude ﻿<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=202&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>just a newbie note:</p>
<p>a lot of common Haskell functions are defined in the module Prelude (e.g. isLower, isUpper).The default module for WinHugs however is Hugs, hence if you try to access these functions directly (which every newbie does <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> )..you get errors like this<br />
<pre class="brush: plain;">ERROR - Undefined variable &quot;isLower&quot;</pre></p>
<p>.<br />
To correct load the module Hugs.Prelude<br />
<pre class="brush: plain;">

Hugs&gt; :module Hugs.Prelude

Hugs.Prelude&gt; isLower 'a'
True

</pre></p>
<p>﻿</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rationalpie.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rationalpie.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rationalpie.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rationalpie.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rationalpie.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rationalpie.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rationalpie.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rationalpie.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rationalpie.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rationalpie.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rationalpie.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rationalpie.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rationalpie.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rationalpie.wordpress.com/202/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=202&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rationalpie.wordpress.com/2010/03/18/winhugs-error-undefined-variable-islower/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/4246c9fd77ce864b702fa11a9d5f8c6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shashank</media:title>
		</media:content>
	</item>
		<item>
		<title>Most searched for RFC</title>
		<link>http://rationalpie.wordpress.com/2010/03/07/most-searched-for-rfc/</link>
		<comments>http://rationalpie.wordpress.com/2010/03/07/most-searched-for-rfc/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 11:38:31 +0000</pubDate>
		<dc:creator>Shashank</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[IETF]]></category>
		<category><![CDATA[most searched]]></category>
		<category><![CDATA[RFC]]></category>

		<guid isPermaLink="false">http://rationalpie.wordpress.com/2010/03/07/most-searched-for-rfc/</guid>
		<description><![CDATA[interesting trivia: Which is the most searched for RFC (request for comment by IETF)? If google is to be believed it is: RFC 1918 (rfc1918) &#8211; Address Allocation for Private Internets<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=200&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>interesting trivia: Which is the most searched for RFC (request for comment by IETF)?</p>
<p>If google is to be believed it is: RFC 1918 (rfc1918) &#8211; Address Allocation for Private Internets <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rationalpie.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rationalpie.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rationalpie.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rationalpie.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rationalpie.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rationalpie.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rationalpie.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rationalpie.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rationalpie.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rationalpie.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rationalpie.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rationalpie.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rationalpie.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rationalpie.wordpress.com/200/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=200&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rationalpie.wordpress.com/2010/03/07/most-searched-for-rfc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/4246c9fd77ce864b702fa11a9d5f8c6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shashank</media:title>
		</media:content>
	</item>
		<item>
		<title>Java: Calling overriden method in superclass constructor</title>
		<link>http://rationalpie.wordpress.com/2010/02/20/java-calling-overriden-method-in-superclass-constructor/</link>
		<comments>http://rationalpie.wordpress.com/2010/02/20/java-calling-overriden-method-in-superclass-constructor/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 12:54:58 +0000</pubDate>
		<dc:creator>Shashank</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Calling overriden method]]></category>
		<category><![CDATA[superclass constructor]]></category>

		<guid isPermaLink="false">http://rationalpie.wordpress.com/?p=189</guid>
		<description><![CDATA[A commonly occurring inheritance design is to have an abstract method in the superclass which is called in the superclass constructor as a way to let subclasses change the way the object is initialized. For example: Superclass: Subclass: The idea is to enforce the constraint that the loadConfig method is always called in the constructor [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=189&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A commonly occurring inheritance design is to have an abstract method in the superclass which is called in the superclass constructor as a way to let subclasses change the way the object is initialized. For example:</p>
<p>Superclass:</p>
<p><pre class="brush: java;">

public abstract class Super {
  public Super() {
    loadConfig();
  }

  protected abstract void loadConfig();
}
</pre></p>
<p>Subclass:</p>
<p><pre class="brush: java;">

public class Sub extends Super {

  protected String var;

  protected void loadConfig() {
    var = &quot;loaded_config&quot;;
  }
}
</pre></p>
<p>The idea is to enforce the constraint that the loadConfig method is always called in the constructor of the object, how the configuration is to be loaded exactly is left to the subclasses.</p>
<p>This however does not work a expected</p>
<p><pre class="brush: java;">

public class Test {
  Sub s = new Sub();
  System.out.println(&quot;var value: &quot; + s.var);
}
</pre></p>
<p>The output is not &#8220;var value: loaded_config&#8221; as a lot of us would expect. it&#8217;s &#8220;var value: null&#8221;.<br />
To understand why, change the Sub class to this:</p>
<p><pre class="brush: java;">

public class Sub extends Super {

  protected String var = setMeth();

  private String setMeth() {
    System.out.println(&quot;Setting member variable with setMeth&quot;);
    return &quot;setMeth value&quot;;
  }

  protected void loadConfig() {
    System.out.println(&quot;Setting member variable with loadConfig&quot;);
    var = &quot;loaded_config&quot;;
  }
}
</pre></p>
<p>Now the output should be:</p>
<p><pre class="brush: plain;">

Setting member variable with loadConfig
Setting member variable with setMeth
var value: setMeth value
</pre></p>
<p>What happens is that in the subclass constructor, the superclass constructor is called before the subclass object is created (that is why you always need to put calls to super() as the first statement). As a result, although the overriden method does it&#8217;s job fine in setting the value of the variable the way we want, just after this happens (from inside the super class ctor), the sub class object is initialized and the value for the member variable is overwritten (by the setMeth in second case and as the default null in the first).</p>
<p>The only way out of this (that I know!) is to move this obligation of calling the loadConfig method on to the subclass implementation code (which is clearly not anyone&#8217;s first choice <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  )</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rationalpie.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rationalpie.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rationalpie.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rationalpie.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rationalpie.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rationalpie.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rationalpie.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rationalpie.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rationalpie.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rationalpie.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rationalpie.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rationalpie.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rationalpie.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rationalpie.wordpress.com/189/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=189&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rationalpie.wordpress.com/2010/02/20/java-calling-overriden-method-in-superclass-constructor/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/4246c9fd77ce864b702fa11a9d5f8c6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shashank</media:title>
		</media:content>
	</item>
		<item>
		<title>Linux http_proxy: escape @ character</title>
		<link>http://rationalpie.wordpress.com/2010/02/20/linux-http_proxy-escape-character/</link>
		<comments>http://rationalpie.wordpress.com/2010/02/20/linux-http_proxy-escape-character/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 04:13:58 +0000</pubDate>
		<dc:creator>Shashank</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[escape @ character]]></category>
		<category><![CDATA[http_proxy]]></category>

		<guid isPermaLink="false">http://rationalpie.wordpress.com/?p=185</guid>
		<description><![CDATA[to use services like wget on linux from behind a proxy server that requires username-password authentication requires setting up an environment variable for the shell usually it suffices to do this: the placeholders having obvious meanings. A problem however arises if the password has an &#8216;@&#8217; character inside it. This @, being a delimiter will [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=185&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>to use services like wget on linux from behind a proxy server that requires username-password authentication<br />
requires setting up an environment variable for the shell</p>
<p>usually it suffices to do this:</p>
<p><pre class="brush: bash;">
shashanksingh@nsl-31:~$http_proxy=http://username:password@proxyserver:80/
</pre></p>
<p>the placeholders having obvious meanings. A problem however arises if the password has an &#8216;@&#8217; character inside it. This @, being a delimiter will mess things up, e.g., if the password were my@pass, the url will become</p>
<p><pre class="brush: plain;">
http://username:my@pass@proxyserver:80/
</pre></p>
<p>wget will then parse it and treat the first @ as if it were the delimiter to mark the end of the password and the beginning of the proxy address. As a result it will assume:</p>
<p><pre class="brush: plain;">
user: username
pass: my
proxy host: pass@proxyserver:80
</pre></p>
<p>and you will get an error like this</p>
<p><pre class="brush: bash;">
Resolving pass@proxyserver... failed: Name or service not known.
</pre></p>
<p>One possible solution that comes to mind is to escape the @. This somehow does not work (for wget at least). So</p>
<p><pre class="brush: bash;">
shashanksingh@nsl-31:~$http_proxy=http://username:\@password@proxyserver:80/
</pre></p>
<p>gives the same error (I wonder if I am guessing the escape character right, if you know why it&#8217;s not working please post in comments <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</p>
<p>A work-around is to create a .wgetrc file. wget loads this file when run (you can find more details <a href="http://www.home.umk.pl/%7Emgw/wget/wget_6.html">here</a>).</p>
<p>A file like this works fine for me</p>
<p><pre class="brush: plain;">
http_proxy=proxyserver:80
proxy_user=username
proxy_passwd=my@pass
</pre></p>
<p>Place the .wgetrc file in your home directory (<em>$HOME</em>) or other possible locations as mentioned in the link above.</p>
<p>UPDATE: while escaping does not seem to work for wget, exporting a http_proxy in .bashrc seem to handle escaping using &#8216;\&#8217;. So if your password is @agrambagram, adding a line at the end of ~/.bashrc works<br />
<pre class="brush: bash;">
export http_proxy=http://username:\@agrambagram@proxyserver:80
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rationalpie.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rationalpie.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rationalpie.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rationalpie.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rationalpie.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rationalpie.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rationalpie.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rationalpie.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rationalpie.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rationalpie.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rationalpie.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rationalpie.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rationalpie.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rationalpie.wordpress.com/185/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=185&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rationalpie.wordpress.com/2010/02/20/linux-http_proxy-escape-character/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/4246c9fd77ce864b702fa11a9d5f8c6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shashank</media:title>
		</media:content>
	</item>
		<item>
		<title>PostgreSQL: Reset root password</title>
		<link>http://rationalpie.wordpress.com/2010/02/18/postgresql-reset-root-password/</link>
		<comments>http://rationalpie.wordpress.com/2010/02/18/postgresql-reset-root-password/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 17:12:09 +0000</pubDate>
		<dc:creator>Shashank</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[forgot password]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[reset root password]]></category>

		<guid isPermaLink="false">http://rationalpie.wordpress.com/?p=171</guid>
		<description><![CDATA[I had an old installation of postgreSQL on my Win32 XP box. I never really used it until today when I was forced to ditch MySQL in favor of postgreSQL. But the classical problem now:  I had forgotten the password for my default postgres account. Since I had no other user(role) created, this meant  had [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=171&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I had an old installation of postgreSQL on my Win32 XP box. I never really used it until today when I was forced to ditch MySQL in favor of postgreSQL. But the classical problem now:  I had forgotten the password for my default <em><strong>postgres</strong></em> account. Since I had no other user(role) created, this meant  had no choice but to forcefully reset my <strong><em>postgres</em></strong> password.</p>
<p>Unfortunately people at postgreSQL seem to be suffering from a widespread tendency of treating a windows user as someone who needs to be punished for committing the cardinal sin of opting windows. I remember several of my batchmates having had their brains fried trying to install postgreSQL on their windows machines (before I stepped in to save them, of course <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> ).</p>
<p>Anyway, enough digression! Here is how it worked out for me:</p>
<ol>
<li>Get the server running:<br />
<pre class="brush: bash;">pg_ctl.exe start -D &quot;C:\Program Files\PostgreSQL\8.3\data&quot;</pre></li>
<li> Open the file <pre class="brush: bash;">&quot;C:\Program Files\PostgreSQL\8.3\data\pg_hba.conf&quot;</pre>
<p>Initial Content:</p>
<p><pre class="brush: plain;">
# TYPE DATABASE  USER CIDR-ADDRESS  METHOD

# IPv4 local connections:
host all all  127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5</pre></p>
<p>Changed to:</p>
<p><pre class="brush: plain;">
# TYPE DATABASE USER CIDR-ADDRESS METHOD

# IPv4 local connections:
host all all 127.0.0.1/32 trust sameuser
# IPv6 local connections:
host all all ::1/128 trust sameuser</pre></li>
<li>reload the server config:<br />
<pre class="brush: bash;">pg_ctl.exe reload -D &quot;C:\Program Files\PostgreSQL\8.3\data&quot;</pre></li>
<li>run:<br />
<pre class="brush: bash;">psql -U postgres</pre></p>
<p>At this point if you get this error:</p>
<p><pre class="brush: bash;">psql: FATAL:&amp;nbsp; role &quot;postgres&quot; does not exist</pre></p>
<p>do this:</p>
<p><pre class="brush: bash;">createuser.exe -s postgres</pre></li>
<li>run this to start command line client:<br />
<pre class="brush: bash;">psql -U postgres</pre></li>
<li>run SQL to change password:<br />
<pre class="brush: sql;">postgres=# ALTER USER postgres WITH ENCRYPTED PASSWORD 'password';</pre></p>
<p>Note that the inverted commas around the password are required but are not a part of the password</li>
<li>Rollback the changes made in step 2</li>
<li>reload the server config again as in step 3</li>
<li>Curse the postgre config for one last time</li>
<li>Get going!</li>
</ol>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:119px;width:1px;height:1px;overflow:hidden;">
<p># TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD</p>
<p># IPv4 local connections:<br />
host    all         all         127.0.0.1/32          md5<br />
#host    all         all         127.0.0.1/32          trust sameuser<br />
# IPv6 local connections:<br />
host    all         all         ::1/128               md5<br />
#host    all         all         ::1/128               trust sameuser</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rationalpie.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rationalpie.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rationalpie.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rationalpie.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rationalpie.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rationalpie.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rationalpie.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rationalpie.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rationalpie.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rationalpie.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rationalpie.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rationalpie.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rationalpie.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rationalpie.wordpress.com/171/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rationalpie.wordpress.com&amp;blog=10934005&amp;post=171&amp;subd=rationalpie&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rationalpie.wordpress.com/2010/02/18/postgresql-reset-root-password/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/4246c9fd77ce864b702fa11a9d5f8c6b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shashank</media:title>
		</media:content>
	</item>
	</channel>
</rss>
