Skip to content

Instantly share code, notes, and snippets.

@mplatts
mplatts / error.js
Created Aug 26, 2015
Meteor error explanation
View error.js
// see http://docs.meteor.com/#/full/meteor_error
var error = new Meteor.Error('error-name', 'reason');
alert(error) //=> Error: reason [error-name]
alert(error.reason) //=> reason
alert(error.error) //=> error-name
// Explanation.. alert(error) is the same as going alert(error.toString()), which results in "Error: error.reason [error.error]"
View underscore.coffee
array = [1,2,3,4]
_.each array, (item) ->
console.log item
# OR
_(array).each (item) ->
console.log item
@mplatts
mplatts / background-workers.coffee
Created Jun 4, 2015
meteor background job - recurring
View background-workers.coffee
if Meteor.isServer
class @TestJob extends Job
@setupCron: (parser) ->
parser.text('every 5 seconds')
handleJob: ->
console.log 'Job complete'
@mplatts
mplatts / background-workers.coffee
Created Jun 4, 2015
background job using meteor workers
View background-workers.coffee
if Meteor.isClient
Template.hello.events
'click button': ->
Meteor.call('loadJob')
if Meteor.isServer
class @TestJob extends Job
handleJob: ->
console.log 'Job complete'
@mplatts
mplatts / blockhelper.html
Last active Sep 19, 2015
templates - spacebar helpers
View blockhelper.html
<template name="headingWrapper">
<h1>{{> UI.contentBlock}}</h1>
<h4>{{this.subheading}}</h4>
</template>
<template name="main">
{{#headingWrapper subheading="My Subheading"}}
My Heading
{{/headingWrapper}}
</template>
@mplatts
mplatts / transitions.js
Last active Aug 29, 2015
animations 2 js version
View transitions.js
var createHooks;
createHooks = function(options) {
options = _.defaults(options, {
alwaysClass: '',
onscreenClass: '',
offscreenClass: '',
removeClass: '',
removeTimeout: 500,
insertTimeout: 500
@mplatts
mplatts / mod.js
Created Dec 8, 2014
Famo.us modifier cheatsheet
View mod.js
var mod = new Modifier({
origin: [0.5, 0],
align: [0.5, 0],
opacity: 0.3,
transform: Transform.translate(0, 10, 1) // can be a function that runs every tick
})
mod.transformFrom(transform); // evaluated every tick
mod.opacityFrom(0.3);
mod.originFrom(0.5);
@mplatts
mplatts / myView.js
Last active Aug 29, 2015
Famo.us view template
View myView.js
var Engine = famous.core.Engine;
var Surface = famous.core.Surface;
var View = famous.core.View;
var Modifier = famous.core.Modifier;
var MyView = function(){
// Run View as constructor first
View.call(this, arguments);
this.rootMod = new Modifier({
View classes.js
// if we keep using Object.create(parent), we might want the parent to
// have a constructor function so all children turn out the same
parent = {
constructor: function(name) {
this._name = name;
}
}
child1 = Object.create(parent);
@mplatts
mplatts / inheritance.js
Created Dec 7, 2014
Standard inheritance in Javascript
View inheritance.js
function MyClass(){
}
MyClass.prototype.method = function(){}
function MySubClass(){
// use MyClass as the constructor
MyClass.call(this);
}
You can’t perform that action at this time.