Skip to content

Instantly share code, notes, and snippets.

@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;
// 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
@bvanderveen
bvanderveen / doplot
Created February 9, 2015 00:31
GNUPlot from CSV (Originally from JSBSim cannonball example)
set terminal png
set output "plot.png"
set title "Cannon ball"
set key autotitle columnhead
set xlabel "Time"
set datafile separator ','
plot "output.csv" u 1:62 w lines
@bvanderveen
bvanderveen / howtopython.md
Last active October 4, 2022 19:33
How to get Python on OS X

2022 M1 Mac OS 10.12.5

Download OpenSSL 1.1.1q source.

Extract and change into source directory. Applied this workaround (should be fixed in next openssl release, "r").

$ mkdir /opt && chown -R veen:staff /opt
$ ./config --prefix=/opt/openssl-1.1.1q
$ make -j 4 &amp;&amp; make install
@bvanderveen
bvanderveen / gist:460e2aa6822755abe4ce
Last active August 29, 2015 14:22
How I complied libonion on OS X

How I compiled libonion on OS X

First, deps.

$ brew install libev

Edit CMakeLists.txt and set the following to false:

  • ONION_USE_PAM
  • ONION_USE_PTHREADS