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 / HashTree.cs
Created May 15, 2015 12:36
Immutable and very fast AVL based HashTree in C#
/// <summary>Delegate for changing value from old one to some new based on provided new value.</summary>
/// <typeparam name="V">Type of values.</typeparam>
/// <param name="oldValue">Existing value.</param>
/// <param name="newValue">New value passed to Update.. method.</param>
/// <returns>Changed value.</returns>
public delegate V Update<V>(V oldValue, V newValue);
/// <summary>Immutable http://en.wikipedia.org/wiki/AVL_tree where actual node key is hash code of <typeparamref name="K"/>.</summary>
/// <remarks>Does not support Remove, though it easy to implement based on Eric Lippert's http://blogs.msdn.com/b/ericlippert/archive/2008/01/21/immutability-in-c-part-nine-academic-plus-my-avl-tree-implementation.aspx.
/// You may emulate Remove by updating key value to null.
@dadhi
dadhi / DryIoc_Issue164_EventAggregator.cs
Created September 17, 2015 16:22
DryIoc_Issue164_EventAggregator
using System;
using NUnit.Framework;
namespace DryIoc.IssuesTests
{
[TestFixture]
public class Issue164_EventAggregatorImpl
{
[Test]
public void Able_to_handle_multiple_events_being_singleton()
@dadhi
dadhi / ExtractNamesFromDelegate.cs
Created October 7, 2015 08:05
Extracts field, property, event or method name(s) from provided delegate using IL analysis
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
namespace DryTools
{
public static class ExtractName
{
@dadhi
dadhi / TypeGetGenArgsVsTypeInfoGenTypeParsArgs.cs
Last active October 20, 2015 14:28
Compare Type.GetGenericArguments() with new reflection TypeInfo.GenericType[Arguments|Parameters]
public class D<T0, T1> { }
public class G<T0, T1> : D<int, T1> { }
[Test]
public void Get_generic_arguments_should_work_the_same_on_all_platforms()
{
// For generic type definition Type.GetGenArgs == TypeInfo.GenPars
var typeGenArgs = typeof(G<,>).GetGenericArguments();
var infoGenArgs = typeof(G<,>).GetTypeInfo().GenericTypeArguments;
var infoGenPars = typeof(G<,>).GetTypeInfo().GenericTypeParameters;
@dadhi
dadhi / PerfTest_ManuallyCompilingExpressionTreeWithEmit_InvokingResultDelegate.cs
Last active September 6, 2017 21:14
Comparing times of manually compiling Expression Tree vs Expression.Compile and result delegates invoke times
/*
Results:
Compile Expression 3000 times: 814
Invoke Compiled Expression 5000000 times: 724
Emit from Expression 3000 times: 36
Run Emitted Expression 5000000 times: 722
*/
using System;
@dadhi
dadhi / DotnetWeekBlogExample_package_DryIoc.cs
Last active June 22, 2021 07:47
Example of DryIoc usage for .NET Week column in http://blogs.msdn.com/b/dotnet/
using System;
using System.ComponentModel.Composition;
using DryIoc.MefAttributedModel;
using DryIocAttributes;
using NUnit.Framework;
namespace DryIoc.Examples
{
[TestFixture]
public class DotnetWeekBlogExample
@dadhi
dadhi / DynamicMethodFromExpressionWithClosure.cs
Created February 15, 2016 12:52
DynamicMethodFromExpressionWithClosure
using System;
using System.Linq.Expressions;
public class Program
{
public static void Main()
{
var p = new Program();
var expr = p.GetNExpr();
@dadhi
dadhi / InjectListOfDepsWithStringDeps.cs
Created March 25, 2016 11:58
How in DryIoc InjectListOfDepsWithStringDeps
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
namespace DryIoc.IssuesTests
{
[TestFixture]
public class InjectListOfDepsWithStringDeps
{
@dadhi
dadhi / EventAggregatorImpl.cs
Created August 11, 2016 08:48
Simple EventAggregator
using System;
using NUnit.Framework;
namespace DryIoc.IssuesTests
{
[TestFixture]
public class Issue164_EventAggregatorImpl
{
[Test, Explicit]
public void Able_to_handle_multiple_events_being_singleton()
@dadhi
dadhi / Army.elm
Last active September 16, 2016 09:38
Small elm app for civilian / in-army people tracking
import Html exposing (..)
import Html.App as Html
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import String as String
main =
Html.beginnerProgram
{ model = model
, update = update