text:
Q: How to check upload speed in javascript? Basically I have created a simple project where users can drag and drop to upload a file to server. Just to inform the user how long would it take to complete the process I need to show their upload speed. I found this question estimate users' upload speed without direct permission But It quite didn't suited my project.
So here is my code how i'm upload the file:
function upload(file){
    var xhr=new XMLHttpRequest();
    xhr.onreadystatechange = function() {

        if (xhr.readyState == XMLHttpRequest.DONE) {
               alert(xhr.responseText);
        }
    }

    xhr.upload.addEventListener('progress', function(e){
    $('.upgbar').show();
    $('.trkpb').css('width', (e.loaded/e.total*100)+"%");

    var loaded = e.loaded;
    var total = e.total;
    var progressValue = Math.round( ( e.loaded / e.total ) * 100 );

    var seconds_elapsed =   ( new Date().getTime() - started_at.getTime() )/1000; var bytes_per_second =  seconds_elapsed ? loaded / seconds_elapsed : 0 ;
    var Kbytes_per_second = bytes_per_second / 1000 ;
    var remaining_bytes =   total - loaded;
    var seconds = seconds_elapsed ? remaining_bytes / bytes_per_second : 'calculating' ;
    $('.time_re').text("Time Remaining: "+seconds.charAt(0));
    }, false);

    xhr.open('post','../uploadtostack',true);
    xhr.setRequestHeader('X-File-Name',file.name);
    xhr.setRequestHeader('x-File-Size',file.size);
    xhr.setRequestHeader('X-File-Type',file.type);
    xhr.send(file);
}

through xhr.upload.addEventListener I can estimate the time remaining and the amount of data uploaded But don't know to munipulate this to show me the upload speed. and If you Might why am I getting an error at line $('.time_re').text("Time Remaining: "+seconds.charAt(0));

TypeError: seconds.charAt is not a function[Learn More]

I would really appreciate if someone could tell me how to implement a speechecker in javascript || jquery. Regards

A: You can try send a defined size file before and calculate the estimate time with this.
Example: demo file.txt > size 10k 1 second
another: filetoupload.txt > size 20k expected time 2 seconds


text:
Q: sets in python 2.7 deprecated It seems sets are deprecated in Python 2.7 and wondering what is the alternative for unordered unique collection? Thanks.
from sets import Set

a = Set()
a.add("1")
a.add("2")
a.add("3")

if "1" in a:
    print "1"
if "Hello" in a:
    print "Hello"

regards,
Lin

A: Sets are still available in python 2.7 and are built in.
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a_set = set([1, 2, 3])
>>> a_set
set([1, 2, 3])
>>> b_set = {1, 2, 3}
>>> b_set
set([1, 2, 3])

Docs: https://docs.python.org/2/library/sets.html
And see the Notice at the top of the page:

Deprecated since version 2.6: The built-in set/frozenset types replace
  this module.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Changing TextView properties in IBAction method I'm trying to have some text in a UITextView change color (and sometimes change text) after a button press:
I have loaded a text view in ViewController with a simple string in viewDidLoad
self.answer1TextView.text = questions[1];

The above displays just fine.
There is button next to it, which triggers the following method (also in ViewController):
- (IBAction)select1ButtonTapped:(id)sender {
    self.answer1TextView.textColor = [UIColor redColor];
}

The problem is this: when the button is tapped, the text in the UITextView doesn't change color, and the right half of the view disappears.
I'd greatly appreciate some advice on this.  Thank you.


text:
Q: Multiple steps of branching probabilities There are 4 urns.
urn A has 2 black balls and 6 white balls
urn B has 4 black balls and 4 white balls
urn C has 6 black balls and 2 white balls
urn D has 8 black balls
You choose an urn at random with equal probability, then draw 3 balls from it, one at a time, without returning any back to the urn. What's the probability of drawing a black ball if 2 black balls were drawn in the first two drawings?
I understand that I have to multiply probabilities in order to find one "branch" and then sum all the branches, but I keep getting wrong answers like 1/2 or 5/14 and I can't figure out why.

A: Problem Setup:
Let events $A,B,C,D$ be the events that we happened to be drawing from urns $A,B,C,D$ respectively.
Let $X$ be the event that the first two balls drawn happened to be black.
Let $Y$ be the event that the third ball drawn happens to be black.
You are tasked with finding $\Pr(Y\mid X)$.  To do this, recognize that $\Pr(Y\mid X) = \Pr((Y\cap A)\cup (Y\cap B)\cup (Y\cap C)\cup (Y\cap D)\mid X)$
$ = \Pr(Y\cap A\mid X)+\Pr(Y\cap B\mid X)+\Pr(Y\cap C\mid X)+\Pr(Y\cap D\mid X)$
$ = \Pr(Y\mid A\cap X)\Pr(A\mid X) + \dots +\Pr(Y\mid D\cap X)\Pr(D\mid X)$
The value of pieces like $\Pr(Y\mid C\cap X)$ can be found intuitively.  This for instance, we are asking what the probability the third ball drawn will be black given we are pulling from urn C and two black balls have already been pulled.  Well, in this scenario, there are $4$ black balls left after our earlier pulls out of $6$ balls in total giving $\Pr(Y\mid C\cap X) = \dfrac{4}{6}$
The rest of the pieces such as $\Pr(C\mid X)$ can be found from Bayes' Theorem.  Recall that $\Pr(C\mid X) = \dfrac{\Pr(X\mid C)\Pr(C)}{\Pr(X)}$.  Each of the pieces here should be readily obtainable.  I leave the rest of the calculations and piecing of everything together to you.


text:
Q: How to have the program wait for input before proceding I am having a problem where my program is scanning for two different inputs at the same time.
import java.util.Scanner;

public class Person {

public static void main(String[] args){
Person p1 = new Person();

System.out.println("1: Add Person");
System.out.println("2: Delete Person");
System.out.println();
System.out.print("Please make a selection: ");
Scanner keyboard = new Scanner(System.in);
int selection = keyboard.nextInt();

switch(selection){
    case 1:
        System.out.print("Please enter name: ");
        String name = keyboard.nextLine();
        p1.addPerson(name);
        break;
    }
}
public Person(){

}

public void addPerson(String name){

    int day, month, year;

    Scanner keyboard = new Scanner(System.in);
    System.out.print("Please enter date of birth in the format dd mm yyyy: ");
    day = keyboard.nextInt();
    month = keyboard.nextInt();
    year = keyboard.nextInt();
}
}

This is the output:
1: Add Person
2: Delete Person

Please make a selection: 1
Please enter name: Please enter date of birth in the format dd mm yyyy:

The program does not wait for the name to be entered, how do i fix this?

A: The problem is when you do nextInt() it scans an integer, but not the new line character(\n), so when you call nextLine() it just consumes \n you typed when was doing selection and returns empty string.
Several ways to fix it:
First is to call nextLine() after nextInt. To fix your code you would do this:
int selection = keyboard.nextInt();
keyboard.nextLine();

Second option is to call nextLine() but when you need int wrap in in Integer.parseInt(). So, for example, your selection would look like:
int selection = Integer.parseInt(keyboard.nextLine());

Other option would be to use next() instead of nextLine, however, this approach wouldn't work if name contains spaces.

A: You should use keyboard.next()
From the java docs:

next(): Finds and returns the next complete token from this scanner.

This is what keyboard.nextLine() does:

nextLine(): Advances this scanner past the current line and returns the input that was skipped.


text:
Q: On click function is not defined and i dont know why I have to validate an email and a phone. It is not necessary that both are mandatory, just one is enough.
When i click my button, the code error is that handleValidation is not defined, but i do not why. Even the console don't print the console.log.
Here the HTML:
        <form class="form-group p-4">

                <input type="text" class="form-control rounded-0 p-3 m-1" id="name" required
                    placeholder="NOMBRE Y APELLIDO">
                <input type="email" class="form-control rounded-0 p-3 m-1" id="email" placeholder="E-MAIL">
                <input type="tel" class="form-control rounded-0 p-3 m-1" id="phone" placeholder="TELÉFONO">

                <textarea id="message" class="form-control rounded-0 h-100 p-3 m-1" required
                    placeholder="DEJANOS TU MENSAJE"></textarea>

                <button onclick="handleValidation()" id="send-btn"
                    class="main-btn btn btn-primary col-12 rounded-0 p-2 mt-3">ENVIAR</button>

    </form>

and here the JS:
let email = document.querySelector("#email");
let tel = document.querySelector("#phone");

const emailVal = () => {
  if (!(/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)/.test(email))) {
    console.log("bad")
    return false;
  }
  console.log("good")
  return true;
}

const telVal = () => {
  if (!(/^\d{9}$/.test(tel))) {
    console.log("bad")
    return false;
  }
  console.log("good");
  return true;
}

const handleValidation = () => {
  if (emailVal() === true || telVal() === true) {
    alert("tu consulta fue enviada satisfactoriamente");
  } else {
    alert("el email y/o el teléfono son necesarios para contactarte");
  }
}

A: *

*Set an event listener in the script instead of onclick attribute

*You do not get the values of the inputs but the inputs

*Input values should be grabbed into the validations functions, not outside

*Your email regex doesn't seems to work (I didn't check the phone number one)

If you correct all this problems, your script should look like that :
const emailVal = () => {
  let email = document.querySelector("#email").value;
  if (!(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(email))) {
    console.log("bad email")
    return false;
  }
  console.log("good")
  return true;
}

const telVal = () => {
  let tel = document.querySelector("#phone").value;
  if (!(/^\d{9}$/.test(tel))) {
    console.log("bad tel")
    return false;
  }
  console.log("good");
  return true;
}

const handleValidation = () => {
  if (emailVal() || telVal()) {
    alert("tu consulta fue enviada satisfactoriamente");
  } else {
    alert("el email y/o el teléfono son necesarios para contactarte");
  }
}

document.getElementById('send-btn').addEventListener('click', handleValidation);

You will also have to remove your button onclick attribute of course.
Source for email validation regex : https://www.w3resource.com/javascript/form/email-validation.php

A: I checked your code in jsfiddle. I receive very time "el email y/o el teléfono son necesarios para contactarte". So code is correct to some extends. I suggest add the JSSript after the html and vice versa. I'm mixing this all time up.


text:
Q: How do you tell which commit, tag, and branch a git submodule should be on without checking it out I have a project in git.  It has a couple of submodules.  Without going into the submodule and doing a git status or similar, is there a way to tell which commit, branch, and tag it the main project thinks it should be on?

A: The command git submodule modulename gives you the commit without going into the submodule directory, followed by the result of git describe, which gives you most recent tag:
$ git submodule ext/fiji
808e757481874dfd493b8cc08a484235ce807ec2 ext/fiji (Fiji-Madison-23-g808e757)

For branch you have to cd in the directory, or change $GITDIR before running git status.