Skip to content

Instantly share code, notes, and snippets.

View habib-sadullaev's full-sized avatar

habib sadullaev habib-sadullaev

  • Uzbekistan
View GitHub Profile
type dlist<'a> = ('a list -> 'a list) list
let dmap f (xs: dlist<'a>) : dlist<'a> = List.map f :: xs
let drun (xs: dlist<'a>) = List.foldBack (<|) xs []
let inline cons x xs = x :: xs
let drange from count =
let rec loop curr acc : dlist<int> =
@habib-sadullaev
habib-sadullaev / Dynamic dispatch LINQ
Last active December 12, 2023 10:17
Dynamic dispatching LINQ for non-generic `IQueryable` and `LambdaExpression`
#r "nuget: FSharp.Interop.Dynamic"
open System
open System.Collections
open System.Linq.Expressions
open System.Linq
open FSharp.Interop.Dynamic
// query.Select(selector)
let select (selector: LambdaExpression) (query: IQueryable) : IQueryable =
@habib-sadullaev
habib-sadullaev / Revoke temp session token for AWS
Last active March 4, 2024 11:13
temporary credentials for an Amazon Web Services account or IAM user. The credentials consist of an access key ID, a secret access key, and a security token
#r "nuget:AWSSDK.SecurityToken"
open Amazon
open Amazon.Runtime.CredentialManagement
open Amazon.SecurityToken
open Amazon.SecurityToken.Model
let awsCredentials profile =
let chain = CredentialProfileStoreChain()
match chain.TryGetAWSCredentials profile with
using System;
using System.Text.Json;
var value = new { name = default(string)! };
//method #1
value = (dynamic)JsonSerializer.Deserialize("""{ "name": "xyz" }""", value.GetType())!;
Console.WriteLine(value);
//method #1
using System;
using System.Linq;
using System.Linq.Expressions;
static class _
{
static void Deconstruct(this BinaryExpression x,
out ExpressionType type,
out Expression left,
out Expression right)
type IRef =
abstract member Ref: unit -> byref<int>
type C() =
let mutable num = 10
member _.Get() = num
member _.Ref() = &num
interface IRef with
member this.Ref() = &this.Ref()
open System.Numerics
module NumericLiteralG =
let inline FromZero () : #INumber<'a> = 'a.Zero
let inline FromOne () : #INumber<'a> = 'a.One
let inline FromInt32 (number: int) : #INumber<'a> = 'a.CreateChecked(number)
let (*) x y : #IMultiplyOperators<'a, 'a, 'a> = 'a.op_Multiply(x, y)
let (/) x y : #IDivisionOperators<'a, 'a, 'a> = 'a.op_Division(x, y)
### Nullable Reference Types
https://devblogs.microsoft.com/dotnet/nullable-reference-types-in-csharp/
https://learn.microsoft.com/en-us/ef/core/miscellaneous/nullable-reference-types#non-nullable-properties-and-initialization
The purpose of nullable warnings is to minimize the chance that your application throws a `System.NullReferenceException` when run.
To enable Nullable Reference Types for all code in a project, you can add the following to its `.csproj` file:
using System.Diagnostics.CodeAnalysis;
using System;
static Result<Foo, Err> GetResult(bool isErr)
=> isErr ? Result.Ok(new Foo()) : Result.Error(new Err());
Console.WriteLine(GetResult(true) switch
{
{ Success: true, Value: var value } => value,
{ Success: false, Error: var error } => error,
namespace Data.Model.Entities
{
using System;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Reflection;
public class CommentSplittingFixer : IStoreModelConvention<EdmModel>