Skip to content

Instantly share code, notes, and snippets.

Paul dagda1

Block or report user

Report or block dagda1

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View for.clj
; 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
View group.js
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);
View grouped2.js
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');
View serializer.rb
class UserSerializer < ActiveModel::Serializer
embed :ids
attributes :id
attributes :activity_ids
def activity_ids
{url: "/users/#{object.id}/activities"}
end
end
View .vimrc
augroup myvimrc
au!
au BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
augroup END
View reduce.js
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) {
View reduce-redux.js
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');
})
});
View brace.js
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');
})
});
View sp.js
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');
})
});
View aggregate.js
// 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() {
You can’t perform that action at this time.