Skip to content

Instantly share code, notes, and snippets.

@colinbull
colinbull / Directory.build.target
Created March 10, 2019 19:06
Function v2 directory.build.targets
<Project>
<PropertyGroup>
<_IsFunctionsSdkBuild Condition="$(_FunctionsTaskFramework) != ''">true</_IsFunctionsSdkBuild>
<_FunctionsExtensionsDir>$(TargetDir)</_FunctionsExtensionsDir>
<_FunctionsExtensionsDir Condition="$(_IsFunctionsSdkBuild) == 'true'">$(_FunctionsExtensionsDir)bin</_FunctionsExtensionsDir>
</PropertyGroup>
<Target Name="CopyExtensionsJson" AfterTargets="_GenerateFunctionsAndCopyContentFiles">
<Message Importance="High" Text="Overwritting extensions.json file with one from build." />
@colinbull
colinbull / csv.fs
Created August 28, 2016 19:21
A simple CSV file
type Csv private(headers : string[], data : string [] []) =
let headers = ResizeArray<string>(headers)
let data = ResizeArray(data |> Array.map (ResizeArray))
static member Empty = Csv([||], [||])
static member Read(file:string) =
let csv = CsvFile.Load(file)
let headers =
module QuotationPrinter =
open System
open Microsoft.FSharp.Quotations
let rec print depth (expr:Expr) =
match expr with
| Patterns.Value (v, typ) -> sprintf "%A" v
| Patterns.Var v -> sprintf "%s:%s" v.Type.Name v.Name
| Patterns.NewUnionCase (uci, args) ->
@colinbull
colinbull / gist:4ec846e146f4ca15f3e1
Last active August 29, 2015 14:06
SqlProvider with ComposableQuery
open System
open FSharp.Data.Sql
open FSharpComposableQuery
FSharp.Data.Sql.Common.QueryEvents.SqlQueryEvent |> Event.add (printfn "Executing SQL: %s")
type HR = SqlDataProvider<ConnectionStringName = "***********", DatabaseVendor = Common.DatabaseProviderTypes.ORACLE>
let ctx = HR.GetDataContext()
type AuditRecord = {
@colinbull
colinbull / StyleCop
Created July 22, 2014 12:52
Comparing C#, C# + StyleCop and F#
////F#
type AddressContext =
| CustomerAddressContext of customer:Customer
| SiteAddressContext of site:Site
| ContactAddressContext of contact:Contact
with
member x.Id =
match x with
| CustomerAddressContext _ -> 1
@colinbull
colinbull / gist:6974405
Last active December 25, 2015 12:09
I know from this [link](http://cs.hubfs.net/topic/None/59380) that this is bad.... but how else can I achieve something similar.
//I can do the following to cast a given unit but this leads to an individual
//lift function for everyType
type [<Measure>] type megawatt
type [<Measure>] type therm
module Megawatt =
let inline liftFloat a = (float a) * 1.0<megawatt>
let inline liftInt a = (int a) * 1<megawatt>
//This gets dull quickly for lots of units of measure
@colinbull
colinbull / gist:5912890
Created July 2, 2013 20:39
Protobuf DU serialisation
#r "System.Xml.dll"
#r "System.Runtime.Serialization.dll"
#r @"D:\Appdev\fsharp.actor\packages\protobuf-net.2.0.0.640\lib\net40\protobuf-net.dll"
#load "Library1.fs"
open ProtoBuf
open System.IO
open System.Runtime.Serialization
open Protobuf
open Microsoft.FSharp.Reflection
@colinbull
colinbull / CancellableTaskBuilder
Created April 14, 2013 18:34
Simple CancellableTask builder
open System
open System.Threading
open System.Threading.Tasks
type CancelToken =
| Token of CancellationToken
| Default
with
static member Create(cts:CancellationTokenSource) =
Token(cts.Token)
@colinbull
colinbull / gist:2837354
Created May 30, 2012 16:16
polymor[hic decomposition
type IFoo =
abstract Do : unit -> unit
type Foo1() =
interface IFoo with
member x.Do() = ()
type Foo2() =
interface IFoo with
member x.Do() = ()
@colinbull
colinbull / gist:2481599
Created April 24, 2012 17:12
Find is a process is .NET
let processes = System.Diagnostics.Process.GetProcesses() |> Array.filter (fun p -> p.ProcessName.StartsWith("Raven")) |> Seq.head
let ofEnumerator (enum : System.Collections.IEnumerable) : seq<'a> =
let en = enum.GetEnumerator()
seq {
while en.MoveNext() do
yield en.Current :?> 'a
}
let isNet =