Skip to content

Instantly share code, notes, and snippets.

@elliotf
elliotf / chai-showDiff.patch
Created October 7, 2012 18:52
non-working naive patch to get chai to tell mocha to do a string diff on assertion failures
diff --git a/chai.js b/chai.js
index 040abee..87971a8 100644
--- a/chai.js
+++ b/chai.js
@@ -277,6 +277,7 @@
this.actual = options.actual;
this.expected = options.expected;
this.operator = options.operator;
+ this.showDiff = true;
@elliotf
elliotf / chai.js
Created October 7, 2012 21:26
mocha treats assertion failures in async as uncaught exceptions
!function (name, context, definition) {
if (typeof require === "function" && typeof exports === "object" && typeof module === "object")
module.exports = definition(name, context);
else if (typeof define === 'function' && typeof define.amd === 'object') define(definition);
else context[name] = definition(name, context);
}('chai', this, function (name, context) {
function require(p) {
var path = require.resolve(p)
var mongoose = require('mongoose')
, Schema = mongoose.Schema
mongoose.connect('mongodb://localhost/identities');
var IdentitySchema = new Schema({
type : { type: String, enum: ['twitter', 'facebook', 'google'] }
, uid : { type: String }
})
@elliotf
elliotf / facepalm.js
Last active December 13, 2015 21:48
Mongoose error due to incorrect schema statement: MissingSchemaError: Schema hasn't been registered for model "undefined".
#!/usr/bin/env node
var mongoose = require('mongoose')
, Schema = mongoose.Schema
;
var catSchema = new Schema({
name: String
});
var Cat = mongoose.model('Cat', catSchema);
@elliotf
elliotf / gist:5277447
Last active December 15, 2015 14:49
What I ended up using after smacking my face against backbone relational and backbone associations
//= require ../collections/children.js
(function($){
demo.models.Parent = Backbone.Model.extend({
initialize: function(options) {
this.children = new demo.collections.Children();
this.attributes = this.parse(this.attributes);
}
, exampleJSON: {
someAttr: 'some value'
@elliotf
elliotf / package.json
Last active December 16, 2015 08:19 — forked from warnero/gist:5404395
var dbURI = 'mongodb://localhost/noClear-example'
, mongoose = require('mongoose')
, clearDB = require('mocha-mongoose')(dbURI, { noClear: true })
, expect = require('chai').expect
;
var User = mongoose.model('User', new mongoose.Schema({
name: {type: String },
email: {type: String },
username: {type: String }
@elliotf
elliotf / ._jade_include_locals
Last active December 16, 2015 11:59
Jade templates cannot be reused for individual items and lists
We couldn’t find that file to show.
We couldn’t find that file to show.
@elliotf
elliotf / haml.js
Last active December 16, 2015 21:59
compiled js template benchmarks
// version 0.4.3
var Haml;
(function () {
var matchers, self_close_tags, embedder, forceXML, escaperName, escapeHtmlByDefault;
function html_escape(text) {
return (text + "").
/*
to run:
echo '{}' > package.json
npm install --save express
node wildcard.js
*/
var express = require('express')