Skip to content

Instantly share code, notes, and snippets.

View Sean-Bradley's full-sized avatar
📰
https://sbcode.net

SBCODE Sean-Bradley

📰
https://sbcode.net
View GitHub Profile
@Sean-Bradley
Sean-Bradley / gist:cbb4316bff54edd9f3cb103ffc1bad6b
Created March 3, 2019 12:05
python print a number with padded zeros, using % rather than .format
iNum = 123 #will always be a number
sPaddingChar = "0"
iNumPads = 6
#print the number with padded zeros, using % rather than .format
print ('%s' % (str(iNum).rjust(iNumPads, sPaddingChar)))
@Sean-Bradley
Sean-Bradley / gist:d6cee6435c56b7ddfd0e9c65eaa7713f
Last active March 3, 2019 20:57
Testing Python Inheritance Override Order
class Foo:
def testOverideOrder(self):
print("Foo")
class Bar:
def testOverideOrder(self):
print("Bar")
@Sean-Bradley
Sean-Bradley / .gitlab-ci.yml
Created April 2, 2019 06:35
sample gitlab-ci.yml
image: docker:latest
services:
- docker:dind
stages:
- test
- deploy
step-develop:
stage: test
@Sean-Bradley
Sean-Bradley / example.py
Last active April 9, 2019 10:18
Calling the ChairFactory
CHAIR_FACTORY = ChairFactory().get_chair("SmallChair")
print(CHAIR_FACTORY.get_dimensions())
# Asking for a `SmallChair` will pass the request to the `Chair Factory`
FURNITURE = FurnitureFactory.get_furniture("SmallChair")
print(f"{FURNITURE.__class__} : {FURNITURE.dimensions()}")
# prints <class 'chair_factory.SmallChair'> : {'width': 40, 'depth': 40, 'height': 40}
# And Asking for a `MediumTable` will pass the request to the `TableFactory`
FURNITURE = FurnitureFactory.get_furniture("MediumTable")
print(f"{FURNITURE.__class__} : {FURNITURE.dimensions()}")
# prints <class 'table_factory.MediumTable'> : {'width': 110, 'depth': 70, 'height': 60}
from abc import ABCMeta, abstractstaticmethod
from chair_factory import ChairFactory
from table_factory import TableFactory
class IFurnitureFactory(metaclass=ABCMeta): # pylint: disable=too-few-public-methods
"""Furniture Factory Interface"""
@abstractstaticmethod
def get_furniture(furniture):
"""The static funiture factory inteface method"""
class FurnitureFactory(IFurnitureFactory): # pylint: disable=too-few-public-methods
"""The Furniture Factory Concrete Class"""
@staticmethod
def get_furniture(furniture):
"""Static get_furniture method"""
try:
if furniture in ["SmallChair", "MediumChair", "BigChair"]:
return ChairFactory().get_chair(furniture)
if furniture in ["SmallTable", "MediumTable", "BigTable"]:
class ICommand(metaclass=ABCMeta):
"""The command interface, which all commands will implement"""
@abstractstaticmethod
def execute():
"""The required execute method which all command obejcts will use"""
class SwitchOnCommand(ICommand):
"""A Command object, which implemets the ICommand interface"""
class Switch:
"""The Invoker Class"""
def __init__(self):
self._commands = {}
self._history = []