How to pass a variable from Node.js to JavaScript?

I want to pass a variable from Node.js to the internal JavaScript that is inside “flashcards”, I am trying to use EJS to pass the array “cardNames”

Server side:

app.get("/apps/flashcards", (req, res) => {
    res.render("flashcards", { cardNames: ["card1", "card2", "card3", "card4"] });
})

In my “flashcards” EJS file I have four span elements, all of which have the same class (“my-cards”). I want to change their textContent as shown below:

Client side (flashcards file):

<script>
const cardNames = <% cardNames %>
const cards= document.querySelectorAll(".my-cards");
for (let i = 0; i < cards.length; i++) {
    cards[i].textContent = cardNames[i] + ", Score: 0";
}
</script>

I get an error: “Uncaught SyntaxError: Unexpected token ‘const'”
How can I send a file from Node.js to the internal or even external JavaScript? The logic MUST be separate from the html elements so it doesn’t get confusing.
It doesn’t have to be EJS, I’m willing to use other methods as long as I can achieve results.

jqGrid filterToolbar Searching not excluding hidden columns

I am using jqGrid [3.7.1] and on that using below code to hide some columns

jQuery("#gridId").jqGrid('hideCol', ["Col5", "Col7", "Col9"]);

And we also have filterToolbar applied but when we are executing search , I can see that it’s searching on different/hidden columns.

On inspecting I can see that TH under TR with class ui-jqgrid-labels for hidden columns display: none; style attribute gets added.

But for same column TH under TR with class ui-search-toolbar noting gets added and resulting in

<td role="columnheader" class="ui-state-default ui-th-column ui-th-ltr">
  <div style="width:100%;position:relative;height:100%;padding-right:0.3em;">
  <input type="text" style="width:100%;padding:0px;" name="Id" id="**gs_Col5**" value="" spellcheck="false">
  </div>
</td>

Where actual column header under Col6 and Col5 is hidden.

Any idea how to resolve it?

how to setup desandro masonry to auto arrange element width to fit content?

I have a nested dinamic grids page that i want to layout as best as possible

as suggested in CSS-only masonry layout i imported desandro masonry and try to use it but it does not manage well horizontal and vertical completly dynamic size.

i don’t have any information about elements number or size, iam looking to a way to make them spread on page using well available space.

as you can see, firts sub-grid does not increase in width to use less vertical space

the same for all columns: width is simply the minimum to keep content, it does not try to recuce rows

if you setup .grid-item to be display: flex; every item width become the sum of all elements, without trying to increase height to better fill content

is it possibile to setup library to achieve better result or there are alternative libraries to manage that dynamic layout?

thanks

* { box-sizing: border-box; }


/* ---- grid-item ---- */

.grid-item {

  background: #D26;
  border: 2px solid #333;
  border-color: hsla(0, 0%, 0%, 0.5);
  border-radius: 5px;
}
<script src="https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js"></script>

<h1>Masonry - Initialize in HTML</h1>

<div class="grid" data-masonry='{ "itemSelector": ".grid-item" }'>
  <div class="grid-item">
    <div class="grid" data-masonry='{ "itemSelector": ".grid-item" }'>
      <div class="grid-item">
        tre
      </div>
      <div class="grid-item">
        tre
      </div>
       <div class="grid-item">
        tre
      </div>
       <div class="grid-item">
        tre
      </div>
       <div class="grid-item">
        tre
      </div>
       <div class="grid-item">
        tre
      </div>
     </div>
  </div>
  <div class="grid-item">
    <p>casa</p>
    <p>casa</p>
  </div>
  <div class="grid-item">
    <p>casacasacasacasacasacasa</p>
    <p>casa</p>
    <p>casa</p>
    <p>casa</p>
    <p>casa</p>
    <p>casa</p><p>casa</p>
  </div>
  <div class="grid-item">
    <p>casacasacasacasacasacasa</p>
    <p>casa</p>
    <p>casa</p>
    <p>casa</p>
    <p>casa</p>
    <p>casa</p><p>casa</p>
  </div>
  <div class="grid-item">
    <p>casa</p>
    <p>casa</p>
  </div>
  <div class="grid-item">
    <p>casa</p>
    <p>casa</p>
  </div>
  <div class="grid-item">
    <p>casacasacasacasacasacasacasacasacasacasacasacasacasacasacasa</p>
    <p>casa</p>
  </div>
  <div class="grid-item">
     <p>casacasacasacasacasacasacasacasacasacasacasacasacasacasacasa</p>
    <p>casa</p>
  </div>
  <div class="grid-item">
     <p>casacasacasacasacasacasacasacasacasacasacasacasacasacasacasa</p>
    <p>casa</p>
  </div>
  <div class="grid-item">
     <p>casa</p>
    <p>casa</p>
  </div>
  <div class="grid-item">
     <p>casa</p>
    <p>casa</p>
  </div>
  <div class="grid-item">
     <p>casacasacasacasacasacasa</p>
    <p>casa</p>
    <p>casa</p>
    <p>casa</p>
    <p>casa</p>
    <p>casa</p><p>casa</p>
  </div>
  <div class="grid-item">
     <p>casacasacasacasacasacasa</p>
    <p>casa</p>

    <p>casa</p>
    <p>casa</p><p>casa</p>
  </div>
  <div class="grid-item">
    <p>casa</p>
    <p>casa</p><p>casa</p>
  </div>
  <div class="grid-item">
    <p>casa</p>
    <p>casa</p><p>casa</p>
  </div>

</div>

Particle js is not loading

I am currently working on a personal react project that involves particle.js, which is a library for creating interactive backgrounds. However, as I am watching some Udemy videos to learn how to use it, I encounter a problem: it’s not showing any particles on my screen.

App.js

import './App.css';
import { Routes, Route, useLocation } from 'react-router-dom'
import Particles from 'react-tsparticles';
import { loadFull } from 'tsparticles';
import Home from './containers/home';
import About from './containers/about';
import Skills from './containers/skills';
import Resume from './containers/resume';
import Portfolio from './containers/portfolio';
import Contact from './containers/contact';
import Navbar from './components/navBar';
import particlesConfig from "./helpers/particlesConfig";


function App() {

    const particlesInit = async (main) => {
        await loadFull(main);
    };

    const location = useLocation();
    const renderParticleJsIfCurrentPageIsHomePage = location.pathname === "/";

    return (
        <div className="App">
            {renderParticleJsIfCurrentPageIsHomePage && (
                <Particles
                    id="particles"
                    options={particlesConfig}
                    init={particlesInit}
                />
            )}

            <Navbar />

            <Routes>
                <Route path='/' index element={<Home />} />
                <Route path='/about' element={<About />} />
                <Route path='/skills' element={<Skills />} />
                <Route path='/resume' element={<Resume />} />
                <Route path='/portfolio' element={<Portfolio />} />
                <Route path='/contact' element={<Contact />} />
            </Routes>
        </div>
    );
}

export default App;

particlesConfig.js

export default {
    background: {
      color: {
        value: "#1d1d1d",
      },
    },
    fpsLimit: 120,
    interactivity: {
      events: {
        onClick: {
          enable: true,
          mode: "push",
        },
        onHover: {
          enable: true,
          mode: "repulse",
        },
        resize: true,
      },
      modes: {
        push: {
          quantity: 4,
        },
        repulse: {
          distance: 200,
          duration: 0.4,
        },
      },
    },
    particles: {
      color: {
        value: "red",
      },
      links: {
        color: "#ffffff",
        distance: 150,
        enable: true,
        opacity: 0.5,
        width: 1,
      },
      collisions: {
        enable: true,
      },
      move: {
        direction: "none",
        enable: true,
        outModes: {
          default: "bounce",
        },
        random: false,
        speed: 6,
        straight: false,
      },
      number: {
        density: {
          enable: true,
          area: 800,
        },
        value: 80,
      },
      opacity: {
        value: 0.5,
      },
      shape: {
        type: "circle",
      },
      size: {
        value: { min: 1, max: 5 },
      },
    },
    detectRetina: true,
  };

I installed
npm packages but it didn’t help.

How do i incorporate number counting to my website i.e, how many people have actually used the product I offer. Please what is the JavaScript code?

I want to scroll to that section before the numbers start counting but I keep getting a bunch load of error messages

I tried:

Let valueDisplays = document.querySelectorAll(.num);
Let interval = 5000;

valueDisplay.forEach((valueDisplays) => {
    Let startValue = 0;
    Let endValue = parseInt(valueDisplays.getAttribute("data-val"))
    Let count = set interval(function () {
        startValue += 1;
        valueDisplays.textContent = startValue;
        if (startValue == endValue) {
            clear interval(count);
        }
    }, Duration)
})

repeat transfer learning on tensorflowjs

I want to continuously save one model through transfer learning and re-learn the once-learned model.

I’m currently using TensorFlowJS(browser), is there any way?

model.save
model = tf.loadLayersModel
Relearning was attempted by utilizing it, but the previous transfer learning content disappears and a new transfer learning proceeds.

How to drag a div with multiples div into another div with n divs and take the coordinates of the div occupied- Javascript

I am implementing the battleship game in JavaScript, and I would like the user to be able to drag their own ships within a 10 x 10 grid, consisting of 100 cells, each corresponding to a pair of coordinates. Once dragged onto the grid, I want to use all the coordinates occupied by the ship to create an object.
This is my HTML with Javascript:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../src/style.css">
   
    <title>Document</title>
</head>
<body>
    <div id="main">
        <div id="deployment-board">

        </div>
        <div id="selection-panel">
            <h1>Drag your ships</h1>
            <div id="ships-dragging-container">
                <div class="dragging-ship" data-length="5" draggable="true">
                    <div></div>
                    <div></div>
                    <div></div>
                    <div></div>
                    <div></div>
                </div>
                <div class="dragging-ship" data-length="4" draggable="true">
                    <div></div>
                    <div></div>
                    <div></div>
                    <div></div>
                </div>
                <div class="dragging-ship" data-length="3" draggable="true">
                    <div></div>
                    <div></div>
                    <div></div>
                </div>
                <div class="dragging-ship" data-length="3" draggable="true">
                    <div></div>
                    <div></div>
                    <div></div>
                </div>
                <div class="dragging-ship" data-length="2" draggable="true">
                    <div></div>
                    <div></div>
                </div>
            </div>
           
            <button id="rotate">Rotate</button>
        </div>
    

    </div>
    <script>
        let rotateBtn=document.getElementById("rotate");
        rotateBtn.addEventListener("click",function(){
            let shipBlock=document.getElementById("ships-dragging-container");
            let shipBlockDirection=window.getComputedStyle(shipBlock).getPropertyValue("flex-direction");
            if(shipBlockDirection =="column"){
                shipBlock.style.flexDirection="row";
                shipBlock.querySelectorAll(".dragging-ship").forEach(ship=>{
                ship.style.width="30px";
                ship.style.flexWrap="wrap";
                ship.style.height="fit-content";
            })}else{
                shipBlock.style.flexDirection="column";
                shipBlock.querySelectorAll(".dragging-ship").forEach(ship=>{
                ship.style.width="";
                ship.style.flexWrap="";
                ship.style.height="";
            })
                
               

            }
        })
        function displayInitialBoard(){
            for (let i = 0; i < 10; i++) {
                for (let j = 0; j < 10; j++) {
                    let cell = document.createElement("div");
                    cell.className = "cell";
                    cell.textContent = i + '' + j;
                    cell.setAttribute("data-coordinates", i + '' + j);
                    document.getElementById("deployment-board").appendChild(cell);
                }
            }
            

        }
        displayInitialBoard();
        let draggingShip=document.querySelectorAll(".dragging-ship");
        for(let ship of draggingShip){
            ship.addEventListener("dragstart",function(){
                console.log("start");
            })
        }
    </script>
</body>
</html>

This is my CSS:

*{
    box-sizing: border-box;
}
body{
    /* display:flex;
    justify-content: space-evenly;
    align-items: center; */
    height: 100vh;
    padding:0;
    margin:0;

}
.cell{
    height:30px;
    width:30px;
    border:1px solid black
}
#main{
    display:flex;
    align-items: center;
    justify-content: space-evenly;
    height:100%;
    
}
#deployment-board{
    display: flex;
    flex-wrap: wrap;
    width:300px;
    height:300px;
    align-items: center;
    justify-content: center;
}
#selection-panel{
    display:flex;
    flex-direction: column;
    height:300px;
    width:300px;
    gap:5px;
}
#selection-panel h1{
    margin-top:0px;
}
.dragging-ship{
    display:flex;
    width:fit-content;
    cursor:grab;
}

.dragging-ship div{
    border:1px solid black;
    height:28px;
    width:28px;
    background-color: pink;
}
#ships-dragging-container{
    display:flex;
    flex: 1;
    flex-direction: column;
    gap:10px;
}

You can run it here:

https://codepen.io/Eligio-Cristantielli/pen/eYQRqxa

Does anyone have any idea on how to implement this in vanilla Javascript?

How to dynamically generate state variables based on the number of objects fetched

I’m currently trying to write React code that will fetch an object from an API and generate components with them. I am currently testing without using a fetch by creating a dummy object. The component I’m currently trying to generate is a checkbox that toggles between a checked and unchecked state. Unfortunately I can’t figure out how to pass a toggle to my checkbox component. Usually I would just define toggles as individual state variables but since I am constrained to not know the size of the object I don’t know how many checkboxes I will render and, thus, how many toggles I’d have to define.

This is the code I have been trying thus far to no avail. It is supposed to add toggles to the state variable “toggles” so that I have a list of booleans as long as my (in the future fetched) objects. Then I would created a checkbox for every object in “objects” and use the index so that each checkbox has a different toggle it can reference and they don’t all check on the same click.

I think potentially there is an issue with addToggle because it doesn’t seem to update anything when I console.log. Its also possible my entire approach is off base. (I also don’t know if my “objects” variable is an object or pair of objects so sorry if my naming convention is off)

const [toggles, setToggles] = useState([]);

const objects = [
    {
        name: "dummy1"
    },
    {
        name: "dummy2",
    }
]

const addToggle = () => {
    setToggles([...toggles, false]);
    console.log(toggles) // output in console: [], []
}
  
useEffect(() => {
    for (var i = 0; i < objects.length; i++){
        addToggle();
    }
}, []);

This is what is what I’m trying to render in the return of my component.

{objects.map((object, index) => 
  <Checkbox toggle={toggles[index]} setToggle={setToggles} name={object.name} />
)}

This is the checkbox component I’m trying to use. (I wanted to avoid using input)

function RankingCheckbox({toggle, setToggle, name}) {
    if (toggle)
        return (
            <li className="dropdownItem" onClick={() => setToggle(!toggle)}>
                <span className="checkbox">
                    <AiOutlineCheck />
                </span>
                <span className="itemText">{name}</span>
            </li>
        );
    return (
        <li className="dropdownItem" onClick={() => setToggle(!toggle)}>
            <span className="checkbox" />
            <span className="itemText">{name}</span>
        </li>
    );
}

Error : NG0204 with no specific details after Angular upgrade from 15 to 16

I have been working on this task to upgrade from angular 15 to 16. After upgrading to 16 I am seeing this Error: NG0204 error in the console on serving my app. No additional information is provided (see image attached)
enter image description here

Any idea what this could be related to?

I have tried debugging but couldn’t understand whats going on here since theres no additional details in the error.

How can I prevent the page from rendering when I use Dispatch?

In the project I developed with React, I want to capture user information and send it to Redux when the page is entered for the first time, but when I issue dispatch after capturing the data, the page enters an infinite loop. How can I prevent this?

export default ProfileDetailView;

This is my Code :

import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { SET_CANDIDATE_PROFILE_DETAILS } from '@/store/modules/candidate';

import CareerGoalSection from '@/components/profilDetail/CareerGoalSection';
import DocumentSection from '@/components/profilDetail/DocumentSection';
import EducationSection from '@/components/profilDetail/EducationSection';
import LanguageSection from '@/components/profilDetail/LanguageSection';
import ProfilCardSection from '@/components/profilDetail/ProfilCardSection';
import ReferencesSection from '@/components/profilDetail/ReferencesSection';
import SkillsSection from '@/components/profilDetail/SkillsSection';
import WorkExperienceSection from '@/components/profilDetail/WorkExperienceSection';
import ProfilDetailLayout from '@/layouts/ProfilDetailLayout';
import { useTranslation } from 'react-i18next';
import { authSelector } from '@/store/modules/auth';
import { candidateService } from '@/services/candidate.service';

interface ProfileDetailViewProps {
  hideNavFooter: boolean;
}

const ProfileDetailView: React.FC<ProfileDetailViewProps> = ({ hideNavFooter }) => {
  const { t } = useTranslation();
  const { decodedToken } = useSelector(authSelector);
  const candidateId = Number(decodedToken?.CandidateId);
  const dispatch = useDispatch();

  const getProfileDetails = async () => {
    try {
      const details = await candidateService.fetchCandidateProfileDetails(candidateId);
      dispatch(SET_CANDIDATE_PROFILE_DETAILS(details));
    } catch (error) {
      console.error('Error fetching profile details:', error);
    }
  };

  useEffect(() => {
    if (candidateId) {
      getProfileDetails();
    }
  }, [candidateId]);
  
  return (
    <ProfilDetailLayout title={t('profileDetails.name')} showNavAndFooter={!hideNavFooter}>
      <ProfilCardSection />
      <CareerGoalSection />
      <WorkExperienceSection/>
      <EducationSection/>
      <LanguageSection/>
      <SkillsSection/>
      <DocumentSection />
      <ReferencesSection />
    </ProfilDetailLayout>
  );
};

How to fill angular textbox in a webview2 with C#

I have a webpage wiht a lot of textbox. I can fill textbox with this code:

webView21.ExecuteScriptAsync($"document.getElementById('txtPerson_FirstName').value='John';");

But this code doesnt work on a textbox. This is textbox source code :

<input class="form-control ng-pristine ng-valid ng-not-empty ng-touched" name="Quantity_Amount" ng-model="line.Quantity_Amount" ng-keyup="totalCalculator(line,line.AllowanceCalculatorType)" style="width:100%" type="number">

How can I fill textbox in C# using webView2. Thanks

TikTok PKCE in Oauth fails

I’m trying a TikTok login with my desktop app, follοwing these instructions.

So the auth url I’m trying is

www.tiktok.com/v2/auth/authorize/?scope=user.info.basic,video.publish&response_type=code&redirect_uri=http://localhost:51697&client_key=...&code_challenge=e7e8b89c2721d290cc5f55425491ecd6831355e91063f20b39c22f9ec6a71f91&code_challenge_method=S256

This code_challenge is a hex encoding of a SHA-256 of a test “ABCDEFGHIJKLMNOP” challenge.

Note that the TikTok’s JavaScript demo creates the same string

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>

<script>
function generateRandomString(length) {
  return "ABCDEFGHIJKLMNOP";
}

// CryptoJS required
code_verifier = generateRandomString(16);
code_challenge = CryptoJS.SHA256(code_verifier).toString(CryptoJS.enc.Hex);

// e7e8b89c2721d290cc5f55425491ecd6831355e91063f20b39c22f9ec6a71f91

</script>

I get a code and then the claim of the Access Token fails, when passing to the token server (following instructions from here):

code=...&client_key=...&redirect_uri=http://localhost:51697&grant_type=authorization_code&code_verifier=4142434445464748494a4b4c4d4e4f50

This 414243 is the hex of ABCDEFGHIJKLMNOP

{"error":"invalid_request","error_description":"Code verifier or code challenge is invalid.","log_id":"..."}

What am I doing wrong?
By searching on PKCE it says that I have to base64url encode the hash but the TikTok guide doesn’t mention that.