I Can’t Use Two Carousel in index.php

I have a carousel that I wrote below and it works fine. But when I take another copy of it, nothing shows on the screen:

and I Use splide.js lib

<div class="MySlider">
        <div class="title">
            <h1><?php echo get_theme_mod('landingpage_learnslider_title'); ?></h1>
            <h3><?php echo get_theme_mod('landingpage_learnslider_description'); ?></h3>
        </div>
        <div class="slider_wrapper">
            <div class="splide">
                <div class="splide__track">
                    <div class="splide__list">

                        <?php
                        $args = array(
                            'post_type' => 'my_carousel',
                            'posts_per_page' => 5,
                        );
                        $carousel_query = new WP_Query($args);

                        if ($carousel_query->have_posts()) :
                            while ($carousel_query->have_posts()) :
                                $carousel_query->the_post();
                        ?>
                                <div class="splide__slide">
                                    <div class="card">
                                        <img src="<?php echo get_field('post_image')['url']; ?>" alt="<?php echo get_field('alt_img'); ?>">
                                        <div class="main_text">
                                            <a href="<?php the_permalink(); ?>">
                                                <h1><?php the_title(); ?></h1>
                                            </a>
                                            <div class="author">
                                                <h2><i class="fa-solid fa-chalkboard-user"></i>
                                                    <?php echo get_field('Author'); ?> </h2>
                                            </div>
                                            <div class="text_child_box">
                                                <div class="text_child_rate">
                                                    <h3><?php echo get_field('price'); ?> $ </h3>
                                                    <div class="main_rate">
                                                        <?php
                                                        $rating = get_field('rating_stars');
                                                        for ($i = 1; $i <= 5; $i++) {
                                                            if ($i <= $rating) {
                                                                echo '<i class="fa-solid fa-star"></i>';
                                                            } else {
                                                                echo '<i class="fa-regular fa-star"></i>';
                                                            }
                                                        }
                                                        ?>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                        <?php
                            endwhile;
                            wp_reset_postdata();
                        else :
                            echo '<p>There is no content to display</p>';
                        endif;
                        ?>


                    </div>
                </div>
            </div>
        </div>

    </div>

To solve the problem in the first place, I changed the names and then I used other libraries, but they also face the problem in different ways. So I wrote it with vanilla javascript and it still has problems. I am completely stuck.

How to add typescript rules in NextJs Project without losing next/core-web-vitals?

I have a typescript NextJS project with the following .eslintrc.json:

{
    "extends": "next/core-web-vitals"
}

I would like to add some additional typescript rules (like do not allow the type any (no-explicit-any)).

  1. I added npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin
  2. Extend the config by the no-explicit-any rule, updated the parser and added the plugin.
{
    "extends": "next/core-web-vitals",
    "parser": "@typescript-eslint/parser",
    "plugins": [
        "@typescript-eslint"
    ],
    "rules": {
        "@typescript-eslint/no-explicit-any": "warn"
    }
}
  1. Now the no-explicit-any works. However all the default rules from the next/core-web-vitals are not working anymore.

So I can either have the next or use the typescript-eslint rules. How can I use booth?

Why does this throw a TypeError?

There is a task to find a middle of Linked List. Could you please explain why does fast.next in while() loop throw a “TypeError: Cannot read properties of null (reading ‘next’)”?

const middleNode = (head) => {
    let fast = head
    let slow = head

    if (head !== null) {
        while (fast.next !== null) {
            fast = fast.next.next
            slow = slow.next
        }
    }
    return slow
}

How to save user input, update array, and render updated array on button press

I have a react web application that I am developing. The code from the component in question renders semesters of a degree 2 at a time. The user is able to see each class in a semester. There are buttons to go to the next two semesters as well as the previous two semesters. There is also a button to view all semesters at once. This is where my problem lies. In the 2 semester view the user has the option to edit any class that contains ‘Elective’ or ‘Cognate’. There is also a save button under each semester to manage the changes made (the handleSave function does nothing yet). When I make a change in the 2 semester view and then click on the button to display all semesters, my changes are not being reflected.

I have tried creating state variables that are a copy of the splitArray array and then updating that through the handleSave function but it didnt work. I also know that in the 2 semester view a new ‘items’ array is created every time out of the splitArray array. The items[1] is the name of the class to be edited. So i have no idea how to create a copy of the splitArray array with the edited items[1] being in the correct place. The first paragraph (following the showAll? is rendered when the display all button is pressed). The second paragraph is the 2 semester view in which the user is able to make edits.

{showAll
              ? splitArray.map((item, index) => (
                  <li key={index} style={{ display: 'inline-block', marginRight: '10px' }}>
                    <p>Semester {index + 1}:</p>
                    <div className="semester-lines">
                      <div>
                        <p style={{ display: 'flex', flexDirection: 'column' }}>
                          {item
                            .replace(/],/g, ']<br/>')
                            .replace(/[[]]/g, '')
                            .split('<br/>')
                            .map((line, index) => {
                              const items = line.split(',').map(item => item.trim());
                              
                              return (
                                <div key={index} style={{ display: 'flex', justifyContent: 'space-between' }}>
                                  <span style={{ padding: '5px', margin: '5px', backgroundColor: '#323232', boxShadow: '6px 6px 6px rgba(0, 0, 0, 0.30)' }}>
                                    {items[0]}
                                  </span>
                                  <span style={{ padding: '5px',maxWidth: '300px' ,margin: '5px', backgroundColor: '#323232', boxShadow: '6px 6px 6px rgba(0, 0, 0, 0.30)' }}>
                                    {items[1]}
                                  </span>
                                  <span style={{ padding: '5px', margin: '5px', backgroundColor: '#323232', boxShadow: '6px 6px 6px rgba(0, 0, 0, 0.30)', alignSelf: 'flex-end' }}>
                                    {items[2]}
                                  </span>
                                </div>
                              );
                            })}
                        </p>

                        
                      </div>
                    </div>
                  </li>
                ))


              : splitArray.slice(page, page + 2).map((item, index) => (
                  <li key={index} style={{ display: 'inline-block', marginRight: '10px' }}>
                    <p>Semester {index + 1 + page}:</p>
                    <div className="semester-lines">
                      <div>
                      <p style={{ display: 'flex', flexDirection: 'column' }}>
  {item
    .replace(/],/g, ']<br/>')
    .replace(/[[]]/g, '')
    .split('<br/>')
    .map((line, index) => {
      const items = line.split(',').map(item => item.trim());
      const isEditable = items[1].toLowerCase().includes('elective') || items[1].toLowerCase().includes('cognate');

      return (
        <div key={index} style={{ display: 'flex', justifyContent: 'space-between' }}>
          <span style={{ padding: '5px', margin: '5px', backgroundColor: '#323232', boxShadow: '6px 6px 6px rgba(0, 0, 0, 0.30)', maxWidth: '100px', height: 'auto' }}>
            {items[0]}
          </span>
          {isEditable ? (
            <input
              type="text"
              defaultValue={items[1]}
              style={{ height: 'auto', minHeight: '40px', overflow: 'hidden', resize: 'none', padding: '5px', maxWidth: '300px', margin: '5px', color: 'white', backgroundColor: '#323232', boxShadow: '6px 6px 6px rgba(0, 0, 0, 0.30)', textAlign: 'center' }}
              
              onChange={e => (items[1] = e.target.value)}
            />
          ) : (
            <span style={{height: 'auto',boxShadow: '6px 6px 6px rgba(0, 0, 0, 0.30)', padding: '5px', maxWidth: '300px', margin: '5px', backgroundColor: '#323232', boxShadow: '6px 6px 6px rgba(0, 0, 0, 0.30)' }}>
              {items[1]}
            </span>
          )}
          <span style={{ padding: '5px', margin: '5px',  backgroundColor: '#323232', boxShadow: '6px 6px 6px rgba(0, 0, 0, 0.30)', alignSelf: 'flex-end' }}>
            {items[2]}
          </span>
        </div>
      );
    })}
</p>


<button onClick={() => handleSave()}>
                  Save
                </button>
              </div>
            
          </div>
        </li>
      ))}
  </ul>

convert complex and nested json to table in excel using javascript

I am trying to convert a JSON in which some items can contains arrays as well. I get a very nicely structured table if I convert my JSON in json2table.com. I want similar table to be created in Excel using Javascript/nodejs. I tried some packages like ‘json2xls’, ‘xlsx’ etc. However I am not getting the desired output. Here’s my JSON.

JSON:

{
"name":"Gopi",
"id":"01",
"subjects":[{
"subject":"maths",
"marks":"84"
},
{
"subject":"science",
"marks":"85"
}],
"teachers":{
"name": "teacherA"
}
}

enter image description here

I am using below code. But I see [object Object],[object Object] under the column ‘subjects’

var json2xls = require('json2xls');
const fs = require('fs')
var json = {
  "name": "Gopi",
  "id": "01",
  "subjects": [{
    "subject": "maths",
    "marks": "84"
  },
  {
    "subject": "science",
    "marks": "85"
  }],
  "teachers": {
    "name": "teacherA"
  }
}
var xls = json2xls(json);
fs.writeFileSync('stackof.xlsx', xls, 'binary');

Acomodar elementos de izquierda a derecha [closed]

Estoy desarrollando una barra de busqueda, ya logre que funcione correctamente. mi problema es que los articulos aparecen listados uno debajo del otro cuando yo quiero que aparezcan de izquierda a derecha. Si alguien pudiera ayudarme con eso, lo agradeceria mucho.

trato de que los productos de mi lista se acomoden de izquierda a derecha sin que mi barra de busqueda deje de funcionar

Started studying code and January, and I lost a lot of time on deprecated tutorials

Im new into programming,I started studying really hard, 10-14 hrs a day, and I made some bad decisions buying online deprecated courses. I took the JS-NodeJS-Rect/Vue path. For that I thought UDEMI was ok and I got the 2023 full stack course. Now it’s been ok so far, but EJS and mongoose are deprecated and I can’t go along with the course. Are there any resources you can recommend me???? Thanks!!!!!

Some up to date guided way to learn

Get type for an object’s values where each object is of type , and each function have different argument

The object looks like this

export const templates = {
  [EventType.EventType1 + OutputSources.Email]: (params: { documentName: string; link: string }) => {
    return "some html data";
  },
  [EventType.EventType2 + OutputSources.Email]: (params: { documentName: string }) => {
    return "some html data";
  },
  [EventType.EventType1 + OutputSources.Notification]: (params: { documentName: string }) => {
    return "some html data";
  },
} as const;

I want to have a type that contains parameters of each of these function as a union, for example the result for above will look like.
type possibleFunctionArgs = {documentName:string,link:string} | {documentName:string}

What I’ve already tried and failed
type lastFailingAttemptToGetTypes = Parameters<typeof templates[keyof typeof templates]>
For the above code I’m always getting only {documentName:string,link:string} , always getting the one with highest number of parameters

Is there a way in Zod to create a new schema from an object schema by type?

Let’s say I have the following example schema:

const Z_GlobalSettings = z.object({
  crust: z.enum(["thin", "thick"]).default("thin"),
  toppings: z.array(z.string()).min(1).max(5).default(["cheese"]),
  sauce: z.enum(["marinara", "bbq", "ranch"]).default("marinara"),
  delivery_time: z.string().optional(),
  order_notes: z.string().max(50).optional(),
  contact_email: z.string().email().optional(),
  setting_1: z.boolean(),
  setting_2: z.boolean().optional(),
});

type GlobalSettings = z.infer<typeof Z_GlobalSettings>;

How can I programmatically extract the types that contain booleans, or whichever arbitrary type I’m looking for? For example, if I want the booleans from the schema, I’d want my new schema to look like:

const Z_OnlyBoolean = z.object({
  setting_1: z.boolean(),
  setting_2: z.boolean().optional(),
});

I was initially able to accomplish this using Typescript:

type BooleanSettings = {
  [K in keyof GlobalSettings as GlobalSettings[K] extends boolean | undefined
    ? K
    : never]?: boolean;
};

However, this wasn’t working when I wanted to differentiate between z.string() and z.enum(["example1", "example2"]), since they’d both come through as strings. This is why I’m hoping to find a way to filter a schema by type since Zod is keeping track of the difference between strings and enums, but the only way I can find in the documentation is to use the .pick() method and choose them one-by-one. This won’t be great if I add properties in the future, since I’ll need to update the filtered schema as well, and won’t be great for usability since I’ll need to make a new schema for every type I want to extract.

Any ideas on how to accomplish this?

is there a way to use getElementbyid but for multiple of the same id’s

I’m trying to use a function that appends a text onto an answer choice on a multiple choice quiz but I can only seem to access the first answer value.

<!doctype html>
<html>
    
    <head>
        <meta charset="utf-8" />
        <title>name</title>

    </head>
    <h1>
        name
    </h1>
    <body style="background-color:rgb(73, 88, 83);">

            <div id="question1">
                <p>1. which planet is considered earth's sister planet?</p>
                <a href = "#">
                    <p id = "answer" value = "wrong">a. moon</p>
                </a>
                <a href = "#">
                    <p id = "answer"  value = "correct">b. venus</p>
                </a>
                <a href = "#">
                    <p id = "answer" value = "wrong">c. mars</p>
                </a>
            </div>

            <div id="question2">
                <p>2. when did apollo 11 land?</p>
                <a href = "#"> 
                    <p id = "answer" value = "correct">a. 1969</p>
                </a>
                <a href = "#">
                    <p id = "answer"  value = "wrong">b. 1970</p>
                </a>
                <a href = "#">
                    <p id = "answer" value = "wrong">c. 1968</p>
                </a>
            </div>

            <div id="question3">
                <p>3. which is the planet mars?</p>
                <a href = "#">
                    <p id = "answer" value = "wrong">a. <img src = "https://upload.wikimedia.org/wikipedia/commons/e/e1/FullMoon2010.jpg" width="50" height="50"> </p>
                </a>
                <a href = "#">
                    <p id = "answer"  value = "wrong">b. <img src = "https://upload.wikimedia.org/wikipedia/commons/0/0d/Africa_and_Europe_from_a_Million_Miles_Away.png" width="50" height="50"> </p>
                </a>
                <a href = "#">
                    <p id = "answer" value = "correct">c. <img src = "https://upload.wikimedia.org/wikipedia/commons/0/02/OSIRIS_Mars_true_color.jpg" width="50" height="50"> </p>
                </a>
            </div>

            <div class="buttons">
                <button id="reset-button"> Reset </button>
            </div>


            <script>
                const reset = document.getElementById("reset-button")
                var clicked = document.getElementById("answer")
                var text = document.createTextNode(" correct")
                var text_2 = document.createTextNode(" wrong")
        
                reset.addEventListener('click', resetquestions)
                clicked.addEventListener('click', giveAnswer)
                
    
                function giveAnswer() {
                    if(clicked.value === "correct") {
                        clicked.appendChild(text)
                    }
                    else {
                        clicked.appendChild(text_2)
                    }
                }

                function resetquestions() {
                    if(clicked.value === "correct") {
                        text.remove()
                    }
                    else {
                        text_2.remove()
                    }
                }
            </script>
    </body>
</html>

I want to be able to append a correct or wrong text to every answer choice that I click. I tried changing the ID’s to answer_1_1, answer_1_2 and adding an event listener to them individually but unfortunately I wasn’t even able to get the first response’s answer anymore. How can I fix this? sidenote: i’m not allowed to use buttons or input for the answer choices.

The annotation message does not appear. with Chart.js , react-chart-js , and chartjs-plugin-annotation

Show code

import React from "react";
import {
  Chart as ChartJS,
  CategoryScale,
  LinearScale,
  PointElement,
  LineElement,
  Title,
  Tooltip,
  Legend,
} from "chart.js";
import { Line } from "react-chartjs-2";

import annotationPlugin from "chartjs-plugin-annotation";

ChartJS.register(
  CategoryScale,
  LinearScale,
  PointElement,
  LineElement,
  Title,
  Tooltip,
  Legend,
  annotationPlugin
);

export const options = {
  responsive: true,
  plugins: {
    legend: {
      position: "top",
    },
    title: {
      display: true,
      text: "Chart.js Line Chart",
    },
    annotation: {
      annotations: {
        line1: {
          adjustScaleRange: true,
          drawTime: "afterDatasetsDraw",
          type: "line",

          scaleID: "x",
          value: 1,
          borderColor: "rgba(104,1)",

          label: {
            enabled: true,
            content: "Hi !!",
            backgroundColor: "rgba(255, 26, 104, 0.8)",
            color: "black",
          },
        },
      },
    },
  },
};

const labels = [1, 2, 3, 4];

export const data = {
  labels,
  datasets: [
    {
      label: "My First Dataset",
      data: [65, 59, 80, 81, 56, 55, 40],
      fill: false,
      borderColor: "rgb(75, 192, 192)",
      tension: 0.1,
    },
  ],
};

export function ChartPrueba() {
  return (
    <div>
      <h1>Example react-chartjs-2 Chart with the annotation plugin</h1>
      <Line options={options} data={data} />;
    </div>
  );
}

I tried disabling tailwindcss and importing it directly into the app, I use Vite and these are the dependencies

 "dependencies": {
    "chart.js": "^4.2.1",
    "chartjs-plugin-annotation": "^2.2.1",
    "react": "^18.2.0",
    "react-chartjs-2": "^5.2.0",
    "react-dom": "^18.2.0"
  },


Stack asks me to put more words I don’t know why.
Everything is already there so I add random words.
Stack asks me to put more words I don’t know why.
Everything is already there so I add random words.
Stack asks me to put more words I don’t know why.
Everything is already there so I add random words.
Stack asks me to put more words I don’t know why.
Everything is already there so I add random words.
Stack asks me to put more words I don’t know why.
Everything is already there so I add random words.
Stack asks me to put more words I don’t know why.
Everything is already there so I add random words.

}

How to receive push notifications on my iPhone with IOS 16.4

Hello everyone I hope you are well recently there was an update on iOS that now allows you to receive push notifications from a site on iPhone with the version IOS 16.4

Here is a piece of code that I wanted to try on my iPhone however I have no popup to display when I click on the button my iPhone has well the update 16.4 in the settings of my iPhone I gave him access to receive external notifications

Settings>Safari > Advanced>Experimental Features> (accept push api)

I would like to know if someone succeeded in setting up push notifications on safari on iPhone please
Here is my code below

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button class="notify-btn">Click me </button>
</body>
<script src="./main.js"></script>
</html>

main.js

document.querySelector(".notify-btn").addEventListener("click", function() {

  Notification.requestPermission().then(function(result) {
    if (result !== "granted") {
      console.log("No notification permission granted!");
      return;
    } else {
      console.log("Button clicked");
      new Notification("This is a notification", {
        body: "This is the body of the notification",
        icon:
          "https://cdn4.iconfinder.com/data/icons/flat-brand-logo-2/512/medium-512.png",
      });
    }
  });
});

result on my Mac
image

Use mouseover for a list of products

I have multiple product cards within a division. I want to display the relevant information when the mouse is moved on each card, and not to display the information whenever the mouse is out.

<div class="row holderCard d-flex">
<div class="col-md-4 col-sm-12 card">
            <div class="holderDetailsImg">
                <div>
                    <div class="coverGradient d-none"></div>
                    <img src="img/zahedan.jpg" alt="Avatar">
                </div>
                <div class="infoImg d-none">
                    <span class="badgesLike"><i class="fa fa-heart-o"></i></span>
                    <p class="titleDetailesImg">یک متن آزمایشی داخل ان است</p>
                    <p class="descriptionDetailesImg">یک متن آزمایشی داخل آن وجود دارد که با هم هست</p>
                    <span class="badgesTags">مسجد مکی زاهدان</span>
                    <div class="badgesStar">
                        <span class="fa fa-star checked "></span>
                        <span class="fa fa-star checked "></span>
                        <span class="fa fa-star checked "></span>
                        <span class="fa fa-star "></span>
                        <span class="fa fa-star "></span>
                    </div>
                </div>
            </div>
            <div class="container">
                <span class="badges">2</span>
                <p class="captionCard small">مجموعه ای از بهترین مکان های گردردشگری</p>
            </div>
        </div>
        <div class="col-md-4 col-sm-12 card">
            <div class="holderDetailsImg">
                <div>
                    <div class="coverGradient d-none"></div>
                    <img src="img/yazd.jpg" alt="Avatar">
                </div>
                <div class="infoImg d-none">
                    <span class="badgesLike"><i class="fa fa-heart-o"></i></span>
                    <p class="titleDetailesImg">یک متن آزمایشی داخل ان است</p>
                    <p class="descriptionDetailesImg">یک متن آزمایشی داخل آن وجود دارد که با هم هست</p>
                    <span class="badgesTags">بادگیرهای یزد</span>
                    <div class="badgesStar">
                        <span class="fa fa-star checked "></span>
                        <span class="fa fa-star checked "></span>
                        <span class="fa fa-star checked "></span>
                        <span class="fa fa-star "></span>
                        <span class="fa fa-star "></span>
                    </div>
                </div>
            </div>
            <div class="container">
                <span class="badges">2</span>
                <p class="captionCard small">مجموعه ای از بهترین مکان های گردردشگری</p>
            </div>
        </div>
</div>
I have written the mouseover part using the forEach and a condition to have the d-none class. My problem is that when the mouse is placed on any of the cards, only d-none of the first card is removed.

I can’t understand where the problem is.
Because when there is an alert inside the function, all the information cards are shown with float. But the d-none class is not removed

let holderDetailsImg= document.querySelectorAll('.holderDetailsImg')
let coverGradient= document.querySelector('.coverGradient')
let infoImg= document.querySelector('.infoImg')


holderDetailsImg.forEach(function (holderDetailsImg){
    holderDetailsImg.addEventListener("mouseover", mouseOver);
    function mouseOver() {
        if(coverGradient.classList.contains('d-none') || infoImg.classList.contains('d-none')){
            coverGradient.classList.remove('d-none');
            infoImg.classList.remove('d-none');

        }
    }
})

and not css codes. i only add d-none on tags

When using gatsby-source-filesystem’s createRemoteFileNode can I access the publicURL of the downloaded file?

I’m working on plugin for Gatsby.

When using createRemoteFileNode to download a remote file (in my case an image) a File object is returned, however that object doesn’t appear to have any information about where the file was downloaded to. This is added much later in the lifecycle by a resolver and can then be accessed on a File node using the publicURL field.

Is there any way to access the local location of the downloaded file from within JavaScript either from the File object returned by createRemoteFileNode or through another API. Ideally I want to know where the file was downloaded as soon as createRemoteFileNode returns.

Chrome Extesions. If I only using content_scripts. Do I need permisions “host_permisions” and “scripting”?

I read that i need host_permissions or scripting if i “inject programmatically” the content_scritps but the examples show that they use background.js code to inject the script, i don’t use that, i don’t even have a background.js. My extension only has a few functions and events. Yes, the events and functions change the html of page.

In dev mode the extension works without host_permisions, but when I send it to revision, they ask for host_permisions justification anyway