uploads – How to change Route respond To A specific Path?

To increase site loading time and decrease the pressure on my website I have decided to host files(js,css,images) in other hosting, like google storage or amazon aws, problem is that I already published a lot of posts that includes images other files in the html, like:

<img src="https://wordpress.stackexchange.com/site.example/wp-content/uploads/images/image.png">

i can’t go all over the posts to change the src attribute, so I want to change my route code so every time a wp-content or wp-includes files is requested, it will redirect it to the host where my media files are, something like:

    if(str_contains(path, 'wp-content') || str_contains(path, 'wp-includes')){

python – Randomly selected integers from predetermined lists add up to specific input value

Hello im trying to write a Python code that selects integers from arrays up to a certain value.

I wrote this code however the code uses every list once (as is intended). But sometimes it is still below the input value and has no more options to choose from.

For example if i say WantedNumber is 15 and it picks 4 from listC and 5 from listA, it then has no more options for a correct answer in listB.

or sometimes it picks 1 from every list and then it has no more lists to choose from cause it used all of them already.

How can I make it select a random sequence of integers that adds up to WantedNumber

Note: ”similar questions” are always about completely random numbers adding up to input value. But I don’t want random numbers, I want randomly selected predetermined numbers from my lists.

import random

WantedNumber = input('please input your wanted number:')

listA = (1,2,3,4,5)
listB = (1,2,3)
listC = (1,2,4,7)

All = (listA,listB,listC)

x = 0

while x < int(WantedNumber):
    print(x) #this prints the new x value with the new Random2 added up
    Random1 = random.choice(All)
    Random2 = random.choice(Random1)

    print(Random1) #this prints which variable of the list it chose
    print(Random2) #this prints which integer from the array from Random1 it chose
    index = All.index(Random1)

    Y = int(x) + int(Random2)
    if Y<=int(WantedNumber):

magento2 – Hoe to hide the uiComponent meant for a specific step on other step(s) on checkout page?

I’m relatively new to magento 2 and wanted to show totals uiComponent which is in sidebar displayArea at shipping step, now I’ve managed to do that but it keeps showing on billing step as well and I was wondering if there’s any way to hide it on all other steps except for where this uiComponent is meant for. Any help would be hugely appreciated. Here’s my checkout_index_index.xml

<referenceBlock name="checkout.root">
        <argument name="jsLayout" xsi:type="array">
            <item name="components" xsi:type="array">
                <item name="checkout" xsi:type="array">
                    <item name="children" xsi:type="array">
                        <item name="steps" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="shipping-step" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="shipping-totals" xsi:type="array">
                                            <item name="component" xsi:type="string">Magento_Checkout/js/view/summary/totals</item>
                                            <item name="displayArea" xsi:type="string">totals_steps</item>
                                            <item name="config" xsi:type="array">
                                                <item name="template" xsi:type="string">Magento_Checkout/summary/totals</item>
                                            <item name="children" xsi:type="array">
                                                <!-- sort order for this totals is configured on admin panel-->
                                                <!-- Stores->Configuration->SALES->Sales->General->Checkout Totals Sort Order -->
                                                <item name="subtotal" xsi:type="array">
                                                    <item name="component" xsi:type="string">Magento_Checkout/js/view/summary/subtotal</item>
                                                    <item name="config" xsi:type="array">
                                                        <item name="title" xsi:type="string" translate="true">Cart Subtotal</item>
                                                <item name="shipping" xsi:type="array">
                                                    <item name="component" xsi:type="string">Magento_Checkout/js/view/summary/shipping</item>
                                                    <item name="config" xsi:type="array">
                                                        <item name="title" xsi:type="string" translate="true">Shipping</item>
                                                        <item name="notCalculatedMessage" xsi:type="string" translate="true">Not yet calculated</item>
                                                <item name="grand-total" xsi:type="array">
                                                    <item name="component" xsi:type="string">Magento_Checkout/js/view/summary/grand-total</item>
                                                    <item name="config" xsi:type="array">
                                                        <item name="title" xsi:type="string" translate="true">Order Total</item>

user interface – How to go to a specific year/month on the new Facebook UI

The new Facebook UI looks comfortable, however, there’s a feature missing.

Previously, when visiting a profile, visitor may select year and month on the top bar.

Such feature isn’t seen in the new Facebook UI, how to navigate to a specific year/month on a Facebook profile?

randomness – Sampling from specific random distribution on sets

I have a random distribution on sets in mind, that has three parameters: $n, w, k$. The goal is to sample sets of $k$ integers from $(0, n)$ (without replacement) such that the elements within each set fit in a subrange of length $w$. That is, an outcome set $S$ must have properties:

  1. $S subset mathbb{N_0} ; wedge; |S| = k$
  2. $0leq min(S) leq max(S) < n$
  3. $max(S) – min(S) < w$

You can assume that $k leq w/2 < w ll n$.

Now there are many possible distributions possible over these sets. But I’m interested in those that have as property

$$forall x:P(x in S) = frac{k}{n};,$$

that is each integer in $(0, n)$ has an equal chance of being in a set when sampled (or as close as possible). Beyond the above requirements, it’d be ideal if the distribution is an maximum entropy one, but this isn’t as important, and something close would be fine too. As a minimum bar I do think every valid set should have a non-zero chance of occurring.

Is there a practical way of sampling from a random distribution that matches the above requirements?

I’ve tried various methods, rejection sampling, first picking the smallest/largest elements, but so far everything has been really biased. The only method that works that I can think of is explicitly listing all valid sets $S_i$, assigning a probability variable $p_i$ to each, and solving the linear system $$sum_i p_i = 1 quadbigwedgequad forall_x:frac{k}{n} – delta leq sum_{x in S_i} p_i leq frac{k}{n} + delta,$$ minimizing $delta$ first, $epsilon $ second where $epsilon = max_i p_i – min_i p_i$. However this is very much a ‘brute force’ approach, and is not feasible for larger $n, k, w$.

mysql – Finding films where 2 specific actors appeared together. (sakila db)

In the first case you get a combination of all pairs of actors for each film. Try this query:

select f.film_id, fa1.actor_id, fa2.actor_id, concat(a1.first_name," ", a1.last_name), concat(a2.first_name," ", a2.last_name)
from film f
    inner join film_actor fa1
    on f.film_id=fa1.film_id
    inner join actor a1
    on fa1.actor_id=a1.actor_id
    inner join film_actor fa2
    on f.film_id=fa2.film_id
    inner join actor a2
    on fa2.actor_id=a2.actor_id   
where f.film_id = 82;

enter image description here

In the second case you just join the same actor details twice:

select f.film_id, fa1.actor_id, concat(a1.first_name," ", a1.last_name), concat(a2.first_name," ", a2.last_name)
from film f

    inner join film_actor fa1
    on f.film_id=fa1.film_id
    inner join actor a1
    on fa1.actor_id=a1.actor_id
    inner join actor a2
    on fa1.actor_id=a2.actor_id
where f.film_id = 82;    

enter image description here
So there are no rows which correspond to your where conditions (a1.first_name=”CATE” and a2.first_name=”cuba”)

Additional explanation:
SELECT * FROM film – you get the list of films (one row per film)
SELECT * FROM film f JOIN film_actor fa1 ON f.film_id = fa1.film_id – you get the list of actors for the film (multiple lines for each film and each line contains one actor id)
SELECT * FROM film f JOIN film_actor fa1 ON f.film_id = fa1.film_id JOIN actor a1 ON fa1.actor_id=a1.actor_id – you get the same rows as above but with additional details for each actor (each line is still related to only one actor, there is no pairs of actors)
SELECT * FROM film f JOIN film_actor fa1 ON f.film_id = fa1.film_id JOIN actor a1 ON fa1.actor_id=a1.actor_id JOIN actor a2 ON fa1.actor_id=a2.actor_id – the same results as above, you just joined the same details for the same actor twice

FROM film f 
JOIN film_actor fa1 ON f.film_id = fa1.film_id
JOIN film_actor fa2 ON f.film_id = fa2.film_id

After the first join you get the list of actors for the film. And on the second join you add the same list of actors to each line from the above result and get the list of all pairs of actors for each film (as you can see on screenshot above)

sql server – How to delete specific range of data from Service Broker > System Queues data table?

Due to sudden increase of my database .mdf file we found there are 4 internal queue message table are increase unexpectedly. so we decided to delete some range of data from these table.

we try this code:

declare @c uniqueidentifier
    select top 1 @c = conversation_handle from dbo.queuename
    if (@@ROWCOUNT = 0)
    end conversation @c with cleanup

but its try to delete all data and due to space limitation this query cannot execute.
my internal message queue table :

enter image description here

enter image description here

google sheets – Duplicate row values to next row, based off specific column

I’m trying to set up a button that will copy information from the last row and paste it into the row right underneath (based on where column D last has a value). Almost like a “duplicate” button, because I am inputting information that will repeat.

I had a script that was doing the copy perfectly. However, I realized an issue — because I have a unique ID pre-loaded to fill up all rows in the first column (causing the added row to come after this), I wanted this script to seek the last row based on the FOURTH column, not the FIRST.

On a similar pattern, I am looking to ONLY copy the information from column 4, 5, 6, and 7, into the row underneath — not any other info.

My idea was that I could basically combine these two concepts — copying and pasting the last row into the row underneath, and using GetColumnHeight so that I can control which columns should be selected.

function addRow() {
  var sh = ss.getActiveSheet(), lRow = sh.getLastRow();
  var lCol = sh.getLastColumn(), range = sh.getRange(lRow,1,4,lCol);
  sh.insertRowsAfter(lRow, 1);
  range.copyTo(sh.getRange(lRow+1, 1, 1, lCol), {contentsOnly:false});

  var vs=sh.getRange(e.range.rowStart,4,1,3).getValues()
function getColumnHeight(col,sh,ss){
  var ss=ss||SpreadsheetApp.getActive();
  var sh=sh||ss.getActiveSheet();
  var col=col||sh.getActiveCell().getColumn();
  var v=sh.getRange(1,col,sh.getLastRow(),1).getValues().map(function(r){return r(0);});
  var s=0;
  var h=0;
  return (h-s);

I’m really all over the place right now, and struggling to piece something together that will copy and paste the values in column 4,5,6, and 7 into the row below, ignoring the filled values in column A. Any suggestions?

Here is a visual to further explain my goal:


Excel – Number of occurrences of specific day and month between two dates?

I have a start and end date and I am looking for a solution that indicates how often March 30 is contained between the start and end date.

So for 1 Oct 2020 -> 10 Mar 2021 = 0
So for 1 Oct 2020 -> 1 Apr 2022 = 2

I am looking for a self-contained function not mapping out all the dates in multiple cells and then checking whether any date’s month is 3 and day is 30. I tried to play with sequence() but did not get far.

Any slick ideas?

SharePoint REST API – odata $expand is not working on a specific site

I am using SharePoint API to get list items. One of the fields is User Picker.
The query looks like this:


I have two sites (same tenant), with exactly the same list. When I execute this query on SITE1, it succeeds and returns the results (list of items, with AssignedTo expanded). But when I run this query on the second site, it fails with the following message:

Cannot get value for projected field AssignedTo_x005f_UserName.

What could be the reason?

Please note that this applies not only to this list, but to all lists on the site. $expand on User lookup simply does not want to work there for some reason.