Skip to content

Instantly share code, notes, and snippets.

View dferber90's full-sized avatar

Dominik Ferber dferber90

View GitHub Profile
@dferber90
dferber90 / .eslintrc.json5
Created June 3, 2015 10:22
ESLint file for Meteor with ES6
{
// This file should actually be called '.eslintrc'
// Create it at the root directory of your Meteor app
// I want to use babel-eslint for parsing!
"parser": "babel-eslint",
"env": {
// I write for browser
"browser": true,
@dferber90
dferber90 / arrows.es5.js
Last active August 29, 2015 14:22
arrows in es5
// ES5
Template.stats.onCreated(function () {
var self = this;
this.autorun(function () {
var filter = { limit: Session.get('options.limit') };
self.subscribe('tweets', filter);
});
});
@dferber90
dferber90 / arrows.es6.js
Last active August 29, 2015 14:22
arrows in es6
// ES6
Template.stats.onCreated(function () {
this.autorun(() => {
const filter = { limit: Session.get('options.limit') };
this.subscribe('tweets', filter); // same "this" as in line 3
});
});
@dferber90
dferber90 / versions.es5.js
Last active August 29, 2015 14:22
Versions Parsing in ES5
// ES5
var versionsMap = {};
lines.forEach(function (line) {
// split name@version into [name, version]
var lineContents = line.split('@');
var name = lineContents[0];
var version = lineContents[1];
versionsMap[name] = version;
});
@dferber90
dferber90 / versions1.es6.js
Last active August 29, 2015 14:22
Versions Parsing in ES6, Attempt 1
// ES6
const versionsMap = new Map();
lines.forEach((line) => {
const [name, version] = line.split(‘@’); // destructuring
versionsMap.set(name, version);
});
@dferber90
dferber90 / versions2.es6.js
Last active August 29, 2015 14:22
Versions Parsing in ES6, Attempt 2
// ES6
const versionsMap = new Map();
lines.forEach( line => versionsMap.set(...line.split(‘@’)) );
@dferber90
dferber90 / rest.es5.js
Last active August 29, 2015 14:22
Rest Operator
// ES5
UI.registerHelper('sum', function (/* arguments */) {
var summands = Array.prototype.slice.call(arguments);
summands.pop(); // remove last argument hash (Spacebars.kw)
var sum = 0;
for (var i = 0; i < summands.length; i++) {
sum += summands[i];
}
return sum;
});
@dferber90
dferber90 / rest.es6.js
Last active August 29, 2015 14:22
Rest Operator in ES6
// ES6
UI.registerHelper('sum', function (...summands) {
summands.pop(); // remove last argument hash (Spacebars.kw)
return summands.reduce((previousValue, currentValue) => {
return previousValue + currentValue;
});
});
@dferber90
dferber90 / eol.es6.js
Last active August 29, 2015 14:22
Enhanced Object Literals
// ES6
Template.lead.helpers({
twitterLink () {
return this.getTwitterLink();
},
weekday (timestamp) {
return moment(timestamp).format(‘dddd’);
}
});
@dferber90
dferber90 / class.es6.js
Last active November 14, 2015 14:03
Class
// ES6
class Tweet {
constructor (doc) {
_.extend(this, doc);
}
}
Tweets = new Mongo.Collection('tweets', {
transform (doc) {
return new Tweet(doc);