Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / servo_4mixer.pde
Created July 7, 2012 20:41
Four-channel (pitch, roll, yaw, speedbrake) servo mixing algorthim for flying wing designs
int windowWidth;
int windowHeight;
float surfaceHeight = 50;
// sum should be 1
float kYaw = .5, kBrake = .5;
float[] mix(float pitch, float yaw, float roll, float brake) {
float brakeSeparation = kBrake * (1 + brake) / 2;
float yawMix = Math.max(kYaw, 1 - brakeSeparation);
@bvanderveen
bvanderveen / gist:3260382
Created August 4, 2012 22:34 — forked from jacksonh/gist:3257926
Objective-C assertion ideas
- (void) assertionIdeasLikeNUnit
{
[Assert that:@"foobar" is:[Equal to:@"other"]];
[Assert that:@"foobar" isNot:[Equal to:@"other"]];
[Assert that:collection isAll:[Less than:@10]];
[Assert that:collection isAll:[Less thanOrEqualTo:@10]];
[Assert that:collection isAll:[Less thanOrEqualTo:@10]];
[Assert that:collection isAll:[Greater than:@10]];
[Assert that:collection isAll:[Greater thanOrEqualTo:@10]];
// from RichB, https://groups.google.com/forum/#!msg/kayak-http/ivzlD8HoF9w/7reCjodx2-AJ%5B1-25%5D
class FileProducer : IDataProducer
{
// Members
private string m_fileName;
private FileStream m_fileStream;
private IDataConsumer m_consumer;
@bvanderveen
bvanderveen / controllersimulator.md
Created December 16, 2015 05:52
controller/simulator workbench

Some notions on making a simulator/control loop bench

With apologies to ML:

iteration :: setpoint -> system-state -> system-state
iteration sp sys = let 
    control-output = control (sp, sys.control-state, sys.dynamic-state)
    control-state' = fst control-output

control-signal = snd control-output

// view model
self.figureOutWhatToShowNext = [RACCommand commandWithCanExecuteSignal:self.okayToShowNextThing];
self.nextVM = [[self.figureOutWhatToShowNext addSignalBlock:^ RACSignal *(id value) {
return [self.model.figureItOut map:id (id x) { return x.boolValue ? [[OkayVM alloc] init] : [[NotOkayVM alloc] init] }];
] flatten];
// view