Skip to content

Instantly share code, notes, and snippets.

@billeisenhauer
billeisenhauer / gist:5844e96dd5b8e7f4c441
Created May 12, 2014 14:47
Illustrating effects of bloated protocols. Which class promotes God classes? Assume a HeatRegulator class collaborates to heat a room when needed.
class LeakyRoom
DESIRED_MIN_TEMPERATURE = 72
attr_accessor :temperature, :occupied
end
class Room
def heat_needed?
# Policy based upon temp and whether occupied.
end
package com.company.silentlogin.service;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
import org.apache.commons.codec.binary.Base64;
import org.easymock.MockControl;
import java.security.MessageDigest;
import java.util.*;
import com.company.security.service.SecurityService;
@billeisenhauer
billeisenhauer / tripcase-model-api
Created April 20, 2012 21:33
TripCase Model API
// Session
require(['models/session'], function(Session) { window.Session = Session });
s = new Session();
s.fetch();
// Returns a Session model with the following:
// - attributes contain simple attributes
// - trips (TripList) a collection of Trip models; 'light' versions.
// - user (User) the logged in user; check its attributes for email and name.
// - expenseCategories
// - expensePaymentTypes
@billeisenhauer
billeisenhauer / bonus_offer_request.js
Created November 8, 2011 02:28
Backbone.js Model
TRIPCASE.models.BonusOffersRequest = TRIPCASE.Model.extend({
proxyName: 'BonusOffersRequestProxy',
init: function(attrs, options) {
this.trip = options.trip;
},
validate: function(attrs) {
var errors = [];
@billeisenhauer
billeisenhauer / feedback.js
Created November 8, 2011 02:10
Backbone Controller
TRIPCASE.controllers.Feedback = TRIPCASE.Controller.extend({
init: function(options) {
_.bindAll(this, "_onCreate");
},
/* Actions */
feedback: function() {
var feedback = new TRIPCASE.models.Feedback();
# Class singleton methods to mix into ActiveRecord.
module SingletonMethods # :nodoc:
# Extends the existing find method in potentially two ways:
# - If a mappable instance exists in the options, adds a distance column.
# - If a mappable instance exists in the options and the distance column exists in the
# conditions, substitutes the distance sql for the distance column -- this saves
# having to write the gory SQL.
def find(*args)
options = extract_options_from_args!(args)
origin = extract_origin_from_options(options)