Skip to content

Instantly share code, notes, and snippets.

Blaze.registerHelper('ifEqualReturn', function (cond1, cond2, first, second) {
return cond1 === cond2 ? first : second;
});
@davidworkman9
davidworkman9 / router.js
Last active August 29, 2015 14:07
Drop in support for subpaths in iron-router.
(function () {
var url = Meteor.absoluteUrl();
url = url.replace(/https?:\/\//, '');
var slash = url.indexOf('/');
var subpath = url.substring(slash);
subpath = subpath.substring(0, subpath.length-1);
var oldRoute = Router.route;
Router.route = function (name, options) {
arguments[1].path = subpath + options.path;
return oldRoute.apply(this, arguments);
Blaze.registerHelper('isEqual', function (lhs, rhs) {
return lhs === rhs;
});
@davidworkman9
davidworkman9 / ignoreDirs.js
Created October 8, 2014 13:14
Generate Webstorm ignores for .build directories in Meteor
#!/usr/bin/env node
var fs = require('fs');
console.log('Copy the following into .idea/PROJECT_NAME.iml inside of module>component>content:\n');
console.log(
['<excludeFolder url="file://$MODULE_DIR$/app/.meteor" />'].concat(
// read the packages directory
fs.readdirSync(process.argv[2] || 'packages')
// filter out hidden folders/files
.filter(function (d) {
return d[0] !== '.';
@davidworkman9
davidworkman9 / tmpl.html
Created June 13, 2014 20:14
Customizing data passed into a blaze template
<template name="main">
{{> my_tmpl op1=5 op2=10 }}
</template>
<template name="my_tmpl">
{{#with newData}}
{{#with}}
</template>
<template name="adminMenu">
<div class="container container-full">
<h3 class="text-center">Admin Console</h3>
<div class="row">
<div class="col-md-12 margin_none">
<div class="panel-group fullSizedAdminMenu">
{{#each sections}}
{{#if canSeeAtLeastOnePage}}
{{>adminAccordionSection}}
{{/if}}
@davidworkman9
davidworkman9 / allowPositional.js
Last active August 29, 2015 13:56
Proposal for how the positional operator could be allowed in untrusted code in Meteor
function allowedSelector(selector, updateStatement) {
var selectors = [];
var allowed = true;
_.each(Object.keys(selector), function (key) {
var matcher;
if (key !== '_id') {
var parts = key.split('.')
matcher = parts.length > 1 ? new RegExp('^' + escapeRegex(parts[0] + '.$.') + '[A-Za-z]+$') :
new RegExp('^' + escapeRegex(parts[0] + '.$') + '$');
if (!usesKey(matcher updateStatement)) {
/* global Tinytest:true */
/* global testAsyncMulti:true */
'use strict';
if (Meteor.isServer) {
Meteor.methods({
'remove-all-users': function () { return Meteor.users.remove({}); }
});
}
if(Meteor.isClient) (function () {
Meteor.methods({
average_sales: function(options) {
var self, start_day, total_sales, yesterday;
self = this;
this.unblock();
start_day = moment().tz("America/Los_Angeles").subtract("days", 77).startOf('day');
yesterday = moment().tz("America/Los_Angeles").subtract("days", 1).endOf("day");
total_sales = 0;
var query = {
_.each(large_array, function (el) {
setTimeout(function () {
// do calculation
}, 0);
});