contexts – What is the correct to have package A use package B in its private section without making B visible to the user?

V 12.1 on windows.


I am loading pkg2, which in its Private section loads pkg1 in order to call one of its function.

After using pkg2, I found that pkg1 is now visible and can be called without loading it.

I thought the whole idea of loading a package from the private section of another package, is to keep it private and not to leak it to the top user level. Otherwise, why load it from private section in first place?

I am using the layout based on this answer load-a-mathematica-package-from-within-a-package

Here is MWE. First I have the two packages in same folder the main notebook for now to make it easier to test

enter image description here

Here is pkg2.m. This is the one I want to use,

BeginPackage("pkg2`");
Unprotect@@Names("pkg2`*");
ClearAll@@Names("pkg2`*");

test::usage

Begin("`Private`");
Needs("pkg1`");

test():=Module({},    
    Print("Inside test() in pkg2");
    pkg1`foo()    
)
End(); (* `Private` *)
Protect@@Names("pkg2`*");
EndPackage()

I used Needs in the above. Get also works. It seems Needs found pkg1.m since it is in same folder as pkg2.m automatically without having to give full path. Notice that the caller sets the current directory to where the packages are, and I think this is why it worked without the full path. Mathematica seems to search current folder first.

And here is pkg1.m

BeginPackage("pkg1`");
Unprotect@@Names("pkg1`*");
ClearAll@@Names("pkg1`*");

foo::usage

Begin("`Private`");

foo():=Module({},

Print("in pkg1  foo OK")

)
End(); (* `Private` *)
Protect@@Names("pkg1`*");
EndPackage()

And here is main.nb, which loads pkg2.m. And once this package is loaded, then pkg1 becomes visible to the user as well, which is not what I want

enter image description here

Question is : What is the correct to have package A use package B in its private section without making B visible to the user?

Is my wine marketing strategy correct?

Good morning.
I am a marketing student and I am working on a marketing assignment for a australian wine company´s participation in an international trade fair. I have chosen the ProWein fair in Düsseldorf, Germany, which seems to be the best ranked in the world.
My marketing strategy is divided in two action plans: one in the headquarters of the company (Melbourne) and one directly at the fair.
Action Plan 1:
3 teams will be created for this project: International department, marketing,…

Is my wine marketing strategy correct?

algorithms – Joining points of polygon in correct order

I have a point’s array of some 2d shape(polygon). The polygon could be either crossed or convex, I don’t know it. And I want to join those points in the correct order.

My first thought was to take some point as an origin and start looking for the closest one and so on. But this approach doesn’t work for some crossed polygons, for example: on Image1, it would go from x3 to x5 because it is closer than to x4, but what I really want is to join x1-x2-x3-x4-x5-x6.

After some thinking, I’ve realized that my requirement correct order is very unclear because on Image2 red lines are in the correct order too. So let’s add the requirement that polygon lines shouldn’t at least cross.

I really confused, can someone point me in what direction I should move? Maybe it’s some famous algorithm but I just don’t know how to google it properly. Thanks.

Image1:
enter image description here

Image2:
enter image description here

Is this example in Skiena’s Algorithm Design Manual correct?

skiena, hashing and strings

i think the above is incorrect; specifically, i think H isn’t bijective. say our alphabet is the lowercase letters (a-z) and that char(a) = 0. then, e.g., H("abc") = H("bc").

am i missing something?

[ Politics ] Open Question : Is Kayleigh McEnany correct in saying it’s peculiar that Joe Biden doesn’t wear a mask in his own home?

lmao she legit tried to frame Biden as fake because he wore a mask in public but not in his own basement. Who agrees with her?

c – Is my concurrent tcp server correct?

So i’ve made a concurrent server that transferes files with socket programming by using fork(), and made a client to connect to a known localhost and ask for a txt. that is in a file. Then the server sends the file to the client that will be then saved locally. This is for a project at college and i’ve been getting feedback that my fork() function in my server isn’t correct and it shouldn’t work, but for me it works just fine? Please have a look.

Server:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <arpa/inet.h>

#define SIZE 1024

void send_file(FILE *fp, int sockfd){
  int n;
  char data(SIZE) = {0};

  while(fgets(data, SIZE, fp) != NULL) {
    if (send(sockfd, data, sizeof(data), 0) < 0) {
      perror("(-)Error in sending file.");
      exit(1);
    }
    bzero(data, SIZE);
  }
  return;
}

int main(){
  // ip address and port
  char *ip = "127.0.0.1";
  int port  = 8888;

  // variables and structures
  int e;
  int sockfd, new_sock;
  struct sockaddr_in server_addr, new_addr;
  socklen_t addr_size;
  char buffer(SIZE);
  pid_t childpid;

  FILE *fp;
  char *filepath;

  // 1. creating the socket
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if(sockfd < 0){
    perror("(-)Error in socket");
    exit(1);
  }
  printf("(+)Server socket created.n");

  // 2. writing the data in the structure
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = inet_addr(ip);
  server_addr.sin_port = port;

  // 3. binding the ip address with the port
  addr_size = sizeof(server_addr);
  e = bind(sockfd, (struct sockaddr*)&server_addr, addr_size);
  if (e < 0){
    perror("(-)Error in bind");
    exit(1);
  }
  printf("(+)Binding successfull.n");

  // 4. listening to the clients
  e = listen(sockfd, 10);
  if (e < 0) {
    perror("(-)Error in listen");
    exit(1);
  }
  printf("(+)Listening...n");

  // 5. accepting the client connection.

  while (1){
    addr_size = sizeof(new_addr);
    new_sock = accept(sockfd, (struct sockaddr*)&new_addr, &addr_size);
    if (new_sock < 0){
      perror("(-)Error in accpet");
      exit(1);
    }
    printf("Connection accepted from %s:%dn", inet_ntoa(new_addr.sin_addr), ntohs(new_addr.sin_port));

    childpid = fork();
    if (childpid == 0){
      close(sockfd);

      while(1){
        recv(new_sock, buffer, SIZE, 0);

        if (strcmp(buffer, "LIST") == 0){
          // send the list of filenames.
          bzero(buffer, SIZE);
          strcpy(buffer, "data.txtnhello.txt");
          send(new_sock, buffer, SIZE, 0);
          bzero(buffer, SIZE);
        }

        else if (strcmp(buffer, "QUIT") == 0){
          // connection disconnected.
          printf("Connection disconnected from %s:%dn", inet_ntoa(new_addr.sin_addr), ntohs(new_addr.sin_port));
          break;
        }

        else {
          // received the filename, send the file data.
          if (strcmp(buffer, "data.txt") == 0){
            filepath = "server_files/data.txt";
            fp = fopen(filepath, "r");
            send_file(fp, new_sock);
          }

          else if (strcmp(buffer, "hello.txt") == 0) {
            filepath = "server_files/hello.txt";
            fp = fopen(filepath, "r");
            send_file(fp, new_sock);
          }

          bzero(buffer, SIZE);
          send(new_sock, "", 1, 0);
          bzero(buffer, SIZE);
        }

      }
    }

  }

}

Client:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <arpa/inet.h>

#define SIZE 1024

void remove_char(char *s, int c){
  /* This function is used to remove a character from the character array. */
  int j, n = strlen(s);
  for (int i=j=0; i<n; i++)
    if (s(i) != c){
      s(j++) = s(i);
    }
    s(j) = '';
}

void write_file(char *filepath, int sockfd){
  int n;
  FILE *fp;
  char buffer(SIZE);

  fp = fopen(filepath, "w");
  if (fp == NULL) {
    perror("(-)Error in creating file");
    exit(1);
  }

  while (1) {
    n = recv(sockfd, buffer, SIZE, 0);
    if (n == 1) {
      break;
      return;
    }

    fprintf(fp, "%s", buffer);
    fflush(fp);
    bzero(buffer, SIZE);
  }
  return;
}

int main(){
  // ip address and port
  char *ip = "127.0.0.1";
  int port = 8888;

  // variables and structures,
  int e;
  int sockfd;
  struct sockaddr_in server_addr;
  char buffer(SIZE);
  char *filepath;

  // 1. creating the socket
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if(sockfd < 0){
    perror("(-)Error in socket");
    exit(1);
  }
  printf("(+)Client socket created.n");

  // 2. writing the data in the structure
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = inet_addr(ip);
  server_addr.sin_port = port;

  // 3. connect to the server
  e = connect(sockfd, (struct sockaddr*)&server_addr, sizeof(server_addr));
  if(sockfd < 0){
    perror("(-)Error in connect");
    exit(1);
  }
  printf("(+)Connected to the servern");

  printf("n");
  printf("List of the commands.n");
  printf("LIST - list all the files.n");
  printf("LOAD - download the file.n");
  printf("       LOAD <path>n");
  printf("QUIT - disconnect from the server.n");

  while(1){
    fflush(stdout);
    printf("> ");
    fgets(buffer, SIZE, stdin);

    if (strlen(buffer) > 1){
      char *token1 = strtok(buffer, " ");
      char *token2 = strtok(NULL, " ");
      remove_char(token1, 'n');

      if (strcmp(token1, "LIST") == 0) {
        // list all the file of the server.
        send(sockfd, buffer, SIZE, 0);
        recv(sockfd, buffer, SIZE, 0);
        printf("%sn", buffer);
      }

      else if (strcmp(token1, "LOAD") == 0) {
        if (token2 == NULL) {
          printf("(-)Specify the correct filename.n");
        } else {
          // save the data of the file received from the server.
          remove_char(token2, 'n');
          send(sockfd, token2, SIZE, 0);

          if (strcmp(token2, "data.txt") == 0){
            filepath = "client_files/data.txt";
            write_file(filepath, sockfd);
            printf("(+)File saved.n");
          }

          else if (strcmp(token2, "hello.txt") == 0) {
            filepath = "client_files/hello.txt";
            write_file(filepath, sockfd);
            printf("(+)File saved.n");
          }

          else {
            printf("Incorrect pathn");
          }
        }
      }

      else if (strcmp(token1, "QUIT") == 0) {
        // disconnect from the server.
        printf("(+)Disconnected from the server.n");
        send(sockfd, token1, SIZE, 0);
        break;
      }

      else {
        printf("(-)Invalid commandn");
      }
    }

    bzero(buffer, SIZE);
  }

}

What is the correct way to call a PHP Function with multiple parameters from the AJAX Handler?

Q: What is the correct way to call a PHP Function with multiple parameters from the AJAX Handler?

Q: Am I calling the php function correctly?


Page Element
The user clicks a button.

Action:
The click should connect to an external server using the following params:

  1. User Name 2. IP Address 3. Port 4. Public Key 5. Service

Purpose:
Send an vote string (from host A) to an external Gaming server (host B).
I do not need to update any wordpress content.

WordPress Version: 5.4.1
I put my custom php code into “/wp-contents/plugins/my-plugin/votifier.php”

I made sure the custom plugin is activated.

I have WordPress in Debug mode. i.e. Debug mode is true.

The Button

<div id="frm_field_61_container">
<button type="button">Try it</button>
</div>

WordPress JQuery with AJAX

jQuery(document).ready( function($) {
 $("#frm_field_61_container").click(function(){

      jQuery.ajax({

         type : "post",

         dataType : "json",

         url : myAjax.ajaxurl,

         data : {    action: "my_vote_count"
                    ,username: $('input(name="item_meta(59)")').val()
                    ,key: $.trim($("#field_yjr62").val())
                    ,ip: $('input(name="item_meta(40)")').val()
                    ,port: $('input(name="item_meta(42)")').val()
                    ,service: "Votifier"
                },

        success:    function(data,status,xhr){
                    alert("Data: " + data);
                    alert("Status: " + status);
                    alert("xhr: " + xhr);
                }
      });   
   });
});

My Custom PHP Script

<?php


function mainVotifier($username, $public_key, $server_ip, $port, $service_name) {

define( 'VOTE_FORMAT', 'VOTEn%sn%sn%sn%dn' );
define( 'PUBLIC_KEY_FORMAT', '-----BEGIN PUBLIC KEY-----n%sn-----END PUBLIC KEY-----' );

$key    = wordwrap($public_key, 65, "n", true);
$key    = sprintf(PUBLIC_KEY_FORMAT, $key);


  if (php_sapi_name() !== 'cli') {
            //Detect proxy and use correct IP.
            $address = isset($_SERVER('HTTP_X_FORWARDED_FOR')) ? $_SERVER('HTTP_X_FORWARDED_FOR') : $_SERVER('REMOTE_ADDR');
        } else {
            //Script is run via CLI, use server name.
            $address = $_SERVER('SERVER_NAME');
        }

    $data = sprintf(VOTE_FORMAT, $service_name, $username, $address, time());
    openssl_public_encrypt($data, $crypted, $key);
    $socket = @fsockopen($server_ip, $port);

    if ($socket) {
        if (fwrite($socket, $crypted)) {
            fclose($socket);
            return true;
        }
    }

}

?>

/* ===== WP_ENQUEUE SCRIPTS ==== */

/* ===== JQuery Ajax Script to call votifier.php ==== */
add_action( 'wp_enqueue_scripts', 'my_script_enqueuer' );
function my_script_enqueuer() {

   wp_enqueue_script( 'my_voter_script',  plugins_url('sendvote.js', __FILE__), array( 'jquery'),   '1.0', true);

   wp_localize_script( 'my_voter_script', 'myAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));

}

/* ===== My AJAX Handler ==== */

/* add_action( 'wp_ajax_nopriv_my_vote_count', 'my_ajax_handler' ); */ 
add_action( 'wp_ajax_my_vote_count', 'my_ajax_handler');
function my_ajax_handler() {

/*  check_ajax_referer('votifier_response_key'); */

    $username       = $_POST("username");
    $public_key     = $_POST('key');
    $server_ip      = $_POST("ip");
    $port           = $_POST("port");   
    $service_name   = $_POST("service");

   echo "mainVotifier("" . $username . "", "" . $public_key . "", "" . $server_ip . "", "" . $port . "", "" . $service_name . "");";


    wp_die(); // All ajax handlers die when finished

}

Console Results

The console results are good, but the other server is not responding.
I tested the PHP code locally from my personal computer and Server B is responding.


Request URL:https://bestminecraftserverlist.com/wp-admin/admin-ajax.php
Request Method:POST
Remote Address:192.169.170.42:443
Status Code:
200
Version:HTTP/2

Is the definition of the Rieman sum from Thomas’ Calculus correct?

I’m having trouble with theoretical understanding of the Riemann sum with this explanation/definition from Thomas’ Calculus. I checked Wikipedia and it seems to state virtually the same.:

On each subinterval we form the product $f(c_k)*∆x_k$. This product is positive, negative, or zero, depending on the sign of $f(c_k)$. When $f(c_k) > 0$, the product $f(c_k)*∆x_k$ is the area of a rectangle with height $f(c_k)$ and width $∆x_k$. When $f(c_k) < 0$, the product $f(c_k)*∆x_k$ is a negative number, the negative of the area of a rectangle of width $∆x_k$ that drops from the x axis to the negative number $ƒ(c_k)$.

Finally we sum all these products to get:

$$
S_p = sum_{k=1}^{n}{f(c_k)}∆x_k
$$

Any Riemann sum associated with a partition of a closed interval (a, b) defines rectangles that approximate the region between the graph of a continuous function ƒ and the x-axis. Partitions with norm approaching zero lead to collections of rectangles that approximate this region with increasing accuracy

To illustrate the problem, suppose we want to approximate the area between $f(x) = -x$ and the x axis on the interval (-1; 1). The area is 1, but the Riemann sum should give something close to 0:

Riemann sum example

Is the statement that any Riemann sum with the norm approaching 0 approximates the area with increasing accuracy correct? It seems not, since in the example above the area tends to 0 as the norm approaches 0, which is not “increasing accuracy”. Does it miss the part that one should take the absolute values of the rectangles’ areas?

Thank you.

categories – In if…else condition, the else statement shows even if if statement is correct

Will please someone help me why this happens. Firstly here is my code.

add_action( 'woocommerce_after_add_to_cart_form', 'sione_enquiry_button' );
add_action('woocommerce_cart_actions', 'sione_enquiry_button_new');
function sione_enquiry_button() {
if(!is_product()){
return;
}


if (has_term( 'blue-block-frames', 'product_cat' )) {
    ?>
    <input disabled style="padding: 5px 20px;background: #193670!important;border: 0!important;color: white!important;" type="button" id="enquiry-button" class="btn enquiry-button" value="<?php echo __( 'Whatsapp your prescription to +918328120536 after purchase', 'orchid' ); ?>" />

    <?php
    } else {
    ?>
    <input style="padding: 5px 20px;background: #193670!important;border: 0!important;color: white!important;" type="button" id="enquiry-button" class="btn enquiry-button" value="<?php echo __( 'Send Enquiry for Wholesale Price', 'orchid' ); ?>" />

    <?php
    }
}

function sione_enquiry_button_new() {
if(is_cart()) {
$check = false;
// check each cart item for our category
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {

    $product = $cart_item('data');

    // replace 'membership' with your category's slug
    if ( has_term( 'blue-block-frames', 'product_cat', $product->id ) ) {
$check= true;
    }
}
if($check == true) {
    ?>
    <input disabled style="padding: 5px 20px;background: #193670!important;border: 0!important;color: white!important;" type="button" id="enquiry-button" class="btn enquiry-button" value="<?php echo __( 'Whatsapp your prescription to +918328120536 after purchase', 'orchid' ); ?>" />

    <?php
} else {
    ?>
    <input style="padding: 5px 20px;background: #193670!important;border: 0!important;color: white!important;" type="button" id="enquiry-button" class="btn enquiry-button" value="<?php echo __( 'Send Enquiry for Wholesale Price', 'orchid' ); ?>" />

    <?php
}
}
}

Will someone please tell me why else statement is showing even else is false.

terminology – Determining correct term for a button with options and Vue JS example

I am familiar with some UI terms but certainly not all. I remember smiling when I figured out what people meant by the term “snackbar” (and have now designed one myself).

However, there is a button which normally has a small-ish triangle to the right. Normally you click the button and a single action happens, however if you specifically click the “small-ish” triangle, you’ll get a dropdown list of options. The default one is typically the one you’d have gotten had you just clicked the main part of the button. But the other options are things an advanced user might want to do. Another thing I’ve seen on the side is a .. but rotated 90 deg.

Again, my question is what the normal term is (if there is one). any additional link to a VueJs example would be over the moon.