Maximum update depth exceeded in react native. I’m trying to count how many times map function (loop) executing but it gives this error

I’m trying to count how many times map function (loop) executing?
but it gives this error:

Maximum update depth exceeded. This can happen when a component
repeatedly calls setState inside componentWillUpdate or
componentDidUpdate. React limits the number of nested updates to
prevent infinite loops.

counterFun = () => {
        const { Counter } = this.state;
        this.setState({ Counter: Counter + 1 })
};

something.map((item)=>{
    return(
       this.counterFun();
    )
})

How can I count through map function OR any loop?

Thank you.

I try calling it using a api in laravel, however I always get a syntax error stating “expected expression, got end of script.”

$(function () {
      var table = $('#datatablesSimple').DataTable({
          processing: true,
          serverSide: true,
          method: 'get',
          ajax: "http://127.0.0.1:8000/api/category",
          columns: [
  
              {data: 'DT_RowIndex', name: 'DT_RowIndex'},
  
              {data: 'name', name: 'name'},
  
              {data: 'email', name: 'added_by'},
  
              {data: 'action', name: 'action', orderable: false, searchable: false},
  

I try calling it using a api in laravel, however I always get a syntax error stating “expected expression, got end of script.”

SQL efficiently check if one of a user’s meeting is missing a review with nested relationships

This is my current code to check if a user needs to give a review or not (that works), but it seems a little janky

// This function checks if the user logging in with id has any reviews he needs to fill out
export async function requireUserReviews(id: string) {
    let user = await db.user.findUnique({
        where: {
            id
        },
        include: {
            teacherMeetings: true,
            studentMeetings: true,
            reviewsGiven: true
        }
    })

    if (!user) {
        throw new Error('User not found')
    }

    // An array of all the meetings you need a review for
    let reviews: Meeting[] = []

    const twoHrs = 1000 * 60 * 60 * 2
    user.teacherMeetings.forEach((meeting) => {
        if (
            new Date(meeting.updatedAt) < new Date(Date.now() - twoHrs) &&
            meeting.status !== 'cancelled'
        ) {
            reviews.push(meeting)
        }
    })

    user.studentMeetings.forEach((meeting) => {
        if (
            new Date(meeting.updatedAt) < new Date(Date.now() - twoHrs) &&
            meeting.status !== 'cancelled'
        ) {
            reviews.push(meeting)
        }
    })

    // Filter out all the meetings for which you've already written a meeting for
    reviews = reviews = reviews.filter((meeting) => {
        if (!user) {
            throw new Error('User not found in meeting filter')
        }
        let cond = true

        // Does a linear search from each review given and sees if it's a review for a meeting review you want to give
        user.reviewsGiven.every((review) => {
            if (review.meetingId == meeting.id) {
                cond = false
                return false
            }
            return true
        })

        console.log(meeting.description, cond)
        return cond
    })

    if (reviews.length > 0) {
        console.log('reviews', reviews)
        throw redirect(`/review/${reviews[0].id}`)
    }

    return user
}

Basically what it does is first grab the user from the id of the user. This user, I also grab a list of three relationships from this person (teacherMeetings, studentMeetings, and reviewsGiven). teacherMeetings is a list of all meetings this user has done where he was a teacher, studentMeetings is similar, and reviewsGiven is self-explanatory.

Then I go through each teacherMeeting and studentMeeting seeing if the meeting happened more than two hours ago and wasn’t cancelled. The reason I check if it happened two hours ago and not just now is because I don’t want to interrupt someone’s coding flow if they’re in the zone by forcing a review instantly, so I wait two hours.

If the meeting wasn’t cancelled and happened more than two hours ago, I push it to a reviews array. Afterwards, I filter the reviews array and check to see if I’ve already given a review for each review in the review arrays. I check if I’ve already given a review by checking each current element in review with a list of all reviews I’ve already given. If I’ve already given it, return false so filter filters it out. Keep the ones where I haven’t already given a review.

This is basically a o(n*m) sweep right here, n for # of reviews you should give and another m for # of reviews you’ve already given. Both n and m are equal if you’ve successfully given all the reviews you should. O(n^2) solution seems very janky, I was wondering if you had any better ideas?

In meeting, I have a relation for reviews[] but I can’t access meeting.reviews since reviews[] is a relation but taking advantage of this turns the o(n^2) mess into just o(1) since there’s only at most two reviews.

I could potentially also take the list of meetings and then for each meetingRequest do a database call and get the list of meetings, but then it becomes n database calls instead of just one, so even though it’s only o(n) * 2 (2 since each reviews only has at most 2 elements), it’s n database calls which may be costly.

What should I do?

Read Gmail JavaScript API no work | Failed to execute ‘atob’

I have a problem with displaying decrypted messages using the Gmail API, can someone help me and explain how to do it to make everything work properly.

The error that is displayed to me: Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.

My testing page:
https://apps.klubuntu.eu.org/dev/gapi/browser-samples-master/gmail/quickstart/

PS: Sorry for all grammar mistakes, i am not very advanced in English yet

I’m try decrypt messages using atob & i’m try split messages and use atob.

Show notifications and then remove the alert

I have a page with several menu items. With the exception of the Notifications page, if I am on any page and I receive a notification, for example my score is above 70%, the Notifications menu item indicates that I have received a notification by changing the notification text to red letters.
By default, all menu item letters are white.
In php, after the query and calculation, when the score reaches 70%, the notification menu item changes to red. I want when I open the notifications page, the notification menu item to change from red to white.
When the calculation score reaches 80%, the notification menu item should turn red again. And it should be white again when I open the notifications menu.
So it should work on a similar principle to a chat application, when I get a message it should indicate, and when I open it, it should no longer indicate that I have received a message.
My problem is that although the notification menu item turns white when I open it, when I open another page it turns red again.
So, staying with the chat app example, if I open my message and exit or go to another page, it doesn’t indicate that I’ve received a message because I’ve already opened it.
Here is my code:

example.php:

<body>

                <nav id="nav">                    

                    if ($percentage_result >= 70) {

                        echo   "<a href='notifications.php' class='iconText notofication_display_red' id='notofication_display'><i class='bx bxs-bell menuIcon'></i><span class='menu_group'>Notifications</span></a>";
                    } else {
                        echo "<a href='notifications.php' class='iconText class='bx bxs-bell menuIcon'></i><span class='menu_csoport'>Notifications</span></a>";
                    }
                    ?>

                </nav>

    <!--=============== script ===============-->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="../js/notifications.js"></script>
   
</body>

notifications.js:

window.addEventListener('load', () => {

    const activeStite = window.location.pathname;        
    if (activeStite === "/example/php/notifications.php") {
        var indicator = document.getElementById("notofication_display");
        indicator.classList.remove("notofication_display_red");
        indicator.classList.add("notofication_display_white");
    }

});

menu.css:

.notofication_display_red {
    color: red;    
}

.notofication_display_white {
    color: white;
}

How I calculated the 70 or 80 percent, I didn’t write that down because it’s not relevant to my current problem.
I hope I have made myself clear and if I get a reply then thank you very much.

How to return result of Promise with a custom Blazor event javascript (not async)?

I know there are similar questions – scripts can log the result of a Promise to the console, but the returned result is undefined – but the answers are to call the promise function from an async function (and many answers have comments that they don’t work). Since my “calling” script is for an event, I don’t see how to make it async. So event execution continues without waiting for the result. I’ve tried assigning to a top level variable with same result. The custom event is fired by a browser event, and the args are returned to a method in the razor page. I’d like to send imageB64string (or globalimagevar) as a return arg. This is for Net6 Blazor WASM (and Server once it works) apps.

let globalimagevar = "";

async function func1(fileParam) {
    await blobToBase64(fileParam).then(result => {
        console.log("logged from func1: " + result);
        console.log("result displays correcly in console");
        globalimagevar = result;
        return result;
    });
}

function blobToBase64(blob) {
    const reader = new FileReader();
    reader.readAsDataURL(blob);
    return new Promise((resolve, _ ) => {
        reader.onloadend = () => {
            resolve(reader.result);};});}

Blazor.registerCustomEventType("pastemultimedia", {
    browserEventName: 'paste', createEventArgs: event => {
        let isMultimedia = false;
        let data = event.clipboardData.getData('text');
        let imageB64string = "";
        const items = event.clipboardData.items;
        const acceptedMediaTypes = ["image/png"];

        for (let i = 0; i < items.length; i++) {
            const file = items[i].getAsFile();

            if (!file) { continue; }
            if (!items[i].type.includes('image')) { continue; }
            if (acceptedMediaTypes.indexOf(items[i].type) === -1) { continue; }

            isMultimedia = true;
            const url = window.URL || window.webkitURL;
            data = url.createObjectURL(file);

            imageB64string = func1(file).toString;
            console.log("imageB64string is: " + imageB64string);
            console.log("globalimagevar is: " + globalimagevar);
        }
        return { isMultimedia, data, imageB64string };
     }
})

Result:
imageB64string is: function toString() { [native code] }

ImagePasteEvent.js:40 globalimagevar is:

ImagePasteEvent.js:5 logged from func1: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVEAAAHaCAYAAAC5AXpZAAAgAElEQVR4nO3df3xU9YHv/xfJYZiEiTNhJmbCBJliiMFgDBo2CroGBbGyUlqxtqDfsqU+9F573W6rbRd7v9r7uHXd1nZdv2VXH1y37u1qa6tbyi60FCpxKWiWKJESDRBoEEISMyETMwzDMAnfP2byexICn0B….

My variable isn’t working how it’s supposed to for one function only

Ok so basically, I’m making a calculator which is not yet finished and I am encountering some problems. So I made a % option and so after clicking on that button, the code for taking the second number which will be (x/100 * y) y in that formula doesn’t work. So, according to the code here:
if (operator === "%" && number1 != null) { takeNumber2 = true }
the takeNumber2 should be true which it is (according to the console) but upon taking a value for number2, the code doesn’t work as it should because of
if (number1 !== null && operator !== null && number2 === null || takeNumber2 === true) { number2 = 0; } else if (number2 !== null && number1 !== null && operator !== null || takeNumber2 === true) { number2 = number2 * 10 + 0; }
now in theory because of this code, if number2 has a value of null, it just takes the value as the button has been pressed (in this case 0) which works, but it also says that if number2 does have a value which isn’t null then number2 should be number2 * 10 + the button pressed (in this case: 0), however, this does not work ONLY for this percent function. It works for all other functions. Any ideas/suggestions on how to fix this?

Here’s my code:

index.html:

`

<!DOCTYPE html>
<html>
    <head> 
        <title> Calculator (Scientific + Geometrical) </title>
        <link rel="stylesheet" href="./style.css">
    </head>
    <body>
        <script src="./index.js"> </script>

        <h1> Calculator (Scientific + Geometrical) </h1>

        <br>

        <button type="button" onclick="key0();" class="button"> 0 </button>
        <button type="button" onclick="key1();" class="button"> 1 </button>
        <button type="button" onclick="key2();" class="button"> 2 </button>
        <button type="button" onclick="key3();" class="button"> 3 </button>
        <button type="button" onclick="key4();" class="button"> 4 </button>
        <button type="button" onclick="key5();" class="button"> 5 </button>
        <button type="button" onclick="key6();" class="button"> 6 </button>
        <button type="button" onclick="key7();" class="button"> 7 </button>
        <button type="button" onclick="key8();" class="button"> 8 </button>
        <button type="button" onclick="key9();" class="button"> 9 </button>

        <br> <br>

        <button type="button" onclick="add();" class="button"> + </button>
        <button type="button" onclick="subtract();" class="button"> - </button>
        <button type="button" onclick="multiply();" class="button"> * </button>
        <button type="button" onclick="divide();" class="button"> / </button>
        <button type="button" onclick="equals();" class="button"> = </button>

        <br> <br>

        <button type="button" onclick="pi();" class="button"> π </button>
        <button type="button" onclick="root();" class="button"> √ </button>
        <button type="button" onclick="power();" class="button"> ^ </button>
        <button type="button" onclick="percent();" class="button"> % </button>

        <br> <br>

        <button type="button" onclick="location.reload();" class="button"> AC </button>
        </div>
    </body>
</html>

`

style.css

`

body {
    background-color: black;
}

h1 {
    color: white;
    text-align: center;
}

.button {
    font-size: 150%;
    width: 5%;
}
.button:hover {
    color: red;
    font-size: 175%;
    width: 7.5%;
}

`

index.js:

`

let number1 = null;
let number2 = null;
let operator = null;
let result = null;
let takeNumber2 = false;

function key0() {
    if (number1 === null && operator === null) {
        number1 = 0;
    } else if (number1 !== null && operator === null) {
        number1 = number1 * 10 + 0;
    }

    if (number1 !== null && operator !== null && number2 === null || takeNumber2 === true) {
        number2 = 0;
    } else if (number2 !== null && number1 !== null && operator !== null || takeNumber2 === true) {
        number2 = number2 * 10 + 0;
    }
}
function key1() {
    if (number1 === null && operator === null) {
        number1 = 1;
    } else if (number1 !== null && operator === null) {
        number1 = number1 * 10 + 1;
    }

    if (number1 !== null && operator !== null && number2 === null || takeNumber2 === true) {
        number2 = 1;
    } else if (number2 !== null && number1 !== null && operator !== null || takeNumber2 === true) {
        number2 = number2 * 10 + 1;
    }
}
function key2() {
    if (number1 === null && operator === null) {
        number1 = 2;
    } else if (number1 !== null && operator === null) {
        number1 = number1 * 10 + 2;
    }

    if (number1 !== null && operator !== null && number2 === null || takeNumber2 === true) {
        number2 = 2;
    } else if (number2 !== null && number1 !== null && operator !== null || takeNumber2 === true) {
        number2 = number2 * 10 + 2;
    }
}
function key3() {
    if (number1 === null && operator === null) {
        number1 = 3;
    } else if (number1 !== null && operator === null) {
        number1 = number1 * 10 + 3;
    }

    if (number1 !== null && operator !== null && number2 === null || takeNumber2 === true) {
        number2 = 3;
    } else if (number2 !== null && number1 !== null && operator !== null || takeNumber2 === true) {
        number2 = number2 * 10 + 3;
    }
}
function key4() {
    if (number1 === null && operator === null) {
        number1 = 4;
    } else if (number1 !== null && operator === null) {
        number1 = number1 * 10 + 4;
    }

    if (number1 !== null && operator !== null && number2 === null || takeNumber2 === true) {
        number2 = 4;
    } else if (number2 !== null && number1 !== null && operator !== null || takeNumber2 === true) {
        number2 = number2 * 10 + 4;
    }
}
function key5() {
    if (number1 === null && operator === null) {
        number1 = 5;
    } else if (number1 !== null && operator === null) {
        number1 = number1 * 10 + 5;
    }

    if (number1 !== null && operator !== null && number2 === null || takeNumber2 === true) {
        number2 = 5;
    } else if (number2 !== null && number1 !== null && operator !== null || takeNumber2 === true) {
        number2 = number2 * 10 + 5;
    }
}
function key6() {
    if (number1 === null && operator === null) {
        number1 = 6;
    } else if (number1 !== null && operator === null) {
        number1 = number1 * 10 + 6;
    }

    if (number1 !== null && operator !== null && number2 === null || takeNumber2 === true) {
        number2 = 6;
    } else if (number2 !== null && number1 !== null && operator !== null || takeNumber2 === true) {
        number2 = number2 * 10 + 6;
    }
}
function key7() {
    if (number1 === null && operator === null) {
        number1 = 7;
    } else if (number1 !== null && operator === null) {
        number1 = number1 * 10 + 7;
    }

    if (number1 !== null && operator !== null && number2 === null || takeNumber2 === true) {
        number2 = 7;
    } else if (number2 !== null && number1 !== null && operator !== null || takeNumber2 === true) {
        number2 = number2 * 10 + 7;
    }
}
function key8() {
    if (number1 === null && operator === null) {
        number1 = 8;
    } else if (number1 !== null && operator === null) {
        number1 = number1 * 10 + 8;
    }

    if (number1 !== null && operator !== null && number2 === null || takeNumber2 === true) {
        number2 = 8;
    } else if (number2 !== null && number1 !== null && operator !== null || takeNumber2 === true) {
        number2 = number2 * 10 + 8;
    }
}
function key9() {
    if (number1 === null && operator === null) {
        number1 = 9;
    } else if (number1 !== null && operator === null) {
        number1 = number1 * 10 + 9;
    }

    if (number1 !== null && operator !== null && number2 === null || takeNumber2 === true) {
        number2 = 9;
    } else if (number2 !== null && number1 !== null && operator !== null || takeNumber2 === true) {
        number2 = number2 * 10 + 9;
    }
}

function add() {
    if (operator === null && number1 !== null) {
        operator = "+";
    }
}
function subtract() {
    if (operator === null && number1 !== null) {
        operator = "-";
    }
}
function multiply() {
    if (operator === null && number1 !== null) {
        operator = "*";
    }
}
function divide() {
    if (operator === null && number1 !== null) {
        operator = "/";
    }
}
function equals() {
    if (number1 !== null && number2 !== null && operator !== null) {
        if (operator === "+") {
            result = number1 + number2;
            alert("The answer is " + result);
            number1 = null;
            number2 = null;
            operator = null;
        }
        if (operator === "-") {
            result = number1 - number2;
            alert("The answer is " + result);
            number1 = null;
            number2 = null;
            operator = null;
        }
        if (operator === "*") {
            result = number1 * number2;
            alert("The answer is " + result);
            number1 = null;
            number2 = null;
            operator = null;
        }
        if (operator === "/") {
            result = number1 / number2;
            alert("The answer is " + result)
            number1 = null;
            number2 = null;
            operator = null;
        }
        if (operator === "root") {
            result = Math.pow(number1, 1/number2);
            alert("The answer is " + result);
            number1 = null;
            number2 = null;
            operator = null;
        }
        if (operator === "power") {
            result = Math.pow(number1, number2);
            alert("The answer is " + result);
            number1 = null;
            number2 = null;
            operator = null;
        }
        if (operator === "%") {
            result = number1 / 100 * number2;
            alert("The answer is " + result);
            number1 = null;
            number2 = null;
            operator = null;
        }
    }
}

function pi() {
    if (number1 === null) {
        number1 = Math.PI;
    }
    if (number1 !== null && operator !== null && number2 === null) {
        number2 = Math.PI;
    }
}
function root() {
    operator = "root";

    if (operator === "root" && number1 !== null) {
        takeNumber2 = true;
    }
}
function power() {
    operator = "power";

    if (operator === "power" && number1 !== null) {
        takeNumber2 = true;
    }
}
function percent() {
    operator = "%";

    if (operator === "%" && number1 != null) {
        takeNumber2 = true;
    }
}

setInterval(function() {
    console.log("Number 1: " + number1);
    console.log("Number 2: " + number2);
    console.log("Operator: " + operator);
    console.log("Take Number 2: " + takeNumber2);
}, 10000)

`

Redirect to a section of a web page using spring

I would like to know if it is possible to redirect from a web page to another web page (to a specific section within it, with a tag), but that the call to this second web page would go through spring boot and be returned with Spring MVC and a thymeleaf template.
In other words, if it is possible to tell spring to return a web page (I know how to do it) and redirect you to a specific section within it.

What I want to make is an application that sends you notifications of certain events, such as receiving a message in a chat, that you have been sent a request, you have been invited to an event in the calendar…. And I want the notifications to contain a link to the section of the mainhub related to that notification.

Checking for duplicate property values in an array of nested objects

I have a JSON file with an array that has nested objects and arrays that simulates a shopping cart. I want to check for duplicate values and if there are any, update the quantity value of the item otherwise, just add the items to the cart.

Here is the JSON file:

[
    {
        "email": "[email protected]",
        "status": "OPEN",
        "items": [
            {
                "name": "hamster",
                "quantity": 2,
                "price": 20
            },
            {
                "name": "saw dust",
                "quantity": 1,
                "price": 20
            },
            {
                "name": "hamster-cage",
                "quantity": 1,
                "price": 150
            },
            {
                "name": "book: how to care for your hamster",
                "quantity": 1,
                "price": 150
            },
            {
                "name": "hamster-cage",
                "quantity": 1,
                "price": 150
            }
        ]
    }
]

And here is what I have done so far:

const data = require("./data.json");

function checkIfPresent(key){
    let ans = data.findIndex((obj) => Object.values(obj).includes(key))
    return ans;
}

for(let x = 0; x < data.length; x++)
{
    let arr;
    if(checkIfPresent(data[x].items)){
        arr[ans].quantity += data[x].items.quantity;
    }else{
        arr.push(data[x].items);
    }
}

The code does not work the way it’s supposed to, please help.

MissingRequiredParameter: Missing required key ‘Bucket’ in params

I’m working on a project and used AWS to store user’s uploads. When I test the route on my localhost, it works as intended, but testing the upload route from my deployed site gives me the following error and I’m not sure why:

2022-04-02T13:43:24.562294+00:00 app[web.1]: node:internal/process/promises:279

2022-04-02T13:43:24.562296+00:00 app[web.1]: triggerUncaughtException(err, true /* fromPromise */);

2022-04-02T13:43:24.562298+00:00 app[web.1]: ^

2022-04-02T13:43:24.562298+00:00 app[web.1]:

2022-04-02T13:43:24.562298+00:00 app[web.1]: MissingRequiredParameter: Missing required key ‘Bucket’ in params

2022-04-02T13:43:24.562299+00:00 app[web.1]: at ParamValidator.fail (/app/node_modules/aws-sdk/lib/param_validator.js:50:37)

2022-04-02T13:43:24.562305+00:00 app[web.1]: at ParamValidator.validateStructure (/app/node_modules/aws-sdk/lib/param_validator.js:62:14)

2022-04-02T13:43:24.562305+00:00 app[web.1]: at ParamValidator.validateMember (/app/node_modules/aws-sdk/lib/param_validator.js:89:21)

2022-04-02T13:43:24.562306+00:00 app[web.1]: at ParamValidator.validate (/app/node_modules/aws-sdk/lib/param_validator.js:34:10)

2022-04-02T13:43:24.562306+00:00 app[web.1]: at Request.VALIDATE_PARAMETERS (/app/node_modules/aws-sdk/lib/event_listeners.js:132:42)

2022-04-02T13:43:24.562307+00:00 app[web.1]: at Request.callListeners (/app/node_modules/aws-sdk/lib/sequential_executor.js:106:20)

2022-04-02T13:43:24.562314+00:00 app[web.1]: at callNextListener (/app/node_modules/aws-sdk/lib/sequential_executor.js:96:12)

2022-04-02T13:43:24.562315+00:00 app[web.1]: at /app/node_modules/aws-sdk/lib/event_listeners.js:86:9

2022-04-02T13:43:24.562315+00:00 app[web.1]: at finish (/app/node_modules/aws-sdk/lib/config.js:396:7)

2022-04-02T13:43:24.562315+00:00 app[web.1]: at /app/node_modules/aws-sdk/lib/config.js:414:9 {

2022-04-02T13:43:24.562316+00:00 app[web.1]: code: ‘MissingRequiredParameter’,

2022-04-02T13:43:24.562316+00:00 app[web.1]: time: 2022-04-02T13:43:24.558Z

2022-04-02T13:43:24.562316+00:00 app[web.1]: }

2022-04-02T13:43:24.589668+00:00 heroku[router]: at=error code=H13 desc=”Connection closed without response” method=POST path=”/api/photos/upload” host=nameless-harbor-84311.herokuapp.com request_id=0818f822-84ba-495f-a270-085fb2173a30 fwd=”76.183.71.226″ dyno=web.1 connect=5001ms service=207ms status=503 bytes=0 protocol=https

2022-04-02T13:43:24.769585+00:00 heroku[web.1]: Process exited with status 1

2022-04-02T13:43:24.819056+00:00 heroku[web.1]: State changed from up to crashed

I tried including the S3 bucket name in the S3 config and I expected it to work as the error said it was missing the bucket name, but i received the same error.

Is there a way for nodejs’ “net” module to determine if a data packet is the last packet in a sequence?

I’m getting a large amount of json data from a TCP Server. I can successfully connect to the server with nodejs’ “net” module and send the packet to request the data from it. The server sends the data back in packets, of course, so I have a listener which gets the string data from each packet and stores it in a string buffer.

screenshot of described code

The issue is that net’s data event doesn’t offer any indication of whether a packet is the last packet in the sequence or not. In Wireshark, I can clearly see that the last packet is the one with the PSH flag:

screenshot of described wireshark packet

but there’s no way to look at flags or packet details with net, only data.

I looked within the net documentation for other events which might indicate the last packet in the sequence. I tried using the end event, but this was not correct. I took every event in the documentation and put a simple event listener on it to log when it was fired, and the only one which fired at the last packet was the data event. I tried seeing if maybe there were a few extra bytes in the data which contained extra details, but net only returns data. I tried looking into net’s source code, but I’m too inexperienced to figure out the problem from there.

This might be a dumb question, but I’m just too inexperienced with net to figure out how to do this, and every simple tutorial for a TCP client in node js just says that you can listen for data packets with the data event. If nothing else works, I can just look for the packet whose last character is a ‘}’ to indicate the end of the JSON object, but I imagine this could cause bigger issues down the road.

three.js particle sphere display nothing on page with useEffect

I am trying to create a sphere with particles filled on its surface. It will move depends on the position on mousemove.

Strangely, it is not displayed on my webpage. I do see the div in the elements in developer tool.

I have tried:

  1. add camera to scene
  2. increase camera distance camera.position.z
  3. change background color with setClearColor()
  4. increase the size of particles on the sphere
useEffect(() => {
        const scene = new THREE.Scene();
        document.addEventListener("mousemove", onMouseMove, false);
        const camera = new THREE.PerspectiveCamera(
            75,
            window.innerWidth / window.innerHeight,
            0.1,
            1000
        );
        let mouseX;
        let mouseY;

        const renderer = new THREE.WebGLRenderer({ alpha: true });
        renderer.setClearColor(0xffffff, 1);
        renderer.setSize(window.innerWidth, window.innerHeight);

        sphereRef.current.appendChild(renderer.domElement);

        window.addEventListener("resize", function () {
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize(window.innerWidth, window.innerHeight);
        });

        const distance = Math.min(200, window.innerWidth / 4);
        const geometry = new THREE.BufferGeometry();

        for (let i = 0; i < 1600; i++) {
            var vertex = new THREE.Vector3();

            // var theta = THREE.Math.randFloatSpread(360);
            var theta = Math.acos(THREE.Math.randFloatSpread(2));
            var phi = THREE.Math.randFloatSpread(360);

            vertex.x = distance * Math.sin(theta) * Math.cos(phi);
            vertex.y = distance * Math.sin(theta) * Math.sin(phi);
            vertex.z = distance * Math.cos(theta);

            geometry.setFromPoints(vertex);
            geometry.computeVertexNormals();
        }

        //setting particles color and size
        var particles = new THREE.Points(
            geometry,
            new THREE.PointsMaterial({ color: 0x000000, size: 5 })
        );
        particles.boundingSphere = 50;

        //adding particles to group for sphere
        var renderingParent = new THREE.Group();
        renderingParent.add(particles);

        var resizeContainer = new THREE.Group();
        resizeContainer.add(renderingParent);
        scene.add(resizeContainer);


        camera.position.z = 200;
        scene.add(camera);


        var animate = function () {
            requestAnimationFrame(animate);
            renderer.render(scene, camera);
        };

        function onMouseMove(event) {

            mouseX = (event.clientX / window.innerWidth) * 2 - 1;
            mouseY = -(event.clientY / window.innerHeight) * 2 + 1;
            myTween = gsap.to(particles.rotation, {
                duration: 0.1,
                x: mouseY * -1,
                y: mouseX,
            });
        }

        animate();

        return () => sphereRef.current.removeChild(renderer.domElement);
    })
<div className="sphere" id='sphere' ref={sphereRef}></div>

Why does it say “CSSLayerBlockRule” in Chrome Console?

I am working on a typical “snake” game in js, and came across the following output on Chrome’s console:

console output

The prints from my script are working fine, but I cannot find any documentation on the last two lines. They do not seem like errors to me, but what are they?

EDIT: Since i got some downvotes, could someone point out my mistake in asking this question?

how to fix chrome tab delete extension?

I am trying to make this extension delete this specific tab, but its not working.
Here is my backround.js

chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(tab.id, {file: "bookmarklet.js"})
chrome.tabs.getCurrent(function(tab) {
    chrome.tabs.remove(tab.id, function() { });
});

});

Here is my bookmarklet.js

if (window.location.href.indexOf(“unblocked”, “games”, “1v1”, “smash carts”, “slope unblocked”, “retrobowl”,) > -1) {
alert(“You are not supposed to be on the website. You will be reported to an adminstrator immediatly.”);
console.log(window.location.href)
chrome.tabs.getCurrent(function(tab) {
chrome.tabs.remove(tab.id, function() { });
});

How do I fix this? Thanks