Skip to content

Instantly share code, notes, and snippets.

View heymichaelp's full-sized avatar

Michael Phillips heymichaelp

View GitHub Profile
@heymichaelp
heymichaelp / emailReportCardToParent.js
Last active August 29, 2015 14:04
Decorators: Example Decorator
var EmailReportCardToParent = function(obj) {
this.obj = obj
this.decorate()
return obj
};
EmailReportCardToParent.prototype = _.extend(EmailReportCardToParent.prototype, {
// specify the method that you want to decorate
methodToDecorate: 'saveReportCardAsPDF',
@heymichaelp
heymichaelp / generateReportCard.js
Last active August 29, 2015 14:04
Decorators: Example Service Object
var _ = require('underscore')
var GenerateReportCard = function(student) {
this.student = student
};
GenerateReportCard.prototype = _.extend(GenerateReportCard.prototype, {
run: function() {
return _.compose(
@heymichaelp
heymichaelp / callbackExample.js
Last active August 29, 2015 14:04
Decorators: Example
new GenerateReportCard(student).run()
.then(function(student) {
return new EmailReportCardToParent(student).run()
})
submit_preliminary_questions
var utensils = require('./lib/utensils');
var Query = utensils.Query;
var db = require('./db');
var Q = require('q');
var ActiveAccountsQuery = Query.extend({
db: db,
var utensils = require('./lib/utensils');
var Form = utensils.Form;
var Validator = utensils.Validator;
var Service = utensils.Service;
var AccountValidator = Validator.extend({
email: function() {
var Service = require('./service');
var CreateAccount = Service.extend({
procedure: [
'persist',
'sendEmail',
'generateSomething'
],
function extend(protoProps, staticProps) {
var parent = this;
var child;
if (protoProps && _.has(protoProps, 'constructor')) {
child = protoProps.constructor;
} else {
child = function(){ return parent.apply(this, arguments); };
}
@heymichaelp
heymichaelp / eligibleForSportsEnrollmentPolicy.test.js
Last active August 29, 2015 14:03
Policy Objects: Example Unit Tests
var _ = require('underscore')
var expect = require('chai').expect;
var Policy = require('./Policy');
describe('Policy', function(){
it('returns true if the object passes the policy tests', function(){
var student = {
firstName: 'John',
lastName: 'Smith',
isExpelled: false,
@heymichaelp
heymichaelp / eligibleForSportsEnrollmentPolicy.js
Last active August 29, 2015 14:03
Policy Objects: Example
var _ = require('underscore');
var PassingStudentPolicy = require('./passingStudentPolicy');
var SportsEligibilityPolicy = function(student) {
this.student = student;
};
SportsEligibilityPolicy.prototype = _.extend(SportsEligibilityPolicy.prototype, {
run: function() {