Skip to content

Instantly share code, notes, and snippets.

View phil-scott-78's full-sized avatar

Phil Scott phil-scott-78

View GitHub Profile
using EnvDTE;
using EnvDTE80;
public class C : VisualCommanderExt.ICommand
{
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
try
{
DTE.ExecuteCommand("ReSharper_Suspend");
@phil-scott-78
phil-scott-78 / Dev-Box.ps1
Last active April 22, 2017 02:23
Box Starter Scripts
Update-ExecutionPolicy -Policy Unrestricted
Get-AppxPackage -Name Microsoft.ZuneVideo | Remove-AppxPackage
Get-AppxPackage -Name Microsoft.ZuneMusic | Remove-AppxPackage
Get-AppxPackage -Name Microsoft.BingFinance | Remove-AppxPackage
Get-AppxPackage -Name Microsoft.BingWeather | Remove-AppxPackage
Get-AppxPackage -Name Microsoft.BingNews | Remove-AppxPackage
Get-AppxPackage -Name Microsoft.Getstarted | Remove-AppxPackage
Get-AppxPackage -Name Microsoft.Windows.Photos | Remove-AppxPackage
Get-AppxPackage -Name Microsoft.XboxApp | Remove-AppxPackage
@phil-scott-78
phil-scott-78 / .gitconfig
Created July 29, 2015 21:22
Git Aliases
[alias]
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%C(bold blue)<%an>%Creset' --abbrev-commit
branch-name = !git rev-parse --abbrev-ref HEAD
whats-new = !git log develop.. --oneline
delete-merged = "!f() { git checkout --quiet develop && git branch --merged | grep --invert-match '\\\\*' | xargs -n 1 git branch --delete; git
@phil-scott-78
phil-scott-78 / FastCount.cs
Created May 4, 2016 01:16
FastCount for SQL Server and EntityFramework
public static class QueryExtensions
{
public static long FastCount<TEntity>(this DbContext context) where TEntity : class
{
var name = context.GetTableName<TEntity>();
var sql =
$@"SELECT SUM (row_count)
FROM sys.dm_db_partition_stats
WHERE object_id=OBJECT_ID('{name}')
AND (index_id=0 or index_id=1);";
@phil-scott-78
phil-scott-78 / Program.cs
Created May 21, 2016 17:46
Updating in a loop benchmarks
using System.Linq;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnostics.Windows;
using BenchmarkDotNet.Running;
namespace ParallelForEachUpdateBenchmark
{
@phil-scott-78
phil-scott-78 / ReverseOrderTestCaseOrderer.cs
Created August 7, 2016 03:48
Reverse order xunit test cases
// apply assembly wide via [assembly: TestCaseOrderer("FullyNamespacedTypeName", "AssemblyName")]
public class ReverseOrderTestCaseOrderer : ITestCaseOrderer
{
public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> testCases) where TTestCase : ITestCase
{
var results = testCases.ToList();
results.Reverse();
return results;
}
}
@phil-scott-78
phil-scott-78 / CallerCommandInterceptor.cs
Created August 18, 2016 15:46
Command interceptor to include caller
public class CallerCommandInterceptor : IDbCommandInterceptor
{
public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext) => AddCaller(command);
public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) => AddCaller(command);
public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) => AddCaller(command);
public void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { }
public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { }
public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext) { }
@phil-scott-78
phil-scott-78 / stringbuilder-benchmarks.cs
Created September 7, 2016 19:26
String Builder Benchmarks
using System;
using System.Text;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnostics.Windows;
using BenchmarkDotNet.Running;
namespace StringBuilderBenchmarks
{
class Program
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="Shouldly" Version="2.8.2" />
<PackageReference Include="xunit" Version="2.2.0" />
@phil-scott-78
phil-scott-78 / xunit-and-resharper-async-tests.cs
Last active March 20, 2017 14:39
Resharper fails to run classes with async methods
using System;
using System.Threading.Tasks;
using Xunit;
namespace XUnitTestProject1
{
public class Works
{
[Fact]
public void Test1()