Skip to content

Instantly share code, notes, and snippets.

@csanz
Created April 24, 2012 19:27
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csanz/2482934 to your computer and use it in GitHub Desktop.
Save csanz/2482934 to your computer and use it in GitHub Desktop.
intro to node.js slide show app written in node.js
var color = require('colors');
var stdin = process.openStdin()
, slides = {
1: "\tNode.js" +
"\n\n\t\tJavascript running on the server" +
"\n\n\t\tWritten in C++ (POSIX)" +
"\n\n\t\tWraps V8 JS VM (Google/Chrome)"
, 2: "\tOthers / Evented I/O" +
"\n\n\t\t > Reactor Pattern" +
"\n\n\t\t > EventMachine(Ruby) / Twisted (Python)" +
"\n\n\t\t > Nginx + Lighthttp"
, 3: "\tBefore and now" +
"\n\n\t\t > Javascript 12 years ago" +
"\n\n\t\t > ActiveX / AJAX" +
"\n\n\t\t > Server!"
, 4: "\tLow Level stuff" +
"\n\n\t\t > Single Thread / Event Loop (libev)" +
"\n\n\t\t > Schedules Blocking I/O / Thread Pool" +
"\n\n\t\t > File Descriptors (epoll, kqueue, select)" +
"\n\n\t\t > Life is good"
, 5: "\tStreams" +
"\n\n\t\t > abstract interface implemented by various objects (HTTP)" +
"\n\n\t\t > abstract interface?" +
"\n\n\t\t > Readable, writable or both" +
"\n\n\t\t > Example with bash"
, 6: "\tDemo" +
"\n\n\t\t > Super simple HTTP server" +
"\n\n\t\t > Load Test the event loop / Max the file descriptors w/ ab" +
"\n\n\t\t > Fake a blocking I/O job" +
"\n\n\t\t > Streams with request"
, 7: "\tThanks!" +
"\n\n\t\t > Check out http://geekli.st" +
"\n\n\t\t > Create Cards!"
}
require('tty').setRawMode(true);
init()
stdin.on('keypress', function (s, key) {
if (key && key.ctrl && key.name == 'c') process.exit();
process.stdout.write('\u001B[2J\u001B[0;0f\n\n');
if(key && key.name === 'i'){
init();
}else{
console.log(slides[s].bold);
console.log("\n\n\n\n\n\t[Slide %s]".grey, s)
}
});
function init(){
process.stdout.write('\u001B[2J\u001B[0;0f\n\n');
console.log("\tAn introduction to the event-driven I/O" +
"\n\tframework that is changing the way we" +
"\n\tthink about developing web applications" +
"\n\n\n\t\t\tNode.js".green)
}
@cronopio
Copy link

Thanks for open sourced!, but what is that tty module?

@cronopio
Copy link

oh! @csanz thanks so much!. I did not know that core module.

@csanz
Copy link
Author

csanz commented Apr 25, 2012

\o :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment