Inject a newline in a linux command’s output to improve readability.

(for posterity, ’cause I always forget…)

  • Add alias:
alias nl="sed 'N;s/\n/\n\n/'"
  • Enjoy! For e.g.
ps -ef | grep -i username | nl

This injects an extra newline after every newline in the command’s output. Makes it much easier to read verbose output such as searching for java server processes (glassfish, WL) which have really long command lines.

Cherry-picking a GIT merge commit from a branch.

Git doesn’t let you cherry pick a merge commit from one branch on to another branch. For e.g. a:

git cherry-pick ac61858fac21c33f47e95f3bac4c8cc3a643195b

Where ac61858 is a merge commit generates the following error:

error: Commit ac61858fac21c33f47e95f3bac4c8cc3a643195b is a merge but no -m option was given.

This is because the merge commit is merge of two lines of development. So when using it to cherry pick to another branch, GIT doesn’t know which of the two branches to merge to the destination branch.

This is explained @ http://stackoverflow.com/a/12628579/209952.

In order to get this to work, you need to use the -m option, with the parent to pick.

Also, cherry pick commits the changes with a message right away. If you want to avoid an immediate checkin, use the -n option.

So, say you have a RELEASE branch with two merge commits C1, C2. You want to merge these changes (and only these) back to, say, MASTER. Here’s how you would go about it:

git checkout MASTER
git cherry-pick -n -m 1 C1
git cherry-pick -n -m 1 C2
git commit -m"Merging feature xyz changes from RELEASE to MASTER"

Note the “-m 1” in the above commands. 1 means in include changes merged to RELEASE, 2 would mean use the state of RELEASE at the time of merge.

Turning code formatting off and on in Eclipse

Eclipse allows you to turn code formatting on and off for a certain section of your code. This is extremely helpful when, say, you want to temporarily comment out a block of code and you end up formatting the file. Eclipse will have mashed up the whole comment block into an unrecognizable mish-mash.

To avoid this, you can surround that code (or comment) block with the following:


// @formatter:off


your code block


// @formatter:on



Remember, for this to work, you have to enable these tags in the code formatting preferences.

In Eclipse preferences: Java > Code Style > Formatter. Click on “Edit” button, “Off/On Tags”, check off “Enable Off/On tags”.

You can even select the text you want, the default being “@formatter:off” and “@formatter:on”.

Code on!

How to change the default search engine for the FireFox address bar

Here’s how you do it…

Change the default search engine of FireFox address bar:
With FireFox you can search simply by typing your search terms in the address bar (that’s where you see your current URL). In this case, the default search engine will be used to search.

  1. Open about:config in Firefox (if you doing it for the first time, you may have to promise you are going to be careful)
  2. Search for keyword.url from the filter box.
  3. Double click on this entry. It will open a dialog where you can edit the ‘keyword.url’ string.
  4. Change this string to whatever you want it to be:

To use Google search, change the string to: http://www.google.com/search?hl=en&q=

Duct tape programmers – A slightly older, but good read.

Duct tape programmers are pragmatic. Zawinski popularized Richard Gabriel’s precept of Worse is Better. A 50%-good solution that people actually have solves more problems and survives longer than a 99% solution that nobody has because it’s in your lab where you’re endlessly polishing the damn thing. Shipping is a feature. A really important feature. Your product must have it.

More @ http://www.joelonsoftware.com/items/2009/09/23.html.

Customizing iGoogle…

I’ve started using iGoogle as a sort of “dashboard” for stuff that I need to check on every once in a while. Love iGoogle for that.

The problem? 
I don’t like the standard Google search box that appears at the top of every iGoogle tab. With the logo, the text box and the buttons, it takes up too much screen real estate for a dashboard. If I need to search, I have the Google classic search page set as my homepage. No need to mix the search with the iGoogle gadgets…

The solution?
Two nifty little FireFox extensions, AdBlock+ and Element Hiding Helper for AdBlock+.

Rolling your own search plugin for FireFox

Just created my first search plugin for FireFox, for the Motley Fool CAPS site..

Here’s how:

Make sure you know the search URL. For e.g. searching for “test” on google.com gives you the following URL: “http://www.google.com/search?q=test”.

    • Start with the MyCroft Search Plugin Submission Utility
    • Enter the information in the form. Substitute the search query in the search URL with “{searchTerms}”. This would mean the google search query would be “http://www.google.com/search?q={searchTerms}”.
    • Hit the “Generate Plugin” button. This generates some XML in the text area below the button.
    • Save the generated XML to the FireFox searchplugins directory (typically “C:\Program Files\Mozilla Firefox\searchplugins” on Windows) as a .xml file.
    • Restart FireFox. 

    You should see the search box next to the (awesome?) address bar have a new dropdown option for the search you just added. Note also that you’re missing a neat little icon that other search engines in the dropdown have.

    To add this icon, go back to your XML file.

    • Notice the tag in the file? This needs to be updated.
    • Save the icon you wish to add to the search engine to your desktop. This is typically the favicon file for the website you are building the search engine for ( for google).
    • Now you need to base64 encode this icon file and copy the generated text to the element. I used the one @ http://software.hixie.ch/utilities/cgi/data/data.
    • The encoded string will be a long string of the form “data:image/x-icon,%01%01%10%10%…”.
    • Replace the text in the tag with this encoded string. For e.g. data:image/x-icon,%01%01%10%10%…
    • Restart FireFox.

    There should see the icon added to your search plugin.

    See, it’s not that hard, if you know the steps :-).

    "When in doubt, leave it out"

    Heard this little gem of an advice, while watching a Youtube video interview of Joshua Bloch.

    Effective Java Programming with Joshua Bloch

    Less is more. If you’re not sure if you need to add a certain capability, leave it out. You cal always add it later.

    Beautiful advice. Over the years, the one thing that I’ve seen is that if you make a product that is chock-full of complex features, multiple configurations, etc, most users will just go with the defaults that you give them. So the payouts of having a complex set of features usually isn’t there. So go ahead, be lazy! If it’s not required, don’t do it.