Skip to content

Instantly share code, notes, and snippets.

Ralf Westphal ralfw

Block or report user

Report or block ralfw

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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 Oct 21, 2018
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
@ralfw
ralfw / Dockerfile
Created Aug 18, 2016
Roll your own Elm Docker container
View Dockerfile
# Build image with Node.js, Elm and Nginx
FROM debian:latest
# prepare
RUN apt-get -y update
RUN apt-get -y install apt-utils
# install curl, http://stackoverflow.com/questions/27273412/cannot-install-packages-inside-docker-ubuntu-image
RUN apt-get -y install curl
@ralfw
ralfw / game.cs
Last active Oct 8, 2018
IODA Architecture for Bowling Game Kata
View game.cs
public class Game {
private int[] rolls = new int[21];
private int currentRoll = 0;
public void roll(int pins) {
rolls[currentRoll++] = pins;
}
public int score() {
var frames = Detect_frames (rolls);
@ralfw
ralfw / ppoop.cs
Last active Sep 12, 2015
ppoop solution
View ppoop.cs
using System;
using System.Collections.Generic;
namespace ppoop
{
// source: http://www.csis.pace.edu/~bergin/patterns/ppoop.html
class MainClass
{
public static void Main (string[] args)
View gist:8b5e796f5012f549b170
using System;
using System.Windows.Forms;
using Akka.Actor;
namespace spike.akka
{
static class Program
{
[STAThread]
static void Main()
You can’t perform that action at this time.