This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module IDocumentStoreExtensions | |
| open Raven.Client | |
| open System.Linq | |
| type IDocumentStore with | |
| member this.getAll<'a>() = | |
| let rec load results = | |
| use session = this.OpenSession() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module portFinder | |
| open System.Net | |
| open System.Net.Sockets | |
| let nextPort() = | |
| TcpListener(IPAddress.Loopback, 0) |> fun l -> | |
| l.Start() | |
| (l, (l.LocalEndpoint :?> IPEndPoint).Port) |> fun (l, p) -> | |
| l.Stop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module SitemapParser | |
| open FSharp.Data | |
| open System.IO | |
| open System.IO.Compression | |
| open System.Net.Http | |
| type SiteMapIndexProvider = XmlProvider< """<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>location</loc><lastmod>2000-01-01T00:00:00+00:00</lastmod></sitemap><sitemap><loc>location</loc><lastmod>2000-01-01T00:00:00+00:00</lastmod></sitemap></sitemapindex>""" > | |
| type SiteMapProvider = XmlProvider< """<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>location</loc><lastmod>2000-01-01T00:00:00+00:00</lastmod><changefreq>monthly</changefreq><priority>0.0</priority></url><url><loc>location</loc><lastmod>2000-01-01T00:00:00+00:00</lastmod><changefreq>monthly</changefreq><priority>0.0</priority></url></urlset>""" > |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| System.Net.Dns.GetHostName() |> System.Net.Dns.GetHostEntry |> fun x -> x.AddressList |> Seq.filter (fun x -> x.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork) |> Seq.map (fun x -> x.ToString()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Result = | |
| | Text of string | |
| | Number of int | |
| override self.ToString() = | |
| match self with | |
| | Text s -> s | |
| | Number i -> i.ToString() | |
| type Tree = | |
| | Branch of (int -> Result) * Tree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let (>>=) (i1, s1) k = | |
| let i2, s2 = k i1 | |
| (i2, sprintf "%s\r%s" s1 s2) | |
| let half i = | |
| let half = i / 2 | |
| (half, sprintf "half of %i is %i" i half) | |
| half 8 >>= half >>= half |> snd |> printfn "%s" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let logs = ["Awesome";"Win";"Mathematical";"Skill"] | |
| let (>>=) m k r = (m r, r) ||> k | |
| let add1 i (logs : string list) = | |
| let result = i + 1 | |
| logs.[result] |> printfn "%s" | |
| result | |
| let add2 i (logs : string list) = | |
| let result = i + 2 | |
| logs.[result] |> printfn "%s" | |
| result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let retry f = | |
| let rec innerRetry f i = | |
| try | |
| f() | |
| with | |
| | ex when i > 0 -> | |
| Syslog.Error ex | |
| Syslog.Info("Retry no {0}", (i - 5) * -1) | |
| Async.Sleep 1000 |> Async.RunSynchronously | |
| innerRetry f <| i - 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let asQueryString o = | |
| o.GetType().GetProperties() | |
| |> Array.map (fun p -> (p.Name, p.GetValue(o) |> string)) | |
| |> Array.map (fun (name, value) -> | |
| let m = Regex.Match(value, "Some\((?<value>.*?)\)") | |
| (name, if m.Groups.Count = 2 then m.Groups.["value"].Value else value)) | |
| |> Array.map (fun (name, value) -> sprintf "%s=%s" name value) | |
| |> String.concat "&" | |
| |> sprintf "?%s" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [<AutoOpen>] | |
| module TestFramework | |
| open NUnit.Framework | |
| let private assrt assertion actual expected = assertion(box expected, box actual, sprintf "Expected: %+A\rActual: %+A" expected actual) | |
| let (==) actual expected = assrt Assert.AreEqual actual expected | |
| let (!=) actual expected = assrt Assert.AreNotEqual actual expected | |
| type Test = TestAttribute |