Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

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
dtchepak / Monoid.kt
Last active October 31, 2017 23:40
Kotlin monoid attempt
/**
* 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
public class DiagnosticsSubstitutionContext : ISubstitutionContext
{
[ThreadStatic]
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; }
-- Based on https://gist.github.com/evancz/78293dc6a4ac2547676c
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
dtchepak / a.fs
Created September 25, 2015 05:08
FsCheck: Replaying a particular seed
// Based on example from http://fsharpforfunandprofit.com/posts/property-based-testing/
[<Test>]
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
dtchepak / replsession.hs
Created May 21, 2015 04:30
Reader to construct a function that reads values from a single value
-- 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
dtchepak / echo.rb
Last active September 12, 2022 07:24
Simple Ruby HTTP server to echo whatever GET or POST requests come through. Largely based on https://www.igvita.com/2007/02/13/building-dynamic-webrick-servers-in-ruby/.
# Reference: https://www.igvita.com/2007/02/13/building-dynamic-webrick-servers-in-ruby/
require 'webrick'
class Echo < WEBrick::HTTPServlet::AbstractServlet
def do_GET(request, response)
puts request
response.status = 200
end
def do_POST(request, response)
puts request
@dtchepak
dtchepak / Console.swift
Last active August 29, 2015 14:15
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 …
import Foundation
import UIKit
import XCTest
// INTRODUCTION
// 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
dtchepak / README.md
Created August 31, 2014 06:53
D3 newbie updates a bar chart
module DaveSquared.Sample
open Xunit
let incr x = x+1
// Test using Unquote
open Swensen.Unquote
[<Fact>]