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 / home-grown-farmer-resource.fsx
Created June 30, 2021 04:08
Create a minimal ARM resource to use with Farmer template generation.
#r "nuget: Farmer"
open Farmer
// Give it a resource type. This is helpful the resource and handling dependencies.
let rightClickDeployments = ResourceType ("Microsoft.Hi/rightClickDeployments", "2021-06-29")
// Define the resource itself.
let minimalResource =
{ new IArmResource with
@ninjarobot
ninjarobot / farmer-global-app.fsx
Last active June 18, 2021 03:37
Farmer application with multiple resource groups and traffic manager
#r "nuget: Farmer, 1.6.0"
open Farmer
open Farmer.Builders
open Farmer.Builders.ContainerGroups
open Farmer.Builders.TrafficManager
open Farmer.TrafficManager
let msi = userAssignedIdentity {
name "my-app"
@ninjarobot
ninjarobot / du-with-partial-active-pattern.fs
Last active April 8, 2021 20:08
Using partial active patterns to return calculated data in pattern matches
/// Several types of consoles
type Console =
| Playstation_5
| Xbox_Series_X
| Switch
with
member this.Name =
match this with
| Playstation_5 -> "Playstation 5"
| Xbox_Series_X -> "XBox Series X"
@ninjarobot
ninjarobot / JsonConfigSource.fs
Created January 20, 2021 23:52
Load a configuration source from a JSON string in F#
open Microsoft.Extensions.Configuration
/// Builds a configuration source from raw JSON.
let configSourceFromJson (json:string) : IConfigurationSource =
{ new IConfigurationSource with
member this.Build (builder:IConfigurationBuilder) =
{ new ConfigurationProvider() with
member this.Load() =
this.Data <- Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string,string>> json
} :> IConfigurationProvider
@ninjarobot
ninjarobot / minecraftServerDeployment.fsx
Created January 5, 2021 17:02
Generates an ARM deployment template for creating a Minecraft Server running on Azure container instances
#r "nuget: Farmer"
#r "nuget: MinecraftConfig"
#r "nuget: FSharp.Data"
open System
open Farmer
open Farmer.Builders
open FSharp.Data
open MinecraftConfig
@ninjarobot
ninjarobot / wcfclient.fs
Created December 5, 2020 02:08
Using WCF in dotnet without a trusted certificate
let binding = CustomBinding ()
let textMessageEncoding = TextMessageEncodingBindingElement ()
textMessageEncoding.MessageVersion <- MessageVersion.Soap11
let transport = HttpsTransportBindingElement (RequireClientCertificate=false, AllowCookies=true, MaxReceivedMessageSize=int64(Int32.MaxValue))
binding.Elements.Add textMessageEncoding
binding.Elements.Add transport
@ninjarobot
ninjarobot / etcdDeployment.fsx
Created November 22, 2020 13:48
Deploying etcd on Azure with Farmer
open System
open Farmer
open Farmer.Builders
let deploymentLocation = Location.EastUS
let etcdDataStorage = storageAccount {
name "etcddata"
add_file_share_with_quota "data" 5<Gb>
}
@ninjarobot
ninjarobot / ACI_in_VNet_with_MSI.json
Last active October 13, 2020 14:03
Creating an Azure container instance in a vnet using managed identity
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"resources": [
{
"apiVersion": "2018-11-30",
"dependsOn": [],
"location": "eastus",
@ninjarobot
ninjarobot / deployment_cleanup.sh
Created February 28, 2020 20:55
Cleanup ARM deployments
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "Usage: deployment-cleanup.sh <subscription_id> <resource_group>"
exit 1
fi
az group deployment list --subscription $1 -g $2 --query '[].{name:name,ts:properties.timestamp}[*].name' -o tsv | tail -n +100 | xargs -n1 az group deployment delete --subscription $1 -g $2 -n
@ninjarobot
ninjarobot / DivisionBySubtraction.fs
Created January 13, 2020 21:00
Division by subtraction example in F#
type DivisionProblem =
{
Dividend : int
Divisor : int
}
type DivisionSolution =
{
Quotient : int
Remainder : int
Divisor : int