#StackBounty: #php #sockets #websocket #rabbitmq #swoole Swoole with RabbitMQ

Bounty: 50

I’m trying to send some data from php application to the user’s browser using websockets. Therefore I’ve decided to use Swoole in combination with RabbitMQ.

It’s the first time I’m working with websockets and after reading some posts about Socket.IO, Ratchet, etc. I’ve decided to halt on Swoole because it’s written in C and handy to use with php.

This is how I understood the idea of enabling data transfer using websockets:
1) Start RabbitMQ worker and Swoole server in CLI
2) php application sends data to RabbitMQ
3) RabbitMQ sends message with data to worker
4) Worker receives message with data + establishes socket connection with Swoole socket server.
5) Swoole server broadcasts data to all connections

The question is how to bind Swoole socket server with RabbitMQ? Or how to make RabbitMQ to establish connection with Swoole and send data to it?

Here is the code:

Swoole server (swoole_sever.php)

$server = new swoole_websocket_server("", 2345, SWOOLE_BASE);

$server->on('open', function(SwooleWebsocketServer $server, $req)
    echo "connection open: {$req->fd}n";

$server->on('message', function($server, SwooleWebsocketFrame $frame)
    echo "received message: {$frame->data}n";
    $server->push($frame->fd, json_encode(["hello", "world"]));

$server->on('close', function($server, $fd)
    echo "connection close: {$fd}n";


Worker which receives message from RabbitMQ, then makes connection to Swoole and broadcasts the message via socket connection (worker.php)

$connection = new AMQPStreamConnection('', 5672, 'guest', 'guest');
$channel = $connection->channel();

$channel->queue_declare('task_queue', false, true, false, false);

echo ' [*] Waiting for messages. To exit press CTRL+C', "n";

$callback = function($msg){
    echo " [x] Received ", $msg->body, "n";
    sleep(substr_count($msg->body, '.'));
    echo " [x] Done", "n";

    // Here I'm trying to make connection to Swoole server and sernd data
    $cli = new swoole_http_client('', 2345);

    $cli->on('message', function ($_cli, $frame) {

    $cli->upgrade('/', function($cli)
        $cli->push('This is the message to send to Swoole server');

$channel->basic_qos(null, 1, null);
$channel->basic_consume('task_queue', '', false, false, false, false, $callback);

while(count($channel->callbacks)) {


New task where the message will be send to RabbitMQ (new_task.php):

$connection = new AMQPStreamConnection('', 5672, 'guest', 'guest');
$channel = $connection->channel();

$channel->queue_declare('task_queue', false, true, false, false);

$data = implode(' ', array_slice($argv, 1));
if(empty($data)) $data = "Hello World!";
$msg = new AMQPMessage($data,
    array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)

$channel->basic_publish($msg, '', 'task_queue');

echo " [x] Sent ", $data, "n";


After starting both swoole server and worker I’m triggering new_task.php from command line:

php new_task.php

In command line prompt where a RabbitMQ Worker is running (worker.php) I can see that a message is delivered to the worker (“[x] Received Hello World!” message is appearing).

However in command line prompt where Swoole server is running happens nothing.

So the questions are:
1) Is the idea of this approach right?
2) What am I doing wrong?

Get this bounty!!!

#StackBounty: #machine-learning #logistic #predictive-models #application #domain-adaptation Testing the scope of application of a logi…

Bounty: 50

My aim is to assess whether I can apply a logistic regression that was fitted on a sample A (where I have explanatory variables and the outcomes) to a different sample B where I don’t know the outcomes yet.

The measure later when I have outcomes would be discriminatory power.

What statistical approaches can I use here? Is this a problem that is known and studied in statistics? Can we apply methods in the context of dataset shift here?

Can we argue with some sort of similarity between A and B? If we assume that the joint distribution of $(X,y)$ or better the conditional distribution of the features $y$ given the target $X$ is the same on A and B?

Get this bounty!!!

#StackBounty: #html #css #html5 Converting DIV-like page into blog-like layout within CSS?

Bounty: 50

This is my HTML page:

https://jsfiddle.net/62czmtvt/2/ (to actually see the HTML page working)

Code from JSFiddle:

  <meta charset="utf-8">

  <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
       Remove this if you use the .htaccess -->
  <meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1">
<!-- this is the stylesheet in the file -- <link rel="stylesheet" type="text/css" href="style.css"> -->
<!-- contents of style.css -->
:root {
background-color: #FFFACD;
div.infoguide { 
width: 240px; 
font-family: Arial, sans-serif; 
background-color: #F0FFF0;
div {
A:link { text-decoration: underline; color: rgb(204, 51, 51); }
A:visited { text-decoration: underline; color: rgb(204, 51, 51); }
A:active { text-decoration: underline; color: rgb(204, 51, 51); }
A:hover { text-decoration: underline; color: rgb(204, 51, 51); }
body { margin-left: 0px; margin-top: 0px; }
body, td, th { font-family: Arial,Helvetica,sans-serif; font-size: 12px; color: rgb(46, 46, 46); line-height: 16px; }
h1 { font-family: Arial,Helvetica,sans-serif; font-size: 20px; font-weight: bold; line-height: 20px; margin-bottom: 0px; }
h2 { font-family: Arial,Helvetica,sans-serif; font-size: 15px; font-weight: bold; margin-bottom: 0px; }
h3 { font-family: Arial,Helvetica,sans-serif; font-size: 13px; font-weight: bold; margin-bottom: 0px; }
h3 A:link { text-decoration: none; color: rgb(204, 51, 51); }
h3 A:visited { text-decoration: none; color: rgb(204, 51, 51); }
h3 A:active { text-decoration: none; color: rgb(204, 51, 51); }
h3 A:hover { text-decoration: underline; color: rgb(204, 51, 51); }
ul { margin-left: 1.5em; padding-left: 0px; }
.info_data { border-color: rgb(137, 137, 137); border-style: solid; border-width: 1px; font-size: 11px; padding: 4px; text-align: center; }

.news_headline { font-family: Arial,Helvetica,sans-serif; font-size: 15px; font-weight: bold; line-height: 22px; }
.red { color: rgb(204, 51, 51); }
.red_padded { color: rgb(204, 51, 51); padding: 4px 0px; }
.redbg { background-color: rgb(220, 6, 0); } 
      <title>First Drive: 2017 Porsche Panamera - Autos.ca</title>

It works!

It works!

A headline

It works!

It’s a sandbox page for a blog-like layout of a magazine site, and I’m trying to achieve this sort of look:

Magazine article

but so far I haven’t quite managed to get it to look the way I want to of being a three-column DIV with a header in a pseudo-blog-style layout.

I’ve been trying the :root element in my CSS file, is this encouraged or discouraged in a HTML5 page?

I would appreciate any advice or help with this!

Get this bounty!!!

#StackBounty: #machine-learning #logistic #t-test #svm #feature-selection How do I use weight vector of SVM and logistic regression for…

Bounty: 50

I have trained a SVM and logistic regression classifier on my dataset for binary classification. Both classifier provide a weight vector which is of the size of the number of features. I can use this weight vector to select the 10 most important features. For doing that I have turned the weights into t-scores by doing a permutation test. I did 1000 permutations of the class labels and at each permutation I calculated the weight vector. In the end I subtracted the mean of the permuted weights from the real weights and divided by the standard deviation of the permuted weights. So I have now t-scores.

Should I use the absolute values of the t-scores, i.e. selecting the 10 features with the highest absolute values? So let’s say the features have the following t-scores:

feature 1: 1.3
feature 2: -1.7
feature 3: 1.1
feature 4: -0.5

If I select the 2 most important features by considering the highest absolute values, feature 1 and 2 would win. If I consider not the absolute values, feature 1 and 3 would win.

Second, this only works for SVM with linear kernel but not with RBF kernel as I have read. For non-linear kernel the weights are somehow no more linear. What is the exact reason that the weight vector cannot be used to determine the importance of features in case of non-linear kernel SVM?

Get this bounty!!!

#StackBounty: #mining-pools #mining-theory #nonce #stratum What's an example of an ExtraNonce2 value that would be considered inval…

Bounty: 50

I’ve been learning about mining as part of a pool and using the Stratum protocol to submit completed work back to a pool — https://en.bitcoin.it/wiki/Stratum_mining_protocol . There is this parameter, “ExtraNonce2,” a value that the miner keeps changing. Could someone tell me a scenario where a pool worker submits a nonce that correctly hashes the data it was given according to the difficulty, but it submits an “ExtraNonce2” value that causes the mining pool to reject the submission?

Get this bounty!!!

#StackBounty: #instagram Is any web-working autopost tool for Instagram which allows adding several photos per post?

Bounty: 100

I am looking for web-working auto post tool for Instagram which allows adding several photos per post. Free or paid. Can you recommend one?

All apps I have found, makes Instagram post with only 1 picture per post. But I need up to 10 pictures in one post.

I need to publish 5-10 post per day. Each post will have up to 10 pictures of items we sell.
I need this tool because we work using PC, not tablets, not smartphones. So we can not use Instagram directly.
We don’t need scheduler option.

Get this bounty!!!

#StackBounty: #hypothesis-testing #statistical-significance #normal-distribution #optimization #central-limit-theorem Picking a signifi…

Bounty: 50

Suppose you are running a casino and that you are responsible for ensuring that all the dice are fair to avoid lawsuits. In order to do this, you take a mean of 1000 throws of each die and perform a hypothesis test [using the central limit theorem, CLT] to see whether they are likely biased.

The average cost of a lawsuit is £240000, whilst the cost of a die is £3, so in order to minimise costs you would aim to have $240000P(textrm{Type II Error}) = 3alpha$ where $alpha$ is the significance level of the hypothesis test (and also the probability of a type I error). The cost of testing the die may be ignored.

Now, in order to find the optimal $alpha$ value, one must know the value of $P(textrm{Type II Error})$, something that can only be calculated if the actual mean of the die (which is what we are testing for in the first place) is known, so the optimal solution cannot be found. That being said, however, I’m sure scenarios like this arise rather often, so how are they usually dealt with?

tldr: How would you find a threshold value for the mean of a die above (or below) which it should be considered biased whilst also keeping $240000P(textrm{Type II Error}) approx 3P(textrm{Type I Error})$

Edit: It seems my choice of example is rather poor, as a die shouldn’t even be tested for fairness with a test like this. That being said, however, my question really concerns the tradeoff between Type I and Type II error, not the die in particular.

Get this bounty!!!

#StackBounty: #go #yaml Validate yaml schema with golang for specifed schema structure

Bounty: 100

We have tool which need to read yaml file with specific structure.
When we got the yaml file we need to know if

  1. Check if the yaml file is valid according to some guideline
  2. Where is the syntax error if any

For example this is example of the validation that we need to address

   _version:  {required: true}
   id: {required: true, pattern: '/^[A-Za_-.]+$/'}   
   release-version: {required: true}

        name:{required: true, unique: true, pattern: '/^[A-Za-z0-3_-.]+$/'}
          type: map
          mapping: { =: {type: any} } 
  1. Mapping is a key value object
  2. seq can have multiple builds
  3. type any is and key value

We use this open source to parse the yaml

Get this bounty!!!