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 / cracklib-from-fsharp.fs
Created September 23, 2019 14:52
Using cracklib from F#
open System
open System.Runtime.InteropServices
[<DllImport("libcrack.so.2", CallingConvention=CallingConvention.Cdecl)>]
extern nativeint FascistCheck(string pw, string dictPath)
[<EntryPoint>]
let main argv =
while true do
Console.WriteLine "Enter a potential password:"
@ninjarobot
ninjarobot / deploy.json
Created November 26, 2019 16:17
Azure Container with Managed Identity and Private Network
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vnetName": {
"type": "String",
"defaultValue": "priv-net"
},
"addressPrefix": {
"type": "String",
@ninjarobot
ninjarobot / azurts-fsadvent-post.md
Last active December 13, 2019 23:44
Azure Alerts to Slack with F# and azurts!

Azure Alerts to Slack with F#

If you have applications in Azure, there is a good chance you're making use of Azure Monitor with Application Insights or Log Analytics. These can provide useful diagnostic information, healthchecks, and alerting for VM's, serverless function apps, containers, and other services. The alerts can send email and call webhooks, but for the most flexibility, delivering them to an Azure Function allows for robust processing with custom F# code. With the azurts library, this can be used to filter alerts based on content and deliver them to different Slack channels.

Azure to Slack

Composing a Webhook

Azurts uses a "railway oriented programming" technique that is popular in several F# libraries to compose a series of ho

@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
@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 / 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 / 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 / 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 / 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 / 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