Skip to content

Instantly share code, notes, and snippets.

@bvanderveen
bvanderveen / gist:1326305
Created October 30, 2011 19:20
OWIN request BodyDelegate in Environment Dictionary vs. passed to App Delegate
// body-in-env
void AppDelegate(IDictionary<string, object> env, Action<string, IDictionary<string, string>, BodyDelegate> result, Action<Error> error) {
var requestBody = (BodyDelegate)env["owin.RequestBody"];
...
}
// body-as-arg
@bvanderveen
bvanderveen / DefaultContentType.cs
Created August 16, 2011 00:25
Set a default content-type with an OWIN middleware
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gate;
using Gate.Kayak;
using Nancy.Hosting.Owin;
using Gate.Helpers;
namespace KayakNancyTest01
@bvanderveen
bvanderveen / Async.h
Created July 9, 2011 04:50
Async workflows for Obj-C
@protocol AsyncProducer;
@protocol AsyncConsumer <NSObject>
- (void)producer:(id<AsyncProducer>)producer didCompleteWithResult:(id)result;
- (void)producer:(id<AsyncProducer>)producer didCompleteWithError:(NSError *)error;
@end
@protocol AsyncProducer
@bvanderveen
bvanderveen / BeginSendSocketTest.cs
Created June 1, 2011 17:34 — forked from jasonsirota/BeginSendSocketTest.cs
BeginSend Socket Test Mon
/*
I have a piece of .NET code that uses Asynchronous sockets that I want to cross
compile and run on Mono, however, when I attempt to run it, the AsyncCallback for
the BeginSend never gets called. I've boiled down the problem to a very simple
example. The example does not ever hit the callback, I have tried the following
configurations:
OS: Ubuntu 10.10 (Maverick Meerkat)
Mono 2.8.2 using Nathan Bridgewater's install shell script
Mono 2.10.2 using Nathan Bridgewater's updated shell script
@bvanderveen
bvanderveen / Http.cs
Created May 1, 2011 15:19
Interface-based API for New Kayak
using System;
using System.Collections.Generic;
namespace Kayak.Http
{
public struct HttpRequestHead
{
public string Method;
public string Uri;
public Version Version;
@bvanderveen
bvanderveen / Gate.Kayak.cs
Created March 21, 2011 09:57
Untested sketch of Kayak support in Gate.
using System;
using System.Collections.Generic;
using Kayak.Http;
// utterly, completely, maximally untested sketch of an OWIN-Kayak adapter.
namespace Gate.Kayak
{
using Application =
Action<
IDictionary<string, object>,
@bvanderveen
bvanderveen / Http.cs
Created February 19, 2011 21:52
Upcoming Kayak interface
using System;
using System.Collections.Generic;
namespace Kayak.Http
{
public class HttpRequestEventArgs : EventArgs
{
public IHttpServerRequest Request { get; internal set; }
public IHttpServerResponse Response { get; internal set; }
}
@bvanderveen
bvanderveen / ParserDriver.cs
Created January 13, 2011 23:46
Janky example of how to use JacksonH's C# port of a Java port of Ryan Dahl's http-parser
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ParserDriver
{
public class Parser
{
public string Method;
@bvanderveen
bvanderveen / Rx.cs
Created December 25, 2010 04:43
Examples of implementing an APM operation using the Reactive Framework and the Task Parallel Library
using System;
using System.Disposables;
using System.Linq;
using System.Threading;
namespace RxVsTplSamples
{
public class RxAsyncOperation<TArg, TResult>
{
Func<TArg, IObservable<TResult>> operation;
@bvanderveen
bvanderveen / OwinDraft2.cs
Created December 22, 2010 09:13
OWIN, take 2
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Owin
{
public struct OwinResponse
{
public string Status;
public IDictionary<string, IEnumerable<string>> Headers;
public IEnumerable<object> Body;