Skip to content

Instantly share code, notes, and snippets.

@lessismore1
lessismore1 / .gitlab-ci.yml
Created February 21, 2022 21:52 — forked from t3easy/.gitlab-ci.yml
Build and deploy docker containers with GitLab CI
image: an-image-with-docker-and-docker-compose
variables:
DOCKER_TLS_VERIFY: "1"
DOCKER_CERT_PATH: ".docker"
before_script:
- mkdir -p $DOCKER_CERT_PATH
- echo "$DOCKER_CA" > $DOCKER_CERT_PATH/ca.pem
- echo "$DOCKER_CERT" > $DOCKER_CERT_PATH/cert.pem
@lessismore1
lessismore1 / gist:24e587eb2cd1fc5dc49695bcf228f843
Created February 17, 2019 03:49 — forked from nakamura-to/gist:4316660
ASP.NET Web API Test in F#
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
lessismore1 / getMimeTypefromString
Created February 2, 2019 15:24
Get mimeType from file extension as string
//Mime types. Some keys are duplicated.
array(
".3dm"=>"x-world/x-3dmf",
".3dmf"=>"x-world/x-3dmf",
".a"=>"application/octet-stream",
".aab"=>"application/x-authorware-bin",
".aam"=>"application/x-authorware-map",
".aas"=>"application/x-authorware-seg",
".abc"=>"text/vnd.abc",
@lessismore1
lessismore1 / ApiModel.hs
Created April 2, 2018 10:07 — forked from ploeh/ApiModel.hs
Handling a reservation request in Haskell. Proof of concept
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
lessismore1 / RResult.md
Created April 1, 2018 22:08 — forked from mrange/RResult.md
Railway Oriented Programming and F# Result

Railway Oriented Programming and F# Result

Full source: https://gist.github.com/mrange/aa9e0898492b6d384dd839bc4a2f96a1

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
lessismore1 / gist:169c41b8c4ff7ed0372b07adc496098d
Created March 30, 2018 07:08 — forked from theburningmonk/gist:3921623
F# - helper functions to Start and Wait for a plain Task (not Task<T>)
open System.Threading.Tasks
[<AutoOpen>]
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
lessismore1 / gist:10d0005baa6cad4ff2873435df008c21
Created March 27, 2018 06:23 — forked from mausch/gist:3188428
Async exception handling in F#
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
lessismore1 / SendGridEmail
Created March 26, 2018 18:15 — forked from jamessdixon/SendGridEmail
Send Grid Email in F#
#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
@lessismore1
lessismore1 / FuncHelper.fs
Created March 24, 2018 10:47 — forked from chamook/FuncHelper.fs
Convert a C# Func or Action into an F# function
open System.Runtime.CompilerServices
[<Extension>]
type public FSharpFuncUtil =
[<Extension>]
static member ToFSharpFunc<'a> (func:System.Func<'a>) = fun () -> func.Invoke()
[<Extension>]
static member ToFSharpFunc<'a,'b> (func:System.Converter<'a,'b>) = fun x -> func.Invoke(x)
// 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