Binomial distribution intituition for N

Question: I am unable to convince myself intuitively as to why the variance of a binomial distribution increases with increase in n (number of trials). In general, I expect that as n increases, the distribution should converge near np = mean (p is the probability of success). We even define probability as a value which is obtained when n limits to infinity (i.e. n increases). So shouldn't I expect the when I increases n, the probability to get np=mean value increase as well?

Like in the picture above, as n increases, for constant p = 0.5, the variance increases.
Comment: variance for a binomial is $np(1-p)$, $n$ independent trials each with variance $p(1-p)$. Sample proportion is the number of successes divided by $n$. rule of thumb $\text{var}(Y/n) = \text{var}(Y)/n^2$, so the sample proportion has variance $p(1-p)/n$
Answer: Note that the values of $X \sim Binomial(n,p)$ correspond to number of "positive" trials, not probability. As $n$ grows, the values of $\hat{p} = X/n$ converge to the true $p$, hence the probability as a long-run frequency definition. Values of $X = n\hat{p}$ clearly don't converge.
Same distinction might help understanding the variance: variance of the proportion of positive trials decreases, $Var(X/n) = np(1-p) / n^2 = p(1-p)/n$, so the proportion estimates get more precise. Variance of the actual number of positive outcomes increases, however.
Comment: $n\hat{p}$ is $X$, not $\bar{X}$ (in relation to the statement in the last sentence of your first paragraph) .... aside from that, +1
Answer: The variance of the distribution increases with N as you are measuring the total number of successes, not the ratio. Imagine you throw a coin once. The variance is tiny as all possible results are 0 heads and 1 heads (1/2 of a success from the mean).
If you throw it a million times, you won't often get results that close to the mean.
However, if your varaible of interest is the prportion of heads (rather than the raw number), variance will keep decreasing as you flip the coin more and more tiems (proportional to 1/N)
Answer: What binomial distribution describes, is the distribution of "successes" in $n$ Bernoulli trials, each having probability of success $p$. The most popular handbook example, is that you have a biased coin with probability of tossing heads equal to $p$, you throw it $n$ times and count the total number of heads tossed.
In single coin toss the variance is $p(1-p)$, if you toss it twice, it is $p(1-p) + p(1-p)$ by the property of variance of uncorrelated variables that $\mathrm{Var}(A+B) = \mathrm{Var}(A) + \mathrm{Var}(B)$, if you toss it $n$ times, it varies by $\sum_{i=1}^n p(1-p) = np(1-p)$.
Say that you record results of tossing some coin $n$ times, then your friend tosses it $m$ times. You repeat this experiment many times and in each row of your notebook you record the successes by you in one column and your friends results in the second column. In the end you observe that on average you observed $np \pm x$ heads, while your friend $mp \pm y$ heads. If you summed together the results rowwise, on average you would observe $np+mp = (n+m)p$ heads for both of you. How much would the sum vary? It wouldn't be $(n+m)p \pm x$, neither it wouldn't be $(n+m)p \pm y$, since in both cases this would mean that the additional tosses cannot make the result more extreme. This wouldn't make sense. Say that you never tossed more then $k$ heads, while your friend never tossed more then $r$ heads, then obviously if you sum the number of heads tossed by both of you, the result can be greater then $k$ or $r$.

Binomial distribution intituition for N


Compute the integral $\int_0^1\int_0^1\ldots\int_0^1 f(x_1 + x_2 + \ldots + x_n)\,dx_1\,dx_2\ldots dx_n $

Question: A mysterious result, probably by Euler himself, goes as follows:

If $n$ is a positive integer and $f:\mathbb R \rightarrow \mathbb C$ is integrable on the open interval $(0, n)$, then
  $$\int_0^1\int_0^1\ldots\int_0^1 f(\lfloor x_1 + x_2 + \ldots +x_n\rfloor) \, dx_1 \, dx_2\ldots dx_n = \sum_{k=1}^\infty A(n,k)\frac{f(k)}{k!},
$$
  where the $A(n,k)$'s are the Eulerian numbers.

Is there an analogous result without the floor function ? Thats is, is there an analogous formula for the integral
$$
\int_0^1\int_0^1\ldots\int_0^1 f(x_1 + x_2 + \ldots + x_n)\,dx_1\,dx_2\ldots dx_n \; ?
$$
Comment: @GabrielRomon Ya, that is indeed true and I considered it myself. It also provides a way to approximate the integral via statistical sampling.
Answer: Here is a detailed solution motivated by @Arthur's. Let $\mathbf w \in \mathbb R^n$, non of whose coordinates is $0$. For any real $z$, define
$$G_{\mathbf w,z} := \{\mathbf x \in \mathbb R^n | \mathbf w^T \mathbf x \le z\}, \;H_{\mathbf w,z} := \{\mathbf x \in \mathbb R^n | \mathbf w^T \mathbf x = z\}.$$
The sought-for integral is precisely
$$\int_{[0,1]^n} f(\mathbf w^T\mathbf x)d\mathbf x= \mathbb E_{x_1,\ldots, x_n \sim \mathcal U[0, 1]} [f(\mathbf w^T \mathbf x)]$$
with the choice $w_1 = \ldots w_n = 1$.
Now, let $F_{\mathbf w}$ be the cdf of $\mathbf w^T\mathbf x$ for i.i.d $x_1,\ldots,x_n \sim \mathcal U[0,1]$. Then its not hard to see that
$F_{\mathbf w}(z) = \operatorname{vol}_n (G_{\mathbf w,z} \cap[0,1]^n)$,
with density $f_{\mathbf w}(z) = \|\mathbf w\|_2^{-1} \operatorname{vol}_{n-1} (H_{\mathbf w,z} \cap[0,1]^n)$. By elementary properties of expectations, one has
$$
\begin{split}
\int_{[0,1]^n} f(\mathbf w^T\mathbf x)d\mathbf x &= \mathbb E_{x_1,\ldots, x_n \sim \mathcal U[0, 1]}f(\mathbf w^T\mathbf x)  = \int_{-\infty}^\infty \mathbb E(f(\mathbf w^T\mathbf x) | \mathbf w^T\mathbf x = z)f_{\mathbf w}(z)dz\\
&= \int_{-(-\mathbf w)_+^T\mathbf 1_n}^{(\mathbf w)_+^T\mathbf 1_n} \|\mathbf w\|_2^{-1}\operatorname{vol}_{n-1} (H_{\mathbf w,z} \cap[0,1]^n)f(z)dz.
\end{split}
$$
Invoking Theorem 4 of this paper yields
$$
\|\mathbf w\|_2^{-1}\operatorname{vol}_{n-1} (H_{\mathbf w,z} \cap[0,1]^n) = \frac{1}{(n-1)! \prod_{k=1}^n w_k}\sum_{K \subseteq [\![n]\!]}(-1)^{\#K}\left(z - \mathbf w^T\mathbf 1_K\right)_+^{n-1},
$$
where $\mathbf w^T \mathbf 1_K := \sum_{k \in K}w_k$. Putting things together gives
$$
\int_{[0,1]^n} f(\mathbf w^T\mathbf x)d\mathbf x= \frac{1}{(n-1)! \prod_{k=1}^n w_k}\sum_{K \subseteq [\![n]\!]}(-1)^{\#K}\sigma_{\mathbf w, K}(f),
$$
where $\sigma_{\mathbf w, K}(f):= \Lambda_{-(-\mathbf w)_+^T\mathbf 1_n,(\mathbf w)_+^T\mathbf 1_n,\mathbf w^T\mathbf 1_K}(f)$ and
$$\Lambda_{a,b,c}(f) := \int_{a}^b \left(z - c\right)_+^{n-1}f(z)dz.
$$
Thus the whole game is about computing the numbers $\Lambda_{a,b,c}(f)$.
Examples

Volume of hypercube $[0,1]^n$. This is a pathologically simple example and is only here to act as a sanity check. Take $w_1 = \ldots = w_n = f = 1$, and for any $K \subseteq [\![n]\!]$ with $\#K = k$, one has

$$\sigma_{\mathbf w, K}(f) = \int_{k}^n (z-k)^{n-1} dz = \frac{1}{n}(n-k)^n.
$$
Thus
$$\int_{[0,1]^n} dx_1 \ldots dx_n =
\frac{1}{n!}\sum_{k=0}^n C^n_k(-1)^k(n-k)^n = 1
$$

Expected value of sum of $n$ i.i.d uniform random variables.
Take $w_1 = \ldots = w_n = 1$ and $f = \operatorname{id}$. For any $K \subseteq [\![n]\!]$ with $\#K = k$, one has

$$\sigma_{\mathbf w, K}(f) =
\int_0^n(z-k)^{n-1}zdz = \frac{(n - k)^n(n^2 + k)}{n(n+1)}
$$
$$
\begin{split}
\int_{[0,1]^n}(x_1+ \ldots + x_n)dx_1 \ldots dx_n &= \frac{1}{(n+1)!}\sum_{k=0}^n (-1)^kC^n_k (n-k)^{n}(n^2 + k)\\
&= \frac{1}{(n+1)!}\frac{n}{2}(n+1)! = \frac{n}{2}
\end{split}
$$
Answer: I propose the following:

If $A(c)$ is the hyperarea of the region of the hyperplane $x_1+\cdots + x_n = c$ bounded by the hypercube $0\leq x_1, \ldots,x_n\leq 1$, the integral is equal to $\frac 1{\sqrt n} \int_0^{n}A(c)f(c)dc$.

I might have missed something, though, as I haven't done any general checking. It works for $n = 1,2$ and $f(x) = 1$, so I don't think I've missed any constant factors, at least. Comments and corrections are welcome.
Comment: Nice! I can derive your formula upto withing the $\frac{1}{\sqrt{n}}$ factor (mistake ?). Indeed, let $H_z := \{(x_1,\ldots,x_n) | \sum_i x_i = z\}$. Then,
$$
\begin{split}
\int_{[0,1]^n} f(\sum_i x_i)dx_1 \ldots dx_n &= \int_{z=0}^n \left(\int_{[0,1]^n \cap H_z}f(z)dx_1\ldots dx_n\right)dz\\
&= \int_{z=0}^n \left(\int_{[0,1]^n \cap H_z}dx_1\ldots dx_n\right)f(z)dz\\ = \int_{z=0}^n \operatorname{vol}([0,1]^n \cap H_z)f(z)dz
\end{split}
$$
Comment: @dohmatob I needed the $\frac1{\sqrt n}$ factor to make the $n = 2, f(x) = 1$ case work, since the graph of $A(c)$ in that case is an isosceles triangle with height $\sqrt2$ and base $2$. It might not be the _correct_ factor in the general case, but for the two simplest cases it works, so that's why I guessed it. However, it seems reasonable, since it represents the distance between the hyperplanes $x_1+\cdots +x_n = c$ and $x_1+\cdots x_n = c+1$ (in other words, the velocity at which the hyperplane "sweeps over" the hypercube)
Comment: you're right about the strange $\sqrt{n}$ term in the denominator. Actually, this term is just the $\ell_2$ norm of the weighting vector $w = (1,\ldots,1)$ required to pass from volume of the polytope to the hyper-area of its boundary, via derivatives w.r.t $z$. See my post below. That is $\partial_z \operatorname{vol}(z) = \|w\|_2 \operatorname{surface}(z)$.


How many different words can be formed with the letters of 'SKYSCRAPERS' if A and E are together?

Question: a. How many different words can be formed with the letters of 'SKYSCRAPERS' if A and E are together?
b. How many of the words formed from 'SKYSCRAPERS' begin with 'K' and end with 'A'?
Attempt:
I tried solving the a part using $ 9! \cdot 10C2 $ since we can arrange AE among the other 9 words in 10C2 ways but I don't think my attempt is right.
If I am right, I plan to solve the b part using the same method.
This combinatorics question is from my textbook. I came across it when solving different questions. Please assist, if I am wrong with the two parts. Thanks
Comment: For part $b$, notice that this is exactly the same as "how many different words can be formed with the letters of 'SYSCRPERS'", because the 'K' and 'A' are fixed in place.
Comment: @Bye_World thank you very much for that. The b part will now be 30,240. I didn't look at it that way.
Comment: @Bye_World how about the part a. Is that right?
Answer:
How many different words can be formed with the letters of SKYSCRAPERS if A and E are together?

The word SKYSCRAPERS has eleven letters.  If we place the letters A and E in a box, we have ten objects to arrange.  They include $3$ Ss, $1$ K, $1$ Y, $1$ C, $2$ Rs, $1$ P, and $1$ box containing A and E.  Choose three positions of the ten positions for the Ss, which can be done in $\binom{10}{3}$ ways, and two of the remaining seven positions for the Rs, which can be done in $\binom{7}{2}$ ways.  We are left with five positions in which to arrange five different objects, the four single letters and the box containing A and E, which can be done in $5!$ ways.  Finally, arrange A and E within the box, which can be done in $2!$ ways.  Hence, the number of arrangements of the letters of SKYSCRAPERS in which A and E are adjacent is
$$\binom{10}{3}\binom{7}{2}5!2! = \frac{10!}{7!3!} \cdot \frac{7!}{5!2!} \cdot 5! \cdot 2! = \frac{10!}{3!}$$

How many words formed with the letters of SKYSCRAPERS begin with K and end with A?

As @Bye_World pointed out in the comments, since the positions of K and A are fixed, this amounts to arranging the nine letters of the word SYSCRPERS.  Of those nine letters, there are $3$ Ss, $1$ Y, $1$ C, $2$ Rs, $1$ P, and $1$ E.  Proceeding as above, we choose three of the nine positions for the Ss, two of the remaining six positions for the Rs, then arrange the four single letters in the remaining four positions, which can be done in
$$\binom{9}{3}\binom{6}{2}4! = \frac{9!}{6!3!} \cdot \frac{6!}{4!2!} \cdot 4! = \frac{9!}{3!2!}$$
ways.  The factor of $3!$ in the denominator represents the number of ways the three Ss can be permuted among themselves within a given arrangement, and the factor of $2!$ in the denominator represents the number of ways the two Rs can be permuted among themselves within a given arrangement.  Since permuting indistinguishable letters among themselves within a given arrangement does not produce an arrangement that is distinguishable from the given arrangement, we would be counting each distinguishable arrangement $3!2! = 6 \cdot 2 = 12$ times if we did not divide by this factor.
Answer: You are almost right with part (a).
We have the $9!$ ways to arrange:

    S    K    Y    S    C    R    P    R    S

and with the repetition, this becomes $\dfrac{9!}{3!2!}$.
As the $A$ and $E$ must be together, we cannot place them in $\dbinom{10}{2}$ ways, as not all of these placements mean that $A$ and $E$ are together.
Instead, there are $10$ slots available, and we can place either $AE$ or $EA$ into any of the $10$ slots, giving $20$ ways to place $A$ and $E$ in total.
So, the final answer for part (a) is:
$$\frac{9!}{3!2!}\cdot20=\frac{10!}{3!}$$


A question on rearrangement of polynomials

Question: Let $ A,B,C,D$ be polynomials in $n$ variables. Is it possible to find $A,B,C,D$ such that:

$AB+CD=AC+BD$ (All polynomials are to be unequal)

Thanks in advance....
Comment: Setting $A=B=C=D$ is one such solution.
Comment: I made an edit, all polynomials are to be unequal...
Comment: Are you considering polynomials over arbitrary rings?
Comment: Hint: ${\rm LHS}-{\rm RHS}=(A-D)(B-C)$.
Answer: $AB+CD=AC+BD$ implies $(A-D)(B-C)=0$, so there exist different polynomials satisfying the relation iff the ring of coefficients has zero divisors.


Why Does Overdrive cause Low End to lose?

Question: When running the bass signal through the OD pedal, the signal gets compressed and this adds harmonic overtones and increases the level of highs and mids to the signal.
Q: When people say the distortion will make  the low end drop, what do they mean by that? Is it in terms of Amplitude decreasing to the low end signal or decreasing in volume  of the low end sound to human ears as mid and high overtones are now louder?
Comment: I guess it's not so much a loss of bottom end, but a gain of top, which then makes the sound less bottom heavy. This is a comment rather than an answer, but makes sense to me.
Comment: The signal ends up containing more highs than lows, so it sounds like the bottom end has been lost.
Comment: @Tim sometimes when bass is overdriven, the signal is split to low and high bands and only the high band is run through the overdrive. This keeps the low-end clear, but gives the sound overdriven harmonics and compression. If what you're saying was true and overdrive only caused additional highs, then the parallel two-band processing should result in the same thing and would make no sense. The problem must be either that overdrive _removes_ some low frequencies, or that it _adds_ some _unwanted_ low frequencies that make the sound muddy and that the two-band parallel processing does not add.
Comment: @piiperiReinstateMonica - thanks for all that. I've never used overdrive or distortion on bass, in all the years! It stands to reason that when harmonics are amplified due to overdrive, the higher end of the spectrum will be more pronounced, as harmonics are higher pitch anyhow, and it also makes sense not to amplify the lower end any more - too muddy. The start of any note played will generally be a quick attack, whatever overdrive is doing, and the end will be whenever the player decides it will be, usually. Notes aren't often longer than a bar (not when I play...).
Comment: @Tim Can you pls clarify more on that? Do you mean in terms of low end signal level's lost or human ear perception? Thank you.
Comment: ... (continued) maybe one reason is the _compression_ aspect of overdrive. You don't necessarily want to lengthen the low end of your bass notes. The notes have to start and end sharply to be rhythmically clear. What happens during the bass transient i.e. quick change of signal content ... when it goes through the overdrive, it gets mushed. Even without considering that clipping might actually remove some of the low frequencies. So, two bad things for bass: (1) rhythmic transients are mushed, and (2) the _pitch_ becomes less clear. Rhythm and bass pitch are the most important roles of bass.
Answer: When designing overdrive and distortion pedals, the engineers will often include a high pass filter. The sound of a guitar (or bass) has more energy at the lower frequencies. Including this low frequency content in the input to the distortion stage can sound muddy. Source: this analysis of the TubeScreamer pedal https://www.electrosmash.com/tube-screamer-analysis#clip-high-pass
Depending on which OD pedal you have, you could google for the schematic and see if anyone comments on the design. Otherwise try to find a pedal or patch which is specifically designed for bass.


SQL: How can I generate a time series from timestamp data and calculate cumulative sums across different event types?

Question: Building a timeseries with cumulative sums based on singe grouped events
To begin I need to highlight I am quite new to SQL and the current state was achieved with the help of stack overflow.
I have a table containing events of different kinds as they occur. I would like to transform this data into a time series filling the time gaps between the events and cumulating the numbers across the different kind of events.
So it is all about creating a timeseries from single events and calculate the running/cumulative sum across groups of events
Here the example of source data:
Source:
event_timestamp    type  value
01.01.2023 10:00   1     10
03.01.2023 10:00   2     10
05.01.2023 10:00   2     10
07.01.2023 10:00   1     10

Desired outcome:
event_timestamp    type value cumulative_sum
01.01.2023 10:00   1    10    10
02.01.2023 10:00   1    0     10
03.01.2023 10:00   1    0     10
03.01.2023 10:00   2    10    10
04.01.2023 10:00   1    0     10
04.01.2023 10:00   2    0     10
05.01.2023 10:00   1    0     10
05.01.2023 10:00   2    10    20
06.01.2023 10:00   1    0     10
06.01.2023 10:00   2    0     20
07.01.2023 10:00   1    10    20
07.01.2023 10:00   2    0     20

I got to a point, where I can create this (limited to a single event type):
time               type value cumulative_sum
01.01.2023 10:00   1    10    10
02.01.2023 10:00   1    0     10
03.01.2023 10:00   1    10    20
04.01.2023 10:00   1    0     20
05.01.2023 10:00   1    0     20
06.01.2023 10:00   1    0     20
07.01.2023 10:00   1    0     20

with the following sql statement (postgresql):
SELECT
generate_series AS timestamp,
-- hard coded event type below
COALESCE(events.type, 1) AS type,
COALESCE(events.value, 0) AS value,
COALESCE(SUM(td.value) OVER (ORDER BY generate_series), 0) AS cumulative_sum
FROM
generate_series('2023-01-01'::timestamp, '2023-01-07'::timestamp, '1 day') AS generate_series
LEFT JOIN
-- hard coded event type below
events ON generate_series = events.event_timestamp AND event.type = 1
ORDER BY
generate_series;

Now I am questioning if I should try to find the SQL statement doing all in a better way (no idea how) or if I should use a python script to just run this statement per event type and sequentally , insert the data into the table.
Questions summarized:

Would it be advisable to do such a calculation with a combination of SQL and e.g. python?
Would it be better to split the creation of the timeseries and the cumulative sum?
If the pure SQL way is recommended, how can this done considering the groups
Comment: Just as an aside, I think your expected result is incorrect.  Type 1 accumulation shouldn't hit 20 until the last timestamp, if I understand your description properly.
Comment: Well I double checked and you are right - I will fix it
Answer: You're very close.  All you need is to create the series for each type.  A cross join can do that easily.
Check this out:
SELECT generate_series AS timestamp
     , etypes.type
     , COALESCE(events.value, 0) AS value
     , COALESCE(SUM(events.value) OVER (PARTITION BY etypes.type ORDER BY generate_series), 0) AS cumulative_sum
  FROM generate_series('2023-01-01'::timestamp, '2023-01-07'::timestamp, '1 day') AS generate_series
  CROSS JOIN (SELECT DISTINCT type FROM events) AS etypes
  LEFT JOIN events ON generate_series = events.event_timestamp AND events.type = etypes.type
 ORDER BY generate_series, etypes.type
;

With no data in the given range, the result is this:

timestamp
type
value
cumulative_sum

2023-01-01 00:00:00
1
0
0

2023-01-01 00:00:00
3
0
0

2023-01-02 00:00:00
1
0
0

2023-01-02 00:00:00
3
0
0

2023-01-03 00:00:00
1
0
0

2023-01-03 00:00:00
3
0
0

2023-01-04 00:00:00
1
0
0

2023-01-04 00:00:00
3
0
0

2023-01-05 00:00:00
1
0
0

2023-01-05 00:00:00
3
0
0

2023-01-06 00:00:00
1
0
0

2023-01-06 00:00:00
3
0
0

2023-01-07 00:00:00
1
0
0

2023-01-07 00:00:00
3
0
0

Test case (with a little data added)
You could also create the series with different range for each type, based on the start and end for that type.
Here's an example of that:
SELECT generate_series AS timestamp
     , etypes.type
     , COALESCE(events.value, 0) AS value
     , COALESCE(SUM(events.value) OVER (PARTITION BY etypes.type ORDER BY generate_series), 0) AS cumulative_sum
  FROM (SELECT type
             , MIN(event_timestamp) AS mints
             , MAX(event_timestamp) AS maxts
          FROM events
         GROUP BY type
       ) AS etypes
  JOIN LATERAL (SELECT generate_series(mints, maxts, '1 day') AS generate_series) AS gs ON 1 = 1
  LEFT JOIN events ON generate_series = events.event_timestamp AND events.type = etypes.type
 ORDER BY generate_series, etypes.type
;

Result with your data:

timestamp
type
value
cumulative_sum

2023-01-01 00:00:00
1
10
10

2023-01-02 00:00:00
1
0
10

2023-01-03 00:00:00
1
0
10

2023-01-03 00:00:00
2
10
10

2023-01-04 00:00:00
1
0
10

2023-01-04 00:00:00
2
0
10

2023-01-05 00:00:00
1
0
10

2023-01-05 00:00:00
2
10
20

2023-01-06 00:00:00
1
0
10

2023-01-07 00:00:00
1
10
20
Comment: Thabk you very much
Comment: This solution helps me a lot. I have an additional question: I will store desired outcome in a table (let's call it event_history) to work on this. I was wondering if I can do the calculation incremental by replacing the MIN() statement with the increment day.
To maintain the overall sum:

Would it be better to add the last result per type each time?

or

Would it be smarter to Insert temporary placeholder entries per type at the beginning of the list?
Comment: It's hard to tell what would be best.  If I really had to do this, I might just extend the current result, by starting with the last calculated sum per type from the most recent result.  This can be done easily in the above solution.  The min/max range which drives calculation is easily replaced.


Como usar split() dentro de um loop em Java?

Question: Boa noite, to aprendendo Java a pouco tempo e queria saber como que eu poderia ler um arquivo de texto que possua um ou dois números em no máximo 10 linhas. Algo como os arquivos abaixo:
16x9_resolutions.dat
640 360
1280 720
1366 768
1600 900
1920 1080

ranking.dat
10000
9000
8900
8878
8803
7995
7967
7960
7906
7845

Consegui fazer isso:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class Files{

    private String vet[] = new String[10];

    public void read(String path) throws IOException {
        BufferedReader buffRead = new BufferedReader(new FileReader(path));
        String line = "";
        int i = 0;
        while (true) {
            line = buffRead.readLine();
            if (line != null) {
                this.vet[i] = line;
                i++;
            } else{
            break;
            }
            if(i == 10){
               break;
            }
        }
        buffRead.close();
    }

    public int getResolutions(int pos){
        return Integer.parseInt(this.vet[pos]);
    }

}

Na classe acima eu consigo ler apenas um numero por linha. Quero que o método read() consiga ler os dois tipos de arquivos que eu mostrei, no caso de dois números por linha ele deve colocar o segundo número na próxima posição do vetor e pular pra próxima linha.
Vi alguns posts na internet falando sobre o split() mas nenhum mostrava como usa-lo dentro de um loop. Queria algo como:
while (true) {
    line = buffRead.readLine();
    if (line != null) {
        if(line.split() == "2 numeros separados por espaço"){
            this.vet[i] = line.split("primeiro numero");
            i++;
            this.vet[i] = line.split("segundo numero");
            i++;
        }else{
            this.vet[i] = line;
              i++;
        }
    }else{
       break;
    }
    if(i == 10){
        break;
    }
}

Answer: O método String.split recebe um separador como parâmetro. Então você poderia fazer algo como:
String[] campos = linha.split(" ");
for(String campo: campos) {
   // processa cada campo na linha
}

Uma outra opção melhor é usar a classe java.util.Scanner assim:
Scanner sc = new Scanner(linha);
while(sc.hasNext()) {
   String campo = sc.next();
}

Scanner tem outros métodos interessantes que facilitam ainda mais como Scanner.nextInt ou Scanner.nextLong. Vale uma olhada na documentação: https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html
Comment: @kiss_cpp O Scanner quebra a string orginal em tokens ("10 20" cria dois tokens: "10" e "20") Cada Scanner.next() retorna um token. A primeira vez que chamar o next() retorna o "10", a segunda retorna o "20".
Comment: No segundo exemplo, .hasNext() retorna true se tiver outro token. Então no caso se for "10 20" no input o resultado vai ser true?
Comment: o sc.next() não vai pegar a string inteira?
Answer: Primeiramente, você precisa definir bem o problema:

é para ler somente as 10 primeiras linhas do arquivo?
ou é para ler o arquivo até encontrar 10 números, independente da quantidade de linhas?
ou alguma outra opção?

Por ora, vamos manter simples e assumir que ou o arquivo tem 10 linhas (um número por linha), ou tem 5 linhas (com dois números por linha). Ou seja, sempre serão 10 números.
Sendo assim, você pode ler a linha, fazer o split para ver se tem um ou 2 números, e em seguida guardá-los no array. Lembrando que split quebra uma string em várias partes, usando um separador, e retorna um array com estas partes.
Outro ponto é que, se você quer ler números, então por que guardar tudo em um array de String? Se a ideia é ter números, então converta-os para o tipo apropriado (que no caso, parece ser int, já que seus exemplos só têm números inteiros).
Então uma solução simplificada seria:
public class LerArquivo {

    // se quer ler números, use um array de int (não de String)
    private int[] numeros = new int[10];

    public void read(String path) {
        try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
            int pos = 0;
            String linha;
            // já leio a linha e verifico se é null
            leitura: while ((linha = reader.readLine()) != null) {
                String partes[] = linha.split(" "); // separa a linha por espaços
                // percorre as partes do resultado do split, e converte para números
                for (String parte : partes) {
                    // converte para número
                    this.numeros[pos] = Integer.parseInt(parte);
                    pos++; // incrementa a posição do array
                    if (pos == this.numeros.length) { // se já lotou o array, para de ler
                        break leitura; // interrompe o while
                    }
                }
            }
        } catch (IOException e) {
            // mostrar alguma mensagem de erro, etc
        }
    }
}

Usei um bloco try-with-resources (disponível a partir do Java 7), que garante que o arquivo é fechado no final (mesmo em caso de erro), assim você não precisa chamar close (e da forma que você fez, sem garantia que será chamado, caso dê algum erro no meio da leitura).
No while, usei um label (leitura:), que é algo pouco usado, mas serve para dar um "nome" para o loop, assim eu consigo usar o break leitura para indicar que quero interromper a leitura assim que a quantidade de números lidos for igual ao tamanho do array.
Para cada linha lida, faço o split usando o espaço como separador. Assim, ele "quebra" a linha em várias partes (separando por espaço), e para cada parte eu converto para número e adiciono no array. Este código assume que sempre serão números (pois se não for, parseInt lança uma exceção - você pode adicionar um try/catch e decidir o que fazer se der erro, por exemplo).
Desta forma, tanto faz quantos números têm em cada linha. Na verdade, pode até ter todos na mesma linha que não fará diferença, já que eu pego cada linha, separo por espaço e vejo tudo que tem ali, até completar a quantidade de números.

Enfim, a forma "correta" depende do que você quer fazer exatamente (as perguntas que coloquei no início). Se quer sempre 10 números, é uma coisa. Se quer validar que as linhas têm sempre um (ou sempre dois) números, a solução é outra (teria que ver if (partes.length == 2), por exemplo, e ainda teria que validar se são números mesmo, fazendo o try/catch no parseInt, etc).
Comment: @kiss_cpp Isso é o [*enhanced for*](https://blogs.oracle.com/corejavatechtips/using-enhanced-for-loops-with-your-classes), é só um outro jeito de percorrer um array. Vc poderia fazer `for (int i = 0; i < partes.length; i++) { String parte = partes[i]; etc...}`, que daria na mesma (mas quando eu só quero percorrer os elementos do array, sem me importar com o índice, costumo usar o *enhanced for*, acho mais sucinto e direto).
Comment: Muito obrigado @hkotsubo. Pra deixar mais claro o que eu quero fazer é ler valores que podem ser int ou String e que podem estar em duplas ou sozinhos em cada linha. Eles não necessariamente precisam ser 10 mas essa é a quantidade máxima. Sua resposta já vai me ajudar muito.
Comment: Uma coisa que não entendi foi o for (String parte : partes), o que significa esse : ?


$\ell_p$ is a separable space

Question: In my understanding, to prove that $\ell_p$ is a separable space, one may take the subspace of rational sequences, which satisfy the following condition:
$$\sum\limits_{k=1}^\infty |x_k|^p\in \mathbb Q\mbox{ with $\{x_k\}$ a rational sequence}$$
Then this space is countable and dense in $\ell_p$.

Countability:

Since $\mathbb Q$ is countable, there exists an injection $f:\mathbb Q\to \mathbb N$. Thus there exists an injection $g:(\ell_p)_\mathbb{Q}\to \mathbb N$, defined by $g\left[(x_k)_{k=1}^\infty\right]=f\left[\sum\limits_{k=1}^\infty |x_k|^p\right]\in \mathbb N$.

Density:

Let $(y_i)_{i=1}^\infty\in \ell_p$, then, since $|y_i|\in \mathbb R$ for all $i\in\mathbb{N}$, there is a sequence $(x_k)_{k=1}^\infty\in (\ell_p)_\mathbb{Q}$ (with $|x_k|\in\mathbb Q$) such that
$$\forall \varepsilon >0, |y_i-x_k|^p  <\varepsilon, \mbox{ for some $k\in\mathbb{N}$ }$$
Do you think this proof is good enough, or am I missing some important point(s)?
Comment: You say $(x_i)_{i=1}^\infty\in \ell_p$, then $(x_k)_{k=1}^\infty\in (\ell_p)_\mathbb{Q}$.  You should use a different symbol than $x$ for your sequence in $(\ell_p)_\mathbb{Q}$.  Changing the letter for the index set, when it's still the same index set, doesn't change the sequence.
Comment: Thanks, I'll edit my notation now.
Comment: For the countability argument, why is $g$ an injection? For the density argument, how do you know that there is such a sequence $(x_k)$?
Comment: Also, it's not clear to me that the set of rational sequences satisfying $\sum |x_k|^p \in \mathbb Q$ is actually a subspace. E.g. take $p = 3/2$ and define $x_1 = 1$, and $x_k = 0$ for $k > 1$. Then the sum of $(x_k)$ with itself is the sequence $(2, 0, 0, \ldots)$, and $\sum |x_k + x_k|^p = 2^p = 2^{3/2} \not\in \mathbb Q$.
Comment: Do you mean that the sum $M:=\sum_{n=1}^\infty|x_n|^p$ is rational? Or that any $x_n$ in the seuqnce is rational? Beacuse in the first case the set obtained isn't countable.
Comment: Also, when you finally prove density, what you state doesn't imply density.  to show that $(\ell_p)_\mathbb Q$ is dense in $\ell_p$, show that for any $y\in\ell_p$ and $\varepsilon>0$, there is some $x\in(\ell_p)_{\mathbb Q}$ such that $\|x-y\|_p<\varepsilon$.
Comment: @Aweygan I think my argument about density is exactly what you said.
Comment: What do you mean by $\|y_i - x_k\|_p^p$? Aren't $y_i$ and $x_k$ scalars?
Comment: Thank you for your comments. Please check my proof again, since I've edited it.
Answer: The set you describe, let's call it $X,$ is uncountable. Proof: Define $x_n = 1/2^{n/p}, n\in \mathbb N.$ Then $(x_n)\in X.$ Note that $x_m\ne x_n$ if $m\ne n.$ It follows that if $\sigma_1, \sigma_2$ are distinct bijections of $\mathbb N$ to $\mathbb N,$ then $x_{\sigma_1(n)}, x_{\sigma_2(n)}$ are distinct sequences in $X.$ Since the set of such bijections is uncountable, so is $X.$
I'm not sure why you're going to all this trouble. An easy countable dense subset of $l^p$ is the set of rational sequences in $l^p$ that are $0$ except for finitely many terms.

Added later: @DanielWainfleet pointed out that in my first answer I neglected the requirement that the sequences in $X$ should have all rational terms. To achieve that, inductively choose distinct rational $x_1,x_2,\dots$ such that
$$\frac{1-(x_1^p + \cdots + x_n^p)}{2} < x_{n+1}^p < 1-(x_1^p + \cdots + x_n^p).$$
for all $n.$ Then $\sum_{n=1}^{\infty}x_n^p = 1.$ The rest of the argument is the same.
Comment: Although your last sentence is well-said, it seems that in the Q we should have $x\in (x_k)_k \in X$ iff each $x_k\in \Bbb Q$ as well as $\|x\|^p\in \Bbb Q.$  If such $ x$ exists with $x_k\ne 0$ for infinitely many $k$ then by the methods of your answer, $X$ is uncountable. Such $x$ do exist, but it may not be obvious.
Comment: If we consider the set of rational sequences in $\ell_p$, can we define such sequences as, say, $(x_k)=\{0,0,\dots, 0, f(n_1), f(n_2), \dots, f(n_l), \dots, 0,\dots\}$, where $f$ is an injection from $\mathbb{N}$ into $\mathbb{Q}$ (since $\mathbb{Q}$ is countable and $|\mathbb{N}|=|\mathbb{Q}|$)? Then all rationals would be covered by this set.
Comment: @DanielWainfleet Yes you are right. Thank you. I'll add to my answer.
Comment: @sequence I'm afraid I don't understand your comments.
Comment: To the proposer: The set of sequences in your last comment to this A is not a dense set.
Comment: @zhw Can you please show how such a set is dense?  I can't seem to figure it out
Comment: @VinnyChase which set? the first one, or the added later one
Comment: @zhw original.  I am looking to prove that $l_{conv}^\infty$ is separable so I figured I could use the set of sequences with finitely many nonzero terms
Comment: @VinnyChase  If $x= (x_k)\in l^p,$ do you see why $\sum_{k=1}^{n}x_ke_k \to x$ in $l^p?$
Comment: @zhw not really, is $e_k$ a basis element?
Comment: @VinnyChase  Let's put it this way: $(x_1,\dots, x_n,0,0,0,\dots ) \to (x_k)$ as $n\to \infty.$
Comment: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/77340/discussion-between-vinny-chase-and-zhw).
Comment: @VinnyChase Sorry, I don't do chat.
Comment: @zhw No problem.  So how does saying that that sequence converges lead us to the conclusion that the set is dense?

$\ell_p$ is a separable space


display just the label from node_lode()

Question: How to display just the label from the object returned by the function
node_load().
the field_view_field() can hide the label and view the value
but i want the converse.
Answer: If you want to find the label for a specific field then you can use field_info_instance()
https://api.drupal.org/api/drupal/modules!field!field.info.inc/function/field_info_instance/7
<?php
$field_instance = field_info_instance('node', 'field_body', 'article');
$label = $field_instance['label'];
?>

However, the titles are available in the rendered node if they are not hidden in your view mode, and can accessed like :
<?php
$node  = node_view(node_load($nid));
$label = $node['field_body']['#title'];
?>

Comment: i found this pretty short:

inside the node.tpl.php thanks for your support

display just the label from node_lode()


Replace special string characters in jquery

Question: HI,
I have some string from XML file, and I I want to replace all "& lt;, and & gt;" ... in "< and '>"
this is the AJAX call (jQuery):
$.ajax({
        type: "GET",
        url: "xml.xml",
        dataType: "html",
        success: function(xml) {

            alert(xml);

            $(xml).find('reslult').each(function(){
                            var bid = $(this).find('bid').text();
                            $('.Sign2').text(bid);
            });
            }
        });

I can't use "DataType:XML", because XML file is beginning with  .....  :(
Thanks !
Answer: Alexander,
You can use two string replace functions before your $(xml)... line, like so:
xml.replace(/& lt;/g,'<');
xml.replace(/& gt;/g,'>');
Answer: Can't you just use the javascript unescape() function on the string?
Comment: no, thats not for encode/decode special html characters, its for uri characters...for example, a space " " escapes to "%20"


How to match city names split by space?

Question: Trying to figure out given two different types of strings, how to make a determination whether or not a city name is actually a split word? Since working in python, I Split the string and save s[0] for street num, s[-1] for zip code and so on but how to figure out whether the city name may be a split word such as New York or San Jose!?
E.g. : 123 Main Street St. Louisville OH 43071  [City name is single word]
E. g : 45 Holy Grail Al. Niagara Town ZP 32908 [City name 'Niagara Town' is two words]
Forgive the noob question.
Thank you,
Comment: How do you get the addresses in the first place. If it is user input then you can have them enter address line 1 then town etc in different fields instead of in one go and save it as string with commas. Like 123 Main St, London, EC1 0HB. Now you can split by commas. And the town name will be one string no matter how many words.
Comment: Don't apologize for a noob question. Everyone is noob here! Don't worry. Try to explain (as noyanc mentioned) from where you get the string.
Comment: Maybe also start by seeing if there is a certain format in your address strings, else unless by doing a lookup there will not be any safe methods to guarantee identifying 2 part cities.
Comment: Addresses are stored in a list and each entry in a list is stored as a single string. There are only single white space characters in between. For instance it would read as

'123 Main Street St. Louisville OH 43071'

OR

'45 Holy Grail Al. Niagara Town ZP 32908'

So a little stumped as to how to put regular expression for it!
Answer: I making two assumptions here:
1) That the number code before the town name is always numeric
2) That there is no town name with a number name
<code>index =   list(filter(lambda x: x[1].isnumeric(),enumerate(x.split())))[-1][0]

" ".join(x.split()[index+1:])
</code>
So what is happening: We try to identify the last part of the split that is purely numeric, and then get the index of that element.  Then we join all elements after that numeric element.

How to match city names split by space?


Same taxonomy in two content type

Question: I have two content types Blog and Stay which use the same taxonomy Location. I have two or more posts use same term Cyclades.
Is it possible when a user clicks on a Cyclades term link in a Blog post to only show posts from Blog content on the taxonomy page? Likewise, when a user clicks on Cyclades in a Stay post, to show only Stay content on the page?
I know i can create two different taxonomy for each content type, but I dont want this solution.
Answer: You can have same taxonomy being used by multiple content types.
You can achieve this by using 2 options
1. Overriding node.tpl.php for the taxonomy page. Here you can create two separate tpl files specific two different content types.
2. Create PAGE display of VIEWs and pass "type" as an argument. Based on this argument you can always display the teasers belonging only to the desited "Content Type."
Option # 2 is little easier from implementation point of view whereing Option # 1 though could little time consuming but will be better from performance perspective.
Comment: thank you for your answer. I create it with views and rewrite url.

Same taxonomy in two content type


Multivariable Limits Involving Sines and Logs

Question: I've been stuck on this for a while now and was wondering if anyone could help me out by starting off in the right direction. Thanks.
Find $$\lim_{x,y \to 0} \frac{\sin xy}{\ln(x^2+y^2+1)}$$
Comment: Can you solve $$\lim_{(x,y) \to (0,0)} \frac{xy}{x^2+y^2}?$$
Answer: Change $(x,\, y)$ to polar coordinates:
$$\begin{cases}
x=\rho\cos{\theta},\\
y=\rho\sin{\theta}.
\end{cases}$$
Then
$$\lim\limits_{(x,\,y) \to (0,0)} \dfrac{\sin {xy}}{\ln{(x^2+y^2+1)}}=
\lim\limits_{\rho \to 0} \dfrac{\sin {(\rho^2 \sin{\theta}\cos{\theta}) }}{\ln{(1 + \rho^2)}}=\sin{\theta}\cos{\theta}$$
which depends on $\theta,$ therefore, limit does not exist.
Answer: Hint: Try $x=0$ and $y=x$ as paths to approach $(0,0)$.
Comment: After I make a substitution, can I then use l'Hopital's rule?
Comment: I guess that basic limits will suffice...


Question about this thing for timpani

Question:
I'm transposing some music in Medly and looking at the sheet music I came across this in the timpani part. Does anyone know what this means because I have no clue >~< I listened to the music a few times but it honestly still makes no sense on what that does. All I recognize is it's tremolo whole note but those other bars on the line I haven't seen or heard of.
Thank you ^~^
Comment: What piece is this? That might help somewhat. As it is, my first guess is that something has gone wrong in the software. Either some things aren't appearing, or the wrong character from the font has been substituted. Something along those lines.
Comment: Based on a comment in one of the answers, was the score made with Musescore (or Finale, Sibelius, etc.), or was this from a printed score in a book? (PDFs can be created from book scans.)
Comment: The piece is Gusty Garden Galaxy and maybe that might be it because it's weirdly spaced and it doesn't show up on other sheets, although if it is a software problem would it show up on multiple sources because it shows up in the pdf file the picture is from and on the YouTube video of the music itself.
Comment: Yeah it was made in Musescore which lately has been having A LOT of bugs.
Answer: This sort of looks like what the beams would be, if you wrote out the roll as an 8th note plus all 16ths. Not quite though, I think the 16ths would all be beamed together in each beat. So really, this looks like what the beams would be if it were one 16th and all 32nd notes, except missing one beam. And that would be a decent way of getting MIDI/notation software to play an accented roll if it didn't have the capability of interpreting the tremolo mark.
So my best guess is that this software implements rolls "behind the scenes" as described, but hides that layer, and some glitch has caused part of that layer to become visible.
Either that, or this is some weird visualization meant to show you what the playback is going to do, which wouldn't print.
Comment: I'll note that, in MuseScore at least, it's easily possible to hide the notes and stems but not the beams. I've accidentally left pieces of notes in scores where they were supposed to be hidden.

Question about this thing for timpani


Pandas/Python how to store store looped values

Question: I am trying to loop multiple tickers into a function and I can print successfully the results however I cannot store them, only the last element is outputted. The loop seems overwrites the values generated earlier, can you please advise?
import yfinance as yf

y = ['SBUX', 'ICE']
b = {}

for x in y:
    ticker = yf.Ticker(x)
    d = ticker.get_info()
    for k, v in d.items():
        if k == 'zip' or k == 'sector' or k == 'symbol':
            b[k] = d[k]
    print(b)

result from the code:
{'zip': '98134', 'sector': 'Consumer Cyclical', 'symbol': 'SBUX'}
{'zip': '30328', 'sector': 'Financial Services', 'symbol': 'ICE'}

result if b is printed outside the code:
{'zip': '30328', 'sector': 'Financial Services', 'symbol': 'ICE'}

I would like to be able to print the 2 lines outside the code
Answer: You can append them to a dataframe:
import yfinance as yf
import pandas as pd

new_df = pd.DataFrame()
y = ['SBUX', 'ICE']
b = {}

for x in y:
    ticker = yf.Ticker(x)
    d = ticker.get_info()
    for k, v in d.items():
        if k == 'zip' or k == 'sector' or k == 'symbol':
            b[k] = d[k]
    new_df = new_df.append(b, ignore_index=True)

Comment: Thank you its working! do you know why with a list instead of a data frame is not working?
Comment: Hello thank you however I get the following  message: ValueError: If using all scalar values, you must pass an index
Comment: Because you are creating the dict from start each run of the loop. You need to append it to array or dataframe (like my soluytion)


Form parameters not getting sent?

Question: I am trying to make a login request but for some reason none of the inputs are getting sent with the request.
Have a bad feeling it's just some stupid mistake but I have been looking for 2h now and I can't find anything.
CODE:
Html / Laravel Blade:
<form method="POST" action="{{ route('admin.login') }}">
    {{ csrf_field() }}

            <input id="username" name="username" type="text" class="validate" required>
            Username

            <input id="password" name="password" type="password" class="validate" required>
            Password

            <button class="btn btn-block waves-effect waves-light" type="submit" name="submit">Login</button>

</form>

Route:
Route::post( '/admin/login', 'Auth\AdminLoginController@login' )->name( 'admin.login' );

Controller:
public function login( Request $request )
{
    dd($request);
}

Result:

Thanks
Comment: change namespace to:  use Illuminate\Http\Request;
Comment: try dd($request->all()); and show me what u get
Comment: Error: "Call to undefined method Illuminate\Support\Facades\Request::all()"
Comment: That fixed it! Thanks!
Answer: try dd($request->all());
And make sure you are using the right namespace for Http requests:
 use Illuminate\Http\Request;

Not:
use Illuminate\Support\Facades\Request;

Form parameters not getting sent?


Maximum length of MAIL FROM address

Question: When sending out emails with a MAIL FROM address > 81 characters I receive bounce messages from some MTAs:

501 Syntax error - Badly formatted address. (in reply to MAIL FROM command)

As soon as I change the MAIL FROM address to <= 81 characters, the MTA accepts my message.
I didn't find any limits in the RFC docs.
Is this expected behaviour or is the recipients' MTA misconfigurated?
Answer: Accoding to the answers given at
https://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address
The answer is 254 according to RFC 5321
So, those MTA are badly configured.
Comment: No, it has not. A SMTP server is magically required to actually acccept valid email addresses, or? How else would it work?
Comment: That's the length of a valid email address. Maybe it have something to do with the SMTP protocol or a different restriction though?

Maximum length of MAIL FROM address


Can not reset TD style

Question: I have removed padding from all TD elements in stylesheet. But I have a special table having cellpadding="10". Its TD are rendered having 0px padding due to above mentioned style.
how should I reset TD padding to nothing so it inherits the 10px padding from cellpadding?

td {padding:0}

#specialtable td {
  /* What should I write here? */
}

    test

Comment: Typo: in your CSS you have `#specialtable` (lowercase `t`), but in your HTML the id you have `specialTable` (uppercase `T`).
Comment: @noisypixy that's just a typo
Answer: You can use the :not pseudo-class to define the padding for all td except those under a #specialTable.

table:not(#specialTable) td {
  padding: 0;
}

    test

Comment: Thank you this works fine in my case. But in general do you have any idea how to reset the previous style to nothing?
Comment: @AliSheikhpour usually you could use the [initial](https://developer.mozilla.org/en-US/docs/Web/CSS/initial) keyword (e.g. `padding: initial`) or similars, but they didn't work for this case.
Answer: From here one can see that we can define an inherit value for the padding, which should inherit the padding from the parent. As far as I know that is the default value. So you can set the padding to default by giving it the inherit value.
Comment: Unfortunately inherit is not working for `cellpadding` as the `cellpadding` is not a css style but a HTML tag.

Can not reset TD style


required most recent date for the value in Column

Question: I have a data frame
df = pd.DataFrame({'Col1':['a','a','a','b','b','b','c','c','c'],
                  'Col2':[ '2020-12-01','2020-11-05','2019-01-05','2017-08-07',
                          '2018-07-16','2018-12-31','2019-11-30','2018-05-15',
                          '2019-01-15']})

I want the unique values in Col1 to be with most recent date Col2.
The required column would be like this
    Col1  Col2
0   a     2020-12-01
1   b     2018-12-31
2   c     2019-11-30

Answer: First, convert Col2 as datetime using pd.to_datetime if it's not datetime already, then use GroupBy.max
df['Col2'] = pd.to_datetime(df['Col2'])
df.groupby('Col1').max()

#            Col2
# Col1
# a    2020-12-01
# b    2018-12-31
# c    2019-11-30

Answer: Sort the dataframe based on Col2 first and then groupby and agg last
Do:
df.sort_values(by='Col2').groupby('Col1').last()


Solo piano: Why not compose everything in or including the keys C major and A minor?

Question: This is a follow-up question to What's the point of keys other than C and Am?
After going through that question, I wrote down the key general facts:

The C major and A minor keys have the simplest key signatures.
Music is not about the individual notes but the relationships between them (intervals).
Music can be transposed to a different key. For example, vocalists music all the time to match their vocal range.
Keys are only identical on equal-tempered instruments
The chosen key is often constrained within the limits of the range of the chosen instrument.

Question
My question is about the specific case of the piano, where I see that the points about just intonation and instrument range do not apply. Also, all the notes of the C major (C) and A minor (Am) scales are white notes on the piano.
For example, in this video of the Tetris theme tune being played on the piano in different keys, I would not have been able to guess which of them is the original or correct key. The piano seems to be an instrument where changing the key does not change much.
However, Western piano composers, old and contemporary, have not composed all their music in C or Am, or at least started there if they intend to change the key later (modulation). For example, Moonlight Sonata is in C-sharp minor.
If music sounds similar in each key, why would a piano composer choose a key over another? Why not just start composing a song in the simplest key for piano?
Comment: Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/139331/discussion-on-question-by-hb20007-why-doesnt-all-solo-piano-music-begin-in-c-ma).
Comment: Please keep discussions about the questions in the chat. Any further comments will be deleted since they can't be moved into chat.
Comment: Your idea seems to be because you can transpose and relative harmonic relationships are important, that "music is not about the individual notes" and the various keys are redundant. Wrong. First, range matters. Higher or lower ranges move into different keys. Second, and more fundamentally, the relative relationship and contrast of multiple keys is more of the most important aspects of harmony and composition.
Comment: A simple analogy can be had from art. You can paint a monochromatic picture and still recognize the subject, therefore multiple colors are redundant. Both ideas, one key signature and one color painting, are silly for obvious reasons.
Answer: C and Am are NOT always the easiest keys - and I'm considering piano here. Just because they both (presumably) use the 'white keys' doesn't make the pieces easier to play. There are many, many pieces that have been written in different keys, and I'd challenge anyone to play them as well in key C/Am.
Mainly due to fingering. It may appear, mainly to beginners, that any piece is easier to execute in key C/Am, but once you've tried using the black keys as well, it becomes obvious that there will be better keys than those!
I really don't think it's much to do with what each key sounds like individually - with 12tet being the normal piano tuning, that won't make any difference to most, if not all listeners/players.
All that apart - I can't think why anyone would go to a concert and listen to piece after piece in the same key! I certainly get fed up after about 3 in the same key when I'm playing - so use my key change to play in a different key if the next number is another. It does relieve the boredom, and we do tend to think differently in different keys, although I can't reason why.
Comment: @hb20007 - it will depend wholly on what piece is in question. That's like asking 'which  are the easiest tools to use...'  or 'which are the best paintbrushes to use...'
Comment: Any input on what the easiest keys actually are? Or examples of pieces written in different keys which would be more difficult to play in C or Am?
Comment: Wow @Tim. Another question answered by you that is then _closed by you_. Is reputation _removed_ after an question is closed?
Comment: @MichaelCurtis - I was waiting for this comment! The answer seemed too obvious to miss. Then, on reflection, I found a dupe.  Is it now down to me to check out everything first? 'Cos I probably won't... Don't think rep is removed - don't mind if it is.
Answer: There are many reasons why composers would prefer to write for piano on keys other than C or a. For instance:

Absolute pitch of notes and phrases. The same theme played in C major and in G major sounds rather different simply because all notes in it are a fifth higher. The impact on a sensitive musical listener can be quite significant.

Simple variety. A dozen piano sonatas all in C major would quickly become hard to tell apart even for the author.

Limitations of the instrument. The keyboard isn't infinite, and romantic composers permanently pushed the boundaries of the piano (you can tell exactly what the highest note on Chopin's instrument used to be simply because all of his pieces go only so high). Having or not having a specific note available at the top or bottom of the range can make or break the conception of an entire movement.

Playability and readability. There is a reason why many sonatinas for beginners, and many first symphonies even of the greatest composers, are written in C. Conversely, music in C has an undertone of being beginner's music; when Paul Dukas chooses E flat minor for his piano sonata, you know that he means business!
Comment: The timbre of notes on some , maybe most instruments, will change, but on piano, I doubt there's any difference in timbre between playing a piece in, say, F#. And OP is asking specifically about piano, not guitar or flute. The point about  a sensitive listener' may be relevant, but for the vast majority, no-one would notice.
Comment: @KilianFoth - This is tantamount to "D minor is the saddest key" which is a meme that will not go away, long after it was suitably ridiculed in [Spinal Tap](https://www.youtube.com/watch?v=eTDEKk3bB04) The dependancy of the claim really only works before the invention of equal temperament.
Comment: You don't have to have perfect pitch do perceive a motif played in G vs the same motif played in C differently. The timbre of notes always changes subtly across the range of an instrument. For instance, the difference in character between the lowest and highest C on a concert flute is extreme. With a difference of just 7 semitones the effect is of course smaller, but it is there.
Comment: @Tim I passionately disagree. The greater part of the genius of music is that hearers are reliably affected differently by changes in parameters that they claim not to perceive, and couldn't *consciously* distinguish.
Comment: @Tetsujin No, it isn't. I am nowhere referring to the character of keys that *used to* be caused by different micropatterns between the semitones. The point is simply that the same starting chord in C will sound differently when when shifted up *because of the shift*. For instance, there is a limit to how low a specific triad sounds reasonably transparent when you transpose it down; moving tings up and down *will* change the degree to which this applies. Claiming that this makes no difference to listeners is simply wrong.
Comment: It's a good answer but do you have more information regarding the first and second points? As I understand, most people do not have perfect pitch so they will differentiate the music by its intervals. So why does this contribute to variety and what difference do the actual notes make?
Comment: "The timbre of notes always changes subtly across the range of an instrument." This is a good point; I did not think about it. It would be great if you can edit it in the answer, because I believe it is an important one.
Answer: Piano music sounds best when much of the music hangs around middle C; that is, the instrument usually sounds good when at least the accompaniment parts are in the middle range. Too much to the bass side can make the music sound "muddy" and too much to the treble side can sound "tinny" though there is music that takes advantage of these ranges. Even though the piano may be tuned in equal temperament, the absolute pitches matter. Notes on a piano have different numbers of strings so the quality of the same named note in different octaves does sound different.
If one takes a piece and transposes it up (or down), the melody and bass just get moved but the accompaniment (the notes between the melody and bass) may change. For example, if a piece is raised up around half an octave (from C to F or G, for example), A C-chord that was written as C-E-G may be changed to a G chord as B-D-G (rather than G-B-D) to keep the total range around the middle of the keyboard. The overall texture becomes different; not necessarily better or worse, but different. Composers usually have a particular sound in mind.
If a piano were tuned in a non-equal temperament; transposing a melody may change the character entirely. The main points of the music will be the same (a perfect cadence is still a perfect cadence; a G chord followed by a C chord still sounds like a cadence, but the "tone color" of the piece changes.
Comment: Sorry, but none of this rings true. A piece could be in just about any key, and still be played on 3 strings, that pianos have in the several octaves in mid-range. There would also be no need to change inversions of chords for the same reason. -1.


Rewrite a text field in "Manage display" of content type

Question: This feels like it should be simple to do, but I can't work it out.
If I have a text field, how do I rewrite the output of the field on the "Manage display" tab of the content type? For example, I might want to add units, or convert a product ID into a link to an external website.
I know how to do this stuff in Views, but it would seem to make sense to be able to do it via the "Manage Display" tab for a content type. Am I missing something?
Answer: You have a couple of choice based on your needs:

Overriding the template file (twig) of the specific field
Using form_hook_alter
For complex and clean solution I suggest you to use a custom widget for your field type.
Comment: There are also some simple string formatter  contrib modules
Answer: You can achieve this by creating field.html.twig.
Default theme implementation for a field.
You will get more information:
Override field template (twig)
field.html.twig and field--node--title.html.twig
Comment: This option was much easier than I thought it would be.


Why do odds ratios from formula and R's fisher.test differ? Which one should one choose?

Question: In the following example
> m = matrix(c(3, 6, 5, 6), nrow=2)
> m
     [,1] [,2]
[1,]    3    5
[2,]    6    6
> (OR = (3/6)/(5/6))    #1
[1] 0.6
> fisher.test(m)        #2

    Fisher's Exact Test for Count Data

data:  m
p-value = 0.6699
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
 0.06390055 5.07793271
sample estimates:
odds ratio
 0.6155891

I calculated the odds ratio (#1) "manually", 0.600; then (#2) as one of the outputs of the Fisher's exact test, 0.616.
Why didn't I get the same value?
Why do several ways of computing the odds-ratio exist, and how to choose the most appropriate one?
Answer: From the help page for fisher.test():

Note that the conditional Maximum Likelihood Estimate (MLE) rather
  than the unconditional MLE (the sample odds ratio) is used.
Answer: To add to the discussion here, it is useful to ask what exactly is conditioned on in this "conditional" likelihood. The Fisher test differs from other categorical analyses in that it considers all margins of the table to be fixed whereas the logistic regression model (and corresponding Pearson chi-square test which is the score test of the logistic model) only consider one margin to be fixed.
The Fisher test then considers the hypergeometric distribution as a probability model for the counts observed in each of the 4 cells. The hypergeometric distribution has the peculiarity that, since the distribution of the originating odds ratio is not continuous, you often obtain a different OR as a maximum likelihood estimate.
Comment: I don't think your answer makes it clear how this particular likelihood might arise. If you model the data-generating process with a product-binomial, say, you get a different  likelihood (& MLE) conditional on the marginal totals, from what you get if you model it with Wallenius' non-central hypergeometric distribution - the marginal totals are "considered fixed" in both cases.
Answer: I am stuck with the same problem. I searched and searched in stackExchange and Google, and I did not find anything explicitly explaining how the odds ratio in fisher.test() is calculated. This is not a complete answer, but it provides something useful to the discussion.
One thing is clear, fisher.test() calculates a completely different odds ratio with a different (and more complicated) method.
If you write fisher.test in R Console and press Enter, the output will be the complete code of the function fisher.test(). The interesting part concerning our doubt is:
m <- sum(x[, 1L])
n <- sum(x[, 2L])
k <- sum(x[1L, ])
x <- x[1L, 1L]
lo <- max(0L, k - n)
hi <- min(k, m)

support <- lo:hi #Interval of definition of Hypergeometric Distribution

logdc <- dhyper(support, m, n, k, log = TRUE) #log of Hypergeometric Probability Function

dnhyper <- function(ncp) {
  d <- logdc + log(ncp) * support
  d <- exp(d - max(d))
  d/sum(d)
}

mnhyper <- function(ncp) {
  if (ncp == 0)
    return(lo)
  if (ncp == Inf)
    return(hi)
  sum(support * dnhyper(ncp))
}

mle <- function(x) {
  if (x == lo)
    return(0)
  if (x == hi)
    return(Inf)
  mu <- mnhyper(1)
  if (mu > x)
    uniroot(function(t) mnhyper(t) - x, c(0, 1))$root
  else if (mu < x)
1/uniroot(function(t) mnhyper(1/t) - x, c(.Machine$double.eps,
                                              1))$root
  else 1
}

Well, if you

Define x = matrix(c(3, 6, 5, 6), nrow=2)
Run every line of the code extracted from fisher.test in order
Run mle(x)

You get 0.6155891. So this is how the odds ratio in fisher.test is calculated. However, I do not understand the algorithm. I have not found any article explaining it, and it does not seems possible to translate it to a "simple" mathematical formula.
EDIT:
The odds ratio estimate obtained by fisher.test is the conditional maximum-likelihood estimate (CLME) of the odds ratio.
Given a table like this (where $C1$ is the sum of the first column, and so on):
\begin{array}{ll|l}
a_{11} & a_{12} & R_1 \\
a_{12} & a_{22} & R_2 \\ \hline
C_1 & C_2 & n
\end{array}
The CLME odds ratio is defined as
$$ \text{arg } \max_{\psi >0} \frac{\binom{C_1}{a_{11}}\binom{C_2}{a_{12}}\psi^{a_{11}}}{\sum_{k = \max(0, R1 - C2)}^{min(R1, C1)} \binom{C_1}{k}\binom{C_2}{R_1-k}\psi^k }$$
There is no explicit formula of the CLME odds ratio, so one has to use iterative methods to find the argument of the maximum of the function. I suppose that is what fisher.test() does, but I don't recognize the algorithm. So I programmed one by myself:
OR <- function(x) {
  C1 <- sum(x[, 1])
  C2 <- sum(x[, 2])
  R1 <- sum(x[1, ])
  a11 <- x[1, 1]
  a12 <- x[1, 2]
  n <- sum(x)

  fobjetivo <- function(psi)  {
    lo <- max(0, R1 - C2)
    hi <- min(R1, C1)
    sumandosDenom <- numeric(n)
    for (k in lo:hi) {
      sumandosDenom[k] <- choose(C1,k) * choose(C2, R1-k) * psi^k
    }
    salida <- ( choose(C1, a11) * choose(C2, a12) * psi^a11 ) / sum( sumandosDenom )
    return(salida)
  }
  as.numeric(optimize(fobjetivo, interval = c(0.01, 100), maximum = T, tol = 0.00001)$maximum)
}

x = matrix(c(3, 6, 5, 6), nrow=2)
OR(x)

The output is 0.6052843. Still not the same value obtained by the fisher.test(), but in general it appears to be closer than the sample odds ratio. I suppose the difference is explained by the different methods, by I don't know for sure.
Reference: Kenneth J. Rothman, Sander Greenland and Timothy L. Lash (2008): Modern Epidemiology, 3rd Edition, Lippincott-Raven Publishers, p. 257
Answer: To answer your second question, biostats isn't my forte but I believe the reason for multiple odds ratio statistics is to account for sampling design and design of experiments.
I've found three references here that will give you a bit of understanding as to why there is a difference between conditional MLE vs unconditional for odds ratio, as well as other types.

Point and interval estimation of the common odds ratio in the combination of 2 × 2 tables with fixed marginals
The Effect of Bias on Estimators of Relative Risk for Pair-Matched and Stratified Samples
A Comparative Study of Conditional Maximum Likelihood Estimation of a Common Odds Ratio
Comment: It'd be useful to summarize at least a little what those references have to say.
Comment: @Scortchi, agreed. I've been busy with work and only had the chance to read through the first page or two of each. I'll add a summary of each this weekend.
Comment: @Jon I only asked one question. It was bli who added a second question 4 years after I posted my original question. I'm not reversing bli's annoying edit as you referenced the second question, but I'm not sure how to accept an answer any more.
Comment: @Jon If you could, it would be useful to add that brief summary


Is this topological space metrizable?

Question: Let $X=\left\{0,1,2\right\}^{\mathbb{Z}}$ carry the product topology $\tau$. Surely, $(X,\tau)$ is compact (Tychonoff).
But is $(X,\tau)$ metrizable and if yes - why?
Is there a metric that generates $\tau$?
Comment: Are you giving $\{0,1,2\}$ the discrete topology? If so, $X$ is homeomorphic to the Cantor set. To get an explicit metric, put the discrete metric on $\{0,1,2\}$ and use any of the usual constructions for a metric on the product of countably many metric spaces.
Comment: Ok. Another question. Is $(X,d)$ with $d(x,y)=\begin{cases}2^{-k}\text{ with k maximal so that }x_{[-k,k]}=y_{[-k,k]}, & x\neq y\\0,  & x=y\end{cases}$ a compact metric space?
Comment: What do you mean by $x_{[-k,k]}$?
Comment: I mean the positions from -k to k in the sequence $x\in X$.
Comment: Ah, okay. Yes, it is; it's a good exercise to prove that this metric does in fact generate the product topology on $X$.
Comment: Do I see it right: If $(X,\tau)$ is a metrizable topological space, then $(X,d)$ is a metric space, where $d$ is any metric that generates the topology $\tau$?
Comment: Yes, that's correct. A metrizable space is one whose topology can be generated by some metric.
Comment: By the way: Does the matrix d I metioned have a special name?
Comment: The metric in your first comment? Not that I know of.
Answer: A countable product of metric spaces is metrizable. In fact, if $d_n$ is a metric on $X_n$, then $$d(x,y) \equiv \sum_{n=1}^{\infty}2^{-n}\frac{d_n(x_n,y_n)}{1+d_n(x_n,y_n)}$$ is a metric on $$\prod_{n=1}^{\infty}X_n$$ that generates the product topology.

Is this topological space metrizable?


pdf parse to text in java

Question: I have an Arabic PDF, and I want to parse it into text document using Java. I have tried many times, and the English words parse successfully but the Arabic words don't.
Can anyone recommend a solution that will convert the Arabic words properly as well?
Comment: which library are you using to read the pdf file?
Comment: i tried pdfbox and iText and Apache plug-ins they not work probably like i want
Comment: See these: http://www.prasannatech.net/2009/01/convert-pdf-text-parser-java-api-pdfbox.html
Comment: pdfbox not good for parsing arabic pdf
Answer: There are several libraries that come to mind. Apache Tika, iText or pdfbox will all more or less solve your problem. Although, I must put in a word for Tika, as it supports language detection, and can also handle other document types too.
Comment: i tried all the libraries you mentioned ,they cant parse arabic pdf,apache tika parse arabic but not all the pdf files i think that the pdf is encoded or security on it i cant understand because also when i want to shadow the words it cant shadow it successfully ,pleeeeeeeeeeeease help me
Comment: In IText you would set the [ALLOW_COPY](http://api.itextpdf.com/com/itextpdf/text/pdf/PdfWriter.html#ALLOW_COPY) permission using the [setEncryption](http://api.itextpdf.com/com/itextpdf/text/pdf/PdfWriter.html#setEncryption(byte[],%20byte[],%20int,%20int)) method of PdfWriter. If you are editing existing PDFs that are already encrypted, you need the current password first.
Comment: If a PDF files has the right to extract the text removed (This can be controlled for each file), no software will be able to help you.
The current settings of a PDF can be found be opening the file in the Adobe Reader an pressing Crtl-D (or goning to the document properties using the menu).
Comment: thanx for your help ,but i want to know what is the property i should change in the pdf properties to make it selectable ????
Answer: I think you can use iText for pdf manipulation using Java. It supports Arabic too.
Comment: i tried iText it create a pdf not convert it to text please if you have ahelp give me

pdf parse to text in java


Como faco para selecionar algumas linhas de publicos diferentes?

Question: Preciso selecionar um publico dentro de algumas condicionantes.

As 3 primeiras linhas do GRUPO 1

A primeira linha do GRUPO 3
Caso não tenha primeira linha no GRUPO 3:

A primeira linha do GRUPO 4

A primeira linha do GRUPO 2
Caso não tenha a primeira linha do GRUPO 4
Então em vez de selecionar só a primeira linha do GRUPO 2, deve selecionar 2 linhas.

Estou tentando rankear e pegar isso com case when, mas esta complicado. Algume me ajuda?
Obrigada.
Tenho uma tabela de publico no seguinte formato:

CLIENTE
GRUPO
RANK

100
1
1

101
1
2

102
1
3

103
1
4

104
1
5

105
2
1

106
2
2

107
2
3

108
2
4

109
4
1

110
4
2

Tabela Final Pego os 3 primeiros do GRUPO 1, a primeira linha do GRUPO 4 e a primeira do GRUPO 2

CLIENTE
GRUPO
RANK

100
1
1

101
1
2

102
1
3

109
4
1

105
2
1
Comment: bem vinda Juliana. Leia sua pergunta e tente pensar nas pessoas que não conhecem as tabelas, os campos, nada, não tem como ajudar. Coloque na pergunta o modelo de dados e query que já tem, e um exemplo do resultado esperado
Comment: Será que fazer o UNION dos selects com as devidas condições não seria uma abordagem melhor do que com CASE/WHEN?
Comment: Qual seu `SGBD`? Consegue colocar na sua pergunta o `script` de criação de tabelas e inserção dos dados?
Answer: Interpretando "caso não tenha primeira linha" como não existindo registros nesse grupo, tente:
SELECT * FROM (
(SELECT * FROM tabela WHERE GRUPO = 1 ORDER BY CLIENTE LIMIT 3) a
UNION
(SELECT * FROM tabela WHERE GRUPO = 3 ORDER BY CLIENTE LIMIT 1) b
UNION
(SELECT * FROM tabela WHERE GRUPO = 4 AND NOT EXISTS (SELECT * FROM tabela WHERE GRUPO = 3) ORDER BY CLIENTE LIMIT 1) c
UNION
(SELECT * FROM tabela WHERE GRUPO = 2 AND NOT EXISTS (SELECT * FROM tabela WHERE GRUPO = 3)ORDER BY CLIENTE LIMIT 1) d
UNION
(SELECT * FROM tabela WHERE GRUPO = 2 AND NOT EXISTS (SELECT * FROM tabela WHERE GRUPO = 4) ORDER BY CLIENTE LIMIT 1 OFFSET 1) e
)
ORDER BY CLIENTE;

Answer: Juliana, segue uma sugestão para testes utilizando uma CTE para obter a quantidade de linhas dos grupos para depois utilizar essa quantidade na clausula Where:
with CTE_Count as
(
    select
        count(case when Grupo = 2 then 1 end) as QtdGrupo2,
        count(case when Grupo = 3 then 1 end) as QtdGrupo3,
        count(case when Grupo = 4 then 1 end) as QtdGrupo4
    from Tabela
)

select
    t.*
from Tabela as t
cross join CTE_Count as c
where
    (t.Grupo = 1 and t.Rank <= 3) or
    (t.Grupo = 3 and t.Rank = 1) or
    (t.Grupo = 4 and t.Rank = 1 and c.QtdGrupo3 = 0) or
    (t.Grupo = 2 and
        (
            (t.Rank = 1 and c.QtdGrupo3 = 0) or
            (t.Rank = 2 and c.QtdGrupo3 = 0 and c.QtdGrupo4 = 0)
        )
    )

Espero que ajude


What advantages are there to learning on a guitar with no fret markings?

Question: I recently picked up a classical guitar and am considering buy fret markings for it. But I before I do so I would like to know what advantages are there to learning on a guitar with no fret markings. If they are significant I won't bother with the markings.
I am in the process of learning all the notes on the fret board.
Answer: If you can learn to play without fret markers, you will have a tremendous advantage over those who have learned to rely on the fret markers.
When I first began learning to play guitar I relied on the fret markers to help me find my place on the fretboard.  But when I started playing for audiences on dark stages, I recognized the limitations of not being able to just instinctively know where the frets are.  So I found it prudent to start practicing playing without looking at the fret markers to learn to play without having to look down at the fretboard and find the fret markers.
I actually would practice in dark rooms so I couldn't cheat and glance at the fret markers.  Eventually I got to a point where I rarely if ever look at the fret markers.  This allows me to sing into the microphone without turning my head down to check my fret markers from time to time and also allows me to make maintain eye contact with (or at least look at) the audience.
Playing instinctively will also contribute to smoother playing since you will never have to momentarily hesitate to check the fret markers.
And even if you don't plan to sing into a microphone while playing or perform on a dark stage, it would be difficult to read music or tablature while playing, if you had to look away from the music to see where the frets are.
On the other hand, if it is easier for you to learn with the fret markers, you can always try to learn to play without them as you progress.  But once you learn by relying on the fret markers, you might become psychologically dependant on them and it might be more difficult to learn to play without them.
And I have seen some very talented and experienced guitarist, who not only rely on the fret markers, but enlarge them on their guitars to help see them on dark stages.
So it's really up to you.  But I would encourage you to try learning without fret markers and see how far you get.  If it proves too difficult in the beginning, perhaps you can use round stick on labels and add one or two fret markers on the edge of the fretboard - maybe at the 7th fret.
Good luck - whichever way you choose to go.
Comment: Amazing answer will keep trying it!
Answer: With a classical guitar with no fret markings, the join of the shoulders with the neck will be precisely at the 12th fret. So you can identify the 5th fret as 1 hand-width past the nut and the 7th fret as 1 hand-with from the 12th-fret join.
Practice not even looking at the fret-board while you play. Instead, look at the music, the conductor, the other musicians, the needle on the metronome, whatever.
Your fingers will learn where everything is.
Answer: I was just reading one of the 19th century Method books in which the author insisted that you hold the guitar vertically, and learn to place the left hand without looking.  If you do that fret markers won't do you any good.  Admittedly, many (most?) modern classical performers do watch their left hand fingerings closely.
A compromise is small fret markers at the 5 and 7 on the edge of the neck.  They are visible to the player, but not to the audience.  As a beginner I appreciate them on my Yamaha.
Answer: I started playing the guitar by reversing the strings of a right-handed guitar to left-handed. There were no fret markings on the guitar and the white dots for 3rd, 5th and 7th frets in the side facing to the player were invisible to me.
It provides frustration for some time but after that you see the benefits of your muscles memorizing the fret positions instead of your eyes.
Answer: For certain long, fast slides I still look down, but my visibility on stage is very limited (I wear a mask in my current band) so practicing knowing where you are by feel has been very helpful for me.
I'd recommend trying it without fret markers.


scipy 0.16 and robust regression with implicit ODE

Question: I do want to fit an implicit ODE to some data and It would be good if I use robust regression. This feature is implemented in scipy 0.17 but it seems that the ODE solver (assimulo package) requires scipy 0.16 ( with scipy 0.17: anaconda3/envs/scipy0.17/lib/python3.4/site-packages/scipy/linalg/../../../../libgfortran.so.3: version 'GFORTRAN_1.4' not found).
There is a section in the scipy cookboock dealing with robust regression. It is said, that the residuals and the Jacobian matrix are modified at each timestep.
So it would not be enough to change  just the residual function ? In which way would I have to change the Jacbian Matrix and can this be done at each timestep using scipy 0.16 ?
Any ideas how I could use either scipy 0.17 with assimulo (maybe by symlinks ) or implement a robust nonlinear fitting method within scipy 0.16 ? Or are there some other optimization packages which would work ?
Comment: You might be interested in this package: http://symfit.readthedocs.io/en/latest/fitting_types.html#ode-fitting
Answer: It seems something is broken in the package. From the issue tracker:
At least on an Ubuntu machine, following workaround helps: export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libgfortran.so.3 By this way the problematic version of libgfortran is replaced temporarily.


Entity Framework Context is quite slow, not sure because of my coding or generally slow?

Question: I found EF is quite slow to start. And wanted to know, because of my coding design or generally EF is slow.
I have got few tables
    public class ApplicationDbContext: DbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
    public DbSet<ClientModel> ClientModels { get; set; }
    public DbSet<EmployeeModel> EmployeeModels { get; set; }
    public DbSet<ClientContactModel> ClientContactModels { get; set; }
    public DbSet<FileModel> FileModels { get; set; }
    ........
}

And I am using IRepository for each model. For examoke Client Model
 public interface IClientRepository
{
    IQueryable<ClientModel> ClientModel { get; }
    bool SaveClient(ClientViewModel client);
    bool DeleteClient(int? clientID);
}

 public class ClientRepository : IClientRepository
{
 constructor ...
 public IQueryable<ClientModel> ClientModel => context.ClientModels.OrderBy(c => c.ClientName);
}

In my Startup  for each model
  services.AddTransient<IClientRepository, ClientRepository>();

And Finally  my Controller i can access the data
private IClientRepository clientRepository;
private IEmployeeRepository employeeRepository;

public ClientController(IClientRepository _clientRepository, IEmployeeRepository _emp)
    {
        clientRepository = _clientRepository;
        employeeRepository = _emp;
    }

Is it the best way to get the data from database or shall i use context without interfaces- something like this
private readonly ApplicationDbContext context;
public ClientController(ApplicationDbContext cont)
    {
        context = cont;
    }

START UP
 public class Startup
{
    public IConfiguration Configuration { get; }
    public Startup(IConfiguration configuration) => Configuration = configuration;

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddSingleton(Configuration);
        services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration["ConnectionString1"]));
        services.AddDbContext<AppIdentityDbContext>(options => options.UseSqlServer(Configuration["ConnectionString2"]));
        services.AddDbContext<AppEmployeeDbContext>(options => options.UseSqlServer(Configuration["ConnectionString3"]));

        services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<AppIdentityDbContext>().AddDefaultTokenProviders();
        services.AddTransient<IClientRepository, ClientRepository>();
        services.AddTransient<IEmployeeRepository, EmployeeRepository>();
        services.AddTransient<IClientContactRepository, ClientContactRepository>();
        services.AddTransient<IFileRepository, FileRepository>();
        services.AddTransient<IDolsMcaClientRepository, DolsMcaClientRepository>();
        services.AddTransient<IDolsMcaItemRepository, DolsMcaItemRepository>();
        services.AddTransient<IMcaRepository, McaRepository>();
        services.AddTransient<IIncidentRepository, IncidentRepository>();

        services.AddMvc();
        services.AddSession(options =>
        {
            options.IdleTimeout = TimeSpan.FromSeconds(1000 * 60 * 60); //1hr
            options.Cookie.HttpOnly = true;
            options.Cookie.IsEssential = true;
        });
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseStaticFiles();
        app.UseStatusCodePages();
        app.UseSession();
        app.UseAuthentication();

        app.UseMvc(routes => {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();
        }
        else
        {
            app.UseExceptionHandler("/Error/500");
            app.UseStatusCodePagesWithReExecute("/Error/{0}");
        }

        app.Run(async (context) =>
        {
            await context.Response.WriteAsync("Empty!");
        });
    }
}

Comment: What are you observing that you define as "slow"?
Comment: That's pretty normal and it doesn't usually have anything to do with Entity Framework. Why do you believe that EF is holding it up?
Comment: When i click Start Debugging, it takes a minute to start the first page.
Comment: it will take some time for the first time.
Comment: I used Dapper, for this project in the beginning and it is quite fast and better. But couldn't figure out how to use identity with dapper so changed this web to EF now but it is quite slow to start. Any updates or change i am wasting times.
Comment: is it .NET Core or .NET Framework?
Comment: it is .NET CORE
Comment: Can you share your whole startup and dbcontext classes? You may be running migrations every time your project starts.
Comment: _When i click Start Debugging, it takes a minute to start the first page._ what makes you think that has anything to do with the context class?
Answer:
I found EF is quite slow to start. And wanted to know, because of my
  coding design or generally EF is slow.

First of all, if you are using Entity Framework Core you don't need to create extra Repository layer as EF Core is a repository by itself. Instead of creating extra Repository classes and IRepository interfaces you can create extension methods for your entities and inject the ApplicationDbContext directly to your services. You can have a look at what is the idea of this approach here
When you know that you only read the data in the given scope you can use lazy loading to improve the speed of your queries. This can give you a big performance boost. Check also how AsNoTracking thingy works to improve the performance
Avoid things like this context.ClientModels.OrderBy(c => c.ClientName); as it results in select * from ... which is quite common problem. I know that in your case you are using the IQueryable so you can add some more logic to the query, however, creating an extra field to just only invoke the OrderBy on seems like a triumph of form over content.
Use Async methods as EF Core allows you to do this.
If you are saying that Entity Framework is slow maybe think more about the system architecture as in the case where you have to deal with millions of records in your DB you can think about changing approach and denormalized your DB to avoid complex JOIN queries as it always has a big impact on the performance when dealing with big data.


Ola, queria saber porque ocorre este erro no meu scipt .php: mysql_num_rows() expects parameter 1 to be resource, boolean given in

Question: <?php
    $error = "";
    if(isset($_POST['registrar'])){
        $nome = $_POST['nome'];
        $email = $_POST['email'];
        $apelido = $_POST['apelido'];
        $pass = $_POST['pass'];
        $cpass = $_POST['cpass'];
        $notify = $_POST['notify'];

        $verify = mysql_query("SELECT * FROM users WHERE email = '$email'");

        if(strlen($nome) < 3){
            $error = "
Nome muito pequeno!
";
        }else if(strlen($email) < 8){
            $error = "
Email muito pequeno!
";
        }else if(strlen($apelido) < 3){
            $error = "
Apelido muito pequeno!
";
        }else if(strlen($pass) < 8){
            $error = "
Senha muito pequena!
";
        }else if($pass != $cpass){
            $error = "
As duas senhas não batem!
";
        }else if(mysql_num_rows($verify) > 0){
            $error = "
Email ja registrado!
";
        }else{
            mysql_query("INSERT INTO users (`nome`,`email`,`apelido`,`senha,`notify,`active`) VALUES ('$nome','$email','$apelido','$pass','$notify','false')");
            $error = "
Sua conta foi registrada, Entre em seu email para verificar.
";
        }
    }
?>

<!DOCTYPE html>

    <title>Register - TheNiceComp</title>
    <link rel="stylesheet" type="text/css" href="style.css">

    <?php include("header.php"); ?>

Registre-se

            <?php echo $error; ?>
            <form method="POST">

                        Nome:
                        <input type="name" name="nome">

                        Email:
                        <input type="email" name="email">

                        Apelido:
                        <input type="name" name="apelido">

                        Senha:
                        <input type="password" name="pass">

                        Confirme a Senha:
                        <input type="password" name="cpass">

                        Receber novidades no Email:
                        <input type="checkbox" name="notify">

                <input type="submit" name="registrar" value="Registrar" style="width: 50%">
            </form>

qualquer ajuda fico grato!!
Comment: Olá @TheNiceComp, teve a oportunidade de verificar a resposta?
Comment: Se a resposta lhe atendeu, não esqueça de votar e aceitá-la.
Answer: Há algum erro ao executar o seu select, portanto $verify é false e como é passado para mysql_num_rows esse erro é então apresentado.
É preciso verificar o sucesso da query com, por exemplo,
if (!$verify) {
    die('Invalid query: ' . mysql_error());
}

Um outro detalhe importante a ser mencionado é que esses métodos foram removidos no PHP 7, devendo ser substituídos por mysqli_num_rows e mysqli_query.


Does the android NDK compiler support inline assembly? (ie asm or __asm keywords?)

Question: Just wondering if andorid NDK supports direct embedding of asm?
<code>asm{
//lots of strange asm instructions...
 }
</code>
If so, I presume you'd have to get some refference to the instruction sets of the specfic arm achitecture - where would you find these?
Thanks,
Steve.
Answer: The Android NDK uses GCC, so you can safely look at GCC documentation.
As for the specific ARM instructions, something like ARM architecture may be a good starting point.
Comment: is the GCC compiler version specific to andorid? Or can I find the documentation in any linux based resource? Thanks
Comment: The compiler itself is standard. The NDK r6 for example uses GCC v4.4.3. The NDK does have it's own build system and the like to wrap it all up however. That said, yes the standard GCC documentation should do.
Answer: In addition to @NuSkooler this is another useful resource
ARM GCC inline assembler cookbook


how to save the result of a t4 template on a different folder

Question: When i try to specify an absolute path for the generated files using
<code>someTemplate.RenderToFile("c:\\tmp\\filename.ext");
</code>
I'm getting the following error
Error   263 Running transformation: System.Runtime.InteropServices.COMException (0x80004005): There is already a file of the same name in this folder.
even though the folder is empty.
Answer: This functionality was implemented in version 9.3 of T4 Toolbox: http://t4toolbox.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25294
Answer: Vitor,
Are you using Template.RenderToFile method from T4Toolbox? If yes, this method currently doesn't support saving files to a different folder. This has been on my to-do list for a while. What are you generating, anyway?
Comment: I built a template of the row data gateway (http://martinfowler.com/eaaCatalog/rowDataGateway.html) to use in simple asp.net webapps.

And everytime i change someting in the db schema and have to generate those classes I have to manually copy them to main project... which is kinda boring...


href link not working on overlapping divs

Question: I have two divs that overlap horizontally. My issue is that one of the divs contain text and a href link which is not working.
You can see the code I have here
https://jsfiddle.net/jayreis/w7regdcr/
 .postwrapper
 {
    margin:auto;
    width:80%;
    display:block;
    padding-bottom:15px;
 }
 .imageDiv
 {
        margin-left: 100px;
        background: #fff;
        display: block;
        width: 445px;
        height: 220px;
        padding: 10px;
      border-radius: 2px 2px 2px 2px;
 }
.imageDiv img
{
  width:600px;
  height:400px;
}
.textboxDiv
{
  position:relative;
  bottom:145px;
  left:470px;
  zoom: 1; /*to fix the has layout bug in IE older version*/
  filter: alpha(opacity=50);
  opacity: 0.9;
  background-color:#ffffff;
  text-align:center;
}
.textboxDiv:after
{
  content:'';
  position: absolute;
  top: -15px;
  left: -15px;
  right: -15px;
  bottom: -15px;
  border: #dddddd 2px solid

}
.readarticle
{
  text-decoration:none;
  border-top: 1px solid #a61531;
  float:left;
  color:#000000;
  z-index: 99999;
}

date here

the title

desc here

READ ARTICLE

So if you look at the css if I change the  position: absolute; to be  position: relative; in the class style .textboxDiv:after the link then works but I loose the border style I need around the box.
Any suggestions how I can keep the style yet make the links work in the textboxDiv ??
Answer: .readarticle is not positioned, so the z-index won't work. Simply add position: relative; and it'll work.
  .readarticle
  {
    text-decoration:none;
    border-top: 1px solid #a61531;
    float:left;
    color:#000000;
    z-index: 99999;
+   position: relative;
  }

MDN Documentation: Z-Index


If $(a_1,\ldots,a_n)=(1)\implies$ some $x_i$ is unit

Question: Let $R$ be an unital commutative ring such that is local. I'm trying to prove
$$(a_1,\ldots,a_n)=(1)\implies \text{some}\ a_i\text{ is unit}$$
If $R$ is local this statement above is true?
Thanks in advance
Comment: You simply proved the contrapositive.
Comment: @PedroTamaroff oh, it's true, I will edit it.
Comment: @PedroTamaroff so if $R$ is maximal, the statement is true?
Comment: Maximal ideals are always proper. What do you mean by "$R$ is maximal"?
Answer: Yes, your proof is correct.  A ring is local iff the set of non units is an ideal, which would of course be maximal.  So if $a_1,\dots,a_n$ are not units then they are all contained in the maximal ideal and hence the ideal they generate is contained in the maximal ideal also.
Of course this does not hold in a general ring.  Take say, $\mathbb{Z}$ and consider the ideal generated by $2$ and $3$.
Comment: I remarked that I proved the contrapositive.
Comment: Using your example, it's not possible, but if $R$ is local the statement is true?
Comment: Yes and your proof is correct.


How do you prove the following formula $\binom{n+i-1}{n} = \sum\limits_{k=0}^{n}\binom{i-1}{k} \binom{n}{k}\ $?

Question: I'd like to prove the following formula: For any $i, n \in \mathbb{N}^* $ $$\binom{n+i-1}{n} = \sum\limits_{k=0}^{n}\binom{i-1}{k} \binom{n}{k}\ .$$
In fact, I fixed $i \in \mathbb{N}^*$ and verified some cases of $n$. For example,
$$\binom{i+2-1}{2} = \binom{i-1}{0} + 2\binom{i-1}{1} + \binom{i-1}{2},$$
$$\binom{i+3-1}{3} = \binom{i-1}{0} +3\binom{i-1}{1} + 3 \binom{i-1}{2} + \binom{i-1}{3},$$
Can you help me?
Answer: $$\sum\limits_{k=0}^{n}\binom{i-1}{k} \binom{n}{k}=\sum\limits_{k=0}^{n}\binom{i-1}{k} \binom{n}{n-k}$$
Imagine that you are choosing $n$ balls from two boxes, one has $i-1$ balls while the another has $n$ balls. The way to choose, in one hand, is
$$\binom{n+i-1}{n}$$
But on the other hand, it's
$$\sum\limits_{k=0}^{n}\binom{i-1}{k} \binom{n}{n-k}$$
It's done here.
Answer: You want to select $n$ objects out of $n+i-1$ objects. You can visualize the $n+i-1$ objects as $n$ objects first, followed by $i-1$ objects.
To select your $n$ objects, you can take $k$ out of the first $n$, and then take $n-k$ out of the following $i-1$. This can be done for any $0\le k \le n$.
Now take the sum over $k$.
Answer: Here's an algebraic answer using generating functions.  For convenience let $m = i-1$, so we are trying to prove
$$
\binom{n+m}{n} = \sum\limits_{k=0}^{n}\binom{m}{k} \binom{n}{k}\ .
$$
By the binomial theorem, the lefthand side is the coefficient of $x^n$ in $(1+x)^{n+m}$.  Since $\binom{n}{k} = \binom{n}{n-k}$, the convolution formula for polynomials tells us that the righthand side is the coefficient of $x^n$ in $(1+x)^m (1+x)^n$.  (This "convolution formula" is just the fact that the coefficient of $x^n$ in the product $\left(\sum_{i=0}^r a_i x^i\right) \left(\sum_{i=0}^s b_i x^i\right)$ is $\sum_{k=0}^n a_k b_{n-k}$.)  Since $(1+x)^m (1+x)^n = (1+x)^{n+m}$, then the two sides are equal.
In symbols, we can write this as follows:
\begin{align*}
\binom{n+m}{n} &= [x^n] (1+x)^{n+m} = [x^n] (1+x)^{n} (1+x)^{m} = \sum_{k=0}^{n} \left([x^k] (1+x)^{n} \cdot [x^{n-k}](1+x)^{m}\right)\\
&= \sum\limits_{k=0}^{n}\binom{m}{k} \binom{n}{n-k} = \sum\limits_{k=0}^{n}\binom{m}{k} \binom{n}{k} \, ,
\end{align*}
where $[x^n]f(x)$ denotes the coefficient of $x^n$ in the polynomial $f$.
Answer: You may immediately prove it observing that it is a particular case of the Chu-Vandermonde identity $$\dbinom{x+a}{n}=\sum_{k=0}^{n}\dbinom{x}{k}\dbinom{a}{n-k}.$$ In fact, taking $$a=n,\,x=i-1$$ and observing that $$\dbinom{n}{n-k}=\dbinom{n}{k}.$$ we get $$\sum_{k=0}^{n}\dbinom{i-1}{k}\dbinom{n}{n-k}=\sum_{k=0}^{n}\dbinom{i-1}{k}\dbinom{n}{k}=\color{red}{\dbinom{n+i-1}{n}}.$$ Another simple way is to use the Egorychev representation $$\dbinom{n}{k}=\frac{1}{2\pi i}\oint_{\left|z\right|=1}\frac{\left(1+z\right)^{n}}{z^{k+1}}dz$$ then we have $$\dbinom{n+i-1}{n}=\frac{1}{2\pi i}\oint_{\left|z\right|=1}\frac{\left(1+z\right)^{n+i-1}}{z^{n+1}}dz$$ $$=\frac{1}{2\pi i}\oint_{\left|z\right|=1}\frac{\left(1+z\right)^{n}}{z^{n+1}}\sum_{k=0}^{i-1}\dbinom{i-1}{k}z^{k}dz=\sum_{k=0}^{i-1}\dbinom{i-1}{k}\frac{1}{2\pi i}\oint_{\left|z\right|=1}\frac{\left(1+z\right)^{n}}{z^{n-k+1}}dz$$ $$=\sum_{k=0}^{i-1}\dbinom{i-1}{k}\dbinom{n}{n-k}=\color{blue}{\sum_{k=0}^{n}\dbinom{i-1}{k}\dbinom{n}{n-k}}$$ where the last identity follows from the observation that if $k>n$ then $\dbinom{n}{n-k}=0.$
Answer: It's just the Vandermonde's identity. Notice that $$\sum_{k=0}^n \binom {i-1}{k}\binom {n}{k}=\sum_{k=0}^n \binom {i-1}{k}\binom {n}{n-k}$$
Then by Vandermonde's identity we get
$$\sum_{k=0}^n \binom {i-1}{k}\binom {n}{n-k}=\binom {n+i-1}{n}$$


Difference between drupal_write_record and db_insert

Question: I want to know what is the difference between drupal_write_record and db_insert
example :
can i translate that drupal_write_record('MyCustomTable', $Myrecord, $primary_key); to an insert query ?
thank you
Answer: drupal_write_record doesn't know by itself whether to do the insert or the update, but this is determined by the existence (or not) of the 3rd parameter: $primary_keys which defaults to array() while db_insert is to insert new record to database.
according to drupal_write_record API documentation

$primary_keys: To indicate that this is a new record to be inserted, omit this argument. If this is an update, this argument specifies the primary keys' field names. If there is only 1 field in the key, you may pass in a string; if there are multiple fields in the key, pass in an array.

Also

Do not use drupal_write_record() within hook_update_N() functions, since the database schema cannot be relied upon when a user is running a series of updates. Instead, use db_insert() or db_update() to save the record.
Comment: Not entirely, but you could with a `db_merge` @Mitch
Comment: Thank you, but can i replace a drupal_write_record by an insert ?