Skip to content

Instantly share code, notes, and snippets.

@n1ckdm
n1ckdm / decision_tables.rs
Last active August 5, 2022 08:23
example of decisiont tables for apostrophe logic
let contraction_table = |w: &str| match
(contraction(w),pronoun(w),with_verb(w)) {
(false ,_ ,_ ) => "No Apostrophe",
(true ,true ,true ) => "Use Apostrophe",
(true ,false ,_ ) => "Use Apostrophe",
(true ,true ,false ) => "No Apostrophe"
};
let possessive_table = |w: &str| match
(possessive(w),is_it_it(w),is_or_has(w),name_ends_in_s(w),plural_name(w),ends_in_s(w)) {
[Fact]
public async Task GameIsTied()
{
await _appService.Handle(new CreateGameCommand(_gameId, _player1));
await _appService.Handle(new MakeMoveCommand(_gameId, _player1, Move.Rock));
await _appService.Handle(new MakeMoveCommand(_gameId, _player2, Move.Rock));
var events = await _repository.Load(_gameId);
Assert.True(events.Contains(new Events.GameTiedEvent(_gameId)));
}
private async Task<Game> GetCurrentState(Guid gameId) =>
(await _repository.Load(gameId)).Aggregate(new Game(), (g, e) => Game.Apply(g, e));
private List<IEvent> SendToAggregate(ICommand command, Game game) =>
command switch
{
CreateGameCommand c => game.Handle(c),
MakeMoveCommand c => game.Handle(c),
_ => throw new NotImplementedException()
};
private async Task<Game> GetCurrentState(Guid gameId) =>
(await _repository.Load(gameId)).Aggregate(new Game(), (g, e) => Game.Apply(g, e));
private List<IEvent> SendToAggregate(ICommand command, Game game) =>
command switch
{
CreateGameCommand c => game.Handle(c),
MakeMoveCommand c => game.Handle(c),
_ => throw new NotImplementedException()
};
public static Game Apply(Game game, IEvent evt)
{
switch (evt)
{
case GameCreatedEvent e:
return new Game
{
State = EState.Created,
Player = e.PlayerEmail,
};
public List<IEvent> Handle(MakeMoveCommand cmd)
{
if (EState.Created == State)
{
return new List<IEvent>
{
new MoveDecidedEvent(cmd.GameId, cmd.PlayerEmail, cmd.Move)
};
}
else if (EState.Waiting == State)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.tailwindcss.com"></script>
<title>Spotify Now Playing</title>
</head>
<body>
@n1ckdm
n1ckdm / make_traced_request.py
Last active November 5, 2021 15:38
Context manager that yeilds a requests session and starts a span that already has the headers injected with the span's context so that this is passed into the request for tracing
import requests
from typing import Generator
from contextlib import contextmanager
from dataclasses import dataclass
@dataclass
class Context:
span: opentracing.Span
session: requests.Session
@n1ckdm
n1ckdm / desserts.py
Created October 27, 2021 19:27
Random desserts
import random
_desserts = {
"AngelDelight": "😇+💕",
"AngelCake": "😇+🍰",
"Amandine": "🍫🍰",
"Bakewell": "🍒+🧁",
"Brownie": "🍫🟤y",
"Battenberg": "🦇+🧊",
"Cake": "🍰",