Skip to content

Instantly share code, notes, and snippets.

@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 / 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);
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 / 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)
@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;