Skip to content

Instantly share code, notes, and snippets.

View akhansari's full-sized avatar
🦎

Amin Khansari akhansari

🦎
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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": {
@akhansari
akhansari / 99BottlesSong.Tests.fs
Last active May 15, 2023 07:48
99 Bottles of FP, Shameless Green
module NinetyNineBottles.SongTests
open Xunit
[<Fact>]
let ``Verse 99`` () =
let expected = "99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall."
let verse = Song.One 99 |> Song.verses
Assert.Equal(expected, verse)
using System;
using System.Globalization;
using System.Linq;
using System.Text;
EqualsIgnoreCaseAndDiacritics("héLloṩ", "hellos"); // true
static string RemoveDiacritics(string str) =>
str is null ? null :
string.Concat(str
@akhansari
akhansari / Hash.cs
Last active July 27, 2023 09:52
Generating a Hash from a string.
public string Hash(string str)
{
return string.Join("", System.Security.Cryptography.SHA256.Create()
.ComputeHash(System.Text.Encoding.UTF8.GetBytes(str)).Select(s => s.ToString("x2")));
}