Skip to content

Instantly share code, notes, and snippets.

View ianaya89's full-sized avatar
👾

Nacho Anaya ianaya89

👾
View GitHub Profile
@ianaya89
ianaya89 / keybase.md
Created August 2, 2016 01:58
Keybase

Keybase proof

I hereby claim:

  • I am ianaya89 on github.
  • I am ianaya89 (https://keybase.io/ianaya89) on keybase.
  • I have a public key whose fingerprint is CC95 CEE3 B67B E98F 11FF 4493 E628 369C 5247 E538

To claim this, I am signing this object:

@ianaya89
ianaya89 / index.js
Created December 9, 2016 18:31
blocking vs. no-blocking
Blocking methods execute synchronously and non-blocking methods execute asynchronously.
Using the File System module as an example, this is a synchronous file read:
const fs = require('fs');
const data = fs.readFileSync('/file.md'); // blocks here until file is read
And here is an equivalent asynchronous example:
const fs = require('fs');
fs.readFile('/file.md', (err, data) => {
@ianaya89
ianaya89 / let-const.js
Created December 12, 2016 15:22
Curso Node.js - IT Master => let & const
// let
if(true) {
var a = 'a';
let b = 'b';
console.log(b + ' is available' );
}
console.log(a); // ✅
console.log(b); // ❌ => ReferenceError: b is not defined
@ianaya89
ianaya89 / arrow-functions.js
Last active December 12, 2016 20:48
Curso Node.js - IT Master => arrow functions
const fakeTitles = [
'Pirate Of Reality',
'Guardians Of Hell',
'Witches With Vigor',
'Spies And Heroes',
'Robots And Kings',
];
// Nueva Sintaxis
const abbreviations = fakeTitles.map(title => title.toLowerCase().slice(0, 3)); // ES6
@ianaya89
ianaya89 / object-literals-extensions.js
Last active December 12, 2016 20:39
Curso Node.js - IT Master => object literals extensions
// properties
const name = 'Ignacio';
const age = 27;
const person = { name, age }; // ES6
const person = { name: name, age: age }; //ES5
// methods
const dog = {
bark() {
@ianaya89
ianaya89 / object-destructuring.js
Last active December 12, 2016 20:45
Curso Node.js - IT Master => object destructuring
// Object
const myObj = {a: 'a', b: 'b', c: 'c'};
const {a, c} = myObj;
console.log(a); // => a
console.log(c); // => c
// Array
const [d, m, a] = [21, 10, 2015];
@ianaya89
ianaya89 / spread-operator.js
Created December 12, 2016 15:57
Curso Node.js - IT Master => spread operator
// asignar parametros a funcion
function getVolume(width, height, depth) {
return width * height * depth;
}
const values = [10, 20, 30];
console.log(getVolume(...values)); // => 6000
// concatenar arrays
const array1 = [1, 2, 3];
@ianaya89
ianaya89 / template-literals.js
Created December 12, 2016 16:01
Curso Node.js - IT Master => template literals
// variables
const foo = 'bar';
const bizz = 'bang';
console.log(`Foo is ${foo} and bizz is ${bizz}`); // => 'Foo is bar and bizz is bang'
// llamadas de funciones
function hello() {
return 'hello';
}
@ianaya89
ianaya89 / default-parameters.js
Created December 12, 2016 20:33
Curso Node.js - IT Master => default parameters
function foo(x = 11, y = 31) {
console.log( x + y );
}
foo(); // 42
foo( 5, 6 ); // 11
foo( 0, 42 ); // 42
foo( 5 ); // 36
const map = new Map();
map.set('foo', 123);
map.get('foo') // 123
map.has('foo') // true
map.set(10, 'Something...');
map.get(10) // Something...
map.has(10) // true