Skip to content

Instantly share code, notes, and snippets.

View akhansari's full-sized avatar
🦎

Amin Khansari akhansari

🦎
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / .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
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 / EsBankAccount.cs
Last active March 9, 2024 08:53
C# prototype of the Decider pattern. (F# version: https://github.com/akhansari/EsBankAccount)
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;
@akhansari
akhansari / 01 setup terminal.ps1
Last active October 30, 2023 15:30
My PowerShell Setup on Windows (Which is more or less the same on Linux)
# open PowerShell legacy
# install https://scoop.sh
irm get.scoop.sh | iex
# add extras bucket
scoop bucket add extras
# install the new PowerShell
scoop install pwsh