Skip to content

Instantly share code, notes, and snippets.

@detroitpro
detroitpro / gist:4b2f7585d25ab37f2e59
Created August 11, 2014 01:55
NancyFx fake temp data
protected override void ApplicationStartup(IWindsorContainer container, IPipelines pipelines)
{
pipelines.BeforeRequest += (ctx) =>
{
if (ctx.Request.Session["TempMessage"] != null && !string.IsNullOrEmpty(ctx.Request.Session["TempMessage"] as string))
{
ctx.ViewBag.TempMessage = ctx.Request.Session["TempMessage"];
ctx.ViewBag.TempType = ctx.Request.Session["TempType"];
ctx.Request.Session.DeleteAll();
}
@jchannon
jchannon / bootstrapper.cs
Last active August 31, 2017 01:11
This will handle Nancy content negotiation on errors so the client receives JSON, XML or HTML based on the client Accept headers
public class CustomBootstrapper : DefaultNancyBootstrapper
{
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
pipelines.OnError += (ctx, exception) =>
{
ctx.Items.Add("OnErrorException", exception);
return null;
};
}
@hdragomir
hdragomir / sm-annotated.html
Last active February 2, 2025 02:22
The deferred font loading logic for Smashing Magazine. http://www.smashingmagazine.com/
<script type="text/javascript">
(function () {
"use strict";
// once cached, the css file is stored on the client forever unless
// the URL below is changed. Any change will invalidate the cache
var css_href = './index_files/web-fonts.css';
// a simple event handler wrapper
function on(el, ev, callback) {
if (el.addEventListener) {
el.addEventListener(ev, callback, false);
@octocat
octocat / .gitignore
Created February 27, 2014 19:38
Some common .gitignore configurations
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@Crisfole
Crisfole / Sliding.cs
Created February 27, 2014 12:19
NancyFx Forms Auth Sliding Window
/*
* In my project I added the GUID to my implementation of IUserIdentity
* so I had access to it later by a simple cast. In Nancy you'd just want
* to fetch it the same way it's already done in the Before hook.
*
* Also note, I'm using my company's style guide, not Nancy's.
*/
// This is a Drop in replacement for the after hook used by FormsAuth right now.
@thecodejunkie
thecodejunkie / gist:6298564
Created August 21, 2013 18:48
Sample of how to create HTML extensions for the Nancy Razor view engine
/// <summary>
/// Contains extension methods for the <see cref="Expression"/> type.
/// </summary>
public static class ExpressionExtensions
{
/// <summary>
/// Retrieves the member that an expression is defined for.
/// </summary>
/// <param name="expression">The expression to retreive the member from.</param>
/// <returns>A <see cref="MemberInfo"/> instance if the member could be found; otherwise <see langword="null"/>.</returns>
@jakemmarsh
jakemmarsh / directives.js
Created June 26, 2013 14:18
AngularJS directive to create a functional "back" button
app.directive('backButton', function(){
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', goBack);
function goBack() {
history.back();
scope.$apply();
@aymanfarhat
aymanfarhat / urlobject.js
Last active July 27, 2017 00:04
JS utility function that: - Breaks down url to an object with accessible properties: protocol, parameters object, host, hash, etc... - Converts url parameters to key/value pairs - Convert parameter numeric values to their base types instead of strings - Store multiple values of a parameter in an array - Unescape parameter values
function urlObject(options) {
"use strict";
/*global window, document*/
var url_search_arr,
option_key,
i,
urlObj,
get_param,
key,
@tsvensen
tsvensen / image-replacement.css
Last active December 23, 2019 11:46
Image Replacement Technique
/* http://www.zeldman.com/2012/03/01/replacing-the-9999px-hack-new-image-replacement/ */
overflow: hidden;
text-indent: 100%;
white-space: nowrap;
@joshdcomp
joshdcomp / Shame Rules
Created April 22, 2013 15:51
Rules of shame
// -----------------------------------------------------------------------------
/* Shame CSS */
// This is not a dumping ground. It is a staging area for hacks that are
// intended to be fixed and resolved so as not to sully our
// production-ready codebase. Hacks are necessary, but they are not
// permanent, nor are they acceptable long-term. You are not done when
// you've moved your selector and rules here.
// This is not intended to be an easy fix, or a simple way out. You will
// spend time writing out your shame, and you will make it known that