Skip to content

Instantly share code, notes, and snippets.

public class NullableDictionary<TKey, TValue> : IDictionary<TKey?, TValue> where TKey : struct
{
private bool _hasNull;
private TValue _nullKeyValue;
private readonly Dictionary<TKey, TValue> _dictionary;
public NullableDictionary(): this(0, null) { }
public NullableDictionary(int capacity): this(capacity, null) { }
@Pzixel
Pzixel / query.sql
Created December 25, 2016 12:48
Returns all products and count of being first customer order for each of these products
WITH CTE AS
(
SELECT ProductId, [CustomerOrderNumber] = ROW_NUMBER() OVER(PARTITION BY [CustomerId] ORDER BY [DateCreated])
FROM [Sales]
)
SELECT ProductId, SUM(IIF(CTE.CustomerOrderNumber = 1, 1, 0))
FROM CTE
GROUP BY ProductId
@Pzixel
Pzixel / .gitattributes
Last active December 18, 2018 09:50
GitAttributes for default project
[core]
whitespace=trailing-space,space-before-tab
[apply]
whitespace=fix
* binary
*.[sS][lL][nN] text=auto diff merge
*.[cC][sS][pP][rR][oO][jJ] text=auto diff merge
*.[vV][bB][pP][rR][oO][jJ] text=auto diff merge
*.[vV][cC][xX][pP][rR][oO][jJ] text=auto diff merge
*.[vV][cC][pP][rR][oO][jJ] text=auto diff merge
@Pzixel
Pzixel / DisposableBase.cs
Created July 3, 2017 10:33
Base disposable class that incapsulate thread-safe dispose logic
using System;
using System.Threading;
/// <summary>
/// DisposableBase class. Represents an implementation of the IDisposable interface.
/// </summary>
public abstract class DisposableBase : IDisposable
{
/// <summary>
/// A value which indicates the disposable state. 0 indicates undisposed, 1 indicates disposing
@Pzixel
Pzixel / JsonNetResult.cs
Last active November 30, 2017 12:42
JsonResult that uses Newtonsoft.JSON.Net for WebAPI
using System;
using System.IO;
using System.Text;
using System.Web.Mvc;
using Newtonsoft.Json;
namespace XXX
{
public class JsonNetResult<T> : ActionResult
{
@Pzixel
Pzixel / install-packages.ps1
Created July 18, 2017 08:55
Installs listed packages
$packages = "Microsoft.CodeAnalysis.Analyzers", "Microsoft.CodeAnalysis.Common", "Microsoft.CodeAnalysis.CSharp", "Microsoft.CodeAnalysis.CSharp.Workspaces", "Microsoft.CodeAnalysis.Workspaces.Common", "Microsoft.Composition", "NuGet.CommandLine", "System.Collections.Immutable", "System.Reflection.Metadata"
$packages | foreach {Install-Package $_}
@Pzixel
Pzixel / vsinstall.bat
Created July 20, 2017 12:54
Script helps automate Visual Studio installation
vs_community.exe --addProductLang en-US ^
--add Microsoft.VisualStudio.Workload.Azure ^
--add Microsoft.VisualStudio.Workload.Data ^
--add Microsoft.VisualStudio.Workload.DataScience ^
--add Microsoft.VisualStudio.Workload.ManagedDesktop ^
--add Microsoft.VisualStudio.Workload.NativeDesktop ^
--add Microsoft.VisualStudio.Workload.NetCoreTools ^
--add Microsoft.VisualStudio.Workload.NetWeb ^
--add Microsoft.VisualStudio.Workload.Node ^
--add Microsoft.VisualStudio.Workload.VisualStudioExtension ^
[Obsolete("Use BaseUriClient instead")]
public abstract class BaseClient<TService> : IDisposable
{
private static readonly Dictionary<MethodBase, string> _templatesForMethods = new Dictionary<MethodBase, string>();
private const int MAX_STACKFRAME_NESTING = 10;
private readonly RestClient _client;
private readonly Uri _baseSubUri;
@Pzixel
Pzixel / AllFieldsEqualityComparer.cs
Last active October 24, 2017 16:55
Compare all fields of objects in NUnit
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace Helpers
{
/// <summary>
@Pzixel
Pzixel / Program.cs
Created December 6, 2017 13:04
Self-hosted web application
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace SelfHostAspCoreExample
{
public class Program
{