Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View sujayy1983's full-sized avatar

Sujayyendhiren Ramarao srinivasamurthi sujayy1983

View GitHub Profile
@sujayy1983
sujayy1983 / discoverLanIps.py
Created January 14, 2015 19:36
Multiprocessing simplest example.
"""
@Author Sujayyendhiren Ramarao
@Description Multiprocessing library example (Synchornization of shared variable)
"""
import nmap
import time
class Discover(object) :
def __init__(self):
@sujayy1983
sujayy1983 / main-sched-process.py
Created January 14, 2015 19:38
Entrypoint file.
"""
@Author Sujayyendhiren Ramarao
@Description Entry point for the multiprocessing example
"""
from multiprocessing import Process, Lock, Value
import discoverLanIps
if __name__ == '__main__':
lock = Lock()
@sujayy1983
sujayy1983 / Visitor.py
Last active August 29, 2015 14:13
An attempt at creating a visitor design pattern in Python. Tested with Python 2.7.6
"""
@Author: Sujayyendhiren Ramarao
@Description: Visitor design pattern
"""
# For creating abstract base class.
import abc
""" Add features to this class using Visitor design pattern"""
class SmartTV (object):
@sujayy1983
sujayy1983 / Observer.py
Created January 17, 2015 18:34
Observer design pattern example. Increase in student record to a database/record is notified to the concerned departments.
"""
@Author Sujayyendhiren Ramarao
@Description Observer Design pattern
"""
import abc
class Subject(object):
""" Subject class that notifies the increase or decrease in student count to all the departments (observers)."""
def __init__(self):
@sujayy1983
sujayy1983 / Decoratr.py
Created January 17, 2015 20:40
A simple example of decorator.
"""
@Author: Sujayyendhiren Ramarao
@Description: Decorator design pattern
"""
def logging_decorator( function ):
def func(*args, **kwargs):
print("Entering function" + str(function))
ret = function(*args,**kwargs)
print("Returned from function" + str(function))
@sujayy1983
sujayy1983 / Singleton.py
Created January 21, 2015 22:02
Singleton design pattern (Two approaches). Taken a lot of help from internet examples.
"""
@Author: Sujayyendhiren Ramarao
@Description: Singleton class. More than one approach.
"""
#Decorator approach
def singleton(class_):
instances = {}
@sujayy1983
sujayy1983 / MyIterator.py
Created January 25, 2015 02:07
1. My iterator implementation. 2. Using the iterator in two ways.
"""
@Author: Sujayyendhiren Ramrarao Srinivasamurthi
@Description: My own iterator.
"""
class Myfib:
""" Fibonacci class"""
def __init__(self, max):
self.max = max
def __iter__(self):
@sujayy1983
sujayy1983 / DenominationCombination.py
Last active August 29, 2015 14:14
Given a value in cents. Find the corresponding combinations in which that money maybe paid.
"""
@Author Sujayyendhiren ramarao srinivasamurthi
@Description For a given value find denominations in cents
"""
lDenom = [ 100 ,50, 25, 10, 5 ,1 ]
lDepth = [ '', '\t', '\t\t', '\t\t\t', '\t\t\t\t', '\t\t\t\t\t']
def combinations ( num , depth ):
for denom in lDenom[depth:6]:
@sujayy1983
sujayy1983 / dfs.py
Created January 25, 2015 18:36
Depth First Search
"""
@Author: Sujayyendhiren Ramarao Srinivasamurthi
@Description: My implementation of DFS
"""
graph = {
'1': ['2', '3', '4'],
'2': ['5', '6'],
'5': ['9', '10'],
'4': ['7', '8'],
'7': ['11', '12']
@sujayy1983
sujayy1983 / Insertion.py
Created January 25, 2015 19:03
Implementaion of insertion sort.
"""
@Author: Sujayyendhiren Ramarao Srinivasamurthi
@Description: Insertion sort
"""
def insertion_sort( data ):
length = len(data)
for idx in range(1, length):
val = data[idx]