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)
New and Fresh Private + Public Proxies Lists Everyday!
Get and Download New Proxies from NewProxyLists.com
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)
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?
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?
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?
I made a plugin to allow wordpress login with external api.
Everything works, now what I have to do is that when a user logs in for the first time, the plugin checks to see if it is already present on wp, and where it was not already present, it creates a new user by taking behind username, email and password.
The new user is created but I would like it to bring with it also the id field from the external api saving it in an ACF field.
This is the code created so far:
<?php
/************************************
* API Authentication
************************************/
add_filter('authenticate', 'au_auth', 10, 3);
/**
* Calls external API when user logs in to WordPress
*
* @param $user
* @param $username
* @param $password
* @return bool|false|object|WP_Error|WP_User
*/
function au_auth($user, $username, $password)
{
$options = get_option('au_options');
$endpoint = $options('au_apiurl');
$user_email_key = 'email';
$password_key = 'password';
// Makes sure there is an endpoint set as well as username and password
if (!$endpoint || $user !== null || (empty($username) && empty($password))) {
return false;
}
// Check user exists locally
$user_exists = wp_authenticate_username_password(null, $username, $password);
if ($user_exists && $user_exists instanceof WP_User) {
$user = new WP_User($user_exists);
return $user;
}
// Build the POST request
$login_data = array(
$user_email_key => $username,
$password_key => $password
);
$auth_args = array(
'method' => 'POST',
'headers' => array(
'Content-type: application/x-www-form-urlencoded'
),
'sslverify' => false,
'body' => $login_data
);
$response = wp_remote_post($endpoint, $auth_args);
// Token if success; Not used right now
$response_token = json_decode($response('response')('token'), true);
$response_code = $response('response')('code');
if ($response_code == 400) {
// User does not exist, send back an error message
$user = new WP_Error('denied', __("<strong>Error</strong>: Your username or password are incorrect."));
} else if ($response_code == 200) {
// External user exists, try to load the user info from the WordPress user table
$userobj = new WP_User();
// Does not return a WP_User object but a raw user object
$user = $userobj->get_data_by('email', $username);
if ($user && $user->ID) {
// Attempt to load the user with that ID
$user = new WP_User($user->ID);
}
} else {
// The user does not currently exist in the WordPress user table.
// Setup the minimum required user information
$userdata = array(
'user_email' => $username,
'user_login' => $username,
'user_pass' => $password
);
// A new user has been created
$new_user_id = wp_insert_user($userdata);
// Assign editor role to the new user (so he can access protected articles)
wp_update_user(
array(
'ID' => $new_user_id,
'role' => 'editor'
)
);
// Load the new user info
$user = new WP_User ($new_user_id);
}
}
// Useful for times when the external service is offline
remove_action('authenticate', 'wp_authenticate_username_password', 20);
return $user;
}
Anyone have any way how to help me?
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.
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?
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.
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 ?
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', '');