Skip to content

Instantly share code, notes, and snippets.

View mikehadlow's full-sized avatar

Mike Hadlow mikehadlow

View GitHub Profile
@mikehadlow
mikehadlow / add-1.fs
Created September 10, 2015 09:51
Partial application in C#
let add a b = a + b
@mikehadlow
mikehadlow / ClassWithDependency.csx
Last active December 16, 2019 09:15
C#: Only Use Static Methods
public class Thing : IThing
{
public Thing(IDependency dependency) { }
public void Do(string arg) { }
}
@mikehadlow
mikehadlow / AwaitableCompositionSpike.cs
Created July 9, 2015 15:27
Composing monadic async results using Linq
using System;
using System.Threading.Tasks;
namespace Monads
{
public static class AwaitableCompositionSpike
{
/// <summary>
/// First spike composes three aysnc results using Bind(..) extension method
/// </summary>
@mikehadlow
mikehadlow / FileCopy.cs
Last active June 19, 2020 13:54
InterceptionStream
using (var inputStream = File.OpenRead(@"TestFiles/Example.txt"))
using (var outputStream = File.OpenWrite(@"TestFiles/Output.txt"))
{
inputStream.CopyTo(outputStream);
}
let private Main () =
// traverse that works for 'get' only
let traverse ((f1, f2): PLens<'a, 'b>): Lens<'a list, 'b list> =
(fun x -> x |> List.map f1 |> List.choose id),
(fun _ -> fun x -> x) // this doesn't work
let resourceMapLens =
Json.ObjectPLens
>??> mapPLens "links"
@mikehadlow
mikehadlow / Program.fs
Created April 20, 2015 11:11
Basic Nowin self host. No dependencies on Microsoft.Owin.* assemblies.
open System
open System.IO
open System.Net
open System.Collections.Generic
open System.Threading.Tasks
let port = 8888
let endWithCompletedTask = fun x -> Task.FromResult(null) :> Task
type OwinEnvironment = {
open System
open Microsoft.Owin.Hosting
[<EntryPoint>]
let main argv =
let baseAddress = "http://localhost:8888"
use application = WebApp.Start<Startup.Startup>(baseAddress)
@mikehadlow
mikehadlow / README.md
Last active July 25, 2023 08:55
D3js Graph with X and Y crosshairs, and a threshold line.

Example of a D3js time series graph with X,Y crosshairs and a threshold line. Just copy the drawLineGraph function and call it with your data. The data shoud be an array of two element arrays. Something like:

var data = [
    [new Date(2014, 01, 10), 404],
    [new Date(2014, 01, 11), 123],
    [new Date(2014, 01, 12), 666]
    ];
    
var warnLine = { lineValue: 200, label: 'my important threshold' };
@mikehadlow
mikehadlow / README.md
Last active August 29, 2015 14:02
Predict Your Awesomeness

The results of playing with building graphs using D3js. This doesn't really predict your awesomeness over the next 100 days, it's entirely random, so if you don't like the results, just hit refresh to see if you get a better prediction :)

@mikehadlow
mikehadlow / README.md
Last active August 29, 2015 14:02
Segment Clock

A little D3js demo of a clock based on circle segments, more normally used for creating pie charts. I've speeded up time to 1 second == 1 hour to make it a little more visually interesting.