Skip to content

Instantly share code, notes, and snippets.

View AlexFrazer's full-sized avatar
🦊
🦊🦊🦊

Frazer AlexFrazer

🦊
🦊🦊🦊
View GitHub Profile
/**
* 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
*/
@AlexFrazer
AlexFrazer / childController.js
Created May 13, 2015 17:29
Extending data with iron:router controllers
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: {
{
// 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)),
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({
// 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 ]
}]
/**
* 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'];
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({
Restivus.addRoute('/order/update', {
role_required: 'admin',
auth_required: true
}, {
post: function () {
var self = this;
Orders.update(self.bodyParams.cardId, {
$set: {
"status": "completed",
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()
// 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
});