Skip to content

Instantly share code, notes, and snippets.

Ronny Carlansson lessismore1

Block or report user

Report or block lessismore1

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:24e587eb2cd1fc5dc49695bcf228f843
open System
open System.Collections.Generic
open System.Net
open System.Net.Http
open System.Web.Http
open System.Web.Http.Dispatcher
open System.Web.Http.SelfHost
open Microsoft.VisualStudio.TestTools.UnitTesting
open Newtonsoft.Json.Linq
open Newtonsoft.Json.Serialization
lessismore1 / getMimeTypefromString
Created Feb 2, 2019 — forked from jmaciasportela/getMimeTypefromString
Get mimeType from file extension as string
View getMimeTypefromString
//Mime types. Some keys are duplicated.
lessismore1 / ApiModel.hs
Created Apr 2, 2018 — forked from ploeh/ApiModel.hs
Handling a reservation request in Haskell. Proof of concept
View ApiModel.hs
module ApiModel where
import Data.Time (ZonedTime(..), parseTimeM, defaultTimeLocale, iso8601DateFormat)
data ReservationRendition = ReservationRendition
{ rDate :: String
, rName :: String
, rEmail :: String
, rQuantity :: Int }
deriving (Eq, Show, Read)
lessismore1 /
Created Apr 1, 2018 — forked from mrange/
Railway Oriented Programming and F# Result

Railway Oriented Programming and F# Result

Full source:

Option<_> is great for ROP (Railway Oriented Programming) but we get no info on what went wrong (the failure value is None which carries no info).

With the introduction F# 4.1 we got Result<_, _> a "smarter" Option<_> as it allows us to pass a failure value.

However, when one inspects the signature of Result.bind one sees a potential issue for ROP:

lessismore1 / gist:169c41b8c4ff7ed0372b07adc496098d
Created Mar 30, 2018 — forked from theburningmonk/gist:3921623
F# - helper functions to Start and Wait for a plain Task (not Task<T>)
View gist:169c41b8c4ff7ed0372b07adc496098d
open System.Threading.Tasks
module Async =
let inline awaitPlainTask (task: Task) =
// rethrow exception from preceding task if it fauled
let continuation (t : Task) : unit =
match t.IsFaulted with
| true -> raise t.Exception
| arg -> ()
lessismore1 / gist:10d0005baa6cad4ff2873435df008c21
Created Mar 27, 2018 — forked from mausch/gist:3188428
Async exception handling in F#
View gist:10d0005baa6cad4ff2873435df008c21
open System
open System.Net
// exception handling in async using Async.Catch
let fetchAsync (name, url:string) =
async {
let uri = new System.Uri(url)
let webClient = new WebClient()
let! html = Async.Catch (webClient.AsyncDownloadString(uri))
match html with
lessismore1 / SendGridEmail
Created Mar 26, 2018 — forked from jamessdixon/SendGridEmail
Send Grid Email in F#
View SendGridEmail
#r "~/packages/Sendgrid.5.1.0/lib/SendGridMail.dll"
#r "~/packages/SendGrid.SmtpApi.1.2.1/lib/net40/SendGrid.SmtpApi.dll"
open System
open System.Collections.Generic
open System.Net
open System.Net.Mail
open SendGrid
View DU.fs
open Microsoft.FSharp.Reflection
let toString (x:'a) =
match FSharpValue.GetUnionFields(x, typeof<'a>) with
| case, _ -> case.Name
let fromString<'a> (s:string) =
match FSharpType.GetUnionCases typeof<'a> |> Array.filter (fun case -> case.Name = s) with
|[|case|] -> Some(FSharpValue.MakeUnion(case,[||]) :?> 'a)
|_ -> None
lessismore1 / FuncHelper.fs
Created Mar 24, 2018 — forked from chamook/FuncHelper.fs
Convert a C# Func or Action into an F# function
View FuncHelper.fs
open System.Runtime.CompilerServices
type public FSharpFuncUtil =
static member ToFSharpFunc<'a> (func:System.Func<'a>) = fun () -> func.Invoke()
static member ToFSharpFunc<'a,'b> (func:System.Converter<'a,'b>) = fun x -> func.Invoke(x)
View fsharp.records.default_values.fs
// Rather than use [<DefaultValue>], define a default record.
type MyRecord = {
field1 : int
field2 : int
let defaultRecord1 = { field1 = 0; field2 = 0 }
let defaultRecord2 = { field1 = 1; field2 = 25 }
// Use the with keyword to populate only a few chosen fields
You can’t perform that action at this time.