Skip to content

Instantly share code, notes, and snippets.

Ralf Westphal ralfw

View GitHub Profile
@ralfw
ralfw / textmanager.cs
Last active May 30, 2020
Text Obfuscation
View textmanager.cs
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 Dec 15, 2019
ES Challenge - Bowling Game Kata Submissions
View akii.cs
class RollMade {
public int Pins;
}
@ralfw
ralfw / 01 bowling game.cs
Last active Dec 10, 2019
EventSourcing Challenge: Bowling Game Kata
View 01 bowling game.cs
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 Nov 27, 2019
DDC 2019 - Event-Orientation Workshop
View 00 eventstore.cs
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 Jul 25, 2019
Experimenter: Reduce noise in code by pushing try-catch into the background
View Experimenter.cs
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 Jul 2, 2019
Bank OCR Test Data
View ocr1.txt
_ _ _ _ _ _ _
| _| _||_||_ |_ ||_||_|
||_ _| | _||_| ||_| _|
_ _ _ _ _ _ _
|_||_|| || ||_ | | ||_
| _||_||_||_| | | | _|
@ralfw
ralfw / classify.cs
Last active Jul 30, 2018
IOSP Example
View classify.cs
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 Jul 1, 2020
Layered design vs stratified design
View layered.cs
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 Feb 3, 2017
Diamond-Square Solution
View 01 terrain generator.cs
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 Aug 22, 2016
Tic Tac Toe in Elm
View 01 Main.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
You can’t perform that action at this time.