Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Jessie J Valladares jessemoon0

🎯
Focusing
  • Tampa, USA
View GitHub Profile
@jessemoon0
jessemoon0 / basicNodeFileUpload.js
Created Oct 14, 2016
Testing Node: Uploading a file, see its progress % and creating an equal size .md file
View basicNodeFileUpload.js
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
@jessemoon0
jessemoon0 / promiseDepenencies.js
Last active Nov 23, 2016
2nd Example of a JS Promise: A cleaner code in case you have many callbacks in your JS.
View promiseDepenencies.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 / promiseExplanation.js
Last active Oct 10, 2016
First Example of a Javascript Promise (Tutorial)
View promiseExplanation.js
//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.