## 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', '');
``````

## design – When components of an event-driven program require specific responses to specific events, is event-driven still the correct approach?

I’m working on a multi-threaded program that interfaces with external USB/serial devices via user-space device drivers.

Early in the design stage, I made the decision to split the program into three components: A, B and C.

• Component A would possess full responsibility of communication with external devices (this is where the user-space device drivers would run). It would run on a dedicated thread.
• Component B would serve an API off of a TCP/IP socket to third-party clients that needed access to the external devices. This component would also run on a dedicated thread.
• Component C would provide a GUI for the user, allowing them to view and manipulate data from the external devices. Again, this would be on a dedicated thread.

So components B and C both require access to the external devices, which component A would provide.

I needed a way for the three components to interface with each other, and at the time I thought making the program event-driven would be appropriate. With this approach, components would emit an event and other components would handle those events. I always knew that some events would require responses, in the form of subsequent events. For example, if component C wanted to pull some data from the external device, to present to the user in the GUI, it would emit an event to request the data from component A, and component A would handle that event, and return the requested data in a subsequent event, which component C would be waiting for.

Since defining the above approach, I’ve realised that, in some cases, a component may require a specific response to a specific event. So building off of the example above, if component C and component B requested different data from component A, component C should be able to wait for the correct response event (that is, the response to the event emitted by component C).

So I’m considering implementing the ability for a component to wait for an event that is a direct response to the previously emitted event. I would do this via event IDs, where each event would carry an ID, and an optional response ID. The response ID would be the ID of the event that the current event is in response to.

But I feel like I’m on the wrong path. Is this really an appropriate use of event-driven design? Is it OK for events to serve as requests for data, and subsequent events as responses? Would you do it differently? If so, how?

EDIT/UPDATE:

I’ve just come across this video by Mark Richards, which seems to describe my approach with event IDs and response IDs (which he calls “correlation IDs”). So maybe I’m not on the wrong path – he seems to think using events for request/response is fine. Would still appreciate your thoughts.

## magento2 – in env.php correct?

I have noticed that when I run bin/magento index:reindex && bin/magento cache:flush my cache folder continues to grow until the server runs out of space (around 350GB).

The only thing I have changed is adding consumers to the env.php file.

Can someone confirm that the following is correct

``````'queue' => (
'amqp' => (
'host' => 'hidden',
'port' => 'hidden',
'user' => 'hidden',
'virtualhost' => "https://magento.stackexchange.com/"
)
),
'cron_consumers_runner' => (
'cron_run' => true,
'max_messages' => 2000,
'only_spawn_when_message_available' => 1,
'maxIdleTime' => 5,
'consumers' => (
'product_action_attribute.update',
'product_action_attribute.website.update',
'exportProcessor',
'inventory.source.items.cleanup',
'inventory.mass.update',
'inventory.reservations.cleanup',
'inventory.reservations.update',
'media.storage.catalog.image.resize',
'codegeneratorProcessor',
'import_export.import_db',
'inventory.indexer.sourceItem',
'inventory.indexer.stock',
'media.content.synchronization',
'media.gallery.synchronization',
'async.operations.all',
'import_export.import_amqp'
)
),
``````

The server is running Litespeed, Magento 2.4.1 and RabbitMQ.

Thanks

## real analysis – Does a sequence of Jacobians converge to the ‘correct’ continuous part plus some controlled singular part?

$$newcommand{M}{mathcal{M}}$$
$$newcommand{N}{mathcal{N}}$$

Let $$M,N$$ be two-dimensional smooth, compact, connected, oriented Riemannian manifolds. (with or without boundaries). Let $$f_n in W^{1,2}(M,N)$$ satisfy $$Jf_n > 0$$ a.e., and suppose that $$f_n rightharpoonup f$$ in $$W^{1,2}(M,N)$$.

Let $$Jf_n dx$$ be the measure on $$M$$ associated with the function $$Jf_n$$, where by $$dx$$ I refer to the standard Riemannian volume form on $$M$$. Suppose that the sequence of measures $$Jf_n dx$$ is uniformly bounded, i.e. $$sup_{n in infty}int_{M} Jf_n dx.

Does $$Jf_n dx$$ weak star converge to $$Jf dx + V(mathcal{N})sum_{iin I} a_i delta_{x_i}$$, where $$I$$ is some finite set with $$a_i in mathbb{Z} setminus {0}$$ and $$x_i in mathcal{M}$$?

(since $$Jf_n ge 0$$ as as measures, we in fact must have $$a_i > 0$$.)

I think that it follows from known results in geometric measure theory (currents), but unfortunately I am not fluent in that language so I am not sure. Is there any reference for that claim?

If I understood correctly, the idea should be as follows:

Since $$Jf_n dx$$ is a bounded sequence of non-negative measures, it converges to some measure $$mu$$. Now, a general structure theorem for currents implies that $$mu$$ can be decomposed as a sum of a continuous part (which should then must be $$Jf dx$$ for some reason?) and a singular part of the form $$V(mathcal{N})sum_{iin I} a_i delta_{x_i}$$.

I think that I found such a structure theorem– this is “Theorem 1 (Structure Theorem)” in the book “Cartesian currents in the calculus of variations”, by Giaquinta, Mariano, Modica, Guiseppe, Soucek, Jiri (Volume II, pg 363).

This theorem assumes $$M$$ to be an Euclidean domain, and $$N$$ is the two-sphere; I am not sure whether it holds verbatim for other manifolds.

Is the reasoning above correct?

## How do I correct where my mobile hotspot on Android is serving as LAN? [closed]

**My Android phone is being used as the LAN at my home. I am not able to use my mobile data at all. **

## c++ – Implementation of xavier initialisation correct?

so I’ve been struggling with a vanishing gradient problem in my neural net for a couple of days now. I decided to implement an xavier initialisation method and the results are pretty amazing. My problem so far has been that as soon as I introduce more than 1 hidden layer, I seem to experience my vanishing gradients problem as my softmax output values dont move from a certain (small) range of numbers.
ie: does not move far away from 0.59 0.48 0.02
So i’m thinking it might be my implementation? Im using an xavier for tanh.

The Code:

``````double randdist(double x, double y)
{
return sqrt(1 / (x + y));
}
int main()
{
int IN = 4;
int HIDLAYERS = 2;
int HID = 8;
int OUT = 3;
double weightinit(5)(8)(8){};
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine generator(seed);

std::normal_distribution<double> distribution(0.0, 1.0);
for (int WD = 0; WD < HIDLAYERS +1; WD++)
{
if (WD == 0)
{
for (int WL = 0; WL < IN; WL++)
{
for (int WK = 0; WK < HID; WK++)
{
double val = distribution(generator) * randdist(IN, HID);
std::cout << "randdist val = " << val << 'n';
weightinit(0)(WL)(WK) = val;
//to chwck values are not 0.
}
}
}
else if (WD < 4 && WD != 0)
{
for (int WL = 0; WL < HID; WL++)
{
for (int WK = 0; WK < HID; WK++)
{
weightinit(WD)(WL)(WK) = distribution(generator) * randdist(HID, HID);
}
}
}
else if (WD == 4)
{
for (int WL = 0; WL < HID; WL++)
{
for (int WK = 0; WK < OUT; WK++)
{
weightinit(WD)(WL)(WK) = distribution(generator) * randdist(HID, HID);
}
}
}
}
for (int i = 0; i < IN; i++)
{
net.inneurons.push_back(Ineuron);
for (int m = 0; m < HID; m++)
{
net.inneurons.back().weights.push_back(weightinit(0)(i)(m));
}
}
//std::cout << "first loop done" << 'n';
for (int s = 0; s < HIDLAYERS; s++)
{
net.hiddenneurons.push_back(std::vector <HiddenN>());
if (s == HIDLAYERS - 1)
{
for (int i = 0; i < HID; i++)
{
net.hiddenneurons(s).push_back(Hneuron);
for (int m = 0; m < OUT; m++)
{
net.hiddenneurons(s).back().weights.push_back(weightinit(s+1)(i)(m));
}
net.hiddenneurons(s).back().bias = 0.0;
}
}
else
{
for (int i = 0; i < HID; i++)
{
net.hiddenneurons(s).push_back(Hneuron);
for (int m = 0; m < HID; m++)
{
net.hiddenneurons(s).back().weights.push_back(weightinit(s+1)(i)(m));
}
net.hiddenneurons(s).back().bias = 0.0;
}
}
}
}
``````

## list manipulation – Correct way to format numbers

I have defined the following function:

``````randvec[mag_]:= mag Normalize[Table[RandomReal[], {j, 1, 4}]]
``````

I would like to format the numbers in the list so that they are 4 d.p. Trying the following:

``````randvec[mag_] := NumberForm[mag Normalize[Table[RandomReal[], {j, 1, modes}]], 4]
``````

casts each entry as a string. What is the appropriate way to format the list without changing the type of the entries?

## c++ – Is this RAII implementation for vector correct?

I am currently trying to understand how std::vector works, so I am building a similar vector myself. Is RAII implemented correctly here ?

``````#include <initializer_list>
#include <algorithm>
#include <memory>

struct out_of_range {};

template<typename T, typename A>
struct vector_base
{
A alloc;    //allocator
T* elem;    //start of allocation
int sz;     //number of elements
int space;  //amount of allocated space
vector_base(int n)
:elem{alloc.allocate(n)}, sz{n}, space{n} {}

void construct(T def) {for (int i = 0; i < sz; i++) alloc.construct(&elem(i), def); }

~vector_base() {alloc.deallocate(elem, space); }
};

template<typename T, typename A = std::allocator<T>> //requires Element<T>()
class vector : public vector_base<T,A>
{
void reserve(int newspace);

public:

vector (int size, T def = T())
: vector_base<T,A>(size)
{
this->construct(def); // initialize each element to 0
}

//{} initialization
vector (std::initializer_list<int> lst)
:vector_base<T,A>(lst.size())
{
std::copy (lst.begin(), lst.end(), this->elem);
}

//destruction of elements is managed in vector_base

vector (const vector& arg); //copy constructor
vector& operator= (const vector& arg); //copy assignment

vector ( vector&& arg); //move constructor
vector& operator= (vector&& arg); //move assignment

//subscript operators
T& operator() (int n) { return this->elem(n); }
const T& operator() (int n) const { return this->elem(n); }

T& at(int n);
const T& at(int n) const;

int size() const { return this->sz; }
int capacity() const { return this->space; }

void resize(int newspace, T def = T()); //growth
void push_back(const T& d);
void erase();
};

//copy constructor
template<typename T,typename A>
vector<T,A>::vector (const vector& arg)
{
this->sz = arg.sz;
this->elem = new T(arg.size());
std::copy (arg.elem, arg.elem + arg.sz, this->elem);
}

//copy assignment
template<typename T,typename A>
vector<T,A>& vector<T,A>::operator= (const vector& arg)
{
if (this == &arg) return *this; //self-assignment, do nothing

if (arg.sz <= this->space) // enough space, no need for extra allocation
{
for (int i = 0; i < arg.sz; i++) this->elem(i) = arg.elem(i); //copy elements
this->sz = arg.sz;
return *this;
}

T* n = new T(arg.sz);
for (int i = 0; i < arg.sz; i++) n(i) = arg.elem(i);  //copy all the elements from a to the newly allocated array
delete() this->elem; //delete the previous value held by elem (remember that it's an ASSIGNMENT, not an INITIALIZATION)
this->space = arg.sz;
this->sz = arg.sz;
this->elem = n; //set the elem (of the current vector) to the argumen's elem
return *this; //return a self-reference
}

template<typename T, typename A>
T& vector<T,A>::at(int n)
{
if (n < 0 || n >= this->sz) throw out_of_range();
return this->elem(n);
}

template<typename T, typename A>
const T& vector<T,A>::at(int n) const
{
if (n < 0 || n >= this->sz) throw out_of_range();
return this->elem(n);
}

//move constructor
template<typename T,typename A>
vector<T,A>::vector (vector&& arg)
{
this->sz = arg.sz;
this->elem = arg.elem;
arg.sz = 0;
arg.elem = nullptr;
}

//move assignment
template<typename T,typename A>
vector<T,A>& vector<T,A>::operator= (vector&& arg)
{
delete() this->elem;
this->elem = arg.elem;
this->sz = arg.sz;
arg.elem = nullptr;
arg.sz = 0;
return *this;

}

template<typename T,typename A>
void vector<T,A>::reserve(int newspace)
{
if(newspace <= this->space) return; //never allocate less memory
T* p = this->alloc.allocate(newspace);
for(int i = 0; i < this->sz; i++) this->alloc.construct(&p(i), this->elem(i)); //copy the elements from the old array to the new one
for(int i = 0; i < this->sz; i++) this->alloc.destroy(&this->elem(i));
this->alloc.deallocate(this->elem, this->space);
this->elem = p; //point elem to the newly allocated array p
this->space = newspace;
}

template<typename T,typename A>
void vector<T,A>::resize(int newspace, T def)
//make the vector have newsize elements
//initialize each new element with a default value
//  -default T value
//  -or a value d if specified
{
reserve(newspace);
for (int i = this->sz; i < newspace; i++) this->alloc.construct(&this->elem(i),def);
this->sz = newspace;
}

template<typename T,typename A>
void vector<T,A>::push_back(const T& d)
{
if(this->space == 0) //if there's no space (default constructor)
reserve(8); //reserve space for 8 elements

else if (this->sz == this->space) //if the space is equal to the size
reserve(this->space * 2); //double the space

this->alloc.construct(&this->elem(this->sz), d); // add d at the end
++this->sz; // increase size by 1
}
``````

## How does the server get the correct MSS value in the TCP triple handshake

When the client establishes TCP connection with the server, it will report its MSS value during the third handshake. According to my understanding, the MSS value should be obtained by subtraction 40 from the MTU value of its interface. If the MTU value of the client interface is 1500, its MSS value to the server is 1460, which is OK at the client.What I find confusing is that the MSS given by the server to the client seems to dynamically sense the minimum MTU between the server and the client and then subtract 40. For example, if I change the MTU of the router interface between the client and the server to 1400, the MSS given by the server to the client would be 1360;I know that it is possible to detect changes through PMTUD after establishing a TCP connection, but this is happening during the TCP handshake 3, and the server gets the correct MSS value. How is this happening?

## debug – Correct my shortcode for displaying a category?

function diwp_create_shortcode_arts_post_type(){

``````\$atts = shortcode_atts( array(
'type' => ' ',
), \$atts );

\$args = array(
'post_type'      => 'arts',
'posts_per_page' => '10',
'post_status' => 'publish',
'tax_query'     => array( array(
'taxonomy'  => 'Types',
'field'     => 'term_id',
'terms'     =>  '10', //(What should I do here, otherwise my code is correct, here I just put category id directly but I wanna display a specific category posts)
) )
);

\$query = new WP_Query(\$args);

if(\$query->have_posts()) :

while(\$query->have_posts()) :

\$query->the_post() ;

\$result .= '<div class="art-item">';
\$result .= '<div class="art-image">' . get_the_post_thumbnail() . '</div>';
\$result .= '<div class="art-name">' . get_the_title() . '</div>';
\$result .= '<div class="art-desc">' . get_the_content() . '</div>';
\$result .= '</div>';

endwhile;

wp_reset_postdata();

endif;

return \$result;
``````

}