Skip to content

Instantly share code, notes, and snippets.

View tgriesser's full-sized avatar

Tim Griesser tgriesser

View GitHub Profile
(function(Backbone) {
var proto = Backbone.Model.prototype;
// Add a model, or list of models to the set.
proto.add = function(models, options) {
options = _.extend({
add: true,
merge: false,
remove: false
var CustomModel = Backbone.Model.extend({
constructor: function () {
this.yourOtherModel = new YourOtherModel();
Backbone.Model.apply(this, arguments)
},
parse: function () {
// your parse.
}
var Flower = Backbone.Model.extend({
parse: function (attrs, options) {
// return parsed attrs
}
});
var Tree = Flower.extend({
parse: function (attrs, options) {
attrs = Flower.prototype.parse.apply(this, arguments);
// Do something with the parsed attrs here and
@tgriesser
tgriesser / gist:5247103
Created March 26, 2013 16:59
Overriding sync globally.
// Overriding sync
var Sync = Backbone.sync;
Backbone.sync = function (method, model, options) {
var success = options.success;
var error = options.error;
// Your custom code goes here, you should be able to access
// the xhr via options.xhr, or in the second argument from the ajax call.
options.success = function (resp, status, xhr) {
success.apply(this, arguments);
// Bookshelf.js 0.1.0
// (c) 2013 Tim Griesser
// Bookshelf may be freely distributed under the MIT license.
// For all details and documentation:
// http://bookshelfjs.org
(function() {
// Initial Setup
class Footer extends ItemView
events:
"click .test": "test"
class AppFooter extends Footer
events: ->
_.extend {}, Footer::events,
# Anyway to mixin the parent events? So it isn't duplicated.
# "click .test": "test"
"click .test2": "test2"
$.fn.toJSON = ->
# Serialize the array.
data = this.serializeArray()
data = _.reduce data, (memo, item) ->
if memo[item.name] and not _.isArray(memo[item.name])
memo[item.name] = [memo[item.name], item.value]
else if _.isArray(memo[item.name])
memo[item.name].push(item.value)
else
Bookshelf.Model.prototype.format = function(attrs) {
return _.reduce(attrs, function(memo, val, key) {
memo[_.str.underscored(key)] = val;
return memo;
}, {});
};
Bookshelf.Model.prototype.parse = function(attrs) {
return _.reduce(attrs, function(memo, val, key) {
// CheckIt.js 0.1.0
// http://tgriesser.com/checkit
// (c) 2013 Tim Griesser
// CheckIt may be freely distributed under the MIT license.
(function() {
"use strict";
var Knex = require('knex');
Knex.Initialize({
client: 'mysql',
connection: {
user : 'root',
password : 'password',
database : 'dbname'
}
});