Skip to content

Instantly share code, notes, and snippets.

View mplatts's full-sized avatar

Matt Platts mplatts

View GitHub Profile
@mplatts
mplatts / games.coffee
Last active April 10, 2016 20:34
templates2 - 1
# lib/collections/games.coffee
@Games = new Mongo.Collection('games')
@mplatts
mplatts / fixtures.coffee
Created November 26, 2014 02:05
templates2 - 2
# server/fixtures.coffee
if Teams.find().count() == 0
_([
{name: 'Barcelona'}
{name: 'Manchester City'}
]).each (data) -> Teams.insert(data)
if Games.find().count() == 0
game = {
@mplatts
mplatts / games.coffee
Last active April 10, 2016 20:33
templates2 - 3
# client/views/games.coffee
Template.games.helpers
games: -> Games.find()
@mplatts
mplatts / games.html
Created November 27, 2014 02:19
templates2 - adding games
<!-- client/views/games.html -->
<template name="games">
<h3>Games</h3>
{{#if creating}}
<form class="form-create">
<select name="teamOne">
{{#each teams}}
<option value="{{_id}}">{{name}}</option>
{{/each}}
@mplatts
mplatts / games.coffee
Last active April 10, 2016 20:31
templates2 - games.coffee
# client/views/games.coffee
Template.games.helpers
teams: -> Teams.find()
games: -> Games.find()
creating: -> Session.get 'creating-game'
Template.games.events
"click .create": (e, tpl) ->
e.preventDefault()
@mplatts
mplatts / games.coffee
Last active August 29, 2015 14:10
templates2 - create game method
# client/views/games.coffee
Template.games.helpers
teams: Teams.find()
games: Games.find()
creating: -> Session.get 'creating-game'
Template.games.events
"click .create": (e, tpl) ->
e.preventDefault()
@mplatts
mplatts / game.coffee
Created November 27, 2014 03:38
templates 2 - edit games
# client/views/game.coffee
Template.game.events
"click .finish-game": (e, tpl) ->
e.preventDefault()
Games.update({_id: @_id}, {$set: {completed: true}})
"click .delete-game": (e, tpl) ->
Games.remove(@_id)
@mplatts
mplatts / inheritance.js
Created December 7, 2014 00:16
Standard inheritance in Javascript
function MyClass(){
}
MyClass.prototype.method = function(){}
function MySubClass(){
// use MyClass as the constructor
MyClass.call(this);
}
// 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 / myView.js
Last active August 29, 2015 14:10
Famo.us view template
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({