d3.unconf example gist. Fork it here.
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
// Long-polling chat server + client. | |
var chats = []; | |
require('http').createServer(function(req, res) { | |
if (/\/c/.test(req.url)) return res.end(chats.join('\n')); | |
var m = req.url.split('='); | |
if (m.length > 1) chats.unshift(m[1].replace(/\+/g, ' ')); | |
res.end('<html><body><form><input name="m"></form><pre></pre><script>' | |
+ 'var r=new XMLHttpRequest;(function e(){r.open("GET","/c",true);r.send();r.onreadystatechange=function(){if(r.readyState==4){document.getElementsByTagName("pre")[0].innerHTML=r.responseText;setTimeout(e,1e3)}}})();document.forms[0].m.focus()' | |
+ '</script></body></html>') | |
}).listen(parseInt(process.env.PORT, 10)|| 3000); |