Генератор для перебора бесконечных ветвящихся неповторяющихся последовательностей (неслучайных чисел с шагом 1).

module.exports = (function(){

    var self = {}

    self.constructor = function()
    {
        if(!(this instanceof self.constructor))
        {
            return new (Function.prototype.bind.apply(self.constructor, [null].concat(Array.prototype.slice.call(arguments))))
        }
        this.pointer = -1
        this.sequence = []
        this.exhausted = false
        this.roundcount = 0
    }

    self.debug = function()
    {
        console.log(JSON.stringify([this.exhausted,this.sequence,this.pointer,this.roundcount]))
    }

    self.currentRound = function()
    {
        return this.roundcount
    }

    self.currentValue = function()
    {
        return this.sequence[this.pointer]
    }

    self.nextValue = function(min,max)
    {
        this.pointer++
        if(this.sequence[this.pointer] == null)
        {
            this.sequence[this.pointer] = { max : max, min : min, val : min }
        }
        return this.sequence[this.pointer].val
    }

    self.nextRound = function()
    {
        if(this.sequence[this.pointer] != null 
        && ++this.sequence[this.pointer].val > this.sequence[this.pointer].max)
        {
            this.sequence.splice(this.pointer,1)
            this.pointer--
            if(this.pointer == -1)
            {
                this.exhausted = true
            }
            else
            {
                this.nextRound()
            }
        }
        this.pointer = -1
        this.roundcount++
        return
    }

    self.constructor.prototype = self
    return self.constructor

})()
NotRand = require('./NotRand.js')

var i = 0;
var a = NotRand()
while(!a.exhausted)
{
    var b = []
    b.push(a.nextValue(1,1))
    b.push(a.nextValue(1,4))
    if(b[1] == 3)
    {
        b.push(a.nextValue(1,3))
        b.push(a.nextValue(1,3))
    }
    else
    {
        b.push(a.nextValue(1,2))
    }
    a.nextRound()
    console.log(b)
}
console.log(a.currentRound())
$ node pereborjs.js 
[ 1, 1, 1 ]
[ 1, 1, 2 ]
[ 1, 2, 1 ]
[ 1, 2, 2 ]
[ 1, 3, 1, 1 ]
[ 1, 3, 1, 2 ]
[ 1, 3, 1, 3 ]
[ 1, 3, 2, 1 ]
[ 1, 3, 2, 2 ]
[ 1, 3, 2, 3 ]
[ 1, 3, 3, 1 ]
[ 1, 3, 3, 2 ]
[ 1, 3, 3, 3 ]
[ 1, 4, 1 ]
[ 1, 4, 2 ]
23
module.exports = (function(){

    var prototype = {}
    var instances_counter = 0

    prototype.constructor = function()
    {
        if(!(this instanceof prototype.constructor))
        {
            return new (Function.prototype.bind.apply(prototype.constructor, [null].concat(Array.prototype.slice.call(arguments))))
        }
        this.id = ++instances_counter
    }

    prototype.render = function()
    {
        console.log(this.id)
    }

    prototype.constructor.prototype = prototype
    return prototype.constructor

})()

http://stackoverflow.com/questions/2856059/passing-an-array-as-a-function-parameter-in-javascript
http://stackoverflow.com/questions/3914557/passing-arguments-forward-to-another-javascript-function

[ ]
 
var sqlite3 = require('sqlite3')

var sqlite3_Database_handler = (function(){ 

    var prototype = {}

    prototype.constructor = function(target)
    {
        this.target = target
    }

    prototype.get = function(receiver, name)
    {
        if(name == "all")
        {
            var target = this.target
            return function(query)
            {
                var deferred = require('q').defer()
                target.all(
                    query,
                    function(error,rows)
                    {
                        deferred.resolve({error:error,rows:rows})
                    }
                )
                return deferred.promise
            }
        }
        return this.target[name]; 
    }

    return prototype.constructor.prototype = prototype

})().constructor

var sqlite3_handler = (function(){ 

    var prototype = {}

    prototype.constructor = function(target)
    {
        this.target = target
    }

    prototype.get = function(receiver, name)
    {
        if(name == "Database")
        {
            var Database = this.target.Database
            return function()
            {
                return Proxy.create(
                    new sqlite3_Database_handler(
                        new (Database.bind.apply(
                            Database,
                            arguments
                        ))
                    )
                )
            }
        }
        return this.target[name]; 
    }

    return prototype.constructor.prototype = prototype

})().constructor

module.exports = Proxy.create(new sqlite3_handler(sqlite3))
var sqlite3 = require('sqlite3')

module.exports = Proxy.create(new((function(){ 

    var prototype = {}

    prototype.constructor = function(target)
    {
        this.target = target
    }

    prototype.get = function(receiver, name)
    {
        console.log("GET " + name)
        return this.target[name]; 
    }

    return prototype.constructor.prototype = prototype

})().constructor)(sqlite3))

Проблема заключалась в том, что если не возвращать true, Array.every прекращает свою работу.

[ ]
 

И стаковерфлов о них: http://stackoverflow.com/questions/21017329/could-i-execute-function-right-before-closure-death-garbage-collection

function getRandomInt(min, max)
{
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

var server = require('http').createServer(function(request, response)
{
    var atEnd = function()
    {
        response.end('No more randoms for you.')
    };

    (function(){    

        response.statusCode = 200;
        response.setHeader('Content-Type','text/html; charset=UTF-8');

        // This loop is emulating a huge sophisticated complex async
        // callback delirium which cannot be easily understood and
        // tracked down, and I won't get paid for its refactoring.
        for(var i = 0;i < getRandomInt(0,getRandomInt(0,1000)); i++)
        {
            setTimeout(function()
            {
                response.write(String(getRandomInt(0,1000) + "<br/>"))
            },getRandomInt(0,30000))
        }

    //  What I'd wish to do:
    //  require('some-cool-module').onClosureDeath(atEnd)

    })()
}
).listen(11111);
[ ]
 

После обновления модулей через npm, я стал получать следующую ошибку:

Error: Cannot find module './binding/Release/node-v11-linux-ia32/node_sqlite3.node'

Я попробовал исправить её при помощи следующих команд, но ни одна из них не помогла.

sudo npm install sqlite3 --build-from-source=sqlite3
sudo npm install sqlite3 --build-from-source
sudo npm install sqlite3 --target_arch=ia32
sudo npm install sqlite3 --stage

Тогда я решил скачать бинарник отсюда https://github.com/mapbox/node-sqlite3/wiki/Binaries#available-binaries
Прямая ссылка: http://node-sqlite3.s3.amazonaws.com/index.html?path=Release/

И распаковать их прямиком в ~/node_modules/sqlite3/lib/binding/Release что помогло исправить ошибку.

wget http://node-sqlite3.s3.amazonaws.com/Release/node_sqlite3-v2.1.a-node-v11-linux-ia32.tar.gz --output-document=./node_sqlite3-v2.1.a-node-v11-linux-ia32.tar.gz
tar -zxvf node_sqlite3-v2.1.a-node-v11-linux-ia32.tar.gz -C ~/node_modules/sqlite3/lib/binding/Release
rm node_sqlite3-v2.1.a-node-v11-linux-ia32.tar.gz
[ ]
 

UPD: новое решение, украденное со стаковерфлооу.

gnome-terminal --execute /bin/bash -c "/bin/bash /home/space1000/horse_fucking_a_parrot.sh; exec /bin/bash -i"

Старый текст поста:
Как оставить gnome-terminal открытым после выполнения программы? Очень простым и очевидным даже самому глупому юзеру путем:

1. Создать файлик keep_terminal_open.sh
2. Дать ему права на выполнение в качетсве программы.
3. Впендюрить туда следующий текст:

#! /bin/sh
$1
bash

4. Вызывать нужную команду примерно таким образом (в моем случае это node.js)

cmd = 'gnome-terminal --execute '
+ __dirname + '/keep_terminal_open.sh '
+ '"node ' + __dirname + '/runme.js"'
console.log(cmd)
require('child_process').exec(cmd)

в bash это выглядит примерно так:

gnome-terminal --execute /home/user/test616/keep_terminal_fucking_open.sh "node /home/user/test616/runme.js"

5. Радоваться полчаса. А все потому, что gnome-terminal косячный, хоть и очень красивый.

Roses are red
Violets are blue
The title is in English...
Use google translate, you!

[ ]