Permalink
Browse files

init

  • Loading branch information...
0 parents commit 7c96d3012d79813d4e7eb3429f507c9e3796daa0 cloudhead committed Apr 14, 2010
Showing with 453 additions and 0 deletions.
  1. +2 −0 README
  2. +32 −0 examples/async.js
  3. +19 −0 examples/cat.js
  4. +10 −0 examples/next-tick.js
  5. +22 −0 examples/promises.js
  6. +28 −0 examples/sync.ru
  7. BIN intro/lars-bak.jpeg
  8. +262 −0 intro/node-intro.md
  9. +3 −0 showoff.json
  10. +75 −0 style.css
@@ -0,0 +1,2 @@
+An introduction to node.js
+
@@ -0,0 +1,32 @@
+
+var http = require('http'),
+ sys = require('sys');
+
+var concurrent = [];
+
+http.createServer(function (request, response) {
+ concurrent.push('*');
+
+ sys.puts("---> " + status());
+
+ dbQuery(function (result) {
+ response.writeHead(200, {'Content-Type': 'text/plain'});
+ response.end(result);
+
+ sys.puts("<--- " + status());
+
+ concurrent.pop();
+ });
+}).listen(8080);
+
+
+// Simulate a slow DB query
+function dbQuery(callback) {
+ setTimeout(function () {
+ callback("hello world\n");
+ }, 1000);
+}
+
+function status() {
+ return (new Date).toLocaleTimeString() + ' ' + concurrent.join('');
+}
@@ -0,0 +1,19 @@
+
+var fs = require('fs'),
+ sys = require('sys');
+
+var file = process.ARGV[2];
+
+fs.stat(file, function (e, stat) {
+ if (e) throw e;
+
+ fs.open(file, "r", stat.mode, function (e, fd) {
+ if (e) throw e;
+
+ fs.read(fd, stat.size, 0, "utf8", function (e, data) {
+ if (e) throw e;
+
+ sys.puts(data);
+ });
+ });
+});
@@ -0,0 +1,10 @@
+var sys = require('sys');
+
+sys.debug("> 1 <");
+
+process.nextTick(function () {
+ sys.debug("> 2 <");
+});
+
+sys.debug("> 3 <");
+
@@ -0,0 +1,22 @@
+var events = require('events'),
+ sys = require('sys');
+
+function doSomethingAsynchronously() {
+ var promise = new events.EventEmitter;
+
+ process.nextTick(function () {
+ promise.emit("success", "Good night.");
+ });
+
+ return promise;
+}
+
+var promise = doSomethingAsynchronously();
+
+promise.addListener("success", function (msg) {
+ sys.puts(msg);
+});
+
+promise.addListener("error", function (msg) {
+ sys.log("error: " + msg);
+});
@@ -0,0 +1,28 @@
+require 'rack'
+
+@concurrent = []
+
+run lambda {|env|
+ @concurrent << '*'
+
+ puts "---> #{status}"
+
+ result = db_query()
+
+ puts "<--- #{status}"
+
+ @concurrent.pop
+
+ [200, {'Content-Type' => 'text/plain'}, [result]]
+}
+
+# Simulate a slow DB query
+def db_query
+ sleep 1
+ "hello world\n"
+end
+
+def status
+ "#{Time.now.strftime("%H:%M:%S ")} #{@concurrent.join}"
+end
+
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,262 @@
+!SLIDE
+
+# node.js
+> evented I/O for V8 JavaScript
+
+!SLIDE bullets incremental transition=scrollHorz
+
+# what is node?
+
+* Server-side JavaScript done right.
+* Runs on V8
+* An environment for developing high-performance web services
+* Evented TCP stack
+* Not a framework
+
+!SLIDE bullets left transition=scrollHorz
+
+# why node?
+
+* Web applications spend most of their time doing I/O
+* JavaScript is the language of the web
+
+!SLIDE transition=scrollHorz
+
+# V8 #
+
+!SLIDE bullets incremental transition=scrollHorz
+
+# V8
+
+* Google's open source JavaScript engine.
+* Developed by Lars Bak.
+* Fast: compiles JavaScript to machine code.
+* Implements most of ECMAScript 5.
+
+!SLIDE center transition=scrollHorz
+
+## Lars Bak
+
+![Lars Bak](lars-bak.jpeg)
+
+!SLIDE transition=scrollHorz
+
+# ECMAScript 5
+
+!SLIDE transition=scrollHorz
+
+### ECMAScript 5
+
+## Safe prototype extension
+
+ @@@ javascript
+ Object.defineProperty(Object.prototype, "forEach", {
+ value: function (callback) {
+ var keys = Object.keys(this);
+
+ for (var i = 0, key; i < keys.length; i++) {
+ key = keys[i];
+ callback.call(this, key, this[key]);
+ }
+ }
+ });
+
+!SLIDE transition=scrollHorz
+
+### ECMAScript 5
+
+## Access to the hidden prototypes
+
+ @@@ javascript
+ Object.getPrototypeOf([]) // Array
+ [].__proto__ // Array
+ [].__proto__.__proto__ // Object
+
+!SLIDE transition=scrollHorz
+
+### ECMAScript 5
+
+## Basic prototypal inheritance
+
+ @@@ javascript
+ var o = Object.create({ foo: 42 });
+
+ o.bar = "bah";
+
+ Object.keys(o) // ["bar"]
+
+ o.foo // 42
+ o.__proto__ // { foo: 42 }
+
+!SLIDE bullets transition=scrollHorz
+
+# node.js #
+
+!SLIDE bullets transition=scrollHorz
+
+### node.js
+
+## Event-driven programming
+
+* Asynchronous I/O
+* Callbacks
+
+!SLIDE transition=scrollHorz
+
+### node.js
+
+## Common.js module system
+
+ @@@ javascript
+ var sys = require("sys");
+
+ sys.puts("hello world");
+
+!SLIDE transition=scrollHorz
+
+### node.js
+
+## Common.js module system
+
+ @@@ javascript
+ require.paths // ["./lib", ...]
+ __dirname // this dirname
+ __filename // this filename
+
+!SLIDE transition=scrollHorz
+
+### node.js
+
+## Simple HTTP server
+
+ @@@ javascript
+ var http = require('http');
+
+ http.createServer(function (request, response) {
+ response.writeHead(200, {
+ 'Content-Type':'text/plain'
+ });
+ response.end('Hello World\n');
+ }).listen(8000);
+
+!SLIDE transition=scrollHorz
+
+# Event-driven programming
+
+!SLIDE transition=scrollHorz
+
+ @@@ javascript
+ setTimeout(function () {
+ // Do something after 1 second
+ }, 1000);
+
+!SLIDE transition=scrollHorz
+
+ @@@ javascript
+ process.nextTick(function () {
+ // Do something asynchronously
+ });
+
+!SLIDE transition=scrollHorz
+
+## Async error handling
+
+ @@@ javascript
+ process.addListener('uncaughtException',
+ function (err) {
+ // Handle exception
+ });
+
+!SLIDE transition=scrollHorz
+
+## Async signal handling
+
+ @@@ javascript
+ process.addListener('SIGINT', function (err) {
+ // Handle Ctrl-C
+ });
+
+!SLIDE transition=scrollHorz
+
+# modules #
+
+!SLIDE transition=scrollHorz
+
+# file-system module #
+
+ @@@ javascript
+ require('fs');
+
+!SLIDE bullets transition=scrollHorz
+
+## modules
+
+# fs
+
+* one-to-one mapping with unix commands
+* most functions have a synchronous version
+
+!SLIDE transition=scrollHorz
+
+## Asynchronous file stat
+
+ @@@ javascript
+ fs.stat("path/to/file", function (err, res) {
+ if (res) {
+ // Handle success
+ } else {
+ // Handle error
+ }
+ });
+
+!SLIDE transition=scrollHorz
+
+## Synchronous file stat
+
+ @@@ javascript
+ var res = fs.statSync("path/to/file");
+
+ if (res) {
+ // Handle success
+ } else {
+ // Handle error
+ }
+
+!SLIDE transition=scrollHorz
+
+# Example
+## `cat`
+
+!SLIDE transition=scrollHorz
+
+# Example
+## Sync vs Async
+
+!SLIDE transition=scrollHorz
+
+# Thanks
+
+!SLIDE transition=scrollHorz
+
+# `http://nodejs.org`
+
+!SLIDE transition=scrollHorz
+
+# @cloudhead
+## Alexis Sellier
+## http://github.com/cloudhead/node-intro
+
+!SLIDE transition=scrollHorz
+
+# Questions?
+
+
+
+
+
+
+
+
+
+
+
@@ -0,0 +1,3 @@
+[
+ {"section": "intro"}
+]
Oops, something went wrong.

0 comments on commit 7c96d30

Please sign in to comment.