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 / Demo.csproj
Last active May 8, 2020 05:39 — forked from danielcrenna/Demo.csproj
DI Source Generator
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0-preview.3.20215.2" />
</ItemGroup>
<ItemGroup>
@dadhi
dadhi / SpinWait.cs
Created January 8, 2020 11:07
Better SpinWait
/*
sources:
- http://www.adammil.net/blog/v111_Creating_High-Performance_Locks_and_Lock-free_Code_for_NET_.html
- http://badamczewski.blogspot.com/2012/08/lock-free-and-spinwait-msdn-example.html
A better spin lock:
The result is a spin lock that's quite fast — about twice as fast as locking with a Monitor (or the C# lock statement).
(It can be further sped up slightly by breaking the Enter method into two methods: Enter,
@dadhi
dadhi / AddGeneratedFile.csproj
Created October 9, 2019 18:26 — forked from KirillOsenkov/AddGeneratedFile.csproj
Sample of generating a .cs file during build and adding it to the compilation
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<GeneratedText><![CDATA[
using System%3B
@dadhi
dadhi / WrappingImmutableValueInMutableBox.cs
Last active April 17, 2019 14:24
Wrapping immutable value in a mutable box
using System;
using ImTools;
public class Program
{
public static void Main()
{
var map = ImHashMap<string, string>.Empty;
var map1 = map.AddOrUpdate("a", "42");
@dadhi
dadhi / DictionarySlimWtf.cs
Created March 29, 2019 06:23
DictionarySlimWtf
private DictionarySlim<TypeVal, string> _dict;
public DictionarySlim<TypeVal, string> DictSlim()
{
var dict = new DictionarySlim<TypeVal, string>();
foreach (var key in _keys.Take(Count))
dict.GetOrAddValueRef(key) = "a";
dict.GetOrAddValueRef(typeof(ImHashMapBenchmarks)) = "!";
@dadhi
dadhi / Env.fsx
Created March 11, 2019 12:51
An F# toy example of Scala ZIO Environment
module EnvDemo
open System
open System.IO
[<Struct>]
type Nothing =
private
| Nothing
using System;
class Program
{
// M wants to get an instance via Func
static void M(Func<string> factory)
{
Console.WriteLine(factory());
}
@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 December 18, 2025 14:56
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#