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
function userExist(user, callback) { | |
db.connection.query('SELECT ...user...', function(err, rows) { | |
if (err) callback(err); // еще желательно проверять typeof колбека, функция ли это | |
if (rows) { | |
callback(null, true); | |
} else { | |
callback(null, false); | |
} | |
}); |
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
var express = require('express') | |
, app = module.exports = express(); | |
app.use(app.router); | |
// the error handler is strategically | |
// placed *below* the app.router; if it | |
// were above it would not receive errors | |
// from app.get() etc | |
app.use(error); |
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
"use strict"; | |
const GeneratorFunction = function*(){}.constructor; | |
const GeneratorFunctionPrototype = GeneratorFunction.prototype; | |
const slice = Array.prototype.slice; | |
const concat = Array.prototype.concat; | |
/** |
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
var http = require('http'); | |
http.createServer(function (req, res) { | |
var ip = req.connection.remoteAddress; | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('Your ip is: ' + ip); | |
}).listen(1337, '127.0.0.1'); | |
console.log('Server running at http://127.0.0.1:1337/'); |
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
var request = require('superagent') | |
, co = require('co'); | |
var join = co.join; | |
var get = co.wrap(request.get); | |
var urls = [ | |
'http://google.com', | |
'http://yahoo.com', |
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
var fs = require('fs'); | |
var co = require('co'); | |
var express = require('express'); | |
var wrapper = require('co-express'); | |
var app = wrapper(express()); | |
var wait = require('co-wait'); | |
app.get('/test', function* (req, res, next) { | |
yield waitAndAnswer(res) | |
}); |
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
var app = angular.module('xo', []); | |
function drawField(game) { | |
var field = game.getField(); | |
} | |
function Player(name, type) { | |
this.name = name || 'noname'; | |
this.type = type; | |
} |
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
// callback - это третий аргумент функции asyncRandom. | |
// Это возможно, потому-что http://ru.wikipedia.org/wiki/Функции_первого_класса | |
function asycRandom(min, max, callback) { | |
var result = Math.ceil(Math.random() * (min - max) + max); | |
callback(result); | |
} | |
// Тут мы передаем третим аргументом анонимную функцию, которая принимает один аргумент num |
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
function Game(type) { | |
this.type = type; | |
this.board = [0,0,0]; | |
} | |
var app = angular.module('xo', []); | |
app.factory('game', function () { | |
return function (type) { | |
return new Game(type); |