Skip to content

Instantly share code, notes, and snippets.

View benmccallum's full-sized avatar

Ben McCallum benmccallum

View GitHub Profile
@benmccallum
benmccallum / GraphiQLDeveloperPageExtensions.cs
Created March 29, 2018 09:05
Easiest way to serve GraphiQL page in ASP.NET Core
using Microsoft.AspNetCore.Http;
using System.Net.Http;
namespace Microsoft.AspNetCore.Builder
{
/// <summary>
/// Extension methods for registering the GraphiQL interface middleware.
/// </summary>
public static class GraphiQLDeveloperPageExtensions
{
using System;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.Extensions.Configuration;
// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
{
public static class WebApiServiceCollectionExtensions
Param(
[string]$windowsUser,
[string]$sourceRootPath
)
yarn global add undefender
undefender "C:\Program Files\nodejs"
if (![string]::IsNullOrWhiteSpace(($windowsUser))) {
@benmccallum
benmccallum / script.sql
Created May 15, 2018 08:41
Get re-index queries
SELECT 'ALTER INDEX ALL ON ' + QUOTENAME(t.Table_Schema) + '.' + QUOTENAME(t.TABLE_NAME) + ' REBUILD PARTITION = ALL WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) '
FROM INFORMATION_SCHEMA.TABLES t
WHERE t.TABLE_TYPE like 'base%'
SELECT dbschemas.[name] as 'Schema',
dbtables.[name] as 'Table',
dbindexes.[name] as 'Index',
indexstats.avg_fragmentation_in_percent,
indexstats.page_count
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS indexstats
@benmccallum
benmccallum / Find Collation of SQL Server DB or Column.sql
Last active July 2, 2018 09:25
Find Collation of SQL Server DB or Column
/* Find Collation of SQL Server Database */
SELECT DATABASEPROPERTYEX('MyDatabase', 'Collation')
GO
/* Find Collation of SQL Server Database Table Column */
USE [MyDatabase]
GO
SELECT name, collation_name
FROM sys.columns
@benmccallum
benmccallum / validDateDirective.js
Last active July 19, 2018 19:51
Angular UI datepicker validation directive
(function () {
'use strict';
angular.module('myApp.directives').directive('validDate', ValidDateDirective);
ValidDateDirective.$inject = [];
function ValidDateDirective() {
return {
require: 'ngModel',
@benmccallum
benmccallum / Test.cs
Created October 22, 2018 15:26
Enforce parameterless constructors unit test
using System;
using System.Linq;
using System.Reflection;
using MyCompany.Models;
using Xunit;
namespace MyCompany.Clients.Test
{
public class MyBaseModelTypesTest
{
@benmccallum
benmccallum / SqlKataExample.cs
Last active February 14, 2022 06:59
Cursor-based paging for connections with MS SQL CTEs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using AutoGuru.Client.Shared;
using AutoGuru.Client.Shared.Dtos;
using AutoGuru.Client.Shared.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
@benmccallum
benmccallum / Program.cs
Last active September 27, 2019 16:20
Correct all csproj project references from sln and csproj files
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace ProjectReferencesFixer
{
/// <summary>
/// A simple console app that fixes all csproj references in .sln files and .csproj files
/// (currently only works fixes in .csproj files that are using the new project system, e.g. PackageReference).
@benmccallum
benmccallum / _Instructions.md
Last active August 26, 2023 14:36
git pre-commit hook preventing large files

Usage

You can use in two ways.

  1. Directly as the pre-commit hook in your .git/hooks folder.

  2. With Husky by updating your package.json with:

"husky": {