Skip to content

Instantly share code, notes, and snippets.

View guifromrio's full-sized avatar

Guilherme Rodrigues guifromrio

View GitHub Profile
@guifromrio
guifromrio / registry-report.coffee
Created February 12, 2015 17:15
Simple report for number of versions for each app in registry.json
_ = require 'underscore'
registry = require './registry.json'
console.log 'Existing packages: ' + Object.keys(registry).length
console.log 'Grouped by appType:'
groupedByAppType = _.groupBy registry, 'appType'
for k, v of groupedByAppType
console.log k, v.length
// View (a template)
<p>First name: <input data-bind=”value: firstName” /></p>
<p>Last name: <input data-bind=”value: lastName” /></p>
<h2>Hello, <span data-bind=”text: fullName”> </span>!</h2>
// ViewModel (diplay data… and logic?)
var ViewModel = function(first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);
// View (a template)
<div ng-controller=”HelloController as hello”>
<label>Name:</label>
<input type=”text” ng-model=”hello.firstName”>
<input type=”text” ng-model=”hello.lastName”>
<h1>Hello {{hello.fullName()}}!</h1>
</div>
// Controller
angular.module(‘helloApp’, [])
var Hello = React.createClass({displayName: "Hello",
render: function() {
return React.createElement("div", null, "Hello ", this.props.name);
}
});
React.render(
React.createElement(Hello, {name: "World"}),
document.getElementById('container')
);
var Hello = React.createClass({
render: function() {
return <div>Hello {this.props.name}</div>;
}
});
React.render(
<Hello name=”World” />,
document.getElementById(‘container’)
);
var CommentList = React.createClass({
render: function() {
var commentNodes = this.props.data.map(function (comment) {
return (
<Comment author={comment.author}>
{comment.text}
</Comment>
);
});
return (
var array = [{name: "Foo", points: 1}, {name: "Bar", points: 3}];
var increasePoints = function (player) {
player.points++;
};
var i;
for (i = 0; i < array.length; i++) {
increasePoints(array[i]);
}
var array = [{name: "Foo", points: 1}, {name: "Bar", points: 3}];
var value, i;
for (i = 0; i < array.length; i++) {
value = array[i];
value.points++;
}
console.log(array) // [{name: "Foo", points: 2}, {name: "Bar", points: 4}]
var array = [{name: "Foo", points: 1}, {name: "Bar", points: 3}];
var increasePoints = function (player) {
player.points++;
};
_.each(array, increasePoints); // MAGIC!
var array = [{name: "Foo", points: 1}, {name: "Bar", points: 3}];
var increasePoints = function (player) {
return {name: player.name, points: player.points + 1};
};
var newArray = [];
_.each(array, function (player) {
newArray.push(increasePoints(player));
});
// array is undisturbed! a little clunky, though...