This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@Author Sujayyendhiren Ramarao | |
@Description Multiprocessing library example (Synchornization of shared variable) | |
""" | |
import nmap | |
import time | |
class Discover(object) : | |
def __init__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@Author Sujayyendhiren Ramarao | |
@Description Entry point for the multiprocessing example | |
""" | |
from multiprocessing import Process, Lock, Value | |
import discoverLanIps | |
if __name__ == '__main__': | |
lock = Lock() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@Author: Sujayyendhiren Ramarao | |
@Description: Singleton class. More than one approach. | |
""" | |
#Decorator approach | |
def singleton(class_): | |
instances = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@Author: Sujayyendhiren Ramrarao Srinivasamurthi | |
@Description: My own iterator. | |
""" | |
class Myfib: | |
""" Fibonacci class""" | |
def __init__(self, max): | |
self.max = max | |
def __iter__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@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]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@Author: Sujayyendhiren Ramarao Srinivasamurthi | |
@Description: Insertion sort | |
""" | |
def insertion_sort( data ): | |
length = len(data) | |
for idx in range(1, length): | |
val = data[idx] |
OlderNewer