This file contains hidden or 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') | |
, path = require('path') | |
var ls = function(directory, extension, cb) { | |
fs.readdir(directory, function(err, list) { | |
if (err) return cb(err); | |
var filteredList = []; | |
for (var k = 0; k < list.length; k++) { | |
var name = list[k]; |
This file contains hidden or 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 http = require('http'); | |
http.get(process.argv[2], function(res) { | |
res.setEncoding('utf8'); | |
res.on('data', function (data) { | |
console.log(data); | |
}); | |
}); |
This file contains hidden or 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
"use strict"; | |
var http = require('http') | |
, bl = require('bl'); | |
http.get(process.argv[2], function(res) { | |
res.pipe(bl(function (err, data) { | |
if (err) return console.error(data); | |
console.log(data.length); | |
console.log(data.toString()); |
This file contains hidden or 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
// "But for this exercise, try and do it without any external helper library." | |
// this version is my (sent1nel's) work | |
var http = require('http') | |
, events = require('events') | |
, util = require('util') | |
, bl = require('bl') | |
function Server() {}; | |
util.inherits(Server, events.EventEmitter); |
This file contains hidden or 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
// recommended solution for me to study; not my own work. | |
var http = require('http') | |
var bl = require('bl') | |
var results = [] | |
var count = 0 | |
function printResults () { | |
for (var i = 0; i < 3; i++) | |
console.log(results[i]) | |
} |
This file contains hidden or 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
"use strict"; | |
var net = require('net') | |
, strftime = require('strftime'); | |
var server = net.createServer(function (socket) { | |
socket.write(strftime('%Y-%m-%d %R') + '\n'); // "2013-07-06 07:42" | |
socket.end(); | |
}) | |
server.listen(process.argv[2]); |
This file contains hidden or 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
/* | |
royalflush:science sent1nel$ node index.js http://www.facebook.com | |
1395511696652 Device(s) /dev/cu.usbmodem1411 | |
1395511701611 Connected /dev/cu.usbmodem1411 | |
1395511701611 Repl Initialized | |
>> Getting http://www.facebook.com...got it! | |
Attempting to encode 'Update Your Browser | Facebook' | |
Encoded title: | |
..- .--. -.. .- - . ....... -.-- --- ..- .-. ....... -... .-. --- .-- ... . .-. ....... ? ....... ..-. .- -.-. . -... --- --- -.- | |
..- .--. -.. .- - . ....... -.-- --- ..- .-. ....... -... .-. --- .-- ... . .-. ....... ....... ..-. .- -.-. . -... --- --- -.- |
This file contains hidden or 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
"use strict"; | |
var express = require('express') | |
, fs = require('fs'); | |
var app = express(); | |
app.get('/', function(req, res) { | |
fs.createReadStream(process.argv[3]).pipe(res); | |
}); |
This file contains hidden or 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
"use strict"; | |
var express = require('express') | |
, map = require('through2-map'); | |
var app = express(); | |
app.post('/', function(req, res) { | |
req.pipe(map(function (chunk) { | |
return chunk.toString().toUpperCase(); |
This file contains hidden or 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
module.exports = { | |
parsetime: function(req, res, next) { | |
req.result = require('./parsetime')(req.iso); | |
next(); | |
}, | |
unixtime: function(req, res, next) { | |
req.result = require('./unixtime')(req.iso); | |
next(); | |
} | |
} |