2012-02-28

annoying google

At some point, google search results stopped linking directly to the destination, instead, they changed to point at http://www.google.com/url?BIGUGLYMESS, which I normally don't mind, but when the url links to some resource you want the URL for that your webbrowser downloads, it's quite annoying.

~/$ python
Python 2.7.2+ (default, Oct  4 2011, 20:06:09) 
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
>>> urllib.unquote('https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCcQFjAA&url=https%3A%2F%2Fep2012.europython.eu%2Fmedia%2Fconference%2Fslides%2F5-years-of-bad-ideas.pdf&ei=gF5NT5j0DbCasgLp94Qh&usg=AFQjCNG38H3baMjpc9vw68G_mP8JpBAVSA&cad=rja')
'https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCcQFjAA&url=https://ep2012.europython.eu/media/conference/slides/5-years-of-bad-ideas.pdf&ei=gF5NT5j0DbCasgLp94Qh&usg=AFQjCNG38H3baMjpc9vw68G_mP8JpBAVSA&cad=rja'
>>> 

Bleh.

unholy python

import dis, sys

def return_value_used():
    frame = sys._getframe(2)
    code = frame.f_code.co_code[frame.f_lasti:]
    try:
        has_arg = ord(code[0]) >= dis.HAVE_ARGUMENT
        next_code = code[3 if has_arg else 1]
    except IndexError:
        return True
    return ord(next_code) != dis.opmap['POP_TOP']

def foo():
    if return_value_used():
        return 42
    print 'doom'

foo()
print foo()
--
This outputs:
doom
42

Well that's... unholy.

(I'm also quite late to this party; Youtube video of the talk or the pdf)