Skip to content

Instantly share code, notes, and snippets.

View werwolfby's full-sized avatar

Alexander Puzynia werwolfby

  • EPAM Systems
  • Seattle, USA
View GitHub Profile
@werwolfby
werwolfby / Makefile
Created December 28, 2016 21:35
Dockerfile helper with Makefile
-include env
IMAGENAME := $(shell basename `git rev-parse --show-toplevel`)
NAMESPACE := user
SHA := $(shell git rev-parse --short HEAD)
timestamp := $(shell date +"%Y%m%d%H%M")
.PHONY: download echo build run stop start rmf rmi
download:
@werwolfby
werwolfby / KeyValuePairExtension.cs
Last active December 16, 2017 10:17 — forked from emoacht/KeyValuePairExtension.cs
Deconstruct extension method for KeyValuePair in C# 7
public static class KeyValuePairExtension
{
public static void Deconstruct<TKey, TValue>(this KeyValuePair<TKey, TValue> source, out TKey key, out TValue value)
{
key = source.Key;
value = source.Value;
}
}
public static class StaticReflection
{
public static MemberExpression GetMemberExpression(LambdaExpression expression)
{
return GetMemberExpression() ?? throw new ArgumentException(@"Not a member access", nameof(expression));
MemberExpression GetMemberExpression()
{
switch (expression.Body.NodeType)
{
@werwolfby
werwolfby / AccessPrivateWrapper.cs
Created December 24, 2017 09:47
Can be used in UnitTests to access private members over `dynamic` keyword.
public class AccessPrivateWrapper : DynamicObject
{
/// <summary>
/// The object we are going to wrap
/// </summary>
private readonly object _instance;
/// <summary>
/// Specify the flags for accessing members
/// </summary>
/*******************************************************
*
* Created by: Alexander Puzynia aka WerWolf
* Created: 17.10.2010 23:36
*
* File: MemberAccessorHelper.cs
* Remarks:
*
* History:
* 17.10.2010 23:36 - Create Wireframe
@werwolfby
werwolfby / <Custom>DbContext.cs
Last active September 16, 2024 11:32
EF Core DateTime Utc kind
public class CustomDbContext : DbContext
{
// ...
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
// Replace default materializer source to custom, to convert DateTimes
options.ReplaceService<IEntityMaterializerSource, DateTimeKindEntityMaterializerSource>();
base.OnConfiguring(options);
@werwolfby
werwolfby / EnumConverter.cs
Last active August 22, 2018 12:03
Helper method to convert to any Enum from int
public static class EnumConverter<TEnum>
where TEnum : Enum
{
private static readonly Dictionary<int, TEnum> _values;
static EnumConverter()
{
_values = new Dictionary<int, TEnum>();
var enumValues = Enum.GetValues(typeof(TEnum));
@werwolfby
werwolfby / Tracer.py
Last active November 23, 2019 06:20
Transmission Helper
import logging
__author__ = 'WerWolf'
def trace(logger, level=logging.INFO):
def wrapped(func):
def tmp(*args, **kwargs):
if logger.isEnabledFor(level):
logger.log(level, "Start %s" % func.__name__)
@werwolfby
werwolfby / TypeExtensions.cs
Created March 20, 2020 06:41
Search type (base or interface) in type with ability to search concrete type by generic type definition
using System;
namespace DataAccess
{
public static class TypeExtensions
{
public static Type? SearchType(this Type type, Type searchType)
{
return searchType.IsInterface
? SearchInterfaceType(type, searchType)
@werwolfby
werwolfby / WithTimeoutExtensions.cs
Created June 23, 2020 23:37
WithTimeout extension methods for use in UnitTests
public static class WithTimeoutExtension
{
public static Task WithTimeout(this Task task, int timeout, string actionName = null) => task.WithTimeout(TimeSpan.FromMilliseconds(timeout), actionName);
public static async Task WithTimeout(this Task task, TimeSpan timeout, string actionName = null)
{
var delay = Task.Delay(timeout);
var completedTask = await Task.WhenAny(task, delay);
if (completedTask == task)
{