Can i control Windows Volume Mixer with Javascript + Arduino

Hi i would like to create my own mixer that can control the output volume of individual apps in the windows volume mixer using an Arduino and specifically JavaScript.

I am learning JS for my job and i think this would be a good little project that i could actual utilize.

What i have learned so far are interactions between JS and HTML web pages so i am wondering is this even possible or would i need to use another language like python.

I’m hoping there is some API that allows me to do this with JS as I am a industrial hardware engineer and python is not something I work with, at least at the minute…

I would appreciate any help, thank you.

ReactJS: Detect which button is clicked

I have this simple requirement that detects which button is clicked. The code is as below:

import React, { useState } from 'react'

const App = () => {
  const data = [
    ['Hotel 1A', ['A']],
    ['Hotel 1B', ['B']],
  ]

  const [sameText, setSameText] = useState(false)

  const changeText = (e: any, index: number, item: any) => {
    console.log(e.target.value)
    console.log(index)
    console.log(item)

    if ((item[e.target.value] = item[index])) {
      setSameText(true)
    }
  }
  return (
    <div className='mx-auto'>
      <div className='flex p-16'>
        {data.map((item, index) => (
          <div className='mx-16' key={index}>
            <div className='p-12'>
              <button onClick={(e) => changeText(e, index, item)} value={index}>
                {item[0]}
              </button>
              <div>{sameText ? 'C' : item[1][0]}</div>
            </div>
          </div>
        ))}
      </div>
    </div>
  )
}

export default App

The code above will display text as below:

Hotel 1A      Hotel 1B
A             B

If I click on Hotel 1A, I have like A to be changed to C and if I click on Hotel 1B, only B will change to C. I thought I need to get the value of the button but I could not get it to work.

Any help would be greatly appreciated.

Bootstrap 5 Nested Accordion How to open Top level accordion when opening nested ones through link

so i am trying to create a page with bootstrap 5 nested accordions.
The idea is to have a button that opens a nested accordion within another accordion but i cant get that to work.

The button works and it opens the nested accordion but only if the top level one is already opened previously.

You can check that on this fiddle i made real quick.

JSFiddle

My HTML Code Bellow :

<button data-bs-toggle="collapse" href="#sub-collapseOne"> This should open both Accordion #1 and accordion #1 sub item #1</button>
<button data-bs-toggle="collapse" href="#collapseTwo"> This opens accordion #2</button>

<div class="container">

<div class="accordion" id="accordionExample">
<div class="accordion-item">
    <h2 class="accordion-header" id="headingOne">
        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
            Accordion #1
        </button>
    </h2>
    <div id="collapseOne" class="accordion-collapse collapse" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
        <div class="accordion-body">

            <div class="accordion" id="sub-accordionExample">
                <div class="accordion-item">
                    <h2 class="accordion-header" id="sub-headingOne">
                        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#sub-collapseOne" aria-expanded="true" aria-controls="collapseOne">
                            Accordion #1 Sub Item #1
                        </button>
                    </h2>
                    <div id="sub-collapseOne" class="accordion-collapse collapse" aria-labelledby="sub-headingOne" data-bs-parent="#collapseOne">
                        <div class="accordion-body">
                            <strong>This is the first item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
                        </div>
                    </div>
                </div>
                <div class="accordion-item">
                    <h2 class="accordion-header" id="sub-headingTwo">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#sub-collapseTwo" aria-expanded="false" aria-controls="sub-collapseTwo">
                            Accordion #1 Sub Item #2
                        </button>
                    </h2>
                    <div id="sub-collapseTwo" class="accordion-collapse collapse" aria-labelledby="sub-headingTwo" data-bs-parent="#collapseOne">
                        <div class="accordion-body">
                            <strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
                        </div>
                    </div>
                </div>
                <div class="accordion-item">
                    <h2 class="accordion-header" id="sub-headingThree">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#sub-collapseThree" aria-expanded="false" aria-controls="sub-collapseTwo">
                            Accordion #1 Sub Item #3
                        </button>
                    </h2>
                    <div id="sub-collapseThree" class="accordion-collapse collapse" aria-labelledby="sub-headingThree" data-bs-parent="#collapseOne">
                        <div class="accordion-body">
                            <strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

<div class="accordion-item">
    <h2 class="accordion-header" id="headingTwo">
        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">
            Accordion #2
        </button>
    </h2>
    <div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionExample">
        <div class="accordion-body">

            <div class="accordion" id="sub2-accordionExample">
                <div class="accordion-item">
                    <h2 class="accordion-header" id="sub2-headingOne">
                        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#sub2-collapseOne" aria-expanded="true" aria-controls="collapseTwo">
                            Accordion #2 Sub Item #1
                        </button>
                    </h2>
                    <div id="sub2-collapseOne" class="accordion-collapse collapse" aria-labelledby="sub2-headingOne" data-bs-parent="#sub2-accordionExample">
                        <div class="accordion-body">
                            <strong>This is the first item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
                        </div>
                    </div>
                </div>
                <div class="accordion-item">
                    <h2 class="accordion-header" id="sub2-headingTwo">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#sub2-collapseTwo" aria-expanded="false" aria-controls="sub2-collapseTwo">
                            Accordion #2 Sub Item #2
                        </button>
                    </h2>
                    <div id="sub2-collapseTwo" class="accordion-collapse collapse" aria-labelledby="sub2-headingTwo" data-bs-parent="#sub2-accordionExample">
                        <div class="accordion-body">
                            <strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
                        </div>
                    </div>
                </div>
                <div class="accordion-item">
                    <h2 class="accordion-header" id="sub2-headingThree">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#sub2-collapseThree" aria-expanded="false" aria-controls="sub2-collapseTwo">
                            Accordion #2 Sub Item #3
                        </button>
                    </h2>
                    <div id="sub2-collapseThree" class="accordion-collapse collapse" aria-labelledby="sub2-headingThree" data-bs-parent="#sub2-accordionExample">
                        <div class="accordion-body">
                            <strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

</div>
</div>

Have tried messing around with data-bs-target and data-bs-parent to no avail.

state href pass scope parameters to new tab

I’m unable to pass $scope value to a new tab via $state.href, it is because the $scope values get destroyed when the $statechanges. my question is how do I persist my values so I can access them on my new tab ?

let stateParams = {
  element: element.id,
  entity: {
        id: $scope.el.id,
        label: $scope.el.reference,
        topic: $scope.el.title
    };
  };

let url = $state.href('element.create', stateParams);
$window.open(url, '_blank');

Better way to inject data between props & axios

What is the better way to inject data in vue files between :

Inject data via props in twig for example or with axios requests when DOM is mounted ?

Both comes from a controller obviously.

{% set data = [] %}

    {% for d in datafromcontroller %}
        {% set data = data|merge([{ name: d.name}]) %}
    {% endfor %}

<component prop="{{ data }}"></component>

or

 mounted() {
    axios
      .get("getData")
      .then((response) => {
        this.data= response.data;
      });
  }

Javascript power and root [duplicate]

simple question
is there an operator for the root as for the power there’s the “* *”.

I tried to search but I couldn’t find it, so I don’t think there is, but if for any reason I didn’t saw but it exist can someone please tell? thx

How to pass specific item to another page HTML JavaScript Jquery

I want to pass specific items(paragraphs) to another page with button. I’m currently beginner in web development. Is there any way to do that? also I need to add those “like” buttons to every paragraph in my page. There’s a lot of them… So is there any way to add those “like” buttons(with same ids) to every paragraph and when I click “like” button it likes this specific paragraphs that’s next to it.

I made “like” button next to one of the paragraph. So far I’ve managed to save like buttons toggle state. Now I need to pass this specific “liked” paragraphitem to another page. Here’s my first page:

<!--Name of that file is "page1.html"-->
<p>A<span id="heart"><i class="fa fa-heart-o" aria-hidden="true" ></i></span></p>
<p>B</p>
<p>C</p>
<p>D</p>
<p>E</p>
<p>F</p>
<p>G</p>

<script>
      $(window).on('load',function(){
        if(localStorage.toggled != "with_toggle"){
          $("#heart").html('<i class="fa fa-heart" aria-hidden="true"></i>');
        }else{
          $("#heart").html('<i class="fa fa-heart-o" aria-hidden="true"></i>');
        }
      });
      $('#heart').toggleClass(localStorage.toggled);
      $('#heart').on('click',function(){
        if (localStorage.toggled != "with_toggle") {
          $("#heart").html('<i class="fa fa-heart-o" aria-hidden="true"></i>');
          $('#heart').toggleClass("with_toggle", true);
          localStorage.toggled = "with_toggle";
        } else {
          $("#heart").html('<i class="fa fa-heart" aria-hidden="true"></i>');
          $('#heart').toggleClass("with_toggle", false);
          localStorage.toggled = "";
        }
      });
</script>

And here’s my second page:

<!--Name of that file is "page2.html"-->
<body>
    <div>
        <!--SAVED PARAGRAPHS/ITEMS--->
    </div>
</body>

Get the 2nd Friday of a month with MomentJS

I am trying to get the nth Friday of a month with momentjs

where n is in the range [1,4]

So if a user supplies n as 2. Then I need to get the date for the second Friday of the month.

Here is what I tried with no sucess

let startingFrom = new Date("StartDateStringGoesHere");
let n=2;
let nthFriday = moment(startDate).isoWeekday(n); //I can't figure out how to resolve it here

Any ideas will be truly appreciated.

Add an opacity slider to a leaflet map generated in r

I would like to add an opacity slider to a leaflet map generated in r. It should change the opacity of the uppermost visible or all visible layers (either of the two, I don’t mind).
I found helpful advice in this thread:
Add opacity slider in R leaflet

This blog:
https://bookdown.org/nicohahn/making_maps_with_r5/docs/leaflet.html

and tried the following two packages, but none of the two seems to work:

leaflet.multiopacity

leaflet.opacity

So I figured out, this should be possible with htmltools. However, I struggle with the following

  1. Dragging the slider moves the map too (while changing the opacity of the labels), as pointed out in Laurens comment here: Add opacity slider in R leaflet

  2. I would like to change the opacity of the selected overlay layers. However I neither manage to get those values nor to change their opacity value.

Not helpful in this cause is, that I have almost no command of Javascript. Here is an example on how far I got. Would appreciate anyone pointing me into the right direction. I don’t even know how the access variables filled by htmltools javascript commands.

library(leaflet)
library(mapview) #to get the franconia dataset
library(htmltools)

colors <- colorFactor(palette = c("Red", "Green", "Blue"),
                      levels = c("Oberfranken","Mittelfranken", "Unterfranken"))


franconia %>% leaflet() %>% 
  addProviderTiles("CartoDB.Positron", group = "CartoDB.Positron") %>% 
  addPolygons(fillColor = ~colors(district),weight =  1, group = "Districts") %>%
  addPolygons(label = ~NAME_ASCI,weight =  1, group = "Names", fillColor = "Grey") %>%
  addLayersControl(baseGroups = "CartoDB.Positron",overlayGroups = c("Districts", "Names"),position = "topleft") %>%
  addControl(html = "<input id="slide" type="range" min="0" max="1" step="0.1" value="0.5">") %>%   # Add Slider
  htmlwidgets::onRender("function(el,x,data){
                     var map = this;
                     var evthandler = function(e){
                        var layers = map.layerManager.getVisibleGroups();
                        Object.keys(layer).forEach(function(el){
                             layer[el]._container.style.opacity = +e.target.value;
                             });
                     };
              $('#slide').on('mousemove',L.DomEvent.stopPropagation);
              $('#slide').on('input', evthandler)}
          ")

enter image description here

How to Disable a Button after 1 click?

i am making an app of react-native and i need someone’s help with my stack of code

i need to disable the button after just one click. can someone help? the problem is, i am using props and because of that i am unable to disable property.

`

import React from "react";
import { View, Text, StyleSheet , Button, Image ,TouchableOpacity} from 'react-native'
import colors from "../../constants/colors";

const DoctorItem = props => {
return(
<TouchableOpacity onPress={props.onViewDetail}>
<View style={styles.dr}>
<Image style={styles.img} source={{uri:props.image}}/>
<Text style= {styles.title}>{props.title}</Text>
<Text style= {styles.price}>{props.price} RS </Text>
<View style = {styles.actions}>
<Button style={styles.btn} color={colors.primary} title="View Details " onPress={props.onViewDetail} />
<Button  style = {styles.btn} color={colors.primary} title="To Registration" onPress={props.onRegistration}  />
</View>
</View>
</TouchableOpacity>
);
}

const styles= StyleSheet.create({
dr:{
shadowColor: 'black',
shadowOpacity: 0.26,
shadowOffset: { width: 0, height: 2 },
shadowRadius: 8,
elevation: 5,
borderRadius: 10,
backgroundColor: 'white',
height: 300,
margin: 20,

    },
    img:{
        width: '100%',
        height: '60%'
    },
    title:{
        fontSize: 18,
        marginVertical : 4,
        textAlign:'center',
        fontFamily:'opsb'
        
    
    
    },
    price:{

fontSize : 14,
color:'#888',
textAlign:'center',
fontFamily:'ops'
},
actions:{
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
height: '25%',
paddingHorizontal: 20

    },
    btn : {
        padding:5,
        color:colors.primary
    }

});

export default DoctorItem;

`

import React from 'react';
import { FlatList, Text } from 'react-native';
import { useDispatch, useSelector } from 'react-redux';
import dr from '../../store/reducers/dr';
import DoctorItem from '../../components/Doctor/DoctorItem';
import DrDetail from '../shop/DrDetail';
import * as appointActions from '../../store/actions/appoint';
import {HeaderButtons,Item} from 'react-navigation-header-buttons';
import CustomHeaderButton from '../../components/UI/headerButton';
import colors from '../../constants/colors';

const drscreen = props => {
const dr = useSelector(state => state.dr.availableDr);
const dispatch = useDispatch()
return (
<FlatList
data={dr}
keyExtractor={item => item.id}
renderItem={itemData => <DoctorItem
image= {itemData.item.imageUrl}
title={itemData.item.title}
price={itemData.item.price}
onViewDetail={()=>{

          props.navigation.navigate('DoctorDetails',{
            doctorId:itemData.item.id,
          doctorTitle:itemData.item.title
        });
        }} 
        onRegistration={()=>{
          dispatch(appointActions.appointDoc(itemData.item))
          
        }}
        />}
    />

);
};

drscreen.navigationOptions = navData => {
return{

    headerTitle: 'All Doctors',
    headerRight: (
      <HeaderButtons HeaderButtonComponent={CustomHeaderButton}>
        <Item
          title="Appoint"
          iconName={"ios-checkmark-done-outline"}
          onPress={() => {
            navData.navigation.navigate ("Register")
              
          }}
        />
      </HeaderButtons>
    )

}

};

export default drscreen;

`

Have tried using the disable function, but probably incorrectly. if anybody is familiar with this coding format, please help.

p5js // Change LIVE capture animation to a gif/moving animation

So lately I have done some exploration on the camera delay sort of effect on P5.js, and I just couldn’t wrap my head around something— When I try to replace the img source from “createCapture(VIDEO)” to “loadImage(“XXXX.gif”)” the moving GIF just stopped and became a static image and did not make the same performance as how a live camera-capturing would (to delay from centre out).

Does anyone have a better idea to run this code with GIF that achieves the same effect?

let cap;
let num =40;
let imgs = [];
let tileNum = 10;


function setup() {
    createCanvas(windowWidth, windowHeight);
    cap = createCapture(VIDEO);
    cap.hide();
    frameRate(24);
    imageMode(CENTER);
}

function draw() {
    background(255);
    
    
    let size = min(cap.width,cap.height);
    let img = createImage(size,size);
    img.copy(cap,(cap.width-size),(cap.height-size)*6.5,size,size,0,0,img.width,img.height);
    
    
    imgs.unshift(img);
    if(imgs.length >num){
        imgs.pop();
    }
    


    let stepX  = width/tileNum;
    let stepY = stepX * img.height /img.width;
    
    let maxDist = dist(width/2,height/2,-10,-10);
    
    if(imgs.length == num){
        for(let y = 0; y< height+10; y += stepY){
            for(let x =0; x < width+10; x+= stepX){
                let dis = dist(width/2,height/2,x,y);
                let index =  Math.floor(dis/maxDist*num);
                image(imgs[index%num],x,y,stepX,stepY);
                
            }
        }   
    }
    
    
}

Redux Invoke function linked to onClick in a different file

I have a code written in React+Redux for a table. The mapping of the table goes as follows:-

ListTemp.js

//editTemp function invoked in the mapping below

 editTemp = (e, temp_id, temp_name, action_url, duration) => {
        e.preventDefault();

        this.props.getTemp(temp_id)

        this.setState({
            isEdit: true,
            temp_id : temp_id
        });
    }

<table  className = "table_style">
                 <thead>
                     <tr className = "table_style" >
                         <th className = "table_style">TempID</th>
                         <th className = "table_style">Name</th>
                         <th className = "table_style">CreatedOn</th>
                         <th className = "table_style">Action</th>
                     </tr>

               </thead>
               <tbody>
                {
                 this.props.temp_list.map((temp,index)=>
                     <tr className = "table_style">
                         <th className = "table_style">{temp.temp_id}</th>
                         <td className = "table_style">{temp.temp_name}</td>
                         <td className = "table_style">{temp.created_on}</td>
                         <td>
                         <button className="btn btn-info" type = "submit" onClick = {(e) => this.editTemp(e, temp.temp_id, temp.temp_name, temp.action_url, temp.duration)}>
                             EDIT
                         </button> 
                         </td>
                     </tr>
                     )
                 }
                </tbody>
                 </table>

Because of the table having a lot of data, I paginated it and the mapping was moved to a different file changing the code as follows:-

ListTemp.js

    showTemp = (temp) => {
        var result = null;
        if (temp.length > 0) {
            result = temp.map((temp, index) => {
                return <ListMapp key={index} temp={temp} index={index} />;
            });
        }
        return result;
    };

 editTemp = (e, temp_id, temp_name, action_url, duration) => {
        e.preventDefault();

        this.props.getTemp(temp_id)

        this.setState({
            isEdit: true,
            temp_id : temp_id
        });
    }

<table  className = "table table-bordered table-hover">
                        <thead>
                        <tr className = "table_style" >
                            <th className = "table_style">TempID</th>
                            <th className = "table_style">Name</th>
                            <th className = "table_style">CreatedOn</th>
                            <th className = "table_style">Action</th>
                        </tr>

                        </thead>
                        <tbody>
                           {
                                this.showTemp(rowsPerPage)
                           }
                        </tbody>
                        </table>

And the mapping in this.showTemp comes from:-

ListMapp.js

class ListMapp extends Component {

  render() {
    var { template, index } = this.props;

      return (
                     <tr className = "table_style">
                         <th className = "table_style">{temp.temp_id}</th>
                         <td className = "table_style">{temp.temp_name}</td>
                         <td className = "table_style">{temp.created_on}</td>
                         <td>
          <td>
             <button className="btn btn-info" type = "submit" onClick = {(e) => this.editTemp(e, temp.temp_id, temp.temp_name, temp.action_url, temp.duration)}>
            EDIT
          </button> 
          </td>               
        </tr>
      );
    }
  }

export default ListMapp;

What is the simplest way in this situation to link/call/map the editTemp function in ListTemp.js from ListMapp.js? Also, please clarify what the return type(s) and payload will be here for invoking of the function if applicable.

Execute synchronously MessageBox show function in ExtJs-5

I want to execute a Ext.Msg.show() function synchronously in ExtJs-5

onButtonClick : function() {
1. some code...
2. Ext.Msg.show({
            title : 'Confirm Please',
            msg : 'Please be informed that record will only save when click ok.',
            buttons : Ext.Msg.OKCANCEL,
            icon : Ext.Msg.QUESTION,
            fn : function(btn) {
                    if ('cancel' === btn) {
                        return;
                    }
                }
            });

3. other message box ...
4. other code ...
}

The above function execute synchronously each step 1, 2, 3 & 4 but doesn’t wait for user interaction on step 2. It directly move to step 3 and after that to step 4. But I want to execute step 3 only when user click on ok else terminate other below steps.

Can anybody check and let me know the possible code that I need to add to make it possible? Thanks