Skip to content

Instantly share code, notes, and snippets.

View a.cs
using System;
using System.Collections.Generic;
using System.Linq;
using MongoDB.Bson;
using MongoDB.Driver;
using NSubstitute;
using NSubstitute.ExceptionExtensions;
using Xunit;
namespace NSubWorkshop
dtchepak / Monoid.kt
Last active Oct 31, 2017
Kotlin monoid attempt
View Monoid.kt
* A type [T] with an associative binary operation.
* Must satisfy the associative property:
* `combine(combine(a, b), c) == combine(a, combine(b, c))`
interface Semigroup<T> {
fun combine(a: T, b: T): T
View DiagnosticsSubstitutionContext.cs
public class DiagnosticsSubstitutionContext : ISubstitutionContext
private static IList<IArgumentSpecification> LastDequeuedList;
private static ConcurrentDictionary<IArgumentSpecification, ArgumentInfo> ArgumentInfos { get; } = new ConcurrentDictionary<IArgumentSpecification, ArgumentInfo>();
private class ArgumentInfo
public string CreationStack { get; }
public int DequeueCounter { get; set; }
View Lens.elm
-- Based on
type alias Lens s a =
{ get : s -> a
, set : a -> s -> s
modify : Lens s a -> (a -> a) -> s -> s
modify l f s =
l.set (f (l.get s)) s
dtchepak / a.fs
Created Sep 25, 2015
FsCheck: Replaying a particular seed
View a.fs
// Based on example from
let repro() =
let seed = (771943725,296061824) // seed reported by failed FsCheck output
let config = {
Config.QuickThrowOnFailure with
Replay = Random.StdGen seed |> Some
Check.One (config, prop)
dtchepak / replsession.hs
Created May 21, 2015
Reader to construct a function that reads values from a single value
View replsession.hs
-- Some function that takes a number and a string
ghci> let f a b = show (a+1) ++ " " ++ b
ghci> :t f
f :: (Show a, Num a) => a -> [Char] -> [Char]
-- Some type with a number of fields we want to read
ghci> data Option = Option { number :: Int, label :: String } deriving (Show, Eq)
ghci> let o = Option 1 "hi"
-- Read value of each field from Option and pass to `f`
dtchepak / echo.rb
Last active Sep 12, 2022
Simple Ruby HTTP server to echo whatever GET or POST requests come through. Largely based on
View echo.rb
# Reference:
require 'webrick'
class Echo < WEBrick::HTTPServlet::AbstractServlet
def do_GET(request, response)
puts request
response.status = 200
def do_POST(request, response)
puts request
dtchepak / Console.swift
Last active Aug 29, 2015
Part of a series of exercises for experimenting with `flatMap` in Swift. Paste into an XCode test project and start filling in the `<TODO />`s. Previous exercises covered the implementation and use of `map` and `flatMap` for `Optional`, `Array`, and `Result` / `Either`. The aim of this exercise is to experiment with using the pattern to combine …
View Console.swift
import Foundation
import UIKit
import XCTest
// Console<T> is a type representing programs that can interact with the console (i.e. read from stdin, write to stdout),
// to produce a value of some type T.
// A Console<()> program is one that returns void ( a.k.a. Unit, written "()" ).
dtchepak /
Created Aug 31, 2014
D3 newbie updates a bar chart
View Sample.fs
module DaveSquared.Sample
open Xunit
let incr x = x+1
// Test using Unquote
open Swensen.Unquote