Skip to content

Instantly share code, notes, and snippets.

View giancorzo's full-sized avatar

Giancarlo Corzo giancorzo

View GitHub Profile
@giancorzo
giancorzo / browser.js
Created July 27, 2017 20:48 — forked from pamelafox/browser.js
Browser banner warning
(function(wndw) {
var Browsers, OS, Platform, Versions, browser_name, browser_version, os, platform;
Versions = {
Firefox: /firefox\/([\d\w\.\-]+)/i,
IE: /msie\s([\d\.]+[\d])/i,
Chrome: /chrome\/([\d\w\.\-]+)/i,
Safari: /version\/([\d\w\.\-]+)/i,
Ps3: /([\d\w\.\-]+)\)\s*$/i,
Psp: /([\d\w\.\-]+)\)?\s*$/i
};
{
"name": "styleguide",
"version": "0.0.1",
"description": "Laboratoria styleguides",
"main": "index.js",
"style": "dist/main.css",
"sass": "sass/main.scss",
"scripts": {
"build": "node-sass --include-path sass sass/main.scss dist/main.css"
},
const get = url => {
return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest();
xhr.addEventListener('load', _ => {
if (xhr.status !== 200) {
reject(new Error(xhr.statusText));
}
resolve(xhr.response);
});
var myPromise = new Promise((resolve, reject) => {
//Instrucciones que se van a ejecutar
if(/* Termino correctamente */) {
resolve('Success!');
} else {
reject('Failure!');
}
});
fs.readdir(source, function (err, files) {
if (err) {
console.log('Error finding files: ' + err)
} else {
files.forEach(function (filename, fileIndex) {
console.log(filename)
gm(source + filename).size(function (err, values) {
if (err) {
console.log('Error identifying file size: ' + err)
} else {
const stations = [{id: 1, name: "Pardo"}, {id: 2, name: "Benavides"}];
// Map, reduce y Filter son clasicos ejemplos de callback,
// donde se delega la lógica detrás del map a una función externa haciéndo
// reutilizable el código
const stationNames = stations.map((station) => {
return station.name;
});
const callback = () => {
console.log('Llamando a mi callback');
}
function otraFuncion(callback) {
console.log('Ejecutando otra funcion');
callback();
}
//Funcion anonima que funciona como callback
console.log('Primero');
setTimeout(_ => {
console.log('Segundo');
},10);
console.log('Tercero');
console.log('Primero');
console.log('Segundo');
console.log('Tercero');
<script id="myTemplate" type="text/x-handlebars-template">
<h1>{{title}}</h1>
<ul>
{{#names}}
<li>{{name}}</li>
{{/names}}
</ul>
</script>