Saturday, September 10, 2011

cloud to surface

We always have been craving for this, we always wanted compact computing devices. We have them now, the all powerful, light weight, low power consuming, multitasking, connected devices. They are all converging into smartphone-tablet form factors. I still believe the tablet market has yet to find the ultimate tablet form factor; in spite of some of the greatest product design brains and billions of dollars of investment, we still don't have a compelling tablet form factor. We have a tablet market leader, who is way ahead of the competition; its still not the best tablet form factor. We ultimately will get there, if not today, tomorrow - we will have the right tablet form factor.


Unfortunately though, that form factor will not be the next big thing in the gadget world. Tablets will clearly eclipse PC share in next 5 years. PC is a history for non-programming world. The next big thing in the gadget world however, is what I call cloud-to-surface. i.e. We won't carry gadgets in our pockets 10 years from now. We won't need gadgets. I see all the surfaces, tables, walls, car dashboards, doors becoming gadgets. We will no longer carry data with us on tablets or smart-phones etc; the data will follow us where we go, including phone calls. Computer will no longer be on top of my desk; my desk will be my computer and so will be my car, and my coffee table, mirror, and the table in my favorite coffee shop or restaurant, and the seat on the train or bus or bus stop. When I put my hand on the surface, becomes my gadget, with my data; when you have it, its yours; and it doesn't leave anything behind. When its with no one, its a dead rock.


The peak of cloud computing is not my data available to me on my own gadgets; the peak is that my data available to me where I am; and when I am not there, its in the cloud. What would it take to get there? LTE + cloud + something like Microsoft surface. We almost have all three of them, they just need to meet each other and huddle.

Thursday, September 1, 2011

Deleting a node from a singly linked list

Deleting a node from a singly linked list

//this case works only when marked node is not the last node


struct node{
    int val;
    struct node * next;
};


bool delete (struct node * mark)
{
    bool deleted = false;
    
    if(mark && mark->next)
    {
        struct node * new_mark = mark->next;
        mark->next = new_mark->next;
        mark->val = new_mark->val;
        
        new_mark->next = NULL;
        free( new_mark );
        new_mark = NULL;
        
        deleted = true;
    }
    else
    {
        //need head for this case
    }
    
    return deleted;
}


// this works even if node to be deleted is last node


struct node{
    int val;
    struct node * next;
};


bool delete (struct node* head, struct node * mark)
{
    bool deleted = false;
    
    //mark and head could be same here or different. But mark->next is not null
    if(mark && mark->next)
    {
        struct node * new_mark = mark->next;
        mark->next = new_mark->next->next;
        mark->val = new_mark->val;
        
        new_mark->next = NULL;
        free( new_mark );
        new_mark = NULL;
        
        deleted = true;
    }
    // here mark->next is null and mark is head, so we can just go ahead and delete it
    else if(mark && !(mark->next) && mark == head)
    {
        free( mark );
        mark = NULL;
        head = NULL;
        deleted = true;
    }
    //here mark is the last node and its not same as head, so now we need to iterate
    else //( mark && !(mark->next) && mark != head )
    {
        struct node * iter = head;
        //iterate until last but one node
        while( iter && (iter->next!=mark) )
        {
            iter = iter->next;
        }
        
        //make sure we are at a node whose next node is mark
        if(iter && (iter->next == mark) )
        {
            free(mark);
            mark = NULL;
            iter->next = NULL;
            deleted = true;
        }
        else
        {
            //sorry mark is not in the list that starts with head
        }
    }
    
    return deleted;
}



Python : HelloWorld

## helloworld.py
import sys


def hello(name):
        name = "hello, " + name
        print name


def main():
        if len( sys.argv ) > 1 :
                hello(sys.argv[1])
        else:
                hello('world')


if __name__ == "__main__":
        main()


## end of helloworld.py




Functions:
here is how you define a function in python


def functionname (arg_list):
       code
       code

they start with word def followed by function name, argument list in parentheses and colon ":" in the end


Tabs / indentation:
Indentation in python sort of works as open and close braces in C


if statements:
if (condition):
else :

just like function name they have colon in the end and tabs as braces


Modules :

Python has something called modules, these are python programs that you can import. Any python program can be imported. When its run as a standalone program, it has __name__ variable set to "__main__" . Otherwise, there is no difference. You do not have to have a function called "main" as a language requirement. I am calling main if __name__ variable is set. Otherwise, other programs importing my python file can invoke hello function on their own.


e.g.

I have imported sys module in this example. sys has a few useful functions or data in it. commandline arguments are available as argv[]


dir()
There is something called dir(). if you do dir(sys) you will see what all is available as a part of sys module

So, if I run dir(helloworld) from command line python, here is what I get:

python
>>> import helloworld
>>> dir(helloworld)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'hello', 'main', 'sys']

I do not know yet what all this means, so thats coming soon.


help()
There is also something called help(). e.g. help(len) can show you what len can do.

Need to write more programs to find more language features.

Python

I have been using python indirectly. There are some engineering systems here at work that use python currently. I never did much of deeper digging but I used to modify a few things here and there to make something work that's broken. Recently a person who interviewed me on phone re-introduced me to python and since I have started digging more and its fun. Its an interpreter. You can just run it from your terminal and start dealing with it. I have started watching google tech videos about it and I highly recommend those. I need to get to know the if, switch statements and all sort of loops, argument passing, referencing, memory allocation etc asap.