Skip to content

Instantly share code, notes, and snippets.

View forgetaboutit's full-sized avatar

Samuel Schuhmacher forgetaboutit

  • Stuttgart, Germany
View GitHub Profile
@forgetaboutit
forgetaboutit / gist:87655fe4a76330d28209
Last active August 29, 2015 14:16
C# phantom types
interface IUnit {}
interface IMeter : IUnit {}
interface ICentimeter : IUnit {}
interface ILiter : IUnit {}
struct Quantity<TUnit> where TUnit : IUnit {
public readonly double Value;
public Quantity(double l) { Value = l; }
public override string ToString() { return string.Format("{0}", Value); }
@forgetaboutit
forgetaboutit / Foldable.cs
Last active August 16, 2016 21:05
Foldables in C#, F#, and TypeScript
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace funsharp
{
// Demo data class
internal class Blarg
@forgetaboutit
forgetaboutit / typeclasses.js
Last active August 29, 2015 14:17
Type class emulation in JavaScript: Maybe and State
//
// Compile with Traceur, available online here:
// http://google.github.io/traceur-compiler/demo/repl.html
//
// Alternatively, load using node:
// $ node --harmony
// > .load filename.js
//
//
@forgetaboutit
forgetaboutit / van-laarhoven-lenses.cs
Last active August 29, 2015 14:18
Lenses à la van Laarhoven
public struct Store<A, B> {
// Setter of accessor (A), return new object (B)
public readonly Func<A, B> Put;
// Getter/Value of accessor (A)
public readonly A Pos;
public Store(Func<A, B> put, A pos) {
Put = put;
Pos = pos;
}

Keybase proof

I hereby claim:

  • I am forgetaboutit on github.
  • I am forgetaboutit (https://keybase.io/forgetaboutit) on keybase.
  • I have a public key ASD0a3jcfbcywKJqx5BQPDGLSxcKVa1eh_8MxXQ7AhjOmgo

To claim this, I am signing this object:

0eNrNXd1yG7cOfpWOrrMZgv/M9C3O5ZmOZ22tnZ3KkrqS3OR08u5nV1pJWwukAMj2+KpJ7H4ESfx8ALHkP7P7xa5Zd+1yO/v2z6x9WC03s2///We2aZ+W9WL4t+3PdTP7Nmu3zfPsy2xZPw9/29SLdllv29WyWi/q5bbSs19fZu1y3vyYfYNfX64C1MunZrGpmkXzsO1Wi5+bpqvsBEP/+uPLrFlu223bHCTa/+Xn3XL3fN90/SCvoR4XdddUm2398Gc/zHq1aQfxBgF6uCp+dV9mP/s/GP3VDcP00myGH3b139Vm3TTz6nk13y2aKg6DDzN4NaDmDehvHtDwBrQ3D2h5A+qbB3SnAR+arn5uH6p12+sKsnvjQICheCpKKKEEKoovoUQUpdquqqdutVvOC3gKw0tUqWxJKlBUGFOEAf7sbGl2oKly6aJcZ0tZrJ7azbbHefjebLbVut5s2pemWnerl3be/+4lMowS6tir8H09aCU2hM0N0TV/7fr/4th6gj3+4t1ju+h/++DTjg7zBN48r7c/q16Mrln0gA/9qm6H/fv1ByaUu2XeijTvs3HdN3UfHSqTV+E9VNELeHT7gmRt4/su7dmQ17tu3Uvfq3fTHdS8um8W20uRYCLRvO36wLb/Wa85xwi4XO+2M2y0s5nfd6vl/5qMGcB5CCxAKSZKQlGgFOQvwcYYoP2/Z62HXXlo9/P+u+53pdqjDeIIQu/ZTzQ/1l2z2RyCUtUue96wLdt1eLUdGP7ZgRz0o10+Vevd8xrDHV2kdr8mU+w1b1Et2r927bza7BaPu65X4vqh/9tJ4QTTtoJp69O0MUQnQFSMhfT0hUwft46BP+tYXMbIDMsadXw6ieMpZTOM4sMb3Jo9Bs9nA5DxFRi6vpIqXIAfV8bSHFG1adZ1t/duIqUyhultUU0ylomCKpI5m/VhioPJYWsE6evJX+85+3SPJws1xrk92EwS042Xq7ZDAfk2rCYOpmcug+7c3Tff65d21Q2/8tB2D7t2e9dPpbl
@forgetaboutit
forgetaboutit / ExpandAndSplice.cs
Last active April 25, 2018 21:45
LINQKit.Core vs. Custom Splice
// Code from the post: https://balefrost.github.io/expression_splicing.html
public static class ExpressionSplicer
{
public static TResult Inline<T1, TResult>(this Expression<Func<T1, TResult>> substitutionExpr, T1 value1)
{
throw new Exception(
"This method isn't meant to be called; it's meant to appear inside a template expression passed to Splice");
}
}
@forgetaboutit
forgetaboutit / JsonFilterToExpression.cs
Last active October 6, 2021 20:34
json-filter-to-expression
public enum Operation
{
Gt,
Gte,
Lt,
Lte,
Eq,
Neq
}