Skip to content

Instantly share code, notes, and snippets.

David Tchepak dtchepak

View GitHub Profile
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
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
{
[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; }
View Lens.elm
-- 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 Sep 25, 2015
FsCheck: Replaying a particular seed
View a.fs
// 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
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
dtchepak / echo.rb
Last active Feb 8, 2020
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/.
View echo.rb
# 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 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
// 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 Aug 31, 2014
D3 newbie updates a bar chart
View README.md
View Sample.fs
module DaveSquared.Sample
open Xunit
let incr x = x+1
// Test using Unquote
open Swensen.Unquote
[<Fact>]
You can’t perform that action at this time.