Skip to content

Instantly share code, notes, and snippets.

View arpitbbhayani's full-sized avatar
🎲
building @DiceDB

Arpit Bhayani arpitbbhayani

🎲
building @DiceDB
View GitHub Profile
# -*- coding: utf-8 -*-
import sys
class IPythonPromptPS1(object):
def __init__(self):
self.line = 0
def __str__(self):
self.line += 1
return "\033[92mIn [%d]:\033[0m " % (self.line)
sys.ps1 = IPythonPromptPS1()
sys.ps2 = " \033[91m...\033[0m "
import sys
sys.ps1 = "\033[1;33m>>>\033[0m "
sys.ps2 = "\033[1;34m...\033[0m "
>>> import sys
>>> sys.ps1 = '::: '
:::
>>> def foo(a, b):
... return a + b
...
>>>
Python 2.7.10 (default, Feb 22 2019, 21:55:15)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
@overload
def area(l, b):
return l * b
@overload
def area(r):
import math
return math.pi * r ** 2
def __call__(self, *args, **kwargs):
"""Overriding the __call__ function which makes the
instance callable.
"""
# fetching the function to be invoked from the virtual namespace
# through the arguments.
fn = Namespace.get_instance().get(self.fn, *args)
if not fn:
def get(self, fn, *args):
"""get returns the matching function from the virtual namespace.
return None if it did not fund any matching function.
"""
func = Function(fn)
return self.function_map.get(func.key(args=args))
def overload(fn):
"""overload is the decorator that wraps the function
and returns a callable object of type Function.
"""
return Namespace.get_instance().register(fn)
import time
def my_decorator(fn):
"""my_decorator is a custom decorator that wraps any function
and prints on stdout the time for execution.
"""
def wrapper_function(*args, **kwargs):
start_time = time.time()