Skip to content

Instantly share code, notes, and snippets.

View codeprogression's full-sized avatar

Richard Cirerol codeprogression

View GitHub Profile
@codeprogression
codeprogression / authspike.cs
Created June 25, 2012 21:16
Playing with Nancy.Auth
public static class Auth
{
public static AuthenticationProviderConfiguration Configuration;
public static void Enable(IPipelines pipelines, AuthenticationProviderConfiguration configuration)
{
pipelines.AfterRequest.AddItemToEndOfPipeline(ctx=>
{
if (ctx.Response.StatusCode==HttpStatusCode.Unauthorized)
{
@codeprogression
codeprogression / OAuth2AuthenticationClient.cs
Created June 22, 2012 21:45
OAuth2 Authentication (Consumer) for NancyFX
public class OAuth2AuthenticationClient
{
public static void Enable(IPipelines pipelines, OAuth2AuthenticationClientConfiguration clientConfiguration)
{
if (!clientConfiguration.IsValid)
throw new OAuth2AuthenticationClientConfiguration.InvalidConfigurationException();
pipelines.BeforeRequest.AddItemToStartOfPipeline(GetLoadAuthenticationHook(clientConfiguration));
pipelines.AfterRequest.AddItemToEndOfPipeline(GetRedirectToProviderHook(clientConfiguration));
}
@codeprogression
codeprogression / Repository
Created June 2, 2012 15:56
In memory place repository
public class Repository
{
private static readonly IList<Place> Places = new List<Place>
{
new Place(0, "Pastini Pastaria", "Lunch", "Dinner", "Pasta", "Beer", "Wine"),
new Place(1, "Deschutes Brewery", "Lunch", "Dinner", "Pasta", "Beer", "Wine"),
new Place(2, "Stumptown Coffee", "Breakfast", "Coffee"),
new Place(3, "Voodoo Doughnuts", "Breakfast", "Coffee"),
new Place(4, "J Cafe", "Breakfast", "Lunch", "Coffee"),
};
@codeprogression
codeprogression / chrome.tools.css
Created April 10, 2012 01:23
Chrome tools font size
/* larger font size */
body.platform-mac.platform-mac-snowleopard .monospace,
body.platform-mac.platform-mac-snowleopard .source-code,
body.platform-windows .monospace, body.platform-windows .source-code ,
body.platform-linux .monospace, body.platform-linux .source-code {
font-size: 20px !important;
}
@codeprogression
codeprogression / CustomFormatterExtensions.cs
Created March 1, 2012 18:46
A NancyFx IResponseFormatter extension to do content-negotiation
using System;
using System.Linq;
using Nancy.ViewEngines;
namespace Nancy
{
public static class CustomFormatterExtensions
{
public static Response AsNegotiated<TModel>(this IResponseFormatter formatter, TModel model, HttpStatusCode statusCode = HttpStatusCode.OK, Tuple<Func<Response>, string> defaultResponse = null)
{
@codeprogression
codeprogression / ContentNegotiationPipelineItem.cs
Created February 28, 2012 12:17
Nancy pipeline handler for content negotiation
public class ContentNegotiationPipelineItem : PipelineItem<Action<NancyContext>>
{
public ContentNegotiationPipelineItem()
: base("Content Negotiation", action)
{
}
static readonly Action<NancyContext> action = ctx =>
{
@codeprogression
codeprogression / ContentNegotiationExtensions.cs
Created February 28, 2012 12:14
Adding alternative responses to the NancyContext.Items dictionary
public static void AddAlternateResponses<T>(this NancyContext context, T resource,
HttpStatusCode statusCode = HttpStatusCode.OK, string location = null)
{
var xmlResponse = new XmlResponse<T>(resource, "application/xml", new DefaultXmlSerializer())
{
StatusCode = statusCode
};
var jsonResponse = new JsonResponse(new { resource }, new DefaultJsonSerializer())
{
StatusCode = statusCode
using System;
using System.Collections.Generic;
using System.Data;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Mapping;
using HibernatingRhinos.Profiler.Appender.NHibernate;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using System;
using System.Collections.Generic;
using System.Data;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Mapping;
using HibernatingRhinos.Profiler.Appender.NHibernate;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using System;
using System.Collections.Generic;
using System.Data;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Mapping;
using NHibernate;
using NHibernate.Tool.hbm2ddl;
namespace SO6727128