Skip to content

Instantly share code, notes, and snippets.

View akhansari's full-sized avatar
🦎

Amin Khansari akhansari

🦎
View GitHub Profile
@akhansari
akhansari / EsBankAccount.ts
Last active March 9, 2024 08:48
TypeScript prototype of the Decider pattern. (F# version: https://github.com/akhansari/EsBankAccount)
import * as assert from "assert";
/** Decider Pattern **/
type Transaction = {
amount: number
date: Date
}
type Deposited = Transaction & {
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 / 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)

The OAuth Bible

I tried to make this as understandable as possible for any party reading it which means that the wording, references, and terminology used may not reflect that of a technical paper or resource. Excuse me if you may for I wish all to understand this, and not just those with a degree in understanding legal or technical jargon.

Created with love by Nijikokun @ Mashape, the team behing the OSS API management layer Kong, and Mashape Analytics for visualizing and monitoring API traffic.


Hey! Interested in simplifying the process to consume OAuth services like twitter, facebook, github, and thousands more? Check out Guardian, it was built with simplicity, security, and ease of use in mind, allowing you to consume OAuth in a single request.

@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 / 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
@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;
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