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: CsvHelper" | |
open System | |
open CsvHelper | |
type Transaction = { Amount: float; Date: DateOnly; Description: string } | |
let readTransactions() : Transaction list = [ | |
use reader = new IO.StringReader(""" | |
Account Number,Posted Date,Check,Description,Debit,Credit |
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 | |
open Microsoft.AspNetCore.Builder | |
open Microsoft.Extensions.Hosting | |
open Microsoft.Extensions.DependencyInjection | |
open Microsoft.FSharp.Core | |
open Microsoft.OpenApi.Models | |
open Swashbuckle.AspNetCore.SwaggerGen | |
type Child = { Text: string } | |
type Parent = { Child: Child option } |
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: System.Data.SQLite" | |
#r "nuget: Dapper" | |
open System | |
open Dapper | |
open System.Data | |
open System.Data.SQLite | |
[<CLIMutable>] // This creates private setters for Dapper to work with, but your F# code cannot | |
type Person = { Id: int; First: string; Last: string } |
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
// SRTP: Statically Resolved Type Parameters | |
// https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/generics/statically-resolved-type-parameters | |
// SRTP Allows for pulling members out of types that where the member is named and typed the same | |
// In this example SRTP will be used to pull out the 'First: string' and 'Last: string' members | |
// from different types | |
// One example of SRTP in the F# Base Class Library is the (+) operator. | |
// You'll see that it has this type signature: |
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:FSharp.Data" | |
open System.IO | |
open System.Text | |
open FSharp.Data | |
type Csv = CsvProvider<"A,B,C\n1,2,3", CacheRows=false> | |
let csvStream = | |
let stream = new MemoryStream() |
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
git init | |
git checkout -b original | |
git commit --allow-empty -m 'Commit 1' | |
git commit --allow-empty -m 'Commit 2' | |
git commit --allow-empty -m 'Commit 3 (third)' | |
git tag third | |
git commit --allow-empty -m 'Commit 4' | |
git commit --allow-empty -m 'Commit 5' | |
git tag fifth | |
git commit --allow-empty -m 'Commit 6 (sixth)' |
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
// Dummy functions to simulate a function that return a result | |
let getNumber expected resultNumber number = | |
if number = expected then | |
Ok resultNumber | |
else | |
Error (sprintf $"Expected {expected} but got {number}") | |
let getOne = getNumber 0 1 | |
let getTwo = getNumber 1 2 | |
let getThree = getNumber 2 3 |
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
git init SomeRepo #creates a folder in your current directory called 'SomeRepo' | |
pushd SomeRepo | |
git commit -m 'EMPTY' --allow-empty #branching doesn't work without a commit in the repo | |
git branch regular-branch | |
git worktree add -b worktree-branch '../SomeRepo#worktree-branch' #folder name example, without -b {BranchName} will create a branch with the name of the directory specified | |
git branch --list | |
popd | |
ls | select -exp Name | |
<# |
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 Result = Accepted | Rejected | |
interface Accepted { | |
status: "Accepted" | |
text: string | |
} | |
interface Rejected { | |
status: "Rejected" | |
} |
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
function toDateString(date) { | |
const year = date.getFullYear(); | |
const month = date.getMonth() + 1; | |
const day = date.getDate(); | |
return `${year}-${month.toString().padStart(2,'0')}-${day.toString().padStart(2,'0')}`; | |
} |
NewerOlder