Why does this canvas content get cut off when oriented sideways?

I have an audio visualizer I’ve made and (I’ve increased the sensitivity of it so the problem is more clear) for some reason it just cuts off at a certain point and I haven’t been able to figure it out. While the visualizer has this issue when oriented to the left like this, the problem does not exist when anchored normally to the bottom. Any help to figure this out would be greatly appreciated!

How it looks now /

bad lookikng

How I want the height to look (but sideways so its extends to the end of the canvas) /

normal looking

This is the code for it:

 <head>
      <meta charset="UTF-8"> 
      <script src="properties.js"></script>
      <script src="clockRefresh.js"></script>
     
      <link href='https://fonts.googleapis.com/css?family=DM Mono' rel='stylesheet'>
      <link href='https://fonts.googleapis.com/css?family=Share Tech Mono' rel='stylesheet'>
  
      <style>
           #time-panel {   
                position: absolute;    
                background-color: rgba(0, 0, 0, 0.3);  
                border-radius: 20px; 
                
           }
           #hour, #min, #sec {
                font-family: 'dm mono';
                font-weight: 1000;                 
           }
           #clock {
                display: table;
                margin: 0 auto;
           }
           #audioCanvas {
                border-radius: 20px; 
                background-color: rgba(0, 0, 0, 0.3); 
                position: absolute;
           }
      </style>
      
 </head>
 <body onload="clock()"  > 
      <div id="time-panel">
           <canvas id="canvas"></canvas>
           <span id="clock">
                <span id="hour"></span>
                <span id="min"></span>
                <span id="sec"></span>
           </span>
      </div>

      <!-- Canvas where visualizer is drawn -->
      <canvas id="audioCanvas"></canvas>
     
    
      <!-- Script that creates said visualizer -->
      <script>
           // Get the audio canvas once the page has loaded
           let audioCanvas = document.getElementById('audioCanvas');

           // Get the 2D context of the canvas to draw on it in wallpaperAudioListener
           let audioCanvasCtx = audioCanvas.getContext('2d');

           // Setting internal canvas resolution to user screen resolution
           // (CSS canvas size differs from internal canvas size)
           audioCanvas.height = window.innerHeight;
           audioCanvas.width = window.innerWidth;

           //temp canvas to store rotation data
           var tempCanvas = document.createElement("canvas"),
           tempCtx = tempCanvas.getContext("2d");

           tempCanvas.width = audioCanvas.width;
           tempCanvas.height = audioCanvas.height;

           function wallpaperAudioListener(audioArray) {
                audioCanvasCtx.clearRect(0, 0, audioCanvas.width, audioCanvas.height);

                if (sessionStorage.getItem("audio-orientation") == "left" ||
                     sessionStorage.getItem("audio-orientation") == "right") {

                

                     // Render bars along the full height of the canvas
                     var barWidth = Math.round(1.0 / 128.0 * audioCanvas.height);
                     var halfCount = audioArray.length / 2;
                }
                else {
                     // Render bars along the full width of the canvas
                     var barWidth = Math.round(1.0 / 128.0 * audioCanvas.width);
                     var halfCount = audioArray.length / 2;
                }
                // Begin with the left channel in red
                audioCanvasCtx.fillStyle = 'rgb(255,0,0)';
                // Iterate over the first 64 array elements (0 - 63) for the left channel audio data
                for (var i = 0; i < halfCount; i += parseInt(sessionStorage.getItem("bar-amount"))) {
                     // Create an audio bar with its hight depending on the audio volume level of the current frequency
                     var height = audioCanvas.height * Math.min(audioArray[i], 1) * sessionStorage.getItem("bar-height");
                     audioCanvasCtx.fillRect(barWidth * i, audioCanvas.height - height * sessionStorage.getItem("bar-distortion"), barWidth, height);
                }

                // Now draw the right channel in blue
                audioCanvasCtx.fillStyle = 'rgb(0,0,255)';
                // Iterate over the last 64 array elements (64 - 127) for the right channel audio data
                for (var i = halfCount; i < audioArray.length; i += parseInt(sessionStorage.getItem("bar-amount"))) {
                     // Create an audio bar with its hight depending on the audio volume level
                     // Using audioArray[191 - i] here to inverse the right channel for aesthetics
                     var height = audioCanvas.height * Math.min(audioArray[191 - i], 1) * sessionStorage.getItem("bar-height");;
                     audioCanvasCtx.fillRect(barWidth * i, audioCanvas.height - height * sessionStorage.getItem("bar-distortion"), barWidth, height);
                }

                if (sessionStorage.getItem("audio-orientation") == "left") {
                     //temp canvas to store rotation data
                     var tempCanvas = document.createElement("canvas"),
                     tempCtx = tempCanvas.getContext("2d");

                     tempCanvas.width = audioCanvas.width;
                     tempCanvas.height = audioCanvas.height;
                     tempCtx.drawImage(audioCanvas, 0, 0, audioCanvas.width, audioCanvas.height);

                     // Now clear the portion to rotate.
                     audioCanvasCtx.clearRect(0, 0, audioCanvas.width, audioCanvas.height);

                     audioCanvasCtx.save();
                     // Translate (190/2 is half of the box we drew)
                     audioCanvasCtx.translate(audioCanvas.width / 2, 0);

                     // Rotate it
                     audioCanvasCtx.rotate(90 * Math.PI/180);

                     // Finally draw the image data from the temp canvas. 45 and 16 are just random numbers so it lines up correctly
                     audioCanvasCtx.translate(audioCanvas.height / 45, -audioCanvas.width / 16);
                     audioCanvasCtx.width = audioCanvasCtx.width * 10;
                     audioCanvasCtx.drawImage(tempCanvas, 0, 0, audioCanvas.width, audioCanvas.height * 2, 0, 0, audioCanvas.width, audioCanvas.height * 2);
                     audioCanvasCtx.restore();
                }
           }


           // Register the audio listener provided by Wallpaper Engine.
           window.wallpaperRegisterAudioListener(wallpaperAudioListener);
      </script>
 </body>

Select input field options being added outside select field

I am building out a dynamic dropdown field that gets populated with all the “Saturdays” during a 3 month period. The dropdown is being populated correctly but I am getting duplicate ‘options’ added after the closing </select> input. I don’t know what could be causing this. Below in the Javascript when I console.log(formatted); the values only appear ONCE in the Chrome console.

WordPress, Contact Form 7
Dev: Laragon localhost

<select name="dates" class="wpcf7-form-control wpcf7-select wpcf7-validates-as-required span6 dates" aria-required="true" aria-invalid="false">
    <option value="0">Saturday, June 18</option>
    <option value="1">Saturday, June 25</option>
    <option value="2">Saturday, July 2</option>
    <option value="3">Saturday, July 9</option>
    <option value="4">Saturday, July 16</option>
    <option value="5">Saturday, July 23</option>
    <option value="6">Saturday, July 30</option>
    <option value="7">Saturday, August 6</option>
    <option value="8">Saturday, August 13</option>
    <option value="9">Saturday, August 20</option>
    <option value="10">Saturday, August 27</option>
</select>
// HERE'S the issue - Duplicate options added to my page
<option value="0">Saturday, June 18</option>
<option value="1">Saturday, June 25</option>
<option value="2">Saturday, July 2</option>
<option value="3">Saturday, July 9</option>
<option value="4">Saturday, July 16</option>
<option value="5">Saturday, July 23</option>
<option value="6">Saturday, July 30</option>
<option value="7">Saturday, August 6</option>
<option value="8">Saturday, August 13</option>
<option value="9">Saturday, August 20</option>
<option value="10">Saturday, August 27</option>

Contact Form 7

[select* dates class:span6 class:dates "Sat, Jun 04"]

Javascript

jQuery(document).ready(function($) {
// Date object
var date = new Date();
var year = date.getFullYear();
var this_month = date.getMonth();
var this_day = date.getDate();
var num_months = 3;
// Select input
var select = $('.contact .dates');
select.find('option').remove();

// 3 months of Saturdays
let index = 0;
for (var i = 0; i < num_months; i++) {
    var cur_month = this_month + i;
    // Loop through each day of the month
    for (var j = 0; j <= new Date(year, cur_month, 0).getDate(); j++) {    
        var date = new Date(year, cur_month, j);
        // Find Saturdays and append option to select input
        if (date.getDay() == 6){
            let day = "Saturday, ";
            let dayNum = date.getDate();
            let month = date.toLocaleString('default', { month: 'long' });
            // Don't include past Saturdays for the current month
            if (dayNum<this_day && date.getMonth()==this_month){
                continue;
            }
            let formatted = day + month + " "+ dayNum;
            //let value = date.toString('dddd, MMMM ,yyyy');
            select.append($('<option></option>').attr('value', index).text(formatted));
            index += 1;
            console.log(formatted); // This only outputs once NOT twice
        } 
    };
}
});

chrome developer tools changes function response

I found the following js function that determines whether the connected device is mobile or desktop. It works but if I have an open window of chromes developer tools it always returns false.

function checkDevice(){
    /* true = desktop  false = mobile */

    var check = true;
        (function(a){
          if(/(android|bbd+|meego).+mobile|avantgo|bada/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|series(4|6)0|symbian|treo|up.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(a.substr(0,4)))
        check = false;
       })(navigator.userAgent||navigator.vendor||window.opera);

       return check; //check
}

How to use tailwindcss with cytoscape.js?

Is there a way to use tailwindcss classes to style a graph node inside a cytoscapejs canvas?

My cytoscape graph is initialized with one node whose data object is set to id: a. The relevant part of the code:

cy.filter(function (element, i) {
    if (element.isNode() && element.data("id") === "a") {
        element.style("background-color", "red");
        // element.addClass("bg-red-900");
        return true;
    } else {
        return false;
    }
});

The commented line is what I tried to do to make tailwindcss work. Although the class bg-red-900 is added to element.classes(), it still doesn’t take effect.

How to put input element into react quicktable?

I am using https://github.com/joeybuczek/react-quicktable in my react application and I am trying to put an <img/> and <input/> in one of the the datacells but it is not working.

 function MyComponent(props) {

 

    const myDataSet = [
        { Column1: "123456789", Column2: <img src="url" />, "Column3":<input type="text" />},
       
      ];
     
    return ( 
        <Fragment>
            <QuickTable data={myDataSet}>
            <Column name="Column1" />
            <Column name="Column2" />
            <Column name="Column3" />
            </QuickTable>
        </Fragment>
     );
    }

I get ” in the that is rendered. I tried passing a variable like this:

   var j = () => {return <img src/>} 
   var k = () => { return <input type="text" />}

I also tried:

var j = <img src/>
var k = <input type="text"/>

When creating a new object with forEach, some prperties show up as $$typeof: Symbol(react.element) React

So I am receiving an array of Objects, each one has a “attributes.seller” property. Then I am using a forEach( ) to go over each one and create a new object with only the properties I need and pushing them to a new array, including the Seller property.
The issue is that on ALL the received objects the “Seller” property exists and its a string.

However, after constructing the new object most of the seller properties show as “seller: {$$typeof: Symbol(react.element), type: ‘button’, key: null, ref: null, props: {…}, …}”

BUT not all of them, some do show correctly. So IDK whatI am doing wrong if my code was working before and it still works but not for all the items.

This is the object array i am receiving

This is where I itirate over each object:

createdResults.forEach((item) => {
      console.log(item.attributes.seller);
      const offer = {
        itemId: Number(item.attributes.itemId),
        token: item.attributes.token,
        amount: item.attributes.amount,
        price: item.attributes.price,
        seller: item.attributes.seller,
      };
      createdArr.push(offer);

Even when I log out to the console items.attributes.itemId, it shows EVERY SINGLE property just fine.

The issue is after I have pushed each new object into the new array that the “seller” property of it shows like this:
New Object

My array can’t find the source of my pictures, how do I fix it? [closed]

So I’m building an comic slider on javascript and I want it to have a “pick a random comic” option. So, naturally, I tried to built a random function over a pretty big array. And made it, but, the function can’t find the src of the pictures! What should I do? Everything seems good but maybe I’m missing something… can u help me with my code? thanks!

function random() {    
var randomNum = Math.floor(Math.random() * imgArray.length);
document.getElementById("comicdehoy").src = imgArray[randomNum];
}

Script cannot find attributes of an appended html element

It outputs undefined for both. It should output lpoop and /poop. No errors are given

<script type="text/javascript">
  function add() {
    console.log("add")
    var l = document.createElement("img")
    l.setAttribute("src", "/poop")
    l.src = "/poop"
    l.setAttribute("class", "l")
    l.className = "lpoop"
    document.getElementById("b").appendChild(l)
  }
  </script>
  <script>
  function find (){
  console.log("find");
  const elm = document.getElementById("b").firstChild;
  console.log(elm.className);
  console.log(elm.src);
  }
</script>
<button onclick="add()">
  hi
</button>
<button onclick="find()">
find
</button>
<div id="b">

</div>

If there is any more detail you want pls comment.

AES encryption using C# and decryption using Javascript

I’ve got a set of functions for encrypting/decrypting on the server (C#), however I’d like to port the decryption piece to Javascript. Here’s the C# decryption functions I’ve used previously in C# with a sample encrypted string, password and IV

I’m having trouble with the JavaScript decryption piece using Cryptojs. The result that comes back is unexpectedly an empty string.

var ciphertext = "0MuDwNoWBFjN/1anszbl0Cxkrwh9ahRwE3c61t7io2c=";
var key = "8beee7ac-42d1-4294-91b8-68cd032cf1e1";
var iv = "9bC_#$/-+%@Kli%1Az=-@qT";

var ciphertextWA = CryptoJS.enc.Hex.parse(ciphertext);
var keyWA = CryptoJS.enc.Utf8.parse(key);
var ivWA = CryptoJS.enc.Utf8.parse(iv);
var ciphertextCP = { ciphertext: ciphertextWA };

var decrypted = CryptoJS.AES.decrypt(
    ciphertextCP,
    keyWA,
{ iv: ivWA }
);
console.log(decrypted.toString(CryptoJS.enc.Utf8));

Error: “You must provide an app access token, or a user access token that is an owner or developer of the app” using Facebook Login SDK

I have the problem that users can use our system to request reports of their ads on facebook.

These are the functions I use in the frontend (React):

export function initFacebookSdk() {
  return new Promise(resolve => {
    // wait for facebook sdk to initialize before starting the react app
    window.fbAsyncInit = function () {
      window.FB.init({
        appId: 'app-id',
        cookie: true,
        xfbml: true,
        version: 'v14.0'
      });
      resolve()
    };   
  });
}

export const FbLogin = () => {
  loadFacebookSDK(document, "script", "facebook-jssdk")
  initFacebookSdk()
  return new Promise( resolve => {
    window.FB.login(response => {
      if (response.authResponse) {
        resolve(response);
      } else {
        resolve(response);
      }
    }, {scope: 'ads_management,ads_read'});
  })
}

And so I call the function

const response = await FbLogin();

I send the token to the backend and this is how it uses the route:

try {
  const { data: accountsInfo } = await axios({
    url: `https://graph.facebook.com/v${FB_GRAPH_API_VERSION}/me/adaccounts?access_token=${accessToken}&pretty=1&limit=100`,
    method: 'GET',
  });
  

  res.status(200).json({success: true, accountsInfo})
  
} catch (err) {
  console.log(err);

  res.status(500).json({success: false})
}

And this is the error that I get when trying to use the user token:

'OAuth "Facebook Platform" "invalid_request" "(#100) You must provide an app access token, or a user access token that is an owner or developer of the app"'

Does anyone know why this is happening to me? help 🙁

Insert a variable into an objects name in Javascript [duplicate]

If you look at the JSON posted further below, I have several objects named row0, row1, row2 etc…

The code I posted further below works but not as intended. The problem lies with the following line:

for (let key in movies.row1) {

I hard coded row1 but I really want to achieve is row1 then row2 then row3 etc…

So I want to insert the value of i into the name of the object after the word row…

movies.rowi <— i needs to be a variable not the letter i.

I tried a few guesses from googling and stackoverflow like movies.row${[i]} but nothing worked. Also, tried spread operator something like movies.row[1…6] but its invalid.

  function display_all_movies(movies) {

    for (i = 0; i < movies.row_count.count; i++) {

    for (let key in movies.row1) {

       document.getElementById("moviesList").innerHTML += `Key: ${key}` + `Value: ${movies.row1[key]}` + '<br>';

    }
  }
}

movies is an object in JSON format, which is validated. Movies JSON is as follows:

{"row0" : {"title":"Avengers","imgName":"Avengers.jpeg","addedBy":"MrCoolDude","stars":"4"},"row1" : {"title":"Spiderman","imgName":"Spiderman.jpeg","addedBy":"TheNumber2Dude","stars":"5"},"row2" : {"title":"Conair","imgName":"conair.png","addedBy":"Eagleuser","stars":"3"}, "row_count" : {"count" : "4"},"row3" : {"title":"Robin","imgName":"Robin.jpeg","addedBy":"UserBatman","stars":"4"}}

`window.location.href` in client vs `res.redirect` in express

I want to send user to a certain link, there are 2 ways to getting there:

  1. Browser Client Approach
  • I call express endpoint /redirect
  • It calculates the url to redirect to
  • It returns the url to redirect to
  • Client browser redirects via window.location.href
  1. Express Server Approach
  • I call express endpoint /redirect
  • It calculates the url to redirect to
  • It calls res.redirect(url)

Which is the best way? Is there any significant differences between these?

The current use case I’m looking into has documentation which showed the 2. express example. However I saw some use cases where the 1. browser approach is used

Enable input field oncheck using javascript

Can I make my code look like this? I am wondering if I can do this, as I am trying this from last 3 days but still no success. I want to enable a specific input field on check using javascript but it is not working.

<?php
    $rows = 1;

    if(isset($_GET['number_of_rows'])) {
        $rows = $_GET['number_of_rows'];
    }

    for ($i=0; $i < $rows; $i++) { 
    ?>

    <input type="checkbox" id="mycheck<?=$i?>" onclick="myFunction<?=$i?>()">Enable row
    <input placeholder="student name" type="text" name='name<?=$i?>' id="input<?=$i?>" disabled required>   
    <input placeholder="student id" type="number" name='id<?=$i?>' id="input<?=$i?>" disabled required>

    </div>

    <?php
    }
    ?>

    <form method="get">
        <input type="number" value="<?=$rows?>" max=10 min="1" name="number_of_rows" required>
        <input type="submit" name="submit2">
    </form>

    <?php for ($i=0; $i < $rows; $i++) { ?>
        <script>

        function myFunction<?=$i?>() {

            if(mycheck<?=$i?>.checked == true) {
                document.querySelectorAll("[id^='input<?=$i?>']")
                .forEach(element => 
                    element.disabled = false
                );
            }

            if(mycheck<?=$i?>.checked == false) {
                document.querySelectorAll("[id^='input<?=$i?>']")
                .forEach(element =>
                    element.disabled = true
                );
            }

            if(document.getElementById("mycheck<?=$i?>").disabled == true) {
                document.getElementById("mycheck<?=$i?>").disabled = false;
            }
        }

        </script>
    <?php } ?>

How to change props object name when it’s clicked in react?

I’m creating a youtube clone using react js and i used this icon

import HomeIconfilled from '@mui/icons-material/Home';
import HomeIcon from '@mui/icons-material/HomeOutlined';

That looks like this HomeIconfilled

which gets rendered by calling this function

        <Sidebariconfunc  Icon={HomeIconfilled} Title="Home"/> 

That takes 2 parameters and reder the icon

function Sidebariconfunc({Icon,Title}) {


return (
    <div className='SidebarRow'>
           <div className='Sidebar_Icon'>
              <Icon/>
           </div>
             <div className='Slidebar_Title'>
                  {Title}
             </div>
    </div>
  )
}

How can i chane the props name to HomeIcon when i click on the icon so that it changes to this this icon HomeIcon
Thamks !

Changing of values of keys in JSON

I have an application, where I use MongoDB, Express and MongoDB. On server side I received data by using find in such look – array of objects(JSON), which is named upProbations. For example, I find information about Max:

[        
  {
        Name: 'Max',
        DateOne: 2019-01-01T00:00:00.000Z,
        DateTwo: 2019-04-01T00:00:00.000Z,
        Info: 'Cheerful'
  }
]

I want to change information a bit – fields DateOne and DateTwo. They have both types Date and I want to leave only 2019-01-01 and same for DateTwo, so i don’t need time(hour, minute, second). The result should look like this:

[        
  {
        Name: 'Peter',
        DateOne: 2019-01-01,
        DateTwo: 2019-04-01,
        Info: 'Cheerful'
  }
]

This result I will futher use for antoher calculations. I have tried such code, but it’s not working:

upProbations = upProbations.map(function(a) {
    a.startProb = a.startProb.toISOString().replace('T', ' ').substr(0, 10);
return a;
})
console.log(upProbations);

In which way I can do this?