replacement – Write repeated expressions within a rule more simply

Is it possible to shorten the length of a (delayed) rule (i.e. lhs :> rhs) when there are expressions which repeat several times? Those expressions involve values of the patterns matched in lhs, so ideas that come to my mind, such as creating a pure function that takes the repeated elements as arguments, do not work.

A simple example of what I refer to can be:

Replace( list , a_ :> {RealDigits(a),Length@RealDigits(a),RealDigits(a)((1))} )

Is there a way to write in such case RealDigits(a) only once instead of three in there?

c – A dynamic string array that can be repeated without counting

Here's a dynamic, repeatable string array that doesn't require caller-level counting.

definition

char **getList(const Mediator *self) {
    char **items = (char *()) {"John", "Jane", NULL}; // dynamic/variable hard coded list

    int size = 0; 
    for (char **ptr = items; *ptr; ptr++) { // count items
        size++;
    }

    char **data = malloc(sizeof(char *) * size + 1);
    if (data == NULL) goto err;

    for (int i = 0; *items; items++, i++) { // copy
        data(i) = malloc(sizeof(char) * (strlen(*items) + 1));
        if (data(i) == NULL) goto err;
        strcpy(data(i), *items);
    }

    data(size) = NULL; // last item
    return data;

    err:
    fprintf(stderr, "Allocation failed.n");
    return NULL;
}

caller

char **data = getList();
for (char **ptr = data; *ptr; ptr++) {
    puts(*ptr);
}
free(data);

Please check whether this code can be improved for redundancies or optimizations.

Repeated and difficult to maintain angle code

Multiple forms use material auto-completion, resulting in code that is repetitive and difficult to maintain.

The controller remains with pairs of repeated methods (for each controller).

displayFn(option?: Interface): string | undefined {
  return option ? option.Property : undefined;
}

filterAutocomplete(ev: string) {
  if (ev !== '' && ev !== null) {
    // ...
  }
}

The view is based on the use of mat-autocomplete, each with a different template variable, to save errors.


  Centro
    
    
    
      {{ option.Property }}
    
  

In summary, it's an example that would serve me for any context of this type:

  1. List item
  2. Project with multiple forms.
  3. Frequent use of autocompletes in forms
  4. Optional use of external libraries.

iis – Sharepoint 2016 events 6398 and 6306 Repeated application pool stopped

SharePoint 2016 Farm 2 Nodes frontend and application
Windows 2019 data center server

I have a problem with my SharePoint Services. I get a lot of events. Error 8306 No one can log in to the websites

I checked the .NET and it's set to FULL
https://docs.microsoft.com/en-us/sharepoint/troubleshoot/security/event-id-8306-and-cannot-activate-security-token-service-application according to this article I found.

The SecurityTokenServiceApplicationPool continues to stop. I restart it and it stops immediately. Here are the events

Protocol name: application
Source: Microsoft SharePoint Products SharePoint Foundation
Date: 05.05.2020 11:20:48 a.m.
Event ID: 6398
Task category: timer
Level: critical
Keywords:
User: network spfarm
Computer: SERV027-N1..network.com
Description:
The Execute method of the Microsoft.SharePoint.Administration.SPUsageImportJobDefinition job definition (ID 5855313d-025b-4407-96e2-7e9b2edba8d2) raised an exception. See below for more information.

Access to the path "C: Program Files Common Files Microsoft Shared Web Server Extensions 16 LOGS" is denied. (Correlation = 9b794f9f-8839-e0f1-3ea7-bb55bf6ffaf9)
Event XML:

6398
16
1
12th
0
0x2000000000000000

78039

application
SERV027-N1.network.com

Microsoft.SharePoint.Administration.SPUsageImportJobDefinition
5855313d-025b-4407-96e2-7e9b2edba8d2
Access to the path "C: Program Files Common Files Microsoft Shared Web Server Extensions 16 LOGS" is denied. (Correlation = 9b794f9f-8839-e0f1-3ea7-bb55bf6ffaf9)

Protocol name: application
Source: Microsoft SharePoint Products SharePoint Foundation
Date: 05.05.2020 11:20:13 a.m.
Event ID: 8306
Task category: claims authentication
Level: error
Keywords:
User: network spfarm
Computer: SERV027-N1.network.com
Description:
An exception occurred when trying to issue a security token: The HTTP service at http: // localhost: 32843 / SecurityTokenServiceApplication / securitytoken.svc / actas is not available. This may be because the service is too busy or no endpoint was found to monitor the specified address. Please make sure the address is correct and try accessing the service again later.
Event XML:

8306
16
2nd
47
0
0x2000000000000000

78038

application
SERV027-N1.network.com

The HTTP service at http: // localhost: 32843 / SecurityTokenServiceApplication / securitytoken.svc / actas is not available. This may be because the service is too busy or no endpoint was found to monitor the specified address. Make sure the address is correct, and try accessing the service again later.

Any ideas or suggestions

Python – Find all the values ​​in a list that are repeated most often

It would be easier and better performing to iterate over it Counter.most_common() instead of using .pop(0) lots.

From here you just want to use it next until the value is no longer the same. Which is effective in what you do with .pop.

from collections import Counter

input_lst = (1, 2, 3, 3, 4, 4, 0, 1)

counts = Counter(input_lst)
items = iter(counts.most_common())
value, amount = next(items)
values = (value)
while True:
    value, a = next(items)
    if amount != a:
        break
    values.append(value)

print(values)

This effectively groups consecutive values ​​so you can use them instead itertools.groupby instead of rolling your own.

from collections import Counter
from itertools import groupby

input_lst = (1, 2, 3, 3, 4, 4, 0, 1)

_, values = next(groupby(Counter(input_lst).most_common(), lambda i: i(1)))
values = (value for value, _ in values)
print(values)

C ++, reducing the number of repeated codes in a Rock Paper Scissors game

I feel like my code is way too much for what it is. This is my first project. I would like to learn some tips to make code more efficient for the future. Any other tips for my code here would be greatly appreciated.

#include 
#include 
#include 
#include 
using namespace std;

int main()
{
    srand(time(0));
    // yn = yes / no
    string yn;
    cout << "Do you want to play Rock, Paper, Scissors? (Enter: y or n) ";
    cin >> yn;
    if (yn == "y")
    {
        // rps = rock paper scissors
        string rps;
        cout << "Choose, Rock, Paper, or Scissorsn";
        cin >> rps;
        if (rps == "Rock")
        {
            // This outputs one of three choices and tells you if you've won, lost, or drew.          
            // rpslist is just the array list
            // rpsnumber is just a random number to pick from the array 
            rock:
            string rpslist(3) = { "Rock", "Paper", "Scissors " };
            int rpsnumber = rand() % 3;
            cout << "I choose: " << rpslist(rpsnumber);            
            if (rpslist(rpsnumber) == "Rock")
            {
                // One of three options here, win / lost / drew and a loop if you want to play again
                // yna = yes or no, a is because the "Rock" option comes first, and b, c follows after
                string yna;
                cout << ", we draw! Do you want to play again? (Enter: y or n) ";
                cin >> yna;
                if (yna == "y") goto rock;
                else (yna == "n"); goto exit;

            }
            else if (rpslist(rpsnumber) == "Paper")
            {
                string yna;
                cout << ", you lose! Do you want to play again? (Enter: y or n) ";
                cin >> yna;
                if (yna == "y") goto rock;
                else (yna == "n"); goto exit;

            }
            else if (rpslist(rpsnumber) == "Scissors");
            {
                string yna;
                cout << ", you win! Do you want to play again? (Enter: y or n) ";
                cin >> yna;
                if (yna == "y") goto rock;
                else (yna == "n"); goto exit;

            }
        }
        else if (rps == "Paper")
        {   
            paper:
            string rpslist() = { "Rock", "Paper", "Scissors" };
            int rpsnumber = rand() % 3;
            cout << rpslist(rpsnumber);

            if (rpslist(rpsnumber) == "Rock")
            {
                string ynb;
                cout << ", you win! Do you want to play again? (Enter: y or n) ";
                cin >> ynb;
                if (ynb == "y") goto paper;
                else (ynb == "n"); goto exit;

            }
            else if (rpslist(rpsnumber) == "Paper")
            {
                string ynb;
                cout << ", we draw! Do you want to play again? (Enter: y or n) ";
                cin >> ynb;
                if (ynb == "y") goto paper;
                else (ynb == "n"); goto exit;


            }
            else if (rpslist(rpsnumber) == "Scissors");
            {
                string ynb;
                cout << ", you lose! Do you want to play again? (Enter: y or n) ";
                cin >> ynb;
                if (ynb == "y") goto paper;
                else (ynb == "n"); goto exit;

            }
        }
        else if (rps == "Scissors")
        {
            scissors:
            srand(time(0));
            string rpslist() = { "Rock", "Paper", "Scissors" };
            int rpsnumber = rand() % 3;
            cout << rpslist(rpsnumber);
            if (rpslist(rpsnumber) == "Rock")
            {
                string ync;
                cout << ", you lose! Do you want to play again? (Enter: y or n) ";
                cin >> ync;
                if (ync == "y") goto scissors;
                else (ync == "n"); goto exit;

            }
            else if (rpslist(rpsnumber) == "Paper")
            {
                string ync;
                cout << ", you win! Do you want to play again? (Enter: y or n) ";
                cin >> ync;
                if (ync == "y") goto scissors;
                else (ync == "n"); goto exit;

            }
            else if (rpslist(rpsnumber) == "Scissors");
            {
                string ync;
                cout << ", we draw! Do you want to play again? (Enter: y or n) ";
                cin >> ync;
                if (ync == "y") goto scissors;
                else (ync == "n"); goto exit;

            }
        }
    }

    else yn == "n";
    exit:
    {
        exit;
    }
}


```

Open Source – Why is the development of web and mobile apps repeated? Why don't we have mid-level abstractions, and if so, why don't people use them?

I'm a new software developer, and one thing that has always bothered me is the amount of reinvention that occurs when developing web and mobile apps. Sure, there are excellent abstractions about the smallest HTTP requirements (back-end frameworks), browser caching (front-end frameworks) and databases (models & OOP) that make life easier, and even many extensions for things that require an abstraction level include, e.g. Authentication libraries for instant login implementation, but beyond that there doesn't seem to be an abstraction / open source level.

For example, I have a client who wants me to create an Instacart clone, and there are two options: First, I can either build from scratch, design all models and views myself, and write a few thousand lines of code, which is the most friends of my engineers said they would / most people tend to do this when prototyping. But it drives me crazy that something is repeated and beaten to death like an app for the delivery of food and groceries, with the same functionality at a high level – catalog listing, purchase processing, forwarding of buyers / deliverers, dealer inventory processing, customer chat created millions of times in different applications in the past.

If I've created an ecommerce website for someone in the past, I could use Django's Oscar or Saleor, which made sense to build on the implemented product list views, billing, shopping carts, checkouts, inventory management, etc., but for most others Apps This is almost as routine (carpooling, delivery of food, social networks of different flavors). There don't seem to be any good open source solutions to build on! If they exist, they are old, poorly documented, and often have dysfunctional parts.

I would post this on Startup Stack-Exchange, but it was out of date and it is not technical enough to stack the overflow, so I thought this would be the best place. I've heard the argument "build it from scratch so you can fully understand the code yourself", but this argument is not feasible for very large projects (we use other people's code by importing libraries / using frameworks freely, this is no different). .

Do I miss something? How can other freelancers / software developers prototype / create large but otherwise routine applications in a way that is half-tailor-made for clients? Is there really no better way than spending hundreds / thousands of hours building something from scratch just because there are no open source solutions for these products? Because when I search for them by searching for "clone / platform for the delivery of food" on Google or GitHub, there are almost 0 good results, with only freelance development agencies promoting their services. As someone new to the industry, this seems to be a huge organizational / industrial mis-optimization! Please check πŸ™‚

Javascript – Check the number of times a character in an array is repeated and displayed on a map

I have to save the array elements in a card as many times as they are repeated. I found this code that works, but I can't fully understand it. Can someone explain that to me? Even if there is another way. Thank you !!

var letters = ("D", "A", "V", "I", "D");

var numLetters = letters.reduce(function(countLetter, letter){
  countLetter(letter) = (countLetter(letter) || 0) + 1;
  return countLetter;
}, {})

console.log(numLetters);

Output: {D: 2, A: 1, V: 1, I: 1}

Products are repeated in the Woocommerce category

I just created a "special" category for a product type. But the products are repeated by three. Thank you in advance.

Link: https://aventurasport.cl/product-category/parapente/


        & # 39; product & # 39 ;, & # 39; posts_per_page & # 39; => 3, & # 39; product_cat & # 39; => & # 39; parapente & # 39;);
$ loop = new WP_Query ($ args);
while ($ loop-> have_posts ()): $ loop-> the_post (); global $ product; ?>



  • <a href = "post-> ID)?> "title ="post-> post_title? $ loop-> post-> post_title: $ loop-> post-> ID); ?> "> <? php the title (& # 39;

    & # 39;, & # 39;
    aa

    & # 39;); Echo & # 39;& # 39 ;. $ product-> get_price_html (). & # 39;& # 39 ;; woocommerce_show_product_sale_flash ($ post, $ product); if (has_post_thumbnail ($ loop-> post-> ID)) echo get_the_post_thumbnail ($ loop-> post-> ID, & # 39; shop_catalog & # 39;); otherwise echo & # 39;placeholder& # 39 ;; Echo & # 39;& # 39 ;. $ product-> get_price_html (). & # 39;& # 39 ;; ?>
    is_in_stock ()):?> <a href = "I would ) ); ?> "class =" button "> "http://wordpress.stackexchange.com/", & # 39; label & # 39; => "http://wordpress.stackexchange.com/", & # 39; class & # 39; => "http://wordpress.stackexchange.com/" ); switch ($ product-> product_type) { case "variable": $ link (& # 39; url & # 39;) = apply_filters (& # 39; variable_add_to_cart_url & # 39 ;, get_permalink ($ product-> id)); $ link (& # 39; label & # 39;) = apply_filters (& # 39; variable_add_to_cart_text & # 39 ;, __ (& # 39; Select options & # 39 ;, & # 39; woocommerce & # 39;)); break; Case "grouped": $ link (& # 39; url & # 39;) = apply_filters (& # 39; grouped_add_to_cart_url & # 39 ;, get_permalink ($ product-> id)); $ link (& # 39; label & # 39;) = apply_filters (& # 39; grouped_add_to_cart_text & # 39 ;, __ (& # 39; View Options & # 39 ;, & # 39; woocommerce & # 39;)); break; Case "external": $ link (& # 39; url & # 39;) = apply_filters (& # 39; external_add_to_cart_url & # 39 ;, get_permalink ($ product-> id)); $ link (& # 39; label & # 39;) = apply_filters (& # 39; external_add_to_cart_text & # 39 ;, __ (& # 39; Read More & # 39 ;, & # 39; woocommerce & # 39;)); break; Default : if ($ product-> is_purchasable ()) { $ link (& # 39; url & # 39;) = apply_filters (& # 39; add_to_cart_url & # 39 ;, esc_url ($ product-> add_to_cart_url ())); $ link (& # 39; label & # 39;) = apply_filters (& # 39; add_to_cart_text & # 39 ;, __ (& # 39; Comprar & # 39 ;, & # 39; woocommerce & # 39;)); $ link (& # 39; class & # 39;) = apply_filters (& # 39; add_to_cart_class & # 39 ;, & # 39; add_to_cart_button & # 39;); } else { $ link (& # 39; url & # 39;) = apply_filters (& # 39; not_purchasable_url & # 39 ;, get_permalink ($ product-> id)); $ link (& # 39; label & # 39;) = apply_filters (& # 39; not_purchasable_text & # 39 ;, __ (& # 39; Read More & # 39 ;, & # 39; woocommerce & # 39;)); }} break; }} // If there is a simple product. if ($ product-> product_type == & # 39; simple & # 39;) { ?> <form action = "add_to_cart_url ()); ?> "class =" cart "method =" post "enctype =" multipart / form-data "> isset ($ _ POST (& # 39; amount & # 39;))? wc_stock_amount ($ _ POST (& # 39; quantity & # 39;)): 0)); // Displays the quantity field. // Show the "Submit" button. echo sprintf (& # 39;& # 39 ;, esc_attr ($ product-> id), esc_attr ($ product-> get_sku ()), esc_attr ($ link (& # 39; class & # 39;)), esc_html ($ link (& # 39 ; label & # 39;))); ?> <? php } else { echo apply_filters (& # 39; woocommerce_loop_add_to_cart_link & # 39 ;, sprintf (& # 39;% s& # 39 ;, esc_url ($ link (& # 39; url & # 39;)), esc_attr ($ product-> id), esc_attr ($ product-> get_sku ()), esc_attr ($ link (& # 39 ; class & # 39;)), esc_attr ($ product-> product_type), esc_html ($ link (& # 39; label & # 39;))), $ product, $ link); }} ?>
  • Delete repeated posts in the result of the MySQL query

    I created a custom post type with a taxonomy and a postmeta (I used ACF for the postmeta). I am trying to retrieve the articles of my custom post, but I have a problem: my first post repeats itself several times.

    Here is my request.

    $query = "
        SELECT p.ID, p.post_title, p.post_status, p.post_type, pm.meta_key, pm.meta_value, pm.post_id, tr.object_id, tr.term_taxonomy_id, tt.term_taxonomy_id, tt.term_id, tt.taxonomy, t.term_id, t.name
        FROM $wpdb->posts p
        LEFT JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id)
        LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
        LEFT JOIN $wpdb->terms t ON (t.term_id = tt.term_id)
        INNER JOIN $wpdb->postmeta pm ON p.ID = pm.post_id
        WHERE p.post_type ='events'
        AND p.post_status='publish'
        AND pm.meta_key ='city' 
        ";
    

    Can someone please tell me where there is a problem?

    Thanks a lot