Skip to content

Instantly share code, notes, and snippets.

@bChiquet
bChiquet / noIfFizBuz.py
Created June 17, 2016 17:06
Maybe slightly overengineered ?
from fractions import gcd
import unittest
from itertools import combinations
baseMods=[(3, 'fizz'),
(5, 'buzz'),
(7, 'foo')]
mods = []
main = do
hspec $ do
describe "thisYearCoef" $ do
it "starts at 100" $ do
thisYearCoef New `shouldBe` 100
it "decreases by 5percent from previous year without accident" $ do
thisYearCoef (Existing 100) `shouldBe` 95
thisYearCoef (Existing 95) `shouldBe` 90
thisYearCoef (Existing 80) `shouldBe` 76
@bChiquet
bChiquet / .hs
Last active October 31, 2016 10:26
--Haskell as OO code
data Card = Card Rank Suit -- my object data
deriving (Eq, Show) -- The "Card" objects inherits Eq, Show from its subcomponents (Eq = equals, Show = toString)
instance Ord Card where -- I say Card implements the interface Ord
compare (Card rank1 _) (Card rank2 _) = compare rank1 rank2 -- Ord has the compare method so I implement it for Card
import random
city = {"gold" : 5,
"food" : 5,
"health" : 5,
"civilians" : 5,
"army" : 5}
def hasFallen (city) :
def militaryPutsch(city):
@bChiquet
bChiquet / 45lines.py
Created January 18, 2017 11:27
Reactive event sourcing from nothing
event_reaction_map = {}
def apply_events_triggered_by(event):
if event in event_reaction_map:
for reaction in event_reaction_map[event]:
reaction()
def react_to(event):
@bChiquet
bChiquet / rules.md
Created January 18, 2017 13:20
Castle game rules

the castle

Rules

Avoid the fall of your city

description

Your city is modeled by several gauges :

  • gold
  • wheat
@bChiquet
bChiquet / Complaint.py
Created January 18, 2017 18:25
Reactive event sourcing in 45 lines
event_reaction_map = {}
def apply_effects_of(event):
if event in event_reaction_map:
for reaction in event_reaction_map[event]:
reaction()
def react_to(event):
from unittest import TestCase
class Anything:
def __eq__(self, other):
return True
def __ne__(self, other):
return False
# Let's start with an easy challenge... Hundreds of visitors shop inside a shopping mall .
# The aim of this challenge is to determine how many people are present in the shopping mall
# at a given point in time.
#
# Data
#
# Input
@bChiquet
bChiquet / .hs
Created April 3, 2017 15:28
append only
import Test.Hspec
main = hspec $ do
describe "fizbuzz" $ do
it "1 gives 1" $ do
fizzBuzz 1 `shouldBe` "1"
it "2 gives 2" $ do
fizzBuzz 2 `shouldBe` "2"
it "3 gives fizz" $ do
fizzBuzz 3 `shouldBe` "fizz"