Skip to content

Instantly share code, notes, and snippets.

@ckpearson
ckpearson / hierarchiseMethod.cs
Last active August 29, 2015 14:06
Hierarchise a collection
/// <summary>
/// Takes an enumerable of items and builds a hierarchy from two properties present on the item
/// </summary>
/// <typeparam name="TOuter">The type of the outer key</typeparam>
/// <typeparam name="TInner">The type of the inner key</typeparam>
/// <typeparam name="TValue">The type of the item being processed</typeparam>
/// <param name="items">The enumerable to process</param>
/// <param name="outerSelector">Function for accessing the outer key</param>
/// <param name="innerSelector">Function for accessing the inner key</param>
public static Dictionary<TOuter, Dictionary<TInner, TValue>> Hierarchise<TOuter, TInner, TValue>(this IEnumerable<TValue> items,
@ckpearson
ckpearson / Unfold.cs
Created December 5, 2014 18:17
F# Seq.Unfold style method in C#
public static IEnumerable<TRes> Unfold<TRes, T>(this T item, Func<T, Tuple<TRes, T>> generator)
{
var res = generator(item);
if (res == null) yield break;
yield return res.Item1;
foreach(var sub in Unfold<TRes, T>(res.Item2, generator)) yield return sub;
}
@ckpearson
ckpearson / howto.md
Created January 30, 2019 00:51
Configuring ASP.NET Core HTTPS with a self-signed CA root & cert for iOS development on OSX

The Problem

ASP.NET core has a very useful dev-certs utility capable of producing self-signed certificates for local https development work.

This works for the most-part, but as soon as you start wanting to do local development of a native app, iOS refuses to trust the certificate, or indeed, to even let you tell it to trust it.

You can see This Issue for some more context.

The Solution

This is what worked for me, I make no guarantees as to its efficiency or ongoing efficacy.

@ckpearson
ckpearson / TopologicalSort.cs
Created April 1, 2019 09:50 — forked from Sup3rc4l1fr4g1l1571c3xp14l1d0c10u5/TopologicalSort.cs
Topological Sorting (Kahn's algorithm) implemented in C#
using System;
using System.Collections.Generic;
using System.Linq;
namespace TopologicalSort {
static class Program {
static void Main() {
//
// digraph G {
// "7" -> "11"