This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SAMPLE ONLY -- DON'T USE FOR REAL STUFF UNLESS YOU'VE REVIEWED AND TESTED :) | |
// Needs work to make robust: check property type's class has default ctor and so on. | |
// Can also filter out interfaces as these will be auto-subbed. | |
public static T SubFor<T>() where T : class | |
{ | |
var gettableVirtualProps = typeof(T).GetProperties() | |
.Where(x => x.CanRead && x.GetGetMethod().IsVirtual) | |
.Select(x => x); | |
var sub = Substitute.For<T>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace MarkupParser | |
{ | |
public abstract class Node | |
{ | |
public static Parser<String> TextParser() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using MongoDB.Bson; | |
using MongoDB.Driver; | |
using NSubstitute; | |
using NSubstitute.ExceptionExtensions; | |
using Xunit; | |
namespace NSubWorkshop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Functors | |
{ | |
public static IEnumerable<B> fmap<A,B>(this IEnumerable<A> functor, Func<A, B> f) | |
{ | |
return functor.Select(f); | |
} | |
public static B? fmap<A, B>(this A? functor, Func<A, B> f) where A : struct where B : struct | |
{ | |
return functor == null ? null : (B?) f(functor.Value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Extensions.cs | |
public static IObservable<T> ObservableFunc<T>(this Func<T> f) { | |
return Observable.Create<T>(obs => { | |
try { | |
obs.OnNext(f()); | |
obs.OnCompleted(); | |
} catch (Exception e) { | |
obs.OnError(e); | |
} | |
return () => {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var done = new Subject<Unit>(); | |
var status = Observable | |
.Interval(TimeSpan.FromMilliseconds(450)) | |
.Select(_ => driver.Status()) // driver keep-alive | |
.TakeUntil(done); | |
// On dispose, window close, etc... | |
done.CompletedWith(Unit.Value); |
NewerOlder