I am trying to upgrade a bootstrap library from 3.37 to 4.6.2 in dojo framework but getting an error when I run the project

I am trying to upgrade a bootstrap library from 3.37 to 4.6.2 in dojo framework but getting an error when I run the project as shown in in this image popper.js error image.

If I include popper.js file in the project I would get the error as shown here multipleDefine error

could anyone please suggest how to resolve this??

I have replaced bootstrap 4.6.2 files under JavaScript library and added popper.js file externally.

Expectation – to resolve the error I am getting at the moment not able to understand the root cause.

calling a function inside a parent by detecting a call in the child in react

I need to call a function inside a dropdown on clicking on a children which is a datepicker library

<dropdownParent>
<datepicker
onChange={()=> childFunction()}
>
</datepicker>
</dropdownParent>

in dropdownParent there is a toggle function which i need to call when this child function is called and I tried callback and other method but since its a library i am confused on hoe to detect the chnage and pass it in parent to invoke parent function

How to unlock pdf buffer array in NodeJS?

I have tried using pdf-lib but could not find any unlock functionality with the library. I also tried with qpdf command using spawn child process but even it was not helpful. Can anyone please help me on this one ?

const qpdfProcess = spawn('qpdf', ['--password=401000056762', '--decrypt', '-', '-']); qpdfProcess.stdin.write(pdfBuffer) const decryptedPdf = qpdfProcess.stdout()

Moment.Js – InvalidDate for Thai date format

I am using momentJs and creating date objects with it to perform validation if given date value is matching with locale and format or not.

When I create object with Moment() it gives Invalid Date.

Below is the sample code same as I am using in my application.

const dateStr = "วันศุกร์ที่ 30 มิถุนายน พ.ศ. 2566";
const formatStr = "ddddที่ d MMMM G yyyy";
const someday = moment(dateStr, formatStr, "th");
console.log(someday);

Output – Invalid Date

_d: Invalid Date {}_
f: "ddddที่ d MMMM G yyyy"_
i: "วันศุกร์ที่ 30 มิถุนายน พ.ศ. 566"
_isAMomentObject: true
_isUTC: false
_isValid: false
_l: "th"
    

Any help would be appreciated.

how to use data of fetcher function in onSuccess function in useMutation in react-query?

I want to use ProcessedData which is automatically passed by react-query into the onSucess function.

Following is my function structure.

useAddProduct function

export const useAddProduct = (prodData) => {
  console.log(prodData);
  const queryClient = useQueryClient();
  return useMutation(addProduct, {
    onSuccess: (data) => {
      console.log(data);
      queryClient.setQueryData("Food-Data", (oldData) => {
        console.log(oldData);
        return {
          ...oldData,
          data: [...oldData.data, data.data],
        };
      });
    },
  });
};

addProduct function

const addProduct = (processedData) => {
  return axios.post("http://localhost:5050/AddProduct", processedData);
};

And this is how I send data from the component.

const data = {
        prodId: id, 
        prodName: textFieldData
      }
      mutateProduct(data);

I want to use processedData in the onSuccess Function so that I don’t depend on the data that comes as a response from my backend.

I have tried to log the prodData but it shows undefined. How can I included the ProcessedData in the useAddProduct function as it is passed automatically by react-query.

TypeError: learnerResult.replace is not a function

Your code could not be executed. Error:TypeError: learnerResult.replace is not a function
at courseraRunTestCase (/home/coder/project/autograde/grader.js:24:106)
at courseraRunTestCases (/home/coder/project/autograde/grader.js:45:5)
at Object.<anonymous> (/home/coder/project/autograde/grader.js:165:5)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
at internal/main/run_main_module.js:17:47

Code:

    const dishData = [
      { name: "Italian pasta"         , price:  9.55 },
      { name: "Rice with veggies"     , price:  8.65 }, 
      { name: "Chicken with potatoes" , price: 15.55 },
      { name: "Vegetarian Pizza"      , price:  6.45 }
    ];
    const tax = 1.20; // +20%

    const isBoolean = (v) => (typeof v === 'boolean') || (v instanceof Boolean);

    const getPrices = (applyTax = true) => {
      if (!isBoolean(applyTax)) {
        console.log('You need to pass a boolean to the getPrices call!');
        return; // Exit...
      }
      for (const { name, price } of dishData) {
        const finalPrice = applyTax ? price * tax : price;
        console.log(`Dish: ${name} Price $${finalPrice}`);
      }
    }

    const getDiscount = (guests = 1, applyTax = true) => {
      if (guests < 1 || guests > 29) {
        console.log('The number of guests must be between 1 to 29');
        return; // Exit...
      }
      getPrices(applyTax);
      const discount = guests < 5 ? 5 : 10;
      console.log(`Discount is: $` + discount);
    }

    getDiscount(2);
    getDiscount(10, false);`

Expected Results :
Dish: Italian pastaPrice: $11.46
Dish: Rice with veggiesPrice: $10.38
Dish: Chicken with potatoesPrice: $18.66
Dish: Vegetarian PizzaPrice: $7.74
Discount is:$5
Dish: Italian pastaPrice: $9.55
Dish: Rice with veggiesPrice: $8.65
Dish: Chicken with potatoesPrice: $15.55
Dish: Vegetarian PizzaPrice: $6.45
Discount is:$10

No Cookie Name is shown when I set an array/object as cookie [duplicate]

I am running into a small problem. I am trying to store some values in cookies using JavaScript so that later I can call and use them in PHP variables. But unfortunately, when I check for cookie name, it appears as blank. This is how I am setting cookie.

<script>
cook = {name: "john",email:"[email protected]"};      
mycook = JSON.stringify(cook); 
document.cookie = mycook;
</script>

This is how it appears in inspect elements.

No Cookie name

To call the values in PHP, I used following codes but none of them work. I just get undefined array key error message. I used 2 variations to see which of them works to echo the cookie elements but none of them works

<?php
if(isset($_COOKIE)){
  echo $_COOKIE['mycook.name'];
  echo '<br>';
  echo $_COOKIE['mycook->email'];  
}
?> 

Game generator – team can’t play twice in the same round

I’m still learning JS and i’m trying to do this game generator. But I still have a problem, the same team cannot play twice in the same round. I aprecciate if someone could help me. Thanks!

This code is asking for user to select how many teams are going to play and then asking the name of the teams



const btn = document.querySelector('#submitbtn')
const section = document.querySelector('#containertimes')

btn.addEventListener("click", function(event){
    event.preventDefault()

    const numTimes = parseInt (document.querySelector('#js-input-times').value)

    section.innerHTML = ''
    for(let i = 1; i <= numTimes; i++){
        const input = document.createElement("input")
        input.type = "text"
        input.id = "nome-time"
        input.name = "time-" + i
        input.placeholder = "Nome do time " + i
        input.required = true
        section.appendChild(input)
    }

    const submitButton = document.createElement("button")
    submitButton.type = "submit"
    submitButton.innerText = "Gerar Jogos"
    submitButton.addEventListener('click', gerarJogos)
    section.appendChild(submitButton)
})

function shuffle(array) {
    let currentIndex = array.length, randomIndex;
    while (currentIndex != 0) {
        randomIndex = Math.floor(Math.random() * currentIndex);
        currentIndex--;
        [array[currentIndex], array[randomIndex]] = [
            array[randomIndex], array[currentIndex]];
    }
    return array;
}

function gerarJogos() {
    const nomeTime = document.querySelectorAll("[name^='time-']")

    let jogosPorRodada = []
    for (let i = 0; i < nomeTime.length; i++) {
        for (let j = i + 1; j < nomeTime.length; j++) {
            jogosPorRodada[i] = jogosPorRodada[i] || []
            jogosPorRodada[i].push(nomeTime[i].value +' x '+ nomeTime[j].value)
        }
    }

    let jogosEmbaralhados = jogosPorRodada.map(function(jogos) {
        return shuffle(jogos)
    })

    let resultado = ''
    for (let i = 0; i < jogosEmbaralhados.length; i++) {
        resultado += 'Rodada ' + (i+1) + '<br>' + jogosEmbaralhados[i].join('<br>') + '<br><br>'
    }

    section.innerHTML = resultado
    
}

AngularJS – Internal Server Error 500 on http PUT request

I am trying to use the following API to change the object in the image.

this.changeAdditionalOption = function(p, groupId) {
        return $http({
            method: 'PUT',
            url: this.apiRequestPrefix + "/api/groups/" + groupId + "/additional-option",
            data: p,
        });
    };

the object

and this is the function I am using. ($scope.enabled is a local variable that is initialized with an getAdditionalOption method. that works fine)

$scope.saveStatus = function() {
                $scope.$emit('progressStart', []);
                var data = {
                  employeeProfile : { enabled : !$scope.enabled}
                };
                HR.changeAdditionalOption(data, vm.dashboard.activeGroup.id).then(
                  function (response) {
                    $scope.enabled = !$scope.enabled;
                    toastr.success('Company Feature Access Updated Successfully!');
                    $scope.$emit('progressEnd', []);
                },
                  function (error) {
                    $rootScope.showErrorHandler(error,error.data);
                    $scope.$emit('progressEnd', []);
                  }
                );
              };

and here is the generated payload for the request.

payload

The payload is correct and the URL of the API is correct. But the request return an Internal Server Error 500. I work in the frontend of this and wanted to know if the problem could be with my code (which is given here). I tried to pass the data as JSON as well but that did not work either.

puppeteer How to get the horizontal/vertical space between two elements?

How to get the horizontal/vertical space between two elements using puppeteer.

Tried using boxModel but it gives just padding/margin of individual elements, the actual element can have totally different representation on the screen.

Is there any way to specify the two selectors add just get spacing between them?
I wanted a distance like this where the items can be not in a parent-child or sibling relation.
enter image description here

How to integrate Quasar UI into Astro SSG

I want to generate static site with Astro generator (https://astro.build/) and I want to use Quasar UI components (https://quasar.dev/) on the site.

I found, I can set Vue app entry point in Astro config (astro.config.mjs):

import {defineConfig} from 'astro/config';
import vue from "@astrojs/vue";

// https://astro.build/config
export default defineConfig({
    integrations: [vue({appEntrypoint: '/src/pages/_app'})]
});

This is my ./src/pages/_app.mjs:

import {Quasar} from "quasar";
export default (app) => {
    app.use(Quasar, {config: {}});
}

I have an error on astro dev:

TypeError: Cannot convert undefined or null to object
    at Function.assign (<anonymous>)
    at installQuasar (/.../astro/node_modules/quasar/dist/quasar.cjs.prod.js:6:15454)
    at Object.install (/.../astro/node_modules/quasar/dist/quasar.cjs.prod.js:6:491344)
    at Object.use (/.../astro/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:4377:28)
    at __vite_ssr_exports__.default (/src/pages/_app.mjs:6:9)
    at Object.renderToStaticMarkup (@astrojs/vue/server.js:22:30)
    at renderFrameworkComponent (/node_modules/astro/dist/runtime/server/render/component.js:178:66)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

How can I integrate Quasar UI into Astro SSG?

How to access value of a global variable that got updated in a async function in javascript

well i am new to JavaScript and am trying to update a global variable inside an async function then i call another function (i.e., after the async function is called) to access the global variable but somehow the global variable isn’t updated.

to better explain the problem, see this code.

let a = "";

async function abc() {
   a = "hello";
}

function getA() {
   console.log(a);
}

abc();
getA();

However, when I call it, the value of a remains unchanged

basically in my code i am trying to read a small text from a file and then save it in a variable after which i use another function to process that text and get output.

Please help !!

Earlier i was using the async function to return the text instead of updating the global variable in that case some sort of promise used to come up and when i tried to console.log() it was fine it said promise fulfilled but when i used to access it. It said undefined.

How can I integrate AdSense into my Docusaurus project for monetization?

I’m working on a Docusaurus project hosted on GitHub at https://github.com/Ajay-Dhangar/CodeMastermindHQ. I want to integrate Google AdSense into my website to monetize it. However, I’m facing issues with the integration and need some help.

I have signed up for an AdSense account and received my ad code from Google. I have also reviewed the AdSense documentation, but I’m not sure where and how to add the AdSense code in my Docusaurus project to display ads on my website. I have tried a few approaches, but none of them seem to work as expected.

Here’s what I have tried so far:

  • Adding the AdSense code directly in my Markdown files
  • Adding the AdSense code in the Docusaurus configuration file
  • Embedding the AdSense code in my custom theme

However, the ads are not showing up on my website as expected. I was expecting to see ads displayed on my website after integrating AdSense.

I would appreciate any guidance or sample code that can help me successfully integrate AdSense in my Docusaurus project. Thank you in advance for your assistance!

Adding attributes to socket connection

I’m building a simple Node.js and socket.io project. I want to save the client’s username as an attribute so I could delete their name if they quit.

io.on('connection', (socket) => {
    console.log('a user connected');

    // grabs all the connected users
    io.emit('update users', Array.from(connectedUsers));
  
    socket.on('join game', (username) => {
        console.log(username + ' joined the game');
        connectedUsers.add(username);
        // applies their name to the socket
        socket.data.username = username;
    
        io.emit('update users', Array.from(connectedUsers));
    
        socket.emit('redirect', '/game');
    });

    socket.on('leave game', () => {
        console.log(socket.data.username + ' left the game');
        connectedUsers.delete(socket.data.username);
    
        io.emit('update users', Array.from(connectedUsers));
    });

});

This is my current server logic, I try adding a username attribute on the join game topic, and try to call it in the leave game topic. The issue is it always returns undefined.

ReactJS: Extract values from Array of Objects?

After some processing, I get an array of objects similar to this:

0: {key: 1}
1: {key: 0}
2: {key: 1}

I want to extract the values from each object and check to see if a specific value exists among the resulting list of values, for example checking for 0. Can anyone describe how to get all the values into a single list?