Check cron job minimum span

I have an app that accepts a cron definition from the user

Now – let’s say I want to limit how many crons the user can run –
so that the minimum span between each cron would be once an hour.

How can I check whether the provided cron-job “at most” or “most frequently”c happens every hour.

How i can add sub-Div at the end of another DEv

I have this main Div with those attributes lass="ms-HorizontalNavItems" role="menubar":-

<div class="ms-HorizontalNavItems" role="menubar">
<span class="ms-HorizontalNavItem" data-automationid="HorizontalNav-link"><a class="ms-HorizontalNavItem-link is-not-selected siteNavLink-74 linkUnselected-75" href="/" target="_self" rel="noopener" data-navigationcomponent="SiteHeader" tabindex="0">Home</a></span>
<span class="ms-HorizontalNavItem" data-automationid="HorizontalNav-link"><a class="ms-HorizontalNavItem-link is-not-selected siteNavLink-74 linkUnselected-75" href="/Shared Documents/Forms/AllItems.aspx" target="_self" rel="noopener" data-navigationcomponent="SiteHeader" tabindex="-1">Documents</a></span>
<span class="ms-HorizontalNavItem" data-automationid="HorizontalNav-link"><a class="ms-HorizontalNavItem-link is-not-selected siteNavLink-74 linkUnselected-75" href="/SitePages/Forms/ByAuthor.aspx" target="_self" rel="noopener" data-navigationcomponent="SiteHeader" tabindex="-1">Pages</a></span>
<span class="ms-HorizontalNavItem" data-automationid="HorizontalNav-link"><a class="ms-HorizontalNavItem-link is-not-selected siteNavLink-74 linkUnselected-75" href="/Lists/Announcements/All Active Items.aspx" target="_self" rel="noopener" data-navigationcomponent="SiteHeader" tabindex="-1">Announcements</a></span>
<span class="ms-HorizontalNavItem" data-automationid="HorizontalNav-link"><a class="ms-HorizontalNavItem-link is-not-selected siteNavLink-74 linkUnselected-75" href="/resources/Forms/AllItems.aspx" target="_self" rel="noopener" data-navigationcomponent="SiteHeader" tabindex="-1">resources</a></span>
<span class="ms-HorizontalNavItem" data-automationid="HorizontalNav-link"><a class="ms-HorizontalNavItem-link is-not-selected siteNavLink-74 linkUnselected-75" href="/_layouts/15/viewlsts.aspx" target="_self" rel="noopener" data-navigationcomponent="SiteHeader" tabindex="-1">Site contents</a></span>
<div class="ms-HorizontalNavItem" data-automationid="HorizontalNav-edit"><button id="HorizontalNav0EditLink" class="ms-HorizontalNavItem-link siteNavLink-74 ms-HorizontalNavItem-Edit editButton-79" aria-label="Edit site navigation">Edit</button></div>
</div>

Now i want to add this Div to be the last sub-div of the main div:-

<div class="ms-HorizontalNavItem" data-automationid="HorizontalNav-edit"><a data-automation-id="button-web-part" href="" target="_blank" class="ms-Button ms-Button--primary root-251" data-is-focusable="true"><span class="ms-Button-flexContainer flexContainer-252" data-automationid="splitbuttonprimary"><span class="ms-Button-textContainer textContainer-253"><span class="ms-Button-label label-254" id="id__141">LEARN MORE</span></span></span></a></div>

can i do so using pure JavaScript? so the main Div will be as follow:

<div class="ms-HorizontalNavItems" role="menubar">
<span class="ms-HorizontalNavItem" data-automationid="HorizontalNav-link"><a class="ms-HorizontalNavItem-link is-not-selected siteNavLink-74 linkUnselected-75" href="/" target="_self" rel="noopener" data-navigationcomponent="SiteHeader" tabindex="0">Home</a></span>
<span class="ms-HorizontalNavItem" data-automationid="HorizontalNav-link"><a class="ms-HorizontalNavItem-link is-not-selected siteNavLink-74 linkUnselected-75" href="/Shared Documents/Forms/AllItems.aspx" target="_self" rel="noopener" data-navigationcomponent="SiteHeader" tabindex="-1">Documents</a></span>
<span class="ms-HorizontalNavItem" data-automationid="HorizontalNav-link"><a class="ms-HorizontalNavItem-link is-not-selected siteNavLink-74 linkUnselected-75" href="/SitePages/Forms/ByAuthor.aspx" target="_self" rel="noopener" data-navigationcomponent="SiteHeader" tabindex="-1">Pages</a></span>
<span class="ms-HorizontalNavItem" data-automationid="HorizontalNav-link"><a class="ms-HorizontalNavItem-link is-not-selected siteNavLink-74 linkUnselected-75" href="/Lists/Announcements/All Active Items.aspx" target="_self" rel="noopener" data-navigationcomponent="SiteHeader" tabindex="-1">Announcements</a></span>
<span class="ms-HorizontalNavItem" data-automationid="HorizontalNav-link"><a class="ms-HorizontalNavItem-link is-not-selected siteNavLink-74 linkUnselected-75" href="/resources/Forms/AllItems.aspx" target="_self" rel="noopener" data-navigationcomponent="SiteHeader" tabindex="-1">resources</a></span>
<span class="ms-HorizontalNavItem" data-automationid="HorizontalNav-link"><a class="ms-HorizontalNavItem-link is-not-selected siteNavLink-74 linkUnselected-75" href="/_layouts/15/viewlsts.aspx" target="_self" rel="noopener" data-navigationcomponent="SiteHeader" tabindex="-1">Site contents</a></span>
<div class="ms-HorizontalNavItem" data-automationid="HorizontalNav-edit"><button id="HorizontalNav0EditLink" class="ms-HorizontalNavItem-link siteNavLink-74 ms-HorizontalNavItem-Edit editButton-79" aria-label="Edit site navigation">Edit</button></div>
<div class="ms-HorizontalNavItem" data-automationid="HorizontalNav-edit"><a data-automation-id="button-web-part" href="" target="_blank" class="ms-Button ms-Button--primary root-251" data-is-focusable="true"><span class="ms-Button-flexContainer flexContainer-252" data-automationid="splitbuttonprimary"><span class="ms-Button-textContainer textContainer-253"><span class="ms-Button-label label-254" id="id__141">LEARN MORE</span></span></span></a></div>

</div>

thanks

Re: How to target child nodes in HTML collection

I am new to programming and this is my first question. The problem I am having is I am trying to use DOM manipulation on all the child nodes of an html collection. I am expecting the nodes to change background color when they are hovered. Here is what I have tried so far:


        let x = 0;

do{
    const square = document.createElement("div");
square.className = "squares";
square.setAttribute("id","block");
    document.getElementById("container").appendChild(square);
    x++;
}
while(x < 16);

var container = document.getElementById("container");
var cells = container.childNodes;

cells.forEach(function(){
cells.onmouseover = function(){
cells.style.backgroundColor = "black";
}
});
console.log(`${cells.length}`);

This doesn’t work even though console.log shows 16 child nodes being targeted.

var container = document.getElementById("container");
var cells = container.children[0];
cells.onmouseover = function(){
cells.style.backgroundColor = "black";
}

I have tried this and can use index but of course only that cell will change bg color. I want any cell that is hovered to change also.

I am at a loss for what I am doing wrong here. If anyone can point me in the right direction I would greatly appreciate it.

Getting an error with Possible Unhandled Promise Rejection (id:2)

I’m trying to add a competition to my firebase with uploading and image but I get this error, “Getting an error with Possible Unhandled Promise Rejection (id:2)” and in my terminal it says “[Unhandled promise rejection: ReferenceError: Can’t find variable: ref]”. Does anyone have any ideas about what’s happening?

When I try to display my user’s name it also shows the same error…

Below is my code for my Database.js file where I do the main functionality to upload to firebase.

import { auth, db } from "./firebase";
import  {doc, setDoc, Timestamp, collection, getDoc, getDocs,addDoc, onSnapshot} from 'firebase/firestore';
import { async, querystring } from '@firebase/util';


export const createUserOnRegister = (user, username) => {

    const userRef = doc(db, 'avatars', user.uid);

    const userData = {
        email: user.email,
        username: username,
        uid: user.uid,
        role: 'student',
        dateCreated: Timestamp.fromDate(new Date())
    }

    return setDoc(userRef, userData);
}

export const getAvatar = async () => {

    const userRef = doc(db, "avatars", auth.currentUser.uid);
    const snap = await getDoc(userRef);

  
    let avatar = {...doc.data(), uid: doc.id}
    avatars.push(avatar);

}

export const updateProfile = (uid, data) => {
    const userRef = doc(db, 'avatars', uid)
    return setDoc(userRef, data, {merge: true}) 
}

export const newComp = (comp) => {
    return addDoc( collection(db, 'comps'), comp )
}

export const getAllComp = () => {
    return collection(db, "comps");
}

export const getEntryOffComp = async(id) => {
    let entries = []

    const collectionRef = collection(db, 'comps/' + id + '/entries')
    const collectionSnapshot = await getDocs(collection(db, 'entries'))

    collectionSnapshot.forEach((doc) => {
        entries.push(doc.data());
    })

    return entries

}

export const addEntryToComp = (data, id) => {
    const collectionRef = collection(db, 'comp/' + id + '/entries')

    return addDoc(collectionRef, data)
}

Leetcode 2152, minimum Number of Lines to Cover Points

Here is solution that able to pass all test cases. I tried to convert it to javascript, but it fails this test case

[[-4,0],[0,4],[-1,-5],[2,3],[-4,1],[-4,3],[-1,5]]

If you don’t have access: may have a look at this https://www.geeksforgeeks.org/minimum-lines-cover-points/

class Solution:
    def minimumLines(self, points: List[List[int]]) -> int:
        slope_calc = lambda p1, p2: (p2[1] - p1[1]) / (p2[0] - p1[0]) if p2[0] != p1[0] else math.inf

        def helper(lines, points):
            if len(points) == 0:
                return len(lines)
            
            point = points[0]
            
            
            # add to existing line            
            for p, slope in lines:
                s = slope_calc(point, p)
                if s == slope:
                    return helper(lines, points[1:])
            
            # if we have a single point and it doesn't belong to an existing
            # line, we must have another line to cover it.
            if len(points) == 1:
                return len(lines) + 1

            # creating new line in the case we have two or more points
            # (cover two at once). iterating through all possibilities.
            best = math.inf
            for i in range(1, len(points)):
                p = points[i]
                slope = slope_calc(point, p)
                lines.append((point, slope))
                best = min(best, helper(lines, points[1:i] + points[i + 1:]))
                lines.pop(-1)
            
            return best

        return helper([], points) if len(points) > 1 else 1

Here is my javascript


var cal_slope = function(p2, p1) {
    if(p2 !== p1) {
        return (p2[1] - p1[1]) / (p2[0] - p1[0]);    
    } else {
        return Number.MAX_SAFE_INTEGER;
    }
}

var dfs = function(lines, pts) {
    // base
    if(pts.length === 0) {
        return lines.length;
    }
    
    const curr_pt = pts[0];
    
    // existing can cover?
    for(let i=0; i<lines.length; ++i) {
        const line_pt = lines[i][0];
        const line_slope = lines[i][1];
        
        const new_slope = cal_slope(line_pt, curr_pt);
        if(new_slope === line_slope) {
            // can cover
            return dfs(lines, pts.slice(1));
        }
    } // el
    
    // cannot cover
    if(pts.length === 1) {
        return lines.length + 1;
    }
    
    
    let best = Number.MAX_SAFE_INTEGER;
    
    // form new slope
    for(let i=1; i<pts.length; ++i) {
        const pt = pts[i];
        const new_slope = cal_slope(pt, curr_pt);
        
        const line1 = lines.slice(0);
        line1.push([curr_pt, new_slope]);
        
        const p1 = pts.slice(1, i);
        const p2 = pts.slice(i+1);
        const newPts = [...p1, ...p2];
        
        best = Math.min(best, dfs(line1, newPts));
    } // el
    
    return best
}

var minimumLines = function(pts) {
    if(pts.length === 1) {
        return 1;    
    } else {
        return dfs([], pts);
    }
};

I’m trying to redirect the js file using router in react js and bootstrap but unable to redirect

/* this is for my portfolio i want to redirect to main page after a short video*/

//importing packages as required

        import './App.css';
        import React from 'react';
        import Vid from './assets/codingmonkeyvid.mp4'
        import {BrowserRouter, Routes, Route} from 'react-router-dom'
        import Secondary from './Secondary'
    

// creating function to which it can redirect

        function Redirect() {
          return(
            <>
              <BrowserRouter>
                <Routes>
                  <>
                    <Route path = '/' element = {<Secondary />}></Route>
                  </>
                </Routes>
              </BrowserRouter>
            </>
          );
        }
    

//setting interval to redirect

        setInterval(() => {
          Redirect()
        }, 5000);
        

//maincode

        function App() {
          return(
            <div>
              <center>
                <video src={Vid} autoPlay muted id='myVid'></video>
              </center>
            </div> 
          )
        }
       

//end of code

        export default App;

Why is returning NextResponse.next() throwing a TypeError in Next.js middleware?

I’m trying to implement simple middleware for auth routes in Next.js 12.1.6. It’s supposed to check for authentication headers, validate tokens and proceed accordingly.

Looking at some examples online, seems like it should return NextResponse.next() to proceed (like calling next() in Express) and new Response() if we don’t want the request to complete. Returning new Response() is working fine but NextResponse.next() throws TypeError: resolver is not a function

import { NextFetchEvent, NextRequest, NextResponse } from "next/server"

const authMiddleware = async (req: NextRequest, ev: NextFetchEvent) => {
    if (validated) {
       return NextResponse.next()
     } else {
       return new Response("Unauthorized")
     } 
    }
export default authMiddleware

I have tried NextResponse.rewrite() using req.page.name but using a dynamic url doesn’t work. NextResponse.redirect() creates an infinite loop.

I’m confused as to why NextResponse.next() is not working for me, and would really appreciate help with implementing next(). Thank you.

How to each tab/link can be clicked to show the respective section?

i wrote this code but i think it’s problably not the efficient way. is there a more efficient way to write this code to have this?

The link contains the class active when it is active. When a new link is clicked we remove the active class from all other links.
The div with the correct content is shown. All the rest will be hidden. <

  //html 
  <div id="group3">
    <p>You can view the groupresults here and edit the results if needed. Save them rework them later.</p>
    <!-- Dummy tabel. Verwijder na feature uitwerken-->
    <table class="table">
      <thead>
        <tr class="info">
          <th></th>
          <th>February</th>
          <th>March</th>
          <th>April</th>
          <th>May</th>
          <th>June</th>
          <th>July</th>
          <th>August</th>
        </tr>
      </thead>
      <tbody id='mytable'>
      </tbody>
    </table>
</div>

<div id="individual">
    <p>You can view the individualresults here.</p>
    <select id="list" class="form-select">
      <option selected>Open this select menu</option>
      </select>
    <br><br>

    <div class="card" style="width: 18rem;">
      <div class="card-body">
        <h5 class="card-title" id="name">Voorbeeld Naam</h5>
        <h6 class="card-subtitle mb-2 text-muted" id="functie">Functie</h6>
        <p class="card-text" id="hobby">Hobbies: </p>
        <p class="card-text" id="scores">1 2 3 4 5 6 7 </p>

      </div>
    </div>
    <br>
    <canvas id="scorechart" width="400" height="200"></canvas>

</div>

<div id="form">
    <p>Enter your own data MENTAL data and review them in the individual tab or group results</p>
    <div id="messages">
    
    </div>

    <form id="newDataForm">
      <div class="input-group">
        <input type="text" id="inputName" class="form-control" placeholder="Name" minlength="2" maxlength="25">
      </div>   
        <div class="input-group" id="dataForm">
          <input type="number" id="input0" class="form-control" placeholder="February" >
          <input type="number" id="input1" class="form-control" placeholder="March" >
          <input type="number" id="input2" class="form-control" placeholder="April" >
          <input type="number" id="input3" class="form-control" placeholder="May" >
          <input type="number" id="input4" class="form-control" placeholder="June" >
          <input type="number" id="input5" class="form-control" placeholder="July" >
          <input type="number" id="input6" class="form-control" placeholder="August" >
        </div>          
      <br>
      <button id="register" type="submit" class="btn btn-primary">Submit your data</button>
    </form>
</div>



  //links
 let grouptab = document.getElementById("grouptab");
 let indvidualtab = document.getElementById("individualtab");
 let formtab = document.getElementById("formtab");

 //set active 
 grouptab.addEventListener('click', function() {
 grouptab.classList.remove('active');
 indvidualtab.classList.remove('active');
 formtab.classList.add('active');

 //hide content
 document.getElementById('group3').style.display ="block";
 document.getElementById('individual').style.display = "none";
 document.getElementById('form').style.display ="none";
 });

 indvidualtab.addEventListener('click', function() {
 grouptab.classList.remove('active');
 indvidualtab.classList.remove('active');
 formtab.classList.add('active');

 //hide content
document.getElementById('group3').style.display ="none";
document.getElementById('individual').style.display = "block";
document.getElementById('form').style.display ="none";
});

formtab.addEventListener('click', function(){

//ative

grouptab.classList.remove('active');
indvidualtab.classList.remove('active');
formtab.classList.add('active');

//hide content

document.getElementById('group3').style.display ="none";
document.getElementById('individual').style.display = "none";
document.getElementById('form').style.display ="block"; 

[when you click on the button, it’s hows only the block which has to be active]]1

How to convert a floating number to fixed floating number using JavaScript

For example, I want to calculate 3/6. 3/6 answer is a 0.5 floating number. When I fixed this number with the javascript toFixed(6) method it returned ‘0.500000’. The problem is that ‘0.500000’ is a string. But I want a floating number with 6 digits after the dot(.). How can I do that? I tried this but it’s won’t work.

parseFloat((3/6).toFixed(6))
//output = 0.5 but i want 0.500000

use sass styles globally in Vue.js

I tried to use sass globally in the vue.js app using this method :

const { defineConfig } = require('@vue/cli-service')
module.exports = {
    css:{
        loaderOptions:{
            sass:{
                data:`@import "@/sass/test.scss";`
            }
        }
    }
}

but in vue.config.js i have these 2 lines of code:

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({transpileDependencies: true})

I’ve tried to put a comma between them and it didn’t work, I’ve also tried to remove the first two lines and it won’t work, I’ve searched but all the results were old,

Add a directive to a programmatically created element in Vue 3 composition API

I’ve got a specific use case where I need to create a number of elements programmatically and give them dynamic tooltips.

This very sadly doesn’t work:

    const newRect = document.createElement("div");
   
    newRect.setAttribute("v-tooltip", "myMessage");

Is this possible? What would be an alternate solution?

I have tried creating wrapper components but those work only if I create a separate Vue instance for them – not possible because of performance reasons.

Hover keyframe values green and red

I’m kind of stuk in a keyframe. I have a table with values from a fetch (json) and i should add a hover when the values is less than 5 in red and starting from 5 in green. This is my code in javascript ->

how do i have to implement the keyframe with it?

 //hover

 let cells = document.querySelectorAll("tbody");
 cells.forEach( el => el.addEventListener('mouseenter', function () {
   if(el.textContent < 5){
     el.classList.add('underfive');
   } else if (el.textContent >=5){
     el.classList.add('abovefive');
   }
 }));

  // reset animationx
  cells.forEach(el => el.addEventListener('mouseleave', function () {
   if(el.textContent < 5){
     el.classList.remove('underfive');
   } else if (el.textContent >=5){
     el.classList.remove('abovefive');
   }
 }));

it should be like this ->

Not working Hoc for my popup. How can I get the common state for two components?

I have a problem, I need to pass the state change functions to two components, but when I specify the state in the HOC, it turns out that each component has its own state, without being tied to the general one. How can this be fixed? And to make a common state for all transmitted components?

This is my HOC component with state

enter image description here

and these are two components to which I connect my HOC, and which have two different states as a result
enter image description here

enter image description here