This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- DROP TABLE Customer | |
-- EXEC sys.sp_cdc_disable_db | |
--https://learn.microsoft.com/en-us/sql/relational-databases/track-changes/enable-and-disable-change-data-capture-sql-server?view=sql-server-ver16 | |
CREATE TAble Customer ( | |
CustomerId INT, | |
Name VARCHAR(100), | |
CONSTRAINT PK_Customer PRIMARY KEY (CustomerId) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "nuget:FSharpPlus" | |
open FSharpPlus | |
type Transaction<'T> = |Transaction of (unit -> 'T) | |
with | |
static member Return (x: 'T) : Transaction<'T> = Transaction.Transaction (fun () -> x) | |
static member (>>=) (x: Transaction<'T>, f: 'T -> Transaction<'U>) : Transaction<'U> = | |
match x with Transaction.Transaction fn -> fn () |> f | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Program | |
open System.Threading | |
let delayInMs = 1000 | |
let doAsync nSlow = | |
[ for i = 0 to nSlow - 1 do yield Async.Sleep delayInMs ] | |
|> Async.Parallel | |
|> Async.RunSynchronously |> ignore<unit array> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a = | |
if true | |
then | |
1 | |
else | |
2 | |
|> (fun x -> sprintf "%i" x) | |
let (|>>) a b = a b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "nuget:Fenix.Dry" | |
module Translate = | |
open Fenix.Dry.Http | |
open Fenix.Dry.Http.HttpResponse | |
let translate q = | |
let body = | |
System.Text.Json.JsonSerializer.Serialize({| text = [|q|]; target_lang = "EN-US"; source_lang = "NB" |}) | |
let resp = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Skapa griden, det är en tabell med sträng 1 på x och sträng 2 på y | |
let longest_common_substring (word_a:string) (word_b:string) = | |
let cell = Array.init word_a.Length (fun _ -> Array.init word_b.Length (fun _ -> 0)) | |
for i = 0 to word_a.Length - 1 do | |
for j = 0 to word_b.Length - 1 do | |
if word_a[i] = word_b[j] then | |
if i > 0 && j > 0 then | |
cell[i][j] <- cell[i-1][j-1] + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
let inline middle a b = min a b + (abs (a - b) / (LanguagePrimitives.GenericOne + LanguagePrimitives.GenericOne)) | |
type Point = { x:int; y:int } | |
module Point = | |
let create x y ={ x = x; y = y } | |
let middle p1 p2 = create (middle p1.x p2.x) (middle p1.y p2.y) | |
let a = 2.0**2.0 | |
let pow n p = System.Math.Pow(n, p) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let private mapRequest (context : Microsoft.AspNetCore.Http.HttpContext) : Svea.Dry.Http.HttpRequest = | |
if context.Request.HasFormContentType then | |
let newStream : System.IO.Stream = | |
let ms = new System.IO.MemoryStream() | |
use sw = new System.IO.StreamWriter(ms, System.Text.Encoding.UTF8, 4096, true) | |
let mutable isFirst = true | |
for item in context.Request.Form do | |
sw.Write(sprintf "%s=%s" (System.Web.HttpUtility.UrlEncode(item.Key)) (item.Value |> Seq.map (fun x -> System.Web.HttpUtility.UrlEncode(x)) |> String.concat ",")) | |
if isFirst then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//LibA.dll 1.0 | |
module LibA = | |
let helloWorld name = sprintf "Hello there %s" name | |
//LibB.dll | |
module LibB = | |
let helloThere name = sprintf "(Through LibB) %s" (LibA.helloWorld name) | |
//App | |
LibB.helloThere "Micke" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Transaction<'a> = string -> 'a | |
module Transaction = | |
let map<'a,'b> (mapper:'a -> 'b) (t:Transaction<'a>) : Transaction<'b> = | |
(fun x -> mapper (t x)) | |
let bind<'a,'b> (binder:'a -> Transaction<'b>) (t:Transaction<'a>) : Transaction<'b> = | |
(fun x -> binder (t x) x) | |
let execute connectionString (t:Transaction<'a>) = | |
t ConnectionString | |
type SqlReader<'state, 'element> = |
NewerOlder