Skip to content

Instantly share code, notes, and snippets.

//
// NSObject+AssociatedObjects.m
//
// Created by Andy Matuschak on 8/27/09.
// Public domain
//
// edited by rebo to add message forwarding, so extended objects can call zero-argument void
// blocks using [instance method] format.
//
// Not really recommended as this produces "may not respond" warnings in compiler.
// setting up the binding for my table here, this works ok:
contentBinding: 'Training.operativesController.arrangedObjects',
selectionBinding: 'Training.operativesController.selection',
// then trying to access the selection in the console gets this:
Training.operativesController.selection.get('firstObject')
TypeError: Result of expression 'Training.operativesController.selection.get' [undefined] is not a function.
nameValue: SC.LabelView.design({
layout: {
top: 30,
left: 125,
height: 24,
width: 200
},
valueBinding: "Training.operativesController.get('selection').get('firstObject').get('name')"
})
var operatives = Training.store.find(Training.OPERATIVES_QUERY).toArray();
console.log('Loading operatives');
Training.operativesController.set('content', operatives);
class Employee < ActiveRecord::Base
has_many :events
def self.in_on_date(date)
Event.where(:date => date).map{ |e| e.employee.name }.uniq
end
def book_in_date!(date)
self.events.build(:date => date)
self.save!
class AttributeAccessor < Module
def initialize(name)
@name = name
@name_ivar = "@#{@name}"
end
def included(model)
super
define_accessors
@rebo
rebo / dci_stuff.rb
Created September 4, 2012 15:01
DCI and Simple Facades
#
# Comparison of a dumb facade implementation to #extend.
# The principle advantage is that with caching it might be quicker that #extend,
# and it isolates the data_object so no behaviour
# changes persist after a context is finished.
#
require 'benchmark'
require 'singleton'
@rebo
rebo / gist:4035073
Created November 7, 2012 22:46
saga outline
class CreatePartyAccountOrderSaga < Saga
attr_reader :saga_info
def initialize(saga_id, party_attributes, account_attributes, order_attributes)
@saga_id = saga_id;
start(party_attributes, account_attributes, order_attributes)
end
def start(party_attributes, account_attributes, order_attributes)
fiber_based_workflow do
party_id = saga_exec("Creating Party..."){CreateParty.execute(*party_attributes)}
raise CreatePartyFailedError, "Party Creation Failed" if timeout?
require 'alias_dci'
class Article < Struct.new(:subject,:body);end
class TextView
attr_reader :contents
def initialize
@contents = ""
end
end
require 'alias_dci'
class Battle
include AliasDCI::Context
role :lion do
def fight
p "#{name}: RAWR, I am a lion and I run fast."
end
end