This file contains 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
#if INTERACTIVE | |
#r "System.Xml.Linq.dll" | |
#else | |
module Rss | |
#endif | |
open System | |
open System.Xml.Linq | |
type NewsItem = { |
This file contains 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
#if INTERACTIVE | |
#r "System.Xml.dll" | |
#r "System.Xml.Linq.dll" | |
#endif | |
open System | |
open System.Net | |
open System.IO | |
open System.Xml.Linq |
This file contains 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 System.Security.Cryptography | |
open System.Text | |
open System.Diagnostics.Contracts | |
let EncryptStringWith (plain:string) (key:string) (iv:string) = | |
let enc = new ASCIIEncoding() | |
use encrypted = new MemoryStream() | |
use encode = new ToBase64Transform() |
This file contains 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.Net | |
open System.IO | |
let makePostRequest (url : string) (requestBody : string) = | |
let req = WebRequest.CreateHttp url | |
req.CookieContainer <- new CookieContainer() | |
req.Method <- "POST" | |
req.ProtocolVersion <- HttpVersion.Version10 | |
let postBytes = requestBody |> System.Text.Encoding.ASCII.GetBytes | |
req.ContentLength <- postBytes.LongLength |
This file contains 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
// 1) Create TransactionScope, on Mono and in .NET, and the later one supports TransactionScopeAsyncFlowOption. | |
// 2) Then, complete the transaction automatically if no exceptions has been thrown. | |
// If Async or Task, then automatically await the result before complete without blocking the thread. | |
#if INTERACTIVE | |
#r "System.Transactions.dll" | |
#endif | |
open System | |
open System.Threading | |
open System.Threading.Tasks |
This file contains 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 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 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 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 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" |