How to preview files from local storage in React JS version 18

I am currently working with a React application that can upload documents, and the files would be stored in the local project directory. I want to add preview functionality where all sorts of uploaded files (jpg,png, pdf, doc, docx, xls, xlsx) can be shown and rendered accordingly, but most of the react libraries I stumbled upon cannot access the files locally (e.g., react-doc-viewer). Some are also deprecated and are not compatible with the current application’s React version 18 (e.g., react-file-viewer). Thus, would you have any recommendations on what options I could have, perhaps specific libraries that I could use?

List Variables – Express JS

I’m trying to debug some code which I would like to access a list of all the global variables my express server has stored;- but im not sure how to do it without using the keys(window) method which only works for browsers. Any ideas?

object(keys) console.log(keys) keys(window)

Math.floor no funciona como esperaba / math.floor not working as expected

me hice una cuenta solo para preguntar esto, y es que math.floor no me esta dando lo que pido,
miren

translated into english by google
Hello, I made an account just to ask this, and it is that math.floor is not giving me what I ask for,
look

class test {
    constructor(valor1,valor2,){
        this.one = valor1;
        this.two = valor2;
    }
    
}

var Jorge = new test("100","50")

    for (let i = 0; i < 30; i++) {
        test = Math.floor(Math.random()*(Jorge.one-Jorge.two+1)+Jorge.two);
        console.log(test)
}

esto tendría que darme un numero que este entre 100 y 50 ni mas ni menos, sin embargo me esta dando numeros que son menores a 50, a veces me tira hasta 0.

probé esto sin un class y funciona perfectamente, no entiendo por que no funciona con los class.
alguna idea?

translated into english by google
this would have to give me a number that is between 100 and 50 neither more nor less, however it is giving me numbers that are less than 50, sometimes it throws me up to 0.

I tried this without a class and it works perfectly, I don’t understand why it doesn’t work with classes.
any ideas?

Clicking menu button not working until page fully loaded

I have a sidebar menu created with w3school. The issue is that until the page is fully loaded (including images and Adsense advertising), the Menu button does not react to clicks.

The javascript code I use is the basic one, inside head tags:

var openMenu = false;

function w3_open() {
  if (openMenu) {
     document.getElementById("mySidebar").style.display = "none";
     openMenu = false;
   } else {
     document.getElementById("mySidebar").style.display = "block";
     openMenu = true;
   }
  
}

function w3_close() {
   document.getElementById("mySidebar").style.display = "none";
   openMenu = false;
}

<button class="w3-button w3-teal w3-xlarge w3-dark-gray" onclick="w3_open()">☰ Menu</button>

I need the menu to be clickable while the webpage is loading.

Horizontal tabs scroll in Angular

I have the below code. The number of article-type-items is dynamic. There can be more than 15 types at a time. I want to make this scrollable horizontally with a left and right arrow at the ends if it exceeds the with. This should be responsive across all devices including Desktop, Laptops, tablets and mobiles. Arrows should be visible only if the width is exceeded. How can I achieve this in HTML/CSS?

Any help is appreciated. Thanks 🙂

<div class="container">
      <!-- Tabs here -->
      <div class="d-flex">
        <div class="me-3 article-type-item">
          <p>Searched Result</p>
        </div>
        <div class="mx-3 article-type-item">
          <p>Trending Topics</p>
        </div>
        <div class="mx-3 article-type-item">
          <p>Reporting</p>
        </div>
        <div class="mx-3 article-type-item">
          <p>Accounting</p>
        </div>
      </div>
    </div>```

Local fonts fails to resolve in next.js while deploying in vercel

I am trying to use next/fonts in next.js 13.3. Everything works fine locally but when I deployed to Vercel, I keep getting this build error Module not found: Can't resolve './fonts/BrFirma-Thin.woff2'

This is what my folder structure looks like

  • src
    • _app.js
    • styles
      • font.js
      • fonts

_app.js

import { BRFirma } from 'styles/font';
...
 <main className={BRFirma.className}>
  ...
 </main>

font.js

import localFont from 'next/font/local';

export const BRFirma = localFont({
    src: [
       
        {
            path: './fonts/BrFirma-Regular.woff2',
            weight: '400',
        },
        {
            path: './fonts/BrFirma-SemiBold.woff2',
            weight: '600',
        },
    ],
}); 

Again I moved the fonts to the public folder just to make sure I am doing it right.

font.js

import localFont from 'next/font/local';

export const BRFirma = localFont({
    src: [
       
        {
            path: '../../public/assets/fonts/BrFirma-Regular.woff2',
            weight: '400',
        },
        {
            path: '../../public/assets/fonts/BrFirma-SemiBold.woff2',
            weight: '600',
        },
    ],
});

Once again, everything works fine locally but deployment still fails with the module not found message.

Just for the record, this is what jsconfig.js file looks like.

{
    "compilerOptions": {
        "baseUrl": "src",
        "paths": {
            "@/*": ["./src/*"]
        }
    },
    "exclude": ["node_modules", "build", "dist", "jest"]
}

Failed to execute ‘createMediaStreamSource’ on ‘AudioContext’: parameter 1 is not of type ‘MediaStream’

I am developing a webApp in ASP.net Core MVC.

I am trying to record audio using AudioContext:

var recordButton = document.getElementById("record-button");
var stopButton = document.getElementById("stop-button");

var audioContext = new AudioContext();

var mediaStream = navigator.mediaDevices.getUserMedia({
    audio: true
});

var microphone = audioContext.createMediaStreamSource(mediaStream);

var gainNode = audioContext.createGainNode();
var recorder = new AudioBufferRecorder();

recordButton.addEventListener("click", function () {
    microphone.connect(gainNode);
    gainNode.connect(recorder);
    recorder.start();
    recordButton.disabled = true;
    recordButton.style.pointerEvents = "none";
});

stopButton.addEventListener("click", function () {
    microphone.disconnect();
    gainNode.disconnect();
    recorder.stop();
    var audioData = recorder.getBuffer().getChannelData(0);
    var formData = new FormData()
    formData.append('audioData', audioData)
    formData.append('sentence', $('#sentence-input').val())
    $.ajax({
        url: '@Url.Action("ProcessAudio", "Sandbox")',
        type: 'POST',
        data: formData,
        processData: false,
        contentType: false,
        success: function (data) {
            $('#modalContent').html(data);

            $('#myModal').modal('show');
        },
    })
});

On var microphone = audioContext.createMediaStreamSource(mediaStream); the exception

Failed to execute ‘createMediaStreamSource’ on ‘AudioContext’: parameter 1 is not of type ‘MediaStream’.

is thrown, even tho I have var mediaStream = navigator.mediaDevices.getUserMedia({ audio: true });

What shall I do?

Kotlin error: ‘LocationRequest.create()’ not working despite updating LocationRequest.Builder

It asks me to update LocationRequest.Builder, but I change it and I still get an error
enter image description here

I tried the LocationRequest.Builder method, but it keeps getting an error

val locationRequest= LocationRequest.create().apply{
            interval =0
            fastestInterval=0
            priority = Priority.PRIORITY_HIGH_ACCURACY
            smallestDisplacement = if ()
        }

Which code would I replace it with, it’s for andriod studio kotlin

HTML and JavaScript – Incorrect POST output generated

Does anyone know why the following would not generate the expected POST output when submitted?

<tr>
   <td><input type="hidden" name="lawyer[1][OptimaID]" value="L7M"></td>
   <td><input type="checkbox" name="lawyer[1][checkbox]" value="checked">
   <input type="hidden" name="lawyer[1][pmID]" value="3"></td>
</tr>
<tr>
   <td>
      <select name="lawyer[2][OptimaID]">
         <option name="lawyer[2][OptimaID]" value="LSF">LS  - </option>
         <option name="lawyer[2][OptimaID]" value="L0J">Lom</option>
         <option name="lawyer[2][OptimaID]" value="L2J">Lm</option>
      </select>
   </td>
   <td><input type="checkbox" name="lawyer[2][checkbox]" value="checked">
   <input type="hidden" name="lawyer[2][pmID]" value="5"></td>
</tr>
<tr>
   <td><input type="hidden" name="lawyer[3][OptimaID]" value="LS9"></td>
   <td><input type="checkbox" name="lawyer[3][checkbox]" value="checked">
   <input type="hidden" name="lawyer[3][pmID]" value="6"></td>
</tr>
<tr>
   <td>
   <input type="hidden" name="lawyer[4][OptimaID]" value="L9"></td>
   <td><input type="checkbox" name="lawyer[4][checkbox]" value="checked">
   <input type="hidden" name="lawyer[4][pmID]" value="1536146674"></td>
</tr>
<tr>
   <td>
      <select name="lawyer[5][OptimaID]">
         <option name="lawyer[5][OptimaID]" value="LSO-53648V">Vart.com</option>
         <option name="lawyer[5][OptimaID]" value="LSO-84359E">L06 - </option>
      </select>
   </td>
   <td><input type="checkbox" name="lawyer[5][checkbox]" value="checked">
   <input type="hidden" name="lawyer[5][pmID]" value="2"></td>
</tr>
<tr>
   <td>
   <input type="hidden" name="lawyer[6][OptimaID]" value="LR"></td>
   <td><input type="checkbox" name="lawyer[6][checkbox]" value="checked">
   <input type="hidden" name="lawyer[6][pmID]" value="3"></td>
</tr>


I am getting:

lawyer[1][OptimaID] "value"
lawyer[1][pmID] "value"
lawyer[2][OptimaID] "value"
lawyer[2][pmID] "value"
lawyer[3][OptimaID] "value"
lawyer[3][pmID] "value"
lawyer[4][OptimaID] "value"
lawyer[4][pmID] "value"
lawyer[5][OptimaID] "value"
lawyer[5][pmID] "value"
lawyer[6][OptimaID] "value"
lawyer[6][pmID] "value"

I tried:

  • adding [] at the end of the name of each field
  • added double quotes around the “OptimaID” and “pmID”
  • starting the index at 0 and 1

Searched for all the html form name array and other posts such as: https://mattstauffer.com/blog/a-little-trick-for-grouping-fields-in-an-html-form/ but cant seem to see why my POST data is not grouping properly

What are the limitations of using Chat GPT to generate code with minimal coding experience? [closed]

I am developing an app with very minimal coding experience by asking chat GPT to do something, then testing it and then putting it back in and getting it to write all the code again, including the changes. Is there a smarter / better way to do it? What do I actually still need to learn to do? Does anyone with experience have any thoughts/advice? Is that what programmers did before chat GPT anyway, getting functions from online and stitching it together? Appreciate any thoughts on the matter as I dont want to spend time learning things I dont need as I have dyslexia and it takes alot of energy. Also is it in our foreseeable future where AI will be building apps from scratch much faster with english?

Cheers!

Iv succesfully gotten chat GPT to write code, iterate it, then ask for another change, and keep feeding it back into itself until it gets that change right then move to the next thing. (500 lines so far)

Datatable.net Built in styles for word wrap

I am using Datatable.net and wanted my excel export to word wrap. I have tried using $(this).attr(‘s’, 55); like this https://datatables.net/reference/button/excelHtml5#Built-in-styles. I have also tried setting the width and seeing if that helps. I have also tried added ” but nothing has been working.

JS Code

$(tableId).DataTable({
    "lengthMenu": [
       [10, 15, 20, -1],
       [10, 15, 20, "All"]
     ],
    "pageLength": -1,
    scrollX: true,
    buttons: [
    {
       extend: 'excelHtml5',
       title: "Individual Report - " + moment().format('MM-DD-YYYY'),
           customize: function (xlsx) {
              var sheet = xlsx.xl.worksheets["sheet1.xml"];
              var col = $("col", sheet);
              col.each(function () {
                 $(this).attr('s', 55);
                 $(this).attr('width', 33);
              });

        }
     }
   ]
 );

Loop in a multidimensionnel JS array

I’ve this array in JS:

datas = [
    ["Elem1", "Data1"],
    ["Elem2", "Data2"],
    ["Elem3", "Data3"]
];

I’m using:

datas.forEach((element, index) => {
  alert(element.Elem1);
});

But it don’t work.

How I can loop to get each result ?

Thanks.

Code can not read property 1 of undefined

I’m a very new programmer and am working on a Tdarr plugin in JS.
Everything works fine until a 4k file tries to get transcoded and it fails with this log

2023-05-24T19:09:54.906Z ZoBKWMMKG:Node[hidden-hog]:Worker[tall-tuna]:{“pluginInputs”:{“BitRate”:”4000″,”ResolutionSelection”:”1080p”,”Container”:”mkv”,”AudioType”:”AAC”,”FrameRate”:”24″}}

2023-05-24T19:09:54.907Z ZoBKWMMKG:Node[hidden-hog]:Worker[tall-tuna]:Error TypeError: Cannot read property ‘1’ of undefined

It’s saying that it’s unable to read property 1 of undefined and I’m looked and looked and looked and can’t find what it is referring to. Hoping to get another set of eyes on it
The plugin Code is here
https://github.com/HaveAGitGat/Tdarr_Plugins/pull/412/commits/1abd84459179292ec07d5587a86c1a68c8b68a4d
So I don’t need to drop 200 lines

Tried transcoding 4k files down to 1080p but it fails due to that undefined error. All Res 1080p and lower that I have tried work correctly