Skip to content

Instantly share code, notes, and snippets.

@Streemo
Streemo / sendMany.js
Created July 28, 2016 18:41
Instead of doing N findOne operations, do a single find operation. Could add some code to explicitly handle 1 vs. N, but it's cleaner to just use arrays for everything, including single elements.
send(m){
if (m.numbers){
m.numbers.forEach((number)=>{
this._sendSMS(m.text, number);
})
} else {
let sentTo = [];
Devices.find({userId: {$in: m.users}}).forEach((device) => {
const devId = this._sendNotification(device, m.title, m.text, m.data);
devId && sentTo.push(devId)
@Streemo
Streemo / gist:e3a54ff724c2e9a3de8218c5756abf31
Created July 28, 2016 18:39
if many users included, don't do N `findOne` operations. Instead, do a single `find` followed by a `forEach`
send(m){
if (m.numbers){
m.numbers.forEach((number)=>{
this._sendSMS(m.text, number);
})
} else {
let sentTo = [];
Devices.find({userId: {$in: m.users}}).forEach((device) => {
const devId = this._sendNotification(device, m.title, m.text, m.data);
devId && sentTo.push(devId)
@Streemo
Streemo / gist:2c6953f4d8a775d826f7185a5a6f2a52
Created July 24, 2016 19:30
Unified SMS/Push Notification API (android + ios + text messaging), ~WIP
import { Messages } from "./Notifications.js" //import
//uses AWS SNS under the hood for all payload delivery
//send a push notification
//will determine whether or not to send to android or ios automatically.
Messages.send({
title: "This is a short Title",
text: "This is the body of the message and is expected to be more detailed and most likely longer...",
users: ["userId1", "userId2", ...],
@Streemo
Streemo / gist:58fbfa370976c183897455b2e52d7c97
Created July 24, 2016 19:30
Unified SMS/Push Notification API (android + ios + text messaging), ~WIP
import { Messages } from "./Notifications.js" //import
//uses AWS SNS under the hood for all payload delivery
//send a push notification
//will determine whether or not to send to android or ios automatically.
Messages.send({
title: "This is a short Title",
text: "This is the body of the message and is expected to be more detailed and most likely longer...",
users: ["userId1", "userId2", ...],
@Streemo
Streemo / gist:cbf5368ccea1a3bf061a
Created May 30, 2015 09:01
do i need to delete the reference before reassingning a value to the key?
//all of this code is in a function.
var docs = Meals.aggregate(pipeline)
var oldData = Cache.regulars.data
var newData = {};
docs.forEach(function(doc){
var id = doc._id
var raw = _.omit(doc,'_id');
newData[id] = raw
var oldDoc = oldData[id]
//ensure that the user does not put in too many '/' and ensures that only
//underground blips can be subblips of underground blips.
cleanPath = function(path){
return path.split('/').reduce(function(prev,curr){
if (curr!=''){
if (prev.search('_')>-1){
if (curr.search('_')>-1){
return prev+=curr+'/';
} else {
return prev+='_'+curr+'/';
Router.map(function(){
this.route('subscriptions', {
path: '/'
});
this.route('home', {
path: '/files/:file(*)'
});
});
Router.map(function(){
this.route('route1', {
path: '/',
template: 'subscriptions',
action: function(){
this.render();
}
});
this.route('route2', {
path: '/files/*',
Router.route('myRoute', {
path: '/files/:file(*)',
action: function(){
this.render('home');
}
});
Router.route('/files/:file(*)', {
action: function(){
this.render('home');
}
});