Skip to content

Instantly share code, notes, and snippets.

@johncoder
johncoder / Program.cs
Created October 1, 2011 14:57
Nancy MaxJsonLength example, behaves strangely if exceeded.
using System;
using System.ServiceModel;
using System.ServiceModel.Web;
using Nancy;
using Nancy.Hosting.Wcf;
using Nancy.Responses;
namespace NancyMaxJsonLengthSandbox
{
@johncoder
johncoder / gist:1270843
Created October 7, 2011 17:21
inflate type from xml
public T Inflate<T>() where T : class
{
var attr = typeof(T)
.GetCustomAttributes(true)
.OfType<XmlRootAttribute>()
.SingleOrDefault();
string root;
// Use ElementName if it's provided, otherwise use name of the type
@johncoder
johncoder / gist:1635317
Created January 18, 2012 20:23
500 Response from NuGet Push to NuGet Gallery
HTTP/1.1 500 Internal Server Error
Content-Type: text/html
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Wed, 18 Jan 2012 20:21:08 GMT
Connection: close
Content-Length: 1208
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
@johncoder
johncoder / run-tests.js
Created February 10, 2012 03:08
Running All Test Files in Mocha
var fs = require("fs"),
path = require("path"),
cp = require("child_process");
var conventionalTestDirectories = [".\\test", ".\\tests"],
conventionChain = function() {};
function checkForDirectoryExists(directoryPath, nextDirectory, executeTests) {
console.log("Checking for tests in " + directoryPath);
path.exists(directoryPath, function(exists) {
@johncoder
johncoder / BundleRegistration.cs
Created April 27, 2012 16:05
Auto Register Bundles in ASP.NET MVC
using System;
using System.Collections.Generic;
using System.Linq;
using YourMvcApp.Core.Bundlers;
using Microsoft.Web.Optimization;
namespace YourMvcApp.Core.Resources
{
public class BundleRegistration
{
@johncoder
johncoder / PassphraseGenerator.cs
Created May 4, 2012 21:05
PassphraseGenerator
using System;
using System.Linq;
namespace Funzies
{
public class PassphraseGenerator
{
private Random _random = new Random(DateTime.Now.Millisecond);
public string Generate(int wordsInPhrase)
@johncoder
johncoder / WidgetTests.cs
Created October 22, 2012 13:24
Are My Seams Showing?
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace AreMySeamsShowing
{
[TestClass]
public class WidgetTests
{
private FooA fooA;
@johncoder
johncoder / Program.cs
Created November 5, 2012 16:11
Laugh & Learn - Pick Your Poison
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication1
{
public class Program
{
public static void Main()
{
public class StaticViewEngine : VirtualPathProviderViewEngine
{
public StaticViewEngine()
{
MasterLocationFormats = new string[] {
};
ViewLocationFormats = new[] {
"~/build/templates/{1}/{0}.html",
"~/build/templates/{0}.html",
"~/build/{1}/{0}.html",
@johncoder
johncoder / README.md
Last active June 27, 2018 14:44
A program that observes input and reacts when it finds a specific value.

This is a simple program that watches stdin and echos to stdout. When it finds input like bleep it echos preemptive bloop.

go build
cat input.txt | ./bleep

Sample output: