Some times we may encounter the situation where we need to know total time taken by the function call. Here is the code which is pretty much handy and simple to measure the total time taken by the function(call)

import time

class MeasureDuration:
    def __init__(self):
    self.start = None
    self.end = None

    def __enter__(self):
    self.start = time.time()
    return self

    def __exit__(self, exc_type, exc_val, exc_tb):
    self.end = time.time()
    print "Total time taken: %s" % self.duration()

    def duration(self):
    return str((self.end - self.start) * 1000) + ' milliseconds'

Here is how you apply the above code to get the time taken by the function call

import time

def foo():

with MeasureDuration() as m:
   foo()    # We can place here the multiple calls or 
        # arbitary code block to measure

Output would look like as follows,

Total time taken: 1001.03282928 milliseconds

Cookie blocked in Iframe for Internet Explorer

Sat 27 June 2015 by Godson

When working with chat application recently which uses user sessions, IE is not saving the cookies. This happens when your webpage gets embedded into an iFrame.


Lets say we have two websites and Now, in I have an iFrame SRC=" ...

read more

How to implement paypal payment gateway

Sat 13 June 2015 by Godson

The PayPal REST APIs are supported in two environments. Use the Sandbox environment for testing purposes, then move to the live environment for production processing.

The following endpoints address are two environments:

Sandbox (for testing) :
Live (production) :

A complete REST operation ...

read more

Implementing Websocket Server Using Twisted.

Sat 13 June 2015 by Godson

Websocket, a technology to support modern web applications.

read more