Skip to content

Instantly share code, notes, and snippets.

/*
* three urls are given, data must be supplied back in the order of the urls via SDOUT
*/
var http = require('http');
var data1 = '';
var data2 = '';
var data3 = '';
var collect = function(url,callback){
//Example given (changed it toUppperCase rather than reverse)
var map = require('through2-map')
inStream.pipe(map(function (chunk) {
return chunk.toString().split('').toUpperCase().join('')
})).pipe(outStream)
//attempt
var stream = require('stream')
var upper = new stream.Transform();
upper._transform = function (chunk, encoding, done){
var data = chunk.toString().split().toUpperCase().join('');
//issue, socket hangs
var stream = require('stream')
var http = require('http');
var upper = new stream.Transform();
upper._transform = function (chunk, encoding, done){
var data = chunk.toString().split().toUpperCase().join('');
data.forEach(this.push.bind(this));
done();
};
var http = require('http');
var map = require('through2-map');
var server = http.createServer(function(req,res){
if (req.method == 'POST') {
req.pipe(map(function (chunk) {
return chunk.toString().toUpperCase()
})).pipe(res);
req.on('end', function() {
res.end();
});
textBuf = new Buffer('bytewiser');
textBuf.pipe(process.stdout);
var buffer = new Buffer([])
for (var i = 2;i <= process.argv.length - 1; i++) {
buffer[i] = process.argv[i];
console.error(buffer[i]);
};
for (var i = 2;i <= buffer.length - 1; i++) {
process.stdout.write(buffer[i].toString('hex'));
};
process.stdout.write('\n');
var http = require('http');
var map = require('through2-map');
var server = http.createServer(function(req,res){
if (req.method == 'POST') {
req.pipe(map(function (chunk) {
return chunk.toString().toUpperCase()
})).pipe(res);
req.on('end', function() {
res.end();
});
var http = require('http');
var url = require('url');
var server = http.createServer(function (request,response){
if (request.method == 'GET'){
reqObj = url.parse(request.url,true);
var dateString = reqObj.query.iso;
console.error(reqObj.query);
var date = new Date(dateString)
console.error(date);
/*Given an unknown number of bytes passed via process.argv,
//create a buffer from them and output a hexadecimal encoded representation of the buffer.
//
//Your answer should be a string of two-character pairs (also known as hexadecimal octets),
//where each pair represents a single number in the array of bytes converted to hexadecimal
*/
var leftpad = function(str){
if (str.length == 1){
str = '0'+str;
}
/*
Write a program that takes the first buffer written to process.stdin,
updates all instances of . with ! and then logs out the updated buffer object.
Bonus points if you never call .toString() on your buffer!
*/
//var buffer = Buffer.from(process.stdin);
var input = ''
process.stdin.on('data', function(d) {
/*