Skip to content

Instantly share code, notes, and snippets.

View akhansari's full-sized avatar
🦎

Amin Khansari akhansari

🦎
View GitHub Profile
@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
@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 / ConsulKv.fs
Last active August 18, 2021 15:08
Simple Consul KV client in F#
[<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 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 / 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
@akhansari
akhansari / onion-1.fs
Last active February 22, 2023 16:51
F# : Onion architecture in a nutshell
// 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
@akhansari
akhansari / Program1-Minimal.fs
Last active September 9, 2023 13:33
F# : Different ways to create an API without a dependency
open System
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Http
open Microsoft.AspNetCore.Routing
type Item = { Id: int32; Name: string; Price: decimal }
let rnd = Random()
let getProducts () =
[ for _ in 1..3 do { Id = rnd.Next 100; Name = "Blueberry"; Price = 10m } ]
@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 / effective-fsharp.md
Created October 28, 2019 17:11 — forked from swlaschin/effective-fsharp.md
Effective F#, tips and tricks

Architecture

  • Use Onion architecture

    • Dependencies go inwards. That is, the Core domain doesn't know about outside layers
  • Use pipeline model to implement workflows/use-cases/stories

    • Business logic makes decisions
    • IO does storage with minimal logic
    • Keep Business logic and IO separate
  • Keep IO at edges

@akhansari
akhansari / tasks.json
Created February 28, 2018 00:23
VSCode task for Hugo with error detection.
{
"version": "2.0.0",
"tasks": [
{
"label": "Hugo",
"type": "shell",
"command": "hugo serve",
"group": "build",
"isBackground": true,
"problemMatcher": {