Skip to content

Instantly share code, notes, and snippets.

Avatar

Streemo Streemo

View GitHub Profile
@Streemo
Streemo / sendMany.js
Created Jul 28, 2016
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.
View sendMany.js
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 Jul 28, 2016
if many users included, don't do N `findOne` operations. Instead, do a single `find` followed by a `forEach`
View gist:e3a54ff724c2e9a3de8218c5756abf31
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 Jul 24, 2016
Unified SMS/Push Notification API (android + ios + text messaging), ~WIP
View gist:2c6953f4d8a775d826f7185a5a6f2a52
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 Jul 24, 2016
Unified SMS/Push Notification API (android + ios + text messaging), ~WIP
View gist:58fbfa370976c183897455b2e52d7c97
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
do i need to delete the reference before reassingning a value to the key?
View gist:cbf5368ccea1a3bf061a
//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]
View gist:09c09e18817a0f17e455
//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+'/';
View gist:5939863ee180327e0050
Router.map(function(){
this.route('subscriptions', {
path: '/'
});
this.route('home', {
path: '/files/:file(*)'
});
});
View gist:3589de15a0399e2960e9
Router.map(function(){
this.route('route1', {
path: '/',
template: 'subscriptions',
action: function(){
this.render();
}
});
this.route('route2', {
path: '/files/*',
View gist:d7bc08e62c52cf837154
Router.route('myRoute', {
path: '/files/:file(*)',
action: function(){
this.render('home');
}
});
View gist:b9b3afeb9231a2542b7c
Router.route('/files/:file(*)', {
action: function(){
this.render('home');
}
});
You can’t perform that action at this time.