Vim: Tabs like firefox in non-gui vim
This might be old news for some but today I discovered firefox like tabs (not to be confused with tab character for indenting) in vim (not gvim).
To open a file in a new tab while inside vim simply do:
:tabe filename
To open all files in a directory in vim tabs from command line do:
vim -p dir_name/*
To move around in tabs in command mode you do:
gt
It is hard to google for them as it is easy to confuse them with tab character. Here is the online doc page for them:
http://vimdoc.sourceforge.net/htmldoc/tabpage.html
The current tab was setup to be not underlined vs other tabs were underline I discovered the way to show current tab in reverse:
:highlight TabLineSel cterm=reverse
Of course the options are endless and when I shared this discovery with Arnab he told me there is an entire chapter about this in the swroopch’s Vim book actually it one section in his Book.
Thank you Daniel Wong for introducing me to vim tabs. It was instant pay off on encouraging Daniel to use either use a real programmers’ editor like Vim or Emacs instead of gedit and teaching him the basic Vim (once he choose my choice of text editor on his own, I did not pressure him, honest).
How to tweet about your latest post on wordpress.com?
One of the reasons I like posterous (other than its awesome multimedia media support) is that when I create post their I can set it up to tweet to my twitter account about my latest post.
WordPress.com is still my first love when it comes to blogging so I thought there has to be a way to tweet about my new post and I finally found it after a lot of googling. So it is a bit obscure.
* Login to wordpress.com
* Go to your blog’s dashboard by clicking “My Dashboard”
* Click on “My Blogs” under Dashboard
* In front of the blog name you want this for (in case you have multiple blogs like me) look for the “publicize” column and check Twitter. WordPress uses oAuth to authorize (did not ask me my twitter login)
* Post new blog entries on WordPress.
Cheers!
PS: Did not find this (http://en.support.wordpress.com/publicize/) when googling but when I searched for wordpress.com publicize.
Oracle: Explain Plan from SQLPlus
I have been spoiled by simple way for getting a explain plan from MySQL and web tools for oracle.
Today somebody asked me how to get an explain plan from oracle command line sqlplus and I discovered it is a little painful. Here is what I found out:
explain plan for select * from shiny_complex_table;
select
substr (lpad(' ', level-1) || operation || ' (' || options || ')',1,30 ) "Operation",
object_name "Object"
from
plan_table
start with id = 0
connect by prior id=parent_id;
Reference: http://www.adp-gmbh.ch/ora/explainplan.html
Blogging from wordpress iphone app
Two new apps I always wanted was the dropbox app and wordpress app, today is my lucky day I got them both.
Vim: Converting to JavaCase to ruby_case
This morning I was in a mode to do a regex kata and thought it would be interesting to see if I can substitute CamelCase (I call it JavaCase for fun) to underscore_separated_words (I did a search and could not find a good word for this so) I will call it ruby_case.
Here is how I started (note in my setting of vim you have to escape parens \):
:%s/\([a-z]\)\([A-Z]\)/\1_\2/gc
The above matches lowercase letter followed by uppercase letter and captures them then replaces them with underscore between them.
:%s/\(\l\)\(\u\)/\1_\2/gc
I found that Vim has metacharacters for upper (\u) and lowercase (\l). So above become cleaner version of the previous, call it refactoring. (JavaCase => Java_Case)
:%s/\(\l\)\(\u\)/\1_\L\2/gc
I found how to change an uppercase capture to lowercase. But this was leaving first character of the word still uppercase (JavaCase => Java_case)
:%s/\(\<\u\).*\(\l\)\(\u\)/\L\1\2_\L\3/gc
In this attempt to capture the first letter and lower case it I lost the letters in between. (JavaCase => ja_case)
:%s/\(\<\u.*\)\(\l\)\(\u\)/\L\1\2_\L\3/gc
Finally, I got what I wanted. (JavaCase => java_case) Hurray!
But I notice the match is greedy, so if there are multiple CamelCase on the same line this would fail.
For now I will leave this as an exercise for the reader as I am out of time for now, when I have a solution I will add it here.
This was a fun little exercise and I enjoyed it very much. Now I can find and solve a problem like this every morning it will jump start the day.
Reference: Vim Regular Expression 101 (http://www.geocities.com/volontir/)
Cheers!
Book: Pragmatic Thinking and Learning
The frisson never died. The excitement kept me turning one page after another. Andy Hunt’s Pragmatic Thinking and learning : Refactor Your Wetware is life changing and I highly recommend it to all Software Developers new and old.
Pragmatic Thinking and Learning (PTL) is full of ideas and insights. It is based on a lot of research and background reading. It would save you a lot of trouble of going through a lot of books and research to learn the same material which might not be written this well. I had already read some of the books mentioned in the book, some were on my candidate list and some I added to my candidate list based on citations from this book but this is a concise collection of all these tips and tricks you learn from all these books (some of them I will never read as they are research on neuroscience and nursing professionals).
What does Pragmatic Programmer and Pragmatic Thinking and Learning have in common besides practical advice, tons of insight and being my all time favorite books? Andy Hunt. Andy is awesome. Not only he writes well he is a very articulate speaker. In fact the way I got introduced to this book while it was being written was a talk he gave at my company. This book is so much more than that talk I loved.
I will write more about the practical tips as I act on them in the future in this blog or on my twitter but for now I just wanted to give a shout out for this fantastic book.
If you want to buy it from my favorite book seller online here is the link.
*nix: Comparing two files
Everybody knows about diff.
I read about sdiff today for side by side diff.
Here is the one I found useful in some cases but I forget it so I am saving it here:
NAME
cmp – compare two files
SYNOPSIS
cmp [-l | -s] file1 file2 [skip1 [skip2]]
DESCRIPTION
The cmp utility compares two files of any type and writes the results to
the standard output. By default, cmp is silent if the files are the
same; if they differ, the byte and line number at which the first differ-
ence occurred is reported.
May be I will add some examples to show the difference but later.
Software Development: Correctness, Completeness, Performance, In That Order
Software development is the act of converting thoughts into actions. In other words goal of software development is to convert requirements into code but this can’t be done in one step and in a single iteration.
Each iteration in the software process you need to get a piece of requirement convert it into design, write a test, add new code and potentially refactor existing code to implement it.
For every piece in each iteration you want to follow the ordered sequence of correctness, completeness and performance. In other words, get it right, get it working, get it fast.
When understanding the requirement you want to make sure you are getting the right requirement basically understand what customers want not what they think they want. Often in requirement gathering phase the customer is biased to what they are used to or how they want something rather than letting you know the input and output they desire from a feature. Your job is to get to the bottom of it by asking good questions.
In the context of requirements completeness means that you not only understand the input and output but the entire context to implement the feature correctly. Once you understand what and in what context only then you turn your attention to performance requirements (if any) as discussion of performance earlier might not be in context and well understood where the customer is coming from. All these discussion do not have to happen at the same time but in should happen in that order.
I think I have already explained the hardest part in the whole iteration. Requirements is often where we get it wrong and the hardest/most-expensive one to correct after the fact.
When it comes to writing code you also follow this sequence, make sure you are implementing what you intend on implementing by writing unit tests first. The act of trying to write test first often force you to think about what you are about to do. You repeat this process until you have met all the requirements for the feature (completeness) and only then you measure performance and do any performance tuning if necessary. Software developers are not only often guilty of the thought crime of premature optimization but actually commit this crime if not stopped in time.
Do you think my thoughts are incorrect, incomplete and would not scale? Please send me a thought patch in the comments.
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!