Skip to content

Instantly share code, notes, and snippets.

View dagda1's full-sized avatar

Paul dagda1

View GitHub Profile
@dagda1
dagda1 / for.clj
Last active August 28, 2015 20:49
; xs = '{a {p 1, q 2} b {m 3, n 4}}
(for [[x y] xs]
(for [[a b] y]
[[a x] b]))
; this produces
; (({[a p] 1} {[a q] 2}) ({[b m] 3} {[b n] 4}))
;
; I require
App.computed.groupable = function(dependentKey, groupBy){
var options = {
initialValue: [] ,
initialize: function(array, changeMeta, instanceMeta){
},
addedItem: function(array, item, changeMeta, instanceMeta){
var key = groupBy(item);
var group = array.findBy('key', key);
groupedDeals: Ember.arrayComputed('contacts', 'deals.@each.status', {
initialValue: [],
initialize: function(array, changeMeta, instanceMeta) {
array.pushObject(Ember.Object.create({key: 'open',name: 'Open Deals',count: 0,value: 0,deals: Ember.A()}));
array.pushObject(Ember.Object.create({key: 'closed',name: 'Closed Deals',count: 0,value: 0,deals: Ember.A()}));
array.pushObject(Ember.Object.create({key: 'lost',name: 'Lost Deals',count: 0,value: 0,deals: Ember.A()}));
},
addedItem: function(array, deal, changeMeta, instanceMeta) {
var contact = deal.get('contact');
class UserSerializer < ActiveModel::Serializer
embed :ids
attributes :id
attributes :activity_ids
def activity_ids
{url: "/users/#{object.id}/activities"}
end
end
augroup myvimrc
au!
au BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
augroup END
App.CompanyItemController = Ember.ObjectController.extend({
total: Ember.reduceComputed("deals.@each.{status,value}", {
initialValue: 0,
addedItem: function(accumulatedValue, item, changeMeta, instanceMeta) {
if (item.get('state') === 'lost') {
return accumulatedValue;
}
return accumulatedValue + item.get('value');
},
removedItem: function(accumulatedValue, item, changeMeta, instanceMeta) {
App.CompanyItemController = Ember.ObjectController.extend({
openDeals: Ember.computed.filter('deals.@each.{status,value}', function(item){
return item.get('state') !== 'lost';
}),
opendDealsValues: Ember.computed.mapBy('openDeals', 'value'),
total: Ember.computed.sum("opendDealsValues"),
dealTotals: App.computed.groupable('deals',function(deal){
return deal.get('state');
})
});
@dagda1
dagda1 / brace.js
Last active August 29, 2015 13:56
App.CompanyItemController = Ember.ObjectController.extend({
openDeals: Ember.computed.filter('deals.@each.{status,value}', function(item){
return item.get('state') !== 'lost';
}),
total: Ember.computed.sum("opendDealsValues"),
dealTotals: App.computed.groupable('deals',function(deal){
return deal.get('state');
})
});
@dagda1
dagda1 / sp.js
Created February 22, 2014 10:35
App.CompanyItemController = Ember.ObjectController.extend({
openDeals: Ember.computed.filter('deals.@each.{status,value}', function(item){
return item.get('state') !== 'lost';
}),
total: Ember.computed.sum("opendDealsValues"),
dealTotals: App.computed.groupable('deals',function(deal){
return deal.get('state');
})
});
// USAGE
// App.SomeModel = DS.Model.extend ({
// users: DS.hasMany('users'),
// contacts: DS.hasMany('contacts')
// // Aggregate users and contacts into one array
// people: App.computed.aggregate('users', 'contacts')
// })
//
App.computed.aggregate = function() {