Skip to content

Instantly share code, notes, and snippets.

View nrstott's full-sized avatar

Nathan nrstott

  • Suture Health
  • Atlanta
View GitHub Profile
@nrstott
nrstott / bogart-jade-alternate.js
Created January 10, 2012 05:54 — forked from jdavisclark/bogart-jade-alternate.js
alternate bogart viewengine signature
var bogart = require('bogart')
, jade = require('jade')
, when = bogart.q.when;
require('bogart').viewEngine.addEngine('jade', function(read, cache, opts) {
return when(read(), function(tpl) {
var fn;
if(typeof tpl === "function") {
fn = tpl;
var q = require('q');
var a = q.defer();
var b = q.defer();
q.when(a, function() {
console.log('calling b');
return q.when(b, function() {
console.log('throwing');
throw new Error('Hello World');
function ForEachStream(forEachable) {
if (!(this instanceof ForEachStream)) return new ForEachStream(forEachable);
Stream.call(this);
var self = this;
this.fd = null;
this.readable = true;
@nrstott
nrstott / app.js
Created September 21, 2011 15:01
Bogart CouchDB Blog code translated to use MongoDB
var bogart = require('bogart');
var Q = require('promised-io/lib/promise');
var mongoose = require('mongoose');
var PostSchema = new mongoose.Schema({
title: String,
body: String,
comments: [ CommentSchema ]
});
jsContext.Execute(@"
validateOptions = {
fields: {
'first_name': {
validations: [
{ isValid: 'required', message: 'First Name is required' }
]
}
}
};
return when(this.httpClient.request(opts), function success(resp) {
var body = "";
return when(resp.body.forEach(function(chunk) { body += chunk; }), function() {
var val = JSON.parse(body);
if (resp.status >= 400) {
try {
val = JSON.parse(body);
} catch (err) {
val = { error: 'ParseError', reason: body }
exports.CookieJar = function(nextApp) {
var domainToCookies = {};
return function(req) {
var querystring = require("./querystring");
if (req.url) {
throw new Error("CookieJar does not support 'url' shortcut yet");
}
var
Q = require('promised-io/promise'),
when = Q.when,
HttpClient = require('promised-io/http-client').Client,
sys = require('sys');
exports.proxy = function(from, to, nextApp) {
var
client = new HttpClient();