This file contains 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
/** | |
* Helpers applying to EVERY mongo collection in my db | |
*/ | |
Mongo.Collection.prototype._utilities = function() { | |
var self = this; | |
/** | |
* return all the ids of the items in this collection | |
* @returns {Array} all the ids in this collection | |
*/ |
This file contains 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
ChildController = ParentController.extend({ | |
showItem: function () { | |
/** | |
* Here is the problem. | |
* I want to implicitly pass the "group" to EVERY rendered route | |
* Is it possible to do this? | |
*/ | |
var group = ChildController.__super__.data.call(); | |
this.render('itemPage', { | |
data: { |
This file contains 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
{ | |
// type as in the primitive type of the data | |
type: Match.Any, | |
// label on the form | |
label: Match.Optional(Match.OneOf(String, Function)), | |
// is it required to be submitted or not | |
optional: Match.Optional(Match.OneOf(Boolean, Function)), | |
// these four are self-explanatory. | |
min: Match.Optional(Match.OneOf(Number, Date, Function)), | |
max: Match.Optional(Match.OneOf(Number, Date, Function)), |
This file contains 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
Games = new Mongo.Collection("games"); | |
if (Meteor.isClient) { | |
Template.leaderboard.helpers({ | |
/** | |
* For user 'corvid', this should return both 'starcraft' and 'warcraft' | |
* because he is a player in the Roles.GLOBAL_GROUP | |
*/ | |
games: function () { | |
return Games.find({ |
This file contains 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
// my data structure | |
[{ | |
forkedFrom: "1234", | |
days: [ 0, 1, 2, 3, 4, 5, 6 ], | |
timesOfDay: [ 0, 1 ] | |
}, { | |
forkedFrom: "5678", | |
days: [ 0, 1, 2, 3, 4, 5, 6 ], | |
timesOfDay: [ 0 ] | |
}] |
This file contains 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
/** | |
* After an order is updated, add that data to the feed | |
*/ | |
Orders.after.update(function (userId, doc, modifier) { | |
// this is tedious | |
var user = Meteor.users.findOne(doc.userId); | |
// for payment status | |
if (_.has(modifier, ['$set', 'payment.status'])) { | |
var status = modifier.$set['payment.status']; |
This file contains 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
Meteor.methods({ | |
'Order.createShipment': function (order) { | |
check(order, Orders.simpleSchema()); | |
if (this.userId !== order.userId) { | |
throw new Meteor.Error(401, "Cannot create shipment for order."); | |
} | |
var EasyPost = Easypost(process.env.EASYPOST_KEY); | |
var response = Async.runAsync(function (done) { | |
EasyPost.Shipment.create({ |
This file contains 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
Restivus.addRoute('/order/update', { | |
role_required: 'admin', | |
auth_required: true | |
}, { | |
post: function () { | |
var self = this; | |
Orders.update(self.bodyParams.cardId, { | |
$set: { | |
"status": "completed", |
This file contains 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
import requests | |
import argparse | |
class ApiInterpreter(object): | |
def __init__(self, version="v1"): | |
self.version = version | |
def get(self, endpoint, data={}): | |
return requests.get(self.base_url.format(version=self.version, endpoint=endpoint), data=data, headers=self.headers).json() |
This file contains 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
// client | |
// ApiV1.login returns a userId and token given the right email and password | |
Meteor.loginWithApi = function (email, password, callback) { | |
ApiV1.login(email, password) | |
.then(function (response) { | |
Accounts.callLoginMethod({ | |
api: true, | |
token: response.data.token, | |
userId: response.data.userId | |
}); |