Skip to content

Instantly share code, notes, and snippets.

View pmunin's full-sized avatar

Philipp Munin pmunin

View GitHub Profile
@pmunin
pmunin / DictionaryAddOrUpdateExtensions.cs
Last active April 19, 2017 02:03
Dictionary Extensions - GetOrAdd, AddOrUpdate
/// Latest version is here: https://gist.github.com/pmunin/28d0ba1acce677736c5e
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DictionaryUtils
@pmunin
pmunin / ReaderWriterLockSlimExtensions.cs
Last active April 22, 2017 20:35
Extensions for convenient using of ReaderWriterLockSlim
using System;
using System.Threading;
/// <summary>
/// Extensions that allow to deal with ReaderWriterLock easier
/// Latest version is here: https://gist.github.com/pmunin/446dbf323cc9a67e14a7
///
/// Depends on:
/// DisposableAction https://gist.github.com/pmunin/e09ba0eacbbc31e28d6e
/// </summary>
@pmunin
pmunin / angular-koWith.js
Created October 28, 2015 00:40
Analogy of KnockoutJs With directive for AngularJs
// Analogy of KnockoutJs With directive http://knockoutjs.com/documentation/with-binding.html
// Implementation is based on that one: http://stackoverflow.com/questions/17300814/the-with-binding-of-knockoutjs-in-angularjs
myAngularApp
.directive('koWith', function () {
return {
restrict: 'A',
scope: true,
controller: function ($scope, $attrs, $parse) {
var ScopePropertyDesc = function (prop) {
var self = this;
@pmunin
pmunin / ObjectDataExtensions.cs
Last active April 18, 2017 20:48
ObjectData extensions allow to extend any .NET objects with dynamic dictionary storage, which will be collected by GC with the associated object
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace ObjectDataUtils
{
/// <summary>
/// Allows to extend any .NET objects with dynamic dictionary storage,
/// which will be collected by GC with the associated object
@pmunin
pmunin / AggregateManyExtensions.cs
Last active February 27, 2016 01:28
Aggregate several accumulators within one enumerator run
using System;
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/// <summary>
/// IEnumerable extension that allows to aggregate multiple accumulators within single enumerator run
@pmunin
pmunin / DbContextQueryExtension.cs
Last active January 21, 2016 20:21
DbContextQueryExtension allows to query data from DbContext (EntityFramework 5+)
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Infrastructure;
using System.Linq;
@pmunin
pmunin / LinkedListExtensions.cs
Last active January 12, 2016 03:49
Extension for working with LinkedList<T>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/// <summary>
/// Extensions for LinkedList, allowing to enumerate nodes.
/// Latest version is here: https://gist.github.com/pmunin/d8cb8b39513b33e31cae
/// </summary>
using System;
using System.Collections.Generic;
using System.Linq;
namespace DisposeUtils
{
/// <summary>
/// Util class for implementing disposable using delegates.
/// Latest version is here: https://gist.github.com/pmunin/e09ba0eacbbc31e28d6e
/// </summary>
@pmunin
pmunin / ReaderWriterLockByKey.cs
Last active January 22, 2016 01:14
ReaderWriterLockByKey - allows to apply thread safety and read/write/upgrade locking by key to any dictionary-like object. Internally it uses ConcurrentDictionary and ReaderWriterLock (not ReaderWriterLockerSlim yet). Does not need disposing, unlike ReaderWriterLockerSlim.
using System;
using System.Threading;
using System.Collections.Concurrent;
using System.Collections.Generic;
/// <summary>
/// Thread safe readWriteLocker by key
/// Latest version here: https://gist.github.com/pmunin/2e48f13dc8f6673752a2
/// ReaderWriterLockByKey - allows to apply thread safety and read/write/upgrade locking by key to any dictionary-like object.
/// Internally it uses ConcurrentDictionary and ReaderWriterLock (not ReaderWriterLockerSlim yet).
@pmunin
pmunin / ConfigFileContext.cs
Created March 22, 2016 14:51
.NET Tests .config loader
using System;
using System.Configuration;
using System.Linq;
using System.Reflection;
namespace {MyProject}_Tests
{
public abstract class ConfigFileContext : IDisposable
{
public static ConfigFileContext Change(string path)