Wednesday, February 23, 2011

Vim shortcuts: Efficient Editing

Vim is editors' best friend, like earthworms are of farmers'. I have started appreciating the beauty of the various shortcuts in vim. They make editing so much fun and time efficient. I wonder it would have been really pathetic to not have been introduced to vim-craft!

Here are some shortcuts that I use:
1. To yank and paste: {[num-of-lines]"[reg-name]yy} + {"[reg-name]p}
2. To cut and paste:  {[num-of-lines]"[reg-name]dd} + {"[reg-name]p}
3. a) To move through the file; mark the file: {m[char]} + {'[char]} 
    b) Some inbuilt marks- {''} : Move to the last visited line, {'.} : Move to last edited line.
4. Ctags are very useful when viewing C files.
5. To move to similar parenthesis: %
6. a) Macros to repeat similar series of tasks over and over:
           q[char]                                      #starts recording into [char]
            q                                               #stops recording
     b) To repeat the macro:

To be continued..

Helpful links:
1. Byte of Vim
2. Vim cookbook

What it means "To Stumble Upon"

It means: drink and drive; You'll hit at something, may be it would change the course of your life, perhaps, also the world's development.. Well it definitely doesn't means think and drive..
And now what's gotten into my head that I am blurting out this very well known thing.. Its just that I see it as a problem with myself..
I think the problem with me is that I want to take careful steps and do calculated things in the process of achieving the ultimate thing.. It would be rather better that I start enjoying the journey instead of the destinations. I have not yet started with learning django though I want to learn it since the middle of this year.. Quoting Rajeev Motwani, Sergey Brin's advisor at Stanford- " It wasn't that they sat down and said, lets build the next great search engine, it was that while solving a problem they stumbled on a neat idea.."
What I should be doing now is wander, instead of travel..
What I have been doing so far is calculate the work I would do, the returns the effort would bring, but these calculation and predictions are based on the my little knowledge, formed out of the little understanding of the peer reviews where I land, based on the foolish keywords combinations searched by Google. so its like I have screwed up the whole thing and still i am hoping to find the best..
Let me now get ready for the adventure, fun, spontaneity.. :P

Utility of bitwise operators.

"All the memory addressing in modern machines is byte ordered.", said my Boss, frustrated at my foolishness and lack of comprehensiveness of this fundamental.
What I was trying to do was read bits from the memory as if accessing them out of an array. For instance read the bit-value at position 13, which is actually 5th bit at second byte, considering the buffer I am working on starts with 0. Damn!! It never happened, I was never successful in this endeavor. Why?? The answer to this became clear to me with that single line my boss told me.
This revelation that memory addressing is byte ordered made many concepts fall into place for me. I instantly became clear of the importance of data types like unsigned/signed int/char, big/little endianness.
This may be wierd. But thats how things are many a times, atleast for me. This is something I wasn't aware of. Aware of as in, conscious realization of it. I am sure I have read it many times, thanks to my background.
I became aware of it just today when I was analyzing a hexdump of a frame transferred between two networking layers. I was supposed to program the fate of the packet based on the value in its header field. Thats when it dawned upon me that in order to know what is there in the frame header, I have to use MASK!!
This is where is most of the C functionalities like typecasting, bitwise and (&), or (^), not (!) etc.. , left and right shift operators (<<) (>>), come handy. Below is a code that highlights the basic usage..

#include "stdio.h"
#include "stdlib.h"

int main()
        int i;
        int * an_int = (int *)malloc(sizeof (int));
        *an_int = 255;
        unsigned char * a_char = (unsigned char*)an_int;
        for (i = ((*an_int) & 0); i < ((*an_int) & 4); i++)
                printf("byte wise an_int has at %d[th] position char %d\n",i,*(a_char+i));
        return 0;

Missing element

They wrote of it,
they write of it..
They will write of it..
I had read it
i remember
but took notice of it never..
Time and now I knew
I missed that,
it remained for me unexpressed
I could never touch, smell, see or taste it..
But it was definitely heard and felt around
and when this happened my joy knew no bound
my eyes whispered and my lips saw
and I was in complete awe..
Yes, its that eternal instinct
none can rob you of
no weapon can destroy
AI as of now lacks..
Is completely humane
but missing in humans nowadays
its explicit but not understood
its written but never taught
its the feeling that can never be stripped of..
Like clothes, talent, knowledge, prowess..
Its the salt in the recipe of living!
Its the character of the being..