Skip to content

Instantly share code, notes, and snippets.

View jessemoon0's full-sized avatar
🎯
Focusing

Jessie Valladares jessemoon0

🎯
Focusing
View GitHub Profile
@jessemoon0
jessemoon0 / promiseExplanation.js
Last active October 10, 2016 05:02
First Example of a Javascript Promise (Tutorial)
//First code about promises
let promiseToCleanTheRoom = new Promise(function(resolve, reject){
//Resolve: Means I am fullfilling this promise (resolving it).
//Reject: Promise is not Fullfilled in given time or constraint.
//HERE IS CLEANING THE ROOM CODE....
//After doing this, clean's value gets set.
let isClean = true; //Here you control resolve and reject in this example.
@jessemoon0
jessemoon0 / promiseDepenencies.js
Last active November 23, 2016 23:02
2nd Example of a JS Promise: A cleaner code in case you have many callbacks in your JS.
//Promise Dependencies (after promiseExplanation)
//In this Example first you clean the room, then remove the garbage and finally win an icecream.
//Here also im directly resolving the promises, real life is code and check if resolved or reject.
let cleanRoom = function(){
return new Promise(function(resolve, reject){
resolve('I Cleaned the Room');
});
};
@jessemoon0
jessemoon0 / basicNodeFileUpload.js
Created October 14, 2016 07:03
Testing Node: Uploading a file, see its progress % and creating an equal size .md file
var http = require('http');
var fs = require('fs');
http.createServer(function(request, response){
var newFile = fs.createWriteStream("big_copy.md"); //This is created automatically
var fileBytes = request.headers['content-length']; //Check how much bytes a file has
var uploadedBytes = 0;//Keep track of the bytes uploaded.
request.on('readable', function(){ //Each time information is read