Put three.js scene inside ionic 6 page

Is there a way to put this scene inside an ionic 6 page? I already tried to copy/paste the script and css but i can’t make it work, i only see a black screen while it should display this

Script:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>My first three.js app</title>
        <style>
            body { margin: 0; }
        </style>
    </head>
    <body>
        <script src="js/three.js"></script>
        <script>
            const scene = new THREE.Scene();
            const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );

            const renderer = new THREE.WebGLRenderer();
            renderer.setSize( window.innerWidth, window.innerHeight );
            document.body.appendChild( renderer.domElement );

            const geometry = new THREE.BoxGeometry();
            const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
            const cube = new THREE.Mesh( geometry, material );
            scene.add( cube );

            camera.position.z = 5;

            function animate() {
                requestAnimationFrame( animate );

                cube.rotation.x += 0.01;
                cube.rotation.y += 0.01;

                renderer.render( scene, camera );
            };

            animate();
        </script>
    </body>
</html>

Check Value is Empty or Not in Array of Object

data : { detailList : { 0:{quantity : “”} 1:{quantity : “”} 2:{quantity : “”} }}

It is an example of the array. The details array can be more than 10 objects.
How I can check that any quantity value is Empty or less than 0 from the whole array. If it is not then it will perform the function which I want like hit API else it will show a message.
I try it through the map but it hit API multiple times depending on the length of detailList.

Show flatpickr calendar in two columns

I need to show the flatpickr calendar in two columns, i have done several searches in the plungin’s doc, but i didn’t find how to do that.

This is my js :

 var calendar = flatpickr(el, {
 mode: "range",

 onChange: function (calendar) {
   if (calendar.length == 2) {
     var start =  numeroAdosCaracteres(calendar[0].getDate()) + "-" + numeroAdosCaracteres(calendar[0].getMonth() + 1) + "-" + calendar[0].getFullYear();

     var end = numeroAdosCaracteres(calendar[1].getDate()) + "-" + numeroAdosCaracteres(calendar[1].getMonth() + 1) + "-" + calendar[1].getFullYear();


     $("#az-start-date").val(start);
     $("#az-end-date").val(end);
   }
    function numeroAdosCaracteres(az_date) {
      if (az_date > 9) {
        return "" + az_date;
      } else {
        return "0" + az_date;
      }
    }
 },

});

This is the HTML :

<div id="az-calendar"> </div>

Evaporate.js upload file with x-amz-security-token: SignatureDoesNotMatch

I want upload a file with evaporate.js and crypto-js using x-amz-security-token:

import * as Evaporate from 'evaporate';
import * as crypto from "crypto-js";

Evaporate.create({
  aws_key: <ACCESS_KEY>,
  bucket: 'my-bucket',
  awsRegion: 'eu-west',
  computeContentMd5: true,
  cryptoMd5Method: data => crypto.algo.MD5.create().update(String.fromCharCode.apply(null, new Uint32Array(data))).finalize().toString(crypto.enc.Base64),
  cryptoHexEncodedHash256: (data) => crypto.algo.SHA256.create().update(data as string).finalize().toString(crypto.enc.Hex),
  logging: true,
  maxConcurrentParts: 5,  
  customAuthMethod: (signParams: object, signHeaders: object, stringToSign: string, signatureDateTime: string, canonicalRequest: string): Promise<string> => {
      const stringToSignDecoded = decodeURIComponent(stringToSign)
      const requestScope = stringToSignDecoded.split("n")[2];
      const [date, region, service, signatureType] = requestScope.split("/");
      const round1 = crypto.HmacSHA256(`AWS4${signParams['secret_key']}`, date);
      const round2 = crypto.HmacSHA256(round1, region);
      const round3 = crypto.HmacSHA256(round2, service);
      const round4 = crypto.HmacSHA256(round3, signatureType);
      const final = crypto.HmacSHA256(round4, stringToSignDecoded);
      return Promise.resolve(final.toString(crypto.enc.Hex));
  },
  signParams: { secretKey: <SECRET_KEY> },
  partSize: 1024 * 1024 * 6
  }).then((evaporate) => {
      evaporate.add({
          name: 'my-key',
          file: file, // file from <input type="file" />
          xAmzHeadersCommon: { 'x-amz-security-token': <SECURITY_TOKEN> },
          xAmzHeadersAtInitiate: { 'x-amz-security-token': <SECURITY_TOKEN> },
       }).then(() => console.log('complete'));
  },
     (error) => console.error(error)
  );

but it produce this output

AWS Code: SignatureDoesNotMatch, Message:The request signature we calculated does not match the signature you provided. Check your key and signing method.status:403

What I’m doing wrong

SIDE NOTE

This is the versione I’m using on browser side:

{
  "crypto-js": "^4.1.1",
  "evaporate": "^2.1.4"
}

How to restrict formik validation when you click cancel button in react

from the field if you defocus without giving anything you are getting the validation error as well without giving value if you click on submit button you are getting validation error this is right ,but how to restrict the cancel button that without giving any data in the field if you click the cancel button then the validation error should not come ,how to restrict the formik validation only for cancel button or any kind of link.
can I use validateOnBlur particularly for cancel button, because in initial stage if i use that its disabling for all defocus kind of error, but I need only clicking on cancel that validation errors should not come. what approach should I follow.

import React from "react";
import { Formik, Form, Field } from 'formik';
 import * as Yup from 'yup';
export default function DropDown() {
 const SignupSchema = Yup.object().shape({
    firstName: Yup.string()
      .min(2, 'Too Short!')
      .max(25, 'Too Long!')
      .required('Name is required'),
  });
  return (
    <>
      <h1>Signup</h1>
     <Formik
       initialValues={{
         firstName: '',
       }}
       //validateOnBlur={false}
       validationSchema={SignupSchema}
       onSubmit={values => {
         console.log(values);
       }}
     >
       {({ errors, touched }) => (
         <Form>
           <Field name="firstName" placeholder="type name" autoFocus="true" autoComplete="off"/>
           {errors.firstName && touched.firstName ? (
             <div style={{color:"red"}}>{errors.firstName}</div>
           ) : null}
          <br/><br/>  
           <button type="submit" >Submit</button>
           <button type="submit" >Cancel</button>
         </Form>
       )}
     </Formik>
    </>
  );
}

Cors in Waveform in Angular [duplicate]

I was trying to use ng-waveform

Link: https://www.npmjs.com/package/ng-waveform

in my ts file included

  import { ITimeUpdateEvent, NgWaveformComponent, IRegionPositions } from 'ng-waveform';
    
  export class soundComponent implements OnInit {

  counter: number = 0;
  @ViewChild('waveform', { static: false }) waveform: NgWaveformComponent;

  src_s='http://127.0.0.1:8000/storage/uploads/83316135.wav';
  play = false;
  isLoaded = false;
  trackLoadTime: number;
  renderingTime: number;
  duration: number;
  currentTime: ITimeUpdateEvent;
  regionPositions: IRegionPositions;


  isSrcError = false;
  isAudioQueried = false;

  isRegionCtrl = true;
  regionStartCtrl = 0;
  regionEndCtrl =80.08;

  useRegion = true;
  src: string;

  onPlayButtonClick() {
    this.waveform.play();
  }
  onPauseButtonClick() {
    this.waveform.pause();
  }

  onTrackLoaded(time: number) {
    this.trackLoadTime = time;
  }

  onTrackRendered(time: number) {
    this.renderingTime = time;
    this.isLoaded = true;
  }

  onDurationChange(duration: number) {
    this.duration = duration;
  }

  onTimeUpdate(event: ITimeUpdateEvent) {
    this.currentTime = event;
  }

  onPaused() {
    this.play = false;
  }

  onRegionChange(region: IRegionPositions) {
    this.regionPositions = region;
    this.regionStartCtrl=this.regionPositions.start;
    this.regionEndCtrl=this.regionPositions.end;
  }

html Component added

 <ng-waveform #waveform class="waveform"
                                                [src]="src_s"
                                                [height]="150"
                                                [useRegion]="true"
                                                backgroundColor="#d3d3d3"
                                                regionBackgroundColor="rgba(255, 255, 255, 0.7)"
                                                regionStartStickColor="#21f032"
                                                regionEndStickColor="red"
                                                regionTextColor="#09417e"
                                                [withRegionLabels]="true"
                                                waveColor="#ff11ff"
                                                (trackLoaded)="onTrackLoaded($event)"
                                                (rendered)="onTrackRendered($event)"
                                                (durationChange)="onDurationChange($event)"
                                                (timeUpdate)="onTimeUpdate($event)"
                                                (paused)="onPaused()"
                                                (regionChange)="onRegionChange($event)"
                                              >

but getting this error:

Access to XMLHttpRequest at
‘http://127.0.0.1:8000/storage/uploads/83316135.wav’ from origin
‘http://localhost:4200’ has been blocked by CORS policy: Response to
preflight request doesn’t pass access control check: No
‘Access-Control-Allow-Origin’ header is present on the requested
resource.

Any solution to resolve this issue Thanks

Call function after another function completes

I am trying to use a promise to ensure one function, “submit()” is called after the another function, “save()” has been completed. I haven’t used promises in a long while and I’m confused on the syntax. I also tried using async and await but to no avail.

public globalFunction() {
//call save() first, wait until fully completed and then call submit()
    this.save().then(() => {
        this.submit(approver);
    })

    //this.save().then(res => this.submit(approver));
}

save() {
    return new Promise<void>((resolve, reject) => {

    this.service.save(this.item.id, updatedItemList).pipe(
      first(),
      catchError((err) => {
        this.toastService.show(`Save failed`, { type: "error" });
        return null;
      })
    ).subscribe((success: boolean) => {
        this.loadItemss().then(() => {
        this.uploadDocs();
      });
      this.toastService.show("Successfully saved", { type: "success" });
    });


    resolve();
  });
}

private submit(approver: Lookup): void {
    this.service.submit(this.item.id, approver).pipe(
      first(),
      catchError((error) => {
        this.toastService.show(`Submit failed`, { type: 'error' });
        return null;
      })
    ).subscribe((success: boolean) => {
      this.toastService.show(`Successfully submitted`, { type: 'success' })
    });
}


How to use GAS versioning/deployments with container-bound scripts

I have several Google Sheets with relatively complex GAS scripts attached – so far I’ve been developing new functionality using copies and github for VC, but I’m wondering if there’s a better way to do this using the in-built deployments/versioning with container-bound scripts?

I’d like to be able to work on HEAD developing new features while users are still on the last ‘stable’ version of the script

Should I move the bound scripts to standalone libraries that can be imported in particular sheets?
Would this have any performance issues?
The docs say that bound scripts have ‘special privileges’ over the parent document – does anyone know what these are?

Thanks for any help!

I’ve tried the following solutions but non work perfectly

  • deploying as an add-on which I thought would be the solution

    • first you had to change GCP project/authentication
    • it’s not clear to me if this would be then made public automatically – which I can’t have as the scripts are internal only
  • deploying the bound script as a library

    • this gives access to versioned deployments but no ability to develop on HEAD while users have access to the last deployment
  • deploying as a standalone library

    • not sure what ‘special privileges’ I’d be missing out on in the parent file

Assign variables in function Javascript [duplicate]

I have the next function in javascript:

const getData = () => {
  let res = null;
  let err = null;
  service
    .get('/users')
    .then((response) => {
      if (response) {
        res = response;
        return response;
      }
      throw new Error(response);
    })
    .catch((e) => {
      err = null;
      return e;
    });

  return {
    res,
    err
  }
};

Even i get the response when i do:

console.log(getData())

… i get both values as null.
Why values are not assigned and how to get the result?

How to structure input parameter to object in JS

I have a simple Express API here.
When the user submits the chain param I want to convert the parameter to an object.
Depending on the input the object will have different values
Right now I just have a bunch of if statements stacked

Is there a better practice solution to implement this as this is quite clunky?

app.get('/gettokens/:chain/:address', async(req, res) => {
    const address = req.params.address;
    let chain = req.params.chain;

    if (chain == 'bsc') {
        chain = {
            moralis: 'bsc',
            coingecko: 'binance-smart-chain'
        }
    }

    if (chain == 'eth') {
        chain = {
            moralis: 'eth',
            coingecko: 'ethereum'
        }
    }

    if (chain == 'avax') {
        chain = {
            moralis: 'avalanche',
            coingecko: 'avalanche'
        }
    }

    if (chain == 'matic') {
        chain = {
            moralis: 'matic',
            coingecko: 'polygon-pos'
        }
    }

React: how can I control the state of another functional component that can be far away in the three?

I’m trying to achieve a thing and I don’t know how to do it.
My idea is in a React application to have a snackbar component. I want to made all the app with functional components. When some event happens in the app – for instance the theme it’s changed, etc… – the snackbar will be shown.

My problem is that the components that call the snackbar can be very distant in the tree. My first idea was adding the snackbar component straight to the html element with a 0 opacity, and when the trigger occurs change the opacity… The other ideas was append a snackbar component to the DOM every time it’s triggered. The las idea was use context, but I understood that is not the best solution to this kind of things. I tried to pass a callback that modifies the state with hooks (useState or useEffect) but it didn’t work…

Which is the best solution to this scenario: control the state of another functional component that can be far away in the three?

Excuse me if it’s a noob question! Thanks you very much!

Import JS files from a Bootstrap template into a Vue3 project

I have a Bootstrap 5, HTML theme with a CSS budle file and different JS bundle files (main JS bundle file and a plugin bundle file) that include the Bootstrap code base + custom template features.

I want to integrate all of these in a Vue 3 project so I can use the template in all my Vue components.

For the CSS part, I have easily imported the CSS bundle file in the App component with a global scope.

But how can I import the JS files? Do I have to import it in all my components? If so, how should I do this? One solution is to link to these files from index.html in the public folder, but then it is not included in the production build, and I get some errors even in development. Is there a simple strategy to integrate these JS bundles in my SRC folder?

Thanks for any help!!

Check if part of a string is in an array

I have an array of type string populated by “bed time”, “sleepy”, and “I am tired”. Is it possible to pick apart a user’s input to find if any words are in the array?

For example: if user says “I am tired goodnight all”. I would like that to be a valid entry as it contains the phrase “I am tired”. Currently this is my code which works only for exact matches:

if(process.env.GN_MESSAGES.includes(message.toLowerCase())) {
    "@alca, heya!"
    client.say(channel, `gn ${tags.username}');
 }

how to trigger a function whenever the mouse on screen

I’m being stuck in a problem

I’m creating something like this: https://www.fariasviolins.com/

My English is not good :3
Specifically, I’m creating a infinity layout, the layout will be moved according to the mouse position(The larger the position, the greater the speed), it means that when the mouse to directions, the layout will be moved. I have tried mousemove and it worked, but I also want the layout still move whenever the mouse on screen(even when the mouse not moving, the the speed will calculate by the position of the mouse), I have tried mouseover, but it didn’t work as I expected. please help me huhuhuhhu, thank you so much

daily deals – sales manager app not letting me to remove added deal

In daily deals – sales manager app(countdown Timer ) on shopify, not letting me to remove added deal as it has disabled the edit/delete button. It happen when I was updating after making changes, I hit update button and from that time only spinner is running and buttons are disabled. I am using Shopify.theme = 9Sleek Custom | SpeedUP Work Boost – OPT and
theme_store_id”:863 . Any suggestion & guidance will be helpful.

enter image description here