Skip to content

Instantly share code, notes, and snippets.

View ianrussellsoftwarepark's full-sized avatar

ianrussellsoftwarepark

View GitHub Profile
// Created in Linqpad
void Main()
{
// 'baaaa' = -1
// 'dog' = 8
// 'aabab' = 3 -> 'aa' + 'ba' + 'b'
// 'aabaa' = 0 -> 'aa' + 'baa'
// 'adoag' = 6 -> 'a' + 'd' + 'oa' + 'g'
calculate("baaaa").Dump();
calculate("dog").Dump();
@ianrussellsoftwarepark
ianrussellsoftwarepark / giraffe.fs
Last active June 20, 2021 12:59
Code for Giraffe 1 blog post
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.DependencyInjection
open Microsoft.AspNetCore.Http
open Giraffe
open Giraffe.ViewEngine
open FSharp.Control.Tasks
type PingModel = {
@ianrussellsoftwarepark
ianrussellsoftwarepark / ComputationExpressions.fs
Created August 8, 2020 14:47
Code for post 12 of Intro to FP in F# series
namespace ComputationExpression
module AsyncResultDemo =
open System
open FsToolkit.ErrorHandling
type AuthError =
| UserBannedOrSuspended
@ianrussellsoftwarepark
ianrussellsoftwarepark / ExampleUsage.fs
Last active October 28, 2020 00:11
Functional wrapper for HttpClient
let getResponse body (cookie: string option) (client:HttpClient) =
task {
return!
Http.createPostRequest Url
|> withBody (RequestBody.Xml body)
|> fun req ->
match cookie with
| Some c -> withCookie c req
| _ -> req
|> Http.execute client
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.DependencyInjection
open Microsoft.AspNetCore.Http
open Giraffe
open Giraffe.iewEngine
open FSharp.Control.Tasks
type PingModel = {
@ianrussellsoftwarepark
ianrussellsoftwarepark / Program.fs
Created March 12, 2021 14:03
Code for INTRODUCTION TO WEB PROGRAMMING IN F# WITH GIRAFFE - PART 2
open System
open System.IO
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.DependencyInjection
open Microsoft.AspNetCore.Http
open Giraffe
open Giraffe.ViewEngine
open FSharp.Control.Tasks
@ianrussellsoftwarepark
ianrussellsoftwarepark / Program.fs
Created March 12, 2021 14:52
Code for INTRODUCTION TO WEB PROGRAMMING IN F# WITH GIRAFFE - PART 3
open System
open System.IO
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.DependencyInjection
open Microsoft.AspNetCore.Http
open Giraffe
open Giraffe.ViewEngine
open FSharp.Control.Tasks
@ianrussellsoftwarepark
ianrussellsoftwarepark / result-composition.fsx
Last active March 7, 2024 10:46
Result composition from F# Essentials Lectures Session 5
type Customer = {
Id : int
IsVip : bool
Credit : decimal
}
type GetPurchasesError =
| HasOddId of int
type IncreaseCreditIfVipError =