How to show the dropdownlist from the selection of items

I have an angular application In that I have to populate the dropdown list based on picklist values.
.component.html

 <div class="row">
          <div class="form-group">
            <div class="col-sm-3">
              <label for="action"> <b>Category</b></label>
            </div>
            <div class="col-sm-7">
              <select>
                <option value="" disabled [selected]="true"></option>
                <option>Billing</option>
                <option>other</option>
                <option>action</option>
               
        </select>
            </div>
          </div>
        </div>

<select class="form-control" name="drpAction" id="actionSelect1ID"
              (change)="actionSelect($event.target.value)" [(ngModel)]="actionStatusTypeID">
                
                <option *ngFor="let code of memberContactCodes; let mIdx = index" [value]="mIdx">
                {{code.Name}}
                </option>
              </select>
              <select class="form-control" name="drpAction" id="billingActionId"
              (change)="billingSelect($event.target.value)" [(ngModel)]="billingActionId">
               
                <option *ngFor="let code of billingActionCodes; let mIdx = index" [value]="mIdx">
                {{code.Name}}
                </option>
              </select>
              <select class="form-control" name="drpAction" id="otherActionId"
              (change)="otherSelect($event.target.value)" [(ngModel)]="otherActionId">
                
                <option *ngFor="let code of otherActionCodes; let mIdx = index" [value]="mIdx">
                {{code.Name}}
                </option>
              </select>
            </div>
          </div>
        </div>

.component.ts

 public billingSelect(data: any) {
    this.billingActionId = data;
}
public otherSelect(data: any) {
  this.otherActionId = data;
}

public actionSelect(data: any) {
  this.actionStatusTypeID = data;
}

.service.ts

    let baseUrl = `/endpoint`;
    this._restfulService
      .restfulGetData(baseUrl)
      .subscribe(
        (actionLookupData: ActionLookupData) => {
          if (actionLookupData) {
            this.memberContactCodes = actionLookupData.MemberContactCodes;
            this.referralCodes = actionLookupData.ReferralCodes;
            this.otherActionCodes = actionLookupData.OtherActionCodes;
           this.billingActionCodes = actionLookupData.BillingActionCodes;
 }
        },
        (err) => {
          console.error(err);
        }
      );
  }

So here my requirement is to show the dropdown based on the picklest values(Billing,other,action) Butin the above code it is showing the 3 dropdowns for action But I have to show only one dropdown for action, but based on the selection of picklists I have to show the dropdown lists.

Can anyone help me on this

Next js changing the tabs using `router.push()`

On my Next Js page i have 3 tabs. It looks like this:

<TabsComponent tabs=[...] onChange={onChange}>
 const onChange = useCallback((tab) => {
    router.push(`/cars/${tab}`);
  }, []);

In each tab component i do a simple request in useEffect hook. The hook has empty dependency.

Question: Changing the tabs in my network tab i noticed that the request is made 2 times which looks weird.
Why the request is made 2 times and is that an issue of next js routing? How to solve this?

Node.js tcp socket shut off trigger

I use node.js with the NET class to connect multiple Rasperry Pi’s.

//Server
const net = require('node:net');
const server = net.createServer();

//Client
const tcpConnect = net.createConnection(SERVERINFO);

Thereby I can easily register multiple clients, open/close streams. Everything works without any problems.

But now I noticed that the callbacks.

tcpConnect.on('end', () => { console.log('end triggered') });
tcpConnect.on('close', () => { console.log('close triggered') });
tcpConnect.on('error', () => { console.log('error triggered') });

do not work if the server suddenly has a power failure (e.g. power supply is pulled). The clients don’t trigger an error/end or close, so I can’t close the connection properly.
As a result, an error is not triggered until the next attempt to write something to an existing stream. But this is not an option for me, especially for “online monitoring”.

Does anyone know a way to identify the shut off of the server immediately?

How to connect to blob container using SAS url in javascript?

i want to connect straight to container not to storage account using container’s url with SAS.

For now i have code that work:

private async getContainer() {   
    const blobServiceClient = new BlobServiceClient(this.props.sasToken);
    let baseContainer = blobServiceClient.getContainerClient(this.props.containerName);
    this.setState(state => ({ ...state, container: baseContainer }));
};

But in property this.props.sasToken i need to pass url to Storage account and container name.

Is it possible to connect to container using url with SAS only for this container? In Azure Storage Explorer it is possible but how to manage the same result programatically?

distube filters not applying

I’m trying to make a discord slash commands filter using distube but when I use the slash command it didn’t apply the filter that I picked but it sent the embed when filter is applied

Node: v17.7.2

Discord: ^13.2.0

can someone help me or tell me why the filter is not applying to the current music in vc?

thank you

const { MessageEmbed } = require('discord.js');
const ee = require('../../config.json');

module.exports = {
    name: 'filter',
    description: 'Add filter.',
    usage: 'filter',
    options: [
        {
            name: 'preset',
            description: 'Filters to add.',
            type: 'STRING',
            required: true,
            choices: [
                {
                    name: 'BassBoost',
                    value: 'bassboost'
                }, 
                {
                    name: 'Nightcore',
                    value: 'nightcore'
                },
                {
                    name: 'Vaporwave',
                    value: 'vaporwave'
                }
            ]
        }
    ],

    run: async(client, interaction, args) => {
        const filterss = interaction.options.getString('preset');
        const queue = client.distube.getQueue(interaction);
      
      let player = client.distube.filters;
      
        if(!queue) {
            return interaction.followUp({embeds: [
                new MessageEmbed()
                .setColor(ee.color)
                .setAuthor({name: 'Error', iconURL: 'https://i.imgur.com/81ig9jl.jpg'})
                .setDescription('No songs are playing!')
            ]})
        }

    let thing = new MessageEmbed().setColor(ee.color);

    if (filterss == "nightcore") {
      thing.setDescription("✅ | Nightcore filter is now active!");
      player.nightcore = true;
    } else if (filterss == "bassboost") {
      thing.setDescription("✅ | BassBoost filter is now on!");
      player.bassboost = true;
    } else if (filterss == "vaporwave") {
      thing.setDescription("✅ | Vaporwave filter is now on!");
      player.vaporwave = true;
    }
      return interaction.followUp({ embeds: [thing] });
    }
}

Comparison of Multiple Conditions Using Filters in React TypeScript

I’m going to make a new arrangement by comparing the current list data with the filter data

I made a new arrangement by comparing one condition using a filter, and all I want to do is compare many conditions, so please help me

index.tsx

const [listData, setListData] = useState<Array<List>>([]);
const [filterData, setFilterData] = useState<Array<List>>(null!);

const fetchData = (form: FetchData) => {
    const filteredData = listData.filter(({ user }) => user === form.user);
    setFilterData(filteredData); //Compare only current users
};


How to add more inputs depend dropdown values (PHP, JS)

so I want to add some input based on the option value from the drop down that will be selected. For example, the dropdown looks like this:

<form action="#" method="post">
    <select name="job" id="job" >
        <option value="">position</option>
        <option value="1">Teacher</option>
        <option value="2">Principal</option>
        <option value="3">Staff</option>      
    </select>
</form>

and if the selected value is number 1 or teacher, it will display new input like this below it:

<input type="number" name="student" id="student">
<input type="Text" name="class" id="class">

if you guys know how to make it, maybe you can help me with this please, either using php or js because I’ve been stuck with this problem for a long time.

rotation of a 3d cube relative to a specific point on the canvas

Using certain methods, I drew a 3D cube.
My task is to rotate it around the z axis. I also need to rotate the cube relative to the coordinates (0,0,0) (on my canvas, these will be the coordinates (150,150,0)). Now it rotates correctly, but only changes its angle relative to the ‘top left corner of my canvas‘.
I think the solution to my problem is as follows:
To rotate the cube relative to the given coordinates, the cube must first be translated to the negative coordinates of this point, and by changing the angle, it must be translated back, but only to the positive coordinates of this point.
In my case the pseudo code would be like this:

// if I want to flip the cube around the coordinates (150,150,0) (this is the center of my canvas), then I need to do the following
translate(-150,-150,0);
rotate();
translate(150,150,0);

In the commented parts of the code, I tried to do this, but when I translate the cube, it gets stuck somewhere in the corner and I don’t know how to fix it.

        function randInt(min, max) {
            return Math.floor(Math.random() * (max - min + 1) ) + min;
        }

        function randomColor() {
            return "rgb(" + randInt(0,255) + "," + randInt(0,255) + "," + randInt(0,255) + ")";
        }

        function ctg(x) { 
            return 1 / Math.tan(x); 
        }

        function draw() {
            let canvas = document.getElementById("canvas");
            let context = canvas.getContext("2d");

            let canvasWidth = 300;
            canvas.width = canvas.height = canvasWidth;

            function drawUW() {
                context.lineWidth = 0.1;
                context.beginPath();
                context.moveTo(0,canvas.height/2);
                context.lineTo(canvas.width,canvas.height/2);
                context.moveTo(canvas.width/2,0);
                context.lineTo(canvas.width/2,canvas.height);
                context.stroke();
            }

            function updateCanvas() {
                context.clearRect(0,0,canvas.width,canvas.height);
                drawUW();
            }
            
            let x = 50, y = 50, z = 50;
            let d = 100;

            let x0 = canvas.width/2;
            let y0 = canvas.height/2;
            let x1 = x0+x;
            let y1 = y0;
            let x2 = x0;
            let y2 = y0-y;
            let x3 = x0+x;
            let y3 = y0-y;
            // x' = xd/(z+d)
            // y' = yd/(z+d)
            let x0p=x0*d/(z+d);
            let y0p=y0*d/(z+d);
            let x1p=x1*d/(z+d);
            let y1p=y1*d/(z+d);
            let x2p=x2*d/(z+d);
            let y2p=y2*d/(z+d);
            let x3p=x3*d/(z+d);
            let y3p=y3*d/(z+d);


            function getWalls() {
                wall01 = [[x0,x2,x3,x1],[y0,y2,y3,y1]];
                wall02 = [[x0p,x2p,x2,x0],[y0p,y2p,y2,y0]];
                wall03 = [[x0p,x2p,x3p,x1p],[y0p,y2p,y3p,y1p]];
                wall04 = [[x1p,x3p,x3,x1],[y1p,y3p,y3,y1]];
                wall05 = [[x2,x2p,x3p,x3],[y2,y2p,y3p,y3]];
                wall06 = [[x0,x0p,x1p,x1],[y0,y0p,y1p,y1]];
            }

            function drawWall(wall) {
                context.fillStyle = randomColor();
                context.strokeStyle = "black";
                context.lineWidth = 0.5;
                context.beginPath();
                context.moveTo(wall[0][0],wall[1][0]);
                context.lineTo(wall[0][1],wall[1][1]);
                context.lineTo(wall[0][2],wall[1][2]);
                context.lineTo(wall[0][3],wall[1][3]);
                context.lineTo(wall[0][0],wall[1][0]);
                context.fill();
                context.stroke();
            }

            function rotatePoint(x,y,z,fi) {
                fi*=Math.PI/180;
                arr = [x,y,z,1];
                newX = 0;
                newY = 0;
                newZ = 0;

                tx = -150, ty = -150, tz = -150;

                arrTranslate = [
                    [1,0,0,tx],
                    [0,1,0,ty],
                    [0,0,1,tz],
                    [0,0,0,1]
                ];

                // z
                arrRotate = [
                    [Math.cos(fi),-Math.sin(fi),0,0],
                    [Math.sin(fi),Math.cos(fi),0,0],
                    [0,0,1,0],
                    [0,0,0,1]
                ];

                // translate
                // for (let i = 0; i < arr.length; i++) {
                //     newX += arr[i] * arrTranslate[0][i];
                //     newY += arr[i] * arrTranslate[1][i];
                //     newZ += arr[i] * arrTranslate[2][i];
                // }

                //rotate
                for (let i = 0; i < arr.length; i++) {
                    newX += arr[i] * arrRotate[0][i];
                    newY += arr[i] * arrRotate[1][i];
                    newZ += arr[i] * arrRotate[2][i];
                }

                tx = 150, ty = 150, tz = 150;
                // translate
                // for (let i = 0; i < arr.length; i++) {
                //     newX += arr[i] * arrTranslate[0][i];
                //     newY += arr[i] * arrTranslate[1][i];
                //     newZ += arr[i] * arrTranslate[2][i];
                // }

                x = newX;
                y = newY;
                z = newZ;
                return [newX,newY,newZ];
            }

            function rotatePoints(fi) {
                x0 = rotatePoint(x0,y0,z,fi)[0];
                y0 = rotatePoint(x0,y0,z,fi)[1];
                x1 = rotatePoint(x1,y1,z,fi)[0];
                y1 = rotatePoint(x1,y1,z,fi)[1];
                x2 = rotatePoint(x2,y2,z,fi)[0];
                y2 = rotatePoint(x2,y2,z,fi)[1];
                x3 = rotatePoint(x3,y3,z,fi)[0];
                y3 = rotatePoint(x3,y3,z,fi)[1];

                x0p = rotatePoint(x0p,y0p,z,fi)[0];
                y0p = rotatePoint(x0p,y0p,z,fi)[1];
                x1p = rotatePoint(x1p,y1p,z,fi)[0];
                y1p = rotatePoint(x1p,y1p,z,fi)[1];
                x2p = rotatePoint(x2p,y2p,z,fi)[0];
                y2p = rotatePoint(x2p,y2p,z,fi)[1];
                x3p = rotatePoint(x3p,y3p,z,fi)[0];
                y3p = rotatePoint(x3p,y3p,z,fi)[1];
            }
            
            let inFi = document.getElementById("fi");
            inFi.addEventListener("change", updateImage);

            function updateImage() {
                rotatePoints(inFi.value);
                getWalls();
                updateCanvas();
                drawWall(wall06);
                drawWall(wall04);
                drawWall(wall03);
                drawWall(wall02);
                drawWall(wall05);
                drawWall(wall01);   
            }
            updateImage();
        }
<body onload="draw();">
    <canvas id="canvas"></canvas>
    <div><input type="number" id="fi" value="0"></div>
</body>

Got Internship but no idea what to do

Recently I got an internship offer from Samsung. It will start in July 2022 but I don’t know what I will do there. I am pretty good at DSA but don’t have any experience in Software Development. I don’t know what and where to start. July is near and I want to get the PPO. Please help.

Sorry for using the Javascript tag.

Compare 2 array of objects if it has floating point property

I want to compare 2 array of objects with floating point property, regardless of the order of objects. Is it possible to do this?

const arr1 = [
  {
    foo: "obj1",
    bar: 1.1
  },
  {
    foo: "obj2",
    bar: 1.2
  }
];
const arr2 = [
  {
    foo: "obj2",
    bar: 1.2
  },
  {
    foo: "obj1",
    bar: 1.10000000000000000001
  }
];

const compareArr = (arr1, arr2) => {
  // how to compare?
};

compareArr(arr1, arr2) // should return true

How to upgrade the the dependency under specific package in npm

I have 5 high-risk vulnerabilities from npm audit --production. This is the dependency of node-sass .

# Run  npm update ansi-regex --depth 8  to resolve 5 vulnerabilities
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │  Inefficient Regular Expression Complexity in                │
│               │ chalk/ansi-regex                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ ansi-regex                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ node-sass                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ node-sass > sass-graph > yargs > cliui > strip-ansi >        │
│               │ ansi-regex                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-93q8-gq69-wqmw            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │  Inefficient Regular Expression Complexity in                │
│               │ chalk/ansi-regex                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ ansi-regex                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ node-sass                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ node-sass > sass-graph > yargs > cliui > string-width >      │
│               │ strip-ansi > ansi-regex                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-93q8-gq69-wqmw            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │  Inefficient Regular Expression Complexity in                │
│               │ chalk/ansi-regex                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ ansi-regex                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ node-sass                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ node-sass > sass-graph > yargs > cliui > wrap-ansi >         │
│               │ strip-ansi > ansi-regex                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-93q8-gq69-wqmw            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │  Inefficient Regular Expression Complexity in                │
│               │ chalk/ansi-regex                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ ansi-regex                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ node-sass                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ node-sass > sass-graph > yargs > cliui > wrap-ansi >         │
│               │ string-width > strip-ansi > ansi-regex                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-93q8-gq69-wqmw            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │  Inefficient Regular Expression Complexity in                │
│               │ chalk/ansi-regex                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ ansi-regex                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ node-sass                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ node-sass > sass-graph > yargs > string-width > strip-ansi > │
│               │ ansi-regex                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://github.com/advisories/GHSA-93q8-gq69-wqmw            │
└───────────────┴──────────────────────────────────────────────────────────────┘

I tried the recommended command npm update ansi-regex --depth 8 but it doesn’t fix the vulnerability.

npm notice created a lockfile as package-lock.json. You should commit this file.
+ [email protected]
added 1 package from 1 contributor, updated 1 package and audited 7 packages in 0.345s
found 0 vulnerabilities

npm notice created a lockfile as package-lock.json. You should commit this file.
+ [email protected]
added 3 packages from 3 contributors, updated 1 package and audited 10 packages in 0.376s
found 0 vulnerabilities

npm notice created a lockfile as package-lock.json. You should commit this file.
+ [email protected]
added 5 packages from 2 contributors, updated 1 package and audited 15 packages in 0.507s

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities

I found a solution by using npm-force-resolutions

"scripts": {
  "preinstall": "npx npm-force-resolutions"
},
"resolutions": {
  "ansi-regex": "5.0.1"
},

After modifying package.json and running npm i, these vulnerabilities are gone but looks like npm i upgraded all packages with dependency ansi-regex. It made a lot off change to my package-locak.json file.

How do I upgrade ansi-regex which is only under [email protected] ?

npm ls ansi-regex


├─┬ [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected] 
│ │ └─┬ [email protected]
│ │   └── [email protected]  deduped
│ └─┬ [email protected]
│   └─┬ [email protected]
│     ├─┬ [email protected]
│     │ ├─┬ [email protected]
│     │ │ └── [email protected] 
│     │ └─┬ [email protected]
│     │   └─┬ [email protected]
│     │     └── [email protected] 
│     └─┬ [email protected]
│       └─┬ [email protected]
│         └── [email protected] 

I am very new to npm and javascript, any help is appreciated!

nth-child selector in javascript

I am working with the following svg
Svg

const selector = document.querySelector('.yAxis g:nth-child(3)');
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 720">
  <rect class="vBoxRect" width="1280" height="720" fill="none" stroke="red"></rect>
  <rect class="boundRect" x="50" y="50" width="1180" height="620" fill="none" stroke="green"></rect>
  <g class="bound" style="transform: translate(50px, 50px);">
    <g fill="none" font-size="10" font-family="sans-serif" text-anchor="end" class="yAxis">
      <path class="domain" stroke="currentColor" d="M0.5,620.5V0.5"></path>
      <g class="tick" opacity="1" transform="translate(0,620.5)">
        <line stroke="currentColor" x2="-6"></line>
        <text fill="currentColor" x="-9" dy="0.32em">0</text>
      </g>
      <g class="tick" opacity="1" transform="translate(0,549.531741126106)">
        <line stroke="currentColor" x2="-6"></line>
        <text fill="currentColor" x="-9" dy="0.32em">10,000</text>
      </g>
      <g class="tick" opacity="1" transform="translate(0,478.56348225221205)">
        <line stroke="currentColor" x2="-6"></line>
        <text fill="currentColor" x="-9" dy="0.32em">20,000</text>
      </g>
      <g class="tick" opacity="1" transform="translate(0,407.59522337831805)">
        <line stroke="currentColor" x2="-6"></line>
        <text fill="currentColor" x="-9" dy="0.32em">30,000</text>
      </g>
      
    </g>
  </g>
</svg>
</body>
</html>

and I want to write a query that selects the 2nd <g> element of class="yAxis"
which is following

<g class="tick" opacity="1" transform="translate(0,549.531741126106)">
    <line stroke="currentColor" x2="-6"></line>
    <text fill="currentColor" x="-9" dy="0.32em">10,000</text>
  </g>

const selector = document.querySelector('.yAxis g:nth-child(3)'); is selecting the correct element but why am I passing 3 as nth-child(3) value when I am selecting the 2nd g element of class=yAxis

Replace pathname and origin using Javascript

I have a function where I get some data via a rest-call and put it into a div with an id schnittstelle-01.

const request = new XMLHttpRequest();
request.open(
    'GET',
    'https://purl.ulb.tu-darmstadt.de/vp/r000000-2001?ed=pa000008',
);
request.addEventListener('load', function (event) {
    if ((request.status = 200)) {
        document.getElementById('schnittstelle-01').innerHTML =
            request.responseText;
        console.log(request.responseText);
        for (let el of document.querySelectorAll('#schnittstelle-01 * a'))
            el.href = el.href.replace(
                window.location.origin,
                'purl.ulb.tu-darmstadt.de/vp/',
                
            );
    } else {
        console.log(request.status);
    }
});
request.send();

The retrieving part is not what bothers me, but the el.href.replace() part…
Let’s say my url is
test.de
the link are supposed to lead to purl.ulb.tu-darmstadt.de/vp/{link-target}
at the moment the links after this point to purl.ulb.tu-darmstadt.de/vp/path-to-site-on-test.de/{link-target}

I cannot figure out how to replace both parts. Any hints would be appreciated! I think I’m missing sth. basic here …

all the best,