Archive for January 2009
Javascript: My first Mozilla Ubiquity Command
I learned about Mozilla Ubiquity yesterday through my colleague Arnab Deka and I read the article about on the bus on my way back home on Instapaper iPhone application and I installed it a little over an hour ago and I am already loving it.
It already comes a lot of command built in but when I looked for a dictionary look-up command I didn’t find it. The closed was the define command which takes you to answer.com.
I thought this was a good way to add my favorite dictionary.com look up command and familiarize myself with how to add a new ubiquity command.
Here is what I came up with in less than 15 minutes using the template and tutorial:
/* This is Ali Rizvi's ubiquity first command */
CmdUtils.CreateCommand({
name: "dictionary",
// icon: "http://saaridev.wordpress.com",
homepage: "http://saaridev.wordpress.com",
author: { name: "Ali Rizvi", email: "@gmail.com"},
license: "Ruby License",
description: "Command to lookup a work on dictioanry.com",
help: "dictionary <word-to-lookup>",
takes: {"input": noun_arb_text},
preview: function( pblock, input ) {
searchText = jQuery.trim(input.text);
if(searchText.length < 1) {
pblock.innerHTML = "Searches for word on dictionary.com";
return;
}
var previewTemplate = "Searches dictionary.com for <b>${query}</b>";
var previewData = {query: searchText};
pblock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
},
execute: function(input) {
var url = "http://www.dictionary.com/browse/{QUERY}";
var query = input.text ;
var urlString = url.replace("{QUERY}", query);
Utils.openUrlInBrowser(urlString);
}
});
When I hit the save button ubiquity command editor posted this gist. Anybody know how to add js syntax highlighting on github gists?
Vim: Auto indenting based on filetype
I had two different behaviors on my windows and linux machine when I used Vim to edit my ruby files.
I liked the auto-indent behavior I had on my windows machine but I did not know how to make it happen on my other linux machine.
I finally invested sometime to find out the difference between the two:
At first I thought I was simply missing
set autoindent
but I verified that I had that in both of my vimrc files.
The difference was that on my windows machine I was using the vimrc_example file which came with this line:
" load indent files, to automatically do language-dependent indenting. filetype plugin indent on
This did the trick and I am so happy now.
Now when I start an if block and hit enter the second line starts with the appropriate indentation and when I type end the editor automatically indents it to the previous indentation level of the appropriate block of code.
Cheers!