Skip to content

Instantly share code, notes, and snippets.

View TheAngryByrd's full-sized avatar
🐦
😠 🐦

Jimmy Byrd TheAngryByrd

🐦
😠 🐦
View GitHub Profile
@TheAngryByrd
TheAngryByrd / program.fs
Last active April 14, 2022 04:29
F# MapGet helper
open System
open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.Hosting
open Microsoft.AspNetCore.Http
open System.Threading.Tasks
let mapGet (pattern : string) handler (app : WebApplication) =
app.MapGet(pattern, (Func<_>(handler))) |> ignore
let mapGetAsync (pattern : string) (handler : HttpContext -> Task) (app : WebApplication) =
@TheAngryByrd
TheAngryByrd / FSharpPlus.Then.fs
Last active March 28, 2022 14:36
FSharpPlus Then
type Default1 = class end
type Then =
inherit Default1
static member inline Then ((x: Result<_,'E> , f: 'T->Result<'U,'E>), _mthd: Then) = Result.bind f x
static member inline Then ((x: option<_> , f: 'T->Option<'U>), _mthd: Then) = Option.bind f x
static member inline Invoke (mapping: 'T->'U) (source: '``Thenable<'T>``) : '``Thenable<'U>`` =
let inline call (mthd: ^M, source: ^I, _output: ^R) = ((^M or ^I or ^R) : (static member Then : (_*_)*_ -> _) (source, mapping), mthd)
call (Unchecked.defaultof<Then>, source, Unchecked.defaultof<'``Thenable<'U>``>)
@TheAngryByrd
TheAngryByrd / OptionExtensions.fs
Created February 22, 2022 16:59
F# Option.Then
module Option =
let inline bind ([<InlineIfLambda>] binder) value =
match value with
| Some x -> binder x
| None -> None
let inline map ([<InlineIfLambda>] mapper) value =
match value with
| Some x -> Some(mapper x)
| None -> None
@TheAngryByrd
TheAngryByrd / GiraffeAsyncComposer.fs
Last active January 16, 2023 16:11
F# Giraffe Compose Async SRTP
open System
open Giraffe
open Microsoft.AspNetCore.Http
open System.Threading
open System.Threading.Tasks
module HttpHandlerHelpers=
/// Converts an Async HttpHandler to a normal Giraffe Task based HttpHandler
let inline convertAsyncToTask (asyncHandler : HttpFunc -> HttpContext -> Async<HttpContext option>) (next : HttpFunc) (ctx : HttpContext) : HttpFuncResult =
@TheAngryByrd
TheAngryByrd / Main.fs
Last active May 14, 2025 06:08
F# Main Async
module Main =
open System
open System.Threading
let inline tryCancel (cts : CancellationTokenSource) =
try
cts.Cancel()
with :? ObjectDisposedException as e ->
// if CTS is disposed we're probably exiting cleanly
()
@TheAngryByrd
TheAngryByrd / dotnet-oss-documentation-tools.md
Created October 31, 2021 19:55
.NET OSS documentation tools

.NET OSS Documentation tools

Criteria

  • What dependencies does it require? (npm, netfx, dotnet-core)
  • Does it seem to be maintained?
  • Does it have a good update story?
  • How easy is it to get started? (good tutorial, templating)
  • Can I change the structure easily to fit the divio structure?
  • Does it support search? Is the search useful?
@TheAngryByrd
TheAngryByrd / AsyncToTaskHelpers.fs
Created October 27, 2021 19:17
AsyncToTaskHelpers
type AsyncBuilder with
member inline __.Bind(t : Task<'a>, cont) = async.Bind(t |> Async.AwaitTask, cont)
member inline __.Bind(t : Task, cont) = async.Bind(t |> Async.AwaitTask, cont)
member inline __.ReturnFrom(t : Task<'a>) = async.ReturnFrom(t |> Async.AwaitTask)
member inline __.ReturnFrom(t : Task) = async.ReturnFrom(t |> Async.AwaitTask)
member inline __.Bind(t : ValueTask<'a>, cont) = async.Bind(t.AsTask() |> Async.AwaitTask, cont)
member inline __.Bind(t : ValueTask, cont) = async.Bind(t.AsTask() |> Async.AwaitTask, cont)
member inline __.ReturnFrom(t : ValueTask<'a>) = async.ReturnFrom(t.AsTask() |> Async.AwaitTask)
member inline __.ReturnFrom(t : ValueTask) = async.ReturnFrom(t.AsTask() |> Async.AwaitTask)
@TheAngryByrd
TheAngryByrd / Expecto.TestContext.fs
Created September 20, 2021 14:54
Expecto Test Context
//based on https://github.com/haf/expecto/blob/main/Expecto/Expecto.fs#L116-L118
/// allows you to build a context for tests given name
let inline testContext (contextBuilder : string -> 'a) (testList: seq<string * ('a -> unit)>) =
Seq.map (fun (name, partialTest) ->
testCase name (fun () -> contextBuilder name |> partialTest)) testList
// Build some context based on the name of the test
@TheAngryByrd
TheAngryByrd / run-until-success.sh
Created May 28, 2021 21:12
Bash run until success
while [ $? -ne 0 ]; do !!; done
@TheAngryByrd
TheAngryByrd / dotnet-dag.sh
Created April 7, 2021 15:12
Create dotgraph from dotnet projects
#!/bin/bash
for i in `find . -type f -iname "*.fsproj"`; do
# get only filename
project=`basename $i`
# remove fsproj extension
project=${project%.fsproj}
references=`cat $i | grep '<ProjectReference' | cut -d "\"" -f 2`