Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Seemann ploeh

View GitHub Profile
@ploeh
ploeh / gist:9702672
Created Mar 22, 2014
ASP.NET Web API 2 ApiController AutoFixture Customization
View gist:9702672
type ApiControllerCustomization() =
let controllerSpecification =
{ new IRequestSpecification with
member this.IsSatisfiedBy request =
match request with
| :? Type as t when typeof<ApiController>.IsAssignableFrom t ->
true
| _ -> false }
interface ICustomization with
View InputParseCommandTest.cs
[Theory]
[InlineAutoHostData(null)]
[InlineAutoHostData("")]
[InlineAutoHostData]
public void ExecuteUnknownInputCorrectlyInvokesOnUnknown(string unknownInput, Action dummyOnExit)
{
var verified = false;
var sut = new InputParseCommand(dummyOnExit, i => verified = i == unknownInput);
sut.Execute(unknownInput);
Assert.True(verified);
@ploeh
ploeh / gist:1185766
Created Sep 1, 2011
Configuring ordered named sequences in Unity
View gist:1185766
container.RegisterType<IMeal, Meal>(
new InjectionConstructor(
new ResolvedArrayParameter<ICourse>(
new ResolvedParameter<ICourse>("entrée"),
new ResolvedParameter<ICourse>("mainCourse"),
new ResolvedParameter<ICourse>("dessert"))));
View gist:4f873315fc556f7672f1
let nerdCapsToKebabCase (text : string) =
let charToString index c =
let s = c.ToString().ToLower()
match index, Char.IsUpper c with
| 0, _ -> s
| _, true -> "-" + s
| _ -> s
text |> Seq.mapi charToString |> String.concat ""
View KeepImmutableSanity.cs
public class ImmutableXYZ {
public ImmutableXYZ() : this("", 0, -1) {
}
private ImmutableXYZ(string abc, int def, int haha)
{
this.abc = abc;
this.def = def;
this.haha = haha;
}
@ploeh
ploeh / FractalTree.fsx
Created Jun 6, 2017
Fractal tree in F#. Our solution from dojo in Copenhagen, 2017-05-30
View FractalTree.fsx
open System
open System.Drawing
open System.Windows.Forms
// Create a form to display the graphics
let width, height = 500, 500
let form = new Form(Width = width, Height = height)
let box = new PictureBox(BackColor = Color.White, Dock = DockStyle.Fill)
let image = new Bitmap(width, height)
let graphics = Graphics.FromImage(image)
View PollingConsumer.hs
{-# LANGUAGE DeriveFunctor #-}
module PollingConsumer where
import Data.Time.Clock
import Control.Monad.Trans.Free (Free, FreeF(..), liftF, runFree)
import Control.Concurrent (threadDelay)
import System.Random (getStdRandom, random, randomR)
import Text.Printf (printf)
-- "Types prevent typos" - https://twitter.com/hmemcpy/status/867647943108681728
View Main.hs
-- Translation to Haskell of:
-- http://ccd-school.de/2017/06/stratified-design-over-layered-design
-- I've deliberately translated each method to a function, in order to show the
-- similarity. Some functions, like extractWords, are redundant (already built
-- in) or almost too simple to get their own function.
module Main where
import Data.List (partition)
@ploeh
ploeh / Foo.cs
Created Jan 26, 2018
Enumerating over generic and non-generic enumerators in C#
View Foo.cs
using System;
using System.Collections;
using System.Collections.Generic;
public class Foo : IEnumerable<int>
{
public IEnumerator<int> GetEnumerator()
{
yield return 42;
yield return 1337;
View RadioCode.hs
module RadioCode where
import Control.Arrow
import Data.Char
import Data.List
import Data.Maybe
icao :: [(Char, String)]
icao =
(head &&& delete ',')
You can’t perform that action at this time.