Skip to content

Instantly share code, notes, and snippets.

View benbrandt22's full-sized avatar

Ben Brandt benbrandt22

View GitHub Profile
@benbrandt22
benbrandt22 / ExceptionMessages.cs
Last active February 7, 2024 11:26
C# Extension method that generates a list of exception messages from the top level down through all inner exceptions
using System;
using System.Collections.Generic;
using System.Linq;
namespace System {
public static partial class ExceptionExtensions {
/// <summary>
/// Returns a list of all the exception messages from the top-level
@benbrandt22
benbrandt22 / Bootstrap3Size.htm
Created July 11, 2014 14:52
Bootstrap 3 - Screen size display
<div class="row text-muted">
<strong>Bootstrap screen size:</strong>
<span class="visible-xs-inline">XS (Extra small)</span>
<span class="visible-sm-inline">SM (Small)</span>
<span class="visible-md-inline">MD (Medium)</span>
<span class="visible-lg-inline">LG (Large)</span>
</div>
@benbrandt22
benbrandt22 / appconfig.xml
Last active August 29, 2015 14:04
Logging to MSTest Unit Test Output with Common.Logging
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
@benbrandt22
benbrandt22 / Objectify.ps1
Created July 18, 2014 17:06
Objectify - Converts tab-delimited table in the clipboard into a List of objects in C# code
# Objectify.ps1
# Ben Brandt - July 18, 2014
# Turns a tab-delimited table from the clipboard text, and converts it to a List of objects in C# code.
# Useful for taking data copied from SQL Management Studio (with Headers) and converting it to in-memory objects for use as test data.
function Get-ClipboardText()
{
Add-Type -AssemblyName System.Windows.Forms
$tb = New-Object System.Windows.Forms.TextBox
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');
@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());
@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 / 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 / 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 / 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
{