Tuesday, January 31, 2012

Today Is Everyday

So long I've been thinking that my problem was thinking that tomorrow was special...

That tomorrow had that special something which will make make me do the things that I didn't want to do today...

That tomorrow I'll have the special skills, the energy, the passion,...

That tomorrow the circumstances will be just right,...

Then it dawned on me today...

I wasn't wrongly thinking that tomorrow was special...

I was thinking that *today is special*...

I've been thinking that today is the special day in which I can't do something...

Today I'm tired...

Today I don't know how...

Today I've got other important things to do...

Today I surely have to rest...

Today I must read this or check that...

Today I must master my inbox, or update my FB status,...

That today isn't like every other day... today is special...

But, no, I've realized it isn't...

Today is like every other day...

The problems and obstacles I have today will be there tomorrow, the day after that, and every other day...

My energy levels will more or less be the same...

My passion and motivation too...

So, I have to hammer it in...

Today is like every other day... Today Is Everyday...

So whatever that needs to be done, I'd rather do it today,...

I'll work - today...

I'll sweat - today...

I'll learn - today...

I'll hustle - today...

Because, today is everyday...

Yes, Today Is Everyday...

Tuesday, January 24, 2012

Ultra cool commands

I planned to make a good cheat sheet from http://www.reddit.com/r/linux/comments/mi80x/give_me_that_one_command_you_wish_you_knew_years/,
well, here are some..., i'll keep updating this when I am bored..
  • units - conversion between more than 2000 kinds of units (kg to pounds, kilometers to miles etc.)
  • ctrl + e - opens current command in $EDITOR and runs the altered version
  • fc - similar to above, but opens previous command
  • ctrl + r - reverse searches what you've entered in command history
  • bind '"\e[A": history-search-backward' - binds your UP arrow key to only search whatever you've entered partially
  • bind '"\e[B": history-search-forward' - binds your DOWN arrow key to only search whatever you've entered partially
  •  lsof - ultra powerful so go here for detailed usage http://danielmiessler.com/study/lsof/
  • find . -print0 | xargs -0 command -Runs command on all the files found.
  • ctrl + a - Go to beginning of line
  • cd - - Go to previous working directory. The directory you were in, before cd ing to some other directory.
  • :w ! sudo tee %  - in vim when you forgot to open the file in sudo mode
  • pushd  - Pushes a directory to stack and cds there
  • popd - removes current directory from stack and cds to prevoius directory
  • tmux - read here http://blog.hawkhost.com/2010/06/28/tmux-the-terminal-multiplexer/
  • man -k searchstring - Search whether a tool is available for some task in your machine

Friday, January 20, 2012

Logical thinking - Interview

The other day, I was interviewing a couple of people to grant them admission to CDAC's course. I wanted to test their logical thinking and here is a question I asked one person. Question: If 50% of the people who watched IPL last year on television were under twenty years of age, what would have been the percentage of people aged more than 50? I didn't really need an answer. I only wanted to see their thought process. Here is what I expect, Attempt 1 - Around 30%, because people aged more than 60 in India tend to be retired, and hence have more free time, their percentage should definitely be more than people aged between 20 -50, who wouldn't have much spare time,... Attempt 2 - Around 20%, because they might be less interested in the IPL kind of cricket! Moral 1 - The answer doesn't matter, what matters is how one thinks. Moral 2 - It easy being smart while sitting on the right side of the table!

Thursday, January 19, 2012

Three ways of saying sorry

Today I realized that there are three things a person might mean when they say sorry.
  • Oops, I am caught :( This is not exactly a sorry, they would do the same stuff again, more carefully. If this is what you mean, don't bother at all. Try explaining the reason without apologizing, if you are in the right. If someone tells this kind of sorry to you, watch out! Be careful next time.
  • I regret doing that/not doing that. People tell this kind of sorry didn't mean to upset others. It was either unexpected or unintended or beyond their ability to deliver. The best thing to do is to let them know you understand and be supportive, and make them feel better.
  • I am sorry, how can I compensate This is the best kind of sorry to tell, rather, to do. Do something to compensate, but, don;t focus on the compensating part. The trick is to go further than what is expected and not tell one word about the extra effort. Reminding the other person that you are doing something to compensate does not help. Instead it makes them sour and reject your compensation. And, if the compensation is not good enough don't do anything at all.
But, the best thing is not to put yourself in the bad spot in the first place.

Tuesday, January 17, 2012

Seeing Wikipedia posts during SOPA blackout

Wikipedia has blacked out its contents today to fight against SOPA. So if there is anything you *must* see right now, do the following,...

But before you do that, learn about SOPA (its wicked, bad and evil). Tweet about it. Tell your friends, colleagues,...

And before I tell you how to go about this, I want you to know that I *hate* SOPA. I am a programmer who uses Debian GNU/Linux. I want all to join the fight for freedom, freedom as described by Stallman. But if you are dying to see that page, here is how,

If you are a little techie,
  • install firebug in firefox.
  • Go to the wiki page you want to see
  • Click on the firebug button in your toolbar, to see the firebug window down.
  • Expand the tag
  • Find this "style id="mw-sopa-blackout" " and click on it and press the delete button
  • Collapse the tag and expand the tag.
  • Find this span role="treeitem" class="nodeLabelBox repTarget "<div id="content" style="display: none;">
  • Delete display: none;
  • The page should be visible now.
If you are not a techie at all,
  • Save the page, by pressing Ctrl+S.
  • In your file explorer, (My Computer or Nautilus), find the save file.
  • Right click and choose Open with and open using notepad or some text editor.
  • Use find to search for the following "/table "
  • Delete from that part to the beginning of the page.
  • Open it in a browser now (preferably in a Firefox or chrome).
If you are a super techie, you must be pissed off at me... :( I sincerely support the fight against SOPA. I voted for the blackout at HN, and wikipedia myself. I tweeted about it. I didn't call anyone (congressman) because I'm from India, nevertheless I did my part.

Friday, January 13, 2012

Analysing a facebook spam/rogue app

Recently a couple of my friends were affected by a rogue app that posted crap using their accounts, and I was a bit curious how everything worked. But, typically they are so short lived, that by the time I get to see them, they are gone from the face of the internet, but, this time...

Luckily today another of my friends *liked* one such shit, and lets see how it works...

First off, it links to an exact Facebook look alike page... http://kustuntuniya.blogspot.com/?3





The page is an exact look alike, however, the lazy fellows were lazy enough not actually make all the links work. The header is just a div element with a CSS background image.

backgroundurl("http://i55.tinypic.com/jpj7fl.jpg") no-repeat scroll center top #3B5998;

 
Similarly the bottom part, is another image http://i.imgur.com/ZJLcI.jpg

Now, its the middle part that is actually interesting. 
The whole dark area is an iframe containing the page http://installplug.info/girlplugin.html 

The page has all the elements and the button like anchor tag, "Install Plugin", with the following code,  
<a class="install nomargin" onclick="instalar();">a>

So, it call our beloved instalar  function in javascript, which is found above in a script tag.


The next two lines tell them the type of browser... To install the XPI addon for firefox and CRX addon for Google chrome.


var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;


Monday, January 2, 2012

Binary Search Tree - C

I got a bit bored today, and wrote this to pass some time. Nothing's special here, but a normal binary search tree implementation in C. I just felt that some other stuff found online to be a little complicated for beginners, well, here is the simplest I could manage.



#include<stdio.h>
#include<stdlib.h>
#include<time.h>

//Create a node, well in layman's terms, a layout for a container, ie. the container should have one compartment to store the actual data, and two compartments to store the addresses of the children

struct node
{
    struct node *left,*right;
    int item;
};

//To insert something we need the data, passing the head could have been avoided had I kept it as a global variable

void insert(int item,struct node *head)
{
    struct node *tmpNode;
    tmpNode =  (struct node *)malloc(sizeof(struct node));
    tmpNode->item = item;
    tmpNode->right = tmpNode->left = NULL;
    findplaceNinsert(tmpNode,head);
    return;
}
//Keep traversing by going either left or right depending on the values, and insert as soon as we find an empty slot

void findplaceNinsert(struct node *tmpNode, struct node *parent)
{
    if(tmpNode->item > parent->item)
    {//Go right
        if(parent->right == NULL) parent->right = tmpNode;
        else findplaceNinsert(tmpNode,parent->right);
    }
    else
    {//Go left
        if(parent->left == NULL) parent->left = tmpNode;
        else findplaceNinsert(tmpNode,parent->left);
    }
    return;
}
//Inorder traversal
void printInorder(struct node *tmpNode)
{
    if(tmpNode->left != NULL) printInorder(tmpNode->left);
    printf("%d ",tmpNode->item);
    if(tmpNode->right != NULL) printInorder(tmpNode->right);
}

int main()
{
    struct node *head;
    int i,item;

    srand(time(NULL));
   
    head = (struct node *)malloc(sizeof(struct node));
    head->left = head->right = NULL;
    head->item = rand()%100;

    printf("\nInserting random numbers...\n");
    for(i=0;i<15;i++)
    {
        item = rand()%100;
        insert(item,head);
        printf("%d ",item);
    }
   
    printf("\n");
    printInorder(head);
}