This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function findColor(canvas, targetColor) { | |
| const ctx = canvas.getContext("2d"); | |
| const width = canvas.width; | |
| const height = canvas.height; | |
| const imageData = ctx.getImageData(0, 0, width, height); | |
| const data = imageData.data; | |
| const [r, g, b, a] = targetColor; | |
| for (let y = 0; y < height; y++) { | |
| for (let x = 0; x < width; x++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (Meteor.isServer) { | |
| // Get connection object. | |
| var connection = Meteor.server; | |
| // Get connection constructor. | |
| var Connection = connection.constructor; | |
| // Get the original "apply" method. | |
| var originalMethod = Connection.prototype.apply; | |
| // Override the "apply" method. | |
| Connection.prototype.apply = function(name, args, options, callback) { | |
| if (!callback && typeof options === 'function') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defineRelation(Posts, Users, 'author', 'userId'); | |
| Template.Users.helpers({ | |
| posts: function() { | |
| return Posts.find({}, { | |
| sort: { | |
| 'author.name': 1 | |
| } | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var defineRelation = function( | |
| Collection, RelatedCollection, relationName, relatedFieldName | |
| ) { | |
| Collection._computations = Collection._computations || {}; | |
| var comps = Collection._computations[relationName] = {}; | |
| var stop = function(doc) { | |
| if (comps[doc._id]) { | |
| comps[doc._id].stop(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Template.Users.helpers({ | |
| // Fetch posts and corresponding authors | |
| var posts = Posts.find().fetch(); | |
| posts.forEach(function(post) { | |
| post.author = Users.findOne(post.userId); | |
| }); | |
| // Sort posts by a give field | |
| posts.sort(function(a, b) { | |
| if (a.get('author.name') < b.get('author.name')) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Template.Users.helpers({ | |
| posts: function() { | |
| return Posts.find({}, { | |
| sort: { | |
| 'author.name': 1 | |
| } | |
| }); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| User = Astro.Class({ | |
| name: 'User', | |
| fields: { | |
| name: 'string' | |
| } | |
| }); | |
| Posts = new Mongo.Collection('posts'); | |
| Post = Astro.Class({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Users = new Mongo.Collection('users'); | |
| User = Astro.Class({ | |
| name: 'User', | |
| collection: Users, | |
| fields: { | |
| name: 'string' | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var autoIncSave = function(doc, fieldName) { | |
| while (true) { | |
| var Class = doc.constructor; | |
| var Collection = Class.getCollection(); | |
| var sort = {}; | |
| var fields = {}; | |
| sort[fieldName] = -1; | |
| fields[fieldName] = 1; |