Skip to content

Instantly share code, notes, and snippets.

View ErikPohl-Lot49-Projects's full-sized avatar
🎯
Focusing

Erik Pohl ErikPohl-Lot49-Projects

🎯
Focusing
  • Boston
View GitHub Profile
@ErikPohl-Lot49-Projects
ErikPohl-Lot49-Projects / iterator_procedural.py
Last active October 29, 2018 06:14
Iterator Design Pattern Procedural
def swipeleft(somelist):
for something in somelist:
yield something
people = [1,2,3,4,5,6,7,8]
swipelefter = swipeleft(people)
for person in swipelefter:
print(person)
@ErikPohl-Lot49-Projects
ErikPohl-Lot49-Projects / iterator_oo.py
Last active November 11, 2018 18:02
Iterator Design Pattern
"""
This design pattern permits access to the elements of an aggregate
in a clear handler without exposing underlying representations.
"""
import collections.abc
class ConcreteAggregate(collections.abc.Iterable):
"""
class PAGovernor(object):
class __OnlyOne:
def __init__(self):
print("the governor is ",repr(self))
self.policy = None
def __str__(self):
return repr(self) + self.policy
instance = None
def __new__(cls): # __new__ always a classmethod
if not PAGovernor.instance:
@ErikPohl-Lot49-Projects
ErikPohl-Lot49-Projects / proxy.py
Created October 28, 2018 16:38
Proxy Design Pattern
# Proxy.py
# Simple demonstration of the Proxy pattern.
class Implementation2:
lock = True
hog = 0
def nextData(self, maskedPassword):
maskedExpectedPass = '12345'
if maskedPassword==maskedExpectedPass:
return "I just got data using the password"
@ErikPohl-Lot49-Projects
ErikPohl-Lot49-Projects / mediator.py
Last active November 11, 2018 18:04
Mediator Design Pattern
import random
"""
I am using mediator to represent a simplified board game version of the Game of Life
This LifeCellGridMediator defines an object that encapsulates how a set of mediated objects interact.
"Mediator promotes loose coupling by keeping objects from referring to
each other explicitly, and it lets you vary their interaction independently."
"""
class LifeCellGridMediator:
@ErikPohl-Lot49-Projects
ErikPohl-Lot49-Projects / memento_pattern.py
Last active November 11, 2018 18:05
Memento Design Pattern
import pickle
class Originator:
"""
Use the memento pattern to create a memento
containing a snapshot of the video game's current internal
state.
Use the memento to restore its internal state.
"""
def __init__(self):
@ErikPohl-Lot49-Projects
ErikPohl-Lot49-Projects / decorator.py
Created October 27, 2018 20:26
Decorator Design Pattern
from functools import wraps
def guarantee(*argsx):
""""this is a decorator to guarantee specific keyword arguments are used
in an otherwise open ended keyword argument list
Allows for extra messaging and handling for an error related to missing or invalid keyword arguments
"""
def real_decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
class McPattyBurgers:
def __init__(self):
self._apps = Apps('Quesadillas')
self._frozenpatty = FrozenPatty()
self._prepackagedbun = PrepackagedBun()
def homemadeburger(self):
self._apps.microwave()
self._frozenpatty.zap()
self._frozenpatty.slatherwith('ketchup')
@ErikPohl-Lot49-Projects
ErikPohl-Lot49-Projects / GoF_design_patterns.csv
Last active December 13, 2018 06:07
Gang of Four Design Patterns
Type Design Pattern Name Description
Creational Abstract Factory This abstraction represents a cluster of dependent or related objects without specifying exact classes
Creational Builder Decouples construction of a complex object from its representation and allows similar complex objects to be built from the same design.
Creational Factory Method This class is able to be a factory to create many different subclasses with the same interface
Creational Prototype You create one instance of the class: then no more new() instances-- just copies of the one instance you made
Creational Singleton This is a class which insures one and only one instantiation of itself will be available at a time
Structural Adapter This adapter pattern allows one class to speak with a client which requests a different interface
Structural Bridge Loosely couple the abstract class through an implementor to the possibly considerably more different concrete classes
Structural Composite The composite design pattern consists of nested classes
@ErikPohl-Lot49-Projects
ErikPohl-Lot49-Projects / meeting_checklist_pattern.csv
Last active November 2, 2018 01:39
Meeting Etiquette Checklist
type meeting checklist item result
pre-meeting How far in advance did you schedule it?
pre-meeting Does the meeting have a clear topic and agenda?
pre-meeting Did the organizer make clear who the intended audience is?
pre-meeting Were people excluded who could have benefited?
pre-meeting Did the organizer consider the schedules of the other participants?
pre-meeting Is the meeting time-boxed appropriately?
pre-meeting Is the presenter presenting some prepared material-- or is everything ad hoc?
during-meeting Do you know who the minute-keeper is and who the facilitator is?
during-meeting Are off-topic discussions sent to a parking lot?