RXJS combineLatest operator

I am trying to use combineLatest operator and getting bit beard response, when I am changing the interval duration for first and second observable

When I am Using following –

`let intObs1$ = interval(1000).pipe(take(3));
    let intObs2$ = interval(500).pipe(take(3));
    combineLatest([intObs1$, intObs2$,]).subscribe(([intObs1, intObs2]) => {
      console.log(intObs1, intObs2);
    })`

output on console is as follows –
0 0
0 1
1 1
2 1
2 2

Whereas when I am using changing it bit –

 let intObs1$ = interval(500).pipe(take(3));
    let intObs2$ = interval(1000).pipe(take(3));
    combineLatest([intObs1$, intObs2$,]).subscribe(([intObs1, intObs2]) => {
      console.log(intObs1, intObs2);
    });

output on console is as follows –
1 0
2 0
2 1
2 2

Can anyone please explain why second script is not emitting the Zero/Zero as initial value ??

convert flat array to 2D array in typescript

I have a flat array like this

['-', '-', '-', '-', '-', '-', '-', '-', '-']

and I want to convert it to be 2D like this

[
  ['-', '-', '-'],
  ['-', '-', '-'],
  ['-', '-', '-']
]

I saw this question but it is in javascript and I am getting error on declaring types of the “list” and “elementsPerSubArray”

// declaring type of list and elementsPerSubArray
function listToMatrix(list: number[], elementsPerSubArray: number) {
    var matrix = [], i, k;

    for (i = 0, k = -1; i < list.length; i++) {
        if (i % elementsPerSubArray === 0) {
            k++;
            matrix[k] = [];
        }
        // here I am facing error says " Argument of type 'number' is not assignable to parameter of type 'never' "
        matrix[k].push(list[i]);
    }

    return matrix;
}

var matrix = listToMatrix([1, 2, 3, 4, 4, 5, 6, 7, 8, 9], 3);

change counter color in js

i want to change color to green when my counter number were grater than zero and change to red when counter less than zero

const addBtn = document.getElementById(`add`);
const resetBtn = document.getElementById(`reset`);
const minusBtn = document.getElementById(`minus`);

const counter = document.getElementById(`counter`);

if (counter.innerHTML > 0) {
    counter.classList.remove(`white`)
    counter.classList.add(`green`)
}

addBtn.addEventListener(`click`, () => {
    counter.innerHTML = Number(counter.innerHTML) + 1;
});

minusBtn.addEventListener(`click`, () => {
        counter.innerHTML -= 1;
});

resetBtn.addEventListener(`click`, () => {
    counter.innerHTML = 0;
});

what should i do?

Get Contingent Values based on selection from SQL Server Table using PHP and JS

I have this SQL table as Sample:

+———————–+———–+————–+————–+——–+
| AssetCategory | AssetType | AssetSubtype | Component | TempID |
+———————–+———–+————–+————–+——–+
| Transportation | Road | Carriage Way | Wear Course | 1 |
| Transportation | Road | Carriageway | Upper Base | 5 |
| Transportation | Road | Carriageway | Lower Base | 6 |
| Transportation | Road | Carriageway | Formation | 7 |
| Transportation | Road | Car Park | Waring Couse | 8 |
| Transportation | Road | Car Park | Upper Base | 9 |
| Transportation | Road | Car Park | Formation | 10 |
| Urban Elements | Artwork | Artwork | Artwork Main | 11 |
| Urban Elements | Artwork | Artwork | Electical | 12 |
| Lighting & Electrical | Pole | Tapered | Pole Main | 13 |
| Lighting & Electrical | Pole | Post Top | Pole Main | 14 |
| Lighting & Electrical | Pole | AdePole | Pole Main | 15 |
+———————–+———–+————–+————–+——–+

Using PHP i have managed to get Asset Category as Distict values in a dropdown. I want to populate Asset Type and Asset Subtype as filtered dropdowns on the basis of selection. What i mean to say is if I select Transportaion in Asset Category dropdown i should get Road only in Asset Type dropdown and when i selct Road in Asset TYpe i get Two options in Asset Subtype dropdown Carriageway and Car Park.

What i have done so far is something like this.

enter image description here

I am unable to figure how rest of the code should look like. Target is only PHP and JS.

<?php
require_once 'DBconn.php';
?>

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="page4.css">
</head>
<body>
    <label>Asset Category:</label>
    <select id="CategorySelect" class="CategorySelect" onchange="loadAssetSubtypes()">
        <option value="Select Category" readonly>Select Category</option>
        <?php
        // Load asset categories in the select
        $runQuery = runQuery('getcategory');
        while ($row = sqlsrv_fetch_array($runQuery, SQLSRV_FETCH_ASSOC)) {
            echo '<option value="' . $row['AssetCategory'] . '">' . $row['AssetCategory'] . '</option>';
        }
        ?>
    </select>

    <label>Asset Type:</label>
  <select id="TypeSelect" onchange="loadAssetSubtypes()">
    <option value="Select Asset Type">Select Asset Type</option>
  </select>

  <label>Asset Subtype:</label>
  <select id="SubtypeSelect">
    <option value="Select Asset Subtype">Select Asset Subtype</option>
  </select>
  <script src="page4.js"></script>
</body>
</html>

How to set Style and Script for one Table but not other Tables?

I’m trying to use styles & scripts in One table but not in other tables. Test keep showing styles & scripts affect ALL tables, how to correct this? Here is part of my code:

<table  onclick="getElement(event)"> 
<!--- style & script for this 'table' only ... how?  -->
<**style**>
td { text-align: center; }
th, td { border: 1px solid gray; }

.btn1 {background-color: #4CAF50;} /* Green */
.btn2 {background-color: #008CBA;} /* Blue */
</style>

<**script**>
function getElement(e) {
    var element = e.target || e.srcElement;
    var btnId = element.id;
ooo
</script>

<col style="width:82%"><col style="width:8%"><col >
<tr>
  <td>Description #1</td>
  <td><a href="/file1.mp4" download"></a>
    <button Id = "btn1-1" class="button btn1">mp4 </button></td>
  <td><a href="/file1.pdf" download"></a>
    <button Id = "btn2-1" class="button btn2" onClick=“???” >PDF</button></td>
</tr>

How to get one table’s style and script different from others?

My tests kept showing Style and Script affected ALL my tables.

What’s the difference between static method inside a class and a function outside of it (JavaScript)

I don’t really catch what is the purpose of putting a static method into a class and then calling it with this class instead of just creating a function with the same code.

class test {
    static sum(a,b){
        return (a+b)
    }
}
sum = (a,b) => a+b
console.log(sum(10,5)) //15
console.log(test.sum(10,5)) //15
```

What is the difference? And why do people use static classes?
P.S. I'm in the very beginning of learning JS  

Node.js – place Json object elements into indivual divs in html?

I have an array of JSON objects. For each object I want to use an individual div to hold and display each object.
I have seen multiple examples using html tables and rows but I need to specifically use divs for this task.
I tried now for a while but am none the wiser. So in this spirit I turn to you , the friends and comrades at Stackoverflow nation

   <div id="each">
        <div>
            id
        </div>
        <div>
            title
        </div>
        <div>
            price
        </div>
    </div>
var data = [
    {
        id: 1,
        title: "foo1",
        price: 44
    },
    {
        id: 2,
        title: "foo2",
        price:78
    },
    {
        id: 3,
        title: "foo3",
        price:98
    },
    {
        id: 4,
        title: "foo4",
        price: 20

    }
];
function builddiv(target, articles) {
    articles.forEach((e) => {
        target.innerHTML += `<div> ${e.id} </div><div> ${e.title} </div><div> ${e.price} </div>`;
    });
    }
builddiv(document.getElementById("each"), data);

how do I reduce the size of the box, I tried changing the width and height of it in media query but they weren’t being applied

desktop view smaller width view code of the boxes in desktop view
`- I am new to this and just started building this website but got stuck here.
– I changed the grid-template-columns, width and height to fit the size in the media query but they -weren’t word.

– I tried:

@media (max-width:700px){
    
    .content-one1, .content-one2, .content-one3{
        width: 10px;
        height: 20px;
    }
}  
- but it wasn't working  `

how to change class with javascript [duplicate]

I want to make the square’s div with the class name “one” to change its class to “two” with different CSS properties

I also want so that after the class name is changed I want it to change the class name to “hovered” on hover and “left” after it leaves the element…

I saw many tutorials but somehow they ended up not working for me

<DOCTYPE>
    <html>
        <head>
            <title>
                Test
            </title>
        </head>
        <style>
            .one{
                height: 200px;
                aspect-ratio: 1 / 1;
                background-color: aqua;
                
            }

            .two{
                height: 200px;
                aspect-ratio: 1 / 1;
                background-color: rgb(219, 126, 5);
            }

            .hovered{
                height: 200px;
                aspect-ratio: 1 / 1;
                background-color: rgb(0, 255, 98);
            }
    
            .left{
                height: 200px;
                aspect-ratio: 1 / 1;
                background-color: rgb(0, 13, 255);
                
        <body>
            <div class="one"></div>
        <script>
            ......
        </script>
        </body>
</html>

Also is there a way to only change the CSS property instead of class name

baseQueue is undefined when trying to fetch data using react-query

I’m not able to fetch data from react query in one of my components but the exact same fetch funtion and key worked somewhere else just fine,

I’m getting this strange error saying

baseQueue is undefined

The error is thrown by useQuery() hook so I’m unable to understand what’s happening.

const dataSourceColorMap = {
  cms: "blue",
  epic: "red",
  athena: "purple",
};
const GiveOrgAuth = () => {
  const {
    data: profile,
    isLoading,
    isError,
  } = useQuery("profile", fetchProfile);
  return (
    <Page title="Give Auth to your org">
      <Grid>
        <Grid.Col span={4}>
          <ConnectPayers />
        </Grid.Col>
        <Grid.Col span={4}>
          <ConnectEMRs />
        </Grid.Col>
        <Grid.Col span={4}>
          <DevFetch />
        </Grid.Col>
      </Grid>
      <Paper mt="md">
        <Title order={4}>Currently Connected Sources</Title>
        {!isLoading && !isError ? (
          profile.dataSources.map((source) => (
            <Badge color={dataSourceColorMap[source]}>{source}</Badge>
          ))
        ) : (
          <></>
        )}
      </Paper>
    </Page>
  );
};

Here’s the fetchProfile function


export const fetchProfile = async () => {
  const res = await axios.get("/api/user/profile");
  return res.data;
};```

I tried to render one of they keys in profile object but it’s working only half the time

How to wait for x number of AJAX calls to finish before calling the function for x more times? [duplicate]

I have a list = mylist[].

 $.each(mylist, function (index, value) {

                myAjaxFunction(index, value)
            });

If the list has 50 items, the ajax calls happen in an instant, all 50 of them. And my backend connector timeout before all 50 of the calls are completed.

I want to modify this such that the backend “myAjaxFunction” is called in batches of 5.
So that the function is called 5 times, then it waits for those 5 AJAX calls to finish, before call the function another 5 times, till the end of the list.

Does anyone know how can I achieve this?

Thanks in advance.

get text from text area in web drive io

To get value of UI textarea

I have DOM

<textarea _ngcontent-yoo-c386="" pinputtextarea="" autoresize="true" readonly="" class="p-inputtextarea p-inputtext p-component p-element execute-textarea ng-pristine ng-valid p-inputtextarea-resizable ng-star-inserted p-filled ng-touched" rows="14" style="height: 277px; overflow: hidden;" xpath="1"></textarea>
<textarea _ngcontent-yoo-c386="" pinputtextarea="" autoresize="true" readonly="" class="p-inputtextarea p-inputtext p-component p-element execute-textarea ng-pristine ng-valid p-inputtextarea-resizable ng-star-inserted p-filled ng-touched" rows="14" style="height: 277px; overflow: hidden;" xpath="1"></textarea>

Value of text area though not visible her is visble in UI

Wante to get text out of it. tieed as bwloe is ot fetching text

let textAreaResponse = await element.getAttribute(‘value’);

I have a problem or upload the file in cloudinary in node.js where image come from react native and clodinary setup in node.js?

I face a problem for uploading the image to cloudinary.The issue is that when i upload the image from my react native app its first change the image into base base 64 and send it into the backend but when the code reaches to the upload system its give the error errno: -4058,
code: ‘ENOENT’,
syscall: ‘open’,
I dont know why i upload the image from phone and this case occur that no path found so i sharre you all my code because i am dont understand why its happen.My credential of cloudinary are ok so there is no issue with cloudinary api .i could not mention it while sharing the code but you have to assume that the credential are ok because i have check it several time.

So lets start the sharing of code
Here is my reactnative component which have the form

     import { View,Text,Button,StyleSheet,Image,KeyboardAvoidingView,Keyboard 
        } from "react-native";
        import {Picker} from "@react-native-picker/picker"
        import React from "react";
        import { useNavigation } from "@react-navigation/native";
        import { TextInput } from "react-native-gesture-handler";
        import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';
        import {useDispatch,useSelector} from "react-redux"
        import { RegisterClass,GetClassessInfo, addAdmin } from '../../actions/adminAction';
        import { useState ,useEffect} from "react";
        import * as ImagePicker from 'expo-image-picker';
        import * as FileSystem from 'expo-file-system';
        
        
        
        
        export default function ManageAdmin(){
            const {isAuthenticated,admin}=useSelector((state)=>state.admin)
            const [name,setname]=useState("");
            const [email,setemail]=useState("");
            const [phone,setphone]=useState("");
            const [address,setaddress]=useState("");
            const [password,setpassword]=useState(""); 
            const [image, setImage] = useState(null);
            const [avatar,setAvatar] =useState(null);
            const navigation=useNavigation();
            const dispatch=useDispatch();
            console.log(admin);
           // console.log("error");
            //console.log(loading);
            //console.log(isAuthenticated);
            
            const AdminSubmit=async()=>{
                dispatch(addAdmin(name,email,address,phone,password,image ))
            }
        
            
            
        useEffect(()=>{
        if(isAuthenticated){
            //console.log(user);
        }
          
        },[])
        
        /*const handleImageSelect = async () => {
          const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
          if (status !== 'granted') {
            return;
          }
        
          const result = await ImagePicker.launchImageLibraryAsync({
            mediaTypes: ImagePicker.MediaTypeOptions.Images,
            allowsEditing: true,
            aspect: [1, 1],
            quality: 1,
          });
        
          if (!result.canceled) {
            const selectedAsset = result.assets[0];
            const base64Image = await FileSystem.readAsStringAsync(selectedAsset.uri, {
              encoding: FileSystem.EncodingType.Base64,
            });
            setAvatar(result.uri);
            setImage(base64Image);
        
            // Use the base64Image as needed
            console.log(base64Image);
            const selectedAsset = result.assets[0];
            setAvatar(result.uri);
            setImage(selectedAsset.uri);
        
            // Use the image URI as needed
            console.log(selectedAsset.uri);
          }
        };*/
        /*const handleImageSelect = async () => {
          const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
          if (status !== 'granted') {
            return;
          }
        
          const result = await ImagePicker.launchImageLibraryAsync({
            mediaTypes: ImagePicker.MediaTypeOptions.Images,
            allowsEditing: true,
            aspect: [1, 1],
            quality: 1,
          });
        
          if (!result.cancelled) {
            const { uri } = result;
            setAvatar(uri);
            setImage(uri);
            console.log(uri);
          }
        };
        */
        const handleImageSelect = async () => {
          const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
          if (status !== 'granted') {
            return;
          }
        
          const result = await ImagePicker.launchImageLibraryAsync({
            mediaTypes: ImagePicker.MediaTypeOptions.Images,
            allowsEditing: true,
            aspect: [1, 1],
            quality: 1,
          });
        
          if (!result.canceled) {
            const selectedAsset = result.assets[0];
            const base64Image = await FileSystem.readAsStringAsync(selectedAsset.uri, {
              encoding: FileSystem.EncodingType.Base64,
            });
            setAvatar(result.uri);
            setImage(base64Image);
        
            // Use the base64Image as needed
            console.log(base64Image);
          }
        };
        const convertImageToBase64 = async (imageUri) => {
          try {
            console.log(imageUri);
            const base64 = await FileSystem.readAsStringAsync(imageUri, {
              encoding: FileSystem.EncodingType.Base64,
            });
            return base64;
          } catch (error) {
            console.error('Error converting image to base64:', error);
            return null;
          }
        };
                 
            return(
        
               <View style={styles.Mainview}>
                 
                 
                  <View style={styles.Mvinnertwo}>
                  
                  <View style={styles.Loginform}>
                  <View style={styles.Loginformfields}>
                  <TextInput style={styles.MvinneroneInputSearch}   placeholder="name "  value={name} onChangeText={text => setname(text)} ></TextInput>
                  <TextInput style={styles.MvinneroneInputSearch}   placeholder="email" value={email} onChangeText={text => setemail(text)}></TextInput>
                  <TextInput style={styles.MvinneroneInputSearch}   placeholder="phone"  value={phone} onChangeText={text => setphone(text)}></TextInput>
                  <TextInput style={styles.MvinneroneInputSearch}   placeholder="address" value={address} onChangeText={text => setaddress(text)} ></TextInput>
                  <TextInput style={styles.MvinneroneInputSearch}   placeholder="password" value={password} onChangeText={text => setpassword(text)}></TextInput>
                  <Button title="Select Image" onPress={handleImageSelect} />
                    {avatar && <Image source={{ uri: avatar }} style={{ width: 200, height: 200 }} />}
                  </View>       
                  <View style={styles.signIN}>
                  <View style={styles.signINbutton}>
                    <Button title="Add Admin" color="#7956b5" 
                      onPress={AdminSubmit}
                    ></Button>
                    </View>
                    <View style={styles.signUpbutton}>
                    <Button title="View All Classes" color="#7956b5" ></Button>
                    </View>
                  </View> 
        
                  </View>
                   
                   </View>
                   
        
        
        
                 </View>
                 
           );
        }
        const styles = StyleSheet.create({
          Mainview:{
            height:"100%",
            backgroundColor:"#7956b5",
            alignItems:"center"
          },
          Mvinnerone:{
          //  flex:1,
            
           
            height:"35%",
            flexDirection:'column'
          },
         
          Mvinnerone1Image:{
            marginLeft:-20,
            alignItems:'flex-start',
            width:150,
            height:150
          },
          Mvinnerone1:{
           flexDirection:'row'
          },
          Mvinnerone1view1:{
            justifyContent:'center',
            alignItems:'flex-start',
            width:"30%",
            
          },
          Mvinnerone1view2:{ 
            justifyContent:'center',
            alignItems:'center',
            width:"70%",
            fontSize:20
          },
          Mvinnerone1view2Text:{
            fontSize:20,
            color:'white'
          },
          MvinneroneInput:{
           justifyContent:'center',
           alignItems:'center'
          },
          MvinneroneInputSearch:{
            //justifyContent:'center',
             //alignItems:'center',
            marginTop:20,
            backgroundColor:'white',
            width:'100%',
            padding:'2%',
            borderColor:"#7956b5",
            borderWidth:2,
            borderRadius:10
            
            
          },
        
          Mvinnertwo: {
            padding:"5%",
            backgroundColor: "white",
            width:"95%",
            height:'100%',
            borderColor:'white',
            borderWidth:1,
            borderRadius:20,
            shadowColor:"black",
            shadowOffset:2,
            
        
        
          },
          Row1:{
            flexDirection:'row',
           
            height:100,
            justifyContent:'center',
            
          },
          cel1:{
            justifyContent:"center",
            alignItems:"center",
            width:"25%",
            
            margin:10,
            borderColor:"#7956b5",
            borderWidth:2,
            borderRadius:10,
            shadowColor:'#000',
            shadowOffset:{width:0,height:7},
            shadowOpacity:0.43,
            shadowRadius:9.51 
          },
          cel2:{
            justifyContent:"center",
            alignItems:"center",
           width:"25%",
           
           margin:10,
           borderColor:"#7956b5",
            borderWidth:2,
            borderRadius:10
          },
          cel3:{
            justifyContent:"center",
            alignItems:"center",
          width:"25%",
          
          margin:10,
          borderColor:"#7956b5",
            borderWidth:2,
            borderRadius:10
          },
          forgotpass:{
            flexDirection:'row',
            justifyContent:'flex-end',
            marginTop:4,
            marginBottom:4
          },
          signIN:{
            marginTop:'2%',
            justifyContent:"center"
          },
          signINbutton:{
            marginBottom:6
          },
          Loginform:{
            //alignItems:"center"
          }
          
          });
    
    Here is the action which target the backend api
    
    export const addAdmin = (name,email,phone,address,password,image) => async (dispatch) => {
        try {
          dispatch({ type: Add_Admin_Request }); 
      
       //   const config = { headers: { "Content-Type": "application/json" } };
          console.log("yes");
          console.log(image);
          const { data } = await axios.post(
            `http://192.168.100.42:4000/api/v1/RegisterAdmin`,
            { name,email,phone,address,password,image },
            {
              headers: {
                "Content-Type": "multipart/form-data",
              },
            }           
          );
          console.log("After Posting");
          console.log(data);
          dispatch({ type:  Add_Admin_Success, payload: data.user });
          
        } catch (error) {
          if (error.response && error.response.data && error.response.data.message) {
            dispatch({ type: Add_Admin_Fail, payload: error.response.data.message });
          } else {
            dispatch({ type: Add_Admin_Fail, payload: "An error occurred" });
          }
        }
      };
    
    Here is the reducer
    
    
    export const adminProfileReducer=(state={admin:{}},action)=>{
    
        
        switch(action.type){
            case Get_AdminOWNPROFILE_REQUEST:
                case Add_Admin_Request:
               return{
                    loading:true,
                    isAuthenticated:false
                };
                case Get_AdminOWNPROFILE_SUCCESS:
                    case Add_Admin_Success:
                    
                    return{
                        
                        ...state,
                        loading:false,
                        isAuthenticated:true,
                        //adminProfileInfo:action.payload
                        user:action.payload
                    };
    
                    
    
                    case Get_AdminOWNPROFILE_FAIL:
                        case Add_Admin_Fail:
                    return{
                        ...state,
                        loading:false,
                        isAuthenticated:false,
                        user:null,
                        error:action.payload
                    };
    
                /*case CLEAR_ERRORS:
            
                 return{
                ...state,
                error:null
        
        
               };*/
               default:{
                return  state;
              }
    
        }
    
    
    }

Here is the backend which have the cloudinary system
exports.registerAdmin = catchAsyncError(async (req, res, next) => {
  console.log("1");
  cloudinary.config({
    cloud_name: 'daequ7ofa',
    api_key: '762768164935239',
    api_secret: 'po-dxhHi3sYDqG4VvB32bDYANMg'
  });
  console.log(req.body.image);

  try {
    const result = await cloudinary.uploader.upload(req.body.image, {
      folder: 'avatar'
    });
    console.log('Image uploaded to Cloudinary:', result);
    const { public_id, secure_url } = result;
    
    const { name, email, password, phone, address } = req.body;

    const user = await admin.create({
      name,
      email,
      password,
      phone,
      address,
      image: {
        public_id,
        url: secure_url
      }
    });

    console.log("Admin created:", user);
    sendToken(user, 201, res);
  } catch (error) {
    console.error('Error uploading image to Cloudinary:', error);
    next(error);
  }
});

Please kindly check it and give the solution.

How to understand ‘The this inside a static block refers to the constructor object of the class’?

MDN-Static initialization blocks:

The this inside a static block refers to the constructor object of the class

I think it’s incorrect. The ‘this’ keyword refers to the class itself, not the constructor object of the class.

class A {
  constructor() {}
  static {
    console.log(this); // class A {}
    console.log(this === A); // true
    console.log(this === A.constructor); // false
  }
}

Did they write it wrong, or did I misunderstand?