Saturday, December 17, 2016

solitary confinement


Never I thought I will break up so easily.

But  I have.

The burden of life becomes too much.

Where to go.......Nowhere.

Whom to talk .....Noone.

What to do .......Nothing.


Saturday, October 29, 2016

Sitting at the airport




So i am leaving for my home town. I arrived at the airport quite early....very early. One of my friend told that their is lounge area before getting the tickets and I can go and rest their.

But as it happens most of time, these are inaccurate information.  lounge area was there only after the security check.

So now I am waiting , before I can get tickets.  So what to do.

Not habitual to listen to music late at night, no interest in watching movies , having no book to read.
Can't run, Can't stretch in public.

So only option left is watch people. :)

One person is managing her bags. Some airport staff are checking out girls.  Person few chairs next to me also have nothing better to do, but just moving his hands over his beard.

nothing special happening. No one is looking suspicious. then how can I make a great suspense story.

Sud I do something. rather than looking for a character outside ..sud i be the character and the narrator .

There is a couple who came and just sit next to me.  having 2 buttermilk packet. Who drink butter milk late at night.

Also this is diwali weekend . So lot of airport staff is in traditional dress.

Still 20 minutes to go before i get my tickets.

Also my fav team liverpool are winning.

So in a snapshot if u see the plot is ready.

Place Airport full of people carrying bags, security also present.
diwali weekend and football match .

Anything can trigger my story to move ahead.

Anyone security threat...somneone bag missing ...some one child missing... some one missing flight due to match.

But in reality nothing is happening.

one person has opened his bags...there is saving kit ...2 jeans ...but nothing of importance.

person next to me, the couple I told u about ...was combing his hair...which he is losing. Now they are taking selfies.  this is biggest idiotic thing now a days in fashion.

One person is wearing red devils jacket...aka man united fan .. team i dislike the most.

Well  time for me to leave ...lets see after I go to lounge do i find something good.


Friday, April 15, 2016

LIFE EPISODE 2 : ALIEN


How should I go with this ...Should I write this as play ...or should I write a story....

Lets try PLAY.


Scene 1)

Pitch Dark : Someone sitting in a corner , Place seems to be like a space observatory lab.

Faint blue and green light coming out from Monitors. Constant buzzing sound from all the machinery running.

Slowly , Slowly voice can be heard more clearly, the person is talking to himself.

 Unknown@thispoint " What the hell is wrong with us , now a days ? We waste so much money trying to find some alien life...as if we treat our fellow beings nicely . What is they come and conquer us , or eliminate us....why not focus on something on hand"

Stares at the giant screen in front wall, which is displaying some orbits and some numbers are constantly changing at left bottom corner.

Start whistling in low tune, makes action as if enjoying the tune he is playing. Stares at the watch in front, its  14 AM in the morning, still  7 hours to go before sun is out and his shift will end.


Scene 2)

9 AM in morning , sky is bright red , in middle of a place which seems to be desert , there is a building, only top of the building which is dome-spaced is coming out of land.

Faint voices can be heard :

Voice 1)  " Is it possible ?"

Voice 2) " You tell me ? You are the genius ...what do you make of this "

Voice 1) " There has to be some glitch....our satellite has passed that place so many times but we never got anything"

Voice 2) " Is it possible, that something might have come now ? "

Voice 1) " Thats impossible ....our other satellite would have picked it up if that thing entered our zone....Its as if it appeared out of no-where"

Voice 2) " So you believe in magic "

............No reply ..........

Voice 2) " So what to be done next ?"

Voice 1) " Well ....we can inform everyone or we can see how long this thing is visible on our radar"

Voice 2) " I am more comfortable with first option , Answering questions once this thing disappears will be more difficult"


Scene 3)

Inside something which appears like a spacecraft, 2 MEN discussing something.

Man 1) " I think they know we are here "

Man 2) " Hmm ."

Man 1) " But why are they not trying to contact us ? "

Man 2) "Mayb ..they are deciding whats needs to be done "


Scene 4) 

Inside the dome ...multiple voices can be heard and also someone humming.


Voice 1) " I think we should invite him  ?"

Voice 2) " Invite ...seriously ...we don't know anything about them...their intentions...their capabilities.......We should put them in quarantine "

Voice 3) " They might consider that to be hostile act "

Voice 2) " But we need to take adequate precautions "

Humming stops ...Voice 4)  " Why not simply contact them and ask who they are ...where are they from "

  Sound of keyboards buttons being clicked in fast manner.....

Voice 4)  " They don't understand any of our languages "

Voice 2) " Hmm ..try images for communication"

Voice 1) " What are the chances , that meaning of images will be same in our world and theirs "

Voice 4) " I think either they don't understand our images or we are not getting them...I send them smiling face ...and they have send something ...which I haven't seen before...what type of creature is this "


Voice 1 , 2, 3  In unisone)  " What is that "  ....."what is ..................."


Voice 4) " What to be done now ???"

Voice  1) " Let send them some video of our world ...which tell them our way of eating, love , dress , vehicles "

Voice 4) " That might make sense to them"  

keyboards button types in quick succession

Voice 4) " HA HA ...i think they got us ...they have also send some video .....Is that how they eat ....there vehicles are so outdated...Is that ....their female species ??????


Scene 5) 

Spacecraft seems to be landing near dome ... Two men  descending.  A small door in dome opens ...4 shadows falls on ground ...whose lengths start to reduce.

The two men looks at the 4 person in front of them and are startled.   They have one Big Eye and one Small eye ....they are half of them in height...No protuding ears ...long arms ...at end of whose there is web.


MEN 1  to MEN 2 )

" It seems that rather than they coming to our world......we have arrived in theirs "
 



END of PLAY ......A picture of alien will help





Thursday, April 14, 2016

Threads - Android Part -1


Its 00:00 AM , my new favorite time to blog.
Also I am fasting ...NAVRATRI ongoing, and I am very hungry but have to wait till morning.


Now the tittle isn't do justice on what I am going to write. Since it will be series of articles only after that we can have more clear picture of Android Threads.


Basically what happened , I am learning Android and was making Server-Client Chat app. Lot of code I got from google....but as I am working more on it , more questions are pouring in.


Coming straight to topic.  Below is very simple Android code.  It has one button and one textbox.

Also it has only one ACTIVITY i.e one screen, on which our button and textview will be visible.

Now the code I have written like below .


package com.example.chetannrathore.testapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    TextView tv;
    Button bt;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tv =(TextView) findViewById(R.id.textView);
        bt=(Button) findViewById(R.id.button);

        tv.setText("before");

        bt.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View v) {
               tv.setText("inbetween");
            }
        });

        tv.setText("after");


    }
}


Now when I run the application, on screen I am seeing AFTER being displayed.  Now basically CODE always 
get executed sequentially. 

So after   tv.setText("before") ;      bt.setonClickListener  should get executed. 

Now I was thinking that till we have not pressed the button, the code should be stopped at this point. But it
doesn't happens. 

What happens is ...tv,setTEXT("after")  also get executed. 

So on my screen I can see    after even when button is not pressed. 


So I thought that  button click listener will be running on separate thread.  But that is totally wrong. 


On reading various post, this is what happens. 


Every activity runs on single THREAD  called MAIN thread and also UI thread. 

So even when you have multiple screen application, all of them run on same MAIN thread. 
  --- This needs to be taken care while designing the APPLICATION, else it will be slow --------


Coming back to code,  all the  UI components like button,list,textbox   also known as widget  are part of
VIEW CLASS. 

So when we define button in our application, we are creating a class of it ( which actually android does for us)

We just need to find it and assign it correctly.
             bt=(Button) findViewById(R.id.button);

Now like a normal class, WIDGET CLASS also have methods and interface defined in them.

  For example in case of BUTTON , we have  setOnclickListener method.  This method needs a View object , 
which implements View.OnCLICKListener interface. 

Hence we do  
                                     bt.setOnClickListener(new View.OnClickListener() {

Now if we use interface, we have to implement its methods....in case of onClickListener , that method is
  OnClick hence we write code for that. 

Also , we need to know which button is clicked, hence OnClick has one parameter which is View.

                        public void onClick(View v) {

Now OnClickListener is part of EventListener Interface in Android.  These EventListener 
has callbacks method , for example Onclick.for OnClickListener Interface

Android framework registers these eventlistener interface callbacks. And wheneven a button or
 scrollview or textview is clicked or focused upon,  it calls the respective callback function and also
 passes the VIEW object which is clicked.



In conclusion , whenever we are running Android application , 

APPLICATION MAIN THREAD is running    and   also ANDROID FRAMEWORK always be running. 
If no button is clicked , MAIN THREAD will suspend.

When button is clicked, FRAMEWORK will call the  eventlistener interface function,  which will put MAIN THREAD 
from SUSPENDED state to ACTIVE state.

Once the button functionality is done, again MAIN THREAD will move to SUSPENDED state.

 

Wednesday, April 13, 2016

ASTROLOGY : The old science or new science


Today I was feeling very calm, a perfect flow of energy.  But last two days I was on fire, ready to pick fight.

I was sitting in my room and when looked outside my window , I saw that today moon is half and bloody. This made me wonder , whether my mood swings all governed by moon.

As per my horoscope, moon plays important role , everyone has some planet whose effects will be more dominating than others.

In short ...I am piece of moon :D :D

 But thinking logically and with the information we have in our hand .....even though this will be slight digress from main topic . but I can't help but to bring this point.

*********
Today in office , my friend was telling me that scientist told based on some model, that human cannot  reduce time taken to run 100m  by more than of 9.72s , but then usain bolt did it in 9.58s

They were telling that force which will be exerted in body will be very much for human to sustain, also taller people will have less chance of running fast.

But once usain bolt actually broke the record, scientist would have taken this data in their model and then would have predicted new threshold

******************************


So they thing is , nothing holds true for long. It is simply we have not encountered that and therefore don;t believe in that.

Coming back to main topic.


Now earth rotates , and so do all the planets. Every planet has GRAVITATIONAL force, and this the only force which we know as of now. Currently GRAVITATIONAL force was discovered, which will again change lot of theories, new theories will come, new type of plans will be designed.


So just for sake of argument, let say the force , however tiny does play some kind of role. These all are external forces.  Also since at every moment , considering the vast amount of randomness which will be generated.  { Every planet is rotating and revolving, so at every moment we will have different amount of force coming } .

Don't you think that astrology will be true ????

Suppose I slap you ...which is external force.....but also reaction of person who got slapped will be different per person...some will fight...some will cry....some will be stunned.

So even tough EXTERNAL force is same....we have different reactions.

So as per gravitational law, even though two person at same place will have almost same type of forces exterted upon them,  we cannot guarantee that they will behave or feel same kind of reactions.


So how to validate this ?  DATA ...and LARGE amount of data....if we can save how a person is feeling at same point and see the planetary position at that time ,  after we have large amount of data we can try to see if we are getting some data which is symmetrical ....else if everything is random ...then either we haven't encountered other parameters in our model....or  ASTROLOGY is biggest fraud which every human civilization fall victim to.


Coming to the second part, which is my favorite..... Can future be changed ?

How to see this ???

Scenario 1)  I tell you that today you will feel more angry and should avoid confrontation.
This is based on planet position today .

Very simple and understandable,

Now , we can argue that planet position will not change , hence you will surely feel angry.

But will you fight or not ????

Is your fighting predicted by ASTROLOGY ????

I think this is where most of us ( including me) misunderstand ASTROLOGY, what if it is not a model to predict exactly what will happen, but more of what situation you will found yourself in.



Scenario 2) Most of times we hear astrologers saying that some particular zodiac sign person will face financial loss.


Is that guaranteed ???  Will all the people who fall into one particular zodiac sign, however different ( country living in, their financial status , .....)  will face loss.

I don't think so....but let have some argument.

We can say that job market is better for people working on JAVA , Android and BIG data currently.
So all the people knowing ANDROID will have better chance of changing jobs.

Offcourse no one will argue, even though if we see individual person we will find that the HYPOTHESIS will be made, is not true for everyone.

It same way for ZODIAC sign,  We all know individuals subjected to same type of environment will develop some common habits.

If 100 children are taught dancing when they were small, and 100 more are made to study ....majority of students who were taught dance will have better chance of doing dance better than the group which studied, even though we can't guarantee it to be 100% true.

Same way, when we our born, all the people born in same month or same week, will have some common position of planets , which will develop in them some common characteristics.

Hence they might feel something same. But again the factors are so many, that  PREDICTION made will not hold TRUE on everyone.


Let me conclude this as we move to new DAY . ( its already 00:32 AM)

Astrology doesn't tell future... we have among us people who are VISIONARY ...who sees what is going around them and tell what will sell in future..what is needed in future.

ASTROLOGY is same thing ...it gives you a VISION of your future...but not in terms of what will happen ...but how will you feel ..

So it should not be taken as excuse of what you can't do or acheive ...but how you can be in more control of your feelings/emotions.

But the biggest downfall of human is  their EMOTIONS.

What if I warn you ...that today might bring shame/embarrassment for you .

and then seeing a 100 rupee note laying on a barren road ...wouldn't you be tempted to pick it up ????






Tuesday, April 12, 2016

LIFE - EPISODE 1 . PILOT LOVE


I think few years have been passed.  As I try to remember , actually lot of time has passed, but still I can picture her clearly.
  the spark in her eyes, which made me to turn and look her again.
  her non-stop chit chat, even though half of the time I was not able to catch the speed by which she use to chat , but was happy to look in her eyes which somehow use to speak to me.
  her confidence and trust in me
 
She was not picture-perfect, few pounds extra , but still somehow when I use to be with her, there was a peaceful calmness. Its like with her my soul got connected.

Have you ever observed, when you are thirsty....any drink apart from water will not quench your thirst. It was the same, first our soul got connected , the question of differences never occurred.


Life is very simply yet complicated.  Parents try to do what they think is good for their children, children try to do what good for parents.  Never they sit together and discuss what makes them happy.

Our first fight occurred over a petty matter, ....it seems petty now, on looking back.

She wanted to go home , to see her parents. Me a born recluse, had deep attachment with only one person and hence it appeared terrible to me to be separated from her for 1 week.

Second time we fought when she came back from home and told me she didn't enjoy her stay.
How can you say a person that he is correct after not listening to him ?
Yet within one month she again went home , even though for just 2 days.

I met within an accident, a minor one, just some bruise on hand and leg.  I can't tell my family as they will get worried about me. Friends, all they say is  LARGER wounds were inflicted on MAHARANA PRATAP...........assholes,

I miss her, she would have taken care of me.

I remember , even though it was just bad cold and fever, she made it sure I was taking steam , taking my medicines at correct time.


What went wrong ....mayb the small things which no one care to observe. We are too busy to see only the big details.



COM port and Linux : Part 1



There was a post written about Serial Port communication, this is continuation of that.

Recap:

Serial communication is mechanism of sending data from one device to another. One bit at a time( Well its quite misleading)

The H/W part is RS-232 , which tells about the voltage to be used and other electronic stuff.
Then there is UART  which is software part which tells how data will be converted to bits, how many bits will be required and how to determine the bit-rate.

So COM port is written on top of UART, this is how you will read data and use it.

When you connect your phone to laptop/pc.  In device manager you can see COM port will be present. ( MODEM device is also seen, which will be some COM port).

See the pic below,  MODEM device is showing in Device manager.

On further clicking it and going to MODEM tab,  we can see  COM91 is COM port.

***COM stand for communication*************



Using tools like tera term  , we can send data to MODEM or to any device connected to COM port.

In case of modem, it understands  AT cmds.  So if we pass AT cmds we can see response.

Pic below.

As can be seen, I have selected COM91.
RED text shows data send, and blue the reply from Modem.




In linux, also we can use socat to send data to COM port.

Step  1) Connect the device to laptop/pc.
           
In linux, all the connected device are shown as device file, which are present under /dev folder.
You can use below command to see any external device.

> dmesg | grep tty

For me , 4 devices are showing .  ttyACM*



Step 2) Before sending data , we have to connect with these device file.  In my case ttyACM1 is correct file.  You can try connecting to each device and see which sends response.

Only root has permission to use these files, so we need to change their permission .

> chmod 777  /dev/ttyACM1   // You have to login as root in terminal to run this command.

Step 3) run socat

>  socat  -  /dev/ttyACM1

then type AT cmd needed.                                // See pic below




So this was in short about COM/serial port.  Actually I was trying to learn serial port programming, which doesn't seems to be very tough.  But debugging will be required.

So instead of modem, I will use my Arduino for it, as I can see what data is received.

Sunday, April 3, 2016

X-Files ; Sockets 3rd and last ; TESLA car


Finally this is last of Sockets, in this I am attaching the zip file of Server and Client Code.

Server will open a server socket and listen to client connection.

Client will open a connection with Server and wait for any input data.

server will send "Hello from Server" to client.

The code is very basic, there is no extra line of code which is not required. NOTE : this app will have problems, as optimized coding is not done.


Also UI-wise,  Server has just one text box, in which Server IP address is shown.

Client has two text-box , in one we will input the Server IP address in other Text Box the message send by server will be displayed.


Also you will see implementation of ASYNC task at server side. It is required to create connection and wait for CLIENT request. First I thought that is not required, but my UI was unresponsive without implementing it.

Reason : socket.accept() call is blocking call, until some client doesn't request connection , further code execution will not take place.

That's it amigo's.


Coming to second part, I was watching X-files,  it's not so good. But there was a question which came to my mind.

1) Is apeing greater than pure genius ?


Now I always wanted to do socket programming, but my inherent nature doesn't allow me to understand other people code. My brain just shuts down, when some one tells me how something worked.

I like to learn by my own. But what I have seen, learning by your own , discovering what other have discovered , reinventing the wheel should be attributed to DUMB people.

The very foundation of human society is build on SHARING.We learn from other experience, other mistakes, other success and this learning shortens next generation re-learning curve.

Now I was talking with my roommate, and he was telling me about TELSA car. What was beautiful in that CAR is that they have MACHINE LEARNING.  So if you are taking your car to some place and say it is hilly terrain. You have some sharp turn and did skid, the next time any TELSA car goes on that route will know what speed is dangerous on that turn.



Wow !!!!

Same way , what I coded in socket programming was learning from the 3-4 applications made by others.

But sometimes I feel what if everything we are learning is not natural but artifical ?

Like the matrix movie, where they show everyone is kept in a chamber and their brains are feed with real world image.

Telling even LIES a hundred times, makes it a truth. This is how we humans are.

What if the CASTE, COLOR, COUNTRIES we have created are in interest of FEW people. And we are told/teached whatever they want.

So it also raises one interesting question :


Do we want to live in harsh reality or beautiful truth ? 
`

It seems there is no option of attaching files to blogspot, so here is link for drive

https://drive.google.com/folderview?id=0B6HF3JcgAklva0VsSWIzZDZldG8&usp=sharing

Saturday, April 2, 2016

Sockets : Part 2


Only I know how tuf it is to write the second part. Not because of technical things, but simply because of my nature. I am very curious by nature , but flicking. I started SOCKETS article to make an app, then once I knew how it can be done, I start becoming disinterested.

But PROCRASTINATION , is not going to take me anywhere. So even if universe ends today, I have to complete this before it.

So lets start directly.

Now as I see right now, maybe this article might not end with Article 2, but spill further into one more article.

Now I will try to have code + theory at same time, else interest goes away. As we have seen in last article knowing just SOCKET API/functions are not enuf, we need to know also about OS. So in this article we will see threads and async task, as per our requirement. 

> Layout of our Program.  If anyone has used Android Studio or Eclispe before for Android application they know about

  Manifest.xml , Layour.xml , .java files. We will not see those in here, possibly I give put snapshot of those in my next article.

Now in Android, when we make application, we divide them into Activities, Each Activity which we create has a UI part, which is govern by .xml file  and .java part which has the code.

So in this article we will focus on code part.

So in both the Server and Client application, we will have  1 activity which will be main activity

 Server Main activity will create a Server class which will have function to open socket, accept client socket and send data to client. Server Class will be defined in separate .Java file, we will not need activity for this as we don't need UI for this.

Client Main activity will create a Client class which will have function to create socket, and once connection is created listen to what Server is sending and display it on UI.  Note Client class will be defined in Client.java file,  no activity is needed for it. Display will be done on the Clint Main activity UI.

Now below picture is for Server App in eclipse,

You can see Mainactivity.java which will have code for MAIN activity. Since it is activity it will have a corresponding xml file, which is activity_main.xml which will have UI.

Then the whole server code will go into Server.Java file.  In this article we will see only Server.java and Client.Java.

Then there is a AndroidManifest.xml file which governs the properties of Android app, we will see its use at the end.







So  we have got enuf skeleton of our app,  we will now start with to put flesh and muscles to it.


Now first starting with Server app, Server app has to accept Client socket request and also send data to existing clients.  So we need to have two simultaneous operation ongoing to support this.
So we will need threads. THREADS helps to run task in parallel. In java already THREAD class is present, we need to extend that class to get the work done.

Code wise

  private class ServerSendData extends Thread {    // here ServerSendData is our class in which we will have code for sending data to client and it is extending the thread class, so our class ServerSendData will run as totally independent body with respect to other part of Server program. 


> Now get started

The below code is psuedo-code for understanding , main code files I will try to upload. 


private class Server {

int port_no = 8080;

void opensocket() {

  ServerSocket serverSocket  = new ServerSocket(port_no);   // SERVER socket is created

 Socket socket_c = serverSocket.accept();  // this will accept only ONE  client connections.

  ServerSendData ssd = new ServerSendData(socket_c);  // Here we have create another class to                                                            send data
   ssd.run();   // we called the other class function
   
}

 private class ServerSendData extends Thread {   // this will run indepently to above code

       string msg = " I am server";
       socket client_socket;
     
     ServerSendData(socket clientsocket)
      {
            client_socket = clientsocket;
      }

     public void run()
    {
           OutputStream outputStream = client_socket.getOutputStream();// Here we are getting outstream                                                                    of socket
    PrintStream printStream = new PrintStream(outputStream); // printstream will put all message                                                               pass to it to outstream
    printStream.print(msg);   // Finally we have send message
    }
      
}
}

The above code shows how to achieve functionality of sending  data from Server.  Below we will see code at Client Side.

private class Client{


void opensocket() {

 Socket socket = new Socket(Server IP addressServer Port);  // Client socket is created

  InputStream inputStream = socket.getInputStream();  // this will get data from socket.
  
 BufferedReader r = new BufferedReader(new InputStreamReader(inputStream));
String x = "";
x = r.readLine();   // So now in x we have our input data, which we can display
}

NOTE : the client code is very simple, since i wanted to show how to achieve functionality code-wise.

In reality, we at client side also run socket creation/communication code as ASYNC task or seperate thread.

Since , reading /writing data from socket can take time, which will make our whole app to hang. So we do that functionality in background.

A bit about ASYNC task :  Classes which implements ASYNC task will run in background so that they don't affect over-all functionality.

Code wise : Classes implement ASYNC task like below

class ClientTask extends AsyncTask {

And then this class needs to implement some fucntions related to Async task like

1) Preexecute :  Function which will be done before Background function.
2) DoinBackground : The code part of this fucntions execute in background.
3) PostExecute : This will get execute after background function is completed.

4) Progress : If you are reading large amounts of data from socket and periodically wants to display that data , you can call this function from inside of DoinBackground. ( Ever notice , in MYNTRA, flipkart,amazon as we scroll items they gets loaded )

More on Async task can be read from internet like : its return type, parameters  etc.




Finally ...I have written the article.  Its so difficult to sit on your ass from long-time. Its time to massage it .

In third article , there will be zip file of  complete code, possible some video also showing communication between Server and Client.  And ...this is far-fetched ...but how to have continuous communication between Server/Client.


Thursday, March 31, 2016

I am obsessed with GOD


I am getting unhealthy obsession with GOD. In the quest to find someone whose existence can't be proved, I fear that I might be alienated from the humans, who do exist.

Its like waiting for one phantom love , which you thought is made for you and ignoring the real persons around you.

But humans and GOD go hand in hand. One can't exist without other.

I recently watched SUPERMAN vs BATMAN. And I loved it, because rather than having high dose of ACTION ( like MARVELL MOVIES) , it deals more with emotions of powerful man.

Lex Luthor said something in that movie which makes your think.  " If GOD is all-powerful, he can't be all-good  and if he is all-good, he can't be all-powerful".

Now how we will measure goodness and power, when we will say that a person is almighty ?

Suppose there is GOD and he is all-good, then he will try to be as fair as possible. But is it possible that all humans will be satisfied ? No , because we have are own emotions and we are selfish.

Now say if 1 in millions don't believe GOD to be all powerful or good, then he can't be all good or powerful.

Its like DEMOCRACY ,  he majority doesn't believe you to be GOOD, then you can't WIN even if you are most unselfish , most emphatic heart out there.


Now do we really want GOD to acknowledge himself ? What will happen if he in reality exist and he proved. 

What is much better -  to believe in someone all mighty , but who is just a belief which can be changed.   OR  having a reality who can do whatever he/she likes.

Maybe we will have chaos, if GOD really exist.  Lets take a scenario.

> GOD exist, he comes and says he is GOD.

> HUMANS : Which religion you belong to ?

> GOD : There is nothing called religion, this is made by you to simply mislead one another. From today there will be no religion, no need to worship me also.

> HUMANS : okay.......this is liberating...we don't have to do things in name of religion. But what if we want you to fulfill our wishes  or if we if feel guilty about something and want forgiveness.

And will you stop something bad from happening ??

> GOD : Its not so easy....there are some wishes which can't be granted...for example if you say GOD made me rich...thats not possible ...I can't make everyone rich ,,,..same way if you have divided yourself on basis of countries and want to win against each other.. How can I grant wish of both parties.

About forgiveness and stopping something bad : First of all we need to define what is bad. If we go by my definition of GOOD/BAD and I stopped everything bad to happen , then FORGIVENESS will not come to picture.  And if it does, that means I allowed something BAD to happen  which will raise questions on my AL-MIGHTINESS.

> HUMANS : Why we want you to exist ?

> GOD : Because you need me ...................................there are some things which you can easily do and don't remember me for those things..........but then there are something which you find hard to do...hard to fathom ...as a  respite...as an excuse  you want me

You humans always want to understand everything ..you want to know about past and also the future.
You can never believe that things happen simply without reason. You are creating paradoxes of your own.


What will happen if all of you becomes totally like each other. No one more beautiful than other, every one having same amount of money ?

-----------------------------------------------------FOOT NOTE------------------------------------------------

As a writer, I don't know the answer of last question ?





Wednesday, March 30, 2016

Sockets : Finally they unraveled themselves : Part 1


Socket programming was something, I was always interested in. But Now when i look back in my college years , I realized that nothing was taught which could have been practical. The teaching situation in india is quite bad.

If internet would have not come, we would still be lagging behind a lot.

Also I am very lazy, until and unless there is no external force, my inertia of rest doesn't allow me to work.


But past is past...behold ..the future is bright.............

Rather than having detailed techincal discussion about them, we will see there overview and then see Android Programming.


1) OSI layer :  If anyone has ever taken any networking course, they know about OSI layer. Below is the diagram



Now , in the above diagram SOCKETS fall between Transport and Session Layer. 
Transport Layer has TCP/UDP.\
 Internet Layer has IP. 

To communicate between any two devices, we need IP address. But what is multiple applications on one device are communicating with other device.  In that case we need PORT, which helps in distinguish traffic flow. 

SOCKET are combination of IP address and PORT, (APPLICATION/Presentation/Session) Layer opens SOCKET with Transport Layer and then all data is read/write from this socket. 


So now we know what is socket and how transfer can be done. Lets see what are API available in Android/Java library to open,close,read,write from a SOCKET. 

Also most of data transfer happening on internet or most of the Android apps we see are based on Server-Client architecture. 

A client will periodic check with Server if some new data is available from him, and will post if any data needs to be posted by Client to Server. 

So if you visualize , Client should know Server IP address, but if Server do not know Client IP address , it will be fine, as onus is on Client and not server. 


So the life - cycle of SOCKET is like below 




1) You create a socket on SERVER using a PORT ID.  ( Note depending on language and platform you are working on , you might also have to BIND the socket to Server IP address)

2) Then SERVER is constantly listening to any NEW CONNECTION coming. 

3) At CLIENT side, we also create socket. NOTE : the use of client side socket is to communicate with SERVER, hence the IP address and PORT no which we provides here is of SERVER.

4) Then CLIENT tries to connect to SERVER. 

5) SEVER once gets CLIENT request, accepts it.

6) Now we have communication link open and data can be transferred between SERVER and CLIENT.

7) Finally we close the connection. 

Now a bit of  Operating System .  If you see SERVER functions design wise, SERVER has to listen to new CLIENT request and also needs to communicate with existing CLIENT, hence we have to need two different THREADS, since both of these functions need to work in parallel. 



Now in Android, we use 

1)  ServerSocket serverSocket  = new ServerSocket(port_no);

    // This is to create Server side socket 

2 and 5) Socket socket_c = serverSocket.accept();

    // This is use to accept client connection, now using socket_c we can communicate with Client, NOTE : we don't use serverSocket to communicate with client, that is only used to listen and accept client connections. Once client connection is accepted, further communication is done using the client socket created at server side for each client.


3 and 4)  socket = new Socket(Server IP address, Server Port);

   // This is used to create socket at client side. This only will also try to connect to server, no other function needs to be called explicitly.



6 ) InputStream inputStream = socket.getInputStream(); 

     // This is used to read data coming to socket, irrespective of socket at server or client side.

    OutputStream outputStream = socket.getOutputStream(); 
    PrintStream printStream = new PrintStream(outputStream);
    printStream.print("data to be send in string format");

    // Below commands are needed to write data into socket.


Viola,  we are almost there. 

So in next post we will see Android App code , as it will also involve thread. 



Saturday, March 26, 2016

Life : Why we fear to take full control of it



Well ..as it happens most of time...after spending 1-2 weeks as normal human being..I get overwhelmed by the emotions which i see around myself...and to get over this hangover , I have to isolate myself and think about the most puzzling thing which have been at the centerstage since adam and eve.


What is life ...Who we are ...What is happiness ..and how to live life..

Everything which we consider right or wrong ..is simply what we were feed from the start. What is all that is lie... Animals kill each other ..they are infidel...they are not virtuous..yet they also live

I have seen humans rule changes as per time and place...lot of things which were considered INCORRECT by the society , has changed. And there is no guarantee that it will not change in future.

So how in this world, should i live his life. Should I do whatever it pleases him, without consideration of anyone else. If i am happy doing something, will it matter what other thinks of me.

All the big industrialist / money-makers have not earn money by 100% morally. Because you can't. When results do not depend entirely on you, to get best results you have to think just about yourself.

Same way I am listening to lot of breakups happening in bollywood now a days, What is this ?
Suddenly after spending 3-4 years , people are realizing that they are not compatible.

Can you really spend your life with only one person ? How can you be sure that he/she loves you as much as we do.  We can simply believe , there is absolutely nothing else on whose basis we can make a conclusion.  If you believe other person to be faithful, it doesn't matter what you see or hear. You can always make  yourself to believe in any lies. Same way if you don't want to believe ..nothing can be done .

So you see, its in our control how we live our life....but even then we tend to give away the control to others ...parents, bosses, loved ones.


I say when we have to live in a world concocted by lies , its better to live in our own lies.
Lets do what we want to do ...if nothing else...mayb atleast we will know in the end if GOD exist or its is biggest myth of all times.


Friday, March 25, 2016

ValGrind : It's leaking :)


Those of you who haven't heard about ValGrind : It is Gates of Death or gates of Valhalla in Norse Mythology.

I just love mythology.  I am not sure, how true it is , but for the time humans were born it existed.
It is our fear , our love , our redemption.

Its changes as humans changes, it is ever evolving.

But this post is not about Gates of Valhalla. ( Does Max max : Fury Road) rings a bell

This post is about second ValGrind : Which is debugging tool suite, It has one tool called MEMCHECK, which helps in checking if your C or C++ program is leaking memory.

Now in the older post, we have seen how to debug crash and know why your program crashed. But seriously, we will not always wait for our program to crash. So we use Memcheck to see if our program gotta piss or not.


1) If you want to use something, you need to have it.  So install it first on your linux machine. Pretty easy. Simply run

> sudo apt-get install valgrind. 

2) I will take the example, where my .C file is  crash.c and my program is crash. To run on this you have to give below command.

> valgrind --tool=memcheck --leak-check=full ./crash

Now what happens is that the output of this command will come on your terminal and which is not easy to read.

So better put that into some file  say "val.txt".

> valgrind --tool=memcheeck --leak-check=full -log-file="val.txt" ./crash


now for my below code, the valgrind output was

Crash.c file 

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

void voldemort(int *);

int main()
{
   int *hp;
   hp=(int *)malloc(sizeof(int)*1);
   voldemort(hp);
  // free(hp);
}

void voldemort(int *hp)
{
  int *temp;
  temp = hp;
  *temp=2; 
  hp=NULL;
  *hp=10;

}


Valgrind output

==8949== Memcheck, a memory error detector
==8949== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==8949== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==8949== Command: ./crash
==8949== Parent PID: 5602
==8949== 
==8949== Invalid write of size 4
==8949==    at 0x8048463: voldemort (crash.c:20)
==8949==    by 0x8048441: main (crash.c:10)
==8949==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==8949== 
==8949== 

==8949== Process terminating with default action of signal 11 (SIGSEGV): dumping core

So if you see , it is telling that at line 20 , there is invalid write. which if we see in crash.c file is correct, and we can modify our program to handle it.


So thats it ...

PLUG the LEAK

Tuesday, March 22, 2016

Core Dump : part 2


In last post, we saw about GDB, and BT . In this post we will work 1-2 more functions

So let see for below code. 

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

void voldemort(int *);

int main()
{
   int *hp;
   hp=(int *)malloc(sizeof(int)*1);
   free(hp);
   voldemort(hp);
}

void voldemort(int *hp)
{
  free(hp);
}

On running I got below error

*** Error in `./crash': double free or corruption (fasttop): 0x0a04b008 ***
Aborted (core dumped)

This is my gdb - bt message

#0  0xb76df424 in __kernel_vsyscall ()
#1  0xb7548827 in __GI_raise (sig=sig@entry=6)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#2  0xb754bc53 in __GI_abort () at abort.c:89
#3  0xb7583993 in __libc_message (do_abort=do_abort@entry=1,
    fmt=fmt@entry=0xb7680a5c "*** Error in `%s': %s: 0x%s ***\n")
    at ../sysdeps/posix/libc_fatal.c:175
#4  0xb758de7a in malloc_printerr (action=<optimized out>,
    str=0xb7680c20 "double free or corruption (fasttop)", ptr=0xa04b008)
    at malloc.c:4996
#5  0xb758eaed in _int_free (av=0xb76c5420 <main_arena>,
    p=<optimized out>, have_lock=0) at malloc.c:3840
#6  0x08048491 in voldemort ()
#7  0x0804847e in main ()

As we can see at step 4, double corruption has taken place. 
And in step 5 , we have called  system function and Step 4 is Voldemort . 

So we got function in which error has occurred.


One more example:

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

void voldemort(int *);

int main()
{
   int *hp;
   hp=(int *)malloc(sizeof(int)*1);
   voldemort(hp);
  // free(hp);
}

void voldemort(int *hp)
{
  int *temp;
  temp = hp;
  *temp=2; 
  hp=NULL;
  *hp=10; 
 
}

On running this I got 
 Segmentation fault (core dumped)

gdb-bt  output is 

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x08048463 in voldemort ()
(gdb) bt
#0  0x08048463 in voldemort ()
#1  0x08048442 in main ()


So as you can see with different type of signal , information can change a bit.

now we know Voldemort is bad guy and causing crash. So we need to check voldemort in detail.


Now if you have noted , then we can see that in front of every fucntion there is one number. To go inside a function we need that number with frame cmd. Example to go inside voldemort, we have to on gdb type below 

(gdb) frame 0                              // this will select this function, then we can use further gdb cmds                                                          list,   info locals

but when I typed, I ran into an error 'SYMBOL table info not available'. This is because at the time of building I have not enabled debugger option.

So I need to use that , like below .   crash.c  is my .c file name, crash will be name of my executable.

> gcc -g -o crash crash.c

Now when I run ./crash , in crashed as expected.  now after running gdb on it .

It automatically gave me line number where crash is happening. AWESOME

#0  0x08048463 in voldemort (hp=0x0) at crash.c:20
#1  0x08048442 in main () at crash.c:10

But to continue our tute, lets select this function

(gdb) frame 0
(gdb) list                    // list the function code
(gdb) info locals          // gives details about local variables.

For my function, below is details


(gdb) frame 0
#0  0x08048463 in voldemort (hp=0x0) at crash.c:20
20  *hp=10;
(gdb) list
15 {
16  int *temp;
17  temp = hp;
18  *temp=2;
19  hp=NULL;
20  *hp=10;
21
22
23 }
(gdb) info locals
temp = 0xa04b008
(gdb)

Now , we have seen that how can be debug crash dump using gdb.  
To quit gdb, simply paste q

But still lot needs to be debugged, like  what are memory address and what are values stored in them.
useful when crash is not happening, but answer is not as expected. 

that we will see in further tutes.