Skip to content

Instantly share code, notes, and snippets.

Avatar
🦎

Amin Khansari akhansari

🦎
View GitHub Profile
@akhansari
akhansari / EsBankAccount.cs
Last active Jul 27, 2022
C# prototype of Decider pattern. F# version: https://github.com/akhansari/EsBankAccount
View EsBankAccount.cs
namespace EsBankAccount.Account;
using Events = IReadOnlyCollection<IEvent>;
public record Transaction(decimal Amount, DateTime Date);
// events
public interface IEvent { } // used to mimic a discriminated union
public record Deposited(Transaction Transaction) : IEvent;
public record Withdrawn(Transaction Transaction) : IEvent;
View BowlingKata.fsx
type Pins = int
let [<Literal>] MaxPins : Pins = 10
type Frame =
| Strike of Pins
| Spare of Pins * Pins
| Open of Pins * Pins
| Pending of Pins
| Final of Pins * Pins option * Pins option
@akhansari
akhansari / .gitconfig
Last active Jun 7, 2022
Multiple Git Configs
View .gitconfig
[core]
excludesFile = ~/.gitignore
[user]
name = My Name
[includeIf "gitdir:~/git/"]
path = ~/.gitconfig-work
[includeIf "gitdir:~/github/"]
path = ~/.gitconfig-home
@akhansari
akhansari / AsyncSeq.fs
Last active Mar 3, 2022
F#: IEnumerable to IAsyncEnumerable
View AsyncSeq.fs
module AsyncSeq =
open System.Collections.Generic
open System.Threading.Tasks
let cancelled (cancellationToken: CancellationToken) =
Task.FromCanceled<bool> cancellationToken
|> ValueTask<bool>
let ofSeq (sq: Task<'T> seq) = {
new IAsyncEnumerable<'T> with
@akhansari
akhansari / async_vs_task_1.fs
Last active Nov 12, 2021
F# 6: Async VS Task
View async_vs_task_1.fs
(*
| Method | Mean | Error | StdDev | Allocated |
|------- |--------:|--------:|--------:|----------:|
| Task | 15.99 s | 0.107 s | 0.095 s | 314 KB |
| Async | 16.02 s | 0.089 s | 0.079 s | 990 KB |
*)
open System.Threading.Tasks
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
@akhansari
akhansari / useful-tools.md
Last active Dec 21, 2021
My Useful Tools
View useful-tools.md

Scoop

  • firacode
  • windows-terminal
  • starship
  • gopass
  • pass-winmenu-nogpg
  • micro
  • nodejs
  • jq
@akhansari
akhansari / ConsulKv.fs
Last active Aug 18, 2021
Simple Consul KV client in F#
View ConsulKv.fs
[<AutoOpen>]
module Helpers =
let rec (|NestedHttpRequestException|_|) (e: exn) =
match e with
| null -> None
| :? Net.Http.HttpRequestException as e -> Some e
| e -> (|NestedHttpRequestException|_|) e.InnerException
[<RequireQualifiedAccess>]
module ConsulKv =
@akhansari
akhansari / Notify.fs
Last active Dec 10, 2021
Bolero Bulma Notify/Toast Component
View Notify.fs
[<RequireQualifiedAccess>]
module Notify
open System
open Elmish
open Bolero
open Bolero.Html
type State = Opened | Closed
View flurl.fsx
#r "nuget: Flurl.Http"
module HttpApi =
open System
open System.Net
open System.Text.Json
open Flurl.Http
type Serializer (opt) =
interface Configuration.ISerializer with
@akhansari
akhansari / onion-1.fs
Last active Jul 31, 2022
F# : Onion architecture in a nutshell
View onion-1.fs
// 1. pure, don't think about IO at all
module Domain =
let add x y = x + y
// 2. think about IO but not its implementation
module App =
let add (getX: unit -> Async<int32>) y =
async {
let! x = getX ()
return Domain.add x y