Last active
August 29, 2015 14:19
-
-
Save Andsbf/096e249b5e2c6244a7b4 to your computer and use it in GitHub Desktop.
Learnyounode - I
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("HELLO WORLD") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var toPrint = process.argv.slice(2).map(Number); | |
toPrint = toPrint.reduce(function(pv,cv){ | |
return pv + cv; | |
}); | |
console.log(toPrint); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var path = process.argv[2]; | |
lFile=fs.readFileSync(path).toString(); | |
lFile = lFile.split('\n'); | |
console.log(lFile.length - 1); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var path = process.argv[2]; | |
fs.readFile(path,function(error,data){ | |
lFile=data.toString().split('\n'); | |
console.log(lFile.length - 1); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
function strEndsWith(str, suffix) { | |
suffix = '.' + suffix; | |
return str.match(suffix+"$")==suffix; | |
} | |
var path = process.argv[2]; | |
var filterKind = process.argv[3]; | |
fs.readdir(path,function(error,data){ | |
data.forEach(function(line, index){ | |
if (strEndsWith(line,filterKind)) console.log(line); | |
}); | |
}); | |
// \\ // \\ Better Solution // \\ // \\ | |
// var fs = require('fs') | |
// var path = require('path') | |
// fs.readdir(process.argv[2], function (err, list) { | |
// list.forEach(function (file) { | |
// if (path.extname(file) === '.' + process.argv[3]) | |
// console.log(file) | |
// }) | |
// }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var extraModule = require('./06a_make_it_modular.js') | |
extraModule(process.argv[2],process.argv[3], function(err,data){ | |
data.forEach(function(element){ | |
console.log(element); | |
}); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs') | |
var path = require('path') | |
module.exports = function (dirName, extensionType, callback) { | |
var result = []; | |
fs.readdir(dirName, function (err, list) { | |
if (err) {return callback(err, null)}; | |
list.forEach(function (file) { | |
if (path.extname(file) === '.' + extensionType) { | |
result.push(file) | |
} | |
}) | |
callback(null, result) | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http = require ('http') | |
var url = process.argv[2]; | |
http.get(url, function(res) { | |
res.setEncoding('utf8'); | |
res.on('data',function(d){ | |
console.log(d); | |
}) | |
}).on('error', function(e) { | |
console.log("Got error: " + e.message); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http = require ('http') | |
var url = process.argv[2]; | |
var data_final = []; | |
http.get(url, function(res) { | |
res.setEncoding('utf8'); | |
res.on('data',function(d){ | |
data_final.push(d); | |
}) | |
res.on('end',function(){ | |
console.log(data_final.join('').length); | |
console.log(data_final.join('')); | |
}) | |
}).on('error', function(e) { | |
console.log("Got error: " + e.message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment