Video transfer from server to client

I don’t know if this is possible or not, if possible then please do let me know.
I want to transfer chunks of files/videos by using custom .gz files and then unzip them using js for streaming on the site.

Any help or discussion regarding this will be appreciated.

Hide reCaptcha response in the front-end

I need to rearrange conditions to hide the reCaptcha response in the front end, as shown in the image below:

enter image description here

I have the following function:

function my_contact_form_generate_response($type, $message){
 
    global $response;
 
    if($type == "success") $response = "<div class='alert alert-primary' role='alert'>{$message}</div>";
    else $response = "<div class='alert alert-danger' role='alert'>{$message}</div>";
    }

reCaptcha response

$request = "https://www.google.com/recaptcha/api/siteverify?secret={$secretkey}&response={$recaptchaResponse}&remoteip={$userIp}";
$content = file_get_contents($request);
$json = json_decode($content);

Conditionals are:

if ($json->success == "true") {
  
  
          //validate email
      if(!filter_var($email, FILTER_VALIDATE_EMAIL)) 
        my_contact_form_generate_response("error", $email_invalid);
      else //email is valid
      {
        //validate presence of name and message
        if(empty($name) || empty($message)){
          my_contact_form_generate_response("error", $missing_content);
        }
        else //ready to go!
        {
          $sent = wp_mail($to, $subject, strip_tags($admin_email), $headers);
          if($sent){
              my_contact_form_generate_response("success", $message_sent); //message sent!
              $_POST = array();
          } 
          else {
             my_contact_form_generate_response("error", $message_unsent); //message wasn't sent 
          } 
        }
        
      
      }
  
} else {
  
  my_contact_form_generate_response("error", $recap_invalid);
}

How can I re-arrange my conditions to hide the failed ReCaptcha error message and only display it if it fails after submitting the form?

Thank you in advance.

Can’t Get My Discord Bot To Play Music (Discord.js)

I’m trying to get my discord bot to play music, but no sound comes through after it joins the channel. I am new to making bots and I’ve spent quite a while trying to make sure I have all the necessary dependencies.

Code:

    const member = interaction.member
    const channel = member.voice.channel

    /* Channel */

    interaction.reply({
        content: 'Joining channel now.',
        ephemeral: true
    })

    if (!(channel instanceof VoiceChannel)) {
        interaction.reply({
            content: 'You need to be in a voice channel!',
            ephemeral: true
        })

        return
    }

    const connection = joinVoiceChannel({
        channelId: channel.id,
        guildId: channel.guild.id,
        adapterCreator: channel.guild.voiceAdapterCreator
    })

    /* Audio Player */

    const audioPlayer = createAudioPlayer({
        behaviors: {
            noSubscriber: NoSubscriberBehavior.Play
        }
    })

    /* Subscription */

    await new Promise(resolve => setTimeout(resolve, 2000))

    interaction.editReply('Playing music now')

    connection.subscribe(audioPlayer)

    const resource = createAudioResource(join(__dirname, 'song.mp3'))
    audioPlayer.play(resource)

Dependencies:


Core Dependencies

  • @discordjs/voice: 0.10.0-dev
  • prism-media: 1.3.4

Opus Libraries

  • @discordjs/opus: 0.8.0
  • opusscript: 0.0.8

Encryption Libraries

  • sodium-native: not found
  • sodium: not found
  • libsodium-wrappers: 0.7.10
  • tweetnacl: not found

FFmpeg

  • version: 2022-07-14-git-882aac99d2-full_build-www.gyan.dev
  • libopus: yes

Trouble saving edited task into local browser storage

I have a to do app with an edit button that edits the existing task. After editing the task, the value changes to a new edited task. However, it changes back to its old value upon creating a new task or refreshing. I tried setItem however it doesn’t seem to work. Below is what i currently tried with the editItem() function.

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>To-Do List</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
    <link rel="stylesheet" href="./style.css">
</head>
<body>

    <div class="container">
        <div class="row mb-5">
            <div class="col h1 text-white text-start text-center text-md-start text-lg-start">TO-DO APP</div>
        </div>

        <div class="row">
            <div class="h6 text-white text-start text-center text-md-start text-lg-start">CREATE A TO-DO</div>
        </div>

        <form id="todo-form">
            <div class="row mb-4">
                <div class="col">
                    <input class="form-control" name="newTask" type="text" placeholder="eg. Do the laundry">
                </div>    
            </div>
   
            <div class="row">
                <div class="h6 text-white text-start text-center text-md-start text-lg-start">CATEGORY</div>
            </div>
   
            <div class="row mb-3">
                <div class="col-6">
                    <input type="radio" class="btn-check" name="category" id="option1" value="Work">
                    <label class="col-12 btn btn-outline-danger p-4 text-white work-task" for="option1">Work</label>
                </div>
                <div class="col-6">
                    <input type="radio" class="btn-check" name="category" id="option2" value="Personal">
                    <label class="col-12 btn btn-outline-primary p-4 text-white personal-task" for="option2">Personal</label>
                </div>
            </div>
   
            <div class="row mb-4">
                <div class="col"><button type="submit" class="btn btn-secondary p-2 w-100 add-task" active>ADD TO-DO</button></div>
            </div>
        </form>

        <div class="row mb-2">
            <div class="h6 text-white text-start text-center text-md-start text-lg-start">TO-DO LIST</div>
        </div>

        <div class="todoList">

        </div>
    </div>
    <script src="main.js"></script>
</body>
</html>

Javascript

const todoForm = document.getElementById("todo-form")

window.addEventListener("load", () => {
    todos = JSON.parse(localStorage.getItem("todos")) || []

    todoForm.addEventListener("submit", (e) => {
        e.preventDefault()
        if (e.target.elements.newTask.value != "") {
            const todo = {
                task: e.target.elements.newTask.value,
                category: e.target.elements.category.value
            }
   
            todos.push(todo);
   
            localStorage.setItem("todos", JSON.stringify(todos));
   
            e.target.reset()
   
            showList()
        }
    })
   
    showList();
})

function showList() {
    let outPut = '';
    let taskListShow = document.querySelector(".todoList")
    const taskName = document.getElementsByClassName('todoContent')

    todos.forEach((data, index)=> {

        outPut += `
        <div class="row todoList mb-3">
            <div class="col-10 col-lg-8 col-md-7 col-sm-6">
                <input class="todoContent no-border text-white w-100" value="${data.task}" readonly>
            </div>
            <div class="col">
                <div class="row action">
                    <div class="col-6">
                        <button type="button" class="btn btn-secondary col-12" onClick="editItem(${index})">Edit</button>
                    </div>
                    <div class="col-6">
                        <button type="button" class="btn btn-danger col-12" onClick="deleteItem(${index})">Delete</button>
                    </div>      
                </div>
            </div>
        </div>`
    });
    taskListShow.innerHTML = outPut;
}

function deleteItem(index) {
    todos.splice(index, 1)
    localStorage.setItem("todos", JSON.stringify(todos))
    showList()
}

function editItem(index) {
    const taskAllName = document.querySelectorAll(".todoContent");
    const taskName = taskAllName[index];
    taskName.removeAttribute("readonly");
    taskName.focus();
    taskName.addEventListener("blur", (e) => {
        taskName.setAttribute("readonly", true);
        taskName = e.target.value;
        localStorage.setItem("todos", JSON.stringify(todos));
        showList()
    });
}

How to open Tom-Select on click, with remote results that reset

I have Tom-Select working with remote data. It works almost perfectly, however, I need it to do 2 things:

  1. Show the Ajax results onClick/onFocus of the select input (currently, results only show after the first letter of the query is typed – I want to show results without a query)

  2. Reload and show the fresh ‘no query’ results again – when clicking after an item has been selected (currently, it shows ‘saved results’ from the previous search, I want to reset and reload every time)

Here is my current code:

var config = {
  plugins: ['clear_button'],
  valueField: 'value',
  load: (q, callback) => this.search(q, callback)
}

async search(q, callback) {
  const response = await get('/search', {
    query: { q: q },
    responseKind: 'json'
  })

  if (response.ok) {
    const list = await response.json
    callback(list)
  } else {
    console.log(response)
    callback()
  }
}

async issues regarding model import using promises and three.js

Im having a problem resolving a promise.

on load my script has a promise that i wish to resolve when a function that contains 3D file imports finishes importing.

the problem im facing is how to make the promises resolve() execute when a model has loaded.

is there a way to get data or any sort of signal from the browser when a model has finished loading?

Empty string data with fetch api

I’m trying to send the form value by formData to my server with fetch(). By right, shouldn’t the form value would be printed in the console ( because of .then(data => { console.log(data); } )? But I only got <empty string> in the console although the server actually received the form value.

Form

<form id="contact-form" method="post">
   <input type="hidden" name="action" value="form_handling">
   <input id="fname" placeholder="First Name" type="text" name="fname">
   <input id="lname" placeholder="Last Name" type="text" name="lname">
   <input id="email" placeholder="Email Address" type="email" name="email">
   <input id="phone" placeholder="Phone Number" type="tel" name="phone">
   <textarea id="message" placeholder="Your Message..." name="message" rows="3"></textarea>
   <input id="submit-form" type="submit" value="Submit"> 
</form>

JavaScript

const contactForm = document.querySelector('#contact-form'),
   btnSubmit = document.querySelector('#submit-form'),
   ajaxData = new FormData(contactForm);

btnSubmit.addEventListener('click', function(e) {
   e.preventDefault();

   fetch('https://local.test/wp-admin/admin-ajax.php', {
      method: 'POST',
      body: ajaxData
   })
   .then( res => res.text() )
   .then( data => {
      console.log(data);
   }).catch( err => {
      console.log(err);
   });
})

Event .key switch for a video game

i want to change the way my Js game works, basically the game does not recognize input whenever the language is not english with no Capital letters ( only when the event.key is equal to wasd ) how can i fix this bug ?
thanks !

window.addEventListener('keydown', (event) => {
    if (!player.isDead){
        switch (event.key) {
            case 'w':
                keys.d.pressed = true;
                player.lastkey = 'd';
                break;

            case 'a':
                keys.a.pressed = true;
                player.lastkey = 'a';
                break;

            case 'w':
                if(player.position.y > 0)
                {
                    player.velocity.y = -10;
                }
                break;
            
            case ' ':
                player.Attacking();
                if(player.lastkey === 'd'){player.SwitchSprite('punch')}
                else{player.SwitchSprite('fpunch')}
                break;
        }
    }

How we sort the data in react [duplicate]

I want to sort the data according to the popularity that is given in the obj

But this is not sorting the obj

I’m using API is data,data.products

import "./styles.css";
import React, { useState, useEffect } from "react";
import axios from "axios";

export default function App() {
  const [data, setData] = useState([]);
  useEffect(() => {
     axios
     .get("https://mindler-dashboard.s3.us-east-2.amazonaws.com/products.json")
     .then((res) => {
     console.log(res.data);
     setData(res.data);
     });
  }, []);

 return (
<div className="App">
  {data.products &&
    Object.keys(data.products)
      .sort((a, b) => b.popularity - a.popularity)
      .map((key) => {
        return (
          <div>
            <h3>{data.products[key].title}</h3>
            <h5>{data.products[key].price}</h5>
            <h5>{data.products[key].popularity}</h5>
          </div>
        );
      })}
</div>
);
}

JaBarcode not show in div generate by JS

I have a barcode and want to display it multiple times to print it out.

When I do add the tag svg from javascript, after generating barcode they don’t show up.

$scope.generatePrintBarcodePage = function (sampleCode, number) {
    $scope.barCodePrint = [];
    var i;
    for (i = 1; i <= number; i++) {
        JsBarcode("#barcode" + i, sampleCode, {
            height: 40,
            displayValue: true
        });
    }
}


$scope.showBarcode = function (sampleCode, number) {
  for (i = 1; i <= number; i++) {      
    const node = document.createElement("svg");
    node.setAttribute("id", "barcode" + i);

    document.getElementById("printPageBarcode").appendChild(node);
    
    JsBarcode("#barcode" + i, sampleCode.SampleCode, {
           
  }
}

Then no barcode is displayed.

But if I pre-create the tag svg on the html file, they are displayed, but if I create it, I have no control over how many barcodes I want to print.

<div id="printPageBarcode" style=" height: 500px;">
    <svg id="barcode1"></svg> <br />
    <svg id="barcode2"></svg>  <br />
    <svg id="barcode3"></svg>  <br />
    <svg id="barcode4"></svg>  <br />
    <svg id="barcode5"></svg> <br />
</div>

How can I add the same barcode multiple time?

How do I form an SQL statement from my question paper

11*)
Endpoint: GET /transfer/flight/:originAirportId/:destinationAirportId
Retrieves data of all flights from origin airport to destination airport with 1 transfer
Request body schema: N/A
Success Response
Code: 201 Created
Content:
[
{
“firstFlightId”: 1,
“secondFlightId”: 3,
“flightCode1”: “SP110”,
“flightCode2”: “SP230”,
“aircraft1”: “BOEING 737”,
“aircraft2”: “BOEING 787”,
“originAirport”: “Changi Airport”,
“transferAirport”: “Narita Airport”
“destinationAirport”: “San Francisco Airport”,

  "Total price”:1855.50

},
…
]

I hope this is enough information

What is the best way to handle numbers with – and . with a controlled input?

I want to save the input in number type every time the value updates. However, with this approach, The value is stuck in NaN or 0 in the scenarios below.

scenario 1: changing 0 to 0.1 (stuck in 0 when ‘0.’ left)

scenario 2: changing -15 to 1 (stuck in NaN when only ‘-‘ left)

What would be the best way to handle these cases when 1) the input has to be controlled element and 2) storing value in string format is not an option?

export default function App() {
  const [input, setInput] = useState(0)

  return (
    <div className="App">
     <input value={input} onChange={(e)=>setInput(parseFloat(e.target.value))}/>
    </div>
  );
}

Is it possible to extract the download syllabus link with python requests or scrapy without selenium

I am trying to extract the download syllabus link from this website-
https://www.simplilearn.com/big-data-and-analytics/python-for-data-science-training

The link is not available on page source, and I was not able to see anything in network tab.
But if we click the link, the link opens in a different tab.

I know, it is possible to extract using selenium, but can we extract without selenium?

enter image description here

the link is hidden with ‘#’ in page source.

So I am not sure, how to extract the links.
I know that I won’t be able to extract using xpath or css.
Can someone help me?

ways of generating random arrays with a button? JS

im a early student and im trying to learn Javascript by myself since in university i only have C. As a side-project im trying to do a password generator, i want to know what are viable ways of generating a random array with elements of other already declared arrays. In other words, i have these arrays:

let upperCase = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"] ;
let underCase = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] ;
let numbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] ;

how would you approach this in Javascript? is it correct to just google some fusion function which mixes everything up or is there a better way? Take in mind that i should be able to constantly press this button and get a new array. They’re in different arrays because i want to add the function to choose whether the password has uppercase/numbers/symbols or not.

react-tsparticles scrolling as background

I would like to use react-tsparticles as a background, and I want it to scroll up as I scroll down. I have found this, but this isn’t exactly what I’m looking for since I want it to extend to the bottom of the page. I have tried adjusting the height of the canvas and div, but I feel like that’s inefficient since it has to load particles for the whole site instead of what’s being viewed. I have also tried adjusting the height of the canvas to the bottom of the page, but keeping the div to the window, but that doesn’t scroll at all.