Thursday, November 22, 2012

The single most reason that keeps me using Vim

I've wanted to use all new and cool Code editors that have come around in past few years. Many times I have switched to them determinedly, only to switch back to Vim after a few days. All the fancy features that I see in the screencasts of these code editors are irresistibly inviting. Yet I can't let go of Vim. After thinking a lot about it, I think it boils down to one single reason.

The h-j-k-l-b-e and Ctrl+w, Ctrl+u, Ctrl+d key sequences.

These are key sequences for moving around inside a code window and then switching between multiple code windows. They are what I use the most in Vim (except for typing actual text). Over years my muscles have deeply memorized these keyboard movements. Every other code editor forces me to use arrow keys or mouse to do these navigations. I cannot get used to it even if I try it for a month. Therefore I switch back to Vim.

Of course I diligently install the Vim emulation plugins that come with the respective new code editor I am trying. But the code navigation key sequences are so frequently used that even a slightest departure from the original Vim behavior creates a lot of cognitive friction.

I'm not saying that h-j-k-l is the most intuitive way to do code navigation, but once your fingers memorize those movements it seems impossible to find anything else that can feel as satisfactory.

Water from air

It's fascinating how a really simple idea can change life as we know it. Today I read this news via slashdot about a new startup NBD nano, that is building a device that can extract water from air. The most interesting part is its implications and applications.

we can somehow have a way to tap into one of the largest reservoirs of water, and that being the air
...
And we see this being applicable to anything from marathon runners to people in third world countries, because we realize that water is such a large issue in the world today
...
We’re actually investigating a type of device that can be used for drip irrigation. And we are looking to incorporate this in greenhouses or green roofs in the immediate future
...
We actually see the maritime environment as really a very large market for us because humidity is actually constantly regenerated over a large body of water and then we can pull that humidity from the air to support people who possibly take long trips on yachts, or provide a sort of potable water source that can be run off a solar panel while at sea.
And the underlying technology seems convincing. Amazing stuff!

Sunday, November 18, 2012

Time travel fiction

This year I read two very gripping thriller novels based on Time Travel.

First one was back in January. 11/22/63 By Stephen King


and recently the twin tomes Black Out and All Clear by Connie Willis.

  

They belong more appropriately to thriller genre than Science fiction, despite the Time travel theme.

Building a huge plot where the timelines and characters are interwoven brilliantly is quite a challenging task. Adding time travel to it makes it even more interesting. Not to mention the awkward paradoxes that arise in the Universe where time travel is possible.

Both (actually all three) novels, are highly recommended if you like reading stories that keep you at the edge of your seat most of the time. Last sentence of almost every chapter is bound to surprise you. (My personal observation: Such novels are really good to improve your reading speed)

In 11/22/63 Stephen King tells the story from a man's point of view who has found a portal through time that opens in the past - more accurately in the year 1958. The entire novel is based on this man's attempt to exploit this portal in order to stop the Kennedy Assassination in 1963. King's description of the America in 60's is very inviting (if only we knew of such portal). The ups and downs in the whole novel keep you entertained all of the time. Here is one of my favorite quotes:

"I saw that most of the passengers were smoking. The atmosphere in there must have been roughly akin to the atmosphere on Saturn" [in reference to popularity of smoking in the 60's]

Black Out and All Clear are two novels continuing the same storyline. The story is about a group of students of history from the year 2060, who travel back to the years of World War II, to study the history first hand (as part of their research assignments) and get trapped in the past. The narration of London during the entire period of war is quite fascinating. The characters of the story live through the London bombings because their portals back to their time stop working for some reason.

Although in 11/22/63, Stephen King has conveniently dumbed down the paradoxical implications of time travels; Connie Willis bravely weaves her story on top of them. Of course no one can give foolproof resolution for the impossible issues that arise with the concept of time travel. However Connie has been fairly successful in building a maze of mysteries and then using her flavor of Time travel theory to explain those mysteries satisfactorily. You have to admire how much work she must have put into these two novels.

Highly recommended.

Thursday, October 11, 2012

When your git branch diverges from your remote

This is a tricky state and in past when I occasionally got myself into it I could never cleanly recover from it. Until now. I just found a clean way.

What's this tricky problem?

You know that git commit --amend is a very useful way to make changes to your last commit. You can add a couple of diffs to it or just change the commit message. It works great as long as you haven't pushed that commit to any remote. If the remote already has your last commit and now you make changes to it locally, your local branch and the remote branch are going to diverge. You will get a message like this

# On branch master
# Your branch and 'origin/master' have diverged,
# and have 1 and 1 different commit(s) each, respectively.

If you try to push to remote, git won't let you (if I recall correctly). Therefore I almost always check whether I've pushed the commits to origin/master before I try to invoke --amend. But sometimes accidentally I forget to check and end up in this tight situation. Well today I got a way to resolve it.

The state of your git repository is like this

Remote: A --> B
         \
Local:  A --> C

After commit A, you created commit B and pushed it to the remote. Then you accidentally did --amend on commit B and changed it to commit C. Here are the steps to recover.
  1. Rewind C. In the past I described different ways of undoing a commit. One of them helps us here. We run git reset --soft HEAD^ to rewind commit C. That is, the changes in commit C come back to the staged state. Now these changes are sum of the diffs that went in commit B and the changes you added with --amend. 
  2. Note the changes you did in --amend (copy them somewhere, hopefully they weren't many). 
  3. Now either erase these changes with git checkout or stash them away with git stash save
  4. Now do a git pull. This will bring your local repo in sync with remote. i.e. your repo's HEAD will now be at commit B. 
  5. Now do the changes that you were trying to commit with --amend (that you saved somewhere earlier). 
  6. Now commit them as a new separate commit D. 
  7. If you had stashed the old mixed changes, do a git stash clear to loose them.
That's it. Now your local and remote branches will look like this after you push

Remote: A --> B --> D
         
Local:  A --> B --> D


Thursday, October 04, 2012

Something like Olivia - John Mayer

One of the best lyrics in John Mayer's latest album - "Born and Raised".

You find a deeper meaning when you ask why he says "Something" and not "Someone".



(and yes, I would like to believe he means Olivia Wilde :)