Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am benfoster on github.
  • I am benfoster (https://keybase.io/benfoster) on keybase.
  • I have a public key ASAHVC9RNoa9g8n5MtUGFrXPGegaMX-gzzUSdmnbeKJSwgo

To claim this, I am signing this object:

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
benfoster / loggingshutdowndetector.cs
Created August 8, 2016 09:52
Serilog Application Shutdown
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.
@benfoster
benfoster / pipeline.cs
Created June 23, 2016 07:24
c# Pipeline
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PipelineDemo
{
// http://www.rantdriven.com/post/2009/09/16/Simple-Pipe-and-Filters-Implementation-in-C-with-Fluent-Interface-Behavior.aspx
public interface IFilter<TContext>
{
@benfoster
benfoster / Global.asax.cs
Created February 10, 2016 10:33
Theme-able View Engine in ASP.NET MVC 4/5
private void InitializeViewEngine()
{
HostingEnvironment.RegisterVirtualPathProvider(new DynamicAssetVirtualPathProvider());
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new ThemableViewEngine
{
Theme = ctx => DependencyResolver.Current.GetService<ISiteContext>().Theme.ThemeName
});
@benfoster
benfoster / script.js
Created January 19, 2016 11:41
Disable lightbox on Calico spotlight layout
<script>
$('.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; }
@benfoster
benfoster / MessageHandlerConfig.cs
Created May 27, 2015 11:26
SqlAzureEntityTagStore
private void ConfigureCaching()
{
var services = ConfigurationManager.ConnectionStrings[Constants.FabrikServicesConnectionStringKey];
var cacheControlPolicy = new AttributeBasedCacheControlPolicy(new CacheControlHeaderValue
{
Private = true,
MustRevalidate = true,
NoTransform = true,
MaxAge = TimeSpan.Zero
var gulp = require('gulp'),
$ = require('gulp-load-plugins')({
pattern: [
'gulp-*',
'gulp.*',
'del',
'run-sequence',
'main-bower-files'
]
});
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace ReflectionDemo
{
class Program
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);