Wednesday, May 30, 2012

how to change the world- my view

Yesterday night I was having dinner with a friend and I told him that our India office is closed tomorrow because of shutdown strike called by opposition party. Then the discussion went on to India, its politics, Oil price and global issues at large. My friend said that when he was in college he wanted to do something to change the world- to make it a better place!

When I woke up today morning the same topic came back to my mind and how a person can contribute to make this world a better place?

The world is made up of individuals. We all suffer. We all go through bad relationships, difficult jobs, hard life experiences, loss, pain. In fact, that’s what most of life is.

But if you slowly work at incrementally improving yourself. then you will make life better for yourself. And as each person makes life better for themselves then incrementally the world becomes a better place to live. We treat with each other with more kindness, more honesty, less betrayal, more humility.

Everyone is coming up with a new smartphone "App" claiming that they will change the world.  No app will do that. The only way the world will change for the better is to improve yourself everyday.

Friday, May 25, 2012

Happiness This Very Moment


When was the last time you felt complete happiness? Completely free- just enjoying every second?

Yesterday is long gone. Tomorrow will never come. I’m happy today, with my bread, with my smile, with both feet flying in the air. Like a bird

My simple goal in life is: I want to be happy. I want every day to be as smooth as possible. No hassles.

How to Remotely Control Your PC using Vpro-AMT

I need to show up a demo today from my client hyper-visor machine. Currently we use virtual room to do the demos for remote people, but since we do not have a virtual room client for linux and my Dom0 client is completely closed so I was looking for a way to show the console screen of my machine in the demo.

I was able to achieve it by following steps on HP 8460 p machine:

Intel vPro is a management platform built into Intel processors and other hardware that allows companies to manage their desktops and laptops out-of-band (OOB). That means the computers can be managed no matter if the computer in on or off, and even if the operating system has failed or there is no hard drive present.

Make sure machine has vPro+AMT support in the processor and BIOS.

Once you have AMT capable system,  continue on to configure Intel AMT KVM.

Enable Hardware KVM

The first thing you will need to do is turn on BIOS verbosity. Reboot your computer and enter your BIOS configuration. Look for something labeled firmware verbosity or boot verbosity and make sure it is turned on. Likewise, if there is an option for an AMT setup prompt make sure that is turned on as well.

Restart your computer and just after the BIOS splash screen you should see a second setup screen that looks something like the image below. Push Ctrl+P at this screen to enter the Management Engine BIOS Extension (MBEx) to configure Intel AMT.

If AMT has never been set up on your computer you will be prompted for a password. Enter “admin” for the default password and you will be prompted automatically to create a new password. The new password has to have be exactly 8 characters and contain one upper case letter, one lower case letter, one number, and one symbol. Enter the new password twice to continue.
Note: If “admin” does not work as the default password you can also try “P@ssw0rd” because that is the default password in Intel’s configuration documentation.

Once you are logged into the MEBx, go to Intel Management Engine and then select activate network access.

Type Y to accept the warning that pops up about activating the ME network interface.

Next select network setup and then Intel(R) ME Network Name Settings.

Select host name and put in your computers name. You technically could put in anything you want here but it may cause problems with DNS if the Intel AMT name is different from your computer’s name.

Return to the main menu using the escape key and then go to manageability feature selection. Push Y to continue past the caution message.
Verify that the manageability feature selection is enabled in the lower window and then select SOL/IDER.

From here verify that SOL, IDER, and Legacy Redirection Mode are all enabled.

Return to the previous menu and then select KVM Configuration.  Make sure KVM Feature Selection is enabled.

From here change User Opt-in so that user consent is not required for KVM session.

Then enable remote control of Opt-in policy.

Push escape three times to exit the MEBx menu and push Y when prompted if you are sure you want to leave.
---

Once you have BIOS things enabled you can use vnc viewer plus client to connect remotely
To find the IP address- when machine boot press CTRL+ALT+F1. This should show the IP address.




You will be prompted for your Intel AMT KVM password.

And a VNC connection will be established with the AMT KVM server.


Monday, May 21, 2012

Some Python Stuff

1. What is Python? State some programming language features of Python.
  • Python is a modern powerful interpreted language with objects, modules, threads, exceptions, and automatic memory managements.
  • Salient features of Python are
-Simple & Easy: Python is simple language & easy to learn.
-Free/open source: it means everybody can use python without purchasing license.
-High level language: when coding in Python one need not worry about low-level details.
-Portable: Python codes are Machine & platform independent.
-Extensible: Python program supports usage of C/ C++ codes.
-Embeddable Language: Python code can be embedded within C/C++ codes & can be used a scripting language.
-Standard Library: Python standard library contains prewritten tools for programming.
-Build-in Data Structure: contains lots of data structure like lists, numbers & dictionarie

2.  Explain how python is interpreted.
Python program runs directly from the source code. Each type Python programs are executed code is required. Python converts source code written by the programmer into intermediate language which is again translated it into the native language / machine language that is executed. So Python is an Interpreted language 
3.  Explain the disadvantages of python.
  • Python isn't the best for memory intensive tasks.
  • Python is interpreted language & is slow compared to C/C++ or java.
  • Python not a great choice for a high-graphic 3d game that takes up a lot of CPU.
  • Python is evolving continuously, with constant evolution there is little substantial documentation available for the language.

 ------------------------------
4. When to use list vs. tuple vs. dictionary vs. set?
List is like array, it can be used to store homogeneous as well as heterogeneous data type (It can store same data type as well as different data type). List are faster compared to array. Individual element of List data can be accessed using indexing & can be manipulated.
List Code Snippet:
list = ["Sarah",29,30000.00]
for i in range (3):
     print list[i]
------------------
Output
Sarah
29
30000.0
Tuples are similar to lists, but there data can be changed once created throught the execution of program. Individual element of Tuples can be accessed using indexing.
Tuples Code Snippet: The Days
days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
print days
------------------------------
('Sunday', 'Mondays', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')
Sets stores unordered values & have no index. And unlike Tuples and Lists, Sets can have no duplicate data, It is similar to Mathematical sets.
  • add() function can be used to add element to a set.
  • update() function can be used to add a group of elements to a set.
  • Copy() function can be used to create clone of set.
Set Code Snippet:
disneyLand = set (['Minnie Mouse', 'Donald Duck', 'Daisy Duck', 'Goofy'])
disneyLand.add('Pluto')
print disneyLand
-----------------------------------------------
Output
set(['Goofy', 'Daisy Duck', 'Donald Duck', 'Minnie Mouse', ’Pluto’])
Dictionary are similar to what their name is. In a dictionary, In python, the word is called a 'key', and the definition a 'value'. Dictionaries consist of pairs of keys and their corresponding values.
Dictionary Code Snippet:
>>> dict = {'India': 'Bharat', 'Angel': ‘Mother Teresa’, 'Cartoon': 'Mickey'}
>>>print dict[India]
Bharat
>>>print dict[Angel]
Mother Teresa

----------------------------------------
5. Describe how exceptions are handled in python.
Errors detected during execution of program are called exceptions. Exceptions can be handled using the try..except statement. We basically put our usual statements within the try-block and put all our error handlers in the except-block.
try…except demo code:
>>> while True:
try:
         x = int(raw_input("Enter no. of your choice: "))
         break
except ValueError:
         print "Oops! Not a valid number. Attempt again"
Enter no. of your choice: 12ww
Oops! Not a valid number. Attempt again
Enter no. of your choice: hi there
Oops! Not a valid number. Attempt again
Enter no. of your choice: 22
>>> 

------
6. Describe how to implement Cookies for Web python.
A cookie is an arbitrary string of characters that uniquely identify a session.
Each cookie is specific to one Web site and one user.
The Cookie module defines classes for abstracting the concept of cookies. It contains following method to creates cookie
  • Cookie.SimpleCookie([input])
  • Cookie.SerialCookie([input]
  • Cookie.SmartCookie([input])
for instance following code creates a new cookie ck-
import Cookie
ck= Cookie.SimpleCookie ( x ) 


--------
7. Describe how to use Sessions for Web python.
Sessions are the server side version of cookies. While a cookie preserves state at the client side, sessions preserves state at server side.
The session state is kept in a file or in a database at the server side. Each session is identified by a unique session id (SID). To make it possible to the client to identify himself to the server the SID must be created by the server and sent to the client whenever the client makes a request.
Session handling is done through the web.session module in the following manner:
import web.session session = web.session.start( option1, Option2,... )
session['myVariable'] = 'It can be requested' 

--
8. What is a negative index in python?
  • Python arrays & list items can be accessed with positive or negative numbers (also known as index).
  • For instance our array/list is of size n, then for positive index 0 is the first index, 1 second, last index will be n-1. For negative index, -n is the first index, -(n-1) second, last negative index will be – 1.
  • A negative index accesses elements from the end of the list counting backwards.
  • An example to show negative index in python
>>> import array
>>> a= [1, 2, 3]
>>> print a[-3]
1
>>> print a[-2]
2
>>> print a[-1]
3
-------
9. What are the rules for local and global variables in Python?
If a variable is defined outside function then it is implicitly global. If variable is assigned new value inside the function means it is local. If we want to make it global we need to explicitly define it as global. Variable referenced inside the function are implicit global. Following code snippet will explain further the difference
#!/usr/bin/python
# Filename: variable_localglobal.py
def fun1(a):
            print 'a:', a
            a= 33;
            print 'local a: ', a
a = 100
fun1(a)
print 'a outside fun1:', a
def fun2():
           global b
           print 'b: ', b
           b = 33
           print 'global b:', b
b =100
fun2()
print 'b outside fun2', b
-------------------------------------------------------
Output
$ python variable_localglobal.py
a: 100
local a: 33
a outside fun1: 100
b :100
global b: 33
b outside fun2: 33


10. What are the steps required to make a script executable on Unix?
The steps that are required to make a script executable are to:

• First create a script file and write the code that has to be executed in it.
• Make the file mode as executable by making the first line starts with #! this is the line that python interpreter reads.
• Set the permission for the file by using chmod +x file. The file uses the line that is the most important line to be used:
#!/usr/local/bin/python
• This explains the pathname that is given to the python interpreter and it is independent of the environment programs.
• Absolute pathname should be included so that the interpreter can interpret and execute the code accordingly. The sample code that is written:

#! /bin/sh
# Write your code here
exec python $0 ${1+"$@"}
# Write the function that need to be included.

11. Write a program to read and write the binary data using python?
The module that is used to write and read the binary data is known as struct. This module allows the functionality and with it many functionalities to be used that consists of the string class. This class contains the binary data that is in the form of numbers that gets converted in python objects for use and vice versa. The program can read or write the binary data is:

import struct
f = open(file-name, "rb")
# This Open() method allows the file to get opened in binary mode to make it portable for # use.
s = f.read(8)
x, y, z = struct.unpack(">hhl", s)
The ‘>” is used to show the format string that allows the string to be converted in big-endian data form. For homogenous list of data the array module can be used that will allow the data to be kept more organized fashion.

12. Write a program to show the singleton pattern used in python.
Singleton patter is used to provide a mechanism that limits the number of instances that can be used by one class. It also allows the same object to be shared between many different parts of the code. This allows the global variables to be used as the actual data that is used is hidden by the singleton class interface. The singleton class interface can have only one public member and one class method Handle. Private constructors are not used to create an object that is used outside the class. The process waits for the static member function to create new instances and return the singleton object. The code that is used to call the singleton object is:

Singleton& Singleton::Handle()
{
if( !psingle ) {
psingle = new Singleton;
}
return *psingle;
}
13. What is LIST comprehensions features of Python used for?
  • LIST comprehensions features were introduced in Python version 2.0, it creates a new list based on existing list.
  • It maps a list into another list by applying a function to each of the elements of the existing list.
  • List comprehensions creates lists without using map() , filter() or lambda form.

14. What is Docstring
Python documentation strings (or docstrings) provide a convenient way of associating documentation with Python modules, functions, classes, and methods. An object's docsting is defined by including a string constant as the first statement in the object's definition. For example, the following function defines a docstring: 

def x_intercept(m, b):
    """
    Return the x intercept of the line y=m*x+b.  The x intercept of a
    line is the point at which it crosses the x axis (y=0).
    """
    return -b/m

15. 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()
Print the length of each line in the file 'file.txt' not including any whitespaces at the end of the lines.
f1=open("filename.txt","r")
leng=f1.readline()
print len(leng) -1, "is the length of the string"

Since the last character is a whitespace we deduct 1 out of the length returned by the len() function.


16.  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)
17. What do youknow about various Python web frameworks
Knowing a few names is usually good enough, though
knowledge about the frameworks is a nice plus) such as
Django, TurboGears, Zope, etc.

18 What do you know about various Python GUI frameworks and
the pros/cons of them (tkinter, wx, pykde, etc)

19Where do you go with Python related questions (c.l.p,
google, google-groups, etc)
20. General- Tabs vs. spaces, and their reasoning. choice of editor/IDE?




Sunday, May 20, 2012

Networking- What happens after you type a URL into a browser

One of the networking related question I love to ask during interview.

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. If your DNS does not know the IP, it will send the request to next forwarder DNS.
3. Browser opens a TCP connection to the web server at port 80. If its an HTTPS URL then it goes to port 443
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.

How to install Xen 4.1 on Ubuntu 11.10

I was trying to make Windows DomU work on Ubuntu+Xen setup. I have to spend couple of hours to find out in what sequence we should do the installation and configuration.

Ubuntu support xen officially from 11.10 version. But there is some issue while creating DomU. Here find some easy step to configure xen 4.1 on 64 bit version of ubuntu 11.10 and solve issue in DomU creation.

1. Install xen and utilities

  1. $sudo apt-get install xen-hypervisor-4.1-amd64 xen-utils-4.1 xenwatch xen-tools xen-utils-common xenstore-utils  
  2. $sudo apt-get install virtinst  
  3. $sudo apt-get install virt-viewer virt-manager  

2.Restart OS and Select Xen KernalVerify the Xen installation using

  1. $sudo xm info  

If this command does not return any error, then the installation is correct.

3.Xend Configuration
Edit
/etc/xen/xend-config.sxp and uncomment this line

(xend-unix-server no)

and change to
  1. (xend-unix-server yes)  
Edit .bashrc file using

  1. #vi ~/.bashrc  
, add the following line:
  1. export VIRSH_DEFAULT_CONNECT_URI="xen:///"  

4. Restart OS and Select Xen Kernel

Verify libvirt Installation

  1. $sudo virsh version   

  1. Compiled against library: libvir 0.8.3  
  2. Using library: libvir 0.8.3  
  3. Using API: Xen 3.0.1  
  4. Running hypervisor: Xen 4.0.0  
If got output like this, you have installed every package correctly.
5.Creating VM using virt-manager
Here I am telling about virtual machine creation using virt-manger
Type $sudo virt-manager for getting GUI for virt-manager
Create new VM using virt-manager(Learn More)
Solution for common error during DomU is given below..
1. Show Something like this

Fix it using
  1. $sudo mkdir /usr/lib64/xen -p  
  2. $sudo cp /usr/lib/xen-4.1/* -r /usr/lib64/xen/  
2. Get like this
Solve it using

  1. $sudo mkdir  /usr/share/qemu  
$sudo cp -r /usr/share/qemu-linaro/keymaps /usr/share/qemu/
 If you have : 
  1. WARNING!  Can't find hypervisor information in sysfs!
    Error: Unable to connect to xend: No such file or directory. Is xend running?
    It’s not that bad. It’s just that GRUB2 start the kernel without the hypervisor (the “right” line in the menu exists, but it’s in second position). So, you need to put Xen hypervisor first, and the “good” way to do this is :

    mv /etc/grub.d/10_linux /etc/grub.d/50_linux

    update-grub2


    to get the supported disk

    install apt-get install qemu-kvm


    qemu-img convert source.vhd -O vmdk destination.vmdk


    2. If for some reason you wish to enable the root account, simply give it a password:
    sudo passwd
    sudo adduser [user name] admin


    Grub issue

    virsh version give error- do not use sudo