Hello, i need to get the download URL from Firebase, Storage , using JavaScript, in html , The Picture gets uploaded , but I get no DownloadURL?

When I hit upload the picture gets uploaded to firebase Storage, but i cant seem to get the image url, I can go to the Storage tab on firebase click on the image and click on its ling , copy the link in and then past it into the DATABASE were i need it for display and it will work, But i dont see an image URL or A download URL when i consolo.log the snapshot of the const TASK!
I fear that the method:

“const task = uploadBytesResumable(storeref, ImSRC, metdata)”

that iam using to upload the image does not produce an image url! Could This be So?
!!!HERE IS ALL THE CODE FOR THE UPLOAD BUTTON !!

Upload.addEventListener(‘click’, (e) =>{

    let ImSRC = files[0];
    
    if(ImSRC == null ){
        alert('no picture selected');
    }else{
            const metdata = {
            contentType: ImSRC.type
            }
            const storeref = sRef(storage,"UsersProPic/" + cUserID);
            const task = uploadBytesResumable(storeref, ImSRC, metdata).then((snapshot)=>{
                    let PicUrl = snapshot;
                    function getData(PicUrl){
                            PicUrl.getDownloadURL.then((url)=>{
                            ProPicUrl = url;
                            })  
                    }
                    console.log(ProPicUrl);
                    
            });
                //update(ref(database, 'PickPlay/' + 'Users/' + cUserID),{
                //  imurl : ProPicUrl
                //})
    
      }
                             
});

java помогите решить задачу [closed]

Дано следующее условие: компания друзей посещает ресторан. Они решили разделить счет поровну и добавить 10 процентов от общей суммы счета в качестве чаевых. Далее друзья равными частями покрывают общую сумму платежа.

Перейдите в класс GoDutch и напишите программу, которая считывает общую сумму счета и количество друзей, а затем выводит размер части оплаты.

Рассмотрим некоторые детали:

Программа должна читать данные из System.in
Общая сумма счета не может быть отрицательной. Если введенное значение отрицательное, программа останавливается и печатает: Bill total amount cannot be negative
Количество друзей не может быть отрицательным или нулевым. Если такое происходит, то программа останавливается и выводит: Number of friends cannot be negative or zero
Общая сумма счета, количество друзей и часть к оплате являются целыми числами.

КОД:

package com.epam.rd.autotasks.godutch;
import java.util.Scanner;
public class GoDutch {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        if (n > 0) {
            System.out.println(n);
        } else if (n < 0) {
            System.out.println("Bill total amount cannot be negative");
            break;

        } else {
            System.out.println("Number of friends cannot be negative or zero");
        }
        if (n == 0) {

            System.out.println("Number of friends cannot be negative or zero");
        }
    }
}

Webserver responds with “text/html” instead of “text/javascript” for mjs

I have a website hosting on localhost:8000. I use a JavaScript module file for import.
The file structure looks like that:

MyApp
|- scripts
   |- main.mjs
   |- package.json
|- index.html

For the MIME-types, I used extensions_map for my webserver. It’s written in python:

import http.server
import socketserver

class Handler(http.server.SimpleHTTPRequestHandler):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, directory="PATH_TO_MyApp", **kwargs)


handler = Handler
handler.extensions_map.update({
    ".html": "text/html",
    ".css": "text/css",
    ".mjs": "text/javascript",
})
httpd = socketserver.TCPServer(("localhost", 8000), handler)
print(handler.extensions_map[".mjs"])  # Output: text/javascript
httpd.serve_forever()

The script tag in the html file looks like that:

<script type="module" src="./scripts/main.mjs"></script>    

The errors:

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
... 5x 

Unchecked runtime.lastError: The message port closed before a response was received.

Extending Error class with CustomError class. Why does error code not exist on type ‘CustomError’?

I got the following Error class extension that works, but only with messages.

class CustomError extends Error {
  constructor(message) {
    super(message); // 'Error' breaks prototype chain here
    this.name = "CustomError";
    Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain
  }
}

// Working Test
throw new CustomError("Message only error.");

So I tried to modify it to include an error code too.

class CustomError extends Error {
  constructor(code, message) {
    super(message); // 'Error' breaks prototype chain here
    this.name = "CustomError";
    this.code = code;
    Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain
  }
}

// Non-Working Test
throw new CustomError(123, "and Message erro.");

But I get the following error:

Property 'code' does not exist on type 'CustomError'.

What am I doing wrong?

Iterating over object and displaying as table – React.js

I have an object:

{
  cities: { 
    MCR: "Manchester",
    LDN: "London",
    NYC: "New York"
  }
}

and I want to iterate over these and display them in a table format which will show the city code and the long name next to it. Something like:

 <tbody>
          <tr>
            <th>City Code</th>
            <th>City Name</th>
          </tr>
            <tr>
              {Object.entries(cities).map(([key, value]) => {
                <>
                <td>{key}</td>
                <td>{value}</td>
                </>
              }
            )}
          </tr>
    </tbody>

However this doesn’t display anything and also shows an error when hovering over value:

Type 'unknown' is not assignable to type 'ReactNode'.ts(2322)

I’m quite new to React and wondering how best to display this information?

Thanks

Upload the video to the buffer, then change the src attribute

<video id=video controls mute></video>
<script>
    
    let source = new MediaSource,
    buffer = MediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');

    (xhr = new XMLHttpRequest).open('get', 'frag_bunny.mp4');
    xhr.responseType = 'arraybuffer';
    xhr.onload = _ => {
        buffer.onupdateend = _ => {
            source.endOfStream();
            video.src = URL.createObjectURL(source);
            video.muted = true;
            video.play();
        };
        buffer.appendBuffer(xhr.response);
    }
    xhr.send();

 </script>

The code is not working. I really need your help

I am looking for a solution in which it is possible to preload a video file to the buffer. At the same time, change the src attribute of the video when the video is in the buffer. That is, upload a video and then insert or change the src attribute of the current video in the document. Is it possible to implement such a thing?

Sending bitcoin transaction using multiple inputs and multiple outputs

My target – send to one of my users requested amount of BTC.
I have many BTC wallets generated from the same mnemonic phrase with different balances.

So, my inputs data is – target wallet, target amount and list of wallets with balances.
If found a set of inputs with total balance more than I need to send, I need to return difference between inputs balance and target amount to random input.

My data looks like:

[
  {
    "wallet": "xxxx1",
    "privateKey": "key1",
    "unspentAmount": 46659,
    "unspentTransactions": [
      {
        "tx_hash_big_endian": "..",
        "tx_hash": "...",
        "tx_output_n": 0,
        "script": "...",
        "value": 46659,
        "value_hex": "00b643",
        "confirmations": 757,
        "tx_index": 1156017252431081
      }
    ]
  },
  {
     "wallet": "xxx2",
    "privateKey": "key2",
    "unspentAmount": 13339,
    "unspentTransactions": [
      {
        "tx_hash_big_endian": "...",
        "tx_hash": "...",
        "tx_output_n": 0,
        "script": "...",
        "value": 13339,
        "value_hex": "00b643",
        "confirmations": 757,
        "tx_index": 1156017252431081
      }
    ]
  }
]

How to build transaction using bitcoin-core or bitcoin-lib?
I need multiple inputs and multiple outputs.

Is event of button which type is submit click or submit?

Could you please advise which event I should write in code for of type submit. Is it click or submit. I know that submit should be put for form. If button submit put inside in form I may write

$('form').submit()

is’s for case of pushing button enter on keyboard.
If push button of the form should I write in code

$('button[type="sumbit"]').click()

Why using .filter() together with .match() is only returning the first element matching the condition?

I have some HTML code where at the most nested level there is some text I’m interested in:

<div class="main">
  <div class="container">
    
    <div class="output_area">
      <pre> WHITE 34 </pre>
    </div>
    <div class="output_area">
      <pre> RED 05 </pre>
    </div>

    <div class="output_area">
      <pre> WHITE 16 </pre>
    </div>
    <div class="output_area">
      <pre> BLACK </pre>
    </div>
  
  </div>
</div>

What I need to do is I need to return the output_area elements only when their nested <PRE> element contains a word + a number (for example WHITE 05, and not just BLACK).

So this is what I did:

I made an array from all output_area elements:

output_areas = Array.from(document.getElementsByClassName('output_area'));

I filtered the output_areas array to only return those output_area elements whose nested <PRE> satisfies my condition of a word + a number, using a regexp, like so:

output_areas.filter(el => el.textContent.match(/^WHITE d+$/g));

Now, what happens is this function will only return the first matching result, so I will get an object of length 1 containing just :

<div class="output_area">
      <pre> WHITE 34 </pre>
</div>

and the output_area element containing <PRE> with “WHITE 16” is not returned.

As you can see at the end of the regular expression I put a “g” to request a global search and not just stop at the first result.

Not understanding why this did not work, I tried to verify what would happen if I would use includes() to perform a search:

output_areas.filter(el => el.textContent.includes('WHITE')

(let’s just forget about the numbers now, it’s not important)

And what happens? This will also return only the first output_area…

But why??? What am I doing wrong?
I am not ashamed to say I’ve been banging my head on this for the last couple of hours… and at this point I just want to understand what is not working.

The only clue I think I got is that if I simplify my search using just a == or !=, for example:

output_areas.filter(el => el.textContent != "")) // return all not empty elements 

I get back all output_area elements and not just the first one!

So I suspect there must be some kind of problem when using together filter() & match(), or filter() & includes(), but with relation to that my google searches did not take me anywhere useful…

So I hope you can help!

Long XHR Get Request stays on “Pending” in Google Chrome even though a response is returned from the server

I run into a situation where the XHR GET Request takes a long time to get a response from the server. For example to get the data for:

  • a month of Jan: 7 seconds
  • a month of Feb: 1.5 minutes
  • a whole year: 7 minutes

Performance issue aside, I want to find out why on a request that takes 7 minutes to complete that Google Chrome stays on the “Pending” state and not receiving the response from the server.

I have confirmed that the server actually sends the response by:

  • setting a breakpoint on the API controller that return a response. The breakpoint actually is hit.
  • testing the same URL on Postman. Postman received the response after 7 minutes.

I am guessing this has something to do with Google Chrome timeout (or web browser timeout) but cannot really find resources that confirm the assumption.

So my questions are:

  • Is the behavior I am seeing due to web browser timeout?
    • If it is, is there a way to increase this timeout across all web browser through javascript? (Basically if the backend performance can’t be improved, what are my options from the front-end perspective to still get the result even though the process takes a long time).