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 | |
open System.Collections.Concurrent | |
let cache = ConcurrentDictionary<(string * obj),Lazy<obj>>() | |
let cacheTimes = ConcurrentDictionary<string,DateTime>() | |
let cacheTimeSeconds = 30. | |
let memoizeConcurrent (caller:string) (f: ('a -> 'b)) = fun x -> | |
match cacheTimes.TryGetValue caller with | |
| true, time when time < DateTime.UtcNow.AddSeconds(-cacheTimeSeconds) | |
-> cache.TryRemove((caller, x|>box)) |> ignore | |
| _ -> () |
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 | |
let ``calculate distance`` (p1Latitude,p1Longitude) (p2Latitude,p2Longitude) = | |
let r = 6371.0; // km | |
let dLat = (p2Latitude - p1Latitude) * Math.PI / 180.0 | |
let dLon = (p2Longitude - p1Longitude) * Math.PI / 180.0 | |
let lat1 = p1Latitude * Math.PI / 180.0 | |
let lat2 = p2Latitude * Math.PI / 180.0 | |
let a = Math.Sin(dLat/2.0) * Math.Sin(dLat/2.0) + |
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; | |
open System.Net; | |
open System.Net.NetworkInformation; | |
let GetLocalIpv4Address() = | |
let interfaces = NetworkInterface.GetAllNetworkInterfaces() | |
let unicastAddresses = | |
interfaces |> Seq.map (fun i -> i.GetIPProperties().UnicastAddresses) |> Seq.concat |> Seq.toList | |
let item = | |
unicastAddresses |> Seq.find (fun a -> a.IPv4Mask.ToString() <> "0.0.0.0" && a.IPv4Mask.ToString() <> "255.0.0.0") |
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 phpMd5 (dataToHash:string) = | |
use md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); | |
let encodedBytes = dataToHash |> System.Text.ASCIIEncoding.Default.GetBytes |> md5.ComputeHash | |
System.Text.RegularExpressions.Regex.Replace(System.BitConverter.ToString(encodedBytes), "-", "").ToLower() |
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
// Nuget packages: Owin, Microsoft.Owin, Microsoft.Owin.Hosting, Microsoft.Owin.Host.HttpListener, Owin.Compression, Microsoft.Owin.StaticFiles, Microsoft.Owin.FileSystems | |
#if INTERACTIVE | |
#I @"./packages/Owin/lib/net40" | |
#I @"./packages/Owin.Compression/lib/net45" | |
#I @"./packages/Microsoft.Owin/lib/net45" | |
#I @"./packages/Microsoft.Owin.Hosting/lib/net45" | |
#I @"./packages/Microsoft.Owin.Host.HttpListener/lib/net45" | |
#I @"./packages/Microsoft.Owin.StaticFiles/lib/net45" | |
#I @"./packages/Microsoft.Owin.FileSystems/lib/net45" |
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
/// <reference path="./../../paket-files/borisyankov/DefinitelyTyped/google.analytics/ga.d.ts" /> | |
export var gaNewElem : any = {}; | |
export var gaElems : any = {}; | |
function gaInit(){ | |
var currdate : any = new Date(); | |
/* tslint:disable:no-string-literal */ | |
/* tslint:disable:semicolon */ |
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 | |
open System.IO | |
open Logary | |
open Logary.Configuration | |
open Logary.Targets | |
open Logary.Metrics | |
#if INTERACTIVE | |
#else | |
[<EntryPoint>] |
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 Microsoft.FSharp.Linq.RuntimeHelpers | |
open System | |
open System.Linq.Expressions | |
module Lambda = | |
let toExpression (``f# lambda`` : Quotations.Expr<'a>) = | |
``f# lambda`` | |
|> LeafExpressionConverter.QuotationToExpression | |
|> unbox<Expression<'a>> |
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 Memoize | |
//More generic variant of http://www.fssnip.net/c4 | |
open System.Collections.Concurrent | |
let cache = ConcurrentDictionary<(string * obj) option,Lazy<obj>>() | |
let memoizeConcurrent (caller:string) (f: ('a -> 'b)) = | |
fun (x :'a) -> | |
(cache.GetOrAdd(Some (caller, x|>box), lazy ((f x)|>box)).Force() |> unbox) : 'b |
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
// In MONO, won't work in interactive, you need to make a project and compile a dll. | |
#if INTERACTIVE | |
#r @"./packages/FSharp.Data/lib/net40/FSharp.Data.dll" | |
#r @"./packages/SQLProvider/lib/net40/FSharp.Data.SqlProvider.dll" | |
// OWIN and SignalR-packages: | |
#I @"./packages/Microsoft.AspNet.SignalR.Core/lib/net45" | |
#r @"./packages/Microsoft.AspNet.SignalR.Core/lib/net45/Microsoft.AspNet.SignalR.Core.dll" | |
#I @"./packages/Microsoft.Owin/lib/net45" |