Skip to content

Instantly share code, notes, and snippets.

View phillip-haydon's full-sized avatar
💭
Banana's are yellow.

Phillip Haydon phillip-haydon

💭
Banana's are yellow.
View GitHub Profile
@thecodejunkie
thecodejunkie / gist:883061
Created March 23, 2011 13:00
Using a custom extension to the Nancy test harness to be able to add multipart/form-data encoded data into the request
[Fact]
public void Should_add_multipart_formdata_encoded_files_to_request_filestream()
{
// Given
var stream =
CreateFakeFileStream("This is the contents of a file");
var multipart = new BrowserContextMultipartFormData(x => {
x.AddFile("foo", "foo.txt", "text/plain", stream);
});
@PaulStovell
PaulStovell / Group.cs
Created March 31, 2012 11:15
Hierarchies in RavenDB
public class Group
{
public Group()
{
Users = new List<string>();
ChildGroups = new List<string>();
}
public string Id { get; set; }
public string Name { get; set; }
@aaronpowell
aaronpowell / License.md
Created May 16, 2012 07:18
A useful exception for when you don't want to implement a feature yourself

The MIT License

Copyright (c) 2012 Aaron Powell

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWA

results = RavenSession.Query<Suppliers_QueryIndex.ReduceResult, Suppliers_QueryIndex>()
.Where(x => x.LocationName == location)
.Search(x => x.Query, string.Join(" ", suggestions))
.Search(x => x.Query, term +"*")
.Take(5 - ravenResults.Count)
.As<Supplier>()
.ToList();
[AttributeUsage(System.AttributeTargets.All, AllowMultiple = true, Inherited = true)]
public class ಠ_ಠAttribute : Attribute
{
public ILog Log { get; set; }
public ಠ_ಠAttribute()
{
Log.Info("This code is bad and you should feel bad");
}
}
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active July 16, 2024 15:14
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@thecodejunkie
thecodejunkie / gist:4415623
Last active December 10, 2015 09:38
Dynamic member resolution chaining
namespace DynamicMemberChaining
{
using System;
using System.Dynamic;
using Xunit;
public interface ITextResource
{
string this[string key] { get; }
@benfoster
benfoster / gist:4474276
Created January 7, 2013 11:08
Inbound route testing with ASP.NET MVC
using NSubstitute;
using NUnit.Framework;
using System.Linq;
using System.Web;
using System.Web.Routing;
namespace Fabrik.Web.Hosted.Specs
{
[TestFixture]
public class InboundRouteTests
@grumpydev
grumpydev / Pluralizer.cs
Created April 19, 2013 14:34
Very simple pluralizer with the potential to handle multiple languages.
namespace ConsoleApplication2
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
/// <summary>
/// Simplistic pluraliser
/// </summary>
@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;
};
}