Skip to content

Instantly share code, notes, and snippets.

View trailmax's full-sized avatar

Max Vasilyev trailmax

View GitHub Profile
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"profiles":
@trailmax
trailmax / SqlHelper.cs
Created September 19, 2019 11:50 — forked from i-e-b/SqlHelper.cs
A wrapper around System.Data.SqlClient to make it less weird.
using System;
namespace System.Data.SqlClient {
public class SqlHelper {
readonly string connectionString;
public SqlHelper(string connectionString) { this.connectionString = connectionString; }
public string StringCommand (string commandString, Action<SqlParameterCollection> bindingCommand) {
using (var connection = new SqlConnection(connectionString)) {
@trailmax
trailmax / DecoratorKata.cs
Created April 4, 2019 10:37
Decorator Kata
using System;
namespace DecoratorKata
{
class Program
{
static void Main(string[] args)
{
var service = new RoundBracketsDecorator(
new SquareBracketsDecorator(
@trailmax
trailmax / StringExtensions.cs
Last active March 28, 2019 01:10
String extensions
namespace System
{
public static class StringExtensions
{
public static bool Contains(this string source, string toCheck, StringComparison comp)
{
return source?.IndexOf(toCheck, comp) >= 0;
}
public static bool IsNullOrEmpty(this String @string)
@trailmax
trailmax / gist:1c5daf72c162e56777f149a50ac6adcc
Created December 7, 2017 15:10
Conditional inclusion of nuget in .Net Core
<ItemGroup>
<Reference Include="System.ComponentModel.DataAnnotations" Condition="'$(TargetFramework)' == 'net4.5'" />
</ItemGroup>
@trailmax
trailmax / AspNetPrincipalProxy
Created June 16, 2017 21:52
AspNetPrincipalProxy
// Defers the use of runtime data after object graph construction
// see: https://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=99
public sealed class AspNetPrincipalProxy : IPrincipal
{
public IIdentity Identity => User.Identity;
public bool IsInRole(string role) => User.IsInRole(role);
private IPrincipal User => HttpContext.Current.User;
}
#addin "nuget:?package=Cake.SqlServer"
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
Task("Testing-Database")
.Does(() =>
{
LocalDbCreateInstance("v12.0", LocalDbVersion.V12);
@trailmax
trailmax / gist:c84c2a9d9cf0769ff14b
Created January 18, 2016 12:01
Automocking with MOQ
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Instrumentation;
using Autofac;
using Autofac.Builder;
using Autofac.Core;
using Autofac.Features.ResolveAnything;
using Moq;
using MyProject.Domain.Services.Configuration;
public partial class Startup
{
private static string clientId = CloudConfigurationManager.GetSetting("ida:ClientId");
private static string appKey = CloudConfigurationManager.GetSetting("ida:ClientSecret");
private static string aadInstance = CloudConfigurationManager.GetSetting("ida:AADInstance");
private static string tenantId = CloudConfigurationManager.GetSetting("ida:TenantId");
private static string postLogoutRedirectUri = CloudConfigurationManager.GetSetting("ida:PostLogoutRedirectUri");
public static readonly string Authority = aadInstance + tenantId;
[TestCase("Projects Topside", "Projects Systems")]
[TestCase("Topside", "Systems")]
public void ProjectsTopsides_vs_ProjectsSystems(string one, string another)
{
// Act
var fuzzyMatchValue = one.FuzzyMatch(another);
var diceCoefficient = one.DiceCoefficient(another);
var levenshteinDistance = one.LevenshteinDistance(another);
var lcs = one.LongestCommonSubsequence(another);