On Github floatdrop / nodejs-shri-2013
on mouseUp get the selection if it is empty then as "Dial what number?" if it is not empty then push this card visual effect zoom open go to stack "Phone" dial it pop card end if end mouseUp
Расчитан на обработку событий
Был написан за 10 дней
Function as first-class objects
Прототипное наследование из Self
$result = mysqli_query( $con, "SELECT * FROM Persons"); while($row = mysqli_fetch_array($result)) { echo $row['Name']."\n"; } file_put_contents("access.log", "Request done")
I/O has to be done differently.We are doing it wrong
function HelloWorld () { console.log('Hello world'); } console.log('Module loaded');
require('./module');
require('./module'); HelloWorld();
function HelloWorld () { console.log('Hello world'); } console.log('Module loaded'); exports.HelloWorld = HelloWorld;
var module = require('./module'); module.HelloWorld();
function HelloWorld () { console.log('Hello world'); } console.log('Module loaded'); global.HelloWorld = HelloWorld;
require('./module'); HelloWorld();
var en_translation = { yes: 'Нет', no: 'Да' }; exports = en_translation;
var en_translation = { yes: 'Да', no: 'Нет' }; module.exports = en_translation;
{ "yes": "да", "no": "нет" }
require('http')
require('express')
require('./index.js')
require('./config.json')
require('./module') // Directory
var http = require('http'); function helloService(request, response) { response.end("Hello, stranger!"); } var server = http.createServer(helloService); module.exports = server;
NODE_PATH
$HOME/.node_modules, $HOME/.node_libraries, $PREFIX/lib/node
module.exports = new Date();
console.log(require("antigravity"));
console.log(module); module.exports = new Date();
var b = require('./b.js'); console.log("B: ", b);
var a = require('./a.js'); console.log("A: ", a);
module.exports.hello = "Hello from A"; var b = require('./b.js'); module.exports.helloFromB = b.hello; console.log("B: ", b);
module.exports.hello = "Hello from B"; var a = require('./a.js'); module.exports.helloFromA = a.hello; console.log("A: ", a);
+ Version independent
- Wieght more
{ "name": "express", "version": "3.4.4", "dependencies": { "connect": "2.11.0", "commander": "1.3.2", "range-parser": "0.0.4", "mkdirp": "0.3.5", "cookie": "0.1.0", "buffer-crc32": "0.2.1", "fresh": "0.2.0", "methods": "0.1.0", "send": "0.1.4", "cookie-signature": "1.0.1", "debug": "*" }, "devDependencies": { "ejs": "*", "mocha": "*", "jade": "0.30.0", "hjs": "*", "stylus": "*", "should": "2", "connect-redis": "*", "marked": "*", "supertest": "0.8.1 - 1" }, "main": "index", "bin": { "express": "./bin/express" }, "scripts": { "prepublish": "npm prune", "test": "make test" }, "engines": { "node": "*" } }
var express = require('express'); var app = express(); app.get('/', function(req, res) { res.end('Hello!'); }); app.listen(3000);
static int uv__loop_init(uv_loop_t* loop, int default_loop) { // ... RB_INIT(&loop->timer_handles); QUEUE_INIT(&loop->wq); QUEUE_INIT(&loop->active_reqs); QUEUE_INIT(&loop->idle_handles); QUEUE_INIT(&loop->async_handles); QUEUE_INIT(&loop->check_handles); QUEUE_INIT(&loop->prepare_handles); QUEUE_INIT(&loop->handle_queue); QUEUE_INIT(&loop->pending_queue); QUEUE_INIT(&loop->watcher_queue); err = uv__platform_loop_init(loop, default_loop); // ... }
int uv_run(uv_loop_t* loop, uv_run_mode mode) { r = uv__loop_alive(loop); while (r != 0 && loop->stop_flag == 0) { // ... uv__update_time(loop); uv__run_timers(loop); uv__io_poll(loop, timeout); // ... } }
static int uv__loop_alive(uv_loop_t* loop) { return uv__has_active_handles(loop) || uv__has_active_reqs(loop) || loop->closing_handles != NULL; }
function fibonacci(n) { if (n < 2) return 1; else return fibonacci(n-2) + fibonacci(n-1); } require('http').createServer(function (req, res) { res.end("40: " + fibonacci(40)); }).listen(8005);
Requests per second: 0.61 Time per request: 1634.748 ms (vs 5676 ms)
function fibonacci(i, n, f1, f2, res) { if (i >= n) res.end(n + ": " + (f1 + f2)); else setImmediate(function() { fibonacci(i + 1, n, f2, f1 + f2, res); }); } require('http').createServer(function (req, res) { fibonacci(0, 1473, 1, 1, res); }).listen(8005);
Requests per second: 264.55 Time per request: 3.780 ms
$ cut -f 1 | uniq -c | sort -n
var app = require('express')();
app.post('/:algo/:secret', function(req, res) { // Some magic should be applied here res.end(req.params.algo + " " + req.params.secret); });
app.listen(31337);
var cipher = require('crypto') .createCipher('aes192', 'secret'); process.stdin.pipe(cipher).pipe(process.stdout);
var app = require('express')();
app.get('/:algo/:secret', function(req, res) { var cipher = require('crypto') .createCipher(req.params.algo, req.params.secret); req.pipe(cipher).pipe(res); });
app.listen(31337);
process.stdin.on('data', function(chunk) { console.log(chunk); });
var backpressure = process.stdout.write('data');
var backpressure = process.stdout.write('data');
This return value is strictly advisory. You MAY continue to write, even if it returns false. However, writes will be buffered in memory, so it is best not to do this excessively. Instead, wait for the drain event before writing more data.