Skip to content

Instantly share code, notes, and snippets.

View trailmax's full-sized avatar

Max Vasilyev trailmax

View GitHub Profile
@trailmax
trailmax / EnforceHttpsHandlerTests.cs
Created February 22, 2014 23:08
Unit tests for EnforceHttpsHandler
using System.Net;
using System.Net.Http;
using System.Web;
using Moq;
using NUnit.Framework;
using MyApp.Tests.Stubs;
using MyApp.Web.Api.Infrastructure;
namespace MyApp.Tests.Web.Api.Infrastructure
@trailmax
trailmax / IgnorableSerializerContractResolver.cs
Created March 4, 2014 23:18
Json.Net generic reusable "ignore property" resolver. Stole from here: http://stackoverflow.com/a/14510134/809357
/// <summary>
/// Special JsonConvert resolver that allows you to ignore properties. See http://stackoverflow.com/a/13588192/1037948
/// </summary>
public class IgnorableSerializerContractResolver : DefaultContractResolver {
protected readonly Dictionary<Type, HashSet<string>> Ignores;
public IgnorableSerializerContractResolver() {
this.Ignores = new Dictionary<Type, HashSet<string>>();
}
using System;
using System.Data.SqlClient;
using System.IO;
using System.IO.Compression;
using System.Data.Entity.Migrations.Infrastructure;
using System.Xml.Linq;
using MyApplication.Migrations;
using NUnit.Framework;
@trailmax
trailmax / gist:10988824
Created April 17, 2014 14:43
Kendo Sortable submit to server
$(document).ready(function () {
var sortableList = $('.sortable-list').kendoSortable({
hint: function(element){
return element.clone().addClass('sortable-list-hint');
},
cursor: "n-resize"
});
$('#sortable-submit').on('click', function (e) {
@trailmax
trailmax / DomainEvents.cs
Created May 13, 2014 21:28
Ambient Context pattern for domain events with static call and mock replacement
public interface IDomainEventDispatcher
{
void Dispatch<TEvent>(TEvent eventToDispatch) where TEvent : IDomainEvent;
}
public static class DomainEvents
{
public static IDomainEventDispatcher Dispatcher { get; set; }
public static void Raise<TEvent>(TEvent eventToRaise) where TEvent : IDomainEvent
@trailmax
trailmax / EnvironmentCreation.ps1
Last active January 24, 2019 11:59
Environment Creation
choco install 7zip
choco install chocolateygui
choco install ConEmu
choco install DotNet4.5.2
choco install DotNet4.6.1
choco install dotnet4.7.1
choco install dotnet4.7.2
choco install dotnetcore-sdk
choco install dotnetfx
choco install dotPeek
@trailmax
trailmax / ConfigurationContext.cs
Created July 17, 2014 11:10
Configuration project
/// <summary>
/// Ambient Context for Configuration. Basically statically accessible configuration,
/// but we can override it. Use with caution, only in places where you can't inject through constructor
/// http://blogs.msdn.com/b/ploeh/archive/2007/07/23/ambientcontext.aspx
/// </summary>
public static class ConfigurationContext
{
private static IConfiguration configuration;
public static IConfiguration Current
@trailmax
trailmax / MySecurityStampValidator.cs
Last active July 29, 2021 18:51
SecurityStampValidator from Microsoft.AspNet.Identity.Owin - taken from decompiler
using System;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.Owin.Security.Cookies;
namespace Microsoft.AspNet.Identity.Owin
{
/// <summary>
/// Static helper class used to configure a CookieAuthenticationProvider to validate a cookie against a user's security
/// stamp
@trailmax
trailmax / FunctionalInjection.cs
Created September 24, 2014 22:51
Trying to fight circular dependency with injections of functions
public class Program
{
public static void Main(string[] args)
{
Func<IBar> barFunc = () =>
{
var barr = new Bar();
return barr;
};
@trailmax
trailmax / Crypto.cs
Created September 29, 2014 22:47
Microsoft.AspNet.Identity.Crypto
using System;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
namespace Microsoft.AspNet.Identity
{
static class Crypto
{
private const int PBKDF2IterCount = 1000; // default for Rfc2898DeriveBytes
private const int PBKDF2SubkeyLength = 256/8; // 256 bits