i want to change the World..but they never gave me the Source Code..!

Macro prescan funda

I was just going through a community post and saw the following C problem, and reminded me of my college days, thanks to the post-maker!

I managed to write this here; because it may come on Google search for others who are still confused with such problem. Hope my explanation helps!!

Predict and explain the output of last printf statement.

#define f(a,b) a##b
#define h(a) g(a)
#define g(a) #a

int main ()
{
printf (“\n%s”,g(f(1,2)) );

printf (“\n%s”,h(f(1,2)) );

printf (“\n%s”,h(h(h(f(1,2)))) );

return 0;

}

Before we jump to find the output, let’s remember a few golden preprocessor rules defined by GNU corp. in gcc.

a) # opeartor stringises the argument.
b) ## opeartor concatenates the two arguments.
c) If an argument is stringified or concatenated, the prescan does not occur.
d) Prescan is a process in which complete macro expansion takes place.

Let’s come to the printfs one-by one:

g(f(1,2)) => matches g(a); which says a whould be stringified. No prescan takes place; just the argument f(1,2) as an string “f(1,2)” comes in printf.
So output is: f(1,2)

h(f(1,2)) => matches h(a) which calls another macro (not doing any concat or stringisation), so prescan should take place and it goes to the lower level expansions.
Hence,
=> h(f(1,2)) => h(1##2) => h(12)
=> g(12) => “12″ (as a string)
“12″ comes in 2nd printf.
So output is: 12

h(h(h(f(1,2)))) => matches h(a); prescan should take place (because no stringisation/concatenation)
so, from lower level, we need to go up replacing the macros by their aproprite values.
h(h(h(f(1,2)))) => h(h(h(12))) (12 is juat a concatenated object, not a string)
=> h(h(g(12)))
=> h(h(“12″)) (12 becomes the string)
=> h(g(“12″))
=> h(“\”12\”") (stringising “12″, causes escape characters \ to come for double-inverted commas, first and last commas being the stringifiers)
=> g(“\”12\”")
=> “\”\\\”12\\\”\”" (as a string)
“\”\\\”12\\\”\”" comes in 3rd printf
So output is: “\”12\”"

Hardly had time to write something…or rather didn’t get anything to press. As told by my ex-fairsex colleague, I usually press geeky things..ohh..thats true. But today is Holi ..of course..its Holi, a day, a holiday, and a holy day as well, so there is something i want to share . This day is kinda special for me..special in a way that it changed my perspective I had some 6 years  in a university hostel. But ..I do miss my BHU/JNU friends who made it joyful and colorful. Last Friday, we (me with my Nalanda friends) played a dry and herbal holi on/after office time. It was so much fun out there and i was going back home after greeting everyone a Happy holi. That’s where the real story began…

Since, it was a pre-Holi day, people from Delhi-NCR were commuting to their homes/native places. So, a general NCR employee can figure out the rush in evening at festival times  in metro stations, DTC buses and all sorts of commutes possible by Sheila Dixit’s grace, we have here. Anyway..I boarded the metro at MG Road station somehow, passing the one and half kilometres long queue. Since my whole body was drenched with colors, i ended up looking  like a clown; needless to say, few people in metro were surprised and kept staring at me , and two kids got scared as well, and stuck with their moms. “Just one more day chap!! Let Holi come, and you won’t even recognize your parents.”  i smiled at them and moved to a corner.

It took me around 20 mins to reach my destination by metro;  got down at Chhatarpur metro station to board a public transport bus which could take me upto Mehrauli. Waiting at the bus stop, 10 minutes passed…20 minutes passed..nothing came…but still had a hope that a bus would come otherwise hiring an auto in delhi is a tough idea. Finally, I found a DTC bus, I let others to board first, since my destination was hardly 10 minutes by bus. The bus was over-crowded, but I was not taking any chance to wait for another. I somehow bought a ticket, and began to move to the front gate. While I was about to get down,  I saw an old lady sitting at the front seat. I figured out that something had happened to her judging by her desparate face  and she was being consoled by other folks in the bus. The bus heading towards my destination, Ladosarai terminal, stopped at the red light. Then, I heard someone instructing that lady to get down here, take some bus or walk a kilometre. Not interested in the conversation, I waited for the lights to turn green, when i knew that she had to go to some hospital in mehrauli where her family was taking care of someone closed to her when she lost her way and unfortunately reached gurgaon. I could see no cellphone with her.  Time passed, the lights turned green and bus stopped at my bus stop in the very next minute. I got down, beside me that lady was getting down with a heavy bag with her, probably that might have contained some meal or clothings etc. for the victim in hospital. The bus passed, leaving her at the stop, but she didn’t know the destination and noone except me got down from that crowdy vehicle. I saw a kind of despair on her face, but i was in a hurry . i fidgetted with my cellphone and started to go when i noticed her in desparate help..i asked her, “kaun sa hospital jana hai aapko mehrauli me?(Which hospital in Mehrauli you want to go??)” knowing that might she not be answering my question. She very hopefully answered, “TB hospital beta!…mera something something….hospital…something something…gurgaon…something something…bahut der….something something…”. Her voice was not clear to me..but i understood what was she trying to say.. because there is only one Tb hospital in mehrauli, and then i recalled those voices..when people were instructing her to move there.  I recalled the venue and realized that it’s not far but it’s a bit hard for her to find. I said, ” aap mere saath chaliye..main aapko hospital tak chhod deta hoo, yahi paas me hi hai”(“you can come with me to the hospital, its nearby”). I was not sure whether She would come with me, because of the reason, the place Delhi is known for and thought if she sould say no..or made any excuses, i would  not bother myself for her anymore. But humanity is something that make you do these deeds even if they are worthless for you but matter to others. well..i am kinda inhuman..thats the other thing.. :) , why should i mess my mind helping her to the hospital or rather i could have gone home as I had to take a bath soon. She told, ” haan beta…something something…hame nahi pata…something something…ladosari…mehrauli..something something”. I listened only that word “haan(yes)” and told her,”aaiye mere saath”(“Come with me”). I took her with me to the hospital. Since, I take long steps , i found her far behind me.So  I stopped for sometime until she reached me, and i asked,”hospital me koi hai?”(“Someone there in hospital..huh?”) damnn me…is it a question?? of course yes..or she is not going to enjoy holi over there. Rather..i should have asked who was there in hospital, any serious case etc. But being an unknown, perhaps that question was also a good one from my side.  She told ,panting,’haan beta…meri beti hai..something something…gharwale..something something…uske liye ye saaman le jana tha…nayi hoo..raste ka pata nahi beta…something something…ballabhgarh..”. I then figured out that her daughter was admitted there and that old lady had come from ballabhgarh.. near delhi..who boarded the bus which connects badarpur to gurgaon via mehrauli, so unfortunately she didn’t get down at Mehrauli and reached gurgaon, and came back from there. Anyway, walking some 200 meters distance, we reached hospital gate, and i saw her family members waiting for her at the gate itself. i said..”okay aunty..main chalta hoo”(“okay aunty…i am leaving now”). I saw a little sparkle of happiness in her eyes..i didn’t know whether it was for her family memebrs or for me..but it soothed me a lot. She said, “haan beta..something something”. She blessed me as she raised her hands before me and then i retraced my path back home. Even though i was not able to be of  much help to her, it made me feel good.

So, you see the manner my pre holi day was celebrated. Thank God, You make humans, but from where does this inhumanity comes, well..thats the question!

 

Disclaimer: The content of the post is author’s sole thought. Please mind scrolling down if you are a television addict.

If you see 6 years from my past, hardly i watched television for half an hour continuously. Being a computer science student, my UbuntuBox itself worked for me whenever i felt an urge for entertainment. As of now, when i have left my hostel room and residing with my bhaiya..the idiot box once again came into picture. Having been tired of 9 hours job, when you come to home, you are not going to strain your fingers on keyboard once again to catch up some fun. Needless to say, many sites are banned in companies, so there is nothing left for you other than your prime activity (“People call it work…ohh i do say”).

Moving ahead..i used to be a good TV maniac when i was a school guy or even before that period. Reason, VJs of MTV or Channel V! They used to teach me…what they taught, you may guess and let me know.  Still finding their lost shows on Youtube becomes my good time pass (who has got time to pass???..huh!) Well..when i usually, non intentionally, surf my tv with a pinch of salt hope that something will entertain me but unfortunately…

MTV/channel V/Vh1: are not aired by the Damnn Cablewalah.

Bhakti channels :Am i that aged to watch’em?

News Channels: Ohh..stupid me! Why dont i also start my news channel. Cover something silly with the camera and air them on regular intervals, such an easy job, isn’t it?

Sports channels: God! FIFA is over and Roger comes very rare so i have to wait for long to tune them

Hindi movie channels: Buddy…is there anything more sucking than a repeated hindi movie on the box?

English movie channels: Oh yes! can i watch them? but that needs concentration.

Comedy channels: it would be kidding if i write anything here.

Saas Bahu Channels: Thanks Ms/Mrs (I dont know what) Kekta Kapoor, for making one’s life a chewing gum and everything an action replay. You have washed not only women’s but also guys’ minds too with your daily soaps. Hats off to you!

Science Channels: Do they entertain really, when you are tired?

Oh! Did i forget to mention any other channel?

So..you might be thinking what the heck this guy is? Wait buddy…

There is something which is very very in vogue and that is Reality shows on television. Earlier, i heard the names only, now i am able to watch them and that why this post is being added. No doubt..people love it more than their personal lives (Correct me!). One such show i came to know about 6 years ago, “INDIAN IDOL” (There are many such shows, but let me restrict myself on this only). I am watching it for last three weeks or so and am trying to point out some things i noticed:

one: Even if you are a singer, don’t put your hands in joining such shows, because you may see your career as what the the first indian idol has right now and others are having (well…anyone knows who are other idols or better say idles, lol :) ) So, probably you’ll not love to be an anchor rather than a singer.

two: If you are a good singer (you think, or your friends say), i would suggest to make it a hobby, not a profession. (of course Luck doesn’t favours all).

three: Judges involved in the show, they know what a fellow can do, but they have given job to speak fake reality. They are meant to fight among one another otherwise who the hell is going to watch. You can smell this rat, when everything is going peachy, suddenly you listen a different sound and the camera halts on one of the faces.

four: If you are a star and you have to promote something, please help yourself and contact Indian idol group, they will provide you the right platform.

five: Contestants, if they dont get a job of a singer, they at least get some popularity for a little timespan and needless to mention: some attractive suit or jewellary sets.

six: The channel gets popularity not by showing their talent but by showing the backstage footage.

seven: You spend one fourth of your showtime in watching their talents, and other time in watching silly quotes, votes prayer, judges’ idea and ugly ads.

So..do you think..it really worked for me?

Rather it caused me to write this post..rofl :P

Hell lot of time passed since i updated my blog with a new post.  This time while working with WPF, i feel like write something on what is called MVVM Design pattern.

MVVM has got three components:

  • Model: Data+Classes; Nothing WPF sepcific.
  • View: This is the User Interface element visible to the user. Its DataContext is its ViewModel.
  • ViewModel: It contains all the data that needs to be displayed and procedures to modify the model at will. ViewModel knows nothing about the View.

This is very loosely coupled design pattern. The View knows the ViewModel but the ViewModel does not know the View. You can very easily replace the View without affecting the ViewModel. This is very useful in Developer/Designer teams where the Developer improves the ViewModel and the Designer enhances the View.

The fact that the ViewModel does not know anything about the View comes as a bit of surprise. A typical View in MVVM does not need have a code-behind (except for the general code that calls the InitializeComponent() method from the constructor)!!

You may be wondering how the view updates itself when the ViewModel changes and how it handles user interaction like button clicks etc. This is what makes MVVM specific to WPF.

The controls in the View bind themselves to the corresponding properties in the ViewModel. The changes in ViewModel will be reflected in the view, thanks to Data Binding in WPF. (Otherwise we would have had to handle every event and then update the view accordingly.)

As for user interaction, we always have had commands in WPF. MVVM leverages on this feature. Instead of writing event handling code for button clicks, we bind the buttons (or MenuItems) to Commands in the ViewModel. Every button binds itself to a command which the ViewModel exposes. This command delegates its job to a method in the ViewModel that gets the work done. But the problem is that there is no built-in command in WPF that does that. We have a RoutedCommand that targets UIElements but not methods. Here comes to the scene a new command that targets methods, the DelegateCommand or the RelayCommand. Controls can bind the RelayCommand (that the ViewModel exposes) and invoke methods in the ViewModel.

The DelegateCommand implements the ICommand interface and delegates the Execute and CanExecute methods in the interface to methods in the ViewModel.

That’s all with the theory and understanding i have. The sample code snippets i will update soon.

Aricent visit in my school

After a long span, i am writing my new post which is not techy in fact.
This is regarding my experience as a student coordinator on arrival of Aricent.
I had so many talks with the Aricent HR since the months of April-May and till now. But due to some reasons or other the things were not getting into shape. Finally, i somehow managed to invite it for recruitment in our campus on 13th Nov., 09. In the long run, the recruitment team arrived at our school in the morning at 09:00am. We had each and every sort of arrangements for that day. After a small talk, there started the pre-placement talk. Thereafter, there was a written exam (1 and half an hour) for which we sat and 14 qualified for the next round among 25. Then, there was a group discussion round for two teams of 7 students each. This was not an elimination round but the marks mattered in the last round that was interview, which lasted upto 7:30pm. Students were waiting for the results curiously. Finally, that time came when the HR announced 10 names of my friends who qualified for Aricent. I saw whole lot of crowd in a deep ocean of delight; but they didn’t know that the person who got immense pleasure from all that, was myself.
When this process was over, we made a warm see off with everyone in the team.

So, it was all about my experience..i hope it continues further.

This post is after about a month long hibernation from my blog.
I made my mind up to listen songs as i usually do (it contributes to my hobby). In fact, i was suffering with a headburst headache, so i thought songs might be the stress buster and good entertainer too. What striked my mind was why couldn’t i play the tracks on command line rather playing’em in traditional RhythmBox or Amarok etc. The way i thought, the way i found…some googling let me find such a tool named mpg123, which is nothing but a command line player cum MPEG streamer.
Installation on Ubuntu/Debian: sudo apt-get install mpg123
Installation on RedHat/Fedora/Cent OS: For this, we have to first enable the rpmforge repo and try
yum install mpg123
and you are done.

Go to the shell; Move into your songs folder; and type in mpg123 * as below:
neeraj@nee-pc:/media/LEISURE/fun/songs$ mpg123 *
Just press Ctrl+C , if you want to switch onto the next song in the folder.
Have a glimpse of the mpg123 on my UbuntuBox:

mpg123

Play files on the shell itself

Type man mpg123 and you will see what else can you do with this versatile thing.
Thanks GNU.
!!

Konchem Ishtam Konchem Kashtam is a typical family entertainer which has been carved in the lines of Siddharth’s previous movie “Bommarillu”, but has a different concept of storyline.  I am not a kind of Kuchh Kuchh Hota hai like movie’s watcher but this movie has something worth watching. The feel of the movie is same as Bommarillu (the first ever South Indian Movie in Telugu, i watched), but the story, screenplay and the direction look different in an innovative way. This whole movie revolves around Siddharth and his love Tamannah and the kind of circumstances they face from their elders, after falling in love. After Vishal-Shekhar, it’s Shankar-Ehsaan-Loy composing for a Telugu movie. They don’t unleash their full potential here, but it’s still an enjoyable album. The song egire egire reminds me youth oriented songs in chartbusters such as RDB and Yuva.

A still is here:

egire egire from KIKK

egire egire from KIKK

A total of 7.5 is there from my side for this movie out of 10 which makes it My movie of the week!!

This was basically a novice step by me to setup an ftp server locally, but i succeed! Proftpd is the professional FTP daemon. It can be found in Synaptic package of Ubuntu or can be downloaded via apt-get. Just install it and use standalone server.

Launch it through console (see manual pages for documentation):

neeraj@nee-pc:~$ proftpd

and check through your browser whether it’s running or not. Type ftp://localhost/ in the address bar and assign username and password (the same you use to login into your system)there in the dialoguebox. You must see a window like this:

Local file transfer protocol
Local file transfer protocol

I tried to access it on other computer on my LAN through my ip:

ftp://192.168.*.*

and it was working perfectly fine. So..are you gaming to set up your own ftp?? what say??

free counters

Hello Googlers!
I am pleased to inform you about The Google India Women In Engineering Award 2010‘. This is an initiative launched by Google India in 2007-2008 with an objective of recognizing and rewarding deserving women students in the field of Computer Science In this third edition of our awards, we welcome applications from female students pursuing Bachelors, Masters and PhD in computer science, who meet the eligibility criteria. Applications are open from15th Sept ’09 to 31st Oct ’09. A group of most deserving students will be chosen form the applicant pool and the award recipients will receive a sum of INR 100,000 each.Highlights of the last years awards can be found on the website.
Feel free to share this within your friends network.
For any questions, please write in to ind-diversity@google.com
I wish i would be from Venus! :)

Follow

Get every new post delivered to your Inbox.