I have a problem with colorbox in wordpress

I have a problem loading the javascript library in wordpress with avada, I add the header but it doesn’t load the file, I tried installing the colorbox plugin but it does not allow me to use the colorbox function, the error that appears is: Uncaught TypeError: jQuery.colorbox is not a function, I really appreciate the solution

Collapse objects in array based on id and calculate new properties in javascript

Here’s a sample of a very particular dataset I am working on. I have an array of objects in the following format:

const input = [
  {year: "2010", country_id: "01", country: "India", region: "North", category: "a", value: "10", population: "100"},
  {year: "2010", country_id: "01", country: "India", region: "South", category: "a", value: "10", population: "100"},
  {year: "2010", country_id: "01", country: "India", region: "North", category: "b", value: "10", population: "100"},
  {year: "2010", country_id: "01", country: "India", region: "North", category: "c", value: "10", population: "100"},
  {year: "2015", country_id: "01", country: "India", region: "South", category: "a", value: "10", population: "100"},
  {year: "2015", country_id: "01", country: "India", region: "South", category: "a", value: "10", population: "100"},
  {year: "2015", country_id: "01", country: "India", region: "North", category: "b", value: "10", population: "100"},
  {year: "2015", country_id: "01", country: "India", region: "North", category: "c", value: "10", population: "100"},
  {year: "2015", country_id: "01", country: "India", region: "East", category: "c", value: "10", population: "100"},
  {year: "2015", country_id: "02", country: "Turkey", region: "North", category: "a", value: "15", population: "25"},
  {year: "2015", country_id: "02", country: "Turkey", region: "North", category: "b", value: "5", population: "25"}
]

How can I collapse the objects in the array based on year and id and create a, b, c and total_population new properties in output based on the data in category, value and population from input?

One thing to note is that a, b and c are cumulative sums and total_population is a cumulative sum based on region. This means that population values are duplicated i some cases (i.e.: there are three entries in country “India” and region “North” that should total 100 and not 300.)

const output = [
  {year: "2010", id: "01", country: "India", a: 20, b: 10, c: 10, total_population: 200},
  {year: "2015", id: "01", country: "India", a: 10, b: 10, c: 20, population: 300},
  {year: "2015", id: "02", country: "Turkey", a: 15, b: 5, population: 25}
]

My best attempt follows. Unfortunately I am constantly getting NaN when trying to execute the cumulative sum. Also, it seems that this solution does not perform well when testing it in a larger dataset.

const years = [...new Set(input.map((d) => d.year))].sort()

const country_ids = [...new Set(input.map((d) => d.country_id))].sort()

const combined_ids = {
  let array = [];

  country_ids.forEach((y, i) => {
    years.forEach((m) => {
      let obj = {};
      obj["year"] = m;
      obj["country_id"] = y;
      obj["combined_id"] = m + "-" + y;
      array.push(obj);
    });
  });

  return array;
}

const output = combined_ids.map((y, i) => {
  input.map((m) => {
    if (y.combined_id === m.year + "-" + m.country_id) {
      y.country_id = m.country_id;

      y[m.category] += !m.category
       ? 0
       : m.value === NaN
       ? 0
       : m.value === null
       ? 0
       : m.value === undefined
       ? 0
       : m.category === undefined
       ? 0
       : +m.value;

      y["total_population"] += +m.population;
      }
  });
  return y;
});

Force HTML -page reload from server application

I have python based CGI application on my server. It reads json file and generates an HTML page for the browser. But if json file is updated the HTML page should be reloaded.

Can any external code on the server somehow force HTML page reload? So that is open in the user’s browser.

Any ideas on how to solve this? It feels stupid code like “reload this HTML every X seconds”. What other opportunities do I have?

Move button when clicked

How do I move the button from the div with id of two to the div with id of one when I click the button?

<div id="one">

</div>

<div id="two">
  <button onclick="moveMe"></button>
</div>
function moveMe() {
 // ??
}

load script after everything else is fully loaded jquery

I have bing ads uet tag and i pasted it in between the tags, as suggested, the code should trigger only once, on every page load, but I have lots of other scripts (i’m using wordpress and jquery), and the tag is triggered twice.

I even tried using it like this, in hope the script will load after everything else is fully loaded, but still no luck:

jQuery(document).ready(function ($) {

    $(window).bind("load", function () {
        (function(w,d,t,r,u)
        {
            var f,n,i;
            w[u]=w[u]||[],f=function()
            {
                var o={ti:"123456789"};
                o.q=w[u],w[u]=new UET(o),w[u].push("pageLoad")
            },
            n=d.createElement(t),n.src=r,n.async=1,n.onload=n.onreadystatechange=function()
            {
                var s=this.readyState;
                s&&s!=="loaded"&&s!=="complete"||(f(),n.onload=n.onreadystatechange=null)
            },
            i=d.getElementsByTagName(t)[0],i.parentNode.insertBefore(n,i)
        })
        (window,document,"script","//something.something.com/something.js","uetq");
    });
}); 

is there any way to force this script to load after everything else, maybe to put a timer, or something, would that be a good idea?

Function validates all fields, even if they are empty/not active

So I am working on a pure Javascript validation and I have some questions about its performance of it. How it works, the function runs the validation function when a “blur” event happens, however, during debugging, I see that all 3 fields are being validated (or at least I think that is what happening) shown in the picture below:debugger info

So, now I am thinking, is there a way to adjust the code, so that when the “blur” event happens, only 1 field is being validated and invoked? Or am I misunderstanding the way it should work?

The validation code is here below:

const mailValidPattern = new RegExp(/^[w-]+@([w-]+.)+[w-]{2,4}$/);
const passValidPattern = new RegExp(/(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{8,}/);

function isValidLength(minAllowedLength, maxAllowedLength, inputElement) {
    return inputElement >= minAllowedLength && inputElement <= maxAllowedLength;
}

const formInputs = document.querySelectorAll(".form__input");

formInputs.forEach(inputElement => {
    inputElement.addEventListener("blur", e => {
        e.target.classList.remove("form__input--error")
        e.target.parentElement.querySelector(".form__input-error-message").textContent = " ";
        const targetId = e.target.id
        const validationMap = {
            signupEmail: () => {
                const targetValue = e.target.value;
                const isValidEmail = targetValue.match(mailValidPattern);
                const emailValidationText = "Invalid email format!";
                const validLength = !isValidLength(6, 50, e.target.value.length);
                !isValidEmail && validLength && inputErrorToggle(inputElement, emailValidationText)
            },

            signupUsername: () => {
                const validLength = isValidLength(8, 50, e.target.value.length);
                const userNameValidationText = "Username must be at least 8 characters!"
                !validLength && inputErrorToggle(e.target, userNameValidationText)
            },

            signupPassword: () => {
                const targetValue = e.target.value;
                const isValidPassword = !!targetValue.match(passValidPattern);
                const passwordValidationText = "Password must be at least 8 characters, including 1 uppercase letter and a number!"
                !isValidPassword  && inputErrorToggle(inputElement, passwordValidationText)
            }
        }
        
        validationMap[targetId]();

    })
});

If needed, I will provide the whole code in a codepen

Need to compare contents of word template & actual PDF

I have 2 files (word & pdf) and need to compare them. word doc will be template which defines how pdf should be generated. Below are the samples.

Word doc:

    <firstname>,<LastName>
    <ID>,<organization>
    <salary>,<place>
    
    Dear <firstname>,
    you are working in the department of <organization> and we are really honored to have you here. Expecting many more successful years of service from you.
    Thanks,

Actual PDF:

    John, Kennedy
    234,google
    USD1245,CA
    
    Dear John,
    you are working in the department of google and we are really honored to have you here. Expecting many more successful years of service from you.
    Thanks,

Can someone help with the comparison logic to validate both the static and dynamic content are getting generated as expected??
we are using TestComplete with JavaScript for the automation.

I have an if whose value is false and the code executes

if (welcome_enabled == true && welcome) {
  await sql.query(`UPDATE `welcome` SET channelid = ${welcome.id} WHERE guildid = ${guild.id};`, async function(update_error) {
    if (update_error) console.log(update_error);
  });
} else if (welcome_enabled == false) {
  await sql.query(`DELETE FROM `leave` WHERE guildid = ${guild.id};`, async function(update_error) {
    if (update_error) console.log(update_error);
  });
}
welcome_enabled == true && welcome == false

and the update query still execute like normal

How do I get a variable to dislay hello world on the home page when a subpage is loaded?

I am creating a website using google sites.The website consists of a main page and a couple of subpages.
I want the code to display ‘hello world’ on the main page when a specific subpage is loaded.
I have embedded the code bellow on the main page.
google shows the error message google.sites.com refused to connect

Thank you in advance. Any tip or advice helps.the code i entered

Filtered array returns as ‘undefined’ in a Leaflet popup

array = [{"shop":"Big Store", "name":"Green Bag"},
         {"shop":"Long Store", "name":"Red Shoes"},
         {"shop":"Big Store", "name":"White Tree"}]

To filter it, I made this function

function filterByShop(array, key, String) {
  return array.filter((obj) => obj[key] == String)
};

If I do alert(JSON.stringify(filterByShop(array, "shop", "Big Store"))), it returns the array minus the Long Store item.

However, if I attach the filtered array to a Leaflet popup via this function, it returns as undefined

function shopsPopup(feature, json){
  json.bindPopup(feature.properties.shop + "</br>" +
                 feature.properties.name + "</br>" +
                 JSON.stringify(filterByShop(array, "shop", feature.properties.shop)))
}

enter image description here

Add 1 to specific number javascript

I need to add 00000046 +1 to this number but 0 must be kept.

Example: 00000046 + 1 = 00000047 and if 100 were reached it would be a number in the form with only five zeros before 00000100 etc.

Is there any method for these types of numbers or how to solve this thank you for your advice

TypeError: [] is not a function

I am making a Discord bot command handler, and I keep getting this error:

(await PG(`${process.cwd()}/Commands/*/*js`)).map(async (file) => {
    ^

TypeError: [] is not a function

Here is my code:

const { Perms } = require('../Validation/Permissions');
const { Client } = require('discord.js')
const { promisify } = require("util")
const { glob } = require('glob');
const PG = promisify(glob)
const Ascii = require('ascii-table')

/** 
 * @param {Client} client
*/

module.exports = async (client) => {
    const Table = new Ascii('Command Loaded')

    CommandsArray = []

    (await PG(`${process.cwd()}/Commands/*/*js`)).map(async (file) => {
        const command = require(file);

        if (!command.name)
        return Table.addRow(file.split("/")[7], 'FAILED', 'Missing a name.')

        if (!command.description)
        return Table.addRow(command.name, 'FAILED', 'Missing the description.')

        if (command.permission) {
            if (Perms.includes(command.permission))
            command.defaultPermission = false;
            else
            return Table.addRow(command.name,'FAILED','Permission is invalid')
        }

        client.commands.set(command.name, command);
        CommandsArray.push(command);

        await Table.addRow(command.name, 'SUCCESSFUL');
    })

    console.log(Table.toString())

    // Permissions check //

    client.on('ready', async() => {
        const MainGuild = await client.guilds.cache.get('940180806696058910');

        MainGuild.commands.set(CommandsArray).then(async (command) => {
            const Roles = (commandName) => {
                const cmdPerms = CommandsArray.find((c) => c.name === commandName).permission
                if (!cmdPerms) return null;

                return MainGuild.roles.cache.filter((r) => r.permissions.has(cmdPerms))
            }

            const fullPermissions = command.reduce((accumulator, r) => {
                const roles = Roles(r.name);
                if (!roles) return accumulator;

                const permissions = roles.reduce((a, r) => {
                    return [...a,{id: r.id, type: 'ROLE', permission: true}]
                }, [])

                return [...accumulator, {id: r.id, permissions}]
            }, [])

            await MainGuild.commands.permissions.set({ fullPermissions });

        })

    })
}

I’ve done some googling, but I was unable to find anything related to just [], type error usually appears when there is a spelling mistake in your code. I have gone through my code numerous times and have been completely unable to find any mistakes, I just cannot figure this out.
I would really appreciate some help, thank you!

how to get special character from string in nodejs and replace

how to find specific special character from string and replace it to unicode u0026 + = u002B

replace only these special character : [$, &, +, #]

example : “HELLO JAMES (WITH ME YOUR) n+++ SEE & FIELD 4-B +++

MY code

 var char = '+';      
          var saa =char.charCodeAt(0);
          console.log(saa)
          var codeHex = saa.toString(16).toUpperCase();
          while (codeHex.length < 4) {
            codeHex = "0" + codeHex;
        }    
        var afteruni = name.replaceAll('+','\u'+codeHex) 

i want like this :

“HELLO JAMES (WITH ME YOUR) nu002Bu002Bu002B SEE u0026 FIELD 4-B
u002Bu002Bu002B”

ERROR : Invalid regular expression: /+/: Nothing to repeat