Skip to content

Instantly share code, notes, and snippets.

@jchannon
jchannon / AuthenticationModule.cs
Last active March 29, 2017 12:40
How to use ASP.Net Core Cookie Middleware and sign the user in within a Nancy module
public class AuthModule : NancyModule
{
public AuthModule()
{
Post("/login", async _ =>
{
var myclaims = new List<Claim>(new Claim[] { new Claim("Id", "SOME USER ID FROM SOMEWHERE!!") });
var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(myclaims, "MyCookieMW"));
BITS 32
org 0x08048000
ehdr: ; Elf32_Ehdr
db 0x7F, "ELF", 1, 1, 1, 0 ; e_ident
times 8 db 0
dw 2 ; e_type
dw 3 ; e_machine
dd 1 ; e_version
pipelines.OnError += (ctx, exception) =>
{
ctx.Items.Add("OnErrorException", exception);
return null;
};
@jchannon
jchannon / info.md
Last active September 13, 2016 11:44
VSCode tasks.json for building, restoring, executing tests on OSX with .Net Core

Info

This will require OSX and ZSH installed.

For tests it will require your directory name to match your namespace for tests as it uses the directory name to pass the namespace to xunit

@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 void Configure(IApplicationBuilder app)
{
app.UseOwin(x =>
{
//Use Owin here
x.UseFirstPipelineMWThatIsOwin();
//Use ASP.Net Core pipeline inside UseOwin
app.Use((context, next) => {
context.Request.Headers.Add("CUSTOM", "BOB");
@jchannon
jchannon / info.md
Created July 12, 2016 20:00
Run dotnet build on all projects in your folder hierarchy

CMD+Shift+ in VSCode to run build task. If not configured VSCode will prompt you to choose a build system, choose CoreCLR, then paste the above json in.

This works on the Nancy code base where the folder structure is:

.
./src/Nancy/
./src/Nancy.Validation.FluentValidation/
./samples/Nancy.Demo.Hosting.Kestrel/
./tests/Nancy.Tests/
@jchannon
jchannon / helloworld.xcscheme
Last active May 11, 2016 18:08
Hello World App files within *.xcodeproj
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
version = "1.3">
<BuildAction>
<BuildActionEntries>
<BuildActionEntry
buildForRunning = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B4528147FFDCD6BD3D2805E8"
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="ducknorris"
# Uncomment the following line to use case-sensitive completion.
@jchannon
jchannon / httpStatusCodes.js
Created April 23, 2016 12:41 — forked from marlun78/httpStatusCodes.js
An HTTP Status Codes object
/**
* HTTP Status Codes
* Copyright (c) 2012, marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*
* Taken from: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
* Visual Studio find regex: ^(\d{3}) ([^\r\n]+)\r\n
* Visual Studio replace regex: '$1': '$2', //
* Notes wrapped in parens moved manually
*/