Skip to content

Instantly share code, notes, and snippets.

Den Lieukhyn idx3d

  • Ukraine
View GitHub Profile
View gm.js
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);
@idx3d
idx3d / cb.js
Last active Dec 29, 2015
callback description
View cb.js
// callback - это третий аргумент функции asyncRandom.
// Это возможно, потому-что http://ru.wikipedia.org/wiki/Функции_первого_класса
function asycRandom(min, max, callback) {
var result = Math.ceil(Math.random() * (min - max) + max);
callback(result);
}
// Тут мы передаем третим аргументом анонимную функцию, которая принимает один аргумент num
View app.js
var app = angular.module('xo', []);
function drawField(game) {
var field = game.getField();
}
function Player(name, type) {
this.name = name || 'noname';
this.type = type;
}
View co_test.js
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)
});
View co_example.js
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',
View node_ip_addr_detection.js
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/');
View continuable-generators.js
"use strict";
const GeneratorFunction = function*(){}.constructor;
const GeneratorFunctionPrototype = GeneratorFunction.prototype;
const slice = Array.prototype.slice;
const concat = Array.prototype.concat;
/**
View errors_handling_express.js
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);
View isexist_example.js
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);
}
});
You can’t perform that action at this time.