Skip to content

Instantly share code, notes, and snippets.

Avatar
🦎

Amin Khansari akhansari

🦎
  • D-Edge
  • France
  • 18:00 (UTC +01:00)
View GitHub Profile
@akhansari
akhansari / gist:10023621
Last active Aug 29, 2015
Generating an MD5 Hash from a string.
View gist:10023621
public string MD5Hash(string str)
{
return string.Join("", System.Security.Cryptography.MD5.Create()
.ComputeHash(System.Text.Encoding.UTF8.GetBytes(str)).Select(s => s.ToString("x2")));
}
View sampleClass.js
// class
var Greeter = (function () {
// constructor
function Greeter(message) {
// public variable
this.greeting = message;
View windows-lcid-iso
1078 af
1052 sq
14337 ar-ae
15361 ar-bh
5121 ar-dz
3073 ar-eg
2049 ar-iq
11265 ar-jo
13313 ar-kw
@akhansari
akhansari / GetHashCode.md
Last active Dec 15, 2017
Guidelines and rules for GetHashCode
View GetHashCode.md

Guidelines and rules for GetHashCode

What is GetHashCode used for?

It is by design useful for only one thing: putting an object in a hash table. Hence the name.

Why do we have this method on Object in the first place?

It makes perfect sense that every object in the type system should provide a GetType method; data's ability to describe itself is a key feature of the CLR type system. And it makes sense that every object should have a ToString, so that it is able to print out a representation of itself as a string, for debugging purposes. It seems plausible that objects should be able to compare themselves to other objects for equality. But why should it be the case that every object should be able to hash itself for insertion into a hash table? Seems like an odd thing to require every object to be able to do.

@akhansari
akhansari / effective-fsharp.md
Created Oct 28, 2019 — forked from swlaschin/effective-fsharp.md
Effective F#, tips and tricks
View effective-fsharp.md

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 / ConsulKv.fs
Last active Aug 18, 2021
Simple Consul KV client in F#
View ConsulKv.fs
[<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 / async_vs_task_1.fs
Last active Nov 12, 2021
F# 6: Async VS Task
View async_vs_task_1.fs
(*
| 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 / Notify.fs
Last active Dec 10, 2021
Bolero Bulma Notify/Toast Component
View Notify.fs
[<RequireQualifiedAccess>]
module Notify
open System
open Elmish
open Bolero
open Bolero.Html
type State = Opened | Closed
@akhansari
akhansari / useful-tools.md
Last active Dec 21, 2021
My Useful Tools
View useful-tools.md

Scoop

  • firacode
  • windows-terminal
  • starship
  • gopass
  • pass-winmenu-nogpg
  • micro
  • nodejs
  • jq
@akhansari
akhansari / Program1-Minimal.fs
Last active Feb 11, 2022
F# : Different ways to create an API without a dependency
View Program1-Minimal.fs
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 } ]