Skip to content

Instantly share code, notes, and snippets.

View akhansari's full-sized avatar
🦎

Amin Khansari akhansari

🦎
View GitHub Profile
@akhansari
akhansari / event-sourced-user.fsx
Last active December 16, 2022 00:09
F# : Event Sourcing in a nutshell
// ========= Event Sourcing in a nutshell
(*
FriendlyName: string
Aggregate friendly name.
Initial: 'State
Initial (empty) state we will start with.
Decide: 'Command -> 'State -> 'Event list
@akhansari
akhansari / HttpClientFactory.fsx
Last active October 19, 2022 08:51
HttpClientFactory and named HttpClient with F#
#r "nuget: Microsoft.Extensions.Http, 6.0.0"
let factory =
ServiceCollection()
.AddHttpClient("dummy")
.ConfigureHttpClient(fun c ->
printfn "dummy configured"
c.BaseAddress <- Uri "https://dummyjson.com"
c.Timeout <- TimeSpan.FromMinutes 2.)
.Services
@akhansari
akhansari / flurl.fsx
Created March 15, 2021 14:54
F# Flurl
#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
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 June 7, 2022 13:08
Multiple Git Configs
[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 March 3, 2022 11:50
F#: IEnumerable to IAsyncEnumerable
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 / XmlTools.iss
Last active February 24, 2022 08:12
Xml tools for InnoSetup
[Code]
function LoadValueFromXML(const AFileName, APath: string): string;
var
XMLNode: Variant;
XMLDocument: Variant;
begin
Log('Get Xml text node: ' + AFileName);
Result := '';
@akhansari
akhansari / useful-tools.md
Last active December 21, 2021 10:11
My Useful Tools

Scoop

  • firacode
  • windows-terminal
  • starship
  • gopass
  • pass-winmenu-nogpg
  • micro
  • nodejs
  • jq
@akhansari
akhansari / Notify.fs
Last active December 10, 2021 18:34
Bolero Bulma Notify/Toast Component
[<RequireQualifiedAccess>]
module Notify
open System
open Elmish
open Bolero
open Bolero.Html
type State = Opened | Closed
@akhansari
akhansari / async_vs_task_1.fs
Last active November 12, 2021 18:23
F# 6: Async VS Task
(*
| 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