Condition for a cubic equation to have a single root

If a cubic equation

$$ f(x) = ax^3+bx^2+cx+d$$

Is given, what is the condition for the equation to only have a single root (counting multiple roots as one)

Single Page Application com express e ejs

Olá, gostaria de saber se é possível fazer uma SPA (Single Page Application) com express e ejs, se sim qual seria a maneira mais recomendada para fazer isso?

Do interactive prototypes have to have every single possible screen?

When prototyping an app do you have to prototype every single screen and screen state in the app so it seems like a coded product? Or is it just certain key flows? Wouldn’t the prototype run into several hundreds of screens if I prototyped every inch of an app?

Search flights from entire Europe to entire SouthAmerica in a single search?

Which sites exist to search for prices of flights with departure entire Europe and destination entire South America, one way, period from date X to Y, in a single search; besides kiwi.com?

mariadb – Galera cluster slightly slower than single database?

I recently set up a MariaDB galera cluster for our production. I used sysbench to benchmark the cluster against the old database which is on a single server.

On my PRD Galera Cluster I got the following results:

SQL statistics:
    queries performed:
        read:                            3914980
        write:                           0
        other:                           782996
        total:                           4697976
    transactions:                        391498 (1304.77 per sec.)
    queries:                             4697976 (15657.22 per sec.)
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)

General statistics:
    total time:                          300.0492s
    total number of events:              391498

Latency (ms):
         min:                                    5.37
         avg:                                   12.26
         max:                                   66.20
         95th percentile:                       15.83
         sum:                              4798745.23

Threads fairness:
    events (avg/stddev):           24468.6250/414.77
    execution time (avg/stddev):   299.9216/0.01

Meanwhile our old single database production got this results:

SQL statistics:
    queries performed:
        read:                            5306060
        write:                           0
        other:                           1061212
        total:                           6367272
    transactions:                        530606 (1768.51 per sec.)
    queries:                             6367272 (21222.18 per sec.)
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)

General statistics:
    total time:                          300.0266s
    total number of events:              530606

Latency (ms):
         min:                                    3.87
         avg:                                    9.04
         max:                                   59.99
         95th percentile:                       12.08
         sum:                              4798278.00

Threads fairness:
    events (avg/stddev):           33162.8750/440.14
    execution time (avg/stddev):   299.8924/0.01

Now I’m wondering why does the cluster operate a bit slower than the single database? They have the same specs: Quadcore CPU, 32GB RAM and vm.swappiness=1. Here’s my cluster configuration (same across 3 servers) and is using HAProxy to load balance between 3 servers:

max_connections = 3000

wsrep_slave_threads=4
innodb_lock_wait_timeout=8000
innodb_io_capacity=2000
innodb_buffer_pool_size=25G
innodb_buffer_pool_instances=25
innodb_log_buffer_size=256M
innodb_log_file_size=1G
innodb_flush_log_at_trx_commit=2
innodb_flush_method = O_DIRECT_NO_FSYNC

innodb_read_io_threads=8
innodb_write_io_threads=4

thread_handling = pool-of-threads
thread_stack = 192K
thread_cache_size = 4
thread_pool_size = 8
thread_pool_oversubscribe = 3

wsrep_provider_options="gcache.size=10G; gcache.page_size=10G"

I used sysbench on a spare server, does the latency between servers also affect the outputs? I would appreciate any inputs, thank you.

php – Hide out of stock only from shop page, not single product variations

So I currently have a shop that uses different variations of products as the sizes.

I have added some code that “greys out” any variations that are out of stock in the drop down on my single products page, as I’d like people to be able to see what sizes may be back in stock soon etc.

There are some single products completely out of stock so I’d like these to be hidden on the shop page, there is an option in WooCommerce but enabling this also hides the out of stock variations on the single product page, which I don’t want to do.

Any ideas how this can be achieved?

object oriented – Apply Single Responsibility Principle java

I have a service that converts a xls file into html. It is working just fine, but it is quite a big method that doesn’t follow any SOLID principles. Therefore I would like to improve it to follow at least the Single Responsibility Principle. But I really don’t know how to apply it and find the level of abstraction in my case.

@Service
public class xlsToHtmlImpl implements MultipartFileToHtmlService {

private final HtmlLayout htmlLayout;

@Autowired
public xlsToHtmlImpl(HtmlLayout htmlLayout) {
    this.htmlLayout = htmlLayout;
}


@Override
public InputStream multipartFileToHtml(MultipartFile multipartFile, boolean hasOnlyOneSheet, boolean hasBorders) throws IOException {

    String fileName = multipartFile.getOriginalFilename();
    BufferedInputStream inputStream = new BufferedInputStream(multipartFile.getInputStream());

    Workbook workbook;
    assert fileName != null;
    //Selecting workbook depending on FileType
    if (fileName.toLowerCase().endsWith(htmlLayout.FILE_TYPES(0))) {
        workbook = new HSSFWorkbook(inputStream);
    } else {
        workbook = new XSSFWorkbook(inputStream);
    }
    //Writing content of multipartFile to outputstream
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    outputStream.write(htmlLayout.openStyle());

    //Selecting style to apply depending on user input
    if (hasBorders) {
        outputStream.write(htmlLayout.noBordersStyle());
    } else {
        outputStream.write(htmlLayout.withBordersStyle());
    }
    outputStream.write(htmlLayout.closeStyle());

    outputStream.write(htmlLayout.openNewHtml());
    outputStream.write(fileName.getBytes());


    //Different algorithm for the content of the body depending on user input
    Sheet sheet;
    if (hasOnlyOneSheet) {
        sheet = workbook.getSheetAt(0);
        Iterator<Row> rows = sheet.rowIterator();
        while (rows.hasNext()) {
            Row row = rows.next();
            Iterator<Cell> cells = row.cellIterator();
            outputStream.write(htmlLayout.newLine());
            outputStream.write(htmlLayout.newRow());
            while (cells.hasNext()) {
                Cell cell = cells.next();
                outputStream.write(htmlLayout.newCell());
                outputStream.write(cell.toString().getBytes());
                outputStream.write(htmlLayout.closeCell());

            }
            outputStream.write(htmlLayout.closeRow());
        }
    } else {
        for (int i = 0; i< workbook.getNumberOfSheets(); i++) {
            sheet = workbook.getSheetAt(i);
            Iterator<Row> rows = sheet.rowIterator();
            outputStream.write(htmlLayout.newLine());
            outputStream.write(htmlLayout.newRow());
            outputStream.write(htmlLayout.closeCell());
            outputStream.write(htmlLayout.closeRow());
            outputStream.write(htmlLayout.newLine());
            while (rows.hasNext()) {
                Row row = rows.next();
                Iterator<Cell> cells = row.cellIterator();
                outputStream.write(htmlLayout.newLine());
                outputStream.write(htmlLayout.newRow());
                while (cells.hasNext()) {
                    Cell cell = cells.next();
                    outputStream.write(htmlLayout.newCell());
                    outputStream.write(cell.toString().getBytes());
                    outputStream.write(htmlLayout.closeCell());

                }
                outputStream.write(htmlLayout.closeRow());
            }
        }
    }

    outputStream.write(htmlLayout.newLine());
    outputStream.write(htmlLayout.closeHtml());
    outputStream.close();

    //Returning result as ByteArrayInputStream to controller
    return new ByteArrayInputStream(outputStream.toByteArray());
}

Where htmlLayout contains html snippet like:

public byte() closeHtml() {return "</table></body></html>".getBytes();}

I tried to follow this article: https://www.baeldung.com/java-single-responsibility-principle#:~:text=As%20the%20name%20suggests%2C%20this,only%20one%20reason%20to%20change.&text=These%20classes%20are%20harder%20to%20maintain.

Following this article, I tried to create different classes as follow:

public class HtmlStyleWrapper {

private byte() style;


public byte() withBordersStyle() {
    return ("table, td{" +
            "    border: 1px solid black;n" +
            "    border-collapse: collapse;n" +
            "    padding: 9px;n" +
            "}").getBytes();
}

public byte() noBordersStyle() {
    return ("td {" +
            "    padding: 9px;n" +
            "}").getBytes();
}

public byte() openStyle() {
    return "</title></head><body><style>".getBytes();
}

public byte() closeStyle() {
    return "</style><table>".getBytes();
}

public void wrapStyle(ByteArrayOutputStream outputStream, boolean hasBorders) throws IOException {
    outputStream.write(openStyle());
    if (hasBorders) {
        outputStream.write(noBordersStyle());
    } else {
        outputStream.write(withBordersStyle());
    }
    outputStream.write(closeStyle());
}


public class HtmlBodyWrapper {

private byte() body;

public byte() openNewHtml() {
    return "<!DOCTYPE html><html><head><title>".getBytes();
}

public byte() newLine() {
    return "n".getBytes();
}

public byte() closeHtml() {
    return "</table></body></html>".getBytes();
}

public byte() newRow() {
    return "<tr>".getBytes();
}

public byte() closeRow() {
    return "</tr>".getBytes();
}

public byte() newCell() {
    return "<td>".getBytes();
}

public byte() closeCell() {
    return "</td>".getBytes();
}

public void wrapBody(ByteArrayOutputStream outputStream, String fileName, boolean hasOnlyOneSheet, Workbook workbook) throws IOException {
//Write to outputstream
}

The aim would be to get something like

wrapHTMLBody(wrapStyle(htmlLayout.getHTML_STYLE()), table)

But I feel like I’m not taking the right approach and that I didn’t understand correctly SRP.

How can a single miner be rewarded less than the current reward?

If a miner starts mining at 40 TH/s it’d make 0.0002462 bitcoin/day (according to this calculator).

Is ~0.0002462 bitcoin actually something that will belong to the miner after an effective 24h of work ?

Since the current reward is 6.25 bitcoin, how can the miner be in posession of less than this reward after any frame of time ?

From my understanding, either the miner has successfully mined the entire block and gets rewarded 6.25 btc OR it hasn’t, and gets rewarded nothing.

Are those figures from common calculators merely an illustration, or does it actually depicts an estimation of what the miner will be in possession ?

export – Convert single and double quotes, dashes, etc. to correct character encoding in WXR import file?

I’ve exported a WordPress export file for import into a new WordPress site.

However, I get the error “This does not appear to be a WXR file, missing/invalid WXR version number”

After some searching, it appeared to be a character encoding issue. I tried running the following code:

$content = utf8_encode(file_get_contents('my-import-file.xml'));

$invalid_characters = '/(^x9xax20-xD7FFxE000-xFFFD)/';

$content = preg_replace($invalid_characters, '', $content );

echo htmlentities($content);

This produced a string that I can copy and paste into a .xml file that I can then successfully import into my site. However, this string has lots of broken characters, such as “â”. Upon comparing with my original string, it seems like these are single quotes, double quotes, dashes, etc.

Based on the answers suggested in this thread, I tried running the following code:

$content = file_get_contents('my-import-file.xml');

$output = iconv('UTF-8', 'ASCII//TRANSLIT', $content);  

echo htmlentities( $output );

This gives me a blank screen with only the following error:

Notice: iconv(): Detected an illegal character in input string in /srv/www/my-site/public_html/load-string.php on line 5

My source site that I’m exporting from is fairly old (created around 2012 or so), but my wp-config.php on my source site has the following set:

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');