"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects." (Robert A. Heinlein)

Tuesday, 25 November 2008

New toy: Ubiquity

There are so many toys in the 'net and so little time to play with!  I first read about this tool from here almost a month ago.
Ubiquity is a Firefox plugin that let you perform a great variety of operations, simply by typing a command. You can , for example, search on the most famous search engines, send a mail or translate a word.You simply have to activate it with it's hot-key (ctrl-space) and type what you need.
This alone would make of Ubiquity an handy tool, if you do not like put your hands off the keyboard to search what you need in menus and bookmarks using the mouse,  what makes of Ubiquity a really enjoyable toy is how easily you can write your own commands.
Just type "command-editor" to get a simple but effective web based editor where you can write your Ubiquity commands with Javascript. No compiling or deploy is needed you can run your command in Ubiquity as soon as you have written it.
Here is my own ubiquity command to reverse a stringselected or passed as parameter. It's only a step beyond a 'hello world' program but it shows quite well how Ubiquity works.
    /* This is a template command */     
"http://example.com/",       author: name: "MM", email: "MM@mm.com"},       license: "LGPL",
      description: "reverse example",
      help: "just reverse a string",
      takes: {"input": noun_arb_text},
      preview: functionpblock, input ) {
        var template = "result will be: ${result}";
        pblock.innerHTML = CmdUtils.renderTemplate(template, {"result": reverse(input)});
      execute: function(input) {
        CmdUtils.setSelection("You selected: " + input.html);

      function reverse(in){
         var res = "";
         for(var i=in.length;i>0;i++){
              res = res + in(i);
         return res;
More details about programming with Ubiquity on its wiki.