Created
September 5, 2012 22:23
-
-
Save ryanwitt/3646299 to your computer and use it in GitHub Desktop.
data generation server for csh week-10 (summer 2012)
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'); | |
var choices = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam erat augue, molestie accumsan vulputate ut, imperdiet ut nunc. Nunc convallis magna sed dolor suscipit placerat faucibus felis tempus. In in odio arcu, a fringilla tellus. Mauris molestie, nibh non pretium condimentum, lacus mi hendrerit erat, ac ornare dui arcu ut ipsum. Pellentesque luctus venenatis orci et feugiat. Praesent dictum bibendum fermentum. Integer aliquam erat ut dolor semper auctor. Ut sed justo sit amet orci convallis ultrices. Maecenas egestas aliquet diam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.'.split(' '); | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
var no = false; | |
console.log(req); | |
req.on('close', function() {no=true; res.end();}); | |
//req.on('end', function() {no=true; res.end();}); | |
if (req.url == '/') { | |
res.end('Use urls: /6 or /8'); | |
} else if (req.url == '/6') { | |
var go = function() { | |
res.write(''+Math.random()+','+Math.random()+','+choices[Math.floor(Math.random()*choices.length)]+','+Math.random()+'\n'); | |
if (!no) process.nextTick(go); | |
} | |
process.nextTick(go); | |
} else if (req.url === '/8') { | |
var go = function() { | |
res.write(''+Math.random()+''+Math.random()+'\n'); | |
if (!no) process.nextTick(go); | |
} | |
process.nextTick(go); | |
} | |
}).listen(1337, '0.0.0.0'); | |
console.log('Server running at http://0.0.0.0:1337/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment