## Counting function first; is it true that \$ pi (n – m)> pi (n) – pi (m) \$?

Let $$pi$$ to be the primary function of counting, and m, n positive integers, $$n> m$$

Is it proven that $$pi (n – m)> pi (n) – pi (m)$$ ?

## c ++ – Optimizing log function calls based on global logging level

I am a member of a university team that designs a nanosatellite.
We decided to implement our own (lighter) logging library to use, instead of, for example, that of Google. `glog`, `spdlog`, `plog` and `Boost::Log`.

• The concept of different levels of logging is introduced, allowing log messages to be divided into subcategories based on their severity and eventuality.
• In addition, a "global log level" can be defined.
Anything less serious than the severity defined as global journal level do not to be connected.

Due to obvious restrictions, it is imperative that log calls below the global log level be optimized at compile time.

The first attempt looked like this (single header file):
log levels:

``````// We can set the global log level by defining one of these
#if defined LOGLEVEL_TRACE
#define LOGLEVEL Logger::trace
#elif defined LOGLEVEL_DEBUG
#define LOGLEVEL Logger::debug
#elif defined LOGLEVEL_INFO
(...)
#else
#define LOGLEVEL Logger::disabled
#endif
``````

the levels themselves are `enum` members:

``````enum LogLevel {
trace = 32, // Very detailed information, useful for tracking the individual steps of an operation
debug = 64, // General debugging information
info = 96, // Noteworthy or periodical events
(...)
};
``````

A `operator<<` overload for better readability:

``````template
Logger::LogEntry& operator<<(Logger::LogEntry& entry, const T value) {
etl::to_string(value, entry.message, entry.format, true);

return entry;
}
``````

And the macro`constexpr` ritual to make the compiler do what we want:

``````#define LOG(level)
if (Logger::isLogged(level))
if (Logger::LogEntry entry(level); true)
entry
// (...)
static constexpr bool isLogged(LogLevelType level) {
return static_cast(LOGLEVEL) <= level;
}
``````

There were a lot of problems with this code (see MR discussion for more).

• An operator of call `enum LogLevel` has been added to return a new `static LogEntry`.
• It is `inline`to force `const` spread to `-O1`.
• Two `LogEntry` `enums` has been created.
• The second is a `nop` with all `inline`.
• `if constexpr` the syntax has been added.

and more (see here and below for justification.)

It's the (hashed) state of the code currently:

``````#include
#include

#define LOGLEVEL_EMERGENCY

#if defined LOGLEVEL_TRACE
#define LOGLEVEL Logger::trace
#elif defined LOGLEVEL_DEBUG
#define LOGLEVEL Logger::debug
#elif defined LOGLEVEL_INFO
#define LOGLEVEL Logger::info
#elif defined LOGLEVEL_NOTICE
#define LOGLEVEL Logger::notice
#elif defined LOGLEVEL_WARNING
#define LOGLEVEL Logger::warning
#elif defined LOGLEVEL_ERROR
#define LOGLEVEL Logger::error
#elif defined LOGLEVEL_EMERGENCY
#define LOGLEVEL Logger::emergency
#else
#define LOGLEVEL Logger::disabled
#endif

#define LOG_TRACE     (LOG())
#define LOG_DEBUG     (LOG())
#define LOG_INFO      (LOG())
#define LOG_NOTICE    (LOG())
#define LOG_WARNING   (LOG())
#define LOG_ERROR     (LOG())
#define LOG_EMERGENCY (LOG())

class Logger {
public:

Logger() = delete;

typedef uint8_t LogLevelType;

enum LogLevel : LogLevelType {
trace = 32,
debug = 64,
info = 96,
notice = 128,
warning = 160,
error = 192,
emergency = 254,
disabled = 255,
};

enum class NoLogEntry {};

struct LogEntry {
std::string message = "";
LogLevel level;

explicit LogEntry(LogLevel level);

~LogEntry();

LogEntry(LogEntry const&) = delete;

template
Logger::LogEntry& operator<<(const T value) noexcept {
message.append(value);

return *this;
}

Logger::LogEntry& operator<<(const std::string& value);
};

static constexpr bool isLogged(LogLevelType level) {
return static_cast(LOGLEVEL) <= level;
}

static void log(LogLevel level, std::string & message);
};

template
constexpr inline auto LOG() {
if constexpr (Logger::isLogged(level)) {
return Logger::LogEntry(level);
} else {
return Logger::NoLogEntry();
}
};

template
((maybe_unused)) constexpr Logger::NoLogEntry operator<<(const Logger::NoLogEntry noLogEntry, T value) {
return noLogEntry;
}

int main() {
LOG_NOTICE << "I am getting optimized away!";
LOG_EMERGENCY << "I am not getting optimized away, and rightfully so";

return 0;
}
``````

As you can see in the compiler explorer, for example, `LOG_NOTICE` becomes optimized far from `-O1`.

Do you have any suggestions?

## Simpler form of the function \$ f (x) = sum_ {n = 1} ^ infty a ^ {- n} * mu (n) \$

I still need help with the inversion of Moebius (I'm pretty terrible about this). I want to know if there is a simpler / other form of the function $$f (x) = sum_ {n = 1} ^ infty a ^ {- n} * mu (n)$$
or $$a = x ^ s.$$ If you could give me a hint, I'd appreciate it, but I'm stuck for now.

## Use action, filter, or hook to add HTML to the WordPress plugin function

I am new to WordPress' actions, filters and anchor points and I wonder if it is possible to use any of the three to add HTML code to a function of plug-in set using the theme's functions.php file. The HTML code is a help text that is currently in the main PHP file of the plug-in, but I would like to move it to the functions.php file because of future plug-in updates . The paragraph with the class "appended-text" is what needs to be added to the HTML using an action, filter or hook.

Function of the plugin:

``````public service insert_upload_form () {
if (! current_user_can (& # 39; upload_files & # 39;)) {
return; // Users must be author or superior
}

\$ user_id = \$ this-> get_user_id ();
\$ post_id = \$ this-> get_post_id (\$ user_id);

?>

<input type = "hidden" name = "metronet_profile_id" id = "metronet_profile_id" value = ""/>
<input type = "hidden" name = "metronet_post_id" id = "metronet_post_id" value = ""/>

<? php
\$ has_profile_image = false;
if (has_post_thumbnail (\$ post_id)) {
\$ has_profile_image = true;
echo & # 39;& # 39 ;;
\$ thumb_src = wp_get_attachment_image_src (get_post_thumbnail_id (\$ post_id), & # 39; thumbnail & # 39 ;, false, & # 39;);
\$ post_thumbnail = sprintf (& # 39;& Esc # 39; esc_url (\$ thumb_src (0)), esc_attr __ (& # 39; Download or edit a profile photo & # 39;, & quot; metronet-profile-picture & # 39;));
echo wp_kses_post (\$ post_thumbnail);
echo sprintf (& # 39;% s& # 39; esc_html __ (& quot; Click to edit & quot ;, & quot; metronet-profile-picture & # 39;));
echo & # 39;& # 39 ;;
} other {
echo & # 39;& # 39 ;;
\$ post_thumbnail = sprintf (& # 39;& # 39 ;, self :: get_plugin_url (& # 39; img / mystery.png & # 39;), esc_attr __ (& # 39; Import or edit a profile photo & # 39;, & # 39; metronet- profile-picture & # 39;));
echo wp_kses_post (\$ post_thumbnail);
echo sprintf (& # 39;% s& # 39; esc_html __ (& quot; Click to edit & quot ;, & quot; metronet-profile-picture & # 39;));
echo & # 39;& # 39 ;;
}
\$ remove_classes = array ('dashicons', 'dashicons-trash');
if (! \$ has_profile_image) {
\$ remove_classes () = mpp-no-profile-image & nbsp;
}
?>
<a id = "metronet-remove" class = ""href =" # "title ="">

<? php printf (& # 39;& # 39; esc_url (self :: get_plugin_url (& img / loading.gif & # 39;))); ?>

<type of entry = "checkbox" name = "metronet-user avatar" id = "metronet-user avatar" value = "on"  />

Note: The optimal image size is 200 pixels wide and 200 pixels high.
The maximum file size is 200 KB.
(Your profile picture may appear "overwritten" in this preview, but it will normally appear in articles and events you post, as well as on your author page.)

<? php
/ **
* Allow other plug-ins to execute code after user interface of the user's profile picture.
*
* @ since 2.3.0
*
* /
do_action (& # 39; mpp_user_profile_form & # 39 ;, \$ user_id);
``````

## refactoring python function to make it more redable and testable

I have a function whose responsibility is to send a push notification to a user. I call this function from a view in the flask framework.

NOTE: This is not a generic or opinion-based question and I've added a python tag because my implementation is in python. In addition, I have read several articles on refactoring for good designs and I want to know of those who have been doing it for a while

here is the function.

`````` def send_push(api_key, cid, username,request_signature):

## ---> DB CALLS
master_db = get_db('master_db')
cname = master_db.companies.find_one({'company_id': cid})('company_name')
company_db = get_db(cname)
application = company_db.applications.find_one({'app_config.api_key':api_key})

if not application:
#error_log_writer(cid=cid, error='API Key is invalid')
raise InvalidApiKey('The API Key is incorrect.')

appname = application('app_name')

# application = company_db.applications.find_one({'app_name': appname})
redis_db = get_redis()

## DB CALLS
# error_log_writer(cid=cid, error='The PUSH request is already in process', appname=appname)
raise SomeCustomException(' The request is already in process.')

auth_id = generate_random_alphanumeric(10)

api_key="xxxxx"
)

## DB CALLS

if not user:
raise UserNotFound

## DB CALLS

data_message = {
"Nick" : "Mario",
"body" : "great match!",
"app_name": appname,
"cid": cid,
"auth_id" : auth_id,
"api_key": api_key,
"request_signature":request_signature
}
message_body = "authenticate app?"

## DB CALLS
redis_data = {'auth_id': auth_id, 'ts': datetime.datetime.now().strftime('%s')}

result = push_service.notify_single_device(registration_id=registration_id,  data_message=data_message)
``````

I think this has a lot of code smell. the things I want to have after refactoring are.

• easy unit tests
• Avoid simulacra for unit tests if necessary
• minimal side effects

Current problem that I think are:

• Many database calls scattered around the core business logic.
• Unit testing is difficult because many database calls need to be mocked
them.that closely couples test to my implementation rather than
behavior of this function.
• A lot of indirection to logic is introduced because of scattered calls
to mongo db & redis

Possible solutions:

• pass db objects to work rather than create them inside the
function that manages the business logic (but this will only postpone the
creatoion object to a higher level so that calls to the database will have to be mocked
anyway)

How will you restructure this function by considering best practices?

Is it a common practice when developing the CRUD application to have several simulacra on average for each function?

## 5th dnd – If a dragon under the effects of its Change Shape function is cloned, can the cloned dragon return to its true form?

Some dragons have the Change Shape feature. For example, the shape change feature of the ancient gold dragon reads as follows:

Change shape. The dragon magically transforms into a humanoid or beast whose challenge is not greater than his own or his true form. He resumes his real form if he dies. Any equipment that he wears or carries is absorbed or worn by the new form (the choice of the dragon).

In a new form, the dragon retains its alignment, health, dice, ability to speak, skills, legendary resistance, actions, scores in Intelligence, Wisdom, and Charisma, as well as that action. Its statistics and features are replaced by those of the new form, with the exception of class features or legendary actions on this form.

This seems to make it eligible for the Clone spell, which reads as follows (that's me pointing out):

This spell develops an inert duplicate of a living creature and average like a
protect against death. This clone forms in a sealed vessel and
reaches its size and maturity after 120 days; you can also choose from
have the clone be a younger version of the same creature. He stays
inert and lasts indefinitely, as long as his ship remains
peaceful.

At any time after the clone, if the original creature dies,
his soul is transferred to the clone, provided that the soul is free and
ready to come back. The clone is physically identical to the original
and has the same personality, the same memories and abilities, but none of the
the equipment of origin. The physical remains of the original creature, if
they always exist, become inert and can not be restored later.
life, since the soul of the creature is elsewhere.

Now, probably if you were using Clone on a creature under the effects of True Polymorph, the spell would be only clone the active layer of True Polymorph, which means that the base creature below will not be cloned. However, the Change Shape function of the dragon gives it specifically the opportunity to reconvert itself into its true form with an action. I guess my confusion is just what it means for the cloned creature. Could he still return to his dragon form with an action, or would his "true form" now only be his cloned form, rendering this action essentially useless?

## php – Function to dry several relational loops ACF

As the title indicates, I use ACF to display data from 3 relational fields.

The problem is that I have to repeat the loop 3 times, one for each of the lists I want to render, I have the impression that there must be a way to write a simple function so that I do not repeat it too much:

``````

Solutions

Company

Resources

``````

How can I write such a function? Thank you in advance for your help.

## c ++ – How to rewrite 3 loops for a function

I build a color sorter using an Arduino uno and a TCS3200 color sensor. I have a code that works perfectly well, but I feel that the code could be a bit clearer since I use 3 almost identical loops for loops. Could anyone help me rewrite these 3 loops for a single loop? Thanks in advance!

As I mentioned, the code works perfectly. I only need help to rewrite these 3 loops

``````void loop() {

delay(150);
float frequencyR(3);

for(unsigned int i = 0; i < 3; i++) {
delay(150);
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
frequencyR(i) = pulseIn(sensorOut, LOW);

delay(150);

}
float frequencyG(3);

for(unsigned int i = 0; i < 3; i++) {
delay(150);
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
frequencyG(i) = pulseIn(sensorOut, LOW);

delay(150);

}
float frequencyB(3);

for(unsigned int i = 0; i < 3; i++) {
digitalWrite(S2, LOW);
digitalWrite(S3, HIGH);
frequencyB(i) = pulseIn(sensorOut, LOW);

delay(150);

}

``````

## reactjs – Change state in a function

I'm trying to change the selectedFile status from null to event.target.files (0), but it does not work in the onChangeHandler function.

``````import React, { Component } from "react";

export default class Comp1 extends Component {
constructor(props) {
super(props);
this.state = {
selectedFile: null,
};
}

onChangeHandler = event => {
console.log(event.target.files(0));   // <--THIS WORKS //
console.log(this.state.selectedFile); // <-- THIS WORKS //
this.setState({
selectedFile: event.target.files(0)
}); // THIS DOES NOT WORK //
console.log(this.state.selectedFile); // selectedFile did not update state //

};
render() {
return (
``````

Press

);
}
}
``````