spring – How can I rewrite the below parser code in Java

spring – How can I rewrite the below parser code in Java – Code Review Stack Exchange

Looking for someone willing to rewrite a few articles for me. | Forum Promotion

Looking for someone willing to rewrite a few articles for me, I purchased them however the grammar and English is really bad. Hoping someone here is willing to read it, add what needs to be added, and rewrite it with better grammar.

I have 11 articles.

Will pay 500 $FP

windows – Script to find create date of old folders & rewrite create date of new folders

I’m sorry if I’m not explaining this properly but here is my problem. I just moved all of my folders/files from an OLD HDD to a NEW HDD. The files on the NEW HDD maintained their created date but the folders now have a create date of TODAY. Can someone please write me a script where it copies the create date of the OLD folders on the OLD HDD and rewrite it to the NEW folders on the NEW HDD.

As of now I have found this to write new dates one by one:

(Get-Item "Z:wwwnewfolder").LastWriteTime=("25 May 2021 00:00:00")

I have over 500 folders so I don’t want to do each and every folder.

Thanks in adavance

url rewriting – How to add custom rewrite rules and point to specific templates

How can I add a custom rewrite rule so I can catch paths like these:

/products/imports/filters
/products/imports/elements
/products/imports/parts

And point them to a template file, for examples:

sector.php

My code:

function sector_rewrite_rule() {
    add_rewrite_rule(
        '(.?.+?)/((^/)*)/((^/)*)/?$',
        'index.php?pagename=$matches(1)/$matches(2)&sector=$matches(3)',
        'top'
    );
}
add_action('init', 'sector_rewrite_rule', 10, 0);

But I get 404 when I tried with the URLs above.

I have a standard page called import created under products already:

products/
   imports/

So I want to catch any word right after this page:

/products/imports/

rewrite tag – How to build a achieve page for a custom CPT with multiple taxonomy button filter

This is an extended question from
Permalink for CPT with taxonomy


I am building a website that has a custom CPT and a few custom taxonomies.
The goal is to setup the archive page to have a front-end filter with buttons.

I have struggling with a few different questions…hoping someone can help.

Here is a screenshot of the HTML mark for the achieve page:

filter html markup screenshot

Here’s the current setup:

Custom Post Type:
English Speaking, with slug name “english-speakings”

Custom Taxonomies:
(1) Question Tasks (“english_speaking_tasks”), and its terms: “task1”, “task2”, “task3”

(2) Difficulties (“english_speaking_difficulties”) and its terms: “easy”, “advanced”, “pro”

(3) Course (“english_speaking_courses”) and its terms: “course-a”, “course-b”, “course-c”

Custom CPT: English-Speakings

register_post_type( 'english-speakings', array(
    'label' => 'English Speaking',
    'public' => true,
    'rewrite' => array(
        'slug' => 'english/speaking/%speaking_task%/%course%/',
    ),
    // Other args here.
) );

Taxonomy

// Task
register_taxonomy( 'speaking-task', array( 'english-speaking' ), array(
    'label' => 'Speaking Tasks',
    'public' => true,
    'rewrite' => array(
        'slug' => 'english/speakings',
    ),
    // Other args here.
) );


// Difficulties 
register_taxonomy( 'english_speaking_difficulties', array( 'english-speaking' ), array(
    'label' => 'Speaking Tasks',
    'public' => true,
    'rewrite' => array(
        'slug' => 'english/speaking/difficulties',
    ),
    // Other args here.
) );



// Course
register_taxonomy( 'english_speaking_courses', array( 'english-speaking' ), array(
    'label' => 'Speaking Tasks',
    'public' => true,
    'rewrite' => array(
        'slug' => 'english/speaking/courses',
    ),
    // Other args here.
) );

'slug' => 'english/speaking/%speaking_task%/???????/',

**Question: For the URL format, I need some guidance or suggestion here… **

For SEO purpose, I like to setup a Clean URL, but I do not need all the taxonomy names to show up there, and I might have more taxonomies created in the future…

Instead of https://example.com/{cpt-slug}/{task-slug}/{course-slug}/{difficulty-slug}
( https://example.com/english/task1/course-a/pro )

The ideal format is:

Example: https://example.com/english/task1/2035 or 20-35 or 20/35
( where 20 and 35 are the term id: course-a(“20”), pro(“35”))


Register the custom var with WP.

I have three taxonomy that need to be functional as filters, so I am going to register them to WP as custom vars:

function cpt_english_register_query_vars( $vars ) {
    $vars() = 'course';
    $vars() = 'task';
    $vars() = 'difficulty';
    return $vars;
}
add_filter( 'query_vars', 'cpt_english_register_query_vars' );

Build Query for the CPT Achieve page

    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; //use 'page' if the query is on a static front page
    
    
    $course =  get_query_var( 'course' ) ?: "courseA"; //set default value as "courseA"
    $task = get_query_var('task') ?: "task1"; // default value "task1" 
    $difficulty = get_query_var('difficulty') ?: "easy"; //default value "easy"
    
    $args = array( 
        'post_type' => 'english_speakings',
        'post_status'    => 'publish',
        'posts_per_page' =>  20 ,
        'paged' => $paged,
    
         'tax_query' => array(
    
           'relation' => 'AND', 
            
            array(
                'taxonomy' => 'english_speaking_tasks',
                'field'    => 'slug',
                'terms'    => $task,
            ),
    
            array(
                'taxonomy' => 'english_speaking_course',
                'field'    => 'slug',
                'terms'    => $course,
            ),
    
            array(
                'taxonomy' => 'english_speaking_difficlties',
                'field'    => 'slug',
                'terms'    => $difficulty,
            ),
    
        ),
    );

$the_query = new WP_Query( $args );

And Output the custom Query:

<?php

if ( $the_query->have_posts() ) {

    while ( $the_query->have_posts() ) {

        $the_query->the_post();
?>

Content ...

<?php
    }
    wp_reset_postdata(); //wp_reset_query();
} else {
    echo '<div class="card-body"><p>Sorry, there are no posts to display</p></div>';
}
?>

And I am lost….

The following are the parts I have trouble with:

(1) I have trouble making up my mind about the URL structure, need advise here

(2) “Adding Rewrite Tags”.. I do not understand how to use rewrite tags, regex and match1, match(2) ..these are very confusing to me

(3) For the front-end the taxonomy term buttons, I am not sure how to build the for each filter term buttons.

(4) I am not sure how to linked the custom var with the correct taxonomy term

Using Filter by an entity reference view with Rewrite Results gives “there are no entities matching” error

I’m using Drupal 9.2.
I have created entity reference views and use them as filter for entity reference fields (autocomplete widget).
When I’m using only “Content: Title” field everything works as expected. When using more fields either hidden (rewriting Title) or visible, I get “There are no entities matching (my selection)” error on save.

Does anybody have any idea why this is happening or how to debug?
Thanks

url rewriting – Rewrite custom post type URL in search

I have a website in which I have a custom post type (guest authors from CoAuthors Plus). With a plugin I managed to make post of custom type “guest author” searchable by WordPress legacy search.

Now, the authors are correctly shown in search results. Although, they are linked to a wrong page, /?post_type=guest-author&p=2148, which brings to a 404.

I’d like to be able to get the URL, interprete it, and redirect to the correct page (which is in the form of /archives/author/name-surname/.

I’m trying to get it working with a rewrite URL, but I’m not able to catch the data and formulate the rewrite.

python – How to rewrite this code from O(n**2) with n>1 to O(n)?

I would like to apologize in advance for this question because this is a very specific case, but I don’t know how else I can come to a solution.

The problem is as follows:

I have written a function that takes as input a list of 5 numbers, then the program’s goal is to return the largest drop in the list. It is important to understand that (5, 3, …) is a decrease of 2 and that (5, 20, …..) is a decrease of 0. In short, a decrease can only be from left to right and the largest decrease can for example also be the decrease from the 1st number to the 4th number, they do not necessarily have to be next to each other.

def biggest_drop(temperature):
    difference = 0
    new_temperature = temperature.copy()
    a = 0
    for i in temperature:  
        del new_temperature(0)
        for j in new_temperature:
            if i <= j:
                   False
            else:
                a = i - j
                if a > difference:
                    difference = a
    return difference

The good news is the code works, the bad news is that because of the double for loop there is already a Big-O notation of O(n2). However, the program must have a Big-O notation of O(n1) and I don’t know how to fix this and where the speed of the code is also high enough. For example, here I have made a fairly sloppy alternative, but it is too slow:

def biggest_drop(temperature):
    difference = 0
    a = 0
    b = temperature(1)
    c = temperature(2)
    d = temperature(3)
    e = temperature(4)
    for i in temperature:
        if temperature(0) <= temperature(1) <= temperature(2) <= temperature(3) <= temperature(4):
            return 0
        elif i > b:
            a = i - b
            if a > difference:
                difference = a
        elif i > c:
            a = i - c
            if a > difference:
                difference = a
        elif i > d:
            a = i - d
            if a > difference:
                difference = a
        elif i > e:
            a = i - e
            if a > difference:
                difference = a
    return difference

Do you have a better idea how my code complies with the big-O notation of O(n1) and is also fast enough for larger n, in other words lists with more than 5 integers?

htaccess – A modern global rewrite command for HTTPS websites without cname (www.) at all

To clarify what @StephenOstermiller mentioned in comments, nothing has changed in this regard for quite literally decades. Any question you find on the Stack Exchange network, regarding canonical redirects on Apache, will be just as relevant now it was “back in the day”.

There is also no single “correct” solution. Due to the variation of servers/configs, different solutions may be required. And due to the powerful/flexible nature of the directives there can be several ways of doing (exactly) the same thing.

So, if you are using a .htaccess file in the document root directory and you want to redirect from HTTP to HTTPS and from www to non-www then you could do this like the following using mod_rewrite (very similar to the non-www to www redirect you posted):

RewriteCond %{HTTPS} off (OR)
RewriteCond %{HTTP_HOST} ^www.example.com (NC)
RewriteRule (.*) https://example.com/$1 (R=301,L)

The above 301 redirects all requests where HTTPS is off or www.example.com is requested to https://example.com/, preserving the URL-path and query string.

Note that the $ at the end of the 2nd RewriteCond pattern (CondPattern) is removed to cache FQDNs that end in a dot. eg. http://www.example.com./foo.

The RewriteRule pattern (.*) captures the requested URL-path, which is referred to using the $1 backreference in the RewriteRule substitution string.

This will not redirect any other subdomains you might have.

(You need RewriteEngine On once at the top of the file.)

Work for any directory and the server config

Due to the way the URL-path is captured in the backreference, the above only works if the .htaccess file is in the document. It also only works in .htaccess files. It will result in a double-slash at the start of the URL-path if used in a server or virtualhost context.

(To be continued…)

Avoid repetition

You could save repetition of the domain name in the substitution string by capturing the required domain name from the preceding CondPattern. And write it like this instead:

RewriteCond %{HTTPS} off (OR)
RewriteCond %{HTTP_HOST} ^www.(example.com) (NC)
RewriteRule (.*) https://%1/$1 (R=301,L)

The %1 backreference contains example.com captured in the preceding CondPattern. Otherwise, this is very similar to the above rule, except that it will not canonicalise a mixed case Host header. If www.ExAmPlE.com is requested then the request will be redirected to ExAmPlE.com. Although this is rare and will potentially only affect bot traffic (browsers lowercase the hostname before making the request).

Generic “no domain” solution

To make this entirely generic, without explicitly stating the domain then you could instead write the rule like this:

RewriteCond %{HTTPS} off (OR)
RewriteCond %{HTTP_HOST} ^www. (NC)
RewriteCond %{HTTP_HOST} ^(?:www.)?(.+?).?$ (NC)
RewriteRule (.*) https://%1/$1 (R=301,L)

However, this doesn’t only redirect www.example.com to example.com. It will also redirect from any www subdomain. For example, www.foo.example.com will be redirected foo.example.com and www.another.example will be redirected to another.example. The www subdomain is simply removed in all cases. This may or may not be desirable for your config. It’s a potential caveat of having an entirely “generic” solution.

redirects – What would be a (modern?) global rewrite command for HTTPS websites without cname (www.) at all?

I host a MediaWiki website on a shared server with Apache, MySQL and PHP.

Up until today I used a CDN to deliver that website’s content — which required redirecting each webpage to a www. including version.

Today I have reached the conclusion that a CDN is redundant for that specific website and deleted the CDN account associated with it.

This is my current global rewrite rules for HTTPS websites WITH www.:

RewriteEngine On
RewriteCond %{HTTPS} off (OR)
RewriteCond %{HTTP_HOST} !^www.seo-wiki.org$ (NC)
RewriteRule (.*) https://www.seo-wiki.org/$1 (L,R=301)

What would be a (modern?) global rewrite command for HTTPS websites without cname (www.) at all (without a CDN)?


SIdenote: I doubt that this question is a duplicate as it from nearly 7 years ago, focused on SSL certificates and some program named WHMCS ; but I seek a modern, global directive set, good for generally any website

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies 5000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive.com Proxies-free.com New Proxy Lists Every Day Proxies123.com Buy Cheap Private Proxies; Best Quality USA Private Proxies