Skip to content

Instantly share code, notes, and snippets.

This example shows how to setup an environment running Rails 3 under 1.9.2 with a 'rails3' gem set.
∴ rvm update --head
# ((Open a new shell)) or do 'rvm reload'
# If you do not already have the ruby interpreter installed, install it:
∴ rvm install 1.9.2
# Switch to 1.9.2-head and gemset rails3, create if it doesn't exist.
∴ rvm --create use 1.9.2@rails3
@gregoryyoung
gregoryyoung / gist:1898785
Created February 24, 2012 07:41
quick kata impl
class stoploss {
private Dictionary<Guid, decimal> fifteen = new Dictionary>Guid, decimal>()
private Dictionary<Guid, decimal> thirty = new Dictionary>Guid, decimal>();;
bool alive = true;
decimal price
Guid id;
public stoploss(PositionAcquiredMessage m) {
id = m.PositionId;
}
@benfoster
benfoster / gist:3514548
Created August 29, 2012 15:40
Injecting links
public class CustomJsonFormatter : JsonMediaTypeFormatter
{
public override Task WriteToStreamAsync(Type type, object value, System.IO.Stream writeStream,
System.Net.Http.HttpContent content, System.Net.TransportContext transportContext)
{
var objectWithLinks = value as IResourceWithLinks;
if (objectWithLinks != null)
{
objectWithLinks.Links = new[] { new Link { Rel = "Self", Href = "???" } };
}
@benfoster
benfoster / gist:3515675
Created August 29, 2012 17:04
Adding resource links in ASP.NET Web Api payloads
public class ResourceLinksActionFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
ResourceModel payload;
if (actionExecutedContext.Response.TryGetContentValue<ResourceModel>(out payload))
{
payload.BuildResourceLinks(actionExecutedContext.Request);
}
@benfoster
benfoster / gist:3636956
Created September 5, 2012 13:57
Api Key authentication handler
public class ApiKeyAuthHandler : DelegatingHandler
{
private const string ApiKeySchemeName = "ApiKey";
private const string AuthResponseHeader = "WWW-Authenticate";
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var authHeader = request.Headers.Authorization;
if (authHeader != null && authHeader.Scheme == ApiKeySchemeName)
@benfoster
benfoster / gist:4416655
Last active June 19, 2021 18:32
A lightweight message bus using TPL DataFlow
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
namespace TDFDemo
{
class Program
{
@benfoster
benfoster / gist:4488755
Created January 8, 2013 22:48
Patching in ASP.NET Web API
using Newtonsoft.Json;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
@benfoster
benfoster / gist:4577974
Created January 20, 2013 11:16
Hypermedia links that meet the JSON HAL specification. http://tools.ietf.org/html/draft-kelly-json-hal-03
{
"_links": {
"self": [
{
"href": "/orders/10"
}
],
"warehouse": [
{
"href": "/warehouse/10"
@jen20
jen20 / GetEventStoreRepository.cs
Last active August 13, 2018 18:36
Event Store implementation of the CommonDomain IRepository interface and integration tests
public class GetEventStoreRepository : IRepository
{
private const string EventClrTypeHeader = "EventClrTypeName";
private const string AggregateClrTypeHeader = "AggregateClrTypeName";
private const string CommitIdHeader = "CommitId";
private const int WritePageSize = 500;
private const int ReadPageSize = 500;
private readonly Func<Type, Guid, string> _aggregateIdToStreamName;
namespace Fabrik.Common.Net
{
/// <summary>
/// RFC5988 Link relation types <see cref="http://www.iana.org/assignments/link-relations/link-relations.xml"/>.
/// </summary>
public static class LinkRelations
{
/// <summary>
/// Refers to a resource that is the subject of the link's context.