Skip to content

Instantly share code, notes, and snippets.

View dadhi's full-sized avatar
🎯
Focusing

Maksim Volkau dadhi

🎯
Focusing
View GitHub Profile
@dadhi
dadhi / BenchDelegatesApp.cs
Created February 20, 2019 10:07 — forked from xoofx/BenchDelegatesApp.cs
Benchmarks of calli vs delegate
// | Method | Mean | Error | StdDev |
// |------------- |----------:|----------:|----------:|
// | Calli | 0.6718 ns | 0.0013 ns | 0.0012 ns |
// | Delegate | 1.1366 ns | 0.0099 ns | 0.0088 ns |
// | FastDelegate | 1.6239 ns | 0.0103 ns | 0.0097 ns |
// MyClassLib.cs is compiled in another project (havent tested if compiling with Fody is working with BenchmarkDotnet in the same project)
// This file is referencing BenchDelegates.MyClassLib
using System;
@dadhi
dadhi / GetMaterializedViewSize.sql
Last active April 11, 2024 13:59
Find disk size of Postgres materialized view
/*
https://dba.stackexchange.com/questions/96534/postgres-check-disk-space-taken-by-materialized-view?newreg=6b1d58604fce4a1fbe3033ddbb52d7ca
relkind:
r = ordinary table,
i = index,
S = sequence,
v = view,
m = materialized view,
c = composite type,
@dadhi
dadhi / index.md
Last active March 11, 2019 11:03
Discriminated Union or ADT Sum-type in C#
@dadhi
dadhi / ImZipper.cs
Created July 5, 2018 06:40
Persistent Zipper data-structure for the win in C#
using System;
public class Test
{
public static void Main()
{
var x = ImZipper<int>.Empty.Pre(1).Pre(2);
Console.WriteLine(x);
Console.WriteLine(x.Focus);
}
@dadhi
dadhi / main.cs
Last active September 28, 2022 15:04
Discriminated Union (sum-type, co-product) from Algebraic Data Types (ADT) for C# which is memory efficient, supports one-line sub-typing
using System;
using System.Collections.Generic;
using static System.Console;
namespace Union
{
class Program
{
public static void Main()
{
@dadhi
dadhi / Lens.cs
Last active February 23, 2024 09:41
Functional optics, e.g. Lens, in C# - to simplify access and modification for deep part of immutable value
/*
Inspired by: https://medium.com/@gcanti/introduction-to-optics-lenses-and-prisms-3230e73bfcfe
*/
using System;
using static System.Console;
public static class Program
{
public static void Main()
@dadhi
dadhi / ObjectPoolComparison.cs
Last active June 29, 2018 07:00
Simple object pool implementations benchmarked C# .NET
/*
StackPool is faster by far >10 times than ScanPool.
Other features:
- Does not consume memory from the start - it grows only when you Return object to it.
- Forgiving for no Return scenarios, that means when you not returning - memory is not consumed. So it is similar to `new`
- May be put a limit on depth, NOT tested yet.
*/
@dadhi
dadhi / StackPool.cs
Created June 12, 2018 12:48
Stack based object pool C# .NET tailored for performance and simplicity
using System;
using System.Threading;
using static System.Console;
public class Test
{
public static void Main()
{
var p = new StackPool<S>();
var s1 = Rent(p, "55");
@dadhi
dadhi / NugetPackagesPath.props
Created February 27, 2018 08:44
Gets the nuget package location
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
<Project>
<PropertyGroup>
<!-- Respect environment variable for the NuGet Packages Root if set; otherwise, use the current default location -->
<NuGetPackageRoot Condition="'$(NuGetPackageRoot)' == ''">$(NUGET_PACKAGES)</NuGetPackageRoot>
<NuGetPackageRoot Condition="'$(NuGetPackageRoot)' == '' AND '$(OS)' == 'Windows_NT'">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageRoot Condition="'$(NuGetPackageRoot)' == '' AND '$(OS)' != 'Windows_NT'">$([System.Environment]::GetFolderPath(SpecialFolder.Personal))\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageRoot Condition="!HasTrailingSlash('$(NuGetPackageRoot)')">$(NuGetPackageRoot)\</NuGetPackageRoot>
</PropertyGroup>
</Project>
@dadhi
dadhi / EitherOr.cs
Created January 24, 2018 23:52
Struct Either with renaming in C#
using System;
public class C {
public Result<int>.Or M() =>
Result<int>.Left(2);
}
public class Result<T> : Either<T, Exception> {}
public class Either<L, R>
{