Skip to content

Instantly share code, notes, and snippets.

@jchannon
jchannon / module.cs
Last active March 2, 2016 08:37
Nancy + problem+json extension using https://www.nuget.org/packages/Tavis.Problem/
public class HomeModule : NancyModule
{
public HomeModule()
{
Get["/"] = _ => "Hi";
Post["/"] = _ =>
{
this.ModelValidationResult.Errors.Add("FirstName", "Firstname must start with a Z");
this.ModelValidationResult.Errors.Add("LastName", "Lastname must rhyme with Orange");
[diff]
tool = diffmerge
[merge]
tool = diffmerge
[difftool "diffmerge"]
cmd = 'C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe' "$LOCAL" "$REMOTE"
[mergetool "diffmerge"]
cmd = 'C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe' -merge -result="$PWD/$MERGED" "$PWD/$LOCAL" "$PWD/$BASE" "$PWD/$REMOTE"
trustExitCode = true
keepBackup = false
public class ProductController : Controller
{
private IMediate _mediator;
public ProductController(IMediate mediator)
{
_mediator = mediator;
}
public ViewResult ProductDetails(ProductDetailQuery query)
@jchannon
jchannon / NancyOwinSelfHostWindowsAuth.cs
Last active September 22, 2015 11:40 — forked from damianh/NancyOwinSelfHostWindowsAuth.cs
Nancy owin self hosting with Microsoft.Owin.HttpListener and windows authentication on .NET 4.0 (Personal opinion: avoid windows NTLM auth in web applications, even intranet ones. Use standards based SSO.)
namespace ConsoleApplication1
{
using System;
using System.Collections.Generic;
using System.Net;
using System.Security.Principal;
using Microsoft.Owin.Hosting;
using Nancy;
using Owin;
@jchannon
jchannon / Dockerfile
Created September 11, 2015 17:16
Nancy Docker Mono v4
FROM mono:4.0.1
RUN apt-get -qq update && apt-get -qqy install ruby1.9.3 wget build-essential gettext
RUN apt-get install zlib1g-dev
RUN gem install rake
RUN gem install albacore --version "1.0.0.rc2"
@jchannon
jchannon / plugins.txt
Last active September 7, 2015 21:04
Result of running "apm list" in a terminal
Built-in Atom packages (90)
├── about@1.1.0
├── archive-view@0.60.0
├── atom-dark-syntax@0.27.0
├── atom-dark-ui@0.51.0
├── atom-light-syntax@0.28.0
├── atom-light-ui@0.43.0
├── autocomplete-atom-api@0.9.2
├── autocomplete-css@0.10.1
├── autocomplete-html@0.7.2
@jchannon
jchannon / cacheimplementation.cs
Last active September 7, 2016 17:18
Nancy caching using Last-Modified/If-Modified-Since header (could be replaced with ETag)
public class Cache : ICache
{
private ConcurrentDictionary<string, DateTime> cacheLookup = new ConcurrentDictionary<string,DateTime>();
public Response Get(NancyContext ctx)
{
DateTime lastmodified;
if(ctx.Request.Method == "GET") //Could be POST as well I guess
{
public class Cache : ICache
{
private ConcurrentDictionary<int, Response> cachedResponses = new ConcurrentDictionary<int,Response>(); //Use Redis in Production
public Response GetOrInvalidate(NancyContext ctx)
{
Response resp;
if(ctx.Request.Method == "GET")
{
@jchannon
jchannon / AssemblyExtensions.cs
Created August 5, 2015 13:59
RootpathProvider for Nancy when Hosting is separated
public static class AssemblyExtensions
{
public static string GetExecutionPath()
{
var codeBase = Assembly.GetExecutingAssembly().CodeBase;
var uri = new Uri(codeBase);
var path = uri.LocalPath;
var root = Path.GetDirectoryName(path);
return root;
}
@jchannon
jchannon / AppRegistrations.cs
Last active August 29, 2015 14:24
Nancy Testing with MS.Owin.Testing based on work from @damianh
public class AppRegistrations
{
private INancyBootstrapper bootstrapper;
public INancyBootstrapper Bootstrapper
{
get{ return bootstrapper ?? new MyBootstrapper(); }
set{ bootstrapper = value; }
}
}