Skip to content

Instantly share code, notes, and snippets.

@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 / 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
@ralfw
ralfw / assemblyLineFor.cs
Last active December 22, 2015 05:29
Pipes and filters à la Steve Bate. No, wait, it´s not pipes and filters anymore. It´s an assembly line processing work pieces. And you can assemble the assembly line using the + operator.
public class AssemblyLineFor<T>
{
public interface IFilter
{
T Process(T message);
}
private readonly IList<Func<T, T>> _stages = new List<Func<T, T>>();
@ralfw
ralfw / pipeline.cs
Created September 3, 2013 10:38
Pipes and filters à la Steve Bate - but with another twist. This time the message flowing through the pipe can change its type.
public class Pipeline
{
public interface IFilter<in TIN,out TOUT>
{
TOUT Process(TIN message);
}
private readonly IList<Func<object,object>> _stages = new List<Func<object,object>>();
@ralfw
ralfw / blackbox.js
Created July 6, 2013 22:23
Tic Tac Toe mit JavaScript und Eventstore Inspiriert durch Mike Bilds Vorlage: https://gist.github.com/MikeBild/5926056
var BlackBox = function() {
var self = this;
self._events = [];
self.Record = function(event) {
self._events.push(event);
self.Recorded(event);
};
@ralfw
ralfw / gist:5486673
Created April 30, 2013 05:03
PoMO mit zwei Pfaden durch den Code
Seite Erste_Seite_laden() {
Seite seite;
var dateiname = Dateiname_von_Kommandozeile_holen();
Zeilen_lesen(dateiname,
zeilen => {
seite = new Seite {
Überschrift = Überschrift_extrahieren(alleDatenzeilen),
Datenzeilen = Zeilen_der_ersten_Seite_selektieren(alleDatenzeilen)
};
@ralfw
ralfw / ParseFiles.cs
Created January 22, 2013 07:49
Class to upload and delete files using the parse.com REST API.
// Be sure to reference System.Web and System.Web.Extensions in your C# project
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Web.Script.Serialization;
namespace parse.com
{
public class ParseFiles
@ralfw
ralfw / ParseObjects.cs
Last active December 11, 2015 10:48
Class to store objects using the parse.com REST API.
// Be sure to reference System.Web and System.Web.Extensions in your C# project
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Web;
using System.Web.Script.Serialization;
namespace parse.com
{
@ralfw
ralfw / test_wrapper.cs
Created November 5, 2012 07:50
Kata Word Wrap mit expliziten Aspekten
using System;
using System.Dynamic;
using NUnit.Framework;
namespace KataWordWrap
{
[TestFixture()]
public class test_Wrapper
{
[TestCase("word", 4, Result="word")]