Monday, June 11, 2012

Sending XML Queries in python using urllib2

Query is the xml string that you want to send.  Modify the content type according to your needs.

    def send_xml_query(self, query, host, port):

        query = query.replace ('\n', '')

        headers = {"Content-type": "application/xml"}

        host = 'http://%s:%s' % (host, port)

        request = urllib2.Request(host, query, headers)

        response = urllib2.urlopen(request)

        return request, response

Wednesday, April 18, 2012

Search your sourcecode better with ack..!

One of my good friends told me about a new tool that I could use to search for strings in my source code.

It is called ack and it is pretty easy to install and use.

I have a RHEL 5.5 system and it works without a lot of hassle.

Below is the URL for it.

The URL for the actual tool is

As the name suggests, this is a better than grep and I second it.

So who is this useful for?

I would say developers who use search more often to look for certain specific strings in their source code would really love this tool.


  • It's fast because it only searches the stuff it makes sense to search.
  • Searches entire trees by default while ignoring Subversion, Git and other VCS directories and other files that aren't your source code.
  • Where grep is a general text search tool, ack is especially for the programmer searching source code. Common tasks take fewer keystrokes.
  • Ack costs nothing. It's 100% free.

Thursday, March 22, 2012

Verify Apple store (In-app purchase) receipts in python

Python is very versatile and dynamic programming language and I use it on a daily basis.

Currently I was working on the In-app purchases from the App store and was wondering how I can verify the app store receipt data on the python prompt.

I found it easy in python to communicate to the app store and verify the app store receipt.  This article talks about how you can do it on the python prompt.  Hopefully this works and helps anybody trying to verify the receipt data from app store through the sandbox/app store.

I was trying to look for examples on the web if somebody had already done it in python but did not find one.  So here it goes.!!!

import urllib, urllib2
import simplejson as json
import datetime
url = ''
receipt_data = 'receipt_data'
password =  'your_password'

data = { "receipt-data": receipt_data, "password": password }
headers = {'Content-Type': 'text/Json; charset=utf-8'}
dataj = json.dumps(data)
request = urllib2.Request(url, dataj, headers)

# In case you are wondering what is being sent and the format
print "request%s" % request.get_data()
# This shows the method either POST or GET (App store wants POST and not GET)
print "request type %s" % request.get_method()
start_time =
response = urllib2.urlopen(request)
wait_time = - start_time
print('Wait time for validation call: %s' % wait_time)
response_json = json.loads(
print response_json

{'status': 21006, 'receipt': {'purchase_date_pst': '2012-03-16 15:33:58 America/Los_Angeles', 'expires_date': '1331937538000', 'product_id': 'your_product_id', 'original_transaction_id': '1222000034404994', 'expires_date_formatted_pst': '2012-03-16 15:38:58 America/Los_Angeles', 'original_purchase_date_pst': '2012-03-16 15:33:59 America/Los_Angeles', 'item_id': 'your_item_id', 'original_purchase_date': '2012-03-16 22:33:59 Etc/GMT', 'expires_date_formatted': '2012-03-16 22:38:58 Etc/GMT', 'bvrs': 'your_version', 'original_purchase_date_ms': '1331937239000', 'hosted_iap_version': '2.718', 'purchase_date': '2012-03-16 22:33:58 Etc/GMT', 'web_order_line_item_id': 'your_id', 'purchase_date_ms': '1331937238000', 'bid': 'your_bid', 'transaction_id': '1222000034419520', 'quantity': '1'}, 'latest_expired_receipt_info': {'purchase_date_pst': '2012-03-17 00:59:55 America/Los_Angeles', 'expires_date': '1331971495000', 'product_id': 'your_product_id', 'original_transaction_id': '1222000034404994', 'expires_date_formatted_pst': '2012-03-17 01:04:55 America/Los_Angeles', 'original_purchase_date_pst': '2012-03-16 15:33:59 America/Los_Angeles', 'item_id': 'your_item_id', 'original_purchase_date': '2012-03-16 22:33:59 Etc/GMT', 'expires_date_formatted': '2012-03-17 08:04:55 Etc/GMT', 'bvrs': 'your_version', 'original_purchase_date_ms': '1331937239000', 'purchase_date': '2012-03-17 07:59:55 Etc/GMT', 'web_order_line_item_id': 'your_item_id', 'purchase_date_ms': '1331971195000', 'bid': 'your_bid', 'transaction_id': '1222000034486923', 'quantity': '1'}}

Below is the URL that has additional details on the error codes and API details.

Tuesday, September 27, 2011

Taking good HDR Pictures

Tips on good HDR pictures

I am copying it to have a good reference

Source :

  1. Always use aperture priority mode.
  2. Always utilize the lowest ISO possible to reduce noise.
  3. Any errors introduced into the work-chain will always run the entire path from the point of introduction.
  4. Reduce or eliminate errors by recognizing common or frequent ones and become cognisant during the workflow.
  5. Perform as much of the “heavy lifting” as possible in the HDR merge/tone-mapping application.  We use Photomatix Pro.

Aperture Priority Mode
Most modern DSLR cameras give the photographer the ability to select several different “priority” modes.  In the holy trinity of camera settings, being ISO, shutter speed and aperture setting (f/stop), if you select aperture priority mode it allows you to specify the f/stop and ISO, and the built in light meter will automatically select the correct shutter speed for you.  If you are in shutter priority mode, you would select ISO and shutter speed, and the built in meter would automatically set the f/stop for you.
I always use aperture priority.  The reason for this is it will create the most crisp and detailed merge possible as each frame, referred to as brackets, will be the identical focus and depth of focus.  If you were to go with shutter priority, each bracket would have a different f/stop and thus a different depth of focus.  This makes for much less clarity in the final merged result.
From here for me, the tricky part is selecting the right f/stop and ISO setting to achieve the result I am going for.  I find that sometimes I have to increase the ISO to get faster shutter speeds to avoid motion blur.  For the style of photography that we do, moving objects like birds and foliage are our biggest nemesis.  I tend to shake my fist at the wind.
Lowest ISO
I always try to use the lowest ISO I possibly can to reduce noise and produce better quality results.  The more noise that is evident in the source files, the more noise you’ll have in your output.  But, as mentioned before, motion is the hardest thing to compensate for with our style of imagery, and therefore we sometimes have to forgo using 100 ISO to offset external lighting and movement issues.
Errors In The Chain
Any time an error is introduced into the work-chain, that error follows forward to the end of the chain; your final result.  This really drives us to be as accurate and careful through each step of the process to avoid or at least vastly reduce these errors.
For example, if I didn’t properly tune my settings during the image capture process and wind caused massive blur in the trees in my picture due to a slow shutter speed, I cannot correct that.  This error will follow through to the bitter end.  These images never make it “live” and end up archived on my long term storage never to be seen again.
Taking this concept further, if during the merge and tone-mapping step I blow out my whites on the histogram, those details are lost forever and cannot be corrected.  What this all comes down to is by the time I am finalizing my image in Photomatix to bring into my final post-processing software, it contains no major errors and has all the dynamic range I want… it just needs some tweaking to really bring it to life.
Reduce or Eliminate Common Mistakes
As I was going through (and continue to) my learning process, I started to notice common mistakes I was making that resulted in sub-standard image quality.  At this point I became aware of these issues and started to look for them before they were introduced into the work-chain.  I can honestly say that our percentage of internet ready images shot up when I started to do this.  You may believe this to be common sense, and I can`t really disagree, but it`s so important I felt it merited discussion.
Heavy Lifting in the Merge
I try to do as much heavy lifting as possible in the merge process.  When the image is loaded into my final post-processing software, no whites or blacks can be blown out, no ghosts can remain, no color banding can exist; these are things that cannot be remedied.
There are many settings, in Photomatix Pro these are represented as sliders, that the photographer can adjust in the tone-mapping phase.  This is a critical phase of image creation.  I have several sliders that almost always remain the same, and several that need to be manually adjusted for each image processed.  I cannot use batch processing, I must merge and tone-map each picture individually.  This is where the personal style comes into play.  Once I identified what I was trying to do with my HDR work, it became a matter of finding those settings that produced these results.
From this point, the final merged and tone-mapped image is saved as a TIFF file and brought into my final phase post-production software.  I only typically perform the following actions in this software, in this order:
  1. Remove any blemishes in the sky, usually perfect, tiny little circles that are darker than their surroundings.
  2. Adjust brightness and contrast, color saturation, and sharpness.
  3. Apply a minor filter that tends to shift the tone scale ever so slightly to a darker tone; I find this accentuates the light and shadow regions in our photos providing a better looking end result.
  4. Apply a high pass sharpen filter to accentuate the details, using a very low threshold setting to avoid over-sharpening.
That`s it.  We have our final image.

Sunday, January 30, 2011

Installing Mercurial on RHEL 5.5

Finally after a few attempts, I could install mercurial on RHEL.

Here are the steps I followed and thanks to a few forum posts, I found out my way through it.

So I tried all kinds of ways but what eventually worked was easy_install.

So this is what you need.


Downloaded the latest mercurial rpm.  Untar it.

Now if you dont have easy_install, install it by running the below command


Once you are done downloading run the below command

ronak@ronak ~ $ sudo sh setuptools-0.6c11-py2.4.egg
[sudo] password for ronak:
Processing setuptools-0.6c11-py2.4.egg
removing '/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg' (and everything under it)
creating /usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg
Extracting setuptools-0.6c11-py2.4.egg to /usr/lib/python2.4/site-packages
setuptools 0.6c11 is already the active version in easy-install.pth
Installing easy_install script to /usr/bin
Installing easy_install-2.4 script to /usr/bin

Installed /usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11

If you see this, easy_install is installed on your system.

Now, remember you have the untar directory mercurial1.7 (or whatever you have).  Make sure you are at that location.

Run the below command

ronak@ronak ~ $ sudo easy_install mercurial-1.7/
ronak@ronak ~ $ sudo easy_install mercurial-1.7/
Running -q bdist_egg --dist-dir /usr/local/home/rpatel/mercurial-1.7/egg-dist-tmp-bHHAXk
zip_safe flag not set; analyzing archive contents... module references __file__
mercurial.lsprof: module references __file__
mercurial.commands: module references __file__
mercurial.extensions: module references __file__
mercurial.i18n: module references __file__
mercurial.templater: module references __file__ module references __file__
Adding mercurial unknown to easy-install.pth file
Installing hg script to /usr/bin

Installed /usr/lib/python2.4/site-packages/mercurial-unknown-py2.4-linux-i686.egg
Processing dependencies for mercurial==unknown
Finished processing dependencies for mercurial==unknown

ronak@ronak ~ $ hg
Mercurial Distributed SCM

basic commands:

 add        add the specified files on the next commit
 annotate   show changeset information by line for each file
 clone      make a copy of an existing repository
 commit     commit the specified files or all outstanding changes
 diff       diff repository (or selected files)
 export     dump the header and diffs for one or more changesets
 forget     forget the specified files on the next commit
 init       create a new repository in the given directory
 log        show revision history of entire repository or files
 merge      merge working directory with another revision
 pull       pull changes from the specified source
 push       push changes to the specified destination
 remove     remove the specified files on the next commit
 serve      start stand-alone webserver
 status     show changed files in the working directory
 summary    summarize working directory state
 update     update working directory (or switch revisions)

use "hg help" for the full list of commands or "hg -v" for details
ronak@ronak ~ $

Hurray... You are done..!!!!


YUM (Yellow Dog Updater, Modified)

The Yellowdog Updater, Modified (YUM) is an open-source command-line package-management utility for RPM-compatible Linux operating systems and has been released under the GNU General Public License. It was developed by Seth Vidal and a group of volunteer programmers. Though yum has a command-line interface, several other tools provide graphical user interfaces to yum functionality.

Installing and Upgrading Packages with Yum

Install Packages, Upgrade packages and System upgrades
Update your package list
# yum check-update
Install a new package
# yum -y install compiz
-y flag allows unattended installation.
Update a single Package
# yum update gnome
Update several packages
# yum update nbserver nbweb-billing nginx
Update all installed packages
# yum update
Search for a package to install
# yum search ImageMagick
If you need a particular library, but don't know what package provides it, yum will find it
# yum provides compiz

Removing Packages through Yum

# yum remove compiz
# yum remove compiz gnome ImageMagick

Obtaining information of installed packages through Yum

# yum list compiz
# yum list | grep gnome
# yum info compiz
# yum list updates

Maintain Yum

# yum clean packages -- to delete all cached packages
# yum clean headers -- to force fresh download of package headers
# yum clean oldheaders -- to remove old headers that the system no longer needs
# yum clean all == remove cached packages and old headers, preserving all the current headers


Red Hat Package Management

Installing RPMs

# rpm -i packagename

# rpm -ivh packagename
  -v adds verbose feedback, and -h draws progress hashmarks

# rpm -ivh --test packagename

Upgrading RPMs

# rpm -Uvh packagename

To test the package install without really installing it.
# rpm -Uvh --test packagename

Removing RPMs

#rpm -e packagename does the job 

# rpm -ev packagename

( You dont need to mention the entire package, (abcd- just the label name (abcd).

Removing/Uninstalling multiple RPMs at once.

# rpm -ev packagename packagename packagename

If you dont want to check dependencies,

#rpm -ev --nodeps packagename

To test your command before uninstalling/removing
#rpm -ev --test packagename

Collecting information on Installed RPMs
Use RPM's querying features.  All the queries start with rpm -q.
# rpm -q compiz

# rpm -qa | grep ubuntu

Listing files in an installed package

# rpm -ql compiz

To list the documentation for an application, use

# rpm -qd ubuntu

To list the configuration files for a package, use

# rpm -qc compiz

Listing the configuration files for a command

# rpm -qcf /usr/bin/ssh

To list all the packages installed, use

# rpm -qa

To see what package a file belongs to, use

# rpm -qf /usr/bin/abcd

To display package information 

# rpm -qi packagename

RPM queries will not follow symlinks, and will report that the file is "not owned by any package"  To find the file that a symlink points to , use:

# namei ~/ronak

Collecting Information from RPMs that are not installed.

Listing documentation files
# rpm -qpd abcd.rpm

Listing all the files of the package:

# rpm -qp1 abcd.rpm

Listing dependencies this package requires, 
# rpm -qpR abcd.rpm

To see what this package provides

# rpm -qp --provides abcd.rpm

Finding recentally installed RPMs

# rpm -qa --last
If the list is too long, rpm -qa --last | head.

Rebuild RPM database

# rpm --rebuilddb

Recreate RPM database
# rpm --initdb

Thursday, December 30, 2010


Vim Text Editor

  • On every platform
  • 100% keyboard driven
  • Text surgery
  • powerful editing
  • Local and remote
  • Highly configurable
  • Extendable with plugins
  • Mac-friendly
  • Great Documentation
  • Long-terms skills
  • Undesirable defaults
  • Clunky scripting Language
  • Destructive tasks are too easy
  • Inconsistent regular expressions
Started in 1976 then 1991 and now it is called VIMproved (VIM)

Main modes of VI editor
  1. Normal
  2. Insert
  3. Visual
  4. Replace
  5. Command-line
Upper case commands are super sized versions of the lower case commands

i - Inserts text starting from the cursor
I - Inserts text starting from the beginning of the line.
w - moves forward one word
3w - moves forward 3 words
b - moves backware one word
W - moves contiguous code as one word and move forward to the next meaningful word
dd - deletes the line where the cursor is located
dw - deletes the word
d2w - delete two words
G - goes to the end of the file
gg - goes to the start of the file
:w - write file (save)
:w! - write without confirmation
:q! - quit vim
:wq! - write and quit
:e filename - opens a file to edit
code folding command starts with a z
cw - change word
3cw - change three words
:h - help:bd - buffer delete

yy - yank line (copy)
Y - yank line (copy)
p - paste below cursor
P - paste above cursor
a - append text after cursor
6l - Forward six letters
2j - Down two lines
fN - Jump forward to the first 'N'
3fN - Jump forward to third 'N'
n- Next 

u - undo
Ctrl+R - redo

vim -N (-N compatible with the latest version only)

Vim comes with 500 different syntax highlights.

:syntax enable
:set syntax=apache

:set hidden
:set syntax=python
:set syntax=cpp

:w !sudo tee %

:set incsearch
:set hlsearch

Search and replace


  % search the current buffer
  g - search for all occurance
  c - ask for confirmation on each match

e.g :%s/2.\2\.8/2.2.9/gc - this will replace all 2.2.8 occurances to 2.2.9 and will confirmation all occurances.

:set number
12G - go to line 12

:cd path
:e . - to find out the files in the directory

V - visual mode

:b name - Switch to buffer (try TAB and arrows as well)
:bp - Previous buffer

:set autochdir - Automatically use the current file's directory as the working directory

Check out the vim-rooter plugin.

:set wildmode=list:longest - Activate TAB auto-completion for file paths.

Directory listing.

i - thin, long, wide or tree listings
s - sort on name, time or file size
r - Reverse sort order
gh - Hide or unhide dot files
- Open the file or directory
x - View file with associated application
d - Make directory
D - delete the file or directory
R - Rename the directory or file
- <-- Go up a directory

Window Management

Ctrl+w s - split window horizontally
Ctrl+w v - split vertically
Ctrl+w j - Move focus down
Ctrl+w k - Move focus up
Ctrl+w h - Move focus left
Ctrl+w l - Move focus right

Ctrl+w J - Move buffer up one window
Ctrl+w K - Move buffer down one window
Ctrl+w H - Move buffer left one window
Ctrl+w L - Move buffer right one window

Ctrl+w c - Close window
Ctrl+w o - Close all but current
Ctrl+w w - Cycle focus
Ctrl+w p - Focus previous window

Friday, October 15, 2010


Came along an interesting puzzle so wanted to share.

Write a function that adds two numbers.  You should not use + or any arithmetic operators.

Lets have two number which are fairly large and try to add those two numbers but try a different approach.

987+789 = 1776

Lets just think backwards

+ 789

Carry : 1110.  This is calculated when the first carry is the first digit and the last carry is the last.

Add 1110 and 666 which gives you the ultimate result.

Now lets implement it in source (I am using python)

>>> def sum_without_arithmetic(a,b):
...     if b==0: 
...         return a
...     sum = a^b
...     carry = (a&b)<<1
...     return sum_without_arithmetic(sum, carry)
>>> sum_without_arithmetic(987,789)

Thursday, October 14, 2010

More Interview Questions


Explain what happens, step by step, after you type a URL into a browser.  Use as much details as possible.

1. Browser contacts the DNS server to find the IP address of the URL.
2. DNS server returns the IP address of the site.
3. Browser opens a TCP connection to the web server at port 80.
4. Browser fetches the html code of the page requested.
5. Browser renders the HTML in the display window.
6. Browser terminates the connection when window is closed.


1. What are different types of join?  Please explain how they differ and why certain types are better in certain conditions.

JOIN is used to combine the results of two tables.  To perform a join, each of the tables must have at least one field which will be used to find matching records from the other table.  The join type defines which records will go into the result set.


Result set will contain only those data where the criteria match.


Outer join will always contain the results of INNER JOIN, however it can contain some records that have no matching record in other table.  OUTER JOINs are divided into following subtypes


The result set will contain all the records from the left table.  If no matching records were found in the right table, then its fields will contain NULL values.


Opposite of the LEFT JOIN.  It will contain all the records from the right table, and missing fields from the left table will contain NULL.

If we have two tables A and B, then we can say that statement A LEFT JOIN B is equivalent to statement B RIGHT JOIN A.


FULL OUTER JOIN combines the results of LEFT and RIGHT joins.  All records from both the tables will be part of the result set, whether matching records exists in other table or not.  If no matching record was found, then the corresponding result fields will have a NULL value.


Compare and contrast Hash Table vs. STL map.

Hash Table:

In a hash table, a value is stored by applying hash function on a key.  Thus, values are not stored in a hash table in sorted order.  Additionally, since hash tables use the key to find the index that will store the value, an insert/lookup can be done in amortised O(1) time (assuming a few collisions in a hash table).  One must also handle potential collisions in a hash table.


In STL Map, insertion of key/value pair is in sorted order of key.  It uses a treee to store values, which is why an O(log n) insert/lookup is required.  There is also no need to handle collisions.  An STL map works well for things like:
  • find min element
  • find max element
  • print elements in a sorted order
  • find the exact element or if the element is not found, find the next smallest number.
Implementation of a Hash Table

  1. A good hash function is required (e.g. operation % prime number) to ensure that the hash values are uni-formally distributed.
  2. A collision resolving method is also needed: chaining (good for dense table entries), probing (good for sparse table entries), etc.
  3. Implement methods to dynamically increase or decrease the hash table size on a given criterion.  For example, when the [number of elements] by [table size] ratio is greater than the fixed threshold, increase the hash table size by creating a new hash table and transfer the entries from the old table to the new table by computing the index using new hash function.
What can be used instead of a hash table, if the number of inputs is small?

You can use an STL map.  Although this takes O(log n) time, since the number of inputs is small, this time is negligible.

Wednesday, May 5, 2010

C++ style puzzles

Some interesting puzzles that can be asked in an interview.

1. Given a vector v, what is the difference between the lines marked A and B?

void f(vector& v) {
v[0]; // A; // B

If v is not empty then there is no difference between lines A and B. If v is empty, then line B is
guaranteed to throw a std::out_of_range exception, but there's no telling what line A might do.
There are two ways to access contained elements within a vector. The first, vector::at, is required to perform bounds-checking to ensure that the vector actually contains the requested element. It doesn't make sense to ask for, say, the 100th element in a vector that contains only 10 elements at the moment, and if you try to do such a thing, at will protest by throwing a std::out_of_range hissy fit (also known as an exception).

Saturday, January 30, 2010

dil to bacha hai ji -- ISHKIYA guitar chords

I have been learning to play guitar for some years now.

Here is my attempt to decode the chords of a new song.

“Dil toh bacha hai ji” from the movie Ishqiya is a good

slow song. Reminds me of the old Rajkapoor movie songs.

Rahat Fateh Ali Khan’s voice has made this song even


Now, to play this song on guitar you show know to play the

Bar Chords.

Strumming pattern: |DD - DD -|DD – DD -|


Aisi ulji nazar unse hatt ti nahi


Daant se reshmi dor katt ti nahi

Umar kab ki baras ke safaid ho gayi

Kaari badari jawani ki chatt ti nahi

F#m        Bm

Walla ye dhadkan bhadne lagi hai

F#m        Bm
Chehre ki rangat udne lagi hai

F#m        Bm
Darr lagta hai tanha sone mein ji
F#m         Bm        C#m

Dil to bachcha hai ji

F#m        Bm        C#m
Dil to bachcha hai ji

F#m        Bm        C#m
Thoda kaccha hai ji

F#m        Bm        C#m
Haan dil to baccha hai ji

Aisi ulji nazar unse hatt ti nahi


Daant se reshmi dor katt ti nahi


Umar kab ki baras ke safaid ho gayi


Kaari badari jawani ki chatt ti nahi

F#m        Bm        C#m
Ra ra ra .. x 2

F#m        F#
Kisko pataa tha pehlu mein rakha

Dil aisa baaji bhi hoga

F#m        F#
Hum to hamesha samajhte the koi

Hum jaisa haaji hi hoga

F#m        Bm
Hai zor karein, kitna shor karein

F#m        Bm
Bewaja baatein pe ainwe gaur karein

Dilsa koi kameena nahi

F#m        Bm
Koi to rokey, koi to tokey

F#m        Bm
Iss umar mein ab khaogey dhokhe

F#m        Bm
Darr lagta hai ishq karne mein ji

F#m        Bm        C#m
Dil toh bachcha hai ji

F#m        Bm        C#m
Dil toh bachcha hai ji

F#m         Bm         C#m

Thoda kaccha hai ji

F#m          Bm         C#m

Haan dil to baccha hai ji

F#m         F#

Aisi udhaasi baithi hai dil pe


Hassne se ghabra rahe hain

F#m         F#

Saari jawani katra ke kaati


Piri mein takra gaye hain

F#m         Bm

Dil dhadakta hai to aise lagta hai who

F#m         Bm
Aa raha hai yahin dekhta hi na woh

F#m         Bm

Prem ki maarein kataar re

F#m         Bm

Taubah ye lamhe katt te nahi kyun

F#m         Bm

Aankhein se meri hatt te nahi kyun

F#m         Bm

Darr lagta hai mujhse kehne mein ji

F#m         Bm         C#m

Dil toh bachcha hai ji

F#m         Bm         C#m

Dil toh bachcha hai ji

F#m         Bm         C#m

Thoda kaccha hai ji

F#m         Bm         C#m

Haan dil toh baccha hai ji

Saturday, August 22, 2009

how to download songs for free...!!!!

Everybody is looking for bollywood songs and they want to play in their cars / ipods and nobody wants to pay for the mp3s or CDs. The only reason is if somebody can get it for free why can't I? Well a lot of people discuss how to download songs from the Internet and there is no single source on the internet that will give you all the songs starting from oldies to the latest songs. I believe lot of people know about the new that is available but oldies fans like me have a hard time finding songs that they can download and play in their ipods and cars.

So as always I dedicate this post to all the fellow oldies fans and obviously the new ones....... I will show you how you can download songs...any songs...

1. Use Firefox only. This works only in firefox
2. Go to Tools-->Add ons--> Get Add ons --> Browse all add ons...
3. This will take you to all the add ons available.
4. Search for downloadhelper.
5. First result you will get is downloadvideohelper.
6. Download that and install it and restart firefox.

You are almost done.....

1. Go to your favorite songs site and start playing your favorite songs and you will see the downloadvideohelper icon revolving.
2. Click the icon and you will see all the songs that are one of them and it will ask you to save ....and there you go.....You are all set.....

Let me know if you have any questions.......

Friday, August 21, 2009

Python Interview questions

List of questions on the interview....

1. What is list comprehension?
2. what is better += or .join()?
3. Do you know what is ISAPI filters?
4. How do you do unit testing?
5. What are you good with? Object oriented or subject oriented?
6. What is your favorite programming language? C++ or Python or anything else?
7. What is your favorite design pattern?
8. Explain singleton design pattern.
9. What version of Python do you use? 2.4/2.6/3.0?
10.Have you used any of the python frameworks? Django?
11. Are you are back end developer or a front end too?
12. When and why did you use Inno setup?
13. Explain difference between public, private and protected in C++
14. How many million pois we have in our db?
15. What is the percentage of C++ coding v/s Python coding in the last two years..?
16. Do you use Navteq maps for the map data?

Tuesday, July 21, 2009

Hindi translation of common english words

I am trying to imporve my hindi vocabulary and was trying to find out transloation of words that we use in our day to day life.

I found a blog that served my purpose....This is not my creation...just a bookmark of somebody else's work... I like to appreciate others work by posting their article on mine and giving them credit ...Here you go and hope you like it...

CRICKET : Gol guttam lakad battam de danadan pratiyogita

CRICKET TEST MATCH : Pakad dandu, maar mandu, de danaadan pratiyogita

TABLE TENNIS : Lakdi ke phalak shetra pe le takaatak de takaatak

LAWN TENNIS : Harit Ghaas par le tada tad, de tada tad

LIGHT BULB : Vidyut Prakashak Kanch golak

TIE : Kanth Langoti

MATCH BOX : Ragdampatti Agni Utpaadan Peti

TRAFFIC SIGNAL : Aavat Jaavat Suchak Jhandaa

TEA : Dugdh Jal Mishrit Sharkara Yukt Parvatiya(pahaadi) Booti

TRAIN : Sahasra Chakra Louh Path Gaamini

ALL ROUTE PASS : Yatr Tatr Sarvatr Gaman Aagya Patr

RAILWAY SIGNAL : Loh Path Gamini Suchak Yantra

RAILWAY SIGNAL : Agni Rath Aava Gaman Soochak Pattika

RAILWAY SIGNAL : Louh path gaamini aawagaman suchak yantra


BUTTON : Ast Vyast Vastra Niyantrak

MOSQUITO : Gunjanhaari Manav Rakt Pipasu Jeev

CIGERETTE : Shweta patra mandit dhumra shalakha

Friday, June 19, 2009

Guitar Chords - Kisi ki muskurahton pe......

Kisiki muskuraahaton pe ho nisaar

Kisika dard mil sake to le udhaar

Kisike waaste ho tere dil mein pyaar

Jeena issi ka naam hai

(repeat again)

Maana apni jeb se fakeer hain

Phir bhi yaaron dil ke hum ameer hai

Mitte jo pyaar ke liye woh zindagi

Jale bahaar ke liye woh zindagi

Kisi ko ho na ho hamein to aitbaar

Jeena issi kaa naam hai

stanza 2nd as first only..
(Rishta dil se dil ke aitbaar ka

Zinda hai hameen se naam pyar ka) - x2

Ke mar ke bhi kisi ko yaad aayenge

Kisi ke aansuon mein muskuraayenge

Kahega phool har kali se baar baar

Jeena isi ka naam hai

Kisiki muskuraahaton pe ho nisaar..

Thursday, June 4, 2009

C++ -- STL -- Vector -- Tutorial

Found out some good tutorial about Vectors. I believe most of the novice C++ programmers will know a lot about STL and vectors but this is one in case if somebody needs to brush up.

Vector Tutorial - Part I

Vector Tutorial - Part II

Hope this helps

Friday, May 29, 2009

Share your videos with your friends SEETOO.COM

Everything is getting pretty easy and this is one step into the easiness over sharing the data.

What if you want to share a movie with your friends miles away from where you are located...or possibly the next room or may be next street? You write it over a CD or a flash drive and give it to him which he copies and starts watching....but that is pretty impossible when you are miles away from your friend. And sometimes it really becomes difficult for you to upload it somewhere and then your friend needs to download it and I would consider it painful to do this stuff for just small thing like a video.

So what is the solution to this problem? Well here it is

And what does seetoo do? Well it says I am seeing this video, you SEE TOO. So it is a service where you share your video to a bunch of friends or many friends over the internet and you can watch it all together.

Well what if you suggest one of your friend a movie and he/she doesn't have a copy of the DVD or doesn't have it downloaded and you know it is painful to wait for the movie to be downloaded. So what you do is talk to him and tell him "Hey I have the movie and I will broadcast it for you.

It is so easy.

1. Go to
2. No login - Best part
3. Select the video you want to share.
4. Start the video.
5. Send an invitation to your friends who want to watch the video.

That's it...!!!! Isn't that too simple? I bet your answer will be yes. Don't believe it. I believe you should give it a try.

let me know if you like it....!!! Enjoy...

My Broadcast Channel

Watch live video from Lifecasting on

Guys this is my broadcast channel. Whenever I think I need to talk to somebody, I turn this on.....

I got the motivation from the below video. See the video and you will know what is it that I am trying to do...

Monday, May 11, 2009

Python Interview Questions and Answers

Hi Everybody,

As always interview questions but this time I was lucky to be interviewed for Python, which I had recent experience on. And the interviewer was great. He told me that he had pretty much fundamental and short questions to ask and he joked about MS interviewees will be joyed with this kind of interview process.

This was basically a python position but this made me feel why people cannot do with other programming language experts for python because a python programmer is really way too different than a C++ or Java programmer. Since I am a C++ programmer with recent experience in Python, I was considered for the position. It was fun going through the interview since it was web conference coding interview.

What I had gone through was the LinuxCBT edition of python which helped me a lot. If I had not referred that I would have done miserably.

I had tried searching for python questions over the internet but was not too lucky since I got only a few of them which made sense. Some of them were asked but restricting to just a couple of them. So I think my questions and answers will really help people to get a good idea on what can be asked for python interviews and also for people who are getting interviewed on python. I really appreciate comments and improvements on the questions and answers.

Hope the information helps.....

1. Name five modules that are included in python by default

2. Name a module that is not included in python by default

3. What is used for?

4. When is pass used for?

5. What is a docstring?

6. What is list comprehension?

7. What is map?

8. What is the difference between a tuple and a list?

Ans. This is the most frequently asked question on python.

A tuple is a list that is immutable. A list is mutable i.e. The members can be changed and altered but a tuple is immutable i.e. the members cannot be changed.

Other significant difference is of the syntax. A list is defined as

list1 = [1,2,5,8,5,3,]
list2 = ["Sachin", "Ramesh", "Tendulkar"]

A tuple is defined in the following way

tup1 = (1,4,2,4,6,7,8)
tup2 = ("Sachin","Ramesh", "Tendulkar")

So the difference is in the type of brackets.

Coding questions

9. Using various python modules convert the list a to generate the output 'one, two, three'

a = ['one', 'two', 'three']


>>> a = ['one','two','three']
>>> ','.join(a)

10. What would the following code yield?

word = 'abcdefghij'
print word[:3] + word[3:]

Ans. This will print the word 'abcdefghij'

11. Optimize these statements as a python programmer

word = 'word'
print word.__len__()

>>> print 'word'.__len__()

12. Write a program to print all the contents of a file


except Exception, e:
  print "%s" %e  

print f1.readlines() 
with open("tmp1.txt", "r") as f:

13. What will be the output of the following code

a = 1
print a
print b



Here in the second line a,b=a+1,a+1 means that a=a+1 and b=a+1 which is 2. But this is the python way of initialization which a python programmer should understand.

14. Given the list below remove the repetition of an element. All the elements should be uniquewords = ['one', 'one', 'two', 'three', 'three', 'two']


>>> set(uniquewords)
set(['three', 'two', 'one'])

15. Iterate over a list of words and use a dictionary to keep track of the frequency(count) of each word. for example



>>> l = ['one', 'one', 'two', 'three', 'three', 'two', 'one', 'one', 'two']
>>> d = {}
>>> for w in l:
...   d[w] = 1 + d.get(w,0)
>>> d
{'three': 2, 'two': 3, 'one': 4}

16.Write the following logic in Python:
If a list of words is empty, then let the user know it's empty, otherwise let the user know it's not empty.

if len(a):
print"The list is not empty"

print"The list is empty"

17. Demonstrate the use of exception handling in python.

print a[5]
except Exception, e # This was important. Just do not say except: and print out something. It is
print e # Important to know what is the error

>>> a=[1,2,3,4]
>>> try:
...   print a[5]
... except Exception, e:
...   print "Error %s" % e
Error list index out of range

18. Print the length of each line in the file 'file.txt' not including any whitespaces at the end of the lines.
>>> f1 = open("", 'r')
>>> i=0
>>> for line in iter(f1):
...   print "Length of line %d is %d" % (i, len(line.rstrip()))
...   i+=1
Length of line 0 is 11
Length of line 1 is 21

19. Print the sum of digits of numbers starting from 1 to 100

Ans. print sum(range(1,101))

This is way too easy but just who know python. Since I am a C++ Programmer, I started writing a for loop to add up which was way too dumb. Hope you don't make this mistake.

Python is known for it short syntax and easy to use functions.

20. Create a new list that converts the following list of number strings to a list of numbers.
num_strings = ['1','21','53','84','50','66','7','38','9']


>>>num_strings = ['1','21','53','84','50','66','7','38','9']
>>>[int(j) for j in num_strings]
[1, 21, 53, 84, 50, 66, 7, 38, 9]

21. Create two new lists one with odd numbers and other with even numbers
num_strings = [1,21,53,84,50,66,7,38,9]

>>>num_strings = [1,21,53,84,50,66,7,38,9]
>>>o, e = [], []
>>>[o.append(n) if n % 2 else e.append(n) for n in num_strings]
[None, None, None, None, None, None, None, None, None]
([1, 21, 53, 7, 9], [84, 50, 66, 38])

>>> num_strings = [1,21,53,84,50,66,7,38,9]
>>> odd, even = filter(lambda x:x%2, num_strings), filter(lambda x: not x%2, num_strings)
>>> print odd,even
[1, 21, 53, 7, 9] [84, 50, 66, 38]

22. Write a program to sort the following intergers in list
nums = [1,5,2,10,3,45,23,1,4,7,9]

nums.sort() # This is the quickest sorting algorithm. This is the best possible way to sort.
print nums

23. Write a for loop that prints all elements of a list and their position in the list.
abc = [4,7,3,2,5,9] 
>>>abc = [4,7,3,2,5,9]
>>>for i, v in enumerate(abc):
...   print i,v
0 4
1 7
2 3
3 2
4 5
5 9

24. The following code is supposed to remove numbers less than 5 from list n, but there is a bug. Fix the bug.
n = [1,2,5,10,3,100,9,24]

for e in n:
if e<5: 
print n

Ans. The output here will be

[2,3,5,10,100,9,24] which means the 1st and the 5th elements are removed.

It should be implemented as below.

>>> n = [1,2,5,10,3,100,9,24]
>>> nlist = filter(lambda x: x >= 5, n)
>>> print nlist
[5, 10, 100, 9, 24]

list.remove(element) will remove the element, and shrink the list. If
you are iterating over the same list at that time, and you wanted to
go to next element, the next element may very well be the one after.
Here is what is happening in the problem: The 0th element in the list
is less than 5 and is removed, thus, making the list shorter by one
element. The next iteration in the for loop goes to n[1], but n[0]
now is 2, so the loop skips element 2 and doesn't remove it. Same
thing happens at 100, but it is ok to skip 100 as it is > 5

25. What will be the output of the following
def func(x,*y,**z):
print z



Here the output is :


If I print all the variables, namely x, y and z it yeilds me this

1 (2,3) {}

* and ** have special usage in the function argument list. *
implies that the argument is a list and ** implies that the argument
is a dictionary. This allows functions to take arbitrary number of
arguments (like your sum function that took range of numbers from 0
.. 100. Pretty cool, eh?

26. Write a program to swap two numbers.
a = 5
b = 9

def swap(c,d):
return d,c


This will print the swapped values of a and b


OR if this does not seem convincing,
a, b = 5, 10

t = a

print a,b

>>> a = 5
>>> b = 10
>>> a,b=b,a
>>> a
>>> b

27. What will be the output of the following code
class C(object):
self.x =1

print c.x
print c.x
print c.x
print c.x


All the outputs will be 1


28. What is wrong with the code
func([1,2,3]) # explicitly passing in a list
func()             # using a default empty list

def func(n = []):
#do something with n

print n

Ans. I tried running the code with my addition of printing the value of n in the function and found out the following result

func([1,2,3]) resulted in [1,2,3]
while func() resulted in []

29. What all options will work?

n = 1
print n++


n = 1
print ++n


n = 1
print n+=1


int n = 1
print n = n+1


n =1
n = n+1

From the above options I believe the following will work

b. and e.

There are some problems with a, c and d.

if you try running the code in a , it does not accept n++ but it accepts ++n

n+=1 is not accepted while in d the variable is preceded by an int which is not pythonically correct.

30. In Python function parameters are passed by value or by reference?
Ans. Please refer to this

31.Remove the whitespaces from the string.
s = 'aaa bbb ccc ddd eee'


a = string.split(s)
print a
['aaa', 'bbb', 'ccc', 'ddd', 'eee'] # This is the output of print a

print string.join(a)
aaa bbb ccc ddd eee # This is the output of print string.join(a)

32. What does the below mean?
s = a + '[' + b + ':' + c + ']'

33. Optimize the below code

def append_s(words):
for word in words:
new_words.append(word + 's')
return new_words

for word in append_s(['a','b','c']):
print word

The above code adds a trailing s after each element of the list. Is there a better way one can write the above script?

34. If given the first and last names of bunch of employees how would you store it and what datatype?

Ans. Either a dictionary or just a list with first and last names included in an element.


Thursday, May 7, 2009

Print all prime number upto a certain Range in C++ and Python

I have tried developing in C++ and Python. I like scripting in python and C++ is my favorite programming language.

#!/usr/bin/env python

#Author : Ronak Patel

#Date : 05/07/2009

#Purpose : Write a script to get all prime numbers upto a certain range.

x = int(raw_input("Enter the range: "))

for i in range(2,x):

isprime = 1

for j in range(2,i):






print "%d\t" % i

The logic is the same but only the syntax is different. Here we have two for loops. The first one starts from 2 and goes till the last number you want. The other loop starts with a 2 and end with the first loop digit. So we make sure all the numbers are verified. Let me explain you in a bit detail.

In the above script, Initially i will be 2 and j will also be 2. It will end up exiting the loop because it satisfies the condition i==j and it will be printed since isprime remains 1. Secondly i will be 2 and j will be 3 which wont satisfy the condition i==j and also i%j==0. So it will move forward with i=3 and j=3 which then shows that it is also a prime number.

Now when i=2 and j=4, it satisfies the condition i%j==0 which means it will not be printed since isprime=0. So this is how this works.

Below is the C++ implementation.

// prime.cpp : Defines the entry point for the console application.

#include "stdafx.h"

//using namespace std;

void prime(int a)
int isprime;

for(int i=2;i<=a;i++)
printf("i in the first loop %d\n", i);
isprime =1;
for(int j =2;j<=i;j++)
printf("\tj in the second loop %d\n", j);

else if (i %j == 0)
isprime = 0;
getchar(); }
void main()
int n;
std::cout<<"Enter range: ";
std::cin >> n;




Hope this helps. I will try and post Perl script too for this. I believe I did not find more implementations of this particular program. You can find many implementations for odd even programs but not prime ones.

Here goes the perl script for the same purpose

#!/usr/bin/perl -w
#use strict;
#Author : Ronak Patel
#Date : 05/07/2009
#Purpose : Write a script in perl to print all prime numbers

print("Enter the range: ");
my $max = <>;
$i = 0;
$j =0;
$isprime = 0;

for($i = 2;$i <= $max; $i++) { $isprime=1; for($j = 2; $j <= $i; $j++) { if($i == $j){} # continue; elsif($i%$j==0) { $isprime = 0; } } if($isprime) { print("$i\n"); } }

Tuesday, May 5, 2009

Conver DOCX to DOC for free

How To Convert DOCX to DOC For Free Instantly

Do you want to convert a DOCX file to DOC file? Do you have a DOCX file made from Microsoft Word 2007 and you can't open it in Microsoft Word 2000, XP or 2003? If you want to convert DOCX to DOC without installing MS Word 2007 then read on and you will learn how to convert DOCX to DOC for free.

For your information, .docx is the default file extension of MS Word 2007. They are actually just zipped XML documents. Try to rename it from .docx to .zip and extract the file using Winzip or Winrar and other decompression tools.

One solution to convert .docx documents to .doc file format is to download the free Miscrosoft Office Compatibility pack available here. Of course you need to have a licensed Windows OS to get the download.

I hope this short tutorial was able to help you convert DOCX files to DOC format or open DOCX files in other word processing software and applications.

Hope this helps the ones in need.

Download bollywood songs for free

I have been asked by a lot of people on a site where they could download mp3 format songs to play in their cars or on their computers.

Since I am an avid fan of bollywood music and songs I tried searching and found a bunch of useful websites where you can download songs and burn them on a CD. Well I don't know the legality issues and just recommend these sites.





Hope you will like it.

Sunday, April 19, 2009

Pal - KK

Hum rahe ya na rahe kal
Kal yaad aayenge yeh pal
Pal, yeh hain pyaar ke pal
Chal, aa mere sang chal
C#m B A E
Chal, soche kya Chhoti si hai zindagi
C#m B A B
Kal mil jaaye to hogi khushnaseebi

Hum rahe ya na rahe, yaad aayenge yeh pal

B C#m B C#m
Shaam ka aanchal odhke aayi
Dekho voh raat suhaani
B C#m B C#m
Aa likh de hum donon milke
Apni yeh prem kahaani


Hum rahe ya na rahe, yaad aayenge yeh pal

chords similar to previous one...
B C#m B C#m
Aane waali subah jaane
Rang kya laaye deewaani
B C#m B C#m
Meri chaahat ko rakh lena
Jaise koi nishaani

Hum rahe ya na rahe, yaad aayenge yeh pal

yaaron - Pal chords

Key: F


F Bb F Bb
yaaro.N dostee ba.Dee hee ha seen hai ye naa

F Bb F Bb
ho to kyaa phir bolo ye zinda gee hai koee

F F/A Bb F F/A Bb
to ho raazdaa r bega raz teraa ho yaar koee

to ho raaz daar

F Bb F Bb
yaaro.N mohabbat hee to banda gee hai ye naa

F Bb F Bb
ho to kyaa phir bolo ye zinda gee hai koee

F F/A Bb F F/A Bb
to dilbar ho yaar jis ko tujhse ho pyaar koee

to dilbar ho yaar

Verse 1

Dm Am Bb F
teree har ek buraayee pe daa.NTe wo dost

Dm Am Bb F
gam kee ho dhoop to saayaa bane teraa wo dost

Bb Am Gm F
naache bhee wo teree khu shee me.N arE


F Bb F Bb
yaaro.N dostee ba.Dee hee ha seen hai ye naa

F Bb F Bb
ho to kyaa phir bolo ye zinda gee hai koee

F F/A Bb F F/A Bb
to ho raazdaa r bega raz teraa ho yaar koee

to ho raaz daar

Verse 2

Dm Am Bb F
tan man kare tujhpe fidaa mahboob wo

Dm Am Bb F
palko.N pe jo rakhe tujhe mahboob wo

Bb Am Gm F
jiskee wafaa tere liye ho arE


F Bb F Bb
yaaro.N mohabbat hee to banda gee hai ye naa

F Bb F Bb
ho to kyaa phir bolo ye zinda gee hai koee

F F/A Bb F F/A Bb
to dilbar ho yaar jis ko tujhse ho pyaar koee

F F/A Bb
to dilbar ho yaar

Dil De Diya hai....Masti Chords

This is one of my favorite songs. I tried playing it and it sounds good. Let me know if you find any problems with it. Thanks for visiting....

Dil de diya hai
jaan tumhe denge

dil de diya hai
jaan tumhe denge
dagaa nahi karenge sanam

------------A#--( D# also seems good here)
hoooo....rabb di kasam ...
yaara rabb di kasam
(repeat once mukhra)

rukh zindagi ne mod liya kaisa

humne socha nahi tha kabhi aisa

rukh zindagi ne mod liya kaisa

humne socha nahi tha kabhi aisa

aata nahi yakeen

kya se kya ho gayaa
kis tarah main tumse bewafaa ho gayaa

insaaf kar do

mujhe maaf kar do

itna hee kar do karam

dil de diya hai

jaan tumhe denge

dagaa nahi karenge sanam

(following stanzas are also like previous one)

Awaargi mein ban gaya diwaana

Maine kyun saadgi ko nahin jaana

Awaargi mein ban gaya diwaana

Maine kyun saadgi ko nahin jaana

Chaahat yahi hai ke, is qadar pyaar doon

Qadmon mein tere main, toh jahaan waar doon

Chain mera le lo, khushi meri le lo

De do mujhe dedo saare gham

Dil de diya hai, jaan tumhein denge

Daga nahin karenge sanam

Mere ashq keh rahe meri kahaani

Inhein samjho na tum sirf paani) -2

Ro ro ke aansuon ke daag dhool jaayenge

In mein wafa ke rang, aaj ghool jaayenge

Paas tum rahogi, bhool ab na hogi

Karoonga na tumpe sitam

Dil de diya hai, jaan tumhein denge
Daga nahin karenge sanam
Ho...rab di kasam yaara, rab di kasam
(Dil de diya hai, jaan tumhein denge
Daga nahin karenge sanam) -2

Tuesday, April 14, 2009

New C++ questions....

Surprisingly the number of interview questions posts have increased since I am appearing for a number of interviews..... but surely this helps me and I hope that it will help some other people too.

1. Tell me the fundamentals of OOPS.

--> Encapsulation, Inheritance, Polymorphism. Define them.

Surprisingly I was asked that I missed abstraction. I believe it is a generic term for encapsulation.

2. Implementation of polymorphism in recent projects...

Implemented the Logger class to log all the install scripts as well as other database related scripts.

3. What kind of polymorphism did you implement in the recent projects?

--> Run time polymorphism.

4. Explain operator overloading.

5. What is a virtual funtion?

6. What are memory leaks?

7. What is a function pointer?

8. What is a VPT (Virtual Pointer Table)?

--> The virtual table is actually quite simple, though it’s a little complex to describe in words. First, every class that uses virtual functions (or is derived from a class that uses virtual functions) is given it’s own virtual table. This table is simply a static array that the compiler sets up at compile time. A virtual table contains one entry for each virtual function that can be called by objects of the class. Each entry in this table is simply a function pointer that points to the most-derived function accessible by that class.

9. What is a smart pointer?

-->Smart pointers are objects which store pointers to dynamically allocated (heap) objects. They behave much like built-in C++ pointers except that they automatically delete the object pointed to at the appropriate time. Smart pointers are particularly useful in the face of exceptions as they ensure proper destruction of dynamically allocated objects. They can also be used to keep track of dynamically allocated objects shared by multiple owners.

Friday, April 3, 2009

C++/Perl/Bash/Python questions

As usual some interview questions and answers that I encountered in one of the telephonic ones.

1. What is the difference between Bash/Shell, perl, python scripting languages?

--> Perl and Python can be used for web based scripting while bash cannot be used.
--> Easy portability for perl and python since both are platform independent while bash is not.
--> Various flavors of shell scripting, bash, korn, ksh, etc.

2. Why is a virtual constructor not possible?

A constructor cannot be virtual because at the time when the constructor is invoked, the virtual table would not be available in the memory. Hence we cannot have a virtual constructor.

3. Can we have an array of references?

No we cannot have an array of references because references cannot be null as pointers can be. Once a reference is created, it cannot be later made to reference another object. We can say it cannot be reseated which is often done with pointers.

References cannot also be uninitialized.

4. Describe the callback function syntax.

5. What is the difference between exec() and system() in perl/bash?

exec() executes in the same shell while system() executes in another shell.

6. Define a constructor and how it might be called.

Constructor is a member function of the class, with the name of the function being the same as the class name. It also specifies how the object should be initialized.

There are two ways of calling a constructor

1. Implicitly - automatically by compiler when an object is created.
2. Explicitly - Calling the constructors explicitly is possible but it makes code unverifiable.

class Point
int x,y;
Point():x(0),y(0) {} // Default constructor with no arguments

void main()
Point MyPoint; // Implicit constructor call. In order to allocate memory on stack, the default constructor is implicitly called.
Point *pPoint = new Point(); //Explicit constructor call. In order to allocate memory on heap we call the default constructor.

What is a modifier?

A modifier, also called a modifying function is a member function that changes the value of at least one data member. In other words, an operation that modifies the state of an object. Modifiers are also known as ‘mutators’. Example: The function mod is a modifier in the following code snippet:

class test
int x,y;
x=0; y=0;
void mod()

What is an accessor?

An accessor is a class operation that does not modify the state of an object. The accessor functions need to be declared as const operations
Differentiate between a template class and class template.
Template class: A generic definition or a parameterized class not instantiated until the client provides the needed information. It’s jargon for plain templates. Class template: A class template specifies how individual classes can be constructed much like the way a class specifies how individual objects can be constructed. It’s jargon for plain classes

Differentiate between a template class and class template.

Template class: A generic definition or a parameterized class not instantiated until the client provides the needed information. It’s jargon for plain templates. Class template: A class template specifies how individual classes can be constructed much like the way a class specifies how individual objects can be constructed. It’s jargon for plain classes.

What is a const method?

Marking a method as const signs a contract with the client code guaranteeing that you will not try to change the internal values of the object within the method.

If you try to declare a method const that actually modifies a data member, the compiler will complain.
You cannot declare a static method const because it is redundant.
Static methods do not have an instance of the class so it would be impossible for them to change internal values.
const works by making it appear inside the method that you have a const reference to each data member. Thus, if you try to change the data member the compiler will flag an error.

A non-const object can call const and no-const methods. However, a const object can only call const methods.

Syntax of a const method:

double SpreadSheetCell::getValue() const

string SpreadSheetCell::getString() const
return (mString);

One should not get into the habit of declaring const all methods that don't modify the object so that you can use references to const objects in your program.

Note that const objects can still be destroyed, and their destructor can be called. You shouldn't try to mark the destructor const.

Thursday, March 26, 2009

Kahin Toh .. Hogi Woh.. Chords Jaane Tu Ya Jaane Na

I found a little bit time to chill out and search for chords for this song. I absolutely love this song. I found it on indianguitartabs and I believe they are perfect. I tried playing it on barre chords and they sound fabulous but still not confirmed with the strumming pattern. Will confirm with my teacher and also provide the strumming pattern. Hope this helps other beginners like me to excel forward.






(A#)Kahin to.. (A#)Kahin to.. (Dm)hogi wo..
(D#)Duniya jahan tu mere (C)sath hai.
(A#)jahan main… (A#)jahan tu… (Dm)Aur jahan..
(D#)bas tere mere (C)jazbaat hai…

(Dm)Hogi jahan… sa(Gm)ba teri…
(A#)palkon ki… (F)kirno(D#) ne…
(Dm)Dori jahan.. (Gm)chand ki…
(A#)sun teri.. bahon (D#)mein……….

(A#)jaane na kahan wo du(D#)niya hai
(C)jaane na wo hai bhi (F)ya nahi
(A#)jahan meri zin(D#)dagi mujhse
(D#)itni (F)khafa (A#)nahi… x 2


(C)Saasein kho gayi hai kiski (Gm)aahon mein…
(C)Mein kho gayi hoon jane kiski (Gm)baahon mein
(C)Manzilon se rahe dhoond(Gm)te chali
Aur (C)kho gayi hai manzil kahin (Gm)rahon mein

(A#)kahi to.. (A#)kahi to.. (Dm)hai nasha…
(D#)teri meri har mula(C)qat mein…
(A#)hotho se.. (A#)hotho ko.. (Dm)chumti…
oh (D#)rehte hai hum har (C)baat pe..

(Dm)kehti hai, fi(Gm)za jahan..
(A#)teri zameen, (F)aas(D#)man…
(Dm)jaha hai tu, (Gm)meri haseen,
(A#)meri khushi, meri ja(D#)han….

(A#)jaane na kahan wo du(D#)niya hai
(C)jaane na wo hai bhi (F)ya nahi
(A#)jahan meri zin(D#)dagi mujhse
(D#)itni (F)khafa (A#)nahi…

Saturday, March 21, 2009

Fundamental questions of C++

The following are the initial questions asked by a technical recruiter for a good project in C++. Have a look and hope this helps.

What is the difference between an ARRAY and a LIST?

-->Array is collection of homogeneous elements.
-->List is collection of heterogeneous elements.

-->For Array memory allocated is static and continuous.
-->For List memory allocated is dynamic and Random.

-->Array: User need not have to keep in track of next memory allocation.
-->List: User has to keep in Track of next location where memory is allocated.

-->Array uses direct access of stored members
-->List uses sequencial access for members.

//With Array you have direct access to memory position 5
Object x = a[5]; // x takes directly a reference to 5th element of array

//With the list you have to cross all previous nodes in order to get the 5th node:
list mylist;
list::iterator it;

for( it = list.begin() ; it != list.end() ; it++ )
if( i==5)
x = *it;

What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?


What are 2 ways of exporting a function from a DLL?
1.Taking a reference to the function from the DLL instance.
2. Using the DLL ’s Type Library

What is the difference between Mutex and Binary semaphore?

semaphore is used to synchronize processes. where as mutex is used to provide synchronization between threads running in the same process.

STL Containers - What are the types of STL containers?
There are 3 types of STL containers:

1. Adaptive containers like queue, stack
2. Associative containers like set, map
3. Sequence containers like vector, deque

Describe two ways where you can prevent a class from being instantiated.

--> Declare all static methods/functions.
--> Declare a private constructor.

Difference between DELETE, TRUNCATE and DROP statements in SQL

- DML statement
- used to remove rows from a table
- WHERE clause can be sued to remove only some rows.
- After performing DELETE operation you can commit or rollback the transaction to make the change permenant or undo it.
- This operation will cause all TRIGGERS on table to fire.

- DDL statement
- removes all rows from a table
- operation cannot be rolled back and no triggers will be fired.
- TRUNCATE is faster and doesn't use as much undo space as DELETE.

--> DROP
- DDL statement
- removes a table from a database
- all the tables' rows, indexes and privileges will also be removed.
- No DML triggers will be fired.
- Operation cannot be rolled back.

From Oracle 10g a table can be undropped.
Flashback Complete