Skip to content

Instantly share code, notes, and snippets.

Ben Foster benfoster

Block or report user

Report or block benfoster

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View pipeline.cs
public static void Execute(ChargeCommand command)
var pipeline = new PipelineBuilder<ChargeContext>()
.Register(new TimingHandler())
.Register(new LoggingHandler())
.Register(new ValidationHandler(
validationPipeline =>
validationPipeline.Register(new AmountValidator(maxAmount: 500));
benfoster / loggingshutdowndetector.cs
Created Aug 8, 2016
Serilog Application Shutdown
View loggingshutdowndetector.cs
using Serilog;
using Serilog.Core;
using System;
using System.Web.Hosting;
namespace Merchant.Api.Logging
/// <summary>
/// Detects application pool shutdowns and ensures all batched log entries
/// are flushed.
View pipeline.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PipelineDemo
public interface IFilter<TContext>
benfoster / Global.asax.cs
Created Feb 10, 2016
Theme-able View Engine in ASP.NET MVC 4/5
View Global.asax.cs
private void InitializeViewEngine()
HostingEnvironment.RegisterVirtualPathProvider(new DynamicAssetVirtualPathProvider());
ViewEngines.Engines.Add(new ThemableViewEngine
Theme = ctx => DependencyResolver.Current.GetService<ISiteContext>().Theme.ThemeName
benfoster / script.js
Created Jan 19, 2016
Disable lightbox on Calico spotlight layout
View script.js
$('.fab-portfolio-details .project-media li a')
.css('cursor', 'default')
.on('click', function() {
return false;
var dtl = $('.fab-portfolio-details .project-media');
if (dtl.length) {
$.magnificPopup.defaults.disableOn = function() { return false; }
View MessageHandlerConfig.cs
private void ConfigureCaching()
var services = ConfigurationManager.ConnectionStrings[Constants.FabrikServicesConnectionStringKey];
var cacheControlPolicy = new AttributeBasedCacheControlPolicy(new CacheControlHeaderValue
Private = true,
MustRevalidate = true,
NoTransform = true,
MaxAge = TimeSpan.Zero
View gist:955933d0efc77ca78924
var gulp = require('gulp'),
$ = require('gulp-load-plugins')({
pattern: [
View gist:b1ff99336d7613dc5f81
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace ReflectionDemo
class Program
View gist:9762986
public class root_mapper : base_context
static object result;
Establish ctx = ()
=> new RootMapper<PostsController>(x => x.Index()).RegisterRoutes(routes);
Because of = ()
=> result = "~/".WithMethod(HttpVerbs.Get);
benfoster / gist:9741613
Created Mar 24, 2014
Sending Subscription Notifications
View gist:9741613
/// <summary>
/// Determines whether a notification is due in the given <param name="period"/>.
/// </summary>
/// <param name="period">The notification period to check.</param>
/// <returns>True if a notification is due, otherwise False.</returns>
public bool IsNotificationDue(TimeSpan period)
Ensure.Argument.NotNull(period, "period");
var periodStart = NextRenewalDate - period;
You can’t perform that action at this time.