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 www.seetoo.com

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 www.seetoo.com
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.

www.seetoo.com

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

My Broadcast Channel

Watch live video from Lifecasting on Justin.tv



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 __init__.py 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']

ANSWER:




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

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__()


ANSWER:
>>> print 'word'.__len__()
4


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


Ans.

try:
  f1=open("filename.txt","r")
except Exception, e:
  print "%s" %e  

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

13. What will be the output of the following code

a = 1
a,b=a+1,a+1
print a
print b

Ans.

2
2

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']

ANSWER:

>>> 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

{'one':2,'two':2,'three':2}

ANSWER:

>>> 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.


Ans.
a=[]
if len(a):
print"The list is not empty"
else:

print"The list is empty"


17. Demonstrate the use of exception handling in python.
Ans.

a=[1,2,3,4]
try:
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.
Ans.
>>> f1 = open("abc.py", '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']

Ans.




>>>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]

Ans.
>>>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]
>>>o,e
([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] 
Ans. 
 
>>>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: 
    n.remove(e)
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

func(1,2,3)

Ans.

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

swap(a,b)

This will print the swapped values of a and b

(9,5)

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

t = a
a=b
b=t

print a,b

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

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

c=C()
print c.x
print c.x
print c.x
print c.x

Ans.

All the outputs will be 1

1
1
1
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?
a.

n = 1
print n++

b.

n = 1
print ++n

c.

n = 1
print n+=1

d.

int n = 1
print n = n+1

e.

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'

Ans.

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):
new_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.


35.
36.

















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):

if(i==j):

continue

elif(i%j==0):

isprime=0

if(isprime):

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"
#include


//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);

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

prime(n);

getchar();

}


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 = <>;
chomp($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.



Bollyextreme

123musiq

j4jumpy

songs.pk

mastimag

Hope you will like it.