Skip to content

Instantly share code, notes, and snippets.

# Circuit Breaker
# - Circuit starts in a "closed" state.
# - Here, all calls to a given service go through
# - Consecutive failures are recorded.
# - When threshold is reached, circuit trips and the circuit gets into an "open" state.
# - In open state, calls to a given service raise CircuitBrokenException
# - Circuit remains "open" until failure timeout elapses
# - After failure timeout elapses, circuit gets into "half-open" state
# - Here, a call to aservice will go through
# - If the call fails, the circuit goes back to "open" state
@alex-magana
alex-magana / Update_Forked_Repo.md
Last active April 17, 2018 16:21 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream [email protected]:ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
<html>
<head>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
<script>
$(document).ready(function(){
$('ul.tabs').tabs({
swipeable : true
});
});
# The class, Printer takes a generic parser. It doesn't depend on the
# low-level details of PdfFormatter or HtmlFormatter classes.
class Printer
def initialize(data, formatter)
@data = data
@formatter = formatter
end
def print(formatter)
formatter.format(@data)
# Dependency inversion violation
# Here we see print_pdf and print_html
# depend on the formatter classes intanciated in them
class Printer
def initialize(data)
@data = data
end
def print_pdf
PdfFormatter.new.format(@data)
# We create 2 interfaces, each specific to the user type
# that utilises it
class CoffeeMachineUserInterface
def select_drink_type
# select drink type logic
end
def select_portion
# select portion logic
end
# Interface segregation principle violation
class CoffeeMachineInterface
def select_drink_type
# select drink type logic
end
def select_portion
# select portion logic
end
# The class, Square violates Liskov substitution principle since it
# replaces the behaviour of set_height and set_width by modifying
# width and height respectively
class Rectangle
def set_height(height)
@height = height
end
def set_width(width)
@width = width
# Here we pass the file format parser as a paremeter
# This design allows for extension by means of adding other
# classes that support other formats, doing this
# without having to modify class, UsageFileParser
class UsageFileParser
def initialize(client, parser)
@client = client
@parser = parser
end
# Violation
# This class violates OCP since we would need to modify this class
# when the need arises to support other file formats apart from
# .csv and .xml
class UsageFileParser
def initialize(client, usage_file)
@client = client
@usage_file = uasge_file
end