Skip to content

Instantly share code, notes, and snippets.

View wilk's full-sized avatar

Vincenzo Ferrari wilk

View GitHub Profile
@wilk
wilk / blocked-scope-function
Created July 1, 2015 20:47
Blocked-Scope Function
{
function num() {return 1}
{
function num() {return 5}
console.log(num()) // 5
}
console.log(num()) // 1
}
@wilk
wilk / arrow-functions
Created July 3, 2015 05:55
Arrow functions
var numbers = [0,1,2,3,4]
var increments = numbers.map(num => ++num) // [1,2,3,4,5]
@wilk
wilk / parameters
Last active August 29, 2015 14:25
ES6 Parameters
// Default Params
function sum(x = 10, y = 20) {
return x + y
}
console.log(sum()) // 30
// Rest Params
function sum(x, y, ...abc) { // ...abc = [30,40,50]
let total = abc.reduce((a,b) => a + b) // 30+40+50 = 120
@wilk
wilk / template-string
Created July 16, 2015 13:41
ES6 Template String
let sentence = `
multiline string
with tabulation
and carriage returns
`
console.log(sentence)
let name = 'Mario'
let template = `hello ${name}`
@wilk
wilk / object-properties
Created July 16, 2015 13:49
ES6 Object properties
let person = {
introduce() {
console.log('My name is Mario')
},
['say' + 'My' + 'Name']() {
console.log('Mario')
}
}
person.introduce() // My name is Mario
@wilk
wilk / destructuring
Created July 16, 2015 14:10
ES6 Destructuring
function people() {
return ['foo', 'bar', 'jar']
}
let [personFoo, personBar, personJar] = people()
console.log(personFoo, personBar, personJar) // foo bar jar
@wilk
wilk / class
Created July 16, 2015 14:46
ES6 Class
class Person {
constructor(name, surname) {
this.name = name
this.surname = surname
}
introduce() {
console.log(`Hi, my name is ${this.name} ${this.surname}`)
}
@wilk
wilk / module
Created July 17, 2015 06:12
ES6 Module
// file js/myModule.js
export function sum(x, y) {return x + y}
export const ADDENDUM = 10
// file yourModule.js
import * as myModule from "js/myModule"
import {sum, ADDENDUM} from "js/myModule"
console.log(myModule.sum(10, 20)) // 30
console.log(sum(ADDENDUM, ADDENDUM)) // 20
@wilk
wilk / parallel.js
Created September 25, 2015 12:00
Node parallel async requests
var parallels = [];
for (var i = 0; i < 10; i++) {
(function (i) {
var deferred = q.defer(),
userId = userIdList[i];
request.post(urlOptions, function (err, response, body) {
if (err) return deferred.reject(err);
if (result.statusCode > 399) {
@wilk
wilk / abstract.md
Last active March 15, 2016 08:27
Angular 2 Abstract

With the new AngularJS 2 beta release, we're finally a bit closer to the realization of the new version of the most famous Google web framework. There are a lot of new features to discover, some given from the experience gained with Angular 1, other born from the new web requirements.

This presentation talks about how to create components with the new Lifecycle Hooks, adding well-defined logics during creation, rendering and destruction. You will be shown why using a new template syntax: a new system to diversify one-way from two-ways data binding, as well as metadata to add features and capabilities to generic classes used as services, components, directives and pipes. We will also discuss about performance and speed improvements granted by the new change detection system via immutables and observables. Finally, an overview of RxJS used for asynchrounus data streams, using push and pull patterns of observable sequences.

This talk will introduce the new changes and new concepts that AngularJS 2 is bringing,