Skip to content

Instantly share code, notes, and snippets.

@ralfw
ralfw / textmanager.cs
Last active May 30, 2020 08:09
Text Obfuscation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace ancientcode {
public class TextManager {
private TextManagerHelper hlp = new TextManagerHelper();
private Random rnd = new Random();
@ralfw
ralfw / akii.cs
Created December 15, 2019 12:11
ES Challenge - Bowling Game Kata Submissions
class RollMade {
public int Pins;
}
@ralfw
ralfw / 01 bowling game.cs
Last active December 10, 2019 09:33
EventSourcing Challenge: Bowling Game Kata
using System.Linq;
using System.Collections.Generic;
class BowlingGameBareBones
{
#region Event definitions
abstract class Event {}
class Rolled : Event {
public uint Pins;
@ralfw
ralfw / 00 eventstore.cs
Last active November 27, 2019 16:27
DDC 2019 - Event-Orientation Workshop
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using Newtonsoft.Json; // NuGet package dependency
namespace eventorientation
{
@ralfw
ralfw / Experimenter.cs
Last active July 25, 2019 09:57
Experimenter: Reduce noise in code by pushing try-catch into the background
public static class Experimenter
{
private static ILogging __log;
public static void Init(ILogging log) => __log = log;
public static bool Try(string logMsg, Action experiment)
{
try
{
@ralfw
ralfw / ocr1.txt
Last active July 2, 2019 08:31
Bank OCR Test Data
_ _ _ _ _ _ _
| _| _||_||_ |_ ||_||_|
||_ _| | _||_| ||_| _|
_ _ _ _ _ _ _
|_||_|| || ||_ | | ||_
| _||_||_||_| | | | _|
@ralfw
ralfw / classify.cs
Last active July 30, 2018 14:11
IOSP Example
void Classify(string number, Action<int> onArabic, Action<string> onRoman) {
if (int.TryParse(number, out var arabicNumber))
onArabic(arabicNumber);
else
onRoman(number);
}
/*
* Note how all details about how classification works are hidden in the function Classify().
* It's not visible to the outside wheter an "if" is used or a table lookup or whatever.
@ralfw
ralfw / layered.cs
Last active July 22, 2022 07:14
Layered design vs stratified design
using System;
using System.Linq;
namespace layered
{
class MainClass
{
public static void Main(string[] args) {
var data = new DataLayer();
var business = new BusinessLayer(data);
@ralfw
ralfw / 01 terrain generator.cs
Last active February 3, 2017 10:05
Diamond-Square Solution
using System;
using System.Linq;
namespace terraingenBlog
{
public class TerrainGenerator {
public static void Interpolate(Terrain terrain, float offset, float amplitude) {
Interpolate(terrain, offset, amplitude, Random_numbers_between_minus_1_and_1());
}
@ralfw
ralfw / 01 Main.elm
Last active August 22, 2016 06:49
Tic Tac Toe in Elm
module Main exposing(main)
import Html exposing (Html, div, span, br, text, table, tr, td, button)
import Html.Attributes exposing (style)
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onClick)
import Array exposing (Array)
import List