Skip to content

Instantly share code, notes, and snippets.

@stephentcannon
stephentcannon / maxcstacksizeexceeded
Created May 18, 2012 11:12
Meteor collection maximum call stack size exceeded
var key = CryptoJS.AES.encrypt('test', 'password');
console.log('key: ' + key);
id = MyCollection.insert({
created: new Date(),
expires: expires,
key: key
}, function(error, result){
console.log('error: ' + error);
console.log('result: ' + error);
});
@stephentcannon
stephentcannon / ftvi
Created May 26, 2012 10:01
findOne template view issue
//all of this is client side
//some of the concept is taken from
//http://stackoverflow.com/questions/10167464/meteor-rendering-template-with-a-document-from-a-collection/10167515#comment13990810_10167515
//collection setup
myCollection = new Meteor.Collection('myCollection');
//subscription is working
//the entire contents render perfectly in a template that shows all records
//it shows changes made server side or client side
@stephentcannon
stephentcannon / gist:3396983
Created August 19, 2012 18:44
Meteor controller, action dynamic query
//this is used on a toggleChild function to add or remove mongo child relationships
//it works fine when for $pull but $addToSet doesn't ever seem to get sent to the server
if(window[Meteor.request.controller.capitalise()]["find"](query).count() == 0){
children[child_collection_name] = child;
modifiers['$addToSet'] = children;
modifiers['$set'] = { client_updated: ts };
} else if (window[Meteor.request.controller.capitalise()]["find"](query).count() == 1){
children[child_collection_name] = child;
@stephentcannon
stephentcannon / gist:3409103
Created August 20, 2012 23:17
Moment.js handlebars helper
// format an ISO date using Moment.js
// http://momentjs.com/
// moment syntax example: moment(Date("2011-07-18T15:50:52")).format("MMMM YYYY")
// usage: {{dateFormat creation_date format="MMMM YYYY"}}
Handlebars.registerHelper('dateFormat', function(context, block) {
if (window.moment) {
var f = block.hash.format || "MMM DD, YYYY hh:mm:ss A";
return moment(context).format(f); //had to remove Date(context)
}else{
return context; // moment plugin not available. return data as is.
// make sure we're using the right db; this is the same as "use aggdb;" in shell
db = db.getSiblingDB("aggdb");
// simple projection
var p1 = db.runCommand(
{ aggregate : "article", pipeline : [
{ $project : {
tags : 1,
pageViews : 1
}}
@stephentcannon
stephentcannon / meteorexecflow.js
Last active December 15, 2015 01:49
Meteor execution flow issue
// CLIENT SIDE
// kicks off process by inserting process/report request into
vat ts = new Date();
var options =
{ start_date: '03/17/2013',
end_date: '03/18/2013',
client_updated_td: ts,
};
Commissions.insert(doc);
#!/bin/bash
# __
# _____ ____ _/ |_ ____ ____ _______
# / \ _/ __ \ \ __\_/ __ \ / _ \ \_ __ \
# | Y Y \\ ___/ | | \ ___/ ( <_> ) | | \/
# |__|_| / \___ > |__| \___ > \____/ |__|
# \/ \/ \/
#
# .___
# __| _/ __ __ _____ ______
#!/bin/bash
# __
# _____ ____ _/ |_ ____ ____ _______
# / \ _/ __ \ \ __\_/ __ \ / _ \ \_ __ \
# | Y Y \\ ___/ | | \ ___/ ( <_> ) | | \/
# |__|_| / \___ > |__| \___ > \____/ |__|
# \/ \/ \/
#
# .___
# __| _/ __ __ _____ ______

##Meteor Latency Compensation - The Correct Way

This is a kind of correction I wan't make regards to the concept describe in discover-meteor book

For the latency compensation to occur we cloud simply share the same method in the client/server. We can do this by simply putting the method under a place which can see by bot the server and client.

But practically(not all the time) we should not do that. In the server code we might have some logic which should not share. Or simply we might have some secret tokens.

So the correcy approach is define the method (in this case post) seperately in the two context. as shown below

@stephentcannon
stephentcannon / Templates rendering
Created February 13, 2014 19:10
What meteor templates are rendering
function logRenders () {
_.each(Template, function (template, name) {
var oldRender = template.rendered;
var counter = 0;
template.rendered = function () {
console.log(name, "render count: ", ++counter);
oldRender && oldRender.apply(this, arguments);
};
});