Range and video are confronting

I am writing a video player. As a timebar I use a range. As video is playing, range is changing too. But I want to change it in the opposite way. I want range make video change its currentTime.
But, because they change each other, I can’t move a thumb. I’d tried setting Interval null but it didn’t work. Give me a hand with this, please.

$(document).ready( function () {
$("#PlayerVideo").on("loadedmetadata", function (event) {
            Video = $("#PlayerVideo")[0];
            
            Duration = Video.duration;
            hours = Math.floor(Duration / 60 / 60);
            mins = Math.floor((Duration - hours * 60 * 60) / 60);
            secs = Math.floor(Duration - mins * 60);
            $("#durTime").html(hours + ":" + mins + ":" + secs);
            
            
            // display cur time 
            Interval = setInterval(
                function () {
                    Play();
                }, 250
            );
        });     

        $("#TimeRange").on("input",
            function()
            {
                $.when().then(
                    function()
                    {
                        Interval = null;
                    }
                ).then(
                    function ()
                    {
                        Video = $("#PlayerVideo")[0];
                        Video.currentTime = $(this).val()*Duration;
                        console.log("cur time is " + Video.currentTime);
                        CurTime = $(this).val()*Duration;
                    }
                ).then(
                    function ()
                    {
                        Interval = setInterval(
                            function () {
                                Play();
                            }, 250
                        );
                    }
                );    
            }
        );

        function Play()
        {
            Video = $("#PlayerVideo")[0];
            CurTime = Video.currentTime;
            console.log(CurTime);
            hours = Math.floor(CurTime / 60 / 60);
            mins = Math.floor((CurTime - hours * 60 * 60) / 60);
            secs = Math.floor(CurTime - mins * 60);
            $("#curTime").html(hours + ":" + mins + ":" + secs);
            $("#TimeRange").val(CurTime / duration * 100);
        }
});

HTML – Text besides div in a line when spaces added

I have html –

https://jsfiddle.net/nko8p6fr/

enter image description here

It can be seen that , in the text – very long text ; there are 2 spaces.

I want long and text to bring in one line.

First line should contain only one word , rest all words in second line.

Something like this –

enter image description here

How can I achieve it?

<div style='padding:12'>
<div style='background-color:red;display:inline-block;height:2.5rem;width:2.5rem;float:left;'>
<span style='vertical-align:middle;float:left;color:black;font-weight:bold;margin-left:20%;margin-top:15%'>7</span><div style='color:black;margin-left:140%;margin-top:3%;vertical-align:middle;width:50%'>very long text</div></div><br><br><br><br>

Note :- These number of <br> are necessary for further blocks to get added and to keep space between them.

test that will check if the function has been executed

I want to write a unit test that checks if the addClass function executes if the conditions are met. Can someone help me? the error I get is:

   expect (received) .toHaveBeenCalled ()
     Matcher error: received value must be a mock or spy function
     Received has value: undefined

A test that doesn’t work for me:

     test ("should add class", () => {
         // given
         const hat = new Hat (true),
             hatWrapper = document.createElement ("div");
             global.scrollY = 500;
             hat.prevAnimationAPosY = 300;
             hat.prevPosY = 200;
         // when
         hat.scrollAnimation (hatWrapper, '400', '200')
         // then
         expect (hat.addClass (hatWrapper)). toHaveBeenCalled ();
     });

https://codepen.io/olivier-mazur/pen/jOZdEQp

digest method cant be used solution

I’ve been getting an error while using Crypto.js and couldn’t figure out why.
I tried to use the createHash.update.digest methods.
After some time I realized that I had a typo but the error that have been thrown was incorrect.
the error was:

“digest method cant be used”

My code was:

this.passwordResetToken = crypto.createHash('sh256').update(resetToken).digest('hex');

The solution to the error was changing the createHash algorithm to the currect one without the typo:

this.passwordResetToken = crypto.createHash('sha256').update(resetToken).digest('hex');

I had a missing ‘a’ in the algorithm name.

Uncaught ReferenceError: GIF is not defined with gif.js

Hey I am trying to use the gif.js together with p5.js in the Processing Launcher.

I have trouble getting gif.js to work in the first place because I get the Uncaught ReferenceError: GIF is not defined
so I am wondering if I have added the Library correctly. I downloaded them from Github and used them like this:

<!-- OK, YOU CAN MAKE CHANGES BELOW THIS LINE AGAIN -->
  <script language="javascript" type="text/javascript" src="libraries/gif.js"></script>
  <script language="javascript" type="text/javascript" src="libraries/gif.worker.js"></script>
  <script language="javascript" type="text/javascript" src="libraries/ready.js"></script>
  <script language="javascript" type="text/javascript" src="libraries/mootools.js"></script>

I am sorry but as being kinda new to all of this, I cannot really work with the minimal Information given on the official GitHub.

This is my current code where the Error persists, whatever I do:

var CanvasElement = this.p5Canvas

var gif = new GIF({
  workers: 2,
  quality: 10
});

// add a canvas element
gif.addFrame(CanvasElement, {delay: 200});

gif.on('finished', function(blob) {
  window.open(URL.createObjectURL(blob));
});

gif.render();

Maybe it is just something so stupid I cannot see it after looking at it for hours 😀
Thanks in advance!

Can I update field of MongoDB by findByIdAndUpdate with “? :” logic?

I use Mongo DB.
I want to update Video model’s show field.

If it is false then true, if else it is true then to false.
So i use this logic false ? true : false.

But it seems not working.

In this case how can I make my purpose?

export const showVideo = async (req, res) => {
  const { id } = req.params;
  await Video.findByIdAndUpdate(id, {
    show: false ? true : false,
  });
  return res.redirect("/video");
};

How to “conventionally” (without class syntax) call a superconstructor that enforces the use of “new”?

I’d like to inherit some class MyClass from some built-in class Class in the conventional way, i.e. without the new “class” syntax. I’m used to the following:

MyClass.prototype = Object.create(Class.prototype);
function MyClass() {
   Class.apply(this, arguments); // calling the superconstructor => "TypeError: Class constructor: 'new' is required"
   ...
}
var myObject = new MyClass(...);

As indicated, for many newer classes, usage of “new” with the constructor is enforced (e.g. for MediaSource). But new will be used with MyClass and will already have created a new object, so that I should not create yet another object inside the constructor. What am I supposed to do, or what is the equivalent here of the super() call in the new class syntax?

The only way I could think of, is to indeed create an instance with new Class() and explicitly return this instance from the constructor. But then the prototype of MyClass (which might have additional properties) is not really used …

getDisplayMedia Screenshot in Safari browser?

This is the code to generate image,

console.log('--imageCapture');
const btn = document.querySelector('#btn')
btn.addEventListener('click',()=>{
  screenshot()
})

function screenshot(){
const canvas = document.createElement("canvas");

// Request media
navigator.mediaDevices.getDisplayMedia().then(stream => 
{
  console.log(stream);
  
  let track = stream.getVideoTracks()[0];
  
  let capture = new ImageCapture(track);
  
  capture.grabFrame().then(bitmap => 
  {
    // Stop sharing
    track.stop();
      
    // Draw the bitmap to canvas
    canvas.width = bitmap.width;
    canvas.height = bitmap.height;
    canvas.getContext('2d').drawImage(bitmap, 0, 0);
      
    const frame = canvas.toDataURL("image/png");
  });
})
.catch(e => {
  console.log(e)});
}

these code runs
It runs perfectly in Chrome, but it can’t running in safari, is there any way to generate image in safari?

Unable to prevent flashing unauthorized content in next.js before redirecting to a route

import JoinComponent from '@/components/join/JoinComponent'
import Footer from '@/components/Layouts/Footer'
import GuestLayout from '@/components/Layouts/GuestLayout'
import Navbar from '@/components/Layouts/Navbar'
import { useAuth } from '@/hooks/auth'
import { useRouter } from 'next/router'

const Join = () => {
    const router = useRouter()
    const { user } = useAuth({
        middleware: 'guest',
        redirectIfAuthenticated: '/',
    })

    if (user !== undefined) {
        return (
            <GuestLayout>
                <title>Join</title>
                <div></div>
            </GuestLayout>
        )
    } else {
        return (
            <GuestLayout>
                <title>Join</title>
                <Navbar />
                <JoinComponent />
                <Footer />{' '}
            </GuestLayout>
        )
    }
}

export default Join

It is supposed to conditionally render the layouts if the user is authenticated but it still renders the else part for a brief amount of time and then redirects to ‘/’.

I am unable to figure out why this is the case.

Is there a Windows 98 themed CSS/JS library that I can use elegantly with Laravel? (solutions that require just Laravel/PHP, and not any .js runtimes)

I’m currently using 98.css, but it’s super limited since it’s only CSS (no JavaScript, and thus not much dynamic content).

I’m currently looking at https://github.com/1j01/os-gui as a possible choice.

Just wondering if there are any others that can work alongside Laravel?

Also, I’m a bit confused as to whether or not these options need a running node.js server. I just want to use Laravel/PHP, and don’t really want the learn the complexities of having to run multiple “servers” if that makes any sense (talking about things like React, Node.js, etc… stuff that needs something running in the background in addition to the PHP server), since I’m running this website alongside other PHP websites via RunCloud on top of a single DigitalOcean droplet.

I hope I made any sense in explaining my thoughts and concerns. Thanks again!

ORA-00936: BAD SQL Grammar

I am trying to debug a failing SQL query within my application.

The following query fails and returns an ORA-00936: BAD SQL Grammar exception

(httpResponse:
{“data”:null,”exception”:”org.springframework.jdbc.BadSqlGrammarException:
StatementCallback; bad SQL grammar)

SELECT SAF.*,round(DBMS_RANDOM.VALUE (1, 20)) rnd FROM
SC_DRIFT.SAFE_DATA_VAGTPLAN SAF, SC_DRIFT.SAFE_SYS_AKTIVITET SAF1
WHERE SAF.AKTIVITET_ID=SAF1.AKTIVITET_ID AND SAF.INITIALER in (SELECT
SAF.INITIALER FROM SC_DRIFT.SAFE_DATA_MEDARBEJDER SAF WHERE
SAF.MED_STEDKODE_ID IN (undefined) AND SAF.INITIALER not in() AND
SAF.INITIALER not in(Select init from SC_DRIFT.SAFE_DATA_VP_KR where
trunc(dato) = trunc(sysdate+0)) AND SAF.STATUS not in (4,6,7) AND
SAF.ROLE_ID not in (4)) AND trunc(SAF.VAGT_DATO) = trunc(sysdate+0)
AND SAF.UGEDAG NOT IN(‘lørdag’,’søndag’) AND SAF.DELETED = 0 and
SAF1.AKTIVITETSKATEGORI in(1) and SAF.GRUPPE_ID in(undefined) and
SAF1.CTI_REQ in(1) order by rnd]; nested exception is
java.sql.SQLSyntaxErrorException: ORA-00936: missing expression n”}

Next JS is loading external script but not executing them

In my next app with the latest version 12.1.6, I’m trying to use bootstrap. I’ve added bootstrap CSS and js files from CDN to the head of pages/_app.js as below,

import '../styles/globals.css'
import Head from 'next/head';

function MyApp({ Component, pageProps }) {
  return (
      <>
      <Head>
        <meta charset="UTF-8"/>
        <meta name="keywords" content="Ogani, unica, creative, html"/>
        <meta name="viewport" content="width=device-width, initial-scale=1"></meta>
        <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
        <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"/>
        <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
        </Head>
      <Component {...pageProps} />
      </>
   );
  }

export default MyApp 

I used bootstrap Nav as below,

 <nav class="navbar navbar-expand-lg navbar-light bg-light">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo03" aria-controls="navbarTogglerDemo03" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="#">Navbar</a>

  <div class="collapse navbar-collapse" id="navbarTogglerDemo03">
    <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search"/>
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

I’ve noticed bootstrap CSS is loaded and executing. But its JS is loading but not executing. Because the page isn’t interactive menu isn’t expanding and collapsing on click. Can anyone tell me what’s a problem with it?

vuejs v-show not working after copying the objects

I have an array of objects:

departments: [(name: 'dep1', show: false),(name: 'dep2', show: false)]

and the div (it’s basically the list)

<div v-show="departments[0].show">departments[0].name</div>
<div v-show="departments[1].show">departments[1].name</div>

When I’m changing values show manually it works as expected:

departments[1].show = true;

but when I’m copying the whole object, it just stop working

new_set_of_departments: [(name: 'dep1', show: true)(name: 'dep2', show: true)]

departments = JSON.parse(JSON.stringify(new_set_of_departments));

<div v-show="departments[1].show">departments[1].name</div>

so v-show is not showing as expected. I tried also with:

departments = Object.assign({}, new_set_of_departments);

but without success

Edit and update an array item as row in map function in ReactJS

I’m making a simple table showing an array of objects ScriptItem. I want to edit and update an item property, for instance the KeyName, as the KeyName is changed, it’s corresponding ScriptItem in array will also be changed right away. How can I make this possible?

export default function ScriptGrid() {

   const { scriptItemsState, dispatch } = useContext(ScriptItemContext)
   const [input, setInput] = useState(scriptItemsState);
   const nullObj = { index: scriptItemsState.length, eventType: " ", keyName: "5", timeOffset: 0, active: true }
   
   const handleChange=(userId, e)=> {
      dispatch({
         type: TYPE.EDIT_ITEM,
         payload:{
            event:e,
            id:userId
         }
      })
  }
return (
      <div style={{ width: '600px', height: '500px', background: 'violet', display: 'inline-block' }}>
         <div>this is script grid</div>
         <button onClick={() => addItem()}>Add Item</button>
         <table style={{ overflow: "scroll" }}>
            <tr>
               <th>Index</th>
               <th>Event Type</th>
               <th>Key Name</th>
               <th>Time Offset</th>
               <th>Active</th>
               <th></th>
            </tr>
            {
               scriptItemsState && scriptItemsState.map((x, i) => (
                  <tr key={i}>
                     <td>
                        <input type="checkbox" />
                     </td>
                     <td>
                        <select>
                           <option>{x.eventType}</option>
                           <option></option>
                        </select>
                     </td>
                     <td><input type="text"  value={x.keyName}/></td>
                     <td><input type="text"  onChange={(e)=>handleChange(x.index,e)}  value={input}/></td>
                     <td><input type="checkbox" checked={x.active}/></td>
                     <td><button onClick={() => removeItem(x.index)}>Remove</button></td>
                  </tr>
               ))
            }
         </table>
      </div>
   )

map function:

import * as TYPE from "./scriptItemType";

export const scriptItemReducer = async (state, action) => {
      const { type, payload } = action;

   switch (type) {
      case TYPE.GET_ALL: {
         return []
      }
      case TYPE.ADD_ITEM: {
         const { scriptItem } = payload
         return [
            scriptItem,
            ...state
         ]
      }
      case TYPE.REMOVE_ITEM:{
         const id=payload.id
         var reducedItem=state.filter((item) => item.index !== id);
         return reducedItem;

      }

      case TYPE.EDIT_ITEM:{
         const id=payload.id;
         const event=payload.event;

         var item=state.find(x=>x.id===id);
         console.log(item)
         var x=[
            item,...state
         ];
         console.log(x)
         return reducedItem;


      }
      default:
         return state;
   }
};

Script table
enter image description here