Skip to content

Instantly share code, notes, and snippets.

@mrange
mrange / gist:8546024
Created January 21, 2014 19:00
Response to Chris Geuer-Pollmann regarding T4Include
<#
// Whenever this file is saved the files in the Includes section is downloaded
// from GitHub (you can download from other websources by changing rootpath)
RootPath = @"https://raw.github.com/";
Namespace = "WebAPI2PostExperiment" ; // The downloaded content is wrapped in this namespace
// Adds explicit usings
Usings = new []
{
Using ("Owin"),
@mrange
mrange / gist:8547725
Created January 21, 2014 20:28
Response to Chris Geuer-Pollmann regarding T4Include
<#
// Whenever this file is saved the files in the Includes section is downloaded
// from GitHub (you can download from other websources by changing rootpath)
RootPath = @"https://raw.github.com/";
Namespace = "WebAPI2PostExperiment" ; // The downloaded content is wrapped in this namespace
Usings = new []
{
Using ("Owin"),
};
@mrange
mrange / lo.fs
Last active August 29, 2015 14:07
LinqOtimizer question.
// The problem with Run is that the expression is begin rebuilt and then compiled everytime, potentially too expensive
let Run : int -> int = fun y -> Query.range(0,1000)
|> Query.filter(fun x -> x > y)
|> Query.sum
|> Query.run
// The problem with BuildFunc is that it doesn't compile :)
let BuildFunc : int -> int = Query.range(0,1000)
|> Query.filter(fun x -> x > VAR) // VAR should be the input parameter to the compiled func
|> Query.sum
|> Query.compile
@mrange
mrange / MyInterpreter.fs
Created December 12, 2014 21:09
A monadic interpreter
type Value =
| NoValue
| Bool of bool
| Int of int
| String of string
| Double of double
| Void
// With interpreters it's often good to have a stack of variables
// For instance when the interpreter calls a function typically a stackframe is pushed
@mrange
mrange / F# question 1
Created January 5, 2015 18:15
F# Question 1
// I like to create class type that accepts a generic enhancer function
// I tried 3 variants and nothing gives me the result I need
// Anyone has any ideas?
// warning FS0064: This construct causes code to be less generic than indicated by
// the type annotations. The type variable 'U has been constrained to be type 'obj'.
type MyTest1<'T>(enhancer : 'U->'U) =
let whatever = 3
type MyTest2<'T>() =
@mrange
mrange / Flowlet
Last active August 29, 2015 14:12
Flowlet gist
// A flowlet sample of simple customer registration flow
// First let's declare some types to hold the registration info
type AddressInfo =
{
FirstName : string
LastName : string
CareOf : string
AddressLine1 : string
AddressLine2 : string
// Copyright 2015 Mårten Rånge
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@mrange
mrange / top100.fs
Last active August 29, 2015 14:16
F# top 100 biggest binaries in a GIT repo and print the Commit they were introduced
// ----------------------------------------------------------------------------------------------
// Copyright (c) Mårten Rånge.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the License.html file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// [email protected]. By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.
open Microsoft.FSharp.Core
open System
open System.Reflection
let mutable errors = 0
let print (cc : ConsoleColor) (prefix : string) (msg : string) : unit =
let old = Console.ForegroundColor
try
@mrange
mrange / my_tuple.cpp
Last active August 29, 2015 14:22
C++14 tuple
#define COPY_MOVE(type) \
type (type const &) = default; \
type (type &&) = default; \
type & operator= (type const &) = default; \
type & operator= (type &&) = default;
template<std::size_t>
struct my_tuple_index
{
};