Skip to content

Instantly share code, notes, and snippets.

@cloudRoutine
cloudRoutine / construct_toml_ap.fsx
Last active November 25, 2015 07:14
Active Pattern VS Match When
let construct_toml (toplevel:(string*Value)list,
tables:(string*(string*Value)list)[]) =
let addSection (table:Dictionary<string,Value>) (kvps:(string*Value) list) =
kvps |> List.iter (fun (k,v)-> table.Add( keyName k,v ))
let foldtoml (prev:string, nested:string list, acc:Dictionary<string,Value>,toml:Dictionary<string,Value>)
(cur:string, elems:(string*Value)list) =
try
(* add parsed elements to current table *)
@cloudRoutine
cloudRoutine / blitparser.fsx
Created November 22, 2015 15:44
Blit Parsing On Stack Allocated Array
open System.Reflection
open System.Reflection.Emit
open System.Runtime.InteropServices
open System
[<AutoOpen>]
module ByteUtils =
type Bit =
| One
@cloudRoutine
cloudRoutine / paracomp.fsx
Last active November 15, 2015 22:27
Heterogeneous Parallel Async Composition Operator
(*
Heterogeneous Parallel Async Composition Operator
- an evolution of http://jackfoxy.com/transparent-heterogeneous-parallel-async-with-fsharp/
*)
type 'T Parallel =
private {
Compute : obj Async []
Unpack : obj [] -> int -> 'T
}
@cloudRoutine
cloudRoutine / componentEvent.fsx
Created October 19, 2015 00:55
Components and Events
open System
type message = string
let logEvent = Event<message> ()
let logStream, post = logEvent.Publish, logEvent.Trigger
logStream.Add <| printf "%s | "
let dispose (d:#IDisposable) = d.Dispose()
[<System.Runtime.CompilerServices.Extension>]
type ExtensionMethods() =
[<System.Runtime.CompilerServices.Extension>]
static member inline GetOption< ^a,'k,'v when 'a : (member TryGetValue : 'k * ('v byref) -> bool)>(this : ^a, key : 'k) =
let mutable v = Unchecked.defaultof<'v>
let scc = ( ^a : (member TryGetValue : 'k * ('v byref) -> bool) this, key, &v)
if scc then
Some v
else
None
@cloudRoutine
cloudRoutine / boyer_moore.fsx
Created September 29, 2015 16:42
Boyer Moore Search Algorithm
// Boyer Moore String Search Algorithm
open System
open System.Collections
/// Returns the index of the given character in the English alphabet counting from 0
let alphabet_index (ch:char) =
let chlow = Char.ToLower( ch)
let charnum = Convert.ToInt32 chlow
charnum - 97 // 'a' is ASCII character 97
@cloudRoutine
cloudRoutine / fs-coreclr-build.md
Last active October 18, 2015 20:59
Build the Visual F# Compiler and Tools for .Net CoreCLR ( On Windows )

Make things easy for yourself and start by running posh as admin

If you already have dnvm installed remember to run update-self if you haven't recently

Clone and checkout the coreclr branch of Kevin Ransom's Fork of the Visual F# Compiler and Tools

Installing DNVM

You need DNVM as a starting point. DNVM enables you to acquire a (or multiple) .NET Execution Environment (DNX).

@cloudRoutine
cloudRoutine / msbuild-xaml.md
Last active July 24, 2017 21:10
MSBUILD XAML Reference
<?xml version="1.0" encoding="utf-8"?>
<Settings>
<Shortcuts>&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfKeyShortcut xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;KeyShortcut&gt;
&lt;Value&gt;EqualsPlus&lt;/Value&gt;
&lt;Alignment&gt;(^|[\w\s])(?&amp;lt;x&amp;gt;=)&lt;/Alignment&gt;
&lt;AlignFromCaret&gt;false&lt;/AlignFromCaret&gt;
&lt;UseRegex&gt;true&lt;/UseRegex&gt;
&lt;AddSpace&gt;true&lt;/AddSpace&gt;
@cloudRoutine
cloudRoutine / 01_folds.fs
Last active December 12, 2022 13:01
F# Transducers - they work for the most part
open System.Collections.Generic
open Microsoft.FSharp.Collections
[<RequireQualifiedAccess>]
module Folds =
// These are the fast implementations we actually want to use