Explain the difficulty of find primes with the same last digit

Question: Refer to https://oeis.org/A340800 to notice that the number of primes between two primes having the same last digit is increasing as the primes themselves increase.  Is there an explanation for this?  How can the size of primes have any influence on the last digit of the following primes?
Answer: Supposing the last digits of primes form a random sequence, from the set 1,3,7,9.
Let the prime we want end in a 1.  The next $n-1$ primes must end with something else, and the $n$th end with a 1.  This happens with probability $$\left(\frac34\right)^{n-1}\frac14$$
So it is harder to belong in a later slot of A340800, so the first one in each slot tends to be higher.
Comment: The same probability occurs for any random list.  So how can you claim that the improbability increases as the numbers in this random list increase?
Comment: Each prime except $2$ and $5$ is in one of the slots, although A340800 only contains the first of each slot.  As $n$ increases, numbers in the $n$th slot become rarer. If one in a million go in the $N$th slot, then it is quite likely that none of the first thousand go in that slot, by which time the early slots all have their first entry.  So numbers tend to increase in A340800, but that is not always true.
Comment: Say we are looking for last digit 1.  If it is many primes away, that means that all the last digits in between are 3,7,9 and they must be close together since there are so many of them.  Why is this not true for last digit 1, but only for last digits 3,7,9?  The same argument could be applied to them singly, hence there's a  contradiction.
Answer: Let $$\mathfrak P(x,n)=\Bbb P(\exists m\leq n \in \Bbb N : x+10m \text{ is prime} | x \text{ is prime})$$
The relative density of primes decreases as numbers get larger. Because of this, $\mathfrak P$ is very high for small $x$ and generally decreasing in $x$. At the same time, it is increasing in $n$ (Every time you add another potential number that might be prime, the probability increases).
One can see from this exactly what the OEIS results show, that if a prime is small, the next prime with the same last digit is very likely not much bigger, and for a large prime, you'll likely need a larger $n$ to satisfy, which implies the next prime will be further away.
Comment: One needs to study for higher primes the average number of primes between two primes having the same last digit to see if this number is increasing.  If the average is 25 primes, then finding one with 28 primes in between is nothing exciting.   If one examined all numbers between the two primes, would the composites also have the same property of having many composites not having the desired last digit?  I think more data is required.
Comment: Well, the decreasing relative density of primes directly implies that the average difference between $p_k$ and $p_{k+1}$ increases as $k\to\infty$, and this in turn means the average distance between prime subject to any other condition increases as well.
Comment: What has to  be done is to find some term in A340800 such that all terms after that are strictly increasing.  Without this there is no way to avoid the randomness of these gaps.   I wonder if anyone has examined the average length of gaps between primes having the same last digits as one moves higher into the primes.   Applying the probability as given by Emp2 (above) does not in any way come close to what A340800 lists.
Answer: Of course the general trend of A340800 must be increasing (although it is not monotonic).  For any $M$, the maximum of $A072971(k)$ for $k \le M$ is some finite
value $N$, and so if $n > N$ and $A340800(n)$ exists at all it must be $prime(k)$ for some $k > M$.  The existence of $A340800(n)$ follows from the prime $k$-tuples conjecture.
Comment: Observing a(13), has four larger terms  before it; a(24) has five larger terms before it; a(28) has 3 larger terms before it; a(35) has 3 larger terms  before it.  Clearly not monotonically increasing, which suggests that the more an event is improbable, the more trials must be made, but not necessarily true in all cases.  One would have calculate the probability for all the failures between the two primes having the same last digit to judge how well the probability reflects the facts of the matter.   I conclude that none of this is related to the primes as primes, but just to wild chance.


Problema em conversão de data (DD/MM/YYYY para YYYY-MM-DD) com 'pd.to_datetime()' - Python

Question: Estou iniciando no mundo do Python e estou tentando desenvolver um código simples para identificar o período de expiração de certificados digitais onde trabalho (é um projeto pessoal, mas aproveitando um problema real).
Consegui extrair os dados do servidor de chaves e transformá-los em um dataframe, porém quando tento converter a coluna "valido_ate" para um formato de data (pd.to_datetime()), a fim realizar cálculos com ela, reparei que em alguns casos o formato fica diferente (não são em todas as linhas desta coluna que isto aconteceu).
Repare que no campo "valido_de", que possui o mesmo código e a mesma fonte de dados isto não aconteceu.
Alguém tem alguma dica?
Observação: este é basicamente o meu primeiro código, não trabalho na área de desenvolvimento, então por favor relevem a questão de "clean code" por enquanto, um dia chego lá hehe :)
#Imports
import requests
import pandas as pd
from bs4 import BeautifulSoup
import matplotlib.pyplot as plt
import re
import xlsxwriter
from datetime import date, timedelta, datetime
from dateutil.parser import parse

#URL
url = requests.get("url_interna", verify=False)
url.content
soup = BeautifulSoup(url.content, 'html.parser')
html = list(soup.children)[3]

#Variáveis
certificates = soup.find(id="tblCertificates")
title_name = soup.find('td', class_='tdTitle tdTitleName').text
title_subject = soup.find('td', class_='tdTitle tdTitleSubject').text
title_valid_from = soup.find('td', class_='tdTitle tdTitleValidFrom').text
title_valid_to = soup.find('td', class_='tdTitle tdTitleValidTo').text
title_status = soup.find('td', class_='tdTitle tdTitleStatus').text
body_name = soup.find(class_="tdBodyName")
body_subject = soup.find(class_="tdBodySubject").get_text()
body_valid_from = soup.find(class_="tdBodyValidFrom").get_text()[14:24]
body_valid_to = soup.find(class_="tdBodyValidTo").get_text()[14:24]
body_status = soup.find(class_="tdBodyStatus").get_text()
lista_names = certificates.select(".tdBodyName")
lista_subject = certificates.select(".tdBodySubject")
lista_valid_from = certificates.select(".tdBodyValidFrom")
lista_valid_to = certificates.select(".tdBodyValidTo")
lista_status = certificates.select(".tdBodyStatus")
names = [pt.get_text() for pt in lista_subject]
valido_de = [pt.get_text()[14:24] for pt in lista_valid_from]
valido_de = pd.to_datetime(valido_de)
valido_ate = [pt.get_text()[14:24] for pt in lista_valid_to]
valido_ate = pd.to_datetime(valido_ate)
status = pd.to_datetime('today') - valido_ate

data = {
'nome': names,
'valido_de': valido_de,
'valido_ate': valido_ate,
'status': status
}

df = pd.DataFrame(data)

cert_ativos = df['status'] <= '1 days'
cert_expirados = df['status'] >= '1 days'

def corrigir_nomes(nome): #Função para remover o CPF do campo "nome"
    nome = nome.replace('0', '').replace('1', '').replace('2', '').replace('3', '').replace('4','').replace('5','').replace('6','').replace('7','').replace('8', '').replace('9', '').replace(':','')
    return nome
def true_false(data): #Função para transformar True/False em Expirado/Ativo
    data = data.replace('True', 'Expirado').replace('False', 'Ativo')
    return data
df['nome'] = df['nome'].apply(corrigir_nomes)
df['status'] = df['status'].apply(true_false)

Comment: Para os "down votes", como é minha primeira publicação, seria interessante um feedback para tentar entender o que estou fazendo de errado para que possa corrigir.
Answer: Depois de algumas tentativas, consegui resolver o problema forçando o formato durante a conversão com pd.to_datetime():
Anterior: valido_ate = pd.to_datetime(valido_ate)
Correto: valido_ate = pd.to_datetime(valido_ate, format='%d/%m/%Y')
Obs.: funcionou no meu caso pois o formato da data de onde estava buscando estas informações era dd/mm/aaaa, então ele "entendeu" que deveria manter esta estrutura para a conversão.
Obrigado!!!
Answer: Tive este mesmo problema hoje e a solução foi parecida com a sua.
No entanto, no meu caso eu estava usando format = '%d/%m/%y'.
Ao alterar para format = '%d/%m/%Y', o código funcionou corretamente.


using bootstrap to calculate t-test p-value and CI in r

Question: I have a data named best and i want to run bootstrap based on these hypothesis to get p-value and CI:
H0:mu<=1600 and H1:mu>1600
What I've tried is:
best <- c(1660, 1820, 1590,1440, 1730,1680,1750, 17201,900,1570,
             1700,1900,1800,1770,2010,1580,1620,1690)
ttest <- c(1:1000)
B      <- 1000
for(i in 1:B){
  boot.c <- sample(best, size=18, replace=T)
  ttest[i]  <- t.test(boot.c, mu = 1600)$statistic
}

p <-  (1 + sum(abs(ttest[i]) > abs(t.test(best,m=1600)$statistic))) / (1000+1)
p

Is it right? is that so, how can i get CI?
In question we got ̅=1,718.3 And =137.8 to do the t-test without r but when i do it like:
 t.test(best, mu = 1600)

Obtained CI and p-value from code above are so different from what I've calculated with hand. why?
Answer: You can run bootstrap using the boot package, and there are a few options for you to construct the confidence interval. First, the boot package can be used like this:
library(boot)
bo = boot(best,function(dat,ind)mean(dat[ind]),R=999)

We can calculate confidence interval like this:
boot.ci(bo)

BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 999 bootstrap replicates

CALL :
boot.ci(boot.out = bo)

Intervals :
Level      Normal              Basic
95%   ( 810, 4188 )   ( 718, 3478 )

Level     Percentile            BCa
95%   (1568, 4327 )   (1614, 6024 )
Calculations and Intervals on Original Scale
Some BCa intervals may be unstable
Warning message:
In boot.ci(bo) : bootstrap variances needed for studentized intervals

And the mighty p-value like (btw @BruceET is correct):
(sum(bo$t>1600)+1)/(999+1)
[1] 0.941

Surprising result, 95% of our bootstrapped means are more than 1600? let's check how you bootstrapped mean looks like:
hist(bo$t,br=100,main="Histogram of bootstrapped means",xlab="mean")

This looks quite strange, and it is definitely so because you have n=18 and the 8th observation is 17201, ~10x more then the rest. We can look at this:
plot(boot.array(bo)[,8],bo$t,
xlab = "No of times column 8 is used",ylab="bootstrapped mean")

This may not be the answer you are looking for, but be careful when you have distributions like this. Bootstrap doesn't solve the problem but it does show you have shaky the estimation of the mean can be. The truth is you don't know if you try to measure these "best" values again, will you get an outlier like 17200, so I would say it doesn't make sense try to calculate p-values and 95% ci.
Answer: There's not enough samples to perform the t approximation in the ttest, so by choosing bootstrap you can draw samples of your target statistics instead of approximate it with a t distribution.
Run boot.c = replicate(1000,mean(sample(best, size=18, replace=T))-1600) will get you the bootstrapped samples of your target statistics.
With the target statistics samples, you shouldn't do ttest on them, instead:
 P value:
sum(boot.c<0)/1000
95% confidence interval:
quantile(boot.c,c(0.025,0.975))
Comment: Code for P-value seems wrong. And I get about 95%.
 Can you explain?
Comment: Bootstrap is a _computational_ method, not an _information gathering_ method. You cannot acquire additional information by re-sampling from existing data..
Comment: Like this there would be so much difference between p-value and CI obtained by t-test and the ones obtained by bootstrap is it acceptable?
Comment: Of course, ttest requires enough samples to approximate the distribution of the target statistics with a t distribution, when there's not enough samples, the t approximation will be bad, thus generate very different result.
Comment: The t-test comes with a number of assumptions about the data, bootstrapping comes with different assumptions. If both had consistently the same results, there wouldn't be much point in learning both. You need to see, whether you tend to believe, that your data comes from a process that involves normality or whether you tend to believe, that your 18 observations describe the possible data close enough to draw conclusions from only them.
Comment: @BruceET Thanks for pointing out, If H0 is `mu>1600`, then the p value should be calculated by `boot.c<0`, but in @lighting 's question H0 is `mu<1600`, thay's why I use `boot.c>0` to calculate the p value. I modified the anser to `boot.c<0` anyway because the H0 in the original question seems not right.
Comment: So, when we compute t-test with given ̅=1,718.3 And =137.8, there would be a p-value and when we do it with bootstrap there is another value, the first one is based on enough samples while the second one is based on more samples with bootstrap? is that right?


Checking $( \binom{n}{k} - \binom{n-k}{k}) / \binom{n}{k} < \frac{k^2}{n}$

Question: Let $n$ and $k$ be integers with $2\leq k \leq n$. I want to check the inequality
$$\left( \binom{n}{k} - \binom{n-k}{k} \right) / \binom{n}{k} < \frac{k^2}{n}$$
which occurs in a paper I am currently reading. For fixed $k$ and $n\to \infty$ one should get asymptotic equality. There should be a "elementary" proof. Here is my question:
Why does this inequality hold?
Direct calculation didn't succeed so far. It might be useful to observe that the inequality is equivalent to
$$ 1- \binom{n-k}{k}/\binom{n}{k} < \frac{k^2}{n} .$$
The asymptotic equality will probably follow directly from the proof.
Comment: To check, why the focus on the asymptotic equality? Aren't you mainly concerned with proving it for fixed integers?
Comment: @CalvinLin The paper uses the asymtotic equality, that's why I'm also interested in that. Nevertheless, the main focus of the question is on the inequality. I think that the asymptotic behaviour will be a direct conclusion from the proof.
Comment: The asymptotic inequality is pretty obvious directly, because ${ n-k \choose k } / { n \choose k } =  [ (n-k)! ( n-k)! ] / [ n! (n-2k)! ]  = \prod_{i=0}^k (n-k -i) / ( n-i) \rightarrow 1^k = 1. \quad $ (Uncertain) In fact, the desired inequality might also follow from this.
Answer: Let $S$ be a set chosen uniformly at random from all size $k$ subsets of $[n]=\{1,2,\dots n\}$.   The probability that $S$ is also a subset of $\{1,2,\dots,n-k\}$ is $\frac{\binom{n-k}{k}}{\binom{n}{k}}$.  So the left side of your inequality corresponds to the probability that $S$ contains at least one number larger than $n-k$.  Call this event $A$.
We can think of $S$ as $\{x_1, x_2, \dots, x_k\}$, where the $x_i$ are $k$ elements successively drawn randomly without replacement from $[n]$.  Note that each $x_i$ is uniform on $[n]$ (this is clear for $x_1$, and by symmetry $x_j$ and $x_1$ have the same distribution for $j>1$) , but the $x_i$ are not independent due to the constraints that they are all unequal.
For $1 \leq j \leq k$, let $A_j$ be the event that $x_j$ is the first of the $x_i$ which is larger than $n-k$.  In other words, $A_j$ is the event that all of $x_1, x_2, \dots, x_{j-1}$ are at most $n-k$, but $x_{j}>n-k$.  This event is disjoint, and their union is $A$.  It follows that
$$P(A) = \sum_{j=1}^k P(A_j)$$
But $P(A_1)=\frac{k}{n}$, and for $j > 1$ we have
$$P(A_j) < P(x_j>n-k) = \frac{k}{n}$$
So this last sum is strictly less than $\frac{k^2}{n}$.
Comment: A very nice proof. Calvin Lins answer makes me hope that there is also a "pure" combinatorical proof. I will formally accept your answer as soon as this proof has reached me. By now of course +1
Comment: @exiting_math Being uniform, all this is purely combinatorial. (+1)
Answer: (Not quite as sharp as you asked for, but good enough for your purposes.)
For $ n < 2k$,  the LHS is 1 and the RHS is $ >1$, so done.
Henceforth, assume that $ n \geq 2k$ (so we don't divide by 0).
Show that  (Fill in the gaps. If you're stuck, explain what you've tried.)
1.
$$ \frac{ n \choose k } { n - k \choose k } = \frac{ (n-k)! (n-k)! } { n! (n-2k)! } = \prod_{i=0}^{k-1} \frac{ n-k-i } { n-i }.$$
2.
$$\prod_{i=0}^{k-1} \frac{ n-k-i } { n-i } = \prod ( 1 - \frac{k}{n-i}) \geq 1 - \sum_{i=0}^{k-1} \frac{k}{n-i} \geq  1 - \frac{k^2} { n-k+1}.$$
3.
$$\left( \binom{n}{k} - \binom{n-k}{k} \right) / \binom{n}{k} \leq \frac{k^2}{n-k + 1}$$
Comment: Could you explain the first inequality $\prod_{i=1}^{k-1} (1-k/(n-i) \geq 1- \sum_{i=0}^{k-1} k/(n-1)$? It seems obvious but I cant find a convincing argument. I know that $ 0 < k/(n-i) <1$.  It reminds me of $(1-q)^k$ with $0<q<1$.
Comment: Just for the notification.
Comment: @exiting_math It's a standard inequality involving products: $ \prod (1 - a_i )  = 1 - \sum a_i + \sum a_i a_j \ldots \geq  1 - \sum a_i $, where $0 < a_i < 1 $.
Comment: Thanks for the reminder! A nice way to see this inequality are elementary symmetric polynomials. (https://en.wikipedia.org/wiki/Elementary_symmetric_polynomial)


ActiveRecord: query not using correct type condition for STI subclass

Question: I have a set of STI subclasses inheriting from a User base class. I am finding that under certain conditions inside a subclass' definition, queries on the subclasses do not correctly use the type condition.
class User < ActiveRecord::Base
  # ...
end

class Admin < User
  Rails.logger.info "#{name}: #{all.to_sql}"
  # ...
end

When loading the Rails console in development, it does what I would expect:
Admin: SELECT `users`.* FROM `users` WHERE `users`.`type` IN ('Admin')

But when hitting the app (localhost / pow), it is missing the type condition and I get this:
Admin: SELECT `users`.* FROM `users`

But not from the app when when deployed to a staging server:
Admin: SELECT `users`.* FROM `users` WHERE `users`.`type` IN ('Admin')

This, of course, causes any queries executed here in the dev app (but not from the console) to be incorrect. Specifically, I am trying to preload a (small) cache of existing db values in order to create a few helpful methods based on those data. Without the type scope, the cache is obviously incorrect!
From the same location (Admin), we get the following confusing contradiction:
[11] pry(Admin)> Admin.finder_needs_type_condition?
=> true
[12] pry(Admin)> Admin.send(:type_condition).to_sql
=> "`users`.`type` IN ('Admin')"
[13] pry(Admin)> Admin.all.to_sql
=> "SELECT `users`.* FROM `users`"

Further, I defined a throwaway subclass Q < User inside the user.rb file. I logged Q.all.to_sql from its definition, from the definition of Admin, and from a view. In that order, we get:
From Q: Q: SELECT `users`.* FROM `users` WHERE `users`.`type` IN ('Q')
From Admin: Q: SELECT `users`.* FROM `users`
From View: Q: SELECT `users`.* FROM `users` WHERE `users`.`type` IN ('Q')

What could cause, in the first line of the Admin subclass definition in admin.rb, any subclass of User to fail to use its type_condition?
This is causing development tests to fail, and so is of some consequence to my app. What on earth could be causing this difference in behavior? Can anyone think of a more general way around the problem of not having the STI conditions defined on a subclass during its definition only in the development app environment?
Answer: One difference between production and development is the following line inside of the application configuration:
# config/environments/development.rb
config.eager_load = false

vs.
# config/environments/production.rb
config.eager_load = true

So on your production environment, all your clases are loaded when the app is started.
When eager_load is set to false, Rails will try to autoload your User class when you first load the Admin class.
Given that, I'd assume that you have another class or module named User.
FYI: ActiveRecord has a method called finder_needs_type_condition?. It should return true for a class that uses STI:
User.finder_needs_type_condition? # should be false
Admin.finder_needs_type_condition? # should be true

Comment: @andrew, just found a page that explains autoloading with STI: http://guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoloading-and-sti . It suggests to explicitely `require` subclasses...
Comment: Thanks for the tips. I get the eager load difference, but it's still mysterious why the issue is *not* present in the dev console but *is* present in the dev app (when I use localhost / pow). The `finder_needs_type_condition?` method is good to know about: yet, it returns `true` when I pry from the app while still giving me `"SELECT `users`.* FROM `users`"` as in the question. Relatedly, I found the private method `type_condition`, which, when calling `to_sql` on, yields ``"`users`.`type` IN ('Admin')"``. So something is clearly broke.
Comment: Related, I was **not** able to replicate this behavior on another STI subclass of a completely different base class, so this seems to have something to do with the `User` class specifically. Progress...
Comment: One more update: I've commented *everything* in my `User` base class out other than the class declaration itself, and the issue persists. So I can't see what could be special about this class now, or how whatever is causing this issue goes away after the class definition is finished.
Comment: Ok so thanks to your pointers I think I at least have a workaround now: when loading the data, use `self.finder_needs_type_condition? ? self.where(type_condition) : self.all`. Ugly, not sure why it's necessary, and leads to a superfluous `WHERE` for other STI classes that don't have this issue. So pretty undesirable to actually use this code in a gem. But I'm not sure what a better solution may be at this point.
Comment: Thanks @andiba! It's 100% not clear to me why, but that does fix the issue. That is recommended to allow the base class (`User`) to be aware of its subclasses (`Admin`), but how does requiring the `admin.rb` file from `user.rb` fix an error that is occurring inside `admin.rb` itself? Very puzzling. Since I'm doing this from a gem, too, the best I can do is put it in the docs that you should do this if you're using the gem from a STI subclass. In any case, this is an effective solution, it would seem -- though I would love to know *why* it's an effective solution!!
Answer: Currently, any User will have an empty :type column. Could this is be a problem?
Have you tried to make User a super class? E.g.
class User < ActiveRecord::Base
end

class Admin < User; end
class NormalUser < User; end

Comment: Correct me if Im misunderstanding something, I've never used `abstract_class` in Ruby / Rails. Reading the docs, I see that `abstract_class` should be set to `true` if I do *not* want the subclasses to use the same table name. But I do, so I'm not sure this is correct for my use case. When I try it, I get what you might then expect: `ActiveRecord::StatementInvalid: Mysql2::Error: Table 'threeplay_development.admins' doesn't exist`. What did you mean by any `User` will have an empty `type` column? The `users` table is populated correctly, I just need to load that data when the app starts.
Comment: Upps, you're right with the `abstract_class`: That was nonsense. However, the **empty** `:type` column problem. When you do a `User.create( {attributes....})` without specifying `:type` it gets a `nil` value. The same with `Admin.create(...)` sets automatically `type = 'Admin'`.
Comment: Yep, thanks for the response. The data already exists and has the `type` column populated (current 13k total `User`s, among them 23 `Admin`s). Here I'm just reading from the table using `Admin.all` (or `self.all` inside the `Admin` class' definition), and it is not generating an appropriate `WHERE` clause under the specific condition outlined above.


What does this macro define?

Question: I read this piece of macro(C code) and was confused in decoding it to know what it defines. What does it define?
#define sram (*((unsigned char (*)[1]) 0))

-AD
Comment: Hard to tell. Can you provide an example of how it's used?
Answer: I think sram means "start of RAM".

unsigned char[1]

An array of size 1 of unsigned chars.
unsigned char(*)[1]

A pointer to an array of size 1 of unsigned chars.
(unsigned char (*)[1]) 0

Cast 0 to a pointer to an array of size 1 of unsigned chars.
*((unsigned char (*)[1]) 0)

Read some memory at location 0, and interpret the result as an array of size 1 of unsigned chars.
(*((unsigned char (*)[1]) 0))

Just to avoid 1+5*8+1==42.
#define sram (*((unsigned char (*)[1]) 0))

Define the variable sram to the memory starting at location 0, and interpret the result as an array of size 1 of unsigned chars.
Comment: +1 for providing me with an explanation to that conundrum in the Hitchhiker's Guide five-part trilogy. Oh, and I guess the rest of your answer was okay too.
Comment: Or on an embedded system it could just mean "SRAM" (Static Random Access Memory) which is typically what a microcontroller's on-chip RAM is made of.
Answer: I think it's returning the base address (0) of memory (RAM) :)
Answer: It defines "sram" as a pointer to memory starting at zero. You can access memory via the pointer, e.g. sram[0] is address zero, sram[1] is the stuff at address one, etc.
Specifically it is casting 0 to be a pointer to an array of unsigned char and going indirect through that (leaving an array of unsigned char).
A similar result can be obtained by
#define sram ((unsigned char*)0)

It is also completely undefined in standard C, but that doesn't stop people from using it and having angels fly out of their navels.

What does this macro define?


How to prove revised Fatou's Lemma?

Question: It is the problem from Durret Exercise 3.24
Let $g\geq 0$ be continuous. If $X_n \Rightarrow X_{\infty}$ (convergent in distribution), then $\liminf E(g(X_n))\geq E(g(X_\infty))$
Suppose we have know the  theorm:
1. Fatou's lemma: If $f_n \geq 0$, then
$\liminf \int f_n \, d\mu \geq \int \liminf f_n \, d\mu$
Solution:
$X_n \Rightarrow X_{\infty}$, $\exists Y_n \stackrel d= X_n$, $ Y \stackrel d= X_{\infty}$ s.t, $Y_n \stackrel{a.s}{\longrightarrow} Y$
Thus we have $g(Y_n) \stackrel{a.s}{\longrightarrow} g(Y)$ with $g()\geq 0$
Thus according to Fatou's lemma,
$\liminf E(g(Y_n))\geq E(g(Y))$
My question:
How to prove $\liminf E(g(X_n))\geq E(g(X_\infty))$
Answer: Hint: If $X \stackrel d= Y$ and $g$ is continuous, then $$E[g(X)] = E[g(Y)]$$ provided at least one side makes sense (i.e. at least one of $E[g(X)^+]$ or $E[g(X)^-]$ is finite)
In your case, $g \geq 0$ implies $g(X)^- = 0$ for any random variable $X,$ so...

How to prove revised Fatou's Lemma?


Windows Phone Application settings

Question: It seems Application Settings on Windows Phone are not secure and encrypted. I used isolated storage tool to pull all app files and folder fro mthe device and AppSettings file seems to be plain XML.
What about app linq databases? .sdf file seems to be encrypted.
I need to store very sensitive data that needs to be accessed both from the app and from background agent which is running in a separate process. They both seem to access application settings but since the storage is not secure I really cannot use app settings.
Answer: You can use the ProtectedData class to encrypt your sensitive data, then store it in the application settings or directly in the isolated storage.
For instance:

// Encrypting
var encryptedData = ProtectedData.Protect(Encoding.UTF8.GetBytes("Hello world!"), null);

// Decrypting
var sensitiveData = Encoding.UTF8.GetString(ProtectedData.UnProtect(encryptedData, null));

Windows Phone Application settings


How to get or calculate lat and long inside a rectangle drawn on Google Maps?

Question: I have a zip codes table which has lat and long columns. I draw a rectangle shape on Google Maps. I want to know how to query the table while having top left, top right, bottom left and bottom right coordinates (so I can find all the rows contained within that shape's bounds).
Thank you!
Comment: what problem are you facing? have you tried `bottom_latitude < your_latitude < top_latitude` and the same for longitude using left and right, for the whole column?
Answer: If you know your map bounds (as you said), then you can figure out a min/max latitude and longitude.
Assuming you are using MySQL or alike you could query your DB like:
SELECT * from YOUR_TABLE where (lat > min_lat and lat < max_lat and lng > min_lng and lng < max_lng)
This is simplified syntax. Adapt it to the language you are using.


Linux distributions recommendations for servers

Question: I have limited Linux server experience. I am looking for recommendations on distributions. What's your favorite for servers and why?
EDIT: Clarification: I'm hoping for one, general purpose distribution, not specific to a particular function. Something for use on file servers, web servers, anything really. Community support, timely patching, administration friendly tools, good track record, etc. are more the angle I'm going for here.
Comment: What are you going to be using it for?
Comment: Sorry I could have been clearer. I'm hoping for one, general purpose distro--file servers, web servers, anything really. Community support, timely patching, admin friendly tools, etc. are more the angle I'm going for here.

I'll clarify the question.
Answer: Debian or Ubuntu (server) due to dist-upgrade.  Any distro can be installed from scratch - but how many can be upgraded in place?  I've got a debian machine that hasn't been reinstalled from scratch since approximately 1995.
There are good communities around both, and also good documentation on making your own packages so you can make the package system work for you personally.  It's Very Cool to be able to easily roll a custom package to deploy to your internal machines.
Getting the most up-to-date versions of software can be a challenge, but backports have filled that gap pretty well.
Comment: I have been using Debian on about 30 servers for the past 5 years and found it very good, stable and secure - except if you need really up-to-date stuff - for instance, if you are hosting Ruby on Rails websites you won't find the most recent versions in the repos.
Ubuntu is great, if you're prepared to upgrade every 6 months - or stick to the LTS versions.
Debian and Ubuntu are similar enough that you use both, without much of a learning curve.
Comment: @Brett Nesbitt: Agree 100%, but I have a minor nitpick: it's arguably much better from a stability point of view *not* to use the latest and greatest on a server.
Comment: @Mihai Limbason: Sadly Debian's release schedule has historically been so slow that their packaged software can be *years* out of date, which is okay for some software but doesn't really suffice for fast-moving targets like python, ruby, django, svn, etc.
Comment: with using Ubuntu, just make sure to stick with the LTS releases
Answer: Red Hat Enterpise Linux or CentOS.  They are stable, you can buy support for them if you care to, and every major release has a guaranteed 5 year support cycle, which is invaluable (don't even get me started on the Fedora server a semi-rogue administrator installed here that we now can't upgrade).
Also, it tends to be the supported solution when installing commercial software on Linux (Oracle comes to mind, but we have other commercial products that state they'll install on anything, but they will only guarantee interoperability with Red Hat/CentOS).
Comment: Another flavor of this, similar to CentOS is Scientific Linux.  It is rebranded RHEL just like CentOS but supported by the national labs and large universities.  That's the distro I'm using for my sites
Comment: The support cycle is *7* years of RHEL releases for security updates.
Comment: When looking for a linux distro, look at the community first. What is their focus? In the case of RHEL, Debian, CentOS, SLES, and Scientific Linux, they focus on creating stable, well maintained platforms. Some people will swear up and down that the best Linux for job X "Is whatever you feel comfortable with." This avoids the question, and is more confusing than helpful to someone who doesn't feel comfortable with ANY of them.
Answer: Ubuntu
Reason: The community - there is a big community and if you need to do something, you can nearly always find someone that has done it first and posted a great set of instructions.
Comment: I started out with Red Hat and then Fedora, but after trying Ubuntu I can't go back.  I have an Ubuntu server running in a VM on my windows server,  I run Ubuntu desktop in a vm on my Vista desktop, and I dual boot my Mac mini to Ubuntu.  I've been installing the desktop version and then installing server stuff as needed even on my server.  I did it the other way once the first time and I just find it easier to start with the desktop version.  Compatibility with my various hardware has been good and updates and upgrades have gone smoothly.
Answer: I run all my servers at work on Gentoo. While a lot of fellow Linux sysadmins will consider me crazy, I must say I've had little to no troubles.
One server run as a build host for the others (they're all the same hardware) and serves the binaries to the others.
I like Gentoo a lot because it gives you loads of control about what is installed and what is not installed.
Community is great, the forums are the best online. If you stay on the stable branch, it's smooth sailing.
Currently I've been leaning a bit more towards Arch Linux because of the lack of compiling, but I haven't installed a server with it yet.
Source based/meta distros can make great servers!
Comment: Gentoo also has hardened profile (http://www.gentoo.org/proj/en/hardened/) for even higher security
Answer: Debian is my server's distribution of choice : it's very stable, available for almost all server platforms and security is a keypoint on that distro !
Answer: I recommend Ubuntu server (LTS preferable for production) as it is the only free of charge Enterprise class linux server distribution.
Comment: Huh? Are you claiming that CentOS is not a zero-cost Enterprise class server distribution?
Comment: No. It is build by community and never ever any big enterprise will support its software on CentOS.
Answer: Slackware

Since its first beta release in April of 1993, the Slackware Linux Project has aimed at producing the most "UNIX-like" Linux distribution out there. Slackware complies with the published Linux standards, such as the Linux File System Standard. We have always considered simplicity and stability paramount, and as a result Slackware has become one of the most popular, stable, and friendly distributions available.

I learned a lot working with this distro, but you will need plenty of time and patience. Slackware is user-friendly, it's just very selective about who its friends are.
Comment: You got that right :-)
Comment: The nice part about Slack is how simple it is. I love using it for servers that will do one task (firewall, apache, dns, etc) because the entire thing can fit easily into 400MB and uptime is clocked in years. When you do this, security updates are few because you don't have things like libPNG (just an example) that nothing on the server uses, but has a security bug that needs to be patched.  That said, Slack does no hand holding so you will know what you are doing to administrate it. So if anyone else is going to work on the box, then I go Ubuntu Server LTS.
Comment: Slackware is interesting to learn stuff on, and I've fond memories of using it as one of my first linux distros, but a system good for learning stuff is just that -- not a general purpose tool.  For general use, I think ubuntu is probably the way to go.  It's hard to beat have good, well maintained and integrated packages for every purpose available at the touch of a button, and being able to upgrade/remove/reconfigure the entire server at any time.
Comment: YMMV, but I found Slackware to be rock-solid and as good as any other alternatives (paid or free). As a bonus, it forces you to learn some extra things along the way.
Answer: Ubuntu if your server is for learning about Linux and servers, CentOS if it's for production. I find the Ubuntu community to be more active then CentOS which may be helpful if your just getting started. CentOS doesn't have a new release every six months which is nice for a server OS. It also uses older but more tested versions of software which is important with a server.
Answer: Debian for it's stability and popularity
Answer: Whatever you choose, if it will be exposed to the public internet, you want to ensure that it supports selinux.  This has saved my butt on at least one occasion where otherwise I surely would have gotten hacked due to a security flaw in software I had installed.  Not only did selinux totally block the attack, but via setroubleshoot it raised a pop-up window to warn me about it.
Answer: I use Arch Linux. I like it for great package manager, "rolling" release, nice community package repository (ABS), nice configuration, great wiki.
For me it is much like Gentoo, but with binary packages.
You can find comparison with other distro on: Arch vs Others.
Answer: I use either CentOS or Ubuntu LTS releases.  Both are stable, well-known and well-supported.
Answer: Personally, OpenSuSE for me.  Mainly because of YaST and autoYaST; great package management, upgrades/updates, etc.
Answer: I just voted up the "function" comment, as it asks a relevant question .. the primary function matters, to some extent.
The other key decision you have is whether you want access to professional support.  If the answer is yes, get Red Hat.  If the answer is no, then I would start with Ubuntu.
Additional note .. Gert's (implied) point about using the same distro for multiple servers is also a great one!
Comment: You can get professional support for Ubuntu from Canonical, but you can try ubuntu without paying anything.
Answer: I recommend using CentOS.

It's the Red Hat Enterprise Linux recompiled from the Red Hat's sources
You can upgrade the distro without a support contract
Red Hat is usually used with commercial software, so being exposed before will help in your journey
Once you pick Red Hat you can go to other distributions and know what's important
Lots of information on internet
Answer: I think there are two approaches:

Rolling distribution
Release distribution

ad.1
I personally prefer rolling distros, since there is no such thing as upgrade to a newer version (which either way might be risky). That's why I prefer Gentoo for my servers. Unfortunately setting up gentoo requires a bit more effort, yet thanks to portage system maintaince (if you use the stable branch) is really easy and painless. The very cool feature is slots and ability do downgrade to literally any old version of the package with one simple command. On the other hand gentoo packages, even in the stable branch tend to be much newer than Debian (see point 2) - if you need a machine with recent software gentoo is for you.
ad.2
Release distro - I'd choose Debian here, mainly for it's popularity around all the hosting companies and a huge packet base. Although I don't use it myself it seems to be the most reasonable distribution with a really high security level. Deployment is fast, no need to compile packages (unless you really need to).
Comment: Debian excels at both rolling and release upgrades, but you're right that some distros fail at one or the other, and so it's an important distinction.


Select from list of objects by object attribute value?

Question: I have a list of objects that are pulled in from an API. Here is the snippet of output (as there's about 300 lines):
combo =>
ID: 6, Name:Thomas Partey, Club:1, Position: 3, Price: $4.7, Total Pts: 57
ID: 7, Name:Martin Ødegaard, Club:1, Position: 3, Price: $7.0, Total Pts: 128
ID: 8, Name:Kieran Tierney, Club:1, Position: 2, Price: $4.6, Total Pts: 23
ID: 12, Name:Emile Smith Rowe, Club:1, Position: 3, Price: $5.6, Total Pts: 5

I would like to only show the combo where Total Pts = 57
So desired output is just:
ID: 6, Name:Thomas Partey, Club:1, Position: 3, Price: $4.7, Total Pts: 57

I've tried the following:
sorted = combo.select{ |item| item[:totalpoints] == 57 }
puts sorted

and
sorted = combo.select(&:totalpoints) == 57

Full code is here if needed:
class Player
attr_accessor :id, :firstname, :secondname, :club, :position, :price, :totalpoints,
:active
def initialize(id, firstname, secondname, club, position, price, totalpoints, active)
@id = id.to_i
@firstname = firstname.to_s
@secondname = secondname.to_s
@club = club.to_s
@position = position.to_i
@price = price / 10.to_f
@totalpoints = totalpoints.to_i
@active = active.to_i
end

def to_s()
 "  ID: " + @id.to_s + ", Name:" + @firstname.to_s + " " + @secondname.to_s + ", Club:"
 +
 @club.to_s + ", Position: " + @position.to_s + ", Price: $" + @price.to_s + ", Total Pts:
 " + @totalpoints.to_s + "    "
end

def self.pull()
require 'net/http'
require 'json'
url = 'https://fantasy.premierleague.com/api/bootstrap-static/'
uri = URI(url)
response = Net::HTTP.get(uri)
object = JSON.parse(response)
elements = object["elements"]
elements.map! { |qb|
    if  qb["chance_of_playing_next_round"].to_f > 0
        Player.new(
            qb["id"],                               # ID
            qb["first_name"],                       # First Name
            qb["second_name"],                      # Surname
            qb["team"],                             # Club
            qb["element_type"],                     # Position
            qb["now_cost"],                         # Current Price
            qb["total_points"],                     # Total Points
            qb["chance_of_playing_next_round"])     # Chance Of Playing
    end
   }
  end

  combo = Player.pull().map{|qb| qb}

Comment: It appears that your input is a file and you have shown an image of part of it (`"combo =>"` on one line, `"ID: 6, Name:Thomas Partey,..., Total Pts: 57"` on the next line, and so on. Is that correct? If not, is `combo` a variable holding an array of hashes, constructed from the file contents? If so, you could simplify your question a lot by making `combo` the starting point, making no reference to the file from which it came.
Answer: Looking at the data from your example you'll need to invoke the totalpoints method on each element in combo and then compare it with what you want;
combo.compact.select { |element| element.totalpoints == 57  }

The compact use is to remove the elements that are nil otherwise you'll get an exception when invoking a method that hasn't been defined on a Nil object (that's the easiest way I could think of, there might be others).
Notice this won't work as expected;
combo.select(&:totalpoints) == 57

because select will be yielding true for every element with a "truthy" value when the method totalpoints is invoked on it. And that result will then be compared to 57 which will never work as intended because the given result might be an array or a hash.


Azure Function - Get service bus connection string from Azure key vault

Question: I have an Azure function that run in a docker container. This function needs to use an Azure service bus. So my function is using the attribute "ServiceBusAccount" to get the service bus connection string
    [FunctionName("MyFunc")]
    [ServiceBusAccount("ServiceBusConnectionString")]
    public async Task MyFunc(...)
    ...

In the configuration builder I run the following code to get the some values from the Azure Key Vault (including the Service bus connection string):
     var configBuilder = new ConfigurationBuilder();

     var config = configBuilder.AddAzureKeyVault($"https://{config["keyVaultName"]}.vault.azure.net", config["keyVaultClientId"], config["keyVaultSecret"])
                .Build();

The problem is that while the host is starting up I got first the warning:

"Warning: Cannot find value named 'ServiceBusConnectionString'"

and then after my function is discovered I got this error:

A host error has occurred. Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus connection string 'ServiceBusConnectionString' is missing or empty

My understanding is that the host environment is trying to get the service bus connection string before even starting up the function and before the configuration builder is invoked in the startup class of the project.
Is there any way to set the service bus connection string at runtime?
EDIT
If you are using Azure DevOps this should help to solve this problem https://daniel-krzyczkowski.github.io/How-to-inject-Azure-Key-Vault-secrets-in-the-Azure-DevOps-CICD-pipelines/
Comment: You are using servicebus trigger function or in an other kind trigger function using servicebus?
Comment: I'm using the servicebus trigger function. If I put the service bus connection string in my local.settings.json everything is fine. When I remove it from there and pull the connection string from Azure Key Vault at runtime I get the error I mentioned above.
Answer: You could set @Microsoft.KeyVault(SecretUri=Secret URI with version) in Application Setting in Function.
1.Turn on Identity of your Azure function.
2.Go to the Access Control section of your Key Vault and click on Add a role assignment blade, assign a role to your function's service principal.
3.Go to your Key Vault and click on Access Policies and then click on Add policy to your function's service principal with key or secret permission.
4.Use the Key Vault Secret in Azure Function.
For more details, you could refer to this article.
Comment: My functions are running in a container. They are not on the Azure portal. Therefore I guess your solution is not viable
Comment: @AlessandroLallo were you able to find a viable solution for this? I am running into the same issue.
Comment: @tubakaya if you are using Azure DevOps this should help https://daniel-krzyczkowski.github.io/How-to-inject-Azure-Key-Vault-secrets-in-the-Azure-DevOps-CICD-pipelines/
Comment: @AlessandroLallo thanks for your reply. I already have an implementation that can replace the appsettings during build. I am looking for a way to not have the setting in appsettings at all and instead instruct the service bus connection string during startup, as your question suggests.


Characterizing and comparing the heterogeneity of ordinal responses from survey

Question: Let us consider the following setting:

We have two groups Q1 and Q2 of questions
Several participants answer all questions using a single ordinal scale A, B, C or D for all questions.

Then, I want to test whether answers from questions coming from group Q1 are more heterogeneous than those from questions from group Q2.
What are the available statistics to quantify "heterogeneity"/"homogeneity" on such an ordinal scale ?
Comment: Outrageous though it may seem to some readers, scoring A as 1 to D as 4, or vice versa, and calculating the SD of scores might work as well as any other method. A problem with diversity measures such as $\sum_j p_j^2$, or its complement, or its reciprocal, or entropy $\sum_j p_j \ln(1 / p_j)$, or its exponential, is that they ignore order.
Comment: ps : Maybe, I have not the good keyword (and "heterogeneity"/"homogeneity" in statistics is used in so many context that it blurs my web-searching line) but I did not manage to find the appropriate literature by my own as for now
Comment: You could construct a confidence interval for the ratio of variances using a two- sample bootrap.
Comment: This sounds like [tag:diversity]. You can peruse that tag, and maybe add it
Answer: Nice question.  The simple "% choosing the most commonly chosen option" should be considered. You could compare the literature on straightlining.
Following @BigBendRegion and Nick Cox's helpful comments you would treat a set of responses of all As and Ds (exemplifying the "extreme" response style) as more variable than a set with equal numbers for all 4 choices. Will this be tenable? You will want to think through how you can best define variability before committing to ways of calculating it. You probably will want to employ and report the results of multiple methods.


Customizing Drupal 6 MP3 Player

Question: I'm going to use MP3 Player module to play some audio files on drupal 6. as you know it uses Wordpress MP3 Player as standalone player and it only has one skin, so how can I obtain more skins or maybe a flash API explaining how to build one?
Comment: I've had great success with http://drupal.org/project/jplayer and you can skin it up all you want if you know php/html/css
Comment: yep, it will use flash for old browsers, html audio for new ones, and its html/css is pretty stock as well.  of course it "likes" html5 more :)
Comment: Thanks Jimajamma, If it can be skinned with html/css then it's really great but what about old browsers that doesn't support HTML5, can they display it?
Comment: Really Thanks, I installed jplayer and it seems not working or maybe I'm missing something: http://s10.postimage.org/9pj5rlcah/jplayer.jpg
Comment: it took a bit of fiddling to work here, so not sure what could be missing or out of whack form that image.  you do have to manually download the actual library from jplayer or happyworm in addition to the module itself (or at least you did back when I installed it)
Answer: I have never used that particular module, but I used to use the standalone version of the WordPress Audio Player a lot.  The player isn't really skinnable in the same way you can skin other Flash components.  There are some JS properties that you can set to change colors and dimenstions.
The documentation for the module claims

Player can be styled and changed through Drupal admin interface.

so you should visit the settings page to see what you can do.
That said, there are other options you can explore

jPlayer
Flowplayer
MediaElement (Drupal 7 only, though)
Comment: Really Thanks MPD, I actually need to create a custom player. I wish there was a source (.fla) of standalone player so I could build  my own one.

Customizing Drupal 6 MP3 Player


AVAudioPlayer not playing audio correctly the first time

Question: I am working on a project that has to play audio that the user recorded themselves. When the app is launched for the first time and the user records a bit of audio, when trying to play it back, the AVAudioPlayer seems to play but is immediately stopped. If the user try to record another bit of audio, the AVAudioPlayer works fine.
Code for playing and stopping audio:
@objc func playAudio() {
    if audioPlayer == nil {
        do{
            if FileManager.default.fileExists(atPath: filename.path) {
                print("File Exists")
            }
            else {
                print("File Doesnt Exists")
            }

            try audioPlayer = AVAudioPlayer(contentsOf: filename)
            audioPlayer.delegate = self
            audioPlayer.prepareToPlay()
            audioPlayer.play()
            print(audioPlayer.isPlaying)
            print("Playing Audio")
            playStopButton.setImage(#imageLiteral(resourceName: "Stop Button"), for: .normal)
        }catch {
            //displayAlert(title: "Oops!", message: "There was an error. Try Recording Again")
            print(error)
        }
    }
    else {
        playStopButton.setImage(#imageLiteral(resourceName: "Play Button"), for: .normal)
        audioPlayer.stop()
        audioPlayer = nil
    }
}

func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
    if flag {
        print("Stopping Cuase Comlete")
        playStopButton.setImage(#imageLiteral(resourceName: "Play Button"), for: .normal)
        audioPlayer.stop()
        audioPlayer = nil
    }
}

Code For Recording Audio
@objc func record() {

    if audioRecorder == nil{

        let settings = [AVFormatIDKey: Int(kAudioFormatMPEG4AAC), AVSampleRateKey: 12000, AVNumberOfChannelsKey:1, AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue]

        do{
            audioRecorder = try AVAudioRecorder(url: filename, settings: settings)
            audioRecorder.delegate = self
            audioRecorder.record()
            //view.backgroundColor = UIColor.red
            //recordButton.setTitle("Stop Recording", for: .normal)
            setupTimer()
            timerDisplay.isHidden = false
            shapeLayer.fillColor = UIColor.black.cgColor

        }catch{
            displayAlert(title: "Oops!", message: "Recording Failed")
        }
    }
    else{
        audioRecorder.stop()
        timer?.invalidate()
        timer = nil
        shapeLayer.strokeEnd = 0
        audioRecorder=nil;

        timerDisplay.isHidden = true
        shapeLayer.fillColor = UIColor.red.cgColor
        let selected = arr[picker.selectedRow(inComponent: 0)]
        UserDefaults.standard.set(selected, forKey: "SelectedTopic")

        present(UINavigationController(rootViewController: PlaybackController()), animated: true, completion: nil)
    }
}

Comment: check path provided for first time is correct ?
Comment: @iOSGeek yes it returns true that the file exists every time
Comment: I do not see any mistake It can happen just because of filename if provided incorrectly , as second Time Its working fine , hard to catch error
Comment: @iOSGeek It can't be the file name the file name is the same each time
Comment: I am facing same issue, Have you find any solution?
Answer: getting same issue with audiorecorder.I fixed by making a method to setup a player. like this:
func setupView() {
        recordingSession = AVAudioSession.sharedInstance()

        do {
            try recordingSession.setCategory(.playAndRecord, mode: .default)
            try recordingSession.setActive(true)
            recordingSession.requestRecordPermission() { [unowned self] allowed in
                DispatchQueue.main.async {
                    if allowed {
                        self.loadRecordingUI()
                    } else {
                        // failed to record
                    }
                }
            }
        } catch {
            // failed to record
        }
    }

and then calling it in my viewDidLoad.as:
self.setupView()


How to cache an AVPlayerItem (Video) for reuse in a UITableview

Question: I have a number of videos that I am displaying in a UITableView. The videos are stored remotely on a server. I am able to load the videos into the tableview using some of the following code.
<code> NSString *urlString = [NSString stringWithFormat:[row objectForKey:@"video_uri"]];
 NSURL* url = [NSURL URLWithString:urlString];
 AVPlayerItem *pItem = [AVPlayerItem playerItemWithURL:url];
 AVPlayer *player = [AVPlayer playerWithPlayerItem:pItem];
</code>
Each time the tableview dequeues the cell then requeues again the video is loaded again from the url. I'm wondering if there is a way to download and cache or save the video so that it can be played from the phone without having to connect again. I was trying to draw opoin the technique used in the LazyTableImages example provided by Apple, but I'me a little stuck.
Comment: Did you ever figure out how to do this?
Answer: After messing around with this unsuccessfully trying to cache AVPlayerItems, I've come to theh conclusion that it works much better if you cache the AVPlayerItem's underlying AVAsset which is meant to be reused, whereas the AVPlayerItem itself is not meant to be reused.
Comment: Can you post sample code or describe the steps how to do cache using AVAsset?
Comment: The "AVPlayerItem is not meant to be reused" part of this answer helped me.
Answer: There's one method to do this, but it may be taxing on older devices subsequently cause your app to be jettisoned by MediaServerD.
Upon creation, save each player into an NSMutableArray. Each index in the array should correspond to the indexPath.row of UITableView.
Answer: Just worked on this problem with a friend yesterday.  The code we used basically uses the NSURLSession built-in caching system to save the video data. Here it is:
<code>    NSURLSession *session = [[KHURLSessionManager sharedInstance] session];
    NSURLRequest *req = [[NSURLRequest alloc] initWithURL:**YOUR_URL**];
    [[session dataTaskWithRequest:req completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

        // generate a temporary file URL

        NSString *filename = [[NSUUID UUID] UUIDString];

        NSURL *temporaryDirectoryURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
        NSURL *fileURL = [[temporaryDirectoryURL URLByAppendingPathComponent:filename] URLByAppendingPathExtension:@"mp4"];

        // save the NSData to that URL
        NSError *fileError;
        [data writeToURL:fileURL options:0 error:&fileError];

        // give player the video with that file URL
        AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:fileURL];
        AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
        _avMovieViewController.player = player;
        [_avMovieViewController.player play];

    }] resume];
</code>
Second, you will need to set the caching configuration for the NSURLSession.  My KHURLSessionManager takes care of this with the following code:
<code>    NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
    config.requestCachePolicy = NSURLRequestReturnCacheDataElseLoad;
    _session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:[NSOperationQueue mainQueue]];
</code>
Lastly, you should make sure your cache is large enough for the files,  I put the following in my AppDelegate.
<code>     [NSURLCache sharedURLCache].diskCapacity = 1000 * 1024 * 1024; // 1000 MB
</code>
Hope this helps.
Comment: this looks like good code. But do you really need an NSURLSession to save to the local disk? Why not just use an AVAssetExportSession?


Extract value of the node with contains only English names

Question: A sample XML file is:
<book category="lovestory">
    <title lang="en">Сумерки</title>
    <author>Stephanie Meyer</author>
   <year>2003</year>
   <price>50.07</price>
</book>

So far I have something like this XPath string:

xpath.compile("/book[/title='[a-zA-z0-9]+']/author");

How can I get all authors of the English books? (I mean that titles are latin npt cyrillic) (This is Russian)
Comment: John le Carré is English. You can't assume that if something contains letters outside the range a-z then it's not English.
Answer: Your XPath is almost correct.
Try to use following XPath:
//book//title[@lang='en']//..//author

Explanation:
You select all books which title is in english //book//title[@lang='en'] and take the author of this book //..//author.

If you cannot rely on the lang attribute you can use regex (as you tried in your example). Following XPath uses a regular expression. The matches function is required which is available in XPath 2.0:
//book//title[matches(text(), '[a-zA-z0-9]+')]//..//author

Single slash / means node which is a direct child of the current.
Double slash // means any descendant node of the current node in the html tree which matches the locator.
Comment: There is also an XPath 1.0 solution: `//book[not(translate(title,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',''))]`
Comment: Note that `[A-z]` matches more than `[a-zA-Z]` https://stackoverflow.com/questions/29771901/why-is-this-regex-allowing-a-caret


I am trying to get user email from firebase, But typescript giving this error in react

Question: I am trying to get user email from firebase the when the user will login. That's why I can't define user before. I used optional chaining but react typescript giving error
Comment: Has nothing to do with optional chaining, the property "email" does not exist on the user variable.
Answer: You need just add 'Email' to type of UserCredential
Comment: can you please tell me how can i do that?
Comment: if you will give information where and how get "user", sure.
Comment: thanks bro i just figured it out.


Div sem padding lef e right na visualização mobile

Question: Olá,
Sou um iniciante em bootstrap e me deparei com um problema de visualização de texto que não estou conseguindo resolver. A situação é a seguinte, conforme nas imagens anexadas, minha página possui um campo que exibe um texto dividido em 3 colunas na versão desktop (col-md-4) e quando a tela é diminuída, passa pra 1 coluna (col-sm-12, col-xs-12). Meu problema é, como vocês podem que a div não está deixando espaço na esquerda e na direita, como fica na versão com 3 colunas. Já tentei colocar um padding left e right de 5% para col-sm-12, mas essa alteração por algum motivo que desconheço também colocou esse padding na versão col-md-4, então desfiz as alterações. Não adicionei css aqui, porque estou usando o default do bootstrap. Alguém sabe como eu poderia colocar esse espaço na versão pequena, sem afetar a versão grande?versão grande
Answer: Tente:
<code>@media (min-width: 768px){
.row{
    padding-left: 15px;
    padding-right: 15px;
  }
}
</code>
Comment: Com o @media, você pode definir quando aplicar esse css. Neste caso em quando tamanho da tela for menor que 768px o css irá adicionar 15 px a esquerda e 15 px a direita da div(row) que envolve as colunas.


How to modify the position of a table

Question: I am able to place the table on the right, but it turns out the table could not display completely. I try to use ax, ax_table=plt.subplots() but it does not go well.
I try to use the "bbox" in the table but I don't quite understand the meaning after I search the Internet.
How do I modify the position of a table and place it on the upper right of the plot (outside the plot)?
import csv
x1=["2018-08-27 15:21:49","2018-08-27 15:21:52","2018-08-27 15:21:53","2018-08-27 15:21:56"]
y1=["5523","3512","6732","3383"]
L=[]
with open("test.csv") as f:
    reader=csv.reader(f)
    for row in reader:
        print(row)
        L.append(row)
    print(L)

fig,ax=plt.subplots()
plt.subplots_adjust(left=0.2, bottom=0.25)

col_lables=['tiestamp','loadingtime']
# row_lables=['row1','row2','row3']
table_val=L
row_colors=['red','gold','green']

##bbox=[left, bottom, width, height]
my_table=plt.table(cellText=table_val,colWidths=[0.3]*5,colLabels=col_lables,
                   colColours=row_colors,loc='right')

plt.title("Static Graph & Table")

x11=[datetime.strptime(d,"%Y-%m-%d %H:%M:%S") for d in x1]
y11=[float(i) for i in y1]

date_format=mdates.DateFormatter("%Y-%m-%d %H:%M:%S")
ax.xaxis.set_major_formatter(date_format)
ax.xaxis.set_major_locator(mdates.DayLocator())

plt.xlabel("Date")
plt.ylabel("Loading time")

plt.plot(x11,y11)
ax.yaxis.set_ticks(y11)
ax.xaxis.set_ticks(x11)

plt.gcf().autofmt_xdate()
# plt.grid()
plt.show()

Right now
Comment: Possible duplicate of [Matplotlib table falls outside plot area](https://stackoverflow.com/questions/27929348/matplotlib-table-falls-outside-plot-area)
Comment: I've seen many others duplicate on this, it's only one of the answers. Dig it up!
Comment: You have different option: use the bbox on the table to reposition it, use the bbox on the plot to make it smaller. You could also create 2 axes, with different size, place one for the plot, one for the table.
Comment: @Mathieu I tried the options you mentioned but with no luck. Is the parameter of bbox issue? I tried a few of bbox set up, and also tried to create 2 axes. If I create the 2 axes, the figure will go out of control...
Answer: Figured it out.
Posting the answer.
Hope it will help
I mixed up with the usage of the subplots. With using the subplots, it will generate a suplot automatically. If you want to add a table only , you need to use the line "ax2.axis('off')".  I also modified the font size with this.
fig,(ax1,ax2)=plt.subplots(1,2,figsize=(10,6))

col_lables=['tiestamp','loadingtime']
# row_lables=['row1','row2','row3']
table_val=L
row_colors=['red','gold','green']

ax2.axis('off')
##bbox=[left, bottom, width, height]
my_table=ax2.table(cellText=table_val,colWidths=[0.3]*4,colLabels=col_lables,
                   colColours=row_colors,loc='best', bbox=[0,0.5,1,0.3])
my_table.set_fontsize(24)
my_table.scale(2,2)

ax1.set_title("Static Graph & Table")

x11=[datetime.strptime(d,"%Y-%m-%d %H:%M:%S") for d in x1]
y11=[float(i) for i in y1]

date_format=mdates.DateFormatter("%Y-%m-%d %H:%M:%S")
ax1.xaxis.set_major_formatter(date_format)
ax1.xaxis.set_major_locator(mdates.DayLocator())

ax1.set_xlabel("Date")
ax1.set_ylabel("Loading time")

ax1.plot(x11,y11)

ax1.yaxis.set_ticks(y11)
ax1.xaxis.set_ticks(x11)

plt.gcf().autofmt_xdate()

# plt.grid()
plt.show()

How to modify the position of a table


Maven/IntelliJ fails to update Selenium Version to 2.53.0

Question: I am trying to update Selenium version from 2.47.1 to 2.53.0 in Maven project. I have updated the required version in pom.xml and expecting that dependencies are resolved automatically (Kept IntelliJ setting for Maven to automatically import dependencies). But I do not see new libraries updated in the project. All classes in the project are started failing as it is not able to find the library. See this image for more details.
enter image description here
When I try to add dependency from Maven, it is not showing me latest version 2.53.0. Please suggest.
Comment: Can you share your pom file ?
Answer: Try Purging your local repository and build again.
<code>mvn dependency:purge-local-repository -DactTransitively=false
</code>
Comment: Thanks Vijendra for this command to purge local repository. I used this and could remove most of the errors from the code. But still there is error for very common method..
wait.until(ExpectedConditions.VisibilityOfElement....
giving error that Maven can not resolve the method. I believe that somehow Maven is still referring some old & corrupted libs, which I need to clean up.
Answer: Thanks Vijendra for your answer. That resolved few errors in my code, but Selenium APIs were still referring to older Selenium Jar 2.47.1 I tried cleaning all local resources and pulled new libraries using Maven, but that did not resolve issue. Finally I deleted the entire local code and set up another code from 'Master' branch in git. Then updated the Selenium Version in pom.xml dependency tag and that pulled all new libraries.


Problem Assigning Static IP to CentOS Server

Question: We have a sandbox server running CentOS that we run inside our office.  Our ISP has assigned us a block of 5 static IPs.  We now want to assign it a static IP.
DEVICE=eth0
BOOTPROTO=none # have also tried "static" here
HWADDR=00:13:72:*:*:*
ONBOOT=yes
TYPE=Ethernet
NETMASK=255.255.255.0
IPADDR=173.*.*.161
GATEWAY=10.1.10.1

/etc/resolv.cnf is also set with the appropriate name servers from our ISP.
When I ifdown eth0 then ifup eth0 I get...
SIOCADDRT: Network is unreachable

When I switch to DCHP, the machine has an IP assigned and there are no connection problems.
Any ideas?
Answer: The IP Address and gateway are in 2 totally different networks. So change your gateway or IP address to an address within the same network.
NETMASK=255.255.255.0
IPADDR=173.*.*.161    <--
GATEWAY=10.1.10.1     <--

Comment: yep.  you are correct.  not sure how I missed that one.  thanks.
Answer: You gateway address and your ip address must be on the same subnet. When the machine gets a DHCP assigned IP, what is the default gateway that gets assigned? Try using that.
Answer: Personally, I'd pull down the networks and configure it manually so you can see what is what.
ifconfig the device manually (ifconfig eth0 126.96.36.199 up I think it was)
Try and ping a gateway, then add it manually route add default gw 188.8.131.52 once you figure out exactly what it was. Everything should fall through from there.
Note, you may need the netmask in your ifconfig command.
Answer: Further to PowerSp00n's answer regarding the wrong gateway (and you really do have 5 IP addresses) your subnet mask should be 255.255.255.248 (/29).
Comment: This isn't true, a block of IP addresses you get isn't the same as a subnet. An ISP can give you a few addresses out of an larger subnet.
Comment: he said "block of 5 IP addresses" -- the key term here is block, if it was a few IP addresses from different subnets (which is rare anyways) it wouldn't be called a block.
Comment: Like I said, a block of IP addresses isn't (always) the same as a subnet. A subnet is a block and a block can be a subnet. You can't assume he has a subnet and is using the wrong netmask.


Insert no MySQL não executa

Question: Estou tendo problemas no SQL ao fazer uma pequena inserção no DB.
Tenho uma tabela com 4 campos:
id_match -> int
id_usuario1 -> int
id_usuario2 -> int
situation -> varchar(5)

Quando faço a seguinte inserção, não entra no BD:
INSERT INTO match VALUES(NULL, '$usuario1', '$usuario2', 'open')

O que está errado?
Comment: qual erro que apresenta ?
Comment: @wryel Rodando na aplicação não apresenta erro nenhum, mas rodando no SQL do phpMyAdmin:
"#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'match VALUES (null, '5', '0', 'open')' at line 1"
Answer: O teu erro deve-se ao facto de match ser uma palavra reservada. Significa isto que, para que para seja utilizada como um identificador (nome de coluna ou tabela, por exemplo) ela precisa de um tratamento especial.
Pelo teu comentário vi que já conseguiste resolver o problema. Fica, no entanto, aqui a resposta para referência futura.
INSERT INTO `match` VALUES(NULL, '$usuario1', '$usuario2', 'open')

Para utilizar uma palavra reservada como nome de tabela, coluna ou indentificar um índice podes usar uma de duas soluções;

Utilizando acento grave "`", ou
Se o ANSI_QUOTES no SQL mode estiver activado podes usar aspas
(")
Comment: Valeu pela explicação @bruno.
Eu cheguei a procurar por palavras reservadas em linguagem sql no google, mas não encontrei nada referente a match.
Mas valeu muito pela dica.
Comment: Sem problema @GustavoSevero. A palavra match na minha resposta tem um link para uma lista das palavras reservadas no MySQL.
Answer: Faça assim que deve funcionar:
INSERT INTO match VALUES(NULL, 5, 0, 'open')

Você está tentando gravar strings um colunas do tipo int. Não é possível.
Com a edição parece que é um código PHP, então o correto seria algo assim:
INSERT INTO match VALUES(NULL, $usuario1, $usuario2, 'open')

Mas não posso garantir porque falta informação sobre o código PHP.
Finalmente existe um erro no nome da tabela. Pelo comentário adicionado abaixo ficou claro qual era o erro. O AP resolveu "escapando" o nome da tabela que é uma palavra reservado do SQL. Desta forma:
INSERT INTO `match` VALUES(NULL, $usuario1, $usuario2, 'open')

Coloquei no GitHub para referência futura.
Comment: Se estão em variáveis, a sua pergunta está errada. É possível fazer o que você quer mas tem que ver todo o contexto. Agora você está falando que é algo totalmente diferente do que está na pergunta. O certo era até remover esta pergunta mas ainda dá tempo de você arrumar ela e colocar tudo como efetivamente você está usando.
Comment: esses dados estão em variáveis... É possível fazer isso?
INSERT INTO match VALUES(NULL, $variavel1, $variavel2, '$variavel3')?
Comment: Olha o erro que apareceu no phpMyAdmin, @bigown:

"#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'match VALUES(NULL, 5, 0, 'open')' at line 1"
Comment: Veja se agora o comando está certo na pergunta @bigown
Comment: Olha! Fiz uma pequena alteração no script sql que funcionou, mas até agora não entendi como, pois NUNCA, NUNCA tive que fazer isso.
Tive que colocar " ` ", crase, antes e depois do nome da tabela:

INSERT INTO `match` VALUES(NULL, '$usuario1', '$usuario2', 'open')

Insert no MySQL não executa


How do I change my private key passphrase?

Question: I have an existing public/private key pair. The private key is password protected, and the encryption may be either RSA or DSA. These keys are the kind you generate with ssh-keygen and generally store under ~/.ssh.
I'd like to change the private key's password. How do I go about it, on a standard Unix shell?
Also, how do I simply remove the password? Just change it to empty?
Answer: To change the passphrase on your default key:
$ ssh-keygen -p

If you need to specify a key, pass the -f option:
$ ssh-keygen -p -f ~/.ssh/id_dsa

then provide your old and new passphrase (twice) at the prompts. (Use ~/.ssh/id_rsa if you have an RSA key.)
More details from man ssh-keygen:
[...]
SYNOPSIS
    ssh-keygen [-q] [-b bits] -t type [-N new_passphrase] [-C comment]
               [-f output_keyfile]
    ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
[...]
     -f filename
             Specifies the filename of the key file.
[...]
     -N new_passphrase
             Provides the new passphrase.

     -P passphrase
             Provides the (old) passphrase.

     -p      Requests changing the passphrase of a private key file instead of
             creating a new private key.  The program will prompt for the file
             containing the private key, for the old passphrase, and twice for
             the new passphrase.
[...]

Comment: Also, for the sake of future lazy person, I'd reverse the order: quick answser first, man page later.
Comment: If your machines use OpenSSH >= 6.5, [you should be using the `-o` option](http://www.tedunangst.com/flak/post/new-openssh-key-format-and-bcrypt-pbkdf) to enable the new private key format (bcrypt as KDF by default). With older OpenSSH versions, [use PKCS#8 for more secure private key files](http://blog.patshead.com/2013/09/generating-new-more-secure-ssh-keys.html).
Comment: I think the answer is great since it both shows where you can change the password, and where to look for the answer. I've helped a lot of people setting up ssh keys, and for them actually remembering which tool they have used isn't always easy. Besides, searching for the answer on the 'net is the first option for many...
Comment: @FranciscoLuz the command in my answer is specific to a DSA key. If you have an RSA key, then your command is correct. I added a blurb to the answer to address this.
Comment: This is from the man page shipping with net-misc/openssh-5.2_p1-r2 on Gentoo Linux.
Comment: Or, more precisely, for a default location DSA key, ssh-keygen -pf ~/.ssh/id_dsa
Comment: I like providing the key file as arg, can you update your answer to reflect my whimsical penchants so I can accept it without reservations? #pedanticwho
Comment: There is a typo, correction: `$ ssh-keygen -p -f ~/.ssh/id_rsa`
Comment: @mike-mazur Huuumm. I wasn't aware of DSA keys. Thanks.
Comment: If you just have a single key and don't tend to customise the key's location, you can simply use: `ssh-keygen -p`.  A default path will be suggested, just like when generating a key.
Comment: Perfect ! it's work for me, but i adapt the good name of my key and that's all. Thank you
Comment: Why am I getting Failed to load key /home/marcus/.ssh/id_rsa: incorrect passphrase supplied to decrypt private key when I enter the correct pass phrase??
Answer: If you don't have ssh-keygen installed, you can also use openssl directly
key="/path/to/your.key"
algo="-des3" # or -aes256 or ...

openssl rsa $algo -in "$key" -out "$key.new"

# and replace old key with new one
mv "$key.new" "$key"

Comment: "Cannot find private key"
Comment: @chx101 : I guess you didn't give the correct path to your key in the `$key` variable.
Comment: Hmmm.. It's in the same directory. ```ssh-keygen``` works with no issues.
Answer: Remove your SSH public/private keys:
rm ~/.ssh/id_rsa*

Recreate the keypair, choosing a new passphrase:
ssh-keygen -t rsa -f ~/.ssh/id_rsa

Add the newly created private key to your OS X Keychain to store the passphrase and manage unlocking it automatically:
ssh-add -K ~/.ssh/id_rsa

Copy the public key to the OS X clipboard for adding to web services like GitHub, etc.
cat ~/.ssh/id_rsa.pub | pbcopy

Add your newly created public key to the ~/.ssh/authorized_keys file of the remote server. Be sure to ensure the correct permissions of both the remote ~/.ssh folder (700) and ~/.ssh/authorized_keys (600). You may want to investigate using ssh-copy-id to ease this process.
Comment: The poster asked how to change passphrase on their key, not throw it away and generate a new one; and they never mentioned OS X.
Comment: I would have upvoted this answer if it wasn't for these three issues: **1.** Deleting the old keys isn't a good start since you'll need those when updating `authorized_keys`. **2.** You haven't mentioned why creating new keys is better than changing passwords on the old. **3.** You make assumptions about OS, which is not supported by the question.
Comment: This is replacing the keys entirely, not replacing the password. Read the question carefully and if you don't know, then don't answer.


Differential form $\sqrt{z}dz$ does not transform uniquely?

Question: On page 107 of his Algebraic Curves and Riemann surfaces Miranda writes

The definition of a meromorphic or holomorphic $1$-form $\omega$ suggests that in order to define $\omega$ on a Riemann surface $X$, one must give local expression for $\omega$ (of the form $f(z)dz$) in each chart of an atlas for $X$. In fact, one can define $\omega$ by giving a single formula in a single chart. […] A [second] problem may arise, namely that the local expression does not transform uniquely to the other points of $X$. For example, consider the meromorphic $1$-form $\sqrt{z}dz$ defined on the complex plane with the negative axis removed, where the branch of the square root is chosen so that $\sqrt{1}=1$. This can be extended to the negative real axis but not uniquely. Hence we do not obtain a meromorphic $1$-form on the whole of $\mathbb{C}^*$.

I am not sure that I understand this paragraph. Miranda seems to consider the chart $\phi\colon \mathbb{C}\setminus \mathbb{R}_{\leq 0}\rightarrow \mathbb{C}\setminus \mathbb{R}_{\leq0};z\mapsto z$. Denote the corresponding local coordinate by $z$. Then we considers the $1$-form $\sqrt{z}dz$, where $\sqrt{-}$ denotes the principal branch of the square root. Now, what is meant by the above sentence marked in bold? The principal branch of the square root function cannot be extended to a global holomorphic function. Does Miranda refer to the fact that it can locally be analytically continued so that one obtains a holomorphic function $f\colon U\rightarrow V$ such that $\mathbb{R}_{\leq 0}\subset U$ and $f(z)=\sqrt{z}$ for $z\in U\cap(\mathbb{C}\setminus \mathbb{R}_{\leq0})$? And this extension is not unique?
Answer: I'm not completely sure what is meant by Miranda. If the meromorphic $1$-form $\omega=\sqrt zdz$ has domain $\mathbb C\setminus\mathbb R_{\le0}$, then it's not possible to extend the domain to any point of $\mathbb R_{\le0}$: suppose $\omega$ can be extended, so that there's an open subset $U$ with $U\cap\mathbb R_{\le0}\neq\emptyset$, a chart $\phi:U\to V$ with $w=\phi(z)$ and $\eta=g(w)dw$ a meromorphic $1$-form on $V$ which transforms to $\omega|_{\mathbb C\setminus\mathbb R_{\le0}}$ under $\phi$. This means that $g(\phi(z))\phi'(z)$ should be a meromorphic function on $U$ and $g(\phi(z))\phi'(z)=\sqrt z$ on $U\cap(\mathbb C\setminus\mathbb R_{\le0})$. This is impossible because if we take a point $\bar z\in\mathbb R_{<0}$, if $z\to\bar z$ from below then $\sqrt z\to-\sqrt{|\bar z|}$ while from above $\sqrt z\to+\sqrt{|\bar z|}$, so $g(\phi(z))\phi'(z)$ cannot be defined in a continuous way on any point of $U\cap\mathbb R_{<0}$ and so is not a meromorphic function on $U$.
On the other hand, if we start with a smaller domain for $\omega$, one which is disjoint from an open subset containing $\mathbb R_{\le0}$, then it's possibile to extend the domain of $\omega$ to also include $\mathbb R_{<0}$ (note that we have no hope for $0$, assuming you want the domain to be connected), but not in a unique way (we can extend the domain "from below" or "from above").


Is there a tag to indicate the required quality of answers?

Question: I am mostly familiar with Worldbuilding.SE. There, we have a tag, hard-science, which is used by the askers that s/he expects answers to provide a certain amount of references and proofs to the claims made, and a minmum amount of information provided (namely more than usual).
I understand that the context is different, but the recent questions of FooBar, namely

What is the Gross Domestic Product (GDP)?
How do economies grow?
What is the relevance of economic growth?

is thought of as a series of educational questions, which could be refered to by new questions, or directly answers most typical question. A FAQ if you want.
But for that purpose it requires that the answers are a bit more thorough. Which leads me to my question:
Is there a way on Ec.SE to indicate that we are interested in having more exhaustive answers? Is there some "meta" tag similar to the hard-science?
And if not, is it desirable?
Answer: Sort of. We have the academic-graduate tag, which is used on questions dealing with material that only arises at the postgraduate or professional research level (i.e. not basic undergraduate or layperson questions). The tag therefore signals the question's target audience, but implicit in this use is the idea that answers will conform to the appropriate degree of academic rigor.
This, though, seems to be slightly different to what you are asking, which seems to be more about the thoroughness and care with which answers are written regardless of the sophistication of the question. My view is that we should aspire for all answers to be appropriately supported by evidence or literature. Answers and questions that do meet this aspiration should be up-voted, and those that do not should be down-voted, put on hold (in the case of bad questions), or (in particularly egregious cases) deleted. As the site matures and questions of particular quality and general interest emerge, they can be administratively "protected", which prevents addition of spurious new content.
These are all mechanisms by which the community can drive the best content to the top. I think it would be a mistake and explicitly start labeling some content privileged as this would seem to imply that we think that less than thorough answers on non-tagged questions are somehow okay.

Edit: What I do think would be helpful is if we start to identify questions that are likely to be of very broad interest in the future and figure out a good way of curating such questions and ensuring they have some very high-quality up-voted answers.
Comment: I guess bounties are a standard way of curating such questions.


rendering  in Visual Studio Code - Python

Question: Is there a way to see/render an HTML object in VS code? When I run my Python render function, I get this as a result in the console:
<IPython.core.display.HTML object>
or am I forced to run it in a Juypter notebook to see the HTML object?
Answer: You can also try the displacy.serve.
Such as:
import spacy
from spacy import displacy

nlp = spacy.load("en_core_web_sm")
doc = nlp("This is a sentence.")
displacy.serve(doc, style="dep")

Then browse it through http://localhost:5000/.
You can refer to the official docs.


managing existing hosts with vagrant bypassing the provider

Question: I'm managing a few web services residing on different fixed hosts with ssh. I wanted to use vagrant so that I can edit local files and have them synced automagically.
however I'm having problems as I'm not using no provider or box, it's a fixed host and it feels like I'm going against vagramt's aim.
here's my Vagrantfile:
<code># -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
  VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.ssh.host = ...
  config.ssh.username = ...
  config.ssh.private_key_path = ".ssh/id_rsa"
  config.vm.synced_folder "src/", "..."
  config.vm.box = "myhost"
  config.vm.provision :shell, :path => "bootstrap.sh"
end
</code>
and here's my bootstrap.sh file:
<code>pip install flask sqlalchemy
</code>
but I can't make vagrant skip providing (with virtualbox or so)
Answer: well, as it always comes out - fighting against your tool in order to force it to do things it's not designed to are a bad idea.
there was probably a way to make vagrant use a void box but vagrant is too much for just keeping 2 directories synced. I found this nice tool that does exactly the same as vagrant for sync just without all the provider/provision etc.


How to force a selection in one field if another webform field is a certain value

Question: I know it is quite simple with Conditionals to show and hide fields based on another fields value in a Webform -- is it possible to change values of fields based on another field's value?
For example, if someone selected a certain membership type in a field at the top, could a field lower down automatically have certain selections disabled automatically (or a single selection selected, and the entire second field disabled)?
This is a bit of an oversimplified example, but:

Membership type (select) > Single person
How many t-shirts would you like (select)? [Preselect "One" and disable the field from edits]

and

Membership type (select) > Two people
How many t-shirts would you like (select)? [Option to select "One" or "Two"]
Answer: You could use normal conditional fields for that. Simply create two "How many t-shirts" fields, one with only one enabled option, second with both available. Then, make them visible depending on value in "Membership type". It is possible since Webform version 7.x-4.0-alpha2, and earlier using this module.
Sure, this will create two separate entries in results, and only one filled, but if your traffic is low, it will be easy to read. And if it's high, you can aggregate easily in your warehouse handling software. Or in spreadsheet of your choice, after export.
Comment: Thank you -- I may end up doing something like this if I can't figure out a more elegant way to do it. I appreciate the idea!
Comment: @Laryn I admit it's not elegant. But it's the only thing I could answer fast :) I'll gladly upvote alternatives.


How to register the SIEBELHTMLLib for programing

Question: I am making a program to access the CARMAN system. But when i compile the program it show me that missing the namespace SIEBELHTMLLib . So my question is how to register the SIEBELHTMLLib  and make it showing in the Visual Studio? And When can i download the setup file for SIEBELHTMLLib ?
Answer: Install Siebel on the machine you are compiling VB program.
Application Name: SiebelHTML
Application ID: {253A9D17-F982-11D4-8BE4-00D0B7E61414}

You can get 'SiebelAx_Desktop_Integration_21225.exe' from any machine which has Siebel application installed. Either register it manually or add a component reference to Visual Studio by providing location of file.


Having trouble playing guitar without Chordify accompaniment

Question: I've been playing acoustic guitar for about a year and a half. About 6 months ago, I was struggling a lot with strumming and so switched to Chordify and started playing along with music. My playing immediately improved dramatically and I can now play along quite well with many of my favourite songs, but now I can't play without the app and its accompanying music. I am reliant on my ear and the rhythm from the song. When I try playing a song without it, it is quite bad. If I was to quit the app, it would be like starting over again (or at least it feels that way). Any suggestions on how to wean myself off the app and start to play without the accompaniment?
Comment: I'd suggest find some other people to play with, it changes everything totally.
Comment: You haven't explained the actual problem. "Quite bad..." in what way? It isn't clear whether you think it's better playing with the app, but the app may just be covering over your mistakes.
Answer: Start to play without the accompaniment.
For real. The only way to get better at the things that you are bad at is to practice them. Most of the time the hard part is recognizing those things. And this will get harder the better you get. After a certain point you'll probably need to record yourself playing and start analyzing and nitpicking to recognize such things.
But once you find a problem you'll want to isolate it and work on that specifically. It's not clear what the problem is other than it "sounds quite bad". You might want to edit your question to include those details.
For example, it sounds like it could be one of two problems:

You're relying on the backing track to keep the rhythm.
You're not actually playing the chords correctly or cleanly enough but the backing track is masking that by playing those notes for you.

The solution to either is to—and this may sound obvious—not use the backing track.
For the first problem, I'd try playing both with and without a metronome. It's good to play to a metronome because it teaches you to keep a steady pulse. And one thing to keep in mind is that you want to play both around and with the metronome. In other words, don't think that you have to play exactly on each metronome tick. Sometimes you'll want to play a little bit ahead or behind it to give it a certain feel. But you'll want that feel to be consistent. That is, you don't want to be speeding up and slowing down unintentionally. That's the skill the metronome helps you develop. And once you get better at it, try to playing without the metronome to see if you keep the time yourself.
By playing with a backing track you're using that as a crutch to provide both the pulse and the feel. Having to do it yourself will teach you quite a bit.
For the second problem, try slowing waaay down. Maybe even forget about time. Try playing one chord or melodic phrase by itself over and over very slowly until you can get each note to ring out clearly and in the way that you intend. Then combine it with the next chord or phrase. Try just switching between the two. Then do the same with the next chord(s). Get small chunks sounding good on their own and then combine them.
Again by playing it in isolation, you'll hear exactly what you're playing without somebody else's playing masking it. A common problem might be that a note in a chord is missing or sounds weak because it's being muted by another finger or isn't fretted completely. This will give you an opportunity to hear these problems and address them directly until they sound good.
Then try it in time and with a metronome.
But whatever the problem is, you'll want to isolate it and work specifically on that thing. And since the general problem is that "you can't play without this backing track", it's safe to say that a large part of the fix is going to be practicing without the backing track.
Answer: Any suggestions on how to wean myself off the app and start to play without the accompaniment?
In no particular order ...

Gradually lower the playback volume: Try gradually lowering the volume of the Chordify playback. Let's say your speaker volume is currently at 10. Lower it to 9 for a week. If all goes well, lower it to 8 for a week. And so on.
Watch only or listen only: Play along, but watch without listening, and/or listen without watching. By learning to play with only one cue or the other, it might help you depend on yourself more while still leaving you some help to lean on.
Play at different speeds: Change the playback tempo. This will disrupt how you're used to hearing and playing the song, forcing you to better develop the physical connection between your strumming, the rhythm, and the sound.
Try different keys: If you're feeling particularly ambitious, try transposing the song. This, too, will require you to have greater awareness of your own playing.
Practice small chunks. Play a few chords, or a few measures, along with the Chordify accompaniment. (Perhaps a few times.) Then play the same few chords or measures on your own. Go back and forth between accompanied and unaccompanied. This would mimic how a teacher might work with you: by demonstration and imitation.
Answer: Try recording covers. Also, play with metronome only (no background sounds).


ROC Curves for different classifiers

Question: I am trying to compare the classification performance of different classifiers. So far, I am using SVM, Random forest, Adaboost.M1, and Naive Bayes. 70% of the data is used for training (and then plotting the ROC curve), while 30% is used for testing (a ROC curve again). Being fairly new to ML and more specifically to ROC curves, I have the following questions:

Can we compare classifiers using the ROC curve? If so, the discussion will be on AUC? In this case, should I discuss accuracy, f-measure...
Should I evaluate using a ROC curve based on the training data or on the test data? Which is more meaningful? And why?
In my simulation, my testing ROC curve is different from training (specifically for SVM classifier). SVM's training ROC curve is very good as compared to testing data curve (see below). Is this correct? If so, how should I analyze/present it? Pointers would be really helpful. The top one is based on the training data, where SVM's curve is very good. The bottom one is based on testing data, where SVM is not so good, and is being outperformed by random forests. So should I say that random forests is doing a good job?

Answer:
Yes, you can compare the AUC's of different classifiers. Including more measures such as accuracy, f-score, precision, recall etc. to the analysis might be good too.
Testing measures should be better, they show you the out-of-sample performance of your system which is closer to the "real life" scenario, i.e. the performance on previously unseen data. Training measures can be helpful too, but they depend on the training algorithm itself, one algorithm might be using regularization techniques that decrease the training accuracy on purpose, while the other doesn't, but they might generalize the same, which is -I think- the case on your first figure.
Yes, this is possible, I would just ignore the training curves. An improvement might be k-fold cross validation instead of dividing the dataset into %70 train - %30 test. Then you use all your dataset to measure the performance.
Comment: So when I do cross validation, I will plot the "testing sets" ROC? (after k folds)
Comment: yes. when you use each one of the k folds for testing, you will have evaluated all your samples as test set, so you can plot the average performance.
Comment: Or compute k different values for AUC if you want to do statistical tests
Answer:

Can we compare classifiers using ROC curve? If so, the discussion will be on AUC? In this case, should I discuss accuracy,
  fmeasure...

You can. Keep in mind what AUC means, i.e. it reflects the separability of classes over a continuous score. It doesn't reward the separation of hard-to -classify instances nor rewards the certainty of probabilistic scores.

Training data ROC curve or testing data ROC curve? Which is more meaningful? and why?

Testing data ROC curve, of course. Consider the scenario where your classifier simply memorizes the training data (Random Forests are likely to do this), your training data AUC will be close to 1, but it's a meaningless result, it's simply a just-identified model artifact. Testing-data metrics, on the other hand, are more likely to be generalizable.

In my simulation, my testing ROC curve is different from training (Specifically for SVM classifier). SVM's training ROC is very
  good as compared to testing data curve (See below). Is this correct?
  If so, how should I analyze/present it? Pointers will be really
  helpful.The top one is training, where SVM's curve is very good. And
  bottom one is on testing data, where SVM is not so good, and random
  forest outperforms. So should I say that random forest is doing a good
  job?

As @jeff said, ignore the training metrics, they aren't useful in your scenario. You could use them only to try to justify a possible overfitting with the SVM, though, but that's it.

ROC Curves for different classifiers