Skip to content

Instantly share code, notes, and snippets.

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"resources": [
{
"apiVersion": "2020-06-01",
"dependsOn": [
"[resourceId('Microsoft.Insights/components', 'safedeps-ai')]",
#r "nuget:Azure.Data.Tables,3.0.0-beta.5"
open System
open Azure.Data.Tables
[<AutoOpen>]
module Extensions =
open System.Reflection
type PKey() = inherit Attribute()
@isaacabraham
isaacabraham / net5sql.fsx
Last active January 20, 2021 20:36
Working with SQL is once again fun in F# scripts.
#r "nuget:microsoft.data.sqlclient"
open Microsoft.Data.SqlClient
let conn = new SqlConnection @"Server=(localdb)\ProjectsV13;Database=SampleDb;Integrated Security=True"
conn.Open()
#r "nuget:Dapper"
open Dapper
let anonRec = conn.Query<{| Id : int; Test : string |}> "SELECT Id, Test FROM dbo.[Table]"
let tupled = conn.Query<struct (int * string)> "SELECT Id, Test FROM dbo.[Table]"
/// An example union.
type Team = Tottenham | Spurs | THFC
module Lists =
open FSharp.Reflection
/// Creates an array of all cases of a given union 'T.
let makeAll<'T> =
FSharpType.GetUnionCases typeof<'T>
|> Array.map(fun info -> FSharpValue.MakeUnion(info, Array.empty) :?> 'T)
#r "nuget:WindowsAzure.Storage"
open Microsoft.WindowsAzure.Storage.Table
type Isaac = { Name : string; Age : int }
let typeCache = System.Collections.Generic.Dictionary()
let addToCache<'T>() =
let theType = typeof<'T>
open System
let rnd = Random ()
type Question = { Operator : string; A : int; B : int }
let createQuestions f operator = [
for a in 1 .. 12 do
for b in 1 .. 12 do
{ Operator = operator
#r "nuget:MBrace.Thespian"
open MBrace
open MBrace.Thespian
MBrace.Thespian.ThespianWorker.LocalExecutable <- "C:/Users/Isaac/.nuget/packages/mbrace.thespian/1.5.4/tools/mbrace.thespian.worker.exe"
let cluster = ThespianCluster.InitOnCurrentMachine(workerCount = 4)
(*
// Couple of interfaces
type IFoo = interface end
type IBar = interface end
// Some records that implement the interfaces
type FooImpl1 = { Name : string } interface IFoo
type FooImpl2 = { OtherName : string } interface IFoo
type BarImpl1 = { Age : int } interface IBar
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
open BenchmarkDotNet.Jobs
[<SimpleJob(RuntimeMoniker.CoreRt31); SimpleJob(RuntimeMoniker.CoreRt50)>]
type Benchmarks() =
[<Benchmark; Arguments 1000; Arguments 10000; Arguments 100000; Arguments 1000000>]
member _.MapCreate size =
let hs = [| for i in 1 .. size -> i, i |] |> Map
[| for i in 1 .. size -> hs.[i] |]
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"resources": [
{
"apiVersion": "2019-06-01",
"dependsOn": [],
"kind": "StorageV2",