October 2008


I frequently use Google for finding several definitions. It feels always painful to run browser every time to grab some definitions. Being a terminal lover, I always wanted to do it on commandline. I wrote a few lines of python code, and its done.

I love this utility.
Cheers !

#!/usr/bin/env python
import urllib2,re,sys
 
def usage():
	if sys.argv.__len__() is not 2:
		print "usage: define < word >\n"
	else:
 
		txt = define(sys.argv[1])
		if txt is not None:
        		print '\n\033[31mDefinition of ' + sys.argv[1].upper() + ':\033[0m\n'+ txt+ '\033[0m\n'
		else:
        		print "\nNo definition found\n"
 
def define(str):
	opener = urllib2.build_opener()
	opener.addheaders = [('User-agent', 'define grabber by t3rm1n4l')]
        try:
 
		txt=opener.open('http://www.google.com/search?q=define:'+ str)
        	txt=txt.read()
        	regex = re.compile("<li>[a-zA-Z,. ]*\.\.\.")
        	obj = regex.findall(txt)
        	return obj[0][4:]
 	except:
		pass
usage()

UPDATE: toolz suggested me that it would be nice to print all the definitions avaliable.

So I have updated the script with more options :)

get it here

Google is playing more with User-agent strings. You won’t find same search results for different User-agent strings :). That’s fun.

$ define keyword -all # for printing all definitions
$ define keyword -4 # For printing 4 definitions
$ define keyword # prints 1 definiton

define utility

Accidents are always unexpected. I had never ever thought even in dream that a computer will become my killer. Today I witnessed to see two computers turned to be my villain. Although it is really stupid to blame a computer, its fun. :D. The reality is unluck trapped me.

Today I had been to NITC’s technical fest Tathva 2008 for participating in Tux of War contest. The prelims went very fine and found myself on the of the prelims result. I went to Software Lab along with other MECians. Navin and I sat in front of a DELL machine. I found some problem with the keyboard that sometimes ‘Return’ was not working. I reported the same. The organisers told us to use the adjacent machine. we tried next one. It had problem with Shift and Return. So we decided to move to the previous one. We received the questions for round 2. I felt very confident to do 3 out of 5 questions. We started working with those idiot keyboard. It was very frustrating to work with it. Keys are not pressed as easier. Damn.. the keyboard gifted us with syntax errors. The machine started behaving wild, when I press some keys letters are not printed instead some applications and windows were opening. Seemed like some keypress jam. I called the organisers more than twice and they came and slapped the keyboard. It stopped misbehaving. When we were about to complete 2 problems, suddenly machine crashed. It stopped working. I called organisers again, they tried rebooting but it failed. I moved to the second machine, the one which had Shift and Return working very bad. I slapped hard the keys to print on screen. 3rd round arrived. We felt good that 3 problems can be done confidently. We started working.. 2 of them almost completed. The time was up. The Tathva guys transferred the old 2 scripts from the last machine. I was in a hurry and was trying to arrange the scripts I have wrote in problem no wise. Accidently I overwrite 2 bash scripts. !!

Finally, in a loser’s words I would say that the DELL keyboards I worked with sucks ! ( Loser in the sense that I couldn’t do what I knew). I don’t want to blame any organisers of NITC or Tathva team. They had done good job. It was my mistake, that I couldn’t perform well and was really trapped by unluck.

A real winner is the one who always can respond well with respect to the situation.


The other part of Tathva

Tux of War event for Tathva was organised very good. The questions were of good standard. It consisted of 3 rounds,
1. Preliminary
2. & 3. scripting round.

NITC software Lab looked great with various distros liked OpenSuse, Debian, Fedora installed on boxes.

It was really great to feel that We the team MEC, contributed a very good number of participants to the event. (around 50). 20 participants were from my class.



The Tux of War event was filled with 9 out of 17 MEC teams won in prelims. The results will be out only by tomorrow. We had a great time to enjoy at the event.

Solutions are here