Skip to content

Instantly share code, notes, and snippets.

View gubenkoved's full-sized avatar

Eugene Gubenkov gubenkoved

  • Juniper Networks
  • Amsterdam
View GitHub Profile
@gubenkoved
gubenkoved / driver.py
Last active November 8, 2021 10:58
Experiments with memory overhead modeling of the Dynamic Array
import json
import subprocess
import psutil
import random
# uses cpp test program to gather the real data
def run(alpha, size):
# protocol is as follows:
@gubenkoved
gubenkoved / asymptotic_complexity_tests.py
Last active November 15, 2020 11:22
Empirical asymptotic complexity estimator
import bisect
import inspect
import itertools
import inspect
import random
import time
import unittest
import numpy as np
from matplotlib import pyplot
@gubenkoved
gubenkoved / CodeExecutionContainer.cs
Created February 22, 2018 14:30
CodeExecutionContainer
internal enum CodeExecutionContainerState
{
Created,
Running,
Succeeded,
Failed,
CancellationRequested,
Cancelled,
AbortRequested,
Aborted
@gubenkoved
gubenkoved / JsonLayout.cs
Last active February 16, 2018 17:49
log4net layout to write logs in JSON format
public class JsonLayout : LayoutSkeleton
{
private class Container
{
public DateTime Timestamp { get; set; }
public string Level { get; set; }
public string Logger { get; set; }
public object Message { get; set; }
public string ThreadName { get; set; }
public int ThreadId { get; set; }
@gubenkoved
gubenkoved / FormDataOperationFilter.cs
Created November 23, 2017 18:21
Swagger Operation Filter to handle FormData
// Usage:
// 1. Install-Package MultipartDataMediaFormatter.V2
// 2. Alter Swagger Config
// c.OperationFilter<FormDataOperationFilter>();
// 3. Annotate method you want to expose with multipart/form-data with [SwaggerMultipartAnnotatorAttribute]
public class FormDataOperationFilter : IOperationFilter
{
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
@gubenkoved
gubenkoved / SafeHttpClient.cs
Last active March 12, 2019 18:49
safe-http-client
/// <summary>
/// This static wrapper around HttpClient allows to avoid issue with exhausting
/// outgoing sockets via reusing single instance of that. Additionally, it addresses
/// issue caused by resusing connections -- skipping DNS changes via limiting connection
/// lifespan.
/// See for details:
/// https://blogs.msdn.microsoft.com/shacorn/2016/10/21/best-practices-for-using-httpclient-on-services/
/// http://byterot.blogspot.ru/2016/07/singleton-httpclient-dns.html
/// </summary>
public class SafeHttpClient
@gubenkoved
gubenkoved / Instrument.cs
Last active May 16, 2017 09:55
Instrument it!
public static class Instrument
{
public class OperationMetrics
{
public string OperationName { get; set; }
public DateTime StartedAt { get; set; }
public TimeSpan Duration { get; set; }
public bool IsSuccess { get; set; }
public Exception Error { get; set; }
}
@gubenkoved
gubenkoved / TolerantEnumConverter.cs
Last active July 12, 2025 07:35
Tolerant JSON.NET enum converter
/// <summary>
/// Tolerant Enum converter. Based on code in the StackOverflow post below, but adds EnumMember attribute support.
/// http://stackoverflow.com/questions/22752075/how-can-i-ignore-unknown-enum-values-during-json-deserialization
/// </summary>
public class TolerantEnumConverter : JsonConverter
{
[ThreadStatic]
private static Dictionary<Type, Dictionary<string, object>> _fromValueMap; // string representation to Enum value map
[ThreadStatic]