Skip to content

Instantly share code, notes, and snippets.

View dburriss's full-sized avatar

Devon Burriss dburriss

View GitHub Profile
@TheAngryByrd
TheAngryByrd / Main.fs
Last active February 20, 2024 04:58
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
()
@ninjarobot
ninjarobot / acr-workflow.fsx
Last active July 27, 2021 03:27
Deploys an Azure Container Registry, builds Docker image, pushes it there, hosts in ACI
#r "nuget: Farmer"
#r "nuget: FSharp.Text.Docker"
open System
open Farmer
open Farmer.Builders
open FSharp.Text.Docker.Dockerfile
// Create Container Registry
let myAcr =
(* QUEUES
https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.queue-1
*)
// 1.0 Basic queue - hand-rolled
let q = System.Collections.Generic.Queue<string>()
q.Enqueue "Hello"
@alfonsogarciacaro
alfonsogarciacaro / Deploy.md
Last active March 3, 2023 09:50
Deploying an F# ASP.NET Core app (Giraffe) to Azure

Deploying an F# ASP.NET Core app to Azure

Last week I spent a lot of time trying to deploy an F# ASP.NET Core app (a Giraffe app, specifically) to Azure because the information to complete all the steps was scattered in several places. So I'm writing this hopefully it will save the pain to others :)

Preparation

The following steps are mostly taken from this guide and it's only necessary to do them once:

  1. Create an account in Azure (or use an existing one)
  2. Create a resource group (or use an existing one)
@ninjarobot
ninjarobot / AzureFunctionSecret.fs
Created January 5, 2018 20:58
Example of retrieving a secret from an F# Azure Function App
namespace AzurefnSecret
open Microsoft.Azure.KeyVault
open Microsoft.IdentityModel.Clients.ActiveDirectory
module Example =
let getSecret (appKeyDescription:string) (appKeyValue:string) (secretUrl:string) =
async {
use keyVault = new KeyVaultClient(fun authority resource (_:string) ->
async {
@mrange
mrange / RResult.md
Created March 18, 2017 12:32
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:

@iamarcel
iamarcel / Creating Neat .NET Core Command Line Apps.md
Last active November 28, 2023 10:41
Creating Neat .NET Core Command Line Apps

Creating Neat .NET Core Command Line Apps

You can now read this on my (pretty) website! Check it out here.

Every reason to get more HackerPoints™ is a good one, so today we're going to write a neat command line app in .NET Core! The Common library has a really cool package Microsoft.Extensions.CommandlineUtils to help us parse command line arguments and structure our app, but sadly it's undocumented.

No more! In this guide, we'll explore the package and write a really neat

@jwosty
jwosty / StateBuilder.fsx
Created March 24, 2016 23:44
F# state monad / computation expression builder, and example usage
open System
open System.IO
type State<'s, 'a> = State of ('s -> ('a * 's))
module State =
let inline run state x = let (State(f)) = x in f state
let get = State(fun s -> s, s)
let put newState = State(fun _ -> (), newState)
let map f s = State(fun (state: 's) ->
@allykzam
allykzam / Errors.fs
Last active September 14, 2020 17:27
F# code for getting attribute data off discriminated union cases
type FatalError(message: string) =
inherit System.Attribute()
member __.Message = message
type Errors =
| [<FatalError("The value specified is currently not available")>] UnknownValue
| NotAnError
let PrintErrorMessage : Errors -> string =
fun err ->
@isaacabraham
isaacabraham / 1 - StorageQueueMailboxProcessor.fs
Last active August 15, 2020 09:36
Demonstrates how to use F# mailbox processors in conjunction with Azure Storage Queues.
/// Code to bind mailbox processors to azure storage queues.
module AzureMailboxProcessor
open System
module private Async =
let AwaitTaskEmpty = Async.AwaitIAsyncResult >> Async.Ignore
module private Option =
let fromNullable (nullable:Nullable<_>) = if nullable.HasValue then Some nullable.Value else None
let toNullable = function