I can’t add buttons with filling from JSON file

I have an html project to which I need to add 4 buttons filled from a JSON file using an array.
The parameters are taken depending on the link id.

    <div class="d-flex justify-content-around mt-4">
        <a href="#" id="button-1" class="btn btn-primary">
            <img src="" alt="Icon" id="icon-button-1"> Button 1
        </a>
        <a href="#" id="button-2" class="btn btn-primary">
            <img src="" alt="Icon" id="icon-button-2"> Button 2
        </a>
        <a href="#" id="button-3" class="btn btn-primary">
            <img src="" alt="Icon" id="icon-button-3"> Button 3
        </a>
        <a href="#" id="button-4" class="btn btn-primary">
            <img src="" alt="Icon" id="icon-button-4"> Button 4
        </a>
    </div>
</div>

        

$(document).ready(function () {
    const urlParams = new URLSearchParams(window.location.search);
    const repoId = urlParams.get('id');



    $.getJSON('repositories.json', function (data) {
        const repo = data.find(r => r.id === repoId);


    

        if (repo.buttons && Array.isArray(repo.buttons)) {
            repo.buttons.forEach((button, index) => {
                const btn = $(`#button-${index + 1}`);
                if (btn.length > 0) {
                    btn.attr('href', button.link || '#');
                    btn.find('img').attr('src', button.icon || 'default-icon.png');
                    btn.find('span').text(button.text || `Button ${index + 1}`);
                }
            });
        }
    });

        </script>
    </body>
    
    </html>

Code from JSON file:

[
    {
        "id": "repo1",

        "buttons": [
            {
                "link": "exmpl.html",
                "icon": "exmpl.png",
                "text": "btn exmpl1"
            },
            {
                "link": "exmpl.html",
                "icon": "exmpl.png",
                "text": "btn exmpl2"
            },
            {
                
                "link": "exmpl.html",
                "icon": "exmpl.png",
                "text": "btn exmpl3"
            },
            {
                "link": "exmpl.html",
                "icon": "exmpl.png",
                "text": "btn exmpl4"
            }
        ]
    },

    {
        "id": "repo2",

        "buttons": [
            {
                "link": "exmpl.html",
                "icon": "exmpl.png",
                "text": "btn exmpl1"
            },
            {
                "link": "exmpl.html",
                "icon": "exmpl.png",
                "text": "btn exmpl2"
            },
            {
                "link": "exmpl.html",
                "icon": "exmpl.png",
                "text": "btn exmpl3"
            },
            {
                "link": "exmpl.html",
                "icon": "exmpl.png",
                "text": "btn exmpl4"
            }
        ]

    }
]

I tried renaming repo.buttons to repoId.buttons, but it didn’t help (fixed the error in the console, but the problem remained)

Console error: Uncaught ReferenceError: repo is not defined

Typescript function return type error not showing

**it described to return void **

type someFn = () => void;
const some: asdFn = () => {
  return 2; // ts not showing error here?
};

as Chatgpt sad i added

"@typescript-eslint/no-invalid-void-type": "error",
"@typescript-eslint/no-unused-vars": "warn",

in eslint config and

"strict": true,              // Enables strict type checking
"noImplicitReturns": true,   // Enforces explicit return or no return

this in tsconfig but still not works

Error on prorammatically accessing global variable [closed]

My code loads a value to a global variable like this:

str="global";
...
window[str+"w"]=100;

This code works fine on desktop browser. But in the mobile browser (Samsung Internet ore Chrome) the global variable remains at the old value.

When the value of the global variable is displayed with an alert at the end of the function where the loading is done, it appears that the new value has been loaded. However, when the same operation is performed in a function called later, it is seen that the global variable has the old value.

How should I render my NextUI Navbar if NextJS uses a mix between serverside and client rendering?

The component

I had a React WebApp that used this Navbar Component for every page:

import React, { useState, useEffect } from "react";
...

function useMobileView() {
  const [isMobile, setIsMobile] = useState(window.innerWidth < 768);

  useEffect(() => {
    setIsMobile(window.innerWidth < 768);
    const handleResize = () => {
      setIsMobile(window.innerWidth < 768);
    };
    window.addEventListener("resize", handleResize);
    return () => window.removeEventListener("resize", handleResize);
  }, []);

  return isMobile;
}

export default function SMNavbar(active) {
  const isMobile = useMobileView();

  return (
    <Navbar>
      <NavbarBrand>
        <a
          href="/"
        >
          <img
            src="Logo.png"
            alt="logo"
          />
        </a>
      </NavbarBrand>
      {!isMobile ? (
        <React.Fragment>
          <NavbarContent>

            ...Navbar Items

          </NavbarContent>
        </React.Fragment>
      ) : (
        <React.Fragment>
          <NavbarMenuToggle />
          <NavbarMenu>
            {/* Explicitly defining each NavbarMenuItem for mobile view */}
            

           ...Navbar Items

          </NavbarMenu>
        </React.Fragment>
      )}
    </Navbar>
  );
}

This worked fine when using React, because everything is loaded once it reaches the client anyway. So it was able to access the ‘window’ attribute and differenciate between the mobile and desktop navbars.

The problem

Now however I’m trying to make a similair webapp using NextJS and want to use my Navbar component again. The problem is that even when I use ‘use client’ it still does some partial server-side rendering. It doesn’t recognize the ‘window’ attribute when doing this so I have to use

if (typeof window === "undefined") return;

but that’s besides the point really. Basically, because the whole rendering is based on the outcome of window.innerWidth < 768 to decide if it should render the mobile navbar or the desktop one, the only two options I see are this:

  1. Initially set the result of isMobile to either true or false

This is a disgusting solution for me, because it will hop from the initial state to the proper one for every page load if its not initially set correctly.

  1. Import the Navbar like this for every component that uses it:
const Navbar = dynamic(() => import("../components/Navbar"), {
  ssr: false,
});

I don’t like this at all either, because then while the page has already basically loaded, the Navbar is nowhere to be found. It takes about a full second for it to show up.

I am still kind of new to Frontend Frameworks, so if there is an obvious solution and I haven’t found it I would be delighted.

I mean, big corperations with their websites must be facing/have long solved the issue of this?

Any help would be GREATLY appreciated.

J_security_check failing when cookie times out – how to clear cookies when logging out?

It’s just a simple username/password login

  <form name="login" method ="POST" role="form" action="j_security_check">
      <div class="login">
         <label> Username</label>
         <input formControlName="username"  name="j_username" autofocus required>
      </div>

      <div class="login">
         <label> Password</label>
         <input type="password" formControlName="password"  name="j_password" required>
      </div>
     <button class="submit" type="submit"> Sing In</button>
</form>

In my application, I have a button that calls “logoutUser”

protected logoutUser() {
   this.http.post('/foo/logout', {}).subscribe ({
     next: () => {
        location.reload(); //reloads the page after the post call invalidates the session
     }});}

the Java backend i have:

 @jakarta.ws.rs.POST
  @operation(responses = {@ApiResponse(responseCode="200", content=@Content(schema = 
  @Schema(implementation = Void.class))),})
  public Response signout(@Context final HttpServletRequest request, @Context final 
      SecurityContext securityContext) {
    
          request.getSession().invalidate();
          return Response.ok().build();
      }
  }

I can login and logout and log back in FINE.
However, if I do the following:
1. Login
2. logout
3. wait ~5 mins
4. login
5. I receive 408 on my POST to …/j_security_check which is a Request Timeout.

   I notice that when I login, i have 2 cookies - JSESSIONIDSSO and JSESSIONID. the JSESSIONIDSSO is set to "REMOVE" when I logout. I also noticed that the console has a warning that cookie "JSESSIONIDSSO" has been rejected because it is already expired. However, if I login within the 5 minutes or so, i still can.
    
    From the login action, i see a POST (return 303) j_security_check where it sends JSESSIONID cookie and the response has the cookies JESSIONID and JSESSIONIDSSO
    
    If I logout and the page refreshes, I see a GET on my current login page and I see the Response with set-cookie on JSESSIONIDSSO=REMOVE, Expires =Thu,01 jan 1970... and JSESSIONID = 123531....
    
    
    I want the "path of least resistance" to get the login to work. If I can refresh cookie or clear cookie/cache when I logout that would be great. or if I can fix in backend that be great too. I think for now I just need to be able to 1. login. 2.logout. 3. after periods of time 4. login success.

Thanks

Facebook not active [closed]

App not active: This app is not currently accessible and the app developer is aware of the issue. You will be able to log in when the app is reactivated.

App not active: This app is not currently accessible and the app developer is aware of the issue. You will be able to log in when the app is reactivated.

How to add or import font family with all font weight in shadow root element that not effect from the outside

How to add or import font family with all font weight in shadow root element that not effect from the outside

In shadow root element css added below code
@import url(‘https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;400;500;700&display=swap’);
or
In shadow root element using link

It does not work because in consuming app font weight 500 missing i.e. in head tag inside body

<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;400&display=swap" rel="stylesheet">

Bold code is shadow element and Italic code in consuming app, problem is that consuming app is override font weight but requirement is in shadow root what font family and font weight added, should not effect from outside the code.

I tried many ways like font family used in local folder of shadow element and using css tried load but it effected from outside the code

How to get {[space][caret][space]} and {{[space][caret][space]}}

I have a Vue project in PHPStorm and every time I want to import or use curly braces in Vue componenent, I’m having to add extra spaces inside my curly braces.

When I type import {, the closing curly brace is added in, so I end up with this:

enter image description here

If I press space once, I have of course:

enter image description here

What I would like, as soon as I press the space, that
the IDE automatically inserts another space and moves caret one position to left, so end up with {[space][caret][space]}. And similarly, {{[space][caret][space]}} for double curly braces (used in Vue components).

I’ve tried with Live Templates (as mentioned here) but it doesn’t seem to trigger after typing { … (I’ve tried selecting ‘None’ and ‘Tab’ as expand but doesn’t work).

It seems that a space is not allowed in the ‘abbreviation’ (when I Apply it and reopen this setting, the space is gone):

enter image description here

Reusable modal fragment thymeleaf

I am trying to reuse the following modal (as a fragment) with thymeleaf.

<th:block th:fragment="modalFragment (modalId, labelId, modalTitle, formId, saveButtonId, fields)">
    <div class="modal fade" th:id="${modalId}" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
         th:aria-labelledby="${labelId}" aria-hidden="true">
        <div class="modal-dialog modal-dialog-scrollable modal-dialog-centered modal-xl">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" th:id="${labelId}" th:text="${modalTitle}">Título del Modal</h5>
                    <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"
                            aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="container-fluid">
                        <!-- Renderizar el formulario solo si formId no es null -->
                        <form th:if="${formId != null and formId != ''}" th:id="${formId}" class="row g-3">
                            <!-- Espacio reservado para campos del formulario dinámicos, definidos en la página de inclusión -->
                            <th:block th:replace="~{this :: fields}"></th:block>
                        </form>
                        <!-- Renderizar contenido alternativo si formId es null -->
<!--                        <th:block th:unless="${formId != null}" th:replace="~{this :: fields}"></th:block>-->
                        <th:block th:unless="${formId != null and formId != ''}">
                            <th:block th:replace="~{this :: fields}"></th:block>
                        </th:block>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cerrar</button>
                    <!-- Renderizar el botón de guardar solo si saveButtonId está definido -->
                    <button type="button" th:if="${saveButtonId != null and saveButtonId != ''}" th:id="${saveButtonId}"
                            class="btn btn-custom">Guardar
                    </button>
                </div>
            </div>
        </div>
    </div>
</th:block>

When I use it this way in my .html it works without problems.

    <div th:replace="~{fragments/modalFragment :: modalFragment(
    modalId='modalUsuario',
    labelId='staticBackdropLabelUsuario',
    modalTitle='Usuario',
    formId='formularioRegistroUsuario',
    saveButtonId='btnGuardarUsuario',
    fields='~{this :: fields}')}">
        <!-- Campos del formulario definidos directamente dentro de la inclusión del modal -->
        <th:block th:fragment="fields">
            <div class="col-md-6 offset-6 d-none">
                <div class="form-floating">
                    <input type="text" class="form-control" id="usuId" name="usuId" placeholder="Id"
                           readonly>
                    <label for="usuId">Id</label>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-floating">
                    <select class="form-select componente-select" id="usuActivo" name="usuActivo"
                            aria-label="Estado"
                            data-lista="1" data-lista-idioma="1" required>
                        <option value="" selected>Selecciona una opción</option>
                    </select>
                    <label for="usuActivo">Estado</label>
                </div>
            </div>

            <!-- Usamos este div vacío para forzar que la siguiente columna que haya después vaya abajo. -->
            <div class="w-100 m-0"></div>

            <div class="col-md-6">
                <div class="form-floating">
                    <select class="form-select componente-select" id="roles"
                            aria-label="Rol"
                            data-live-search="true" data-url="buscarListaRoles">
                        <option value="" selected>Selecciona una opción</option>
                    </select>
                    <label for="roles">Rol</label>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-floating">
                    <select class="form-select componente-select"
                            id="sistemas"
                            aria-label="Sistemas"
                            data-url="buscarListaSistemas"
                            title="Selecciona una opción"
                            data-live-search="true" data-size="8" multiple
                            data-actions-box="true">
                    </select>
                    <label for="sistemas">Sistemas</label>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-floating">
                    <input type="text" class="form-control" id="usuUsuario" name="usuUsuario"
                           placeholder="Usuario" required>
                    <label for="usuUsuario">Usuario</label>
                </div>
            </div>

            <!-- Usamos este div vacío para forzar que la siguiente columna que haya después vaya abajo. -->
            <div class="w-100 m-0"></div>

            <div class="col-md-6">
                <div class="form-floating d-flex align-items-center bg-white">
                    <input type="password" class="form-control"
                           id="usuPassword" name="usuPassword" placeholder="Contraseña">
                    <label for="usuPassword">Contraseña</label>
                    <span><i id="btnMostrarPass"
                             class="bi bi-eye-slash-fill cursor-pointer"></i></span>
                </div>
            </div>

            <div class="col-md-6">
                <div class="form-floating d-flex align-items-center bg-white">
                    <input type="password" class="form-control"
                           id="usuRepitePassword" placeholder="Contraseña">
                    <label for="usuRepitePassword">Repite contraseña</label>
                    <span><i id="btnMostrarRepitePass"
                             class="bi bi-eye-slash-fill cursor-pointer"></i></span>
                </div>
            </div>

            <div id="mensajeMayusculas" class="col-12 text-center d-none">
                <i class="bi bi-exclamation-triangle-fill me-2"></i>
                <span>El bloqueo de mayúsculas está activado</span>
            </div>

            <div class="col-md-6">
                <div class="form-floating">
                    <input type="text" class="form-control" id="usuNombre" name="usuNombre"
                           placeholder="Nombre" required>
                    <label for="usuNombre">Nombre</label>
                </div>
            </div>

            <div class="col-md-6">
                <div class="form-floating">
                    <input type="text" class="form-control" id="usuPrimerApellido" name="usuPrimerApellido"
                           placeholder="Primer apellido" required>
                    <label for="usuPrimerApellido">Primer apellido</label>
                </div>
            </div>

            <div class="col-md-6">
                <div class="form-floating">
                    <input type="text" class="form-control" id="usuSegundoApellido" name="usuSegundoApellido"
                           placeholder="Segundo apellido">
                    <label for="usuSegundoApellido">Segundo apellido</label>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-floating">
                    <input type="text" class="form-control" id="usuDni" name="usuDni"
                           placeholder="DNI">
                    <label for="usuDni">DNI</label>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-floating">
                    <input type="text" class="form-control" id="usuTelefono" name="usuTelefono"
                           placeholder="Teléfono">
                    <label for="usuTelefono">Teléfono</label>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-floating">
                    <input type="email" class="form-control" id="usuEmail" name="usuEmail"
                           placeholder="Email">
                    <label for="usuEmail">Email</label>
                </div>
            </div>

        </th:block>
    </div>

But when I want to add a second modal to the same .html it does not work as it should.

    <div th:replace="~{fragments/modalFragment :: modalFragment(
    modalId='modalUsuario2',
    labelId='staticBackdropLabelUsuario2',
    modalTitle='Usuario2',
    formId='',
    saveButtonId='',
    fields='~{this :: fields}')}">
        <!-- Campos del formulario definidos directamente dentro de la inclusión del modal -->
        <th:block th:fragment="fields">
          <p>HOLA</p>
        </th:block>
    </div>

What it does is to put me the same fields in both modals. In the second one they come out without layout maybe because they’re repeated fields, I see the duplicated ids on the DevTools console.

I have tried to change:

fields='~{this :: fields}')}" with fields='~{this :: fields2}')}" and <th:block th:fragment="fields2"> but it doesn’t work either.

Do you have any idea why it doesn’t work? I guess it doesn’t resolve the “this” context well or something like that.

Time query mysql

I want a query that dynamically fetches data greater than the current time today and less than 24 hours today. If necessary, it should also include data for the next day based on the specified hours value. For example, if I provide hours = 2, the query should fetch data for the next 2 hours from the current time today. However, if I provide hours = 19, the query should return “no rows” if the data does not exist.

Currently, my query retrieves data for today within the next 24 hours, which works fine. However, if I provide a value like hours = 17 or dynamically between 24 hours, it does not include data for the next day if the time exceeds midnight. I need help resolving this issue.

now this query get today data less than or greater than current time..
SELECT *
FROM jobDetails jd
WHERE TIME(time) > TIME(CONVERT_TZ(NOW(), ‘+00:00’, ‘+05:00’))
AND TIME(time) <= TIME(DATE_ADD(CONVERT_TZ(NOW(), ‘+00:00’, ‘+05:00’), INTERVAL ? HOUR));

get data next day 24 hours include another condition.

Write pure CSR components on Deno+Fresh

Sry that I’m new to front-end development.

I have a JS function that operates Monaco editor’s API. Let’s suppose it looks likes this:

export function setTheme(themeName) {
    fetch(`./themes/${themeName}.json`)
        .then(response => response.json())
        .then(themeData => {
            console.log(themeName)
            console.log(themeData)
            monaco.editor.defineTheme(themeName, themeData);
            monaco.editor.setTheme(themeName);
        })
}

It relies on APIs which are not available on Deno, so it’s put as a static JS file. I tried to bundle it with an Island component here:

<Dropdown list={themeList} onChange={setTheme} />

This cannot pass the compile because the server always tries to render it server-side although it’s actually inside an Island (As ChatGPT told me). My question is how to bundle the function with the component only during the client side. ChatGPT asked me to put related CSR-only codes with setState functions like that:

useEffect(() => setTheme(themeName), []);

So I used a function object to store it:

    const setThm = (themeName: string) => {
        useEffect(() => setTheme(themeName), [themeName]);
    }

But Deno still rejected to render the page as it tried to render the function server-side. Function also does not help:

function setThm(themeName: string){
    useEffect(() => setTheme(themeName), []);
}

The same error as above:

error: Uncaught (in promise) ReferenceError: document is not defined
document.addEventListener('DOMContentLoaded', () => {
^
    at file:///path/to/project/static/editor.js:2:1

    info: document global is not available in Deno.
    hint: Use a library like happy-dom, deno_dom, linkedom or JSDom
          and setup the document global according to the library documentation.
Watcher Process failed. Restarting on file change...

So I really have no idea about how to bundle the CSR-only function with a Fresh component now. What exactly should I do is correct?

How can I scan for open ports on a network using Python?

I am trying to create a simple Python script to scan for open ports on a target machine for ethical hacking purposes (I have permission to test this network). My goal is to identify which ports are open using the socket library.

Here’s what I have so far:

python

When I run this script, it sometimes skips open ports or takes a long time to complete. How can I improve this script to make the scan more reliable and faster? Are there better libraries or techniques for port scanning in Python?