Category Archives: Uncategorized

git stashing & branching

Just discovered something useful today.

Workflow:
– I am working on something on my “master” branch
– I need to update master with some new stuff from a remote.
– I don’t want to mess up with my current changes

Here is the best way to do it in my opinion (works with git 1.6 and above).

git stash save "some stash name"
git stash branch stash@{0} # assuming you only have one stash, otherwise git stash list to know the exact index

You changes should end up in the new branch and you can checkout your master branch to get the new changes from the remote repository.

Convention over configuration over convention

Convention makes everything easy and smooth (Rails, …). Configuration is long, tedious and painful and . Documentation is great and necessary in both cases.
However, I favor Configuration with a set of defaults to magic conventions that are supposed to make my life easy. There are many reasons to this but the main is: “I do not want your thing to get in my way”.

Using git-stash with a branch

You’re working on something on master but you want your changes to be transfered to a branch

Do this:

[17:44:40][akadri@kryptonite:~/Projects/myproject]$ git stash save "message"
Saved working directory and index state On master: stash message
HEAD is now at 821a965 commit message

You can list your stash with:

[17:48:09][akadri@kryptonite:~/Projects/myproject]$ git stash list
stash@{0}: On master: stash message

Now you transfer your changes to a new branch of your choosing and checkout that branch with:

[17:51:54][akadri@kryptonite:~/Projects/Wikipedia]$ git stash branch mybranch stash@{0}
Switched to a new branch 'mybranch'

That’s it!

vim tips

These three lines in ~/.vimrc just changed my life!


let g:netrw_preview = 1
let g:netrw_liststyle = 3
let g:netrw_winsize = 30

and then :Explore works the way it should! Just type “p” to open a file in the preview window and bd or bw to delete a buffer (which doesn’t close the preview window and that’s what I like about it!). Ctrl-W-W to switch between Tree selection and preview window.

:help explore to learn more

The help file is pretty cryptic but it actually helps!

PhoneGap Bada

These past two months I’ve been working on porting the PhoneGap mobile framework to the Samsung Bada platform at Nitobi. The Bada SDK is in C++ and I hadn’t touched C++ in years. It was nice to come back to a compiled language tough after years writing scripting/interpreted languages such as Python/Ruby/PHP or Java.

So far everything is pretty much working except Media and File Handlers. Samsung was kind enough to send me a Wave GT-8500 to test with. Details on how I implemented the thing are available on my nitobi blog.

The source is available on github

It is under MIT License

Check it out and share your thoughts/comments!

Vim Search/Replace/Increment

let’s say you have this in a text file:

item
item
item

and you want to change it to this

ordered_item_1
ordered_item_2
ordered_item_3

You can do this in VIM with the following command:

let i=1|g/item/s//\=”ordered_item_”.i/|let i=i+1

You can do it even more easily using AWK but VIM forever!

Keep a task running

so you’ve got task that you want to run but you need to leave right away and you have to logout.

If you do a “command &” it will certainly run and in the background but if you logout it’ll go away. So how can you keep it running ?
With the “nohup(1)” utility. Preceed your command with nohup and end it with “ampersand &” and it will detach it from the current tty and spits the output to ‘nohup.out” in the current directory.
You can also apply this if you want to run some program and don’t want to daemonize it just yet.

This thing helped me twice in the past few days so I bet it will help you too!