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 April 8, 2024 12:40
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 & {
@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

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 / 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 / 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")));
}
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)
@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 / 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