Monday, December 13, 2010

Google translate from shell...

Follows this

#!/usr/bin/env python
from urllib2 import urlopen
from urllib import urlencode
import sys

# The google translate API can be found here:
# http://code.google.com/apis/ajaxlanguage/documentation/#Examples

lang1=sys.argv[1]
lang2=sys.argv[2]
langpair='%s|%s'%(lang1,lang2)
text=' '.join(sys.argv[3:])
base_url='http://ajax.googleapis.com/ajax/services/language/translate?'
params=urlencode( (('v',1.0),
('q',text),
('langpair',langpair),) )
url=base_url+params
content=urlopen(url).read()
start_idx=content.find('"translatedText":"')+18
translation=content[start_idx:]
end_idx=translation.find('"}, "')
translation=translation[:end_idx]
print translation


Usage: filename lang1 lang2 word_or_sentence_to_translate

:)

Sunday, December 12, 2010

Making screenshots under Ubuntu....

1. Install scrot
sudo aptitude install scrot
2. Open configuration editor
gconf-editor
3. Go to apps/metacity/keybinding_commands and change the existing command_scteenshot from gnome-screen shot to scrot '%H-%M-%S_%Y-%m-%d_ccnas.png' -e 'mv $f ~/Pictures/'

Then after Print Screen key is pressed, the screen shot will be created and located in your Pictures folder in your home directory..

:)

Search This Blog