python – Using haversine to order by distance

I’m trying to write a search by location into a website. I cant help but think that the code I’ve written is not very efficient.

If I were to have 1000’s of places it would be fairly slow.

Any improvements?

This is a psuedo version.

import haversine

class Place(db.Model):
   name = "TEST"
   lat = 52
   lng = -2.5

def get_places():
    return Place.query.all()

def sort_by_dist(current_lat,current_lng,limit=10):
    return sorted(get_places(), key=lambda x:haversine((current_lat,current_lng),(x.lat,x.lng)))(:limit)

tweening – Godot tween animation playing order

I’m making a three in line game with godot, but i’m having an issue.

First time when swapping cells, the animation of swapping and the elimination of cells (in the case of making 3 or more cell aligned in a line) played both at the same time.

So i refactored a bit the code, now i have queue for each cell that manages the animation to be played one by one.

Now my problem is this, the cells that the player swaps, they do fine, the play the swap animation then the elimination animation. the problem are the other cells in the line, those get removed as the first cells are playing the swap animation first and then elimination animation.

| *              | Step 1           | Step 2          |  
| cells in line  |  remove animation|   nothing       |
| swaped cells   |  swap animation  | remove animation|

in case i didn’t explained well i left a more graphic description of the flow of the animation steps.

this is how i want the animation to be played

| *              | Step 1           | Step 2            |  
| cells in line  |  nothing         |   remove animation|
| swaped cells   |  swap animation  | remove animation  |

I’m not sure how to solve the problem, each cell manages their animations in the queue.

warning messages – Some of the functions have zero differential order

I am trying to solve the following system of differential equations, but Mathematica (11.3) complains that

NDSolveValue::pdord Some of the functions have zero differential order

I do not understand this message since all of the functions appear with their derivatives in the equations.

Here is the code:

ClearAll("Global`*")
(Rho)0 = 1;
M = 1;
eq1 = D(m(t, r), r) - 4 Pi (Rho)(t, r) R(t, r)^2 D(R(t, r), r);
eq2 = D(m(t, r), t) + (4 Pi)/3 (Rho)(t, r) R(t, r)^2 D(R(t, r), t);
eq3 = D(R(t, r), r, t) - D(R(t, r), t) D((Nu)(t, r), r) - 
   D(R(t, r), r) D((Lambda)(t, r), t);
eq4 = D((Rho)(t, r), r) + 1/4 (Rho)(t, r) D((Nu)(t, r), r);
eq5 = Exp(-2 (Nu)(t, r)) (D(R(t, r), {t, 2}) - 
      D((Nu)(t, r), t) D(R(t, r), t)) - 
   Exp(-2 (Lambda)(t, r)) D((Nu)(t, r), r) D(R(t, r), r) + m(t, r)/
   R(t, r)^2 + (4 Pi)/3 (Rho)(t, r) R(t, r);
{Ro, Ra, Ma, nu, la} = 
 NDSolveValue({eq1 == 0, eq2 == 0, eq3 == 0, eq4 == 0, 
   eq5 == 0, (Rho)(0, r) == (Rho)0, (Rho)(t, 0) == (Rho)0, 
   m(0, r) == M, 
   m(t, 0) == 
    M, (Nu)(0, r) == -(1/4) Log((Rho)0), (Nu)(t, 
     0) == -(1/4) Log((Rho)0), (Lambda)(0, r) == 
    0, (Lambda)(t, 0) == 0, R(0, r) == ((3 M)/(4 Pi (Rho)0))^(1/3), 
   R(t, 0) == ((3 M)/(4 Pi (Rho)0))^(1/3), 
   Derivative(1, 0)(R)(0, r) == 1}, {(Rho), R, 
   m, (Nu), (Lambda)}, {t, 0, 1}, {r, 0, 1})

Note: another message appears saying that the initial and boundary conditions are inconsistent, but that is another problem I have to solve later, I am more concerned with the other message at the moment.

xposed framework – How to determine the boot order of auto-starting apps?

Some apps boot and run in the background when an Android phone boots. WeChat is one example. It starts automatically so that the user can receive messages in real time. My question is how to view and change the boot order of all auto-starting apps. Or else is it random?

The motivation for asking is that I installed Xposed and wanted to change some information of my phone. But unfortunately WeChat sometimes boots before Xposed and thus bypasses the Xposed hooks. I tried very hard to solve this, but to no avail. So any suggestions?

google apps script – How to combine multiple ranges with getRange in order to clear the contents of specific cells?

https://docs.google.com/spreadsheets/d/1VsEvt2KnYGnlN_qHjkjPohVHF5MUqfyHD7tSk0VpkqA/edit#gid=1418057437

I use this sheet to enter data of patients in (Data_Entry) tab. Specific rows are titles and should not be cleared whenever I clear contents of all cells in the sheet/tab. Like Rows 1-4 and rows 20-21. So I made this script to clear specific cells but it seems very basic and it has a problem whenever somebody inserts a new row in between, the whole range needs to be adjusted.

The script has three functions: adding_menu, making borders of query results in (All_patients)tab and ClearContents of (Data_Entry) tab.

So my question is about the last function (ClearContent)

 function onOpen() {

    var menuItems = (
    {name: 'ClearContents', functionName: 'ClearContents'},
    {name: 'Borders', functionName: 'borders'}
  );
  SpreadsheetApp.getActiveSpreadsheet().addMenu('Weekened_Functions', menuItems);
 
 
}

function borders() {
  var range = SpreadsheetApp.getActive().getSheetByName('All_Patients').getDataRange();
  var cell = SpreadsheetApp.getActive().getSheetByName('All_Patients').getRange("B50:H200")
  cell.setBorder(false, false, false, false, false, false);
  var values = range.getValues();
  for (var i = 2; i < values.length; i++) {
    for (var j = 1; j < values(i).length; j++) {
      
        range.getCell(i + 1, j + 1).setBorder(true, true, true, true, true, true);
      }
    }
 
  }
 
function ClearContents() {
  var sheet = SpreadsheetApp.getActive().getSheetByName('Data_Entry');
  sheet.getRange('B5:F19').clearContent(),
  sheet.getRange('B22:F34').clearContent();
  sheet.getRange('B37:F49').clearContent();
  sheet.getRange('B52:F64').clearContent();
  sheet.getRange('B67:F83').clearContent();
  sheet.getRange('B86:F102').clearContent();
  sheet.getRange('B105:F119').clearContent();
  sheet.getRange('B122:F133').clearContent();
  sheet.getRange('B136:F146').clearContent();
  sheet.getRange('B149:F160').clearContent();
  sheet.getRange('B163:F174').clearContent();
  sheet.getRange('B177:F188').clearContent();
  sheet.getRange('B191:F202').clearContent();
  sheet.getRange('B205:F216').clearContent();
  sheet.getRange('B219:F230').clearContent();
  sheet.getRange('B247:F257').clearContent();
  sheet.getRange('B260:F269').clearContent();

  sheet.getRange('M5:M19').clearContent(),
  sheet.getRange('M22:M34').clearContent();
  sheet.getRange('M37:M49').clearContent();
  sheet.getRange('M52:M64').clearContent();
  sheet.getRange('M67:M83').clearContent();
  sheet.getRange('M86:M102').clearContent();
  sheet.getRange('M105:M119').clearContent();
  sheet.getRange('M122:M133').clearContent();
  sheet.getRange('M136:M146').clearContent();
  sheet.getRange('M149:M160').clearContent();
  sheet.getRange('M163:M174').clearContent();
  sheet.getRange('M177:M188').clearContent();
  sheet.getRange('M191:M202').clearContent();
  sheet.getRange('M205:M216').clearContent();
  sheet.getRange('M219:M230').clearContent();
  sheet.getRange('M247:M257').clearContent();
  sheet.getRange('M260:M269').clearContent();

  sheet.getRange('H5:H19').clearContent(),
  sheet.getRange('H22:H34').clearContent();
  sheet.getRange('H37:H49').clearContent();
  sheet.getRange('H52:H64').clearContent();
  sheet.getRange('H67:H83').clearContent();
  sheet.getRange('H86:H102').clearContent();
  sheet.getRange('H105:H119').clearContent();
  sheet.getRange('H122:H133').clearContent();
  sheet.getRange('H136:H146').clearContent();
  sheet.getRange('H149:H160').clearContent();
  sheet.getRange('H163:H174').clearContent();
  sheet.getRange('H177:H188').clearContent();
  sheet.getRange('H191:H202').clearContent();
  sheet.getRange('H205:H216').clearContent();
  sheet.getRange('H219:H230').clearContent();
  sheet.getRange('H247:H257').clearContent();
  sheet.getRange('H260:H269').clearContent();
};

1 how to combine these ranges in simple formula?

2 Is there a way to add exception like: (clear contents of all cells except Column M and Column A and cells containing text “Ward” or “room”or problem list” or “recommendations”?

plugin development – Woocommerce add custom metabox to order with query variable

I’m little frustrated with a problem.

Externally i load to my website a custom query variable on the URL.
Example: https://mywebsite.com/mypage/?source=webview?origin=Android

Varibles: source=webview and origin=Android or origin=IOS

This variables let me know if the web is loaded from my webview app and what OS has the device (IOS or Android).

I try a lots of ways to get this work.
One of this ways is trying to use $_GET like this example:

 add_action('woocommerce_checkout_create_order', 'before_checkout_create_order3', 20, 2);
    function before_checkout_create_order3( $order, $data ) {
        $origen3 = $_GET('device');
        $order->update_meta_data( '_origen3', $origen3 );

}

But i can’t save with php the Device and always have an empty value on my var.

Y also try with get_query_var and here i have two problems.
When i try to save the variable with get_query_var like this:

$device = get_query_var( 'Device' );

I have an empty variable.

If i declare the query_var i have a redirection error.
This is my example:

        function test_query_vars( $qvars ) {
    $qvars() = 'device';
    return $qvars;
}
add_filter( 'query_vars', 'test_query_vars' );

Here i think is something missing because i get the device saved but when i try to go to the home the page redirect to another page. I try re-save the permalinks and the .htaccess file but nothing works.

tnks on advice.

Mandatory Fields Error on Manual order pay page – woocommerce

I’m facing issues with required mandatory fields on the manually generated orders page (payment link through email).

WooCommerce scenario: an order is created by admin. This order’s payment link is sent by email to the customer to pay.

Link like this:

https://asad.app/checkout/order-pay/3566/?pay_for_order=true&key=wc_order_PIBMN20X3Jank

The problem is that when I’m trying to proceed with the payment it says

"Sorry, there was an error: The field Address is mandatory., The field City Name is mandatory."

My question is, there are no user entry fields on this page then why it is showing mandatory fields required. FYI this is working fine on chrome browsers(desktop only) but when the same link is accessed from chrome mobile or safari the error shows up. above give link is the working link, kindly assist me here.

I’m not using any kind of plugin to manage checkout fields.
This feels strange as there are no fields on the page but it still shows the required fields error.

Display customer_note in order confirmation email

I am using this code to display customer_note in order confirmation email:

{{var order.getCustomerNote()|escape|nl2br}}

But it does not show up in the email. I also checked the value of customer_note in sales_order table to make sure it’s not null.
And i went to Order model:

vendor/magento/module-sales/Model/Order.php

And return a test string:

/**
 * Return customer_note
 *
 * @return string|null
 */
public function getCustomerNote()
{
    return "i was here!";
    return $this->getData(OrderInterface::CUSTOMER_NOTE);
}

Surprisingly i can see my test string show up in email.

Do you have any ideas why it doesnt work?
Many thanks.

php – Order custom field values by popularity

I have two custom fields: “usp-custom-ticker” and “ticker”.

I want to combine them into one list (which I already successfully did with the following code):

<?php 
   
       $args=array(
       'posts_per_page' => 35,
       'caller_get_posts'=> 35
     );

     $my_query = new WP_Query($args);
     if( $my_query->have_posts() ) {

       while ($my_query->have_posts()) : $my_query->the_post(); ?>

           
   <?php echo usp_get_meta(false, 'usp-custom-ticker'); ?> <?php echo usp_get_meta(false, 'ticker'); ?>


        <?php
       endwhile;
     }
   wp_reset_query(); 

 ?>

With the above code I have all values from two custom fields. Which includes duplicates.

Basically I want to order that list by popularity (without duplicates).

So, let’s say I have 10 posts.

5 of them have ‘January’.
3 of them have ‘December’
2 of them have ‘June’.

I want to order a list like this: January December June.

I need help. I know it can be done using array_unique (to remove duplicates) and array_count_values (to count values) but haven’t figured out yet how to do that.