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
/** | |
* Some existing external lib which you don't want to touch | |
*/ | |
var SomeModule = { | |
someAsyncFunction : function(callback) | |
{ | |
process.nextTick(function(){ | |
callback(null, 'result'); | |
}) |
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
/** | |
* Seq | |
*/ | |
var fs = require('fs'); | |
var exec = require('child_process').exec; | |
var Seq = require('seq'); | |
Seq() | |
.seq(function () { | |
exec('whoami', this) |
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
someObject = { | |
myNewMethod : function(a, b) // <-- no callback | |
{ | |
console.log(Fiber.current); // Inside of fiber | |
if (a == 1) | |
throw "'a' cannot be 1"; // we can use throw here | |
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 someAsyncFunction(param, callback) { | |
setTimeout(function(){ | |
callback(null, param); // result | |
}, 100) | |
} | |
Function.prototype.sync = function(param) { | |
this(param, function(e, result) { | |
Fiber.run(result); // substitute result instead of yield, resume current Fiber |
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 path = require('path') | |
, fs = require('fs') | |
, Sync = require('sync') | |
// Return a future which just pauses for a certain amount of time | |
function realish (p) { | |
return path.resolve(path.dirname(fs.readlink.sync(fs, p))) | |
} |
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 getUserSummary(userId, callback) | |
{ | |
async.parallel({ | |
user : function(callback) { | |
db.users.findUserById(userId, callback) | |
}, | |
tweets : function(callback) { | |
db.users.getTweets(userId, callback) |
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
createEdge : function(e, callback) | |
{ | |
var self = this, tryNum = 0, | |
isolateRetryAttempts = 20, | |
isolateRetryInterval = 1000; | |
callback = callback || function(){}; | |
if (!(e instanceof Edge) || !e.isValid()) { | |
return callback(new Error("Invalid edge passed")); |
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
// Заюзай node-sync v0.1.9beta2, в ней есть .asyncMiddleware() | |
// это маленькая магия, которая позволяет писать "синхронные" функции типа function(req, res, next) | |
// еще не знаю, как ее лучше назвать... | |
app.post('/q/register', function(req, res) { | |
var mysql = database.spawnConnection(); | |
// А можно реализацию beginSync? | |
mysql.beginSync(); |
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
-module(brute). | |
-export([brute/1]). | |
brute_(N, M, _, O) when N == M -> | |
O; | |
brute_(N, M, L, O) -> | |
[string:right(integer_to_list(N), L, $0) | brute_(N + 1, M, L, O)]. | |
brute(N) -> | |
brute_(0, math:pow(10, N), N, []). |
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
// ==UserScript== | |
// @name OLX Previews | |
// @namespace http://use.i.E.your.homepage/ | |
// @version 0.1 | |
// @description Makes OLX (slando) render large image previews | |
// @match http://kiev.ko.olx.ua/nedvizhimost* | |
// @copyright 2015+, Yuriy Bogdanov | |
// ==/UserScript== | |
;(function(){ |
OlderNewer