I want to have a short code to show the last 2 posts posted by the user connected in a sidebar widget or anywhere

I have read several responses about displaying posts created by the currently logged in user. However, I still can't create a short code that I can use in a widget or page to display the last 2 posts created by the current user, for example, this one.

 get_current_user_id(),
));

while ( $query->have_posts() ) {
    $query->the_post();
    the_title();
}
    wp_reset_postdata();
?>

server – Apache2 does not work and my browser's PHP code

when i reboot the server apache this message

The job for apache2.service failed because the control process came out with the error code.
See "systemctl status apache2.service" and "journalctl -xe" for more details.

after that I check the state of the apache service that these errors show

● apache2.service: the Apache HTTP server
Loaded: Loaded (/lib/systemd/system/apache2.service; activated; preset provider:
Entry: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: failed (Result: exit code) since Monday 2020-02-17 00:44:29 IST; 7min ag
Process: 24336 ExecStop = / usr / sbin / apachectl stop (code = exited, state = 1 / FAIL
Process: 24865 ExecStart = / usr / sbin / apachectl start (code = exited, status = 1 / FAIL
Main PID: 22462 (code = exited, status = 0 / SUCCESS)

February 17 00:44:29 technicalms systemd (1): Start Apache HTTP server …
February 17th 00:44:29 technicalms apachectl (24865): apache2: syntax error on line 228
February 17th 00:44:29 technicalms apachectl (24865): The action & # 39; start & # 39; failure.
February 17 00:44:29 technicalms apachectl (24865): the Apache error log may have more
February 17th 00:44:29 technicalms systemd (1): apache2.service: control process finished,
February 17th 00:44:29 technicalms systemd (1): apache2.service: error with the result & # 39; exi
February 17 00:44:29 technicalms systemd (1): The Apache HTTP server could not be started.

and my browser shows php code as that code does not run

please tell me how can I solve it

Rejected in the code challenge due to lack of separation of concerns, but I feel that YAGNI [Kotlin / Java]

He was recently rejected in a code challenge that was a very simple web service with 3 endpoints:

  • POST /transactions to add transactions with a quantity and time stamp.
  • GET /statistics to check the statistics of last minute transactions.
  • DELETE /transactions.

I just pasted under the service object because the API controller is irrelevant:

data class Transaction(val amount: BigDecimal, val timestamp: Instant)

data class Statistics(val sum: String, val min: String, val max: String, val avg: String, val count: Int)

class TransactionInFutureException(message: String) : Exception(message)
class TransactionBeforeThreshold(message: String) : Exception(message)

const val THRESHOLD_SEC = 60L
const val CLEANER_INTERVAL_MS = 5000L
const val AMOUNT_SCALE = 2

class TransactionsService {
    protected val transactions = ArrayList()

    init {
        thread(start = true) {
            Thread.sleep(CLEANER_INTERVAL_MS)
            synchronized(transactions) {
                val threshold = getCurrentThreshold()
                transactions.removeAll { it.timestamp < threshold }
            }
        }
    }

    fun add(amount: BigDecimal, timestamp: Instant) {
        if (timestamp > Instant.now())
          throw TransactionInFutureException("transaction timestamp cannot be in future")
        else if (timestamp < getCurrentThreshold())
          throw TransactionBeforeThreshold("transaction timestamp cannot be before threshold")

        synchronized(transactions) {
            transactions.add(Transaction(amount, timestamp))
        }
    }

    fun clear() {
        synchronized(transactions) {
            transactions.clear()
        }
    }

    fun statistics(): Statistics {
        synchronized(transactions) {
            val threshold = getCurrentThreshold()
            val liveTransactions = transactions.filter { it.timestamp > threshold }
            val count = liveTransactions.count()
            var sum = BigDecimal(0)
            var max = if (count > 0) liveTransactions.first().amount else BigDecimal(0)
            var min = if (count > 0) liveTransactions.first().amount else BigDecimal(0)
            liveTransactions.forEach {
              sum += it.amount
              max = max.max(it.amount)
              min = min.min(it.amount)
            }
            var avg = BigDecimal(0)
            if (count > 0)
              avg = sum.setScale(AMOUNT_SCALE, BigDecimal.ROUND_HALF_UP).
                        divide(BigDecimal(count), BigDecimal.ROUND_HALF_UP)
            return Statistics(format(sum), format(min), format(max), format(avg), count)
        }
    }

    protected fun getCurrentThreshold() = Instant.now().minusSeconds(THRESHOLD_SEC)

    protected fun format(value: BigDecimal) = value.setScale(AMOUNT_SCALE, BigDecimal.ROUND_HALF_UP).toString()
}

The two main points because they rejected me were:

There was no separation of concerns; Most of the logic is in just one
class.

We felt that there was an excessive use of synchronized blocks, which could be replaced with a synchronized or concurrent collection

It seems they expected me to divide the functionality of TransactionService in a kind of StatisticsCalculator class that will do what the statistics() The method does.

To be honest, by the given requirements, I felt that this is an excessive engineering from here to Mars and I will apply the Yagni beginning:

  • TransactionsService As it stands, it is a 50L code class. It fits on a screen and is easy to follow. There is no cognitive overload when reading it.

  • Is there anything to gain by dividing the class in two at this time? I can barely say it, but I'm sure you'll have to add more complexity to the public API of TransactionService to allow iterating over stored transactions of StastisticsCalculator.

  • As programmers, we make compensation all the time, between complexity, maintainability, construction time, etc. I will declare that following the principle of sole responsibility is pressing too much SOLID over and I will simply adhere to YAGNI Y KISS.

  • When complexity arises in the future, refactoring and dividing will be my first choice.

What you think?

I will create a colorful / black and white professional QR CODE for you. for $ 4

I will create a colorful / black and white professional QR CODE for you.

The QR code is the registered trademark of a type of matrix barcode (or two-dimensional barcode) first designed in 1994 for the automotive industry in Japan. A barcode is a machine-readable optical label that contains information about the item to which it is attached. The QR code is modern technology so that companies and companies stand out among their competitors.

They are used to take information from a transitional medium and put it on your cell phone. You may soon see the QR codes in a magazine ad, on a billboard, a web page or even on someone's shirt.
I will generate a QR code for your website, email, phone number, Facebook, twitter, location, you tube, event, bitcoin, etc.

I can also include your company logo or we can even add your company color in this barcode.
100% satisfaction guaranteeORDER NOW

. (tagsToTranslate) qrcode (t) barcode (t) qr (t) code (t) bar

coding style: organization of the C ++ source code for reusable components

I am implementing a custom container with template as part of a learning project in C ++. The container makes use of different components such as serialization, memory management, iterators. I wonder what is the best way to organize the code.

Option 1: put everything in a header file:

I have seen this in several examples online. But by doing this, I will end up with a file several thousand lines long:

// container.hpp
template 
class Container {

public:
    // params is a struct with typedefs and static variables 
    // used to configure the container at compile time

    // I define additional typedefs and static variables here from params::

public:
    class iterator {

        // can use the typedefs and variables above
    };

    class memory {

        // can use the typedefs and variables above
    };
};

Option 2: split the code into multiple headers

Each file contains the implementation of 1 component.

// memory.hpp
template 
class memory {

public:
    // typedefs and static variables from Container::

};

// iterator.hpp
template 
class iterator {

public:
    // typedefs and static variables from Container::

};

// container.hpp
#include "iterator.hpp"
#include "memory.hpp"

template 
class Container {
public: 
    // typedefs and static variables here from params::


    typedef Container self_type;


    iterator begin();

private:
    memory mem;
};

What are the arguments to choose from?

Solution 1 seems cleaner; something bothers me of having to pass the type of container to memory and the iterators in solution 2. But at the same time, the code is organized in different files in solution 2. Each file contains the implementation of 1 component.

Is it just a matter of personal preference? Or are there objective reasons to choose one solution over the other? Or is there a completely different and better approach?

apache 2.4 – Serves static content, but with a 503 response code

We are currently leading our application cluster with a reverse proxy, and each rising block has an alternate host that only serves a static maintenance page. So, if all backends fail, return this page with a 200 OK, which is not the ideal return code for several reasons.

If my life were simple, I would simply set ErrorDocument 503 /index.html and continue with my life, but the problem is that we serve this site in English and French, and therefore we have 2 different error pages. The mod_rewrite configuration is:

  RewriteCond %{REQUEST_URI} /EN (NC)
  RewriteRule ^/en$ /index-en.html (NC,L)

  RewriteCond %{REQUEST_URI} /FR (NC)
  RewriteRule ^/fr$ /index-fr.html (NC,L)

  RewriteCond %{HTTP:Accept-Language} ^fr (NC)
  RewriteRule .* /index-fr.html (NC,L)

  RewriteCond %{HTTP:Accept-Language} ^en (NC)
  RewriteRule .* /index-en.html (NC,L)

  RewriteRule (.*) /index-en.html (L)

My next opportunity was to add R=503 to RewriteRules, but this causes Apache to return the default 503 ErrorDocument, and not our custom content.

To further complicate this is the fact that the "static" content on these pages is periodically regenerated from our CMS and cached to keep it updated, so I cannot simply leave a fast and dirty PHP script in front. this either.

Is there any way to achieve this purely through the Apache configuration?

excel – What would be the equivalent SQL code for a situation / code below?

I have the following hypothetical situation in EXCEL, I need to RECREATE the same situation in QUERY SQL, how could I do that?

insert image description here

performance: simplify the code of this list program

Hello, with this program, I am asking for a number and I have to create so many nodes and print each digit its value. If I write 123, the output should be 1 -> 2 -> 2 -> 3 -> 3 -> 3 if the number given in the input is negative, the list should be created by adding the nodes in the head.

#include 
#include 

typedef struct Node{
    int val;
    struct Node *next;
} node;

int main(){

    char num_str(64) = {0};
    int num, cifra, *p, counter=1;

    printf("Write a number: n");
    scanf("%d", &num);

    int len = snprintf(num_str, 64, "%d", num);
    printf("The length is %dn", len);

    p = (int *)malloc(len*sizeof(int));

    for(int i = 0; i < len; i++) {
        cifra = (int)(num_str(i))-(int)('0');
        p(i) = cifra;
    }

    node *head = NULL;
    head = (node *)malloc(sizeof(node));
    node *temp = head;

    if(num_str(0)!='-'){
        for(int i=0; i < len; i++){
            for(int j=p(i); j > 0; j--){
                temp->val = p(i);
                temp->next = (node *)malloc(sizeof(node));
                temp = temp->next;
                temp->next = NULL;
                counter++;
            }
        }
    }

    else{
        for(int i=0; i < len; i++){
            for(int j=p(i); j > 0; j--){
                temp = (node *)malloc(sizeof(node));
                temp->val = p(i);
                temp->next = head;
                head = temp;
                counter++;
            }
        }
    }

    temp = head;

    while(temp->next != NULL){
        printf("%d -> ", temp->val);
        temp = temp->next;
    }

    printf("n");

    printf("I have created %d nodesn", counter);

    return 0;
}
```

8 – Can we write javascript code in the twig template?

Yes, you can write JS code in a twig template. I can't think of any syntax crossover, so you should literally be able to write it as is.

In fact, this works fine in html.twig.html:


If you have syntax problems, you can always escape with raw, but it should be unnecessary:

{% raw%}

{% endraw%}

hide item from source code

I'm telling you that all the div they have display none I removed them from the body, which I can't see if I click on inspect element but if I give in View source of the page they appear to me …

How do I hide them altogether?

var body = document.getElementById("body-display");
var div = document.querySelectorAll("#body-display > div");

function remover() {

for (var i = 0; i < div.length; i++) {

if (div(i).style.display == "none") {
body.removeChild(div(i));
} 

}

}
remover(); 
div{
color: #fff;
margin: 5px 0;
padding: 10px;
background-color: green;
}







¡Caja 1 activa!