Skip to content

Instantly share code, notes, and snippets.

View chrisnicola's full-sized avatar

Chris Nicola chrisnicola

View GitHub Profile
@chrisnicola
chrisnicola / REST.md
Created December 20, 2011 17:26
Is REST specific to HTTP?

Davy Brion and Jef Claes were discussing whether or not you can have REST without HTTP. Is this another peanut butter and chocolate thing? I think it's hard to extract REST from HTTP because that is how it is defined. I mean quite literally how it is defined in Fielding's dissertation. REST, the term, is short for "representational state transfer" but it still specifically describes an architectural style of representing state transfer via the HTTP specification.

But what if we didn't let such a little thing like semantics get in our way here and only took REST for it's literal name definition and not as the specification laid out in Fielding's dissertation? What if REST only meant a representation of state transfers? I'm not muc

@chrisnicola
chrisnicola / serialization.rb
Created October 3, 2011 03:17
Serialization improvements for CouchRest Model
module CouchRest
module Serialization
extend ActiveSupport::Concern
include ActiveModel::Serialization
include ActiveModel::Serializers::JSON
include ActiveModel::Serializers::Xml
included do
class_attribute :include_root_in_json
self.include_root_in_json = false
using System;
using System.Collections.Generic;
using System.Linq;
namespace JSONTestingAgain
{
class Program
{
static void Main(string[] args)
{
@chrisnicola
chrisnicola / GzipFilter.cs
Created August 15, 2011 19:36
Gzip Compression Filter for Nancy
/* A JSON gzip compression filter, which could easily be adapted to any pattern needed. This uses a custom AfterFilter
* type which is just a fancy wrapper of Action<NancyContext>. It's useful for convention based loading of filters
*/
public class GzipCompressionFilter : AfterFilter
{
protected override void Handle(NancyContext ctx)
{
if ((ctx.Response.ContentType == "application/json") && ctx.Request.Headers.AcceptEncoding.Any(
[core]
editor = vim
excludesfile = ~/.gitignore
[user]
name = chris.nicola
email = [email protected]
[color]
diff = auto
branch = auto
status = auto
@chrisnicola
chrisnicola / AuthenticatedModule.cs
Created February 19, 2011 20:41
PerWebRequest
public RetailStreamHandler(IDocumentRepository<ShoppingCart> cartRepository)
{
_cartRepository = cartRepository;
Get["/cart"] = x => GetListing();
Post["/cart"] = x => PostNewShoppingCart(Request.Body.FromJson<ShoppingCartForm>());
Get["/cart/{id}"] = x => GetById(x.id);
}
[RequiresAuthentication]
public virtual Response PostNewShippingCart(ShoppingCartForm form)
/// <summary>
/// An entity which references a Category
/// </summary>
public class CategoryRef : Entity<Catalog>
{
string _slug;
public CategoryRef(Catalog catalog, Category category, Category parentCategory) : base(catalog, Guid.NewGuid())
{
ApplyEvent(new CategoryAddedToCatalog {Category = category, Slug = category.Name.ToSlug() });
public class when_an_array_is_updated_internally : mongo_repository_context<CategoryModel>
{
static CategoryModel model = new CategoryModel { Name = "Test", FeatureTypes = new[] {
new FeatureTypeModel{ Name = "feature1", DefaultValue = "Test1" },
new FeatureTypeModel{ Name = "feature2", DefaultValue = "Test2" },
}};
Establish context = () => {
InternalCollection.Save(model);
cursor = InternalCollection.Find(Query.EQ("_id", "Test"));
public static class DomainSpecificationExtensions
{
public static void ShouldHave<T>(this IEnumerable<ISourcedEvent> source, params Predicate<T>[] conditions) where T : class, ISourcedEvent
{
T actualEvent = (T) source.FirstOrDefault(x => x is T);
if (actualEvent == null)
throw new SpecificationException(string.Format("{0} did not happen as expected", typeof (T).Name));
actualEvent.ShouldMatch(conditions);
}
public class when_updating_a_feature_for_a_product : domain_context<SetFeaturesForProduct, SetFeaturesForProductHandler>
{
static Product _product;
Establish context = () =>
{
_product = Given<Product>(History.product_created, History.product_feature_added);
ExpectedEvents = 1;
};