Archive for the 'Uncategorized' Category

dict.org client with Ruby Shoes

Friday, May 2nd, 2008

While reading blogs and other online documents, emails etc, I always come across words whose meaning is not known to me. Usually I lookup these words using Ubuntu’s Dictionary application . Copying the word, pasting it in the text field of the dictionary app, hitting “Search”, and then waiting for results – this was proving to be a difficult process, as I have to do it very often. Today morning Vamsee told me about dict.org and that it has an API. So I thought of using dict.org’s API to build a tiny application that would help me lookup unknown words easily, preferably in a single step.

dict.org follows the standard Dictionary protocol. One could connect with TCP to ‘dict.org’ at 2628, and use the requests specified in the protocol to lookup words.

telnet dict.org 2628
Trying 72.36.131.187…
Connected to dict.org.
Escape character is ‘^]’.
220 aspen.miranda.org dictd 1.9.15/rf on Linux 2.6.18-6-k7 <auth.mime> <13095488.4831.1209719617@aspen.miranda.org>

DEFINE english freedom
150 10 definitions retrieved
151 “Freedom” gcide “The Collaborative International Dictionary of English v.0.48″
Freedom \Free”dom\ (fr[=e]“d[u^]m), n. [AS. fre['o]d[=o]m;
fre['o]free + -dom. See {Free}, and {-dom}.]
1. The state of being free; exemption from the power and
control of another; liberty; independence.
[1913 Webster]

But most of the languages already have dict.org API wrappers. A list is given here. I tried the Ruby and Python APIs, they are pretty straight forward. I also found a ‘dict’ program, which is a dict.org client.

sudo apt-get install dict

$ dict freedom

It dumps the meaning of the word as well as similar words from thesaurus on to the terminal. Now my idea was to build a simple GUI to ‘dict’. To do it in a flash, i decided to use Ruby Shoes, a light weight GUI tool kit in Ruby. More about Shoes and its installation can be read from Divya’s article on Shoes.

First step was to create a Ruby interface for dict.org using the ‘dict’ client.

IO.popen(”dict #{word}”).read

Now using this interface, I made a normal dictionary application using Shoes – one with a text field and search button. On clicking the button, the word in the text field will be looked using dict aand result will be displayed in the window. It worked well, but it did not have any advantage over the dictionary application already available with Ubuntu. I wanted the whole lookup process to happen seamlessly for the user, disturbing his reading flow as less as possible.

So i decided to use the clipboard. User now simply has to select a word. My program will pick it up from clipboard and lookup the word in dict.org and have the meaning, thesaurus and other details ready in a flash. All the user has to do is to select a word..!

My dict.org client with Ruby shoes is available here.

You can run it like this :

$ shoes dict.rb

Print

Unni’s article gets featured in LinuxGazette

Friday, April 4th, 2008

As you might notice, my blogging has gone down a bit – and you might have also observed that there are lot more posts by Unni & Divya, my colleagues. Chalk that up to new projects, and lots of higher priority items. I’m slowly coming to realize, running an actual business is not so easy as they make it sound. But, it’s an amazing ride, for sure.

Coming to the point, I encourage our developers to take some time off at least once every week and do something they think is fun. Yes, it’s very much based on Google’s 20% time, but we try to make it a group event rather than an individual one. And Unni comes up with some pretty fun projects. One such project, which he blogged about here, was recently featured in LinuxGazette. He might be too modest to post about it here, so I’m doing it for him :) (check out the editor’s comment – pretty funny).

Good stuff guys, keep going.

Print

JuggerNaut – Push Server for Rails

Friday, March 14th, 2008

When we build a web page that contains data which gets updated very frequently (eg: Share price of Google, or score of a live cricket match), it would be extremely useful if we could ‘push’ data into the webpage, without the user having to ‘pull’ the data by reloading the page or requesting explicitly.

Juggernaut is a Ruby on Rails plugin that helps to implement this ‘push’ mechanism. Comet is the widely accepted technology for doing the same. Juggernaut claims to have a few advantages over comet. Details can be found here.

Apart from the Rails application, juggernaut runs a separate push server, which maintains persistent socket connection with all connected clients. Ruby app sends data to this push server, which pushes the data to all connected clients.

Juggernaut initiates a flash xmlsocket between server and browser allowing real time communication between the two. The open socket connection allows the server to ‘push’ base64 encoded javascript to the browser which is subsequently decoded and evaluated.

juggernaut.jpg

Installation and configuration of Juggernaut are explained in detail in the Juggrenaut page.

I tried to build a simple Juggernaut-Rails application that would push the current playing song name in my system(rails app runs on the same machine). It was fairly simple, current playing song name was extracted using the Dbus interface of Rhythmbox music player (More details on this can be found in my article on IPC with Dbus. Once the songname was obtained, pushing it to the browsers required only the following code in the controller:

 render :juggernaut do |page|
      page.replace_html 'song_name', "<b> #{song_name} </b>"
 end
Print

Keyboard lights & Ruby

Wednesday, February 20th, 2008

I happened to see a ruby library called Blinkenlights, which helps to control the three LEDs (Caps lock, Scroll lock & Num lock) on keyboards. I have written few simple programs to play with the keyboard LEDs – basically simulation of three experiments I did in my Digital Electronics lab – Binary Counter, Ring Counter & Johnson Counter.

sudo gem install blinkenlights

Binary Counter

A counter that counts from 0 to 7 in binary, using the three LEDs as three bits. 0(000) – All LEDs will be turned off, and 7(111) all of them turned ON.
counter.rb

super user privilege is required to access the keyboard, so run it as

sudo ruby counter.rb

Ring Counter

Starting with 4 (100), we right shift to get 2 (010), again right shift to get 1(001), and then start over again with 4. This causes the keyboard LEDs to turn ON and then OFF one by one.

ringcounter.rb

Johnson Counter

This is the Johson counter sequence : 000,001,011,111,110,100,000,001,…

johnsoncounter.rb

Print