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 time f = | |
| let sw = System.Diagnostics.Stopwatch.StartNew() | |
| f () |> ignore | |
| printfn "Took %fs" sw.Elapsed.TotalMilliseconds | |
| time (fun () -> System.Threading.Thread.Sleep 1000) |
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
| [<JavaScript>] | |
| let lineTo (context : Cvs) x1 y1 x2 y2 = | |
| context.MoveTo (x1, y1) | |
| context.LineTo (x2, y2) | |
| [<JavaScript>] | |
| let horiz context y x1 x2 = lineTo context x1 y x2 y | |
| [<JavaScript>] | |
| let vert context x y1 y2 = lineTo context x y1 x y2 |
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 init settings = | |
| let getJewel a b = | |
| let rnd m = rand() * (float (settings.JewelTypes - m)) |> floor |> int | |
| let shift j jewl = if jewl >= j then jewl + 1 else jewl | |
| match a, b with | |
| | None, None -> rnd 0 | |
| | None, Some i | |
| | Some i, None -> rnd 1 |> shift i | |
| | Some i, Some j when i = j -> rnd 1 |> shift j | |
| | Some i, Some j -> rnd 2 |> shift (min i j) |> shift (max i j) |
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
| // bad way | |
| let formatOrder blah bleh clientName = | |
| let order = getOrder blah | |
| let message = getMessage bleh | |
| let reseult = | |
| if clientName = "boeing" then | |
| sprintf "<Order orderId=\"%d\"/>" order | |
| else | |
| sprintf "Order.orderId:%d" order | |
| 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
| type P<'t> = Parser<'t, unit> | |
| type Json = | |
| | JString of string | |
| | JNumber of float | |
| | JBool of bool | |
| | JNull | |
| | JList of Json list | |
| | JObject of Map<string, Json> |
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 szer = System.Runtime.Serialization.Formatters.Binary.BinaryFormatter() | |
| let inline serialize obj f = | |
| use str = System.IO.File.Create f | |
| szer.Serialize(str, obj) | |
| let inline deserialize f = | |
| use rdr = System.IO.File.OpenRead f | |
| szer.Deserialize rdr |> unbox |
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 filelist = pasvRead src_site resp | |
| let sitelist = deserialize "sites" | |
| sitelist |> Seq.filter (fun x -> x <> src_site) | |
| |> Seq.iter (fun x -> distribute src_site rls filelist x) |
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
| open System.Text.RegularExpressions | |
| System.IO.File.ReadAllText @"C:\Documents and Settings\dgrenier\Desktop\PrintInternalOrderDetail.pdf" | |
| |> (fun input -> Regex.Matches(input, @"(?s:Length (\d+).*?stream\r\n(.*?)\r\nendstream)")) | |
| |> Seq.cast<Match> | |
| |> Seq.map (fun m -> int m.Groups.[1].Value, m.Groups.[2].Value) |
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 next = | |
| let result = ref 0 | |
| let rnd = System.Random() | |
| let rec roll () = | |
| let old = !result | |
| let next = rnd.Next() | |
| if System.Threading.Interlocked.CompareExchange(result, next, old) = old then | |
| next | |
| else | |
| roll() |
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 OptionBuilder() = | |
| member this.Return x = Some x | |
| member this.Bind(x, f) = | |
| match x with | |
| | Some x -> f x | |
| | None -> None | |
| member this.ReturnFrom x = x | |
| let option = OptionBuilder() |