Skip to content

Instantly share code, notes, and snippets.

Isaac Abraham isaacabraham

Block or report user

Report or block isaacabraham

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View AsyncParallelStats.fsx
// Change this to your profile folder for nuget packages
#I @"C:\Users\Isaac\.nuget\packages\"
#r @"XPlot.GoogleCharts\2.0.0\lib\netstandard2.0\XPlot.GoogleCharts.dll"
#r @"Newtonsoft.Json\12.0.3\lib\netstandard2.0\Newtonsoft.Json.dll"
#r @"Google.DataTable.Net.Wrapper\4.0.0\lib\netstandard2.0\Google.DataTable.Net.Wrapper.dll"
open System
open XPlot.GoogleCharts
/// Executes an asynchronous workflow and provides some simple statistics on the results.
View Sequential.fsx
let x =
[| 1 .. 10 |]
|> Array.map(fun n -> async {
printfn "Starting %d" n
do! Async.Sleep 1000
printfn "Done %d" n
return n * 1000
})
let x2 = Async.Parallel(x, 1) |> Async.RunSynchronously
View AsyncExtensions.fs
module Async =
let Bind continuation wf = async {
let! wf = wf
return! continuation wf
}
let Map continuation = Bind (continuation >> async.Return)
// e.g.
let workflow = async { return 10 }
View fizzbuzz.fsx
let (|Mod|_|) div value =
if value % div = 0 then Some() else None
let fizzBuzz = function
| Mod 3 & Mod 5 -> "FizzBuzz"
| Mod 3 -> "Fizz"
| Mod 5 -> "Buzz"
| n -> string n
[ 1 .. 100 ]
@isaacabraham
isaacabraham / sample.json
Created Nov 22, 2019
Invalid ARM template for app service on linux
View sample.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"resources": [
{
"apiVersion": "2016-08-01",
"dependsOn": [
"mysuperwebappisaac-plan",
View timeout
Unhandled exception. System.AggregateException: One or more errors occurred. (Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.)
---> System.Data.SqlClient.SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
---> System.ComponentModel.Win32Exception (258): The wait operation timed out.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParserStateObject.ThrowExceptionAndWarning(Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParserStateOb
@isaacabraham
isaacabraham / matching.fsx
Last active Oct 14, 2019
Some examples of pattern matching with explicit options
View matching.fsx
type SurfaceOrientation = Rotation270 = 0 | Rotation180 = 1 | Rotation90 = 2 | Rotation0 = 3
type DisplayOrientation = Rotation270 | Rotation180 | Rotation90 | Rotation0 | Unknown
type Display = { Rotation : SurfaceOrientation }
let getDefaultDisplay() : Display option = failwith ""
let display = getDefaultDisplay()
// 1. Does not compile! Can't access Rotation directly as the display value is optional.
match display.Rotation with
| SurfaceOrientation.Rotation270 -> DisplayOrientation.Rotation270
@isaacabraham
isaacabraham / 1. types.fsx
Last active Aug 27, 2019
Example of an F# DSL designed for building ARM Templates
View 1. types.fsx
open ARM
let template =
{ Parameters = [
"environment"
"location"
"pricingTier"
]
Variables = [
"environment", "[toLower(parameters('environment'))]"
View recursive-data-structure.fsx
type FileElement =
| Folder of Name : string * Children : FileElement list
| File of {| Name:string; Size : decimal |}
let rec processFileElement element =
match element with
| File details ->
printfn "Oh look, a file called %s of size %MKB!" details.Name details.Size
| Folder (name, children) ->
printfn "I'm entering %s. It has %d direct children." name children.Length
You can’t perform that action at this time.