Skip to content

Instantly share code, notes, and snippets.

View michael-newton-15below's full-sized avatar

Michael Newton michael-newton-15below

View GitHub Profile
@michael-newton-15below
michael-newton-15below / Program.fs
Created October 4, 2012 09:03
Service stress testing with EasyNetQ and F#
// Learn more about F# at http://fsharp.net
open EasyNetQ
open EasyNetQ.Loggers
open FifteenBelow.WindowsServices.Messages
open FifteenBelow.WindowsServices
open FifteenBelow.Utilities.Configuration
open FifteenBelow.Configuration.AppConfig
let mutable logger = new ConsoleLogger()
logger.Debug <- false
let FizzBuzz i =
let rec inner i c =
printf "%d:\t" c
if c % 3 = 0 then printf "Fizz"
if c % 5 = 0 then printf "Buzz"
printfn ""
if c < i then c + 1 |> inner i else ()
inner i 1
let KarlFizzBuzz i =
@michael-newton-15below
michael-newton-15below / GrabNugets.fsx
Created November 20, 2012 15:07
Nuget.Core example
#r "Nuget.Core"
#r "System.Xml.Linq"
open NuGet
open System
open System.Linq
let repoFac = new PackageRepositoryFactory()
let repo = repoFac.CreateRepository("http://btn-tc01:8083")
let FiveFiveVersion = new SemanticVersion("5.5.0")
let packages = repo.FindPackages("Database.PASNGR", new VersionSpec(), false, false)
@michael-newton-15below
michael-newton-15below / NuGetStuff.fsx
Created November 23, 2012 16:19
Compiler error minimal case
#r "FAKE\Nuget.Core.dll"
#r "System.Xml.Linq"
#r "FAKE\FakeLib.dll"
new SemanticVersion("5.5.0.0")
@michael-newton-15below
michael-newton-15below / IErrorHandlerBuilder.fs
Created January 14, 2013 21:02
Error handler interface
open System
type IErrorHandlerBuilder =
abstract member Bind : Option<'T> * ('T -> Option<'U>) -> Option<'U>
abstract member Delay : (unit -> Option<'T>) -> Option<'T>
abstract member Return : 'T -> Option<'T>
abstract member ReturnFrom : Option<'T> -> Option<'T>
abstract member TryFinally : Option<'T> * (unit -> unit) -> Option<'T>
abstract member Using : 'T * ('T -> Option<'U>) -> Option<'U> when 'T :> IDisposable
abstract member Zero : unit -> Option<'T>
module FifteenBelow.MailWatcher.ErrorHandling.Audit
open ...
type AuditBuilder (auditClient : IAuditClient, log : ILog, config : IConfigurationManager) =
let app = config.ApplicationInformation
member this.Bind (expr, func) =
match expr with
| None -> None
| Some r ->
try func r
@michael-newton-15below
michael-newton-15below / TestErrorBuilder.fs
Created January 14, 2013 21:13
Test error handler builder
type TestErrorBuilder () =
member this.Bind (expr, func) =
match expr with
| None -> None
| Some r ->
try func r
with
| _ as e ->
printfn "%A" e
None
@michael-newton-15below
michael-newton-15below / ExampleService.fs
Created January 14, 2013 21:20
Error handler builder usage
open EasyNetQ
type IService =
abstract member Start : unit -> unit
type Service (log : ILog, bus : IBus, indexer : IIndex, audit : IErrorHandlerBuilder) =
member this.Start () =
bus.Subscribe<PasngrEmail>("Archive",
fun (email : PasngrEmail) ->
audit {
@michael-newton-15below
michael-newton-15below / Decompose.fs
Created January 16, 2013 20:00
Decomposing error handling computational expression without use
// Our builder
type TestErrorBuilder () =
member this.Bind (expr, func) =
match expr with
| None -> None
| Some r ->
try func r
with
| _ as e ->
printfn "%A" e
@michael-newton-15below
michael-newton-15below / DecomposeUse.fs
Last active December 11, 2015 05:09
Decompose error handling computation expression with use
// Our basic cexpr, fully sugared
let calculate input =
audit {
use! thing = Some input
return (possibleGoWrongThing thing)
}
// Rest of this might not be valid f# code at every step.
// Expanding using documentation at http://msdn.microsoft.com/en-us/library/dd233182.aspx