Sunday, December 30, 2012

My code is in github now

https://github.com/mikedasuya/ds

Security
http://www.schneier.com/blog/

Applied Cryptography
Bruce Schneier
John Wiley & Sons, 1996
ISBN 0-471-11709-9
Paperback - 784 pages - $60.00
ISBN 0-471-12845-7
Hardcover - 784 pages - $85.00

Tuesday, December 11, 2012

C stricks-ricthie

if there ispointer airthmetic following things must be consindered.
1)Pointer cant point to register variable.

2)Pointer subtraction must be stored in special variable ptrdiff_t and not in integer because it can overflow the integer.

               In a two's complement number system, x &= (x-1) deletes the rightmost 1-bit
in x. Explain why. Use this observation to write a faster version of bitcount.

Denis ricthie

Monday, December 3, 2012

Write a function setbits(x,p,n,y) that returns x with the n bits that begin at position p set to the rightmost n bits of y, leaving the other bits unchanged.



                Write a function setbits(x,p,n,y) that returns x with the n bits that begin at
position p set to the rightmost n bits of y, leaving the other bits unchanged.

So there is x = 32 (0010000)
Y=19 (0010011)

Now p =4
and n =2

So right most 2 bits of y are 11.
So we move these two bits to X position (5,6).

After this code X=48(0110000)


#include
#include


void countNumberOfbits();
int main() {
countNumberOfbits();
return 0;
}

void countNumberOfbits() {
char x = 32;
char y = 19;
int p =4;
int n = 2;

y = y & (~0 << 4);
y = y & (~0 >> 2);
x = x|y;



printf("\n Count is ---:%d: --\n",x);fflush(stdout);
}


Sunday, December 2, 2012

Making tree from array using stack and doing left first traversal



#include
#include
#include "stack.h"

char* replace(char, char*);
void countNumberOfbits();
void constructHeap(int ar[]);

void fillPrimary(stack*,stack*);
void fillSecondry(stack*,stack*);
void traversal(Node * root);


int main() {
/*
    char * ptr = (char*)malloc(6);
    ptr[0] = 'a';
    ptr[1] = 'b';
    ptr[2] = 'c';
    ptr[3] = 'c';
    ptr[4] = 'e';
    ptr[5] = '\0';
    char * mainString = "itsasit is cb";

    replace('c', ptr);
*/
    int ar[10] = {0,1,2,3,4,5,6,7,8,9};
    constructHeap(ar);
//    countNumberOfbits(;
    return 0;
}

void constructHeap(int ar[]) {
    struct Node * root = NULL;
    struct Node * ptr = NULL;
    struct Node * mvptr = NULL;
    stack * st_primary = new stack();
    stack * st_secondry = new stack();
   
    for (int i =0; i< 10; i++) {
        ptr = new Node();
        ptr->lfptr = NULL;
        ptr->rptr = NULL;
        ptr->data = ar[i];
        if (st_primary->length() == 0) {
            printf("\n -------tree is here to stay ---\n");fflush(stdout);
            st_primary->push(ptr);
            root = ptr;
        } else {
            mvptr = st_primary->pop();
            if (mvptr->lfptr != NULL
                   && mvptr->rptr != NULL) {
                mvptr = st_primary->pop();
            }
            fillSecondry(st_primary,st_secondry);
            if (mvptr->lfptr == NULL) {
               
                mvptr->lfptr = ptr;
                st_secondry->push(ptr);
                fillPrimary(st_primary,st_secondry);
                st_primary->push(mvptr);
   
            } else if (mvptr->rptr == NULL) {
                mvptr->rptr = ptr;
                st_secondry->push(ptr);
                fillPrimary (st_primary, st_secondry);
                st_primary->push(mvptr);
            }
        }
    }   
    traversal(root);
   
}


void fillPrimary(stack * st_primary,stack * st_secondry) {
    int len = st_secondry->length();
    for (int i = 0; i < len;i++) {
        printf("\n -----fill primary --:%d:--\n",i);fflush(stdout);
        st_primary->push(st_secondry->pop());
    }

}

void fillSecondry(stack * st_primary, stack * st_secondry) {
    int len = st_primary->length();
    for (int i = 0; i < len;i++) {
        st_secondry->push(st_primary->pop());
    }
}

void traversal(Node * root) {
    Node * mvptr = NULL;
    stack* st_traverse = new stack();
    st_traverse->push(root);
        while (st_traverse->length() != 0) {
        mvptr = st_traverse->pop();
        if (mvptr->rptr) {
            st_traverse->push(mvptr->rptr);
        }
        printf("\n ---Traversla :%d: --\n",mvptr->data);fflush(stdout);
        while (mvptr->lfptr) {
            mvptr = mvptr->lfptr;
            printf("\n Traversal 1---:%d: ---\n",mvptr->data);fflush(stdout);
            if (mvptr->rptr) {
                st_traverse->push(mvptr->rptr);
            }
       
        }
       
    }

}



/*void getNode(node * root) {
    int level = 0;
    if (root->lfptr == NULL) {
        return root->leftPtr;
    } else if (root->rptr == NULL) {
        return root->rptr;
    } else if (root->lfptr != NULL) {
        level++;
        pushlevel(level);
       
   
    } else if (root->rptr != NULL) {
   
    }
   
}
*/


void countNumberOfbits() {
    char x = 23;
    int count = 0;
    printf("\n ---one is :%d: --\n",~(~0 << 1));
    for (int i = 0; i < 7;i++) {
        char y = (x >> i) & ~(~0 << 1);
        printf("\n ---:%d:--x is \n",x);fflush(stdout);
        if (y == 1) {
            count++;
            printf("\n ---x ==1 \n");fflush(stdout);
        }
    }
    printf("\n Count is ---:%d: --\n",count);fflush(stdout);
}

char* replace(char ch, char * ptr) {

    char * str = ptr;
    printf("\n ---STR :%s:--\n",str);fflush(stdout);
    char * ptr_f = str;
    int j = 0;
    for (int i=0;i < 6; i++) {
        if (str[i] != ch) {
            printf("\n ---i:%d:-j-:%d: \n",i, j);fflush(stdout);
            str[j] = str[i];
            j++;
        }

    }
    str[j] = '\0';
    printf("\n ---STR --:%s:\n",ptr);fflush(stdout);
    return str;
}


Thursday, November 29, 2012

New programming puzzles

             Write the function any(s1,s2), which returns the first location in a string s1
where any character from the string s2 occurs, or -1 if s1 contains no characters from s2.
(The standard library function strpbrk does the same job but returns a pointer to the
location.)

Saturday, August 4, 2012

Revolution against corruption gone down the drain

Before I start writing anything,I understand that easiest thing in this world is to give advice and not following it.But still I would like to share my thoughts and also put forward the fact that most people in my country including me are not prepared to sacrifice their life for country.Here is what Bhagat Singh said

I emphasize that I am full of ambition and hope and of full charm of life. But I can renounce all at the time of need, and that is the real sacrifice. These things can never be hinderance in the way of man, provided he be a man. You will have the practical proof in the near future.  
- Selected writings of Shaheed Bhagat Singh (1986), Page. 65

We have already very many such leaders who spare some evening hours for delivering speeches. They are useless. We require ? to use the term so dear to Lenin ? the “professional revolutionaries”. The whole-time workers who have no other ambitions or life-work except the revolution.
  -Bhagat Singh.

What I saw at Jantar Mantar really made me sad.When revolution against corruption went weak,leaders opted for easy way out-political solution.If political solution would have been possible ,it would have happened in last 65 years.So when revolution demanded blood , sacrifice of life, our so called civil society leaders shied away from it.Had one of leaders given his life for war against corruption, by not eating,it would have caused the whole revolution turn into storm unstoppable by any government.It was like thresh hold, one sacrifice and all the sleeping public would have come to streets.Even in the worst case, public would not have come, but atleast it will be the true end to the war against corruption.Just because government is not listening or mass support is not there, leaders cannot abandon the cause.Had Mahatma Gandhi or Bhagat Singh thought about this, they would have never been able to do what they did.They brought revolutions.One sacrifice of Bhagat Singh made thousand more.This shying away from giving sacrifice has done more harm than good. People next time will not be willing to believe any such war against corruption.Revolutions need sacrifice and if it means giving your life for the sake of it,then be it or never start revolutions.

Now lot of people can ask one question:Why wont you do the same? I strongly believe that if I or anybody is leading the revolution, then leader cannot leave it before fulfilling the true cause of revolution.In this case, the revolution was to make the government pass the strong Lokpal Bill.Until that was fulfilled, they should not have back tracked.If god forbids,I am in same situation from where I started some revolution, I would not shy away from supreme sacrifice.But alas .....we do not have more Bhagat Singhs ....or Karatr Singh Sarabha or Bankim Chaterji or Ram Prasad Bismil.I would just end this blog with few lines from my favourite poem.

सरफ़रोशी की तमन्ना अब हमारे दिल में है,
देखना है जोर कितना बाजु-ए-कातिल में है ।

खींच कर लाई है सबको कत्ल होने की उम्मींद,
आशिकों का आज जमघट कूंच-ए-कातिल में है ।

सरफ़रोशी की तमन्ना अब हमारे दिल में है,
देखना है जोर कितना बाजु-ए-कातिल में है ।

है लिये हथियार दुश्मन ताक में बैठा उधर
और हम तैय्यार हैं सीना लिये अपना इधर

खून से खेलेंगे होली गर वतन मुश्किल में है
सरफरोशी की तमन्ना अब हमारे दिल में है


As long as we do not sacrifice our life for country ..........we will be sucked by some problem or the other.People have to be brought out from slumber and that needs sacrifice. Jai Hind









Thursday, July 5, 2012

Coomon sense and honesty at temples

I went to have darshan at shirdi.I think Shirdi Trust has done wonderful job in having the railings and other arrangements so that people do darshans without much hassle.They have put barricades at all the places so that people come in queue.They have arrangements for people to have water/tea while they are standing in queue.But actual reality is quite different. Darshans of SAI BABA is not hassle free but world war -III. People have made two rows/three rows where only one row was possible.There was absolutely no need to make second/third row.Some  people did not hesitate to jump over the 5 foot railing.On confrontation ,answer was "INDIA MIEN AISA HI HOTA HAI".(In india,its ok to break rules). Same has been followed by educated and un-educated alike .There was total chaos because people pushed each other.I could see few elderly people jumping over the railings as well.It was really bad state and lot of pushing happened but some how i am not able to blame the arrangements .Arrangements were fine if only people could have behaved little patiently.There was absolutely no need to make 2 rows where only 1 was intended.There was no need to jump the railings .There was no need to push each other.Only question intriguing me is this "Can chaos be prevented in places where thousands of people visit for darshans". Does the prevention of chaos only responsibility of the Trusts managing the temples/places of worship.Some where its the failure of our education system if chaos happen in-spite of good arrangements.We as society/people have accepted that in India only way forward is by pushing each other.If educated people take pride in breaking rules,what about the un-educated ones.I think we seriously need to revisit the education system and values imparted to students.The degradation of moral values is definitely a problem if only we as people see it and correct it.

Sunday, June 10, 2012

Work Life balance and Saying No

Is it worth?Some times this thought crosses my mind.I look around and see people who are work alcoholic.They work and work and miss some thing very important in life - Balance.Is work life balance important.I think if we have to lead a healthy life,satisfactory life we have to strike the balance.No work is also not good and more work is also bad.Yes at times extra hours are needed at work and one must be ready to go an extra mile .But if organization starts taking extra working hours as granted and start planning your extra hours,definately some thing is wrong.Productivity takes a sharp dip if a person is working more than 8-10 hours.The number of mistakes increase sharply and in turn rework increases.Then it becomes catch 22 situation.People put in more hours to cover the mistakes and since they are already over worked,they commit more mistakes.More mistakes means more working hours.Managers give the plea that once project is over ,some relief will be given in terms of holidays or less work.But in any case balance is lost .So is it possible that you will always meet people who are balanced.No.Then in situations where your boss is work alcoholic what are the different option sub ordinate has.These kind of situation teach you a very good lesson.Lesson is how to say no in a diplomatic way.Saying no smartly needs another blog . I would rather quote here one instance.I  met one manager while i was traveling on vacation to my home.He was busy with his laptop in the waiting lounge before boarding the plane.He was busy calling people and discussing things.By my bad luck,he was seated next to me in plane.Flight was going to take 6 hours and by the time he could say hello to me 4 hours were gone by.I know its bad to look into anybody's laptop but i couldn't resist seeing what he was doing.I started the conversation by asking a question "Are you  going for client visit and preparing all the data?.Answer was no.It was just routine work and he was also going home for vacation.And then ,official Gyan Started.He told me that there were so many people like him in the job market who were ready to take his place.If he will not out perform them in working hours as well as quality,he might loose his position.So he had to work for at least 14-16 hours daily to keep his position secure.I could see big black circles beneath his small eyes.There was little whistling sound when he took breath.Work was taking toll on his health .And i pitied his team.I asked what about your team?.Answer was "Team aah, people must work 14 hours .Saturday is unofficial working and if there is work,Sunday is not a holiday". i was shocked.There were many people according to him in job market whom he think could easily replace his team as well.He had recently changed his job and he had to perform to show his superiors that he is quite capable of doing anything in this world.So he has taken more work in less time and with less resources.Thats just one example but i could see many people like him around me.People like him are not bothered about balance.Neither about their life nor about their teams work life balance.Some time later in life they might feel what they have missed but what about others.Sub-ordinates, specially would suffer with these kind of bosses.Except from saying no to such kind of people there is hardly any other option left with subordinates if they want to make work life balance.

Thursday, June 7, 2012

tooo soft or too harsh bosses

People management is all to gether a different ball game .When transition happens in your career from technical to managerial role,people management plays pivotal role in your growth.In people management,its very important that people are happy as well as they are working properly.They must feel the ownership for their module and give their best shot.But can people management be learned through books.It comes only through experience.Generalization has no place in people management as different people behave differently in different circumstances.Soft skills play a major role when managing people.Tone, words should be carefully chosen .Words shall give feeling to subordinates that boss is happy or not but at the same time shall not demotivate them. Communication has to be precise and well thought of.Boss should not be too soft or too harsh.Too harsh bosses will make people run away and too soft bosses will not be able to push people to complete their work.Management schools can only suggest different techniques and no technique is perfect when dealing with people.To keep people happy and make them work with ownership is real skill set.If one has devolped it over a period of time,it will definately take one to great heights.


Sunday, June 3, 2012

Risk taking capacity and micromanaging

Risk taking capacity goes synonymous with success.So question is what kind of risk.Risk are of different types like taking a plunge from secure job to starting a buissness.There are other forms like when  you work in an organization and delegate.Risk is when you believe in your sub ordinate that he will take charge of work and make things happen.Regular checks are required to ascertain whether things are on the right track or not. These checks can vary from one person to another.There are very few thumb rules which applies to all the people.But if we do not delegate and keep telling an individual what to do how to do when to do, its micromanaging.Micro managing things has two big risks associated with it.One it can push the sub ordinate to a level where he stops taking initiative and gets frustrated.Second your work load increases tremendously.Only thing micro managing helps in achieving is short term goals.How many people are ready to take the risk of leaving things to deserving people whom they think can complete the work .Very few.And those who do they rise because by doing this ,they are preparing thier lower layer and hence have ample time to sharpen thier skills.But at times ,according to situation micro managing is also needed.But thats only for short period of time.If it becomes the norm then definately some thing is amiss.If micromanaging is norm,does it tell some thing about your boss.?