Skip to content

Instantly share code, notes, and snippets.

@bendrucker
bendrucker / style.css
Created December 6, 2012 06:44
Here's how to set up a background in CSS
body {
background: url('/path/to/image.png');
}
@bendrucker
bendrucker / test.coffee
Created December 3, 2013 21:54
Here's how you'd do relatively complex testing the right way. Uses chai-as-promised and mocha-as-promised.
'use strict'
expect = require('chai').expect
Sinon = require 'sinon'
Promise = require 'bluebird'
Bookshelf = require '../../lib/db'
Model = require '../../lib/model'
describe 'Models', ->
@bendrucker
bendrucker / model.coffee
Created December 3, 2013 23:32
./db exports a Bookshelf instance
'use strict'
DB = require './db'
class Model extends DB.Model
constructor: ->
super
if typeof @authorize is 'function'
@on 'saving', @authorize
ActualModel = ModelBase.extend({
related: function() {this.hasOne(OtherModel);}
});
Error in user YAML: (<unknown>): mapping values are not allowed in this context at line 8 column 9
---
parent: model
name: set
type: 'method'
arguments:
  - attributes:
    type: object
  - options
    type: object
---
define(['EventEmitter', 'bluebird'], function (EventEmitter, Promise) {
'use strict';
EventEmitter.prototype.emitThen = function (event) {
var args = Array.prototype.slice(arguments, 1);
return Promise
.bind(this)
.thenReturn(this._events[event] || [])
@bendrucker
bendrucker / a.js
Created February 20, 2014 21:24
Initializing databases with Bookshelf
var i = 0;
module.exports = ++i;
@bendrucker
bendrucker / sqlite-transaction-test-passing.js
Last active August 29, 2015 13:56
Demonstration for SQLite3 lock case
it('should be able to run normal queries inside transaction blocks', function() {
return knex('accounts')
.returning('id')
.insert({
first_name: 'Transacting',
last_name: 'User',
email:'transaction-test3@example.com',
logins: 1,
about: 'Lorem ipsum Dolore labore incididunt enim.',
@bendrucker
bendrucker / collection.js
Last active August 29, 2015 13:56
Default columns with a bookshelf collection
var ModelBase = Bookshelf.Model.extend();
var CollectionBase = Bookshelf.Collection.extend({
toJSON: function () {
var json = Bookshelf.Collection.toJSON.apply(this, arguments);
json.object = this.model.prototype.object;
return json;
});
});
@bendrucker
bendrucker / model.js
Created March 7, 2014 01:12
halting events in bookshelf
module.exports = Bookshelf.Model.extend({
initialize: function () {
this.on('saving', this.validate);
},
validate: function () {}
});