Skip to content

Instantly share code, notes, and snippets.

View flarnie's full-sized avatar

Flarnie Marchan flarnie

View GitHub Profile
@flarnie
flarnie / todo_mvc_demo_spec.rb
Last active August 29, 2015 13:57
A demo feature spec that will run on the ToDoVMC:Backbone.js Demo if capybara and selenium are correctly set up.
require 'spec_helper'
describe "ToDoMVC:Backbone.js" do
# the following is a demo spec for demonstration purposes
# it is meant to run on the ToDoMVC:Backbone.js Demo app:
# http://todomvc.com/architecture-examples/backbone/
it "allows creation of a todo-list item", :js => true do
visit "http://todomvc.com/architecture-examples/backbone/"
fill_in "new-todo", with: "TODOITEM Hello World\n"
@flarnie
flarnie / es-6-transpiler-example.js
Last active August 29, 2015 14:05
ES6 transpiler example: how webpack's es-6-loader transforms our ES6 code.
// ES6 syntax
postsCollection.each((post) => {
if (post.get('highlighted')) {
this.highlightedPosts.push(post);
}
});
// The translated version output by webpack
var this$0 = this;
@flarnie
flarnie / installing-webpack
Created August 15, 2014 17:53
Installing webpack from the command line
npm install webpack -save
@flarnie
flarnie / _application.js
Last active August 29, 2015 14:05
Example files for explanation of webpack
require('./init.js');
@flarnie
flarnie / application.js
Last active August 29, 2015 14:05
How to include js-routes
// ...
//= require js-routes
// ...
@flarnie
flarnie / es6_block_scoping.js
Last active August 29, 2015 14:07
ES6 Block Scoping
// ES6 block scoping ('let' and 'const')
// 'let' example
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let
if (true) {
let foo = 'bar';
}
console.log(foo) // raises error: 'foo' is not defined
// Also prevents pass-by-reference errors in 'for' loops:
var funcs = [];
@flarnie
flarnie / es6_fat_arrow_functions.js
Last active August 29, 2015 14:07
ES6 Fat Arrow Functions
// ES6 "fat arrow functions"
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
// One-line shorthand
var sayHello = (name) => console.log('Hello ', name);
// Multi-line example
var sayHelloTwice = (name) => {
console.log('Hello ', name);
console.log('Hi again ', name);
};
@flarnie
flarnie / es6_template_literals.js
Last active August 29, 2015 14:07
ES6 Template Literals
// ES6 template literals
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings
var id = 3;
var componentType = 'widget';
var description = `This is ${componentType} number ${id}`;
// ES5 compatible syntax transpiled by es6-transpiler
// https://github.com/termi/es6-transpiler
var description = (("This is " + componentType) + (" number " + id) + "");
@flarnie
flarnie / es6_destructuring_assignment.js
Last active August 29, 2015 14:07
ES6 Destructuring Assignment
// ES6 Destructuring Assignment
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
var coordObj = { x: 10, y: -2 };
var coordArr = [10, -2];
// Unpack the object
var { x, y } = coordObj;
// Unpack the array
var [x, y] = coordArr;
@flarnie
flarnie / es6_for_of.js
Last active August 29, 2015 14:07
ES6 Iterating with for .. of loops
// ES6 Iterating with 'for .. of' loops
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
var arr = [1, 2, 3];
arr.foo = 'foo';
// WITH the 'for .. of' syntax
for (let item of arr) {
console.log(item); // logs 1, 2, and 3
}
// WITHOUT using the 'for .. of' syntax