Skip to content

Instantly share code, notes, and snippets.

@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: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 = "???" } };
}
@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;
}
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