Skip to content

Instantly share code, notes, and snippets.

class SomeService
def initialize(some_dependency)
@some_dependency = some_dependency
end
def some_event(value)
@some_dependency.another_event(value.increase_value)
end
end
class CommentsController < ApplicationController
def create
translator.translate params
end
private
def translator
CommentRequestTranslator.new(processor)
class SomeController < ApplicationController
...
def update
ui = SomeViewAdapter.new
domain = SomeDomain.new(ui)
translator = SomeRailsAdapter.new(domain)
translator.some_action(params)
#some processing based upon ui values in order to know what view to render, etc
end
@gmoeck
gmoeck / example.js
Created June 12, 2012 16:29
Extremely Late binding
/* Imagine that you have a publish/subscribe system where you want a publisher to publish messages to a set of subscribers. There are two ways that you can specify the message to send, with a function to call on the object, and with a string.*/
//Functional subscription (Essentially a partially applied function)
publisher.addListener('someEvent', subscriber.someResult, subscriber);
//This ends up having code that looks something like this:
addListener: function(eventName, functionToCall, subscriber) {
this._events[eventName].push({functionToCall: functionToCall, context: subscriber});
},
...
invoke: function(eventName, data) {
var matchersForFilter = function(properties) {
var attributes = util.keys(properties);
var attributesFilters = util.values(properties);
var arraysWithAttributeAndAttributesFilters = util.zip(attributes,
attributesFilters);
var arrayOfMatchersForAttribute =
util.map(arraysWithAttributeAndAttributesFilters, matchersForAttribute);
var matchers = util.flatten(arrayOfMatchersForAttribute, true);
var Deferred = require('shared/deferred').Deferred;
var Repository = require('shared/repository').Repository;
...
{{#if booleanA}}
{{propertyA}}
{{/if}}
{{#if booleanB}}
{{propertyB}}
{{/if}}
//should be
@gmoeck
gmoeck / started.js
Created July 18, 2011 16:09
Started State
App.StartedState = SC.State.extend({
enterState: function() {
//do some stuff
this.setupRoutes();
},
exitState: function() {
//remove some stuff
},
@gmoeck
gmoeck / output.html
Created June 25, 2011 17:52
table_example.handlebars
<table>
<tbody tabindex="-1" id="sc201" class="">
<tr tabindex="-1" id="sc210" class="" style="">
<td tabindex="-1" id="sc214" class="" style=""><span tabindex="-1" id="sc216" class="" style="">something</span></td>
<td tabindex="-1" id="sc220" class="" style=""><span tabindex="-1" id="sc221" class="" style="">new</span></td>
</tr>
<tr tabindex="-1" id="sc225" class="" style="">
<td tabindex="-1" id="sc228" class="" style=""><span tabindex="-1" id="sc229" class="" style="">something</span></td>
<td tabindex="-1" id="sc232" class="" style=""><span tabindex="-1" id="sc233" class="" style="">else</span></td>
</tr>
list: SC.ScrollView.extend({
layout: {height:190},
contentView: SC.TemplateCollectionView.extend({
contentBinding: 'TW.homePageTabsController.contentRecentSearches',
itemView: SC.TemplateView.extend(TW.ItemViewSelectionSupport, {
templateName: 'home_page_tabs_recent_search_item',
classNames: ['simple-link-row'],
performAction: function() {
TW.statechart.sendEvent('performRecentSearch', this.get('content'));