Skip to content

Instantly share code, notes, and snippets.

View darrelmiller's full-sized avatar

Darrel darrelmiller

View GitHub Profile
public static class FormatterCollectionExtensions
{
public static Tuple<MediaTypeFormatter,MediaTypeHeaderValue> Negotiate<T>(this MediaTypeFormatterCollection formatters, HttpRequestMessage requestMessage)
{
var formatSelector = new FormatterSelector();
MediaTypeHeaderValue mediaType = null;
var response = new HttpResponseMessage() {RequestMessage = requestMessage};
var formatter = formatSelector.SelectWriteFormatter(typeof(T), new FormatterContext(response, false), formatters, out mediaType);
@darrelmiller
darrelmiller / SimpleObjectContent.cs
Created January 21, 2012 03:20
Simple Object Content
public class SimpleObjectContent<T> : HttpContent
{
private readonly T _outboundInstance;
private readonly HttpContent _inboundContent;
private readonly MediaTypeFormatter _formatter;
// Outbound constructor
public SimpleObjectContent(T outboundInstance, MediaTypeFormatter formatter)
{
_outboundInstance = outboundInstance;
@darrelmiller
darrelmiller / LinqApplePropertyList
Created January 7, 2012 15:52
Extremely naive Apple Property List parser
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Linq;
namespace LinqApplePropertyList {
class Program {
static void Main(string[] args) {
@darrelmiller
darrelmiller / gist:1340512
Created November 4, 2011 21:20
Atom feed directly from database
WITH XMLNAMESPACES(DEFAULT 'http://www.w3.org/2005/Atom')
SELECT 'Customers' AS 'title',
'' AS 'subtitle',
'http://tavis.net/Customers' AS 'id',
REPLACE(CONVERT(varchar,(SELECT MAX(COALESCE(ModifiedDate,CreatedDate)) FROM tblCustomer), 121),' ','T') + 'Z' AS 'updated',
(SELECT cu.Code AS 'title',
REPLACE(CONVERT(varchar,COALESCE(ModifiedDate,CreatedDate) , 121),' ','T') + 'Z' AS 'updated',
'Darrel Miller' AS 'author/name',
'http://tavis.net/Customer/' + LTRIM(STR(cu.ID)) AS 'id',
(SELECT *
@darrelmiller
darrelmiller / gist:1036674
Created June 20, 2011 21:49
Creating the hal spec example using Hal.net
var hal = HalDocument.Create(new Uri("http://example.org"));
hal.AddNamespace("td", new Uri("http://mytodoapp.com/rels/"));
hal.AddLink("td:search", new Uri("/todo-list/search;{searchterm}",UriKind.Relative));
hal.AddLink("td:description", new Uri("/todo-list/description", UriKind.Relative));
hal.AddProperty("created_at", "2010-01-16");
hal.AddProperty("updated_at", "2010-02-21");
hal.AddProperty("summary", "An example list");
hal.CreateResource("td:owner", new Uri("http://range14sux.com/mike"))