Replacing strings over array. Why one thing works while other similar? code (to my newbie self) doesn’t

In a new complete series of me struggling with any concept:

I have two sets of code, one works the other doesn’t can’t figure out why for the life of me.

const arr1 = [{
    sku: '003CON',
    price: undefined
  },
  {
    sku: 1000,
    price: 2215.49
  },
  {
    sku: 1001,
    price: 2215.49
  },
  {
    sku: 'PD-1000B',
    price: undefined
  },
  {
    sku: 'PD-1007A',
    price: 2195.14
  },
  {
    sku: 'PD-1042A',
    price: 2495.29
  },
  {
    sku: 'BD111-50',
    price: 2495.29
  },
  {
    sku: 'BD222-50',
    price: 2495.29
  },
  {
    sku: 'BD333',
    price: 2495.29
  },
  {
    sku: 'KL.213',
    price: 2495.29
  },
  {
    sku: 'KL.312',
    price: undefined
  },
  {
    sku: 1005,
    price: 2495.29
  },
  {
    sku: 5343,
    price: undefined
  },
  {
    sku: 1231,
    price: undefined
  },
  {
    sku: 3542,
    price: 2495.29
  },
  {
    sku: 6756,
    price: 2495.29
  },
  {
    sku: 7685,
    price: undefined
  },
  {
    sku: 1076,
    price: 2495.29
  },
]

var what = arr1.map((e) => {
  if (typeof e.sku === 'string') {
    return {
      sku: e.sku.startsWith("PD-") ? e.sku.replace("S/A", "").trim() :
        e.sku.startsWith('KL') ? e.sku.replace('.', '').trim() :
        e.sku.startsWith('BD') ? e.sku.replace('-50', '').trim() :
        e.sku,
      price: typeof e.price === "undefined" ? "0" : e.price,
    };
  }
  else {
    return {
      sku: e.sku,
      price: typeof e.price === 'undefined' ? '0' : e.price
    }
  }
});

what.forEach(e => {
  if (typeof e.sku === 'string') {
    if (e.sku.includes('PD-1000B')) {
      e.sku = 'PD-1000-B'
    }
    if (e.sku.includes('PD-1007A')) {
      e.sku = 'PD-1007-A'
    }
    if (e.sku.includes('PD-1042A')) {
      e.sku = 'PD-1042-A'
    }
  }
})

console.log(what)

var what2 = arr1.map((e) => {
  if (typeof e.sku === 'string') {
    return {
      sku: e.sku.startsWith("PD-") ? e.sku.replace("S/A", "").trim() :
        e.sku.startsWith('KL') ? e.sku.replace('.', '').trim() :
        e.sku.startsWith('BD') ? e.sku.replace('-50', '').trim() :
        e.sku.startsWith('PD-1000') ? e.sku.replace('PD-1000','PD-1000-') : //this doesnt work
        e.sku.startsWith('PD-1007') ? e.sku.replace('PD-1007','PD-1007-') : //this
        e.sku.startsWith('PD-1042') ? e.sku.replace('PD-1042','PD-1042-') : //this
        e.sku,
      price: typeof e.price === "undefined" ? "0" : e.price,
    };
  }
  else {
    return {
      sku: e.sku,
      price: typeof e.price === 'undefined' ? '0' : e.price
    }
  }
});

console.log(what2)

So I “””have to””” do the forEach or else the ‘PD-1000B’ et al don’t get replaced ????

I have no clue. Obviously I’m missing something. The only thing I can think of is that maybe if I already looped through startsWith ‘PD-‘ I can’t do something similar?

Thank you.

Adding Text or Any element in 3D cube while rotating in Threejs at react

I’m using a ReactJS in ThreeJs because I don’t wanna forget ReactJs while I’m practicing threejs…
So basically my problem here is that I don’t know or how can I add a text in reactjs because the FontLoader() location in the file of threejs is unfindable for me. I tried to research it but only I get is a normal js and I don’t know how can I find it. Also I tried this one example.. but I couldn’t get it how to add it or how I will do this LINK1 LINK2… I’m trying to understand but its hard to figure out to me because I only understand the basic. So I have a CODEPEN here which you can see the example of the boxes… I’m trying to add some boxes in each or maybe just only one( if you can’t do it in a loop)..

Another maybe if you can answer this another question of mine which is how I will add my div element in boxGeometry?

You can see it in the App.js at the lines of 42-92 lines. And this is the code

let geometry = new THREE.BoxGeometry(1,1,1);
let material = new THREE.MeshPhysicalMaterial({color:0xF7F7F7});
let specifiedList = [
    [0.1,1,1],
    [0.2,-2,2],
    [2,1,3],
    [1,3,3],
    [2,3,1],
    [-2,-2,2],
    [-2,0.5,2],
    [2,-3,1],
    [-4,2,3],
    [-6,-2,-3],
    [-6,-1,-1],
    [6,-1,-1],
    [6,2,-1],
    [6,2,2],
    [6,1,1],
    [6,3,3],
]
for (let i = 0; i <specifiedList.length; i++) {
    let mesh = new THREE.Mesh(geometry,material);
    mesh.position.x = specifiedList[i][0]
    mesh.position.y = specifiedList[i][1]
    mesh.position.z = specifiedList[i][2]
    scene.add(mesh);

    gsap.to(mesh.rotation,{
        scrollTrigger:{
            trigger:".main",
            start:"top top",
            end:"3000px",
            pin:true,
            scrub:true,
            toggleActions:"restart pause resume pause"
        },
        y:Math.PI
    })
    gsap.to(mesh.position,{
        scrollTrigger:{
            trigger:".main",
            start:"top top",
            end:"3000px",
            pin:true,
            scrub:true,
            toggleActions:"restart pause resume pause"
        },
        z:5
    })
    
}

so if anyone have a link or a simple example that can make it just leave a link or something demo in a simplier cause I’m just a beginner yet in Threejs hahaha…

Also don’t suggest me the ‘react-threefiber’ thing in ReactJS cause that is not more specified infomration that I wanna understand.

Errors when using file_get_contents() in PHP

I have been trying to create a Duinocoin Faucet. (Duinocoin is a small crypto that can be mined by small microcontrollers and a faucet is a website that gives out small amounts of crypto.) When I use my site everything works as planned until I submit the form. Then I get multiple errors for the same line of code. (See image for reference) This form just requires a username and a hCapture.

I have already tried the following:

$arrContextOptions = array(
      "ssl" => array(
        "verify_peer" => false,
        "verify_peer_name" => false,
      )
);  
"verify_peer" => false,
"allow_self_signed" => true,

Here is my index.php code:

<?php error_reporting (E_ALL ^ E_NOTICE); ?>
<?php

$data = array(
            'secret' => "*My secret hCapcha code here*",
            'response' => $_POST['h-captcha-response']
        );

$verify = curl_init();
curl_setopt($verify, CURLOPT_URL, "https://hcaptcha.com/siteverify");
curl_setopt($verify, CURLOPT_POST, true);
curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($verify, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($verify);
// var_dump($response);
$responseData = json_decode($response);

if($responseData->success) {
    echo $content = file_get_contents("https://server.duinocoin.com/transaction/?username=My Username&password=My Password&recipient=".$_POST['pseudo']."&amount=0.004&memo=Thanks%20For%20Using%20LeakyFaucet");


}
 

?>
<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>Leaky Faucet | Duino-Coin</title>
  <link rel="stylesheet" href="./style.css">
  <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
  <script src="https://js.hcaptcha.com/1/api.js" async defer></script>
</head>
<body>
<div class="header">
<div class="inner-header flex">
<form class="login" action="" method="POST">
  <input type="text" name="pseudo" placeholder="Username" required>
  <div class="h-captcha" data-sitekey="*My hCapcha Site Key*"></div>
  <button type="submit" value="Go">Login</button>
</form>
</div>
<div>
    <script type="text/javascript">
        $("form").submit(function(event) {

           var hcaptchaVal = $('[name=h-captcha-response]').value;
           if (hcaptchaVal === "") {
              event.preventDefault();
              alert("Please complete the hCaptcha");
           }
        });
    </script>
<svg class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto">
<defs>
<path id="gentle-wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z" />
</defs>
<g class="parallax">
<use xlink:href="#gentle-wave" x="48" y="0" fill="rgba(255,255,255,0.7" />
<use xlink:href="#gentle-wave" x="48" y="3" fill="rgba(255,255,255,0.5)" />
<use xlink:href="#gentle-wave" x="48" y="5" fill="rgba(255,255,255,0.3)" />
<use xlink:href="#gentle-wave" x="48" y="7" fill="#fff" />
</g>
</svg>
</div>
</div>
<div class="content flex">
</div>
</body>
</html>

Any help would be highly appreciated.

mqttws31.js:979 Uncaught DOMException: Failed to construct ‘WebSocket’: An insecure WebSocket connection may not be initiated from an https page

i have to make a chatapp for a course using mqtt (hivemq) with javascript in a webrowser (html css); when i open the file in my browser it works fine, i receive and can send and see others messages but i want my webapp to accessable to everyone .. i tried github pages .. it didnt work cuz it uses https connections and mine uses ws. i understand the problem. i know what the problem is. but is there any way i can fix it? like is there a way i can still use my hivemq chatapp online?

my javascript code looks like this btw:

// Create a client instance
//client = new Paho.MQTT.Client("test.mosquitto.org", 8080, client_id="", clean_session="true", userdata="none", protocol="MQTTv311", transport="tcp");

var client = new Paho.MQTT.Client("broker.hivemq.com", 8000, "Keshav");

// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;

// connect the client
client.connect({onSuccess:onConnect});


// called when the client connects
function onConnect() {
  // Once a connection has been made, make a subscription and send a message.
  console.log("onConnect");
  client.subscribe("codettes2022");
  //pick one!
  message = new Paho.MQTT.Message("Keshav just hopped on! say hi!");
  message2 = new Paho.MQTT.Message("Keshav just landed! say hello!");
  message3 = new Paho.MQTT.Message("Keshav joined the party! welcome!");
  message4 = new Paho.MQTT.Message("welcome keshav, we hope you brought boogie's");
  message.destinationName = "codettes2022";
  message2.destinationName = "codettes2022";
  message3.destinationName = "codettes2022";
  message4.destinationName = "codettes2022";

  var values = [message,message2,message3,message4]
  valueToUse = values[Math.floor(Math.random() * values.length)];
  client.send(valueToUse); //here you send the message name .. message1,2,3,4
}

function sendMessageButton(msgtext){
    if (msgtext!=''){
      message = new Paho.MQTT.Message(msgtext);
      message.destinationName = "codettes2022";
      client.send(message);
      console.log(message);
    }
}
// OR listen to the Enter event on n input box
function sendMsg(ele) {
    if(event.key === 'Enter') {
        message = new Paho.MQTT.Message("Alien says: " +  ele.value);
        message.destinationName = "codettes2022";
        client.send(message);
        //alert(ele.value);
       ele.value = ""; // reset the input after entering
        console.log(message);
    }
}

// called when the client loses its connection
function onConnectionLost(responseObject) {
  if (responseObject.errorCode !== 0) {
    console.log("onConnectionLost:"+responseObject.errorMessage);
  }
}

// called when a message arrives
function onMessageArrived(message) {
  console.log("onMessageArrived:"+ message.payloadString);
  // To do: if user is myself do different style or ignore the message and write directly to log
  var name = "keshav"//change ur name here
  var cor = '<h4 class="styletxt">' + '<h5 class="name">' + name + "</h5>" + message.payloadString + "</h4>"   // "<h4>" + + "</h4>"
  document.getElementById("chatlog").innerHTML += cor + "<br>"
}

html + css:
html:

<!DOCTYPE html>
<html lang="en">
<header>
    <!--<div style="background-color:blue; width: 100%; height: 60px;">
        <h1 style="padding-left: 25%; padding-right: 25%;">hi</h1>
    </div>-->
</header>
<head>
    <meta charset="UTF-8">
    <title>bootcamp2022GANG</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript"></script>
    <script src="script2.js"></script>
</head>
<body>
<!--<div class="status" style="float: top; background-color: #474746; float: top; width: 25%; height: 60px;">

</div>-->


<div>

    <div class="chat-bg">
        <div class="status">

        </div>
        <h4 style="font-family: arial; text-align: center;">chats</h4>
        <div class="codettesBootcamp2022">
            <img class="bootcamp2022LOGO" src="bootcamplogo.jpg">
            <h4 class="bootcamp2022name">Bootcamp2022</h4>
        </div>

    </div>
</div>
<aside>
    <div class="chat-LOG">
        <div class="person">
            <h3 class="person-name">Bootcamp2022</h3>
        </div>
        <div class="text-inpt" style="width: 100%;">
            <div id="chatlog" style="width: 100%; height: 650px; text-align: center;">
                <h6 style="margin: 0; padding-top: 10px;">this chat isn't safe, so chances of message leaks are high. be
                    careful.</h6>
                <div id="name">

                </div>
            </div>
            <input class="inpt" type="text" id="chatInput">
            <button class="sendButton"
                    onclick="sendMessageButton(getElementById('chatInput').value); getElementById('chatInput').value='';">
                <img class="send-img" src="sendmessage-orig.png"></button>
        </div>
    </div>
</aside>

</body>


<!---->


<footer>
    <!--<h2>mail me at [redacted]. the chance ill respond to ur mail is very low.</h2>-->
</footer>
</html>

css:

html{
    background-color: gray;
}

.person{
    border-radius: 20px;
    float: top;
    text-align: center;
    background-color: #6a6b69;
    width: 100%;
    height: 60px;
}

.chat-bg{
    border-radius: 20px;
    float: left;
    float: bottom;
    background-color: #a9a9a9;
    width:25%;
    height: 775px;
}

.status{
    float: top;
    background-color: #474746;
    float: top;
    width: 100%;
    height: 60px;
}

.sendButton{
    border-radius: 25%;
    background-color: #326da8;
    outline: none; border: none;
    height:30px;
    width:30px;
}

.send-img{
    float: center;
    height:20px;
    width:100%;
    max-width: 20px;
    padding-top: 25%;
}

.status{
    border-radius: 20px;
}

.input-message .input{
    border-radius: 20px;
    background-color: blue;
}

.codettesBootcamp2022{
    border-radius: 35px;
    overflow: hidden;
    float: top;
    background-color: #4b2157;
    width: 100%;
    height: 60px;
    max-width: 350px;
    margin:0 auto;
}

.bootcamp2022LOGO{
    max-width: 50px;
    border-radius: 50%;
    padding-top: 5px;
    padding-left: 5px;
}


::placeholder { /* Chrome, Firefox, Opera, Safari 10.1+ */
    color: gray;
    opacity: 1; /* Firefox */
}

.styletxt{
    color: white;
}

.codettesBootcamp2022 .a{ /* Style the links inside the navigation bar */
    float: right;
    color: #f2f2f2;
    text-align: center;
    padding: 14px 16px;
    font-size: 17px;
}

.codettesBootcamp2022:hover{ /* Change the color of links on hover */
    background-color: #ddd;
    color: black;
    /*cursor: pointer;*/ /*dont give the user a feeling that it will do something when it doesnt.*/
}

.bootcamp2022name{
    float: right;
    padding-right: 30%;
    display: inline-block;
    font-family: 'Trebuchet MS', sans-serif;
}

.chat-LOG{
    float: right;
    font-color : white;
    background-color: #dbdbdb;
    width: 73%;
    height: 775px;
    border-radius: 20px;
    font-family: 'Trebuchet MS', sans-serif;
}

.person-name{
    display: inline-block;
    font-family: 'Trebuchet MS', sans-serif;
}

.inpt{
    background-color: #63605f;
    outline: none;
    border: none;
    border-radius: 6px;
    height: 35px;
    width: 90%;
    margin-left:4.3%;
}

@media only screen and (min-width: 768px) {
    /*later*/
}

i use the js in a browser. if you have any suggestions for a better connection using nodejs, also great, ty

XMLHttpRequest does not send parameters with POST request

I am using XMLHttpRequest to make a post request with JavaScript. I make the request and use the send() method with an x-www-form-urlencoded string as the parameter. But when this request gets made in the browser, the paramters I passed through are not sent with the request.
Example: I send a post request

xhttp = new XMLHttpRequest();
xhttp.onload = function() {
    //code
}
xhttp.open('POST', 'https://example.com/request', true);
xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhttp.send('lorem=ipsum&title=title');

So the request gets sent but instead of being sent like: https://example.com/request?lorem=ipsum&title=title
It sends it like this: https://example.com/request with none of the parameters.

Why did I lose my javascript file to npm?

I wrote up a small library, just a .js file with some frequently used functions, and dropped it into the node_modules folder so it was alongside all of my other packages. Great.

A few days later, I added a new package with npm install. When I ran the program to test it, I got errors for my library missing, and sure enough it was no longer in the node_modules folder, recycling bin, or even appearing in my source control because I gitignore’d the folder.

As someone who’s new to projects that use more than a handful of files, could someone please explain what may have caused this, and how I can prevent it in the future?

Discord JS Bot to recognize specific reaction add and reaction remove events on specific message

I am working on a Discord.js bot and, among other things, I want it to be able to post a message and keep track of how many :thumbsup: emojis are added as reactions. That is to say, I want it to count :thumbsup: emojis specifically, nothing else, and I want it to remove from the counter 1 point every time a :thumbsup: emoji is removed as a reaction.

I wrote the initial snippet for this feature some time ago, and the code I wrote for this feature no longer works, if indeed it ever completely did. I believe I was never able to get the reaction removal events to work properly. Recently I’ve discovered that even more than that, however, the reaction add event is being triggered for ALL emojis, not just the one I name here. I would be grateful for any assistance stackoverflow could offer in my efforts to make the following work as intended.

msgChat.send("MESSAGE CONTENT").then(msgElement => {
  const thumbFilter = (reaction) => { return reaction.emoji.name != 'thumbsup' };
  const thumbCounter = testWarning.createReactionCollector(thumbFilter, {dispose: true, time: 28800000 });
  var thumbCount = 0;
  thumbCounter.on('collect', (r, c) => {
    if (r.emoji.name == "thumbsup") {
      thumbCount++;
      if (thumbCount == 6) {
        msgChat.send("Six thumbs were gathered");
        thumbCounter.stop();
      }
    }
  });
  thumbCounter.on('remove', (r, c) => {
    if (r.emoji.name == "thumbsup") {
      thumbCount--;
    }
  });
  thumbCounter.on('end', (r, c) => {
    console.log("Collected " + thumbCount + " thumbs before closing");
  });
});

msgChat in this case is defined (correctly, as far as I can tell) to the channel in which I want the bot to post. Everything else in this snippet is constructed as best as I could from the online documentation of Discord.js. It seems to me, from what I’ve read, that the ‘remove’ event may no longer exist in the current version? But I have had a terrible time finding out how to replace its functionality.

Scraping value of website after script has run on that website and redirects me

I’m going to be honest with you. I’m a beginner in programming in Python.

But my question really needs an answer because I can’t seem to find or understand it by myself.

To be simple and plain I’ll explain what I want it to do.

I want to fill in some values and then click a button, this will run some javascript on the website I’m doing this on that will show me the data based on the value of which it is that day. The output will be available in plain html.

When I click this button that will show the data of the script ran, it redirects me, same site but difference is what’s behind the / of the url and show me the output of the script

I’ve found that Selenium API can do the entering of values and click the button.

But now, and this could be due to my beginners understanding of python/programming in general and how websites with python when being redirected and how it works when the data shown is formulated by a script, but I want to know if or how I can then pull or request that url and/or data the script has outputted. To then scrape that specific output.

Probably important to know is that when the script has run and I copy the URL that has the data I want to scrape and paste it into another tab it redirects me the the form for putting in some values to run that script. Which puts me back to where I started.

I hope I’ve made it clear to what I want it to do.

Is this even possible with python or an API, if so, how?

And if you can please give an explanation.

If you want to help but need more info, please don’t hesitate to ask or lmk.

Thanks in advanced everyone!

getting error when dowloading node sass version 4

when running

npm install --saveDev [email protected] 

I am getting this error I have tried many things like removing node modeules and package-lock.json and intalling window-builder-tools also installing ctgwin but nothing seems to work please help although version 8 is working I think I need 4 because of some error that reuires version 4 thanks in advance

    npm WARN deprecated [email protected]: this library is no longer supported

npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: This version of tar is no longer supported, and will not receive security updates. Please upgrade 
asap.
npm ERR! code 1
npm ERR! path C:UsersAcerDownloadsFrndsmeetclientnode_modulesnode-sass
npm ERR! command failed
npm ERR! command C:WINDOWSsystem32cmd.exe /d /s /c node scripts/build.js
npm ERR! Building: C:Program Filesnodejsnode.exe C:UsersAcerDownloadsFrndsmeetclientnode_modulesnode-gypbinnode-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
npm ERR! Build started 6/25/2022 3:39:36 AM.
npm ERR! Project "C:UsersAcerDownloadsFrndsmeetclientnode_modulesnode-sassbuildbinding.sln" on node 1 (default targets).npm ERR! ValidateSolutionConfiguration:
npm ERR!   Building solution configuration "Release|Win32".
npm ERR! MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe". To fix this, 1) install the .NET Framework 2.0 SDK, 2) install Microsoft Visual Studio 2005 or 3) add the location of the component to the system path if it is installed elsewhere.  [C:UsersAcerDownloadsFrndsmeetclientnode_modulesnode-sassbuildbinding.sln]
npm ERR! Done Building Project "C:UsersAcerDownloadsFrndsmeetclientnode_modulesnode-sassbuildbinding.sln" (default targets) -- FAILED.
npm ERR!
npm ERR! Build FAILED.
npm ERR!
npm ERR! "C:UsersAcerDownloadsFrndsmeetclientnode_modulesnode-sassbuildbinding.sln" (default target) (1) ->
npm ERR! (_src_libsass target) ->
npm ERR!   MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe". To fix this, 1) install the .NET Framework 2.0 SDK, 2) install Microsoft Visual Studio 2005 or 3) add the location of the component to the system path if it is installed elsewhere.  [C:UsersAcerDownloadsFrndsmeetclientnode_modulesnode-sassbuildbinding.sln]
npm ERR! 
npm ERR!     0 Warning(s)
npm ERR!     1 Error(s)
npm ERR!
npm ERR! Time Elapsed 00:00:02.67
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli   'C:\Program Files\nodejs\node.exe',
npm ERR! gyp verb cli   'C:\Users\Acer\Downloads\Frndsmeet\client\node_modules\node-gyp\bin\node-gyp.js',
npm ERR! gyp verb cli   'rebuild',
npm ERR! gyp verb cli   '--verbose',
npm ERR! gyp verb cli   '--libsass_ext=',
npm ERR! gyp verb cli   '--libsass_cflags=',
npm ERR! gyp verb cli   '--libsass_ldflags=',
npm ERR! gyp verb cli   '--libsass_library='
npm ERR! gyp verb cli ]
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | ia32
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (C:UsersAcerDownloadsFrndsmeetclientnode_moduleswhichwhich.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:UsersAcerDownloadsFrndsmeetclientnode_moduleswhichwhich.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:UsersAcerDownloadsFrndsmeetclientnode_moduleswhichwhich.js:80:29)
npm ERR! gyp verb `which` failed     at C:UsersAcerDownloadsFrndsmeetclientnode_moduleswhichwhich.js:89:16
npm ERR! gyp verb `which` failed     at C:UsersAcerDownloadsFrndsmeetclientnode_modulesisexeindex.js:42:5
npm ERR! gyp verb `which` failed     at C:UsersAcerDownloadsFrndsmeetclientnode_modulesisexewindows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
npm ERR! gyp verb `which` failed  python2 Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (C:UsersAcerDownloadsFrndsmeetclientnode_moduleswhichwhich.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:UsersAcerDownloadsFrndsmeetclientnode_moduleswhichwhich.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:UsersAcerDownloadsFrndsmeetclientnode_moduleswhichwhich.js:80:29)
npm ERR! gyp verb `which` failed     at C:UsersAcerDownloadsFrndsmeetclientnode_moduleswhichwhich.js:89:16
npm ERR! gyp verb `which` failed     at C:UsersAcerDownloadsFrndsmeetclientnode_modulesisexeindex.js:42:5
npm ERR! gyp verb `which` failed     at C:UsersAcerDownloadsFrndsmeetclientnode_modulesisexewindows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21) {
npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! gyp verb `which` failed }
npm ERR! gyp verb check python checking for Python executable "python" in the PATH
npm ERR! gyp verb `which` succeeded python C:Python27python.EXE
npm ERR! gyp verb check python version `C:Python27python.EXE -c "import sys; print "2.7.18
npm ERR! gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
npm ERR! gyp verb get node dir no --target version specified, falling back to host node version: 16.14.0
npm ERR! gyp verb command install [ '16.14.0' ]
npm ERR! gyp verb install input version string "16.14.0"
npm ERR! gyp verb install installing version: 16.14.0
npm ERR! gyp verb install --ensure was passed, so won't reinstall if already installed
npm ERR! gyp verb install version is already installed, need to check "installVersion"
npm ERR! gyp verb got "installVersion" 9
npm ERR! gyp verb needs "installVersion" 9
npm ERR! gyp verb install version is good
npm ERR! gyp verb get node dir target node version installed: 16.14.0
npm ERR! gyp verb build dir attempting to create "build" dir: C:UsersAcerDownloadsFrndsmeetclientnode_modulesnode-sassbuild
npm ERR! gyp verb build dir "build" dir needed to be created? C:UsersAcerDownloadsFrndsmeetclientnode_modulesnode-sassbuild
npm ERR! gyp verb find vs2017 Found installation at: C:Program FilesMicrosoft Visual Studio2019BuildTools
npm ERR! gyp verb find vs2017   - Missing Visual Studio C++ core features (Microsoft.VisualStudio.VC.MSBuild.Base)
npm ERR! gyp verb find vs2017   - Missing VC++ 2017 v141 toolset (x86,x64) (Microsoft.VisualStudio.Component.VC.Tools.x86.x64)
npm ERR! gyp verb find vs2017   - Missing a Windows SDK (Microsoft.VisualStudio.Component.Windows10SDK.* or Microsoft.VisualStudio.Component.Windows81SDK)
npm ERR! gyp verb find vs2017   - Some required components are missing, not using this installation
npm ERR! gyp verb find vs2017 Found installation at: C:Program FilesMicrosoft Visual Studio2017BuildTools
npm ERR! gyp verb find vs2017   - Missing Visual Studio C++ core features (Microsoft.VisualStudio.VC.MSBuild.Base)
npm ERR! gyp verb find vs2017   - Missing VC++ 2017 v141 toolset (x86,x64) (Microsoft.VisualStudio.Component.VC.Tools.x86.x64)
npm ERR! gyp verb find vs2017   - Missing a Windows SDK (Microsoft.VisualStudio.Component.Windows10SDK.* or Microsoft.VisualStudio.Component.Windows81SDK)
npm ERR! gyp verb find vs2017   - Some required components are missing, not using this installation
npm ERR! gyp verb Not using VS2017: No usable installation of VS2017 found
npm ERR! gyp verb build/config.gypi creating config file
npm ERR! gyp verb build/config.gypi writing out config file: C:UsersAcerDownloadsFrndsmeetclientnode_modulesnode-sassbuildconfig.gypi
npm ERR! (node:9544) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
npm ERR! (Use `node --trace-deprecation ...` to show where the warning was created)
npm ERR! gyp verb config.gypi checking for gypi file: C:UsersAcerDownloadsFrndsmeetclientnode_modulesnode-sassconfig.gypinpm ERR! gyp verb common.gypi checking for gypi file: C:UsersAcerDownloadsFrndsmeetclientnode_modulesnode-sasscommon.gypinpm ERR! gyp verb gyp gyp format was not specified; forcing "msvs"
npm ERR! gyp info spawn C:Python27python.EXE
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   'C:\Users\Acer\Downloads\Frndsmeet\client\node_modules\node-gyp\gyp\gyp_main.py',        
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'msvs',
npm ERR! gyp info spawn args   '-G',
npm ERR! gyp info spawn args   'msvs_version=auto',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\Users\Acer\Downloads\Frndsmeet\client\node_modules\node-sass\build\config.gypi',     
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\Users\Acer\Downloads\Frndsmeet\client\node_modules\node-gyp\addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\Users\Acer\.node-gyp\16.14.0\include\node\common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=C:\Users\Acer\.node-gyp\16.14.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=C:\Users\Acer\Downloads\Frndsmeet\client\node_modules\node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=C:\Users\Acer\.node-gyp\16.14.0\<(target_arch)\node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=C:\Users\Acer\Downloads\Frndsmeet\client\node_modules\node-sass',       
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'C:\Users\Acer\Downloads\Frndsmeet\client\node_modules\node-sass\build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! Warning: unrecognized setting VCCLCompilerTool/MultiProcessorCompilation
npm ERR! Warning: unrecognized setting VCCLCompilerTool/MultiProcessorCompilation
npm ERR! Warning: unrecognized setting VCCLCompilerTool/MultiProcessorCompilation
npm ERR! Warning: unrecognized setting VCCLCompilerTool/MultiProcessorCompilation
npm ERR! gyp verb command build []
npm ERR! gyp verb build type Release
npm ERR! gyp verb architecture ia32
npm ERR! gyp verb node dev dir C:UsersAcer.node-gyp16.14.0
npm ERR! gyp verb found first Solution file build/binding.sln
npm ERR! gyp verb could not find "msbuild.exe" in PATH - finding location in registry 
npm ERR! gyp info spawn C:WindowsMicrosoft.NETFrameworkv4.0.30319msbuild.exe
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   'build/binding.sln',
npm ERR! gyp info spawn args   '/nologo',
npm ERR! gyp info spawn args   '/p:Configuration=Release;Platform=Win32'
npm ERR! gyp info spawn args ]
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `C:WindowsMicrosoft.NETFrameworkv4.0.30319msbuild.exe` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onExit (C:UsersAcerDownloadsFrndsmeetclientnode_modulesnode-gyplibbuild.js:262:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:520:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
npm ERR! gyp ERR! System Windows_NT 10.0.19043
npm ERR! gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\Acer\Downloads\Frndsmeet\client\node_modules\node-gyp\bin\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="    
npm ERR! gyp ERR! cwd C:UsersAcerDownloadsFrndsmeetclientnode_modulesnode-sass
npm ERR! gyp ERR! node -v v16.14.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! Build failed with error code: 1

npm ERR! A complete log of this run can be found in:
npm ERR!     C:UsersAcerAppDataLocalnpm-cache_logs2022-06-25T00_38_11_826Z-debug-0.log

   

Find same objects in array by name and sum working hours Angular

I need a help for this example. Well, as you can see on picture, I have one array with so many objects. Some of this objects have same names. For example, we have name Abhay Singh 166 times. I need to find a solution, how I can find a same objects by name and sum working hours(hours between StarTimeUtc and EndTimeUtc).
Response

Btw, I calculated hours between StarTimeUtc and EndTimeUtc and here is the code:

    const a = new Date(startDate);
    const b = new Date(endDate);
    let difference = Math.abs(b.getTime() / 1000 - a.getTime() / 1000);
    return Math.round(difference / 60 / 60);
  }

So my table now looks like this:
table

As you can see, I have multiple same names and I need to sum total time in month for every user.

Thank you.

I can not to get the POST value from ajax

I would like to get the value from ajax with post in php, but this is not working, here is my code:

<script type="text/javascript">
    function deletarPerson(id_person) {
        let pag = "<?php echo plugin_dir_url(__DIR__) . 'admin/'; ?>";
        jQuery.ajax({
            url: pag + "/config.php",
            method: "post",
            data: {
                id_person: id_person
            },
            dataType: "html",
            success: function(result) {
                <?php
                    $aux = $_POST['id_person'];
                ?>
                alert('<?php echo $aux ?>')
            },
        })
    }
</script>

Someone can help me?

MUI multiselect chip select same data from two array base on id’s?

<Select
      value={value ? value : personName}
      labelId="demo-multiple-chip-label"
      id="demo-multiple-chip"
      multiple
      name="mis"
      onChange={handleChange}
      input={<OutlinedInput id="select-multiple-chip" label="Chip" />}
      renderValue={(selected) => (
        <Box sx={{ display: "flex", flexWrap: "wrap", gap: 0.5 }}>
          {selected.map((value) => (
            <Chip key={value} label={value} />
          ))}
        </Box>
      )}
      MenuProps={MenuProps}
    >
      {names.map((name) => (
        <MenuItem
          key={name}
          value={name}
          style={getStyles(name, personName, theme)}
        >
          {name}
        </MenuItem>
      ))}
    </Select>

I have two arrays, what I want, I want to select all the objects that are same by id’s.
Thanks for helping in advance….

Jest – absolute import in test file for tsx file is not working

I have a SearchBox component in the project.

SearchBox.tsx

import React from "react";

import IconButton from "@mui/material/IconButton";
import InputBase from "@mui/material/InputBase";
import Paper from "@mui/material/Paper";
import SearchIcon from "@mui/icons-material/Search";

function SearchBox() {
  return (
    <Paper
      component="form"
      sx={{ p: "2px 4px", display: "flex", alignItems: "center", width: 400 }}
    >
      <IconButton sx={{ p: "10px" }} aria-label="search">
        <SearchIcon />
      </IconButton>
      <InputBase
        sx={{ ml: 1, flex: 1 }}
        placeholder="Search or start new chat"
        inputProps={{ "aria-label": "search or start new chat" }}
      />
    </Paper>
  );
}

export default SearchBox;

I’ve tried to import the component in the SearchBox.test.ts.

import Searchbox from "src/components/SearchBox" 

describe('first', () => { 
    it('', () => {...})
})

it just gives me an error. Seem like the absolute import is not working, but I’m not sure if it is Jest problem.

Cannot find module 'src/components/Searchbox' or its corresponding type declarations

jest.config.ts

export default {
  roots: ["<rootDir>/src"],
  moduleFileExtensions: ["js", "ts", "tsx"],
  moduleDirectories: ["node_modules", "src"],
  moduleNameMapper: {
    "src/(.*)": "<rootDir>/src/$1",
  },
};

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "preserve"
  },
  "include": [
    "src"
  ],
  "extends": "./tsconfig.paths.json"
}

tsconfig.path.json

{
  "compilerOptions": {
    "baseUrl": "src",
    "paths": {
      "src/*": ["*"]
    }
  }
}

Change Blur events with javascript event delegation

I have a form that is dynamically added to the DOM and therefore I have to use event delegation.

I can not get this to fire and it looks to me like this event can only be attached to an input element

['change', 'blur'].forEach(event => {
  document.addEventListener(event, e => {
    if (e.target.closest('.dynamic-modal form input')) {
      const $input = e.target.closest('.dynamic-modal form input')
      console.log($input)
      // never logs on change and blur
    }

  })
})

How can I go about solving this?