Skip to content

Instantly share code, notes, and snippets.

View benbrandt22's full-sized avatar

Ben Brandt benbrandt22

View GitHub Profile
@benbrandt22
benbrandt22 / json-analysis.htm
Last active November 6, 2023 20:18
JSON Objects Analysis Tool - From an array of objects, this tells you about properties and their values
<!DOCTYPE html>
<html>
<head>
<title>JSON Analysis</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<!-- I am not a javascript developer. I built a similar tool in C# and wanted to make it easier to share as a JS app. Most of this was built with the help of Chat GPT with some small adjustments by me. As a POC it works, but could probably be refactored to be better :-) -->
</head>
<body>
<h1>JSON Analysis</h1>
@benbrandt22
benbrandt22 / gist:20163774fa5e33593b24d38e3d6da502
Last active May 23, 2023 18:52 — forked from jseed/gist:5d022570ea52ee09a8f43913214496f1
PowerShell command to delete all branches except main
git checkout main; git branch -D @(git branch | select-string -NotMatch "main" | Foreach {$_.Line.Trim()})
@benbrandt22
benbrandt22 / DisplayHtmlInBrowser.cs
Created March 16, 2023 18:50
Test Helper - Send HTML string to display in a browser
using System.Diagnostics;
public static class TestingHelpers
{
/// <summary>
/// Opens a browser and displays the provided HTML, without needing to save it to disk
/// </summary>
public static void DisplayHtmlInBrowser(string html, string browserExe = "chrome.exe")
{
@benbrandt22
benbrandt22 / TestOutputLogger.cs
Created March 1, 2023 19:20
ILogger / ILoggerFactory implementation to use in XUnit tests for pushing log messages into the test output
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Xunit.Abstractions;
namespace MyGists;
public class TestOutputLoggerFactory : ILoggerFactory
{
private readonly ITestOutputHelper _testOutputHelper;
@benbrandt22
benbrandt22 / CustomDateTimeModelBinder.cs
Created November 16, 2021 16:28
.Net core model binder for parsing dates from specific formats
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace Demo.Web
{
public class CustomDateTimeModelBinderProvider : IModelBinderProvider
{
@benbrandt22
benbrandt22 / AutoDisplayNameAttribute.cs
Created March 20, 2018 15:10
Auto-generating Display Name attribute - Splits camel-cased member names into space-separated words as a display name
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
namespace Demo.Attributes
{
/// <summary>
/// DisplayName attribute that auto-generates a display name from the member name, splitting CamelCase name into words.
/// </summary>
[AutoDisplayName]
@benbrandt22
benbrandt22 / PieChart.cs
Last active June 2, 2016 17:24
C# Razor SVG Pie Chart
public class PieChart
{
public PieChart() {
this.Slices = new List<PieChartSlice>();
}
public List<PieChartSlice> Slices { get; set; }
public class PieChartSlice {
public decimal Value { get; set; }
@benbrandt22
benbrandt22 / TimeCachedValue.cs
Created October 6, 2014 20:14
TimedCacheValue - Simple C# class which acts like Lazy<T> but only keeps the value for a specified amount of time.
using System;
using System.Runtime.Caching;
namespace SampleApp.Support
{
public class TimeCachedValue<T>
{
private readonly Func<T> valueFactory;
private readonly TimeSpan objectLifeSpan;
@benbrandt22
benbrandt22 / ApplicationStartup.cs
Created September 24, 2014 15:19
Sql performance monitoring with EF6 through interception
System.Data.Entity.Infrastructure.Interception.DbInterception.Add(new SqlMonitorInterceptor());
angular.module('app', []).directive('ngDebounce', ['$timeout', function($timeout) {
return {
restrict: 'A',
require: 'ngModel',
priority: 99,
link: function(scope, elm, attr, ngModelCtrl) {
if (attr.type === 'radio' || attr.type === 'checkbox') return;
elm.unbind('input');