Skip to content

Instantly share code, notes, and snippets.

@cloudRoutine
cloudRoutine / github-downloader.fsx
Created August 5, 2016 06:31
Download Github release files even from behind a proxy
open System
open System.IO
open System.Web
open System.Net
open System.Collections.Generic
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
@cloudRoutine
cloudRoutine / RoughMetrics.fsx
Last active July 20, 2016 12:10
Since Visual Studio won't calculate code metrics for F# projects, this script will calculate some some rough stats.
open System
open System.IO
let find_files dir = Directory.GetFiles( dir, "*.fs?", SearchOption.AllDirectories )
let not_start (s:string) p = not <| s.StartsWith p
let has_type (s:string) = if s.Contains @"type" then 1 else 0
let has_module (s:string) = if s.Contains @"module" then 1 else 0
let has_binding (s:string) = if s.Contains @"let" ||
s.Contains @"member" then 1 else 0
open System.Diagnostics
open System.Reflection
open Microsoft.FSharp.Core
open Microsoft.FSharp.Core.Operators
open Microsoft.FSharp.Core.LanguagePrimitives
open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
open Microsoft.FSharp.Collections
open Microsoft.FSharp.Primitives.Basics
open System.Collections.Generic
@cloudRoutine
cloudRoutine / foldparser.fsx
Created March 9, 2016 08:18
Parser that folds over stream with a state record
#r "../../../packages/fparsec/lib/net40-client/fparseccs.dll"
#r "../../../packages/fparsec/lib/net40-client/fparsec.dll"
open System
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
open FParsec
open FParsec.Primitives
let (^) = (<|)
@cloudRoutine
cloudRoutine / getUnionFields.fsx
Created March 6, 2016 07:13
netcore compatible `GetUnionFields`
open System
open System.Reflection
type CLIArguments =
| Working_Directory of string
| Listener of host:string * port:int
| Data of byte []
| Port of int
| Log_Level of int
| Detach
@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 / fscheck_doc_old.fsx
Created December 14, 2014 17:04
Old FsCheck Documentation (v 0.6)
(*===============================
|| ||
|| QuickStart ||
|| ||
===============================*)
// A simple example of a property definition is
let prop_RevRev xs = List.rev(List.rev xs) = xs
@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()