Skip to content

Instantly share code, notes, and snippets.

View ninjarobot's full-sized avatar

Dave Curylo ninjarobot

  • Microsoft @Azure
  • Atlanta, GA
View GitHub Profile
@ninjarobot
ninjarobot / Fsharp.Async.Composition.fs
Created March 6, 2024 17:20
F# async composition
let sleepOnError fn =
async {
let! (res:Result<_,_>) = fn
return!
match res with
| Ok o -> async.Return (Ok o)
| Error e ->
async {
do! Async.Sleep 750
return Error e
@ninjarobot
ninjarobot / BasicIoC.fsx
Created May 2, 2022 17:49
Basic IoC using DI in F#
#r "nuget: Microsoft.Extensions.DependencyInjection"
#r "nuget: Microsoft.Extensions.Hosting"
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Hosting
type Foo = { Foo : string }
type Bar = { Bar : int }
type FooBar = Foo -> Bar
@ninjarobot
ninjarobot / tracing-intro-appinsights.md
Last active August 17, 2023 15:17
Correlated tracing in F# with Application Insights

Tracing with Application Insights

Application logging is ubiquitous and invaluable for troubleshooting. Structured logging enables you to log formatted messages and the data fields separately so that you can see the messages but also filter on the data fields. Tracing takes this a step further, where you can correlate many log entries together as you follow a trace of execution through an application. Traces also include additional information about the execution process, such as the sequence of calls to dependencies and how long any given call may take.

Application Insights lets you see all of this data correlated together in an application. You can search for an error log and then see in the execution flow that the log entry was added right after a failed call to another service. Or you can see that a certain web request is slower than others because it spends a lot of time on many redundant data access calls.

What about OpenTelemetry?

@ninjarobot
ninjarobot / Makefile
Last active September 6, 2022 05:49
Building nginx for macOS without homebrew
# default target so running 'make' by itself wll download and build nginx
build: nginx
cd nginx && ./configure --with-pcre=../pcre2 && make
nginx: pcre2
curl -O https://nginx.org/download/nginx-1.21.6.tar.gz
tar -xzvf nginx-*.tar.gz
mv nginx-*/ nginx
rm nginx-*.tar.gz
@ninjarobot
ninjarobot / ExecutionPlan1.fsx
Created April 16, 2022 17:29
Execution plan Computation Expressions
type Step =
| Action of string
| Branch of Step list list
type Plan =
{
Name : string
Steps : Step list
}
@ninjarobot
ninjarobot / ContainerApps-full-workflow.fsx
Last active December 19, 2021 19:23
Full workflow for Azure container apps with Farmer - build and push container, deploy to app.
#r "../../src/Farmer/bin/Debug/net5.0/Farmer.dll"
#r "nuget: FSharp.Text.Docker"
open System
open Farmer
open Farmer.ContainerApp
open Farmer.Builders
open FSharp.Text.Docker.Builders
// Create Container Registry
@ninjarobot
ninjarobot / install-azure-cli-macos.sh
Created November 20, 2021 13:34
Install the Azure CLI on macOS
set -eux
python3 -m venv $HOME/venvs/azure-cli
source venvs/azure-cli/bin/activate
pip install --upgrade pip
pip install azure-cli
deactivate
@ninjarobot
ninjarobot / multiple-locations.fsx
Created November 14, 2021 15:02
Example for deploying to multiple locations with Farmer
#r "nuget:Farmer"
open Farmer
open Farmer.Builders
// Sometimes resources aren't available in certain regions and another location needs to be chosen.
// The best way to do this is to create a nested resource group deployment to the _same_ resource
// group, and choose a different location for that nested deployment
arm {
@ninjarobot
ninjarobot / BuildIso.fsx
Created November 5, 2021 01:45
Builds autoinstall ISO for Ubuntu F# dev environment
#r "nuget: FsCloudInit"
#r "nuget: DiscUtils.Containers"
open System
open System.IO
open FsCloudInit
open FsCloudInit.Builders
open DiscUtils
open YamlDotNet.Serialization
@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 =