What does ifstream::open() really do?

Question: Consider this code:
ifstream filein;

filein.open("y.txt");

When I use the open() function, what happens?

Does the file stream itself get opened?
or does the object's state change to open?
or both?
Comment: http://en.cppreference.com/w/cpp/io/basic_ifstream/open ?
Answer: It's not clear if you want to know implementation details or standard requirements - but as for implementation details - it will call the underlying open system call on the operating system.  On Linux for example this is called open.  On Windows it is called CreateFile.
Answer: The filestream being open or closed is represented by it's state.  So if you change the state to open, the filestream is now open.  Like a doorway.  If you open it, you've changed it's state to the open position.  Then you can later close it, which involves changing it's state to the closed position.  Changing its state to open and opening the stream are the exact same thing.
Answer: The std::ifstream is set up to own a std::filebuf which is a class derived from std::streambuf. The stream buffer is managing buffering for streams in a generic way and abstracts the details of how a stream is accessed. For a std::filebuf the underlying stream is an operating system file accessed as needed. When std::ifstream::open() is called this call is mainly delegated to std::filebuf::open() which does the actual work. However, the std::ifstream will clear() its state bits if the call to std::filebuf::open() succeeds and set std::ios_base::failbit if the call fails. The file buffer will call the system's method to allocate a file handle and, if successful, arrange for this file handle to be released in its destructor or in the std::filebuf::close() function - whatever comes first. When calling std::ifstream::open() with the default arguments the system call will check that the file exists, is accessible, not too many file handles are open, etc. There is an std::ios_base::openmode parameter which can be used to modify the behavior in some ways and when different flags are used when calling std::ofstream::open().
Whether the call to std::filebuf::open() has any other effects is up to the implementation. For example, the implementation could choose to obtain a sequence of bytes and convert them into characters. Since the user can override certain setting, in particular the std::locale (see the std::streambuf::pubimbue() function), it is unlikely that much will happen prior to the first read, though. In any case, none of the state flags would be affected by the outcome of any operation after opening the file itself.
BTW, the mentioned classes are actually all templates (std::basic_ifstream, std::basic_filebuf, std::basic_streambuf, and std::basic_ofstream) which are typedef'ed to the names used above for the instantiation working on char as a character type. There are similar typedefs using a w prefix for instantiations working on wchar_t. Interestingly, there are no typedefs for the char16_t and char32_t versions and it seems it will be a bit of work to get them instantiated as well.
Answer: If you think logically, ifstream is just the stream in which we will get our file contents. The parameters, we provide to ifstream.open() will open the file and mark it as open. When the file is marked as open, it will not allow you to do some operations on file like renaming a file as it is opened by some program. It will allow you to do the same after you close the stream. ifstream - imo is only the helper class to access files.

What does ifstream::open() really do?


Javascript regular expression to match various strings

Question: I have a question that I can't resolve. I have strings that contains hashtags, for example '#question' or '#idea'.
The question is how extract the hashtag?
var hashtag = str.match(/#question?#idea?/i);

Is this regexp correct?
Answer: Your line
var hashtag = str.match(/#question?#idea?/i);

checks whether a string contains a literal #questio, optionally followed by n, followed by #ide, optionally followed by a. If that's the case, hashtag[0] will contain the matched text. This is obviously not what you want.
Try this:
// match a #, followed by either "question" or "idea"
var myregexp = /#(question|idea)\b/i;
var match = myregexp.exec(subject);
if (match != null) {
    result = match[1]; // will contain "question" or "idea"
} else {
    result = "";
}

The \b at the end of the regex is a word boundary anchor. It ensures that only #question but not #questionnaire will be matched.
If you don't know the names of the hashtags beforehand, use
var myregexp = /#(\w+)/;

(this allows ASCII letters, digits and underscore as possible hashtag characters - I don't know if those are the only valid characters. If not, you can use a character class. For example, to allow dashes, too:
var myregexp = /#([\w-]+)/;

Answer: No your regex is not correct.
/#question?#idea?/i

You search for each character in your regex, in this order. The ? makes the character before comes 0 or 1 times, the i at the end makes the expression ignoreCase, i.e. treat upper and lower case the same. You will find:
#question#idea
#questio#ide
#questio#idea
#QUEStion#IDea

but not
#question
#idea

Do you have a fixed set of tags, can they contain only letters, or also numbers, or other characters?
You can check your regexes e.g. here online My example
Answer:
var str = "/foo=bar?#quesAion#dwdad";
var regi = new RegExp("(#[a-z0-9_-]*)", "gi");
var hashtag = str.match(regi);

Hashtag will be an array of found strings or null if not found any.


Quais são os riscos de usar permissão 777?

Question: Sempre quando tenho problema de permissões de pastas no meu sistema operacional Ubuntu, eu costumo dar a permissão 777 para a determinada pasta. Costumo fazer isso no ambiente de desenvolvimento.
Em algumas situações, já dei esse tipo de permissão em ambiente de produção em um servidor Linux, onde rodo minhas aplicações escritas em PHP.
Por exemplo,
quando tive um problema específico de escrita de arquivos de upload na pasta public/uploads de um determinado sistema, eu dei a permissão 777 nesta pasta.
Porém vejo sempre recomendações de que devemos usar a permissão 755 ou 644, porque usar 777 é perigoso.
Mas em que sentido isso seria perigoso?
Por que os programadores mais experientes sempre recomendam a utilização de outros valores para permissões de pasta em produção ao invés de 777?
Por exemplo, já ouvi dizer que uma pessoa pode ter problemas com ataques a uma aplicação web caso haja uma permissão de escrita 777 em determinada pasta. Isso é verdade?
Seria legal também se a resposta pudesse explicar melhor sobre as diferenças entre 644, 755 e 777.
Comment: Resposta que fala sobre o tema: http://pt.stackoverflow.com/a/2281/67
Comment: Possível duplicata de [Permissão negada ao mover arquivo com move\_upload\_file em servidor Linux](http://pt.stackoverflow.com/questions/2270/permiss%c3%a3o-negada-ao-mover-arquivo-com-move-upload-file-em-servidor-linux)
Answer: Ao dar permissões 777 para um arquivo você faz com que todos os usuários possam ler, escrever e executar o mesmo.
Isso significa que qualquer vulnerabilidade do seu sistema permite que um invasor faça o que bem entender com esse arquivo. Pior ainda, com a combinação de permissões de escrita e leitura, um atacante com conhecimento suficiente sobre o seu sistema pode fazer com que um outro usuário privilegiado execute algo sem saber.

Um exemplo ilustrativo
Bob é o sysadmin responsável por um servidor JBoss. O JBoss de Bob está rodando com o usuário jboss. Sua aplicação tem um script inofensivo que copia arquivos de uma pasta de negócios upload para uma pasta de contexto do apache (usuário apache) otimizada para servir arquivos estáticos; esse script roda com o usuário jboss. Soa como algo que você vê por aí não? Por exemplo, para upload de avatares e coisas do gênero.
Digamos que Bob, não querendo lutar com permissões de acesso entre o jboss e apache foi lá e executou chmod 777 na pasta de contexto do Apache. Com isso o script em questão, mesmo rodando com o usuário do jboss, pode escrever arquivos na pasta do apache sem ser incomodado. Parece inofensivo certo?
Depois Bob começou a ter problemas ao lidar com esses arquivos do usuário jboss dentro de uma pasta que pertence ao apache. O apache não exibia as imagens copiadas pelo script. Bob, com pressa, foi lá e alterou seu script para rodar um chmod 777 em todos os arquivos que estão sendo copiados para a pasta do apache. Bob não viu nenhum risco em fazer isso já que a aplicação da firma tinha uma função JavaScript que validava a extensão dos arquivos que eram enviados pelos usuários. A aplicação só permitia que arquivos com extensões de imagem fossem enviadas para o servidor. Alice, a desenvolvedora da firma, copiou a função JavaScript desse post do SOen e colou na aplicação web em questão.
Mallory verifica então que o PHP está instalado no Apache; rodando inclusive na pasta de imagens estáticas... De novo Bob não viu necessidade de ficar mexendo com arquivos de configuração do Apache já que a pasta em questão só teria imagens mesmo.
Mallory então:

Abre as ferramentas de desenvolvimento do Chrome e modifica a função de validação de Alice para permitir upload de arquivos .php.
Cria um script PHP qualquer, por exemplo, para apagar ou roubar todas as imagens do servidor de Bob.
Faz upload do arquivo pelo Chrome
Espera o script do Bob rodar
Executa o script PHP através da pasta de contexto do Apache.

O usuário apache está agora executando o script de Mallory. Mallory acabou de ganhar acesso ao Apache através de uma vulnerabilidade em uma aplicação rodando no JBoss.
Generalizando os pontos da história:

Resolver um problema usando chmod 777 geralmente cria outros problemas que chamam por chmod 777 (permissões estão lá por um motivo)
chmod 777 dá acesso a escrita e execução de um arquivo. Essa combinação abre portas para vários tipos de exploits
chmod 777 significa que seu arquivo poderá ser lido, escrito e executado por qualquer usuário. Isso significa que qualquer usuário que seja comprometido vai poder fazer o que quiser com o arquivo / pasta.
Componentes de software interagem de formas não triviais e falhas de segurança vão sendo acumuladas através das camadas (Alice não validou arquivos no server-side da sua aplicação, Bob não desativou o PHP na pasta de contexto do Apache e ainda escreveu um script péssimo). Por mais que você confie nas suas aplicações, é importante manter segurança em todas as camadas e isso inclui as permissões do sistema de arquivos.
Answer: TL;DR;
Dar permissão 777 é o mesmo que :

"Confiar em todo mundo, independente de quem seja".
"Permitir que qualquer um faça o que quiser".

Você "confia" que ninguém, absolutamente ninguém, vai fazer nada que você não queira e todos seguiram as regras. - (É por isso que não nos preocupamos com segurança não é mesmo?)
Porque 777, e não 7 ou 77
O sistema de permissão se baseia em três níveis de acesso.

Dono - Usuário logado que criou a pasta/arquivo.
Grupo - Grupo em que o usuário esta inserido (analogia para família).
3º - Outros usuários, que não fazem parte do seu grupo (analogia para estrangeiro).

Horizontalmente escrito assim :
Dono | Grupo | 3º
E porque 7?
O sistema de permissão também se baseia em três ações.

r - Ler
w - Escrever
x - Executar

As combinações possíveis geram uma tabela assim :

Logo pode se ver que 7 seria permissão geral, RWX
Acesso + Ações
Assim podemos definir exatamente quem e o que pode ser feito no arquivo/pasta.

7 - Eu sou o dono, posso fazer o que quiser.
5 - Você é da minha família, mas só vou deixar ler e executar, não quero que edite nada.
0 - Você é estrangeiro não confio você, não quero nem sequer que possa ler, vai que roube minha ideia.

Por que as pessoa geralmente usam 777
A resposta para isso esta no acesso, pois o dono do arquivo é um usuário "comum" e o apache é um usuário "avançado" responsável por gerir o servidor. E eles sequer estão no mesmo grupo utilizadores, rede.
Ou seja quando eu estou dando permissão para um arquivo/pasta que criei o apache sera o 3º (estrangeiro).
As pessoas em um modo simples pensam, "ah é o apache que vai acessar" e usam 7, mas esquecem que isso vale para qualquer outra pessoa. inclusive as mal intencionadas.
Adendo
Em servidores isso é mais difícil de acontecer, mas é possível alterar o dono do arquivo/pasta, ou mesmo por os dois no mesmo grupo, assim você poderia restringir os acessos.
Alterando dono

Eu criei a pasta, mas quem vai alterar e escrever é o apache então para não usar 777.
Eu digo que o apache é o novo dono. chown apache file.
Como usuário apache altero a permissão para 700.

Integrando o mesmo grupo

Eu e apache estamos no mesmo grupo.
Então o só preciso trabalhar com 2 bits e manter o terceiro sempre em 0.
770 - Eu e meu grupo podemos fazer o que queremos, o 3º não tem acesso a nada.
Comment: Ali não é gravar e sim escrever. De resto, excelente explicação.
Comment: @JorgeB. Eu sempre achei como gravar, mas realmente faz mais sentido, vou editar.
Comment: Guilherme é r de read, w de write e x execute ;)
Comment: É traduzindo literalmente.
Comment: Guilherme mas neste caso é mesmo escrever, quando gravas, o que acontece é que estás a escrever no ficheiro. Por isso é que se diz escrever no ficheiro e também permissão de escrita.
Answer: Como foi dito acima, usar permissão 777 não é uma boa escolha, pois você permite que todos leia, escrevam e executem.
Permissões usando chmod com numeros é muito complicado utilize a tabela de letras com as opções + e - como foi apresentado acima.
Outra opção é que ninguém citou que é recomendada executar junto com chmod é utilizar o comando chown (o chown altera o dono do arquivo e enquanto o chmod altera as permissões)
Só passei para dar uma reforçada. :)
Answer:
Por exemplo, quando tive um problema específico de escrita de arquivos
  de upload na pasta public/uploads de um determinado sistema, eu dei a
  permissão 777 nesta pasta.

Adoro quem vive de modo perigoso rsrs(brincadeira), já está mais do que explicado os motivos, as respostas anteriores falaram tudo, só vim aqui acrescentar com exemplos práticos o que pode acontecer, de como o seu Sistema Operacional pode ser invadido...
Imagine que estou andando na sua página e me deparo em uma área de upload, digamos que o algoritmo de upload não checa metadados e nem extensões de arquivos, você simplesmente vai estar perdido, o atacante não vai ter acesso root, mas mesmo assim pode fazer um bom estrago, certamente ele vai conseguir ler muitas coisas dentro do seu SO, além de conseguir olhar os códigos fontes de sua página (php, asp, etc), pode até conseguir as senhas do seu banco de dados para acesso (olhando os códigos da sua página ele pode achar as senhas de conexão do seu banco), neste caso o atacante não precisa ser muito esperto, ele iria subir um arquivo na pasta pasta upload ex. hack.php(um código que abra arquivos e mostre na tela), depois é só executar e ver o retorno...
http://meusite/upload/hack.php?var=/etc/passwd

Se ele for um pouco mais esperto, faria um arquivo .php que envie e retorne comandos (dir, ls, rm)
http://meusite/upload/comandos.php?var=ls&local=/etc/

Claro estou só falando coisas básicas para não dar idéias para os mal intencionados, isso é crítico, é o pior cenário possível, o hacker poderia subir qualquer arquivo e usar o php, asp, java, python, etc para executar, poderia tentar escalar root utilizando exploits e ter controle total do SO, ou seja seria uma "festa" dentro da sua pasta upload :-(
Agora imagine que o seu algoritmo de upload check extensões, mas não olha metadados (cabeçalhos), vamos imaginar que o seu algorítimo em tese só deixe fazer upload arquivos .jpg, imagine que eu crie o seguinte arquivo:
<?php echo "
Ola Mundo
"; ?>

E salve como teste.jpg(claro é um exemplo bobo, mas poderia ser algo realmente perigoso), sua pasta upload viraria um campo minado, códigos maliciosos dentro de extensões permitidas :-( digo que é um campo minado pois o hacker só vai precisar disparar o gatilho, geralmente esse gatilho não pode ser executado de fora, via http, eu disse "geralmente", o hacker vai precisar usar artifícios para executar por exemplo um  php teste.jpg.
Esse são só exemplos superficiais de como uma pasta de upload com chmod 777 pode se tornar o calcanhar de aquiles do seu SO.


count the number of words with length $n$ using $a,b,c$ that contain odd number of $a$'s and even number of $b$'s.

Question: count the number of words with length $n$ using $a,b,c$ that contain odd number of $a$'s and even number of $b$'s.
I tried to use the same method that was here but it didn't work because in the first two letters we can't deal with the case $ab$ or $ba$.So how should I start?Any way I wan't the answer written in the book I mean:
$f_n=2f_{n-1}+3f_{n-2}$
Comment: Correct relations are $$ f_n=2f_{n-1}+3f_{n-2}$$.  And/or $$ f_n=3f_{n-1}-1$$
Comment: Where did you get that recurrence relation from?
Comment: Strike the second one - it should actually be $$ f_n=3f_{n-1}+(-1)^{n-1} $$
Comment: @WW1 Yes you are right.How to Prove that?
Answer: let $f_n$ denote the number of words of length $n$ that have odd number of $a$'s and even number of $b$'s.
Notice that the number of words of length $n$ that have even number of $a$'s and odd number of $b$'s is equal to number of words of length $n$ that have odd number of $b$'s and even number of $a$'s. This is because you can interchange $a$ and $b$ in any word and obtain a word of the other kind. (One-to-one correspondence)
Now I leave it to you verify that $f_n = 2f_{n-1}-f_{n-2}+2f_{n-2}+2f_{n-2}$.
Hint: $c \_ + \_ c - cc + aa + bb + ab + ba$
Answer: Let $f_n$ be the number of such words of length $n$. Let us also consider the following sets:

$A=\{x:x\mbox{ is a word of $a$'s with odd length}\}$,
$B=\{x:x\mbox{ is a word of $b$'s with even length}\}$,
$C=\{x:x\mbox{ is a word of $c$'s}\}$,
$F=\{x:x\mbox{ is a word as requested}\}$.

So, every element of $F$ comes from a "mingling" of words of $A,B,C$. We will use the method of the exponential generating functions to calculate the wanted number.
Let $a_n,b_n,c_n$ be the numbers of elements of $A,B,C$ of length $n$, respectively. Then, it is evident that:

$a_n=\left\{\begin{array}{ll}1 & \mbox{if $n$ is odd}\\0&\mbox{else}\end{array}\right.$,
$b_n=\left\{\begin{array}{ll}1 & \mbox{if $n$ is even}\\0&\mbox{else}\end{array}\right.$,
$c_n=1$

So, now we calculate the generating functions:

$$\begin{align*}A(x)=&\sum_{n\geq0}a_n\frac{x^n}{n!}=\sum_{n=\text{odd}}\frac{x^n}{n!}=\frac{e^x-e^{-x}}{2}
\end{align*}$$
$$\begin{align*}B(x)=&\sum_{n\geq0}b_n\frac{x^n}{n!}=\sum_{n=\text{even}}\frac{x^n}{n!}=\frac{e^x+e^{-x}}{2}
\end{align*}$$
$$C(x)=\sum_{n\geq0}c_n\frac{x^n}{n!}=\sum_{n\geq0}\frac{x^n}{n!}=e^x$$.

We know now that $F(x)=A(x)B(x)C(x)$, where $F(x)$ is the exponential generating function of $f_n$. So:
$$\begin{align*}F(x)=&\frac{e^x-e^{-x}}{2}\frac{e^x+e^{-x}}{2}e^x=\frac{e^{3x}-e^{-x}}{4}=\frac{1}{4}\left(\sum_{n\geq0}\frac{(3x)^n}{n!}-\sum_{n\geq0}\frac{(-x)^n}{n!}\right)=\\
=&\sum_{n\geq0}\left(\frac{3^n-(-1)^n}{4}\right)\frac{x^n}{n!}
\end{align*}$$
On the other hand, $F(x)=\sum\limits_{n\geq0}f_n\frac{x^n}{n!}$, so, $f_n=\frac{3^n-(-1)^n}{4}$.
As for the requested recursive relation, it must be changed to the following - which is easy to prove now that we have the formula:
$$f_n=3f_{n-1}+(-1)^n$$
Notes

As shown, the method of the exponential generating functions is a very useful tool in combinatorics.
The series that we used here are not treated in an "analytic" way, but as "algebraic" elements. By that, it is meant that we do not care about convergence and we do use power series as a way to "depict" sequences, where th $n$-th power of $x$ denotes the $n$-th term of the sequence. For instance, the power series $\sum\limits_{n\geq0}2^nx^n=\sum\limits_{n\geq0}(2x)^n$ is equivalent to the sequence $(1,2,4,8,16,\dots)$.
Comment: I changed the plus sign in the middle to a minus sign, but feel free to change this back if I made a mistake in doing so.
Comment: Oh, yeah! You' re right! Thank you! :)


Behaviour of two distinct, arbitrary points of the Thue-Morse Subshift

Question: Let $x^+$ denote the infinite Thue-Morse word, $$x^+ = 0110100110010110\ldots,$$ which is defined as being the only fixed point starting with $0$ of the morphism $S$ (defined over the words on the alphabet $\{0,1\}$) given by $S(0) = 01$ and $S(1) = 10$ - that is, $$x^+ = S^{\omega}(0) = \lim\limits_{n \geqslant 1} S^n(0);$$ this is only one among many different, equivalent definitions of such word (for instance, pick $A_0 = 0$ and let $A_{n+1} = A_n\,^\frown\overline{A_{n}}$ - where $^\frown$ denotes concatenation and $\overline{A_n}$ denotes the bitwise complement of $A_n$. Then $x^+ = \lim\limits_{n \in \mathbb{N}} A_n$). From now on, let $x^+ = (t_n)_{n \in \mathbb{N}}$.
It is known that the Thue-Morse word is uniformly recorrent (meaning, for every finite subword $w$ of $x^+$ there is some $n \in \mathbb{N}$ such that, for every $i \in \mathbb{N}$, the block $t_{i + 1}t_{i + 2}\ldots t_{i + n}$ contains some ocurrence of $w$) but it is $\mathbf{\textrm{not}}$ ultimately periodic (meaning, it is not true that there are $p \geqslant 1$ and $N \geqslant 0$ such that $t_i = t_{i + p}$ for all $i \geqslant N$).
The two-sided Thue Morse sequence $x = (x_i)_i \in \mathbb{Z}$ is defined as $x = x^{-}\,^\frown x^+$, meaning that $x_n = t_n$ for all $n \geqslant 0$ and $x_{-n} = t_{n - 1}$ for all $n \geqslant 1$.  So, $$x = \ldots 100101100.1101001 \ldots$$
Let $\sigma$ denote (as usual) the left shift map on $^\mathbb{Z}\{0,1\}$. The Thue-Morse subshift $X$ is the closure (in the Tychonoff topology) of the orbit $\{\sigma^n(x): n \geqslant 0\}$. Equivalently, $X$ is the family of all doubly infinite sequences $z$ such that every finite subword of $z$ is a subword of $x^+$. It is known that $X$ is a infinite, minimal subshift (that is, every point of $X$ has a dense orbit in $X$).
My question is:
Let $s = (s_i)_{i \in \mathbb{Z}}\,$ and $u = (u_i)_{i \in \mathbb{Z}}\,$ be two distinct points of the Thue-Morse subshift $X$ - that is, there is some integer $i \in \mathbb{Z}$ such that $s_i \neq u_i$. Consider  the set of integers given by $$\{i \in \mathbb{Z}: s_i \neq u_i \}.$$ Is it true that such set is, necessarily, an $\mathbf{\textrm{infinite}}$ set of integers ?
My conjecture is that the answer is "yes", but I wasn't able to produce a proof.
Answer: Bonjour, it is first easy to observe that $S^n (0)$ is obtained from $S^n (1)$ changing the 0's in 1's and vice-versa. Suppose $E=\{ i\in \mathbb{Z}| s_i\not = u_i \}$ is finite and $u$ and $s$ distincts. Let say that $E$ is included in an interval of length $L$.
Let $N$ such that $2^N > L$.
By the recognizability result of Mossé for primitive substitutions, and shifting both sequences of the same amount if needed, there are two points $s'$ and $u'$ of the Thue-Morse shift such that $s=S^N(s')$ and $u=S^N(u')$ (this is not direct but I left it as an exercise). Then there exists $i$ such that for all $j\not \in \{ i, i+1\}$, $S^N(u'_j)=S^N (s'_j)$ and $S^N(u'_iu'_{i+1})\not =S^N (s'_is'_{i+1})$. Thus either $S^N(u'_i)\not =S^N (s'_i)$ or $S^N (u'_{i+1})\not =S^N (s'_{i+1})$. But in both case, from the first observation, it implies that the number of differences is at least $2^N$. This contradicts the facts that $L$ is strictly less than $2^N$.
Comment: Thanks !!!  I will check the arguments as soon as possible...


Cannot get Guitar Rig 5 sounds recorded into Ableton Live 9

Question: I cannot get Guitar Rig 5 sounds and patches recorded into Ableton Live 9.
Ableton Live 9 only records clean sounds from my guitar.
Comment: can you add some information on how you have your recording setup configured. What are the connections between guitar-guitar rig-ableton etc
Comment: Thanks Dr Mayhem I am using a Focusrite Scarlet 2i2 usb to connect my guitar into my computer via usb. And I connect my amp in focusrite output to get the sound. So when I run Guitar Rig 5, I can get the sounds out from it in my amp. However I don't get those effects recorded into Ableton.
Comment: So it sounds like Guitar Rig is only passing your sound with effects to the Focusrite output, and Ableton is using the clean bus in that Guitar Rig is using. You need to ensure it is passing it to the bus that Ableton is using.
Comment: Can you please explain how to ensure Guitar Rig is passing its output to the bus that Ableton is using.
Any help appreciated.
Comment: Is Guitar Rig 5 running as a plugin within Ableton? I think it should be. Also, ensure the track it's on is armed for recording. Can you show a screenshot?
Answer: here's the simple setup:
Guitar >amp >scarlet 2i2 >Ableton....
then in the ableton, set the input/output to:

track 1: guitar input, add guitar rig vst , set the output to sends only. Set the monitoring from [auto] to [in].
track 2: set the input to track 1, then make sure to set the monitoring from [auto] to [in].
then arm the record in track 2.
record track 2.

that should be fine.
hope this helps...


Unnamed unix domain socket has wrong address length

Question: When reading the address of a sending unix datagram domain socket in this minimal example program, I am getting an address length of 0, but the man page for unix domain sockets specifies that:

unnamed: A stream socket that has not been bound to a pathname using
            bind(2) has no name.  Likewise, the two sockets created  by  socket‐
            pair(2)  are  unnamed.   When  the  address  of an unnamed socket is
            returned, its length is sizeof(sa_family_t), and sun_path should not
            be inspected.

I was expecting the address length of an unnamed socket to be 2 based on this man page. Am I misinterpreting the man page, does the man page not apply to unix sockets of type SOCK_DGRAM or am I simply reading the length incorrectly?
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>

const char SOCK_NAME[] = { 0, 't', 'e', 's', 't' };
// or for pathnamed socket
// const char SOCK_NAME[] = "/tmp/test.uds";

const char PAYLOAD[] = "Hello!";

int main() {
    int rx_sock = socket(AF_UNIX, SOCK_DGRAM, 0);

    if (rx_sock < 0) {
        perror("Create RX");
        exit(1);
    }

    int tx_sock = socket(AF_UNIX, SOCK_DGRAM, 0);

    if (tx_sock < 0) {
        perror("Create TX");
        exit(1);
    }

    struct sockaddr_un bind_addr;
    bind_addr.sun_family = AF_UNIX;
    memcpy(bind_addr.sun_path, SOCK_NAME, sizeof(SOCK_NAME));

    socklen_t bind_len = sizeof(sa_family_t) + sizeof(SOCK_NAME);

    if (bind(rx_sock, (const struct sockaddr *)&bind_addr, bind_len) != 0) {
        perror("Bind RX");
        exit(1);
    }

    if (sendto(tx_sock, PAYLOAD, sizeof(PAYLOAD), 0, (const struct sockaddr *)&bind_addr, bind_len) < 0) {
        perror("Sendto");
        exit(1);
    }

    // For pathnamed socket
    // unlink(SOCK_NAME);

    struct sockaddr_un recv_addr;
    socklen_t recv_len = sizeof(recv_addr);
    char buffer[1024];

    ssize_t rx_count = recvfrom(rx_sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&recv_addr, &recv_len);

    if (rx_count < 0) {
        perror("Recvfrom");
        exit(1);
    }

    printf("Address size of TX on receiver side: %d\n", recv_len); // 0

    recv_len = sizeof(recv_addr);

    if (getsockname(tx_sock, (struct sockaddr *)&recv_addr, &recv_len) != 0) {
        perror("getsockname");
        exit(1);
    }

    printf("Address size of TX on sender side: %d\n", recv_len); // 2
}

Comment: Minor issue: `sizeof(PAYLOAD)` should probably be `strlen(PAYLOAD)`. You're getting the size of the pointer there. Otherwise, great question. Seems like a kernel bug. If the behavior is as intended then the man page needs an update. If you made the `SOCK_NAME` a real path like `/tmp/socktest`, and added an `unlink` before the `bind`, you'd have something portable to other Unices that don't have the "abstract namespace". It would be interesting to see if they do the same thing.
Comment: What's unclear about `has no name` and `sun_path should not be inspected`?  Why are you trying to write to it?
Comment: @stark I am writing to the path to bind the receiving socket to an abstract address
Comment: @WumpusQ.Wumbley Thanks for pointing that out, I made `PAYLOAD` an array in the code to use the correct size. I also tried using a pathnamed socket and the address also has length 0 on the receiving side
Comment: @MaxBenson: The **sending** socket is unnamed. The receiver already knows the address they're bound to. `recvfrom()` returns the sender address, and because it is unnamed, there is no sender address.
Answer: You have an unnamed unbound Unix domain datagram socket tx_sock, and an Unix domain datagram socket rx_sock bound to an abstract address in bind_path.
Note: According to man 7 unix, unbound Unix domain stream sockets are unnamed in Linux, and their address lengths will be sizeof (sa_family_t). According to POSIX.1, unbound socket addresses are unspecified, so we really need to be careful about what we expect of unbound socket addresses and their lengths. In this particular case, in Linux, using the man page as a guide, an unbound Unix domain datagram socket has no address, so its length is zero.  (It even makes sense: zero address length indicates you cannot reply to the sender. With an unbound stream socket, there is a connection back to the sender, but no other way to reply to the sender but the connection itself; that is why in that case the address length is then nonzero, sizeof (sa_family_t).)
Abstract Unix domain socket addresses are a Linux extension; they begin with a NUL byte (\0), and are not visible in the filesystem.
You use sendto(tx_sock, msg, msg_len, 0, bind_path, bind_path_len) to send a message.
You use recvfrom(rx_sock, buffer, sizeof buffer, 0, &recv_addr, &recv_addrlen) to receive the message (with recv_addrlen properly initialized to sizeof recv_addr).
Because tx_sock is not bound to any address, it is unnamed unbound: it has no address, cannot be replied to, and therefore recv_addrlen == 0.
If you add code to bind tx_sock to some other abstract address, you'll receive that address in recv_addr and recv_addrlen.
(I verified this behaviour with a test program using four threads, where each thread sends a message to each other thread, and prints all received messages and where they are from, with both standard addresses and abstract addresses. Everything works as documented.)
Comment: The man page states that an unbound and thus unnamed socket has an address length of 2 not 0. I added a call to `getsockname()` above, which confirms that reading the address of the TX socket on the TX side returns length 2, which is expected as per the man page, but reading the address of the TX socket on the RX side returns 0. So why does it return 0?
Comment: @MaxBenson: Ah, now I see the reason for the confusion. I edited my answer to make it hopefully clearer. You see, the term *"unnamed socket"* term only applies to stream sockets, not datagram sockets. To make my answer clearer, I used the term *"unbound"* to indicate a non-connected, non-bound socket. Simply put: *"bound"* -> full address, can respond; *"unnamed"* -> empty address, but can still respond (because a connected stream); and *"unbound"* -> no address, cannot respond.
Comment: I guess your explanation does add up, but I find the man page on this subject confusing. If the behaviour of returning 0 instead of 2 for datagram protocol really is standartized then the man page should mention this fact.
Comment: @MaxBenson: It only applies to Linux (POSIX.1 leaves it undefined!), but definitely the man page could/should describe the behaviour better. There are [easy mechanisms](https://www.kernel.org/doc/man-pages/reporting_bugs.html) for reporting these, but the hard part is getting the wording right. Knowing Kerrisks work, I am sure a clear additional paragraph to describe this [in patch form](https://www.kernel.org/doc/man-pages/patches.html) would be appreciated and included quite quickly. I'm not sure *my* English-fu is up to that task, though.
Answer: Of course you're getting a name length of zero.
The first value in your char array is 0, immediately terminating the string to a length of zero bytes:
const char SOCK_NAME[] = { 0, 't', 'e', 's', 't' };

unnamed: A stream socket that has not been bound to a pathname using bind(2) has no name.

does not apply, because you are using bind() to bind the socket:
Comment: I am clearly not calling `bind()` on the unnamed transmitting socket
Comment: @AndrewHenle: It is the receiving socket that is bound; the sending socket is not. I got initially tripped by this, too.


Sports with multiple balls

Question: What are the competitively played sports which players use multiple balls at the same time?
I'm not counting games that are played in specific regions. Let's say there should be international matches and championships to consider it to be competitive. Also let's not count golf. There are multiple balls, but each player only handles one ball, and players are not allowed to use any other players' ball. Furthermore, lets not consider sports that use multiple balls throughout the game, but in rotation, such that only one ball is used at a time.
Comment: @PhilipKendall I don't see a problem since this is a list of finite set. We can make a community answer of all responses. See https://sports.meta.stackexchange.com/questions/548/community-wiki-for-list-type-questions
Comment: Would bowling count?  Pro bowlers generally use 2-3 balls a game, even more for some guys, depending on the lane conditions.
Comment: I'm gonna say no. As the question mentions, there should be multiple balls taking part of the game at the same time. Bowling is rather a rotation of balls
Comment: I edited the question to specifically mention rotation of balls doesn't count. You can use the same argument that multiple balls are used to play tennis, volleyball, soccer, football ...
Comment: Also, this fits well. ***Most sports require one ball. Wrestling requires two.***
Comment: Sorry, but voting to close as "too broad". List-type questions are a bad fit for Stack Exchange's Q&A format.
Comment: I can suggest you to take alook at this [list of ball games](https://en.wikipedia.org/wiki/List_of_ball_games). You can discover very rare (and not so rare) sports played around the world
Comment: @Ale I have. Some are regional, and I don't count some as sports. And most use only 1 ball
Comment: In a world where board games advanced a ton in the past decade or two, from Ticket To Ride style games (where the aim is different each game) to Catan games (where the layout itself can be different each game) and then to Risk Legacy, which looks interesting in that the results of every game adjust the rules for all future games... it's disappointing there aren't more dynamic, active sports showing up. A game where multiple opponents put balls into play coincidentally could be a top notch game. But only dodgeball seems to do this. Wonder if this question has touched upon a future era to come.
Comment: I've also played wallball and foursquare with multiple balls, but cannot find anything with much competition to those formats.
Comment: Looks like soccer also has experiments with multiple balls.  [Two balls](https://www.soccercoachweekly.net/soccer-drills-and-skills/small-sided-games/multi-ball-game-to-improve-soccer-thinking-skills/) are often used in drills, and some coed games use [three balls](http://youthgroupgames.com.au/games/35/three-ball-soccer/). They each sound popular in spots, but haven't gained a large enough following for any significant international competitions that I'm aware of. Though honestly, they don't sound quite as neat as [three sided football](https://en.wikipedia.org/wiki/Three_sided_football)
Comment: @CodeNewbie If I understand what you mean, that is not true, there is women's wrestling.
Answer: Billiards is a internationally competitive sport which incorporates at most 16 balls in a game. There are other games that can be played on a billiards table such as, seven-ball, eight-ball, nine-ball, ten-ball, cut-throat, straight pool etc. One ball (cue ball) is used to hit other balls (stripes or solids) into the side and corner pockets.
Comment: This is the only multiple ball sport that I could think of that is internationally competitive. Even if there are other sports that involve multiple ball play, billiards is by far the most popular multi-ball sport.
Comment: Just did. Hopefully we'll get some more answers
Comment: Hopefully! I am wanting to know some other sports
Answer: Bocce and it's variants. Normally, played on a flat court (13 feet wide, 91 feet in length) with one small ball (called also jack/boccino/pallino) and each team having 4 big balls. In the simplest variant, there are 2 players/teams.
Action

The 1st player throws the jack on the pitch. Then he bowls one of his
4 balls. Then the 2nd player bowls one of his 4 balls. From then on,
the side which does not have the ball closest to the jack has a chance
to bowl, up until one side or the other has used their four balls.
Then the other side uses its remaining balls.

Scoring

The team with the closest ball to the jack is the only team that can
score points in any frame. The scoring team receives one point for
each of their balls that is closer to the jack than the closest ball
of the other team. The length of a game varies by region but is
typically from 7 to 13 points.

Here is a video that shows and explains the rules in an easy way.
Interestingly, I learned this game from Assassin's Creed video game.
Answer: Dodgeball uses 6 balls. There are tournaments and leagues for it near me and I am sure that there has been international tournaments before.
Answer: Petanque or jeu des boules uses 3 balls for each player and a small target.
Not being able to comment on billiards. The game of snooker uses 22 balls on the table.
Answer: How about the sport of Quidditch? It is a game inspired from a work of fiction, but its rules have been formally defined. there is an international regulatory body for the sport, the International Quidditch Association and there have been international and regional championships for the sports too, such as the IQA World Cup.
Having established the validity of Quidditch as a sport, here is how it is a valid answer to your question. Quidditch is played using 5 balls at the same time. One quaffle, three bludgers and one snitch. The snitch typically comes into play after a certain amount of time has elapsed, so at any time, at least 4 four balls are in play at the same time.
Answer: The group all-around competition speciality involves the use of more than one ball (here a video of WC 2012).
In individual competition each athlete use one rubber ball, while during the group there are more balls on the floor area.
Answer: Let's not forget croquet.
Here are the rules... looks like all forms use 4 balls (2 per pair).  Apparently there also can be 8 separate colored balls when 2 games are being played on one court, called double banker... but unfortunately it appears there's basically not any interaction between the games, as balls are market, and balls deflecting off the balls being used in the other game are replaced.

Sports with multiple balls


Match e-mail addresses not contained in HTML tag

Question: I need to highlight an email addresses in text but not highlight them if contained in HTML tags, content, or attributes.
For example, the string email@example.com must be converted to firstname.lastname@example.com
But email addresses in the string email@example.com must not be processed.
I've tried something like this regexp:
(?<![":])[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}(?!")
but it doesn't work properly.
Comment: duplicate: http://stackoverflow.com/questions/401726/regex-that-only-matches-text-thats-not-part-of-html-markup-python
Answer: I'll guessing that your source text is an HTML file which is missing anchor tags for only some of the contained e-mail addresses. If this is true, then you will not be able to use a regexp to reliably match only untagged e-mail addresses. For example, given the input:
...

You'll find a lot more written by

firstname.lastname@example.com
.

...

it becomes impossible to lexically associate the href with the address and also exclude email@example.com. You need to use an HTML parser; BeautifulSoup is pretty popular.


Não aplicar regra de CSS em apenas uma página

Question: Tenho uma classe em CSS que eu gostaria que não fosse aplicada quando eu estiver em uma página: exemplo.com.br/teste
Tem como eu fazer isso com alguma regra do CSS?
Essa é a classe:
.section-name {
    display: none;
}

Comment: infelizmente não, o correto seria criar uma classe com nome diferente e aplicar ou não quando necessario.
Answer: Você pode botar uma classe exclusiva no bodyda sua página. Por exemplo, na página exemplo.com.br/teste, voce poderia colocar a classe: exclusive no body. Depois no seu CSS você coloca:
body:not(.exclusive) .section-name {
    display: none;
}

Nesse caso ele seria aplicado em todos os .section-name, a não ser que aquela classe esteja aplicada no body.
EDIT - WORDPRESS
Como você pediu por Wordpress, eu vou dar alguns conselhos. Porém tem um tempo que não trabalho com Wordpress. Enfim, você pode ainda usar a técnica que eu te mostrei acima, só que você vai precisar de uma maneira de adicionar o final da sua url como uma classe da body da página.
No Wordpress eles chamam isso de Page Slug, e você pode procurar por plugins que fazem isso automaticamente, como esse.
Procurei saber também, mas não tenho como testar no momento, mas aparentemente, colocando esta função no functions.php do tema, terá o mesmo efeito:
//Page Slug Body Class
function add_slug_body_class( $classes ) {
    global $post;
    if ( isset( $post ) ) {
        $classes[] = $post->post_type . '-' . $post->post_name;
    }
    return $classes;
    }
    add_filter( 'body_class', 'add_slug_body_class' );
}

Comment: Esqueci de mencionar que é Wordpress. As páginas são criadas dinamicamente.
Comment: Mas você consegue [adicionar classes ao `body`](https://code.tutsplus.com/tutorials/adding-to-the-body-class-in-wordpress--cms-21077) com WordPress.
Comment: @FelipeStoker Dei uma atualizada.


What do you consider a new model versus an updated model (time series)?

Question: I am having some issues explaining to [non-statistician] people that it is natural to revise the parameters of a time series (ARIMA) model if you update the model with new data (add new actual values and move the forecasting point forward).
I say: The model is predicting new values of the series based on recent and older values in the series.  If I have new data points and wish to forecast from time t2 rather than point t1 (t2 > t1) then I have to update the model with data between t1 and t2, otherwise I am really forecasting from t1.  This is natural for time series.
They say: Your model coefficients have changed value, therefore you have developed a new model.  You should keep the coefficients the same even with the new data.
The reason for this debate is that I was instructed not to build a new model.  In their opinion, I have built a new model.  In my opinion, I have not.  Semantics aside, I have three main questions:
(1) Am I wrong?  I freely admit that the model may no longer be the "best" model: whether it is the best or most suitable is not at issue. Fundamentally, the question is about when a model should constitute a "new" model.
(2) Is there a practical, not-fundamentally-flawed way to do what they ask, namely to use the time series model with more recent data without changing the coefficients?  The only ways I can think of are: (a) just forecast from the original point but use actual data where actual data exists, and (b) chop out the time between t1 and t2, so that the forecast period begins at t1.  (I should point out that this is technically an ARIMAX model because I use a forecasted macroeconomic variable as an input.)
(3) Assuming I am not wrong, does anyone have a source that might help explain time series to people who know zero statistics.
Comment: In my understanding, the updated (only coefficient values changed) model is a new or another model. But it is not new kind or type of model. It is still a semantic question, so "model has changed" is vague; it's better to be specific: either "model refreshed its parameters" or "type of model changed". In time-series, one usually wants the model to remain a good forecaster for considerable time without any update of parameter values; but this wish is often unrealistic.
Comment: I must admit I get a bit confused myself. Typically with an exponential smoothing model you would not re-estimate alpha (in fact, with a short time series you might not estimate it in the first place, just "borrow" an alpha from a similar series).   Yet with ARIMA models "there are no easy ways to update the parameters of an ARIMA model as new data become available, as there are in some smoothing methods."  (Hanke and Wichern, Business Forecasting, 9th ed. p. 444)  QUESTION: What about ARIMA models that map to smoothing models, e.g. (0,1,1) without constant and single exponential smoothing?
Answer: The question you raise is quite important. WE have implemented the CHOW Test for constancy of parameters in order to test the hypothesis that the parameters haven't changed significantly at one or more points in time. If we detect a significant change then we can then use the most recent data set to develop a new model. This test requires ( at least for us who know time series ) that any anamolous data points have been rectified/corrected via Intervention Detection procedures ( see R. Tsay's work ). If you want to pursue this topic please feel free to contact me off line and I will try and help you.


Filter a nested arrays of structs and return the child object in swift

Question: I have read multiple discussions about filtering nested arrays in swift, however they all return the parent object.
Let's have these simple data:
struct MenuSection: Identifiable {
    let id: id
    var name: String
    var menuRows: [MenuRow]
}

struct MenuRow: Identifiable, Hashable {
    let id: id
    var name: String
}

private let menuSections: [MenuSection] = [
    MenuSection(id: 0, name: "Menu Group 1", menuRows: [
        MenuRow(id: 0, name: "Menu 1")
    ]),
    MenuSection(id: 1, name: "Menu Group 2", menuRows: [
        MenuRow(id: 1, name: "Menu 2"),
        MenuRow(id: 2, name: "Menu 3")
    ])
]

My goal is to get the MenuRow with its id.
So, I create this function and it works:
func getMenuRowWithId(menuRowId: id) -> MenuRow? {
    for menuSection in menuSections {
        for menuRow in menuSection.menuRows {
            if menuRow.id == menuRowId {
                return menuRow
            }
        }
    }
    return nil
}

However, I want to do something more swifty (and maybe more efficient).
I tried something like:
var filtered = menuSections.filter { $0.menuRows.filter { $0.id == 1 }.count != 0  }

but it's returning the MenuSection containing the right MenuRow.
=> I only want the menuRow.
I have tried many things, such playing with compactMap/flatMap to flatten the array before filtering. No way.
How can I browse the menuSections and obtain ONLY the right menuRow ?
Thanks
Comment: If each id is unique or you only care about the first match then you can do `menuSections.flatMap(\.menuRows).first(where: { $0.id == 1 })`
Comment: @alex.bour That's a [keypath](https://sarunw.com/posts/what-is-keypath-in-swift/) which since Swift 5.2 ([SE-0249](https://github.com/apple/swift-evolution/blob/main/proposals/0249-key-path-literal-function-expressions.md)) can implicitly converted to a closure. In this context, it's the same as `.flatMap({ $0.menuRows })`
Comment: In your example you have more than one MenuRow object with the same id yet you only want one object returned. How is that supposed to work?
Comment: Sorry Joakim. I maded the change for all ids to be unique. (in fact, I used UUID but I simplify the post with Int as IDs.
Comment: Fine then my code above solves your problem, right?
Comment: Yes, it's working ! Thanks a lot Joakim. I wasn't using flatMap like you. Can you just tell me what means the "\" before menuRows and why it's required ?
Comment: @JoakimDanielson You should post your solution as an answer so the OP can accept it.
Answer: You can use flatMap first to get all MenuRow objects in one array and then find the correct object in that array using first(where:)
let menuRow = menuSections.flatMap(\.menuRows).first(where: { $0.id == 1 })


Interpretation of a PDE

Question: Let us say that I have the partial differential equation,
\begin{align}
\frac{\partial W}{\partial t}=(b-a)\partial_p\partial_qW -(\dot{a}\partial_p^2+\dot{b}\partial_q^2)W\,,
\end{align}
where $a=a(t)$, $b=b(t)$, and $W=W(q,p,t)$. As this looks similar to the diffusion equation, my guess is that the last term represents the diffusion with respect to $p$ and $q$. Is there a physical meaning for the $(b-a)\partial_p\partial_qW$ term? Alternatively, is this differential equation known by a specific name?
Comment: What is $W$? Is it a function of $t$, $p$ and $q$?
Comment: Yes - I've edited the question to include it.
Answer: I don't think the $\partial_p\partial_qW$ term can be interpreted in isolation. The entire PDE is an anisotropic diffusion equation
$$\frac{\partial W}{\partial t} = \nabla\cdot(\mathbf D\,\nabla W)$$
where $\mathbf D$ is the diffusion coefficient matrix, in this case
$$\mathbf D=\begin{bmatrix}-\dot b & \frac12(b-a) \\ \frac12(b-a) & -\dot a\end{bmatrix}.$$
I believe the matrix $\mathbf D$ needs to be positive definite for the equation to be well-posed.
Answer: If we look carefully and replace
$p \implies X$
$q \implies Y$.
So that we can relate X- and Y- with space co-ordinates.
Then,
$W = f(X, Y, t)$
This makes the things easy and the given equation is comparable to damped wave equation.
Comment: I don't see how it is comparable. Can you explicitly compare them and point out the similarities?

Interpretation of a PDE


Como adequar APP que utiliza protocolo TCP a conexão 3g?

Question: Estou desenvolvendo um APP para Android e utilizei conexão TCP direta e também requisições HTTP.
Para o perfeito funcionamento do meu aplicativo estando conectado em uma rede 3g ao invés do WiFi, preciso modificar meu código? Ou a conexão 3g é gerenciada pelo sistema operacional Android?
Como a conexão 3g envia e recebe pacotes TCP/IP para um servidor conectado a internet? Como é o funcionamento exatamente?
Answer: Ao nível da aplicação, normalmente, não temos que nos preocupar com o tipo de ligação de dados que está disponível no dispositivo.
O sistema operativo é quem tem essa preocupação e gestão.
Respondendo diretamente à tua pergunta:
Não, não tens que modificar o teu código, tudo deverá funcionar corretamente.

#Preocupação a ter aplicação
Na aplicação, temos que nos preocupar sim, em verificar se existe alguma ligação para permitir e/ou realizar operações que a requerem:
###Permissões
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

###Exemplo de verificação
Com estas permissões podemos consultar no dispositivo, qual o estado a ligação:
public void myClickHandler(View view) {
    ...
    ConnectivityManager connMgr = (ConnectivityManager)
        getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        // Temos ligação, continuar
    } else {
        // Não temos ligação, informar utilizador
    }

    // ...
}

Este exemplo e outros podem ser consultados e analisados em detalhe na página de documentação para:
Connecting to the Network | Android Developers (Inglês)

#TCP/IP sobre 3G
TCP/IP está presente em dispositivos que disponham do serviço GPRS que por sua vez se encontra disponível nas tecnologias de comunicações móveis a partir da 2ª Geração.
Dado que um dispositivo com suporte e a fazer uso de TCP/IP recebe pelo menos um endereço IP, a comunicação a partir do mesmo é igual à comunicação em qualquer PC ou servidor ligado à Internet.
Leitura relacionada:

RFC 3481 - TCP over Second (2.5G) and Third (3G) Generation Wireless Networks
Wikipedia: General packet radio service (GPRS)
Wikipedia: 3G

Nota: As particularidades sobre o funcionamento de todos estes serviços e protocolos já fica fora do escopo deste site, pelo que não vou elaborar mais sobre o assunto nesta resposta.


Download roles are not working on Read the Docs

Question: I'm trying to get a download link to work in Read the Docs using reStructuredText (reST) and Sphinx. In the reST documentation for the download role the example to provide a download link is given as
.. only:: builder_html

   See :download:`this example script <../example.py>`.

When making the html source locally the links appear, but when using a GitHub linked project on Read the Docs, they do not.
Answer: As explained in this GitHub Issue Read the Docs uses its own builder called readthedocs. Thus, to include the download links you must also include this builder. For example
.. only:: builder_html or readthedocs

   See :download:`this example script <../example.py>`.


YouTube API v3 search - don't return all videos

Question: I'm using YouTube API v3 and here is my problem:
For example this video:
https://www.youtube.com/watch?v=MHKMfkiq1OA
https://www.googleapis.com/youtube/v3/videos?part=snippet&key=My_Keys&id=MHKMfkiq1OA

was published at 2013-04-02T11:40:24.000Z
By when i try search for this movie using search engine like this:
https://www.googleapis.com/youtube/v3/search?part=snippet&order=date&key=MY_KEY&publishedAfter=2013-04-02T11:40:20.000Z&publishedBefore=2013-04-02T11:40:30.000Z

There is no result for this search, why?
Answer: Basically, "publishedBefore" and "publishedAfter" aren't really search parameters, but are more like filters that are applied to search results. If your API call only includes those two parameters, then there is nothing to base a search on. Notice that with this call:
https://www.googleapis.com/youtube/v3/search?part=snippet&order=date&q=movies&key=MY_KEY&publishedBefore=2013-04-02T11:40:24.300Z&publishedAfter=2013-04-02T11:40:20.000Z

The single video is returned. In essence, omitting the 'q' parameter is like telling YouTube to search for an empty string.
Comment: But in https://developers.google.com/youtube/v3/docs/search/list the q parametr is listed as optional parametr. Also empty string is existing in every string so when i don't specify they q parametr it should return EVERY video. Am i wrong?
Comment: It's optional in the sense that you won't get an error when you don't include it. But not specifying the q parameter does not mean "return all," in the same way that submitting a blank Google search doesn't mean "return all web pages." There are perfectly good reasons why you might omit the 'q' parameter ... for example, you can do a channelId or a topicId search instead. But the YouTube algorithms just don't really have a sense of date-based searching in the way you're hoping for, unfortunately.


How do I tell Entity Framework to use SQL Server Compact in code first?

Question: How do I change my app.config or Migration Configuration.cs file so Entity Framework uses a local SDF file instead of a local SQL Server instance ?  I am using EF 6.1.
Thanks
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>

  </configSections>
  <entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory,  EntityFramework" />
<providers>
  <provider invariantName="System.Data.SqlClient"   type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>

Answer: You should just be able to specify the ProviderName in the connection string to your database.
<connectionStrings>
<add name="DataModelContext"
     providerName="System.Data.SqlServerCe.4.0"
     connectionString="Data Source=location\cfdb.sdf"/>

Comment: And install the EntityFramework.SqlServerCompact nuget package
Comment: Yep, I shouldn't have assumed that.


Passing variables into SLOTs - QSignalMapper

Question:
I am trying to use the same image upload function for both the images upload.
So on click of the Upload button, I need to pass either self.UploadStudentPhoto or self.UploadParentsPhoto to self.UploadFile() function, corresponding to which button is pressed.
As we cannot pass a variable into a SLOT, so I am trying to use QSignalMapper, as below.
self.UploadStudentPhoto = QLineEdit() #Student Photo location
self.UploadParentsPhoto = QLineEdit() #Parents Photo location
self.ParentsImage = None

self.SignalMapper = QSignalMapper()
self.connect(self.ButtonUpload1,SIGNAL("clicked()"),self.SignalMapper, SLOT("map()"))
self.connect(self.ButtonUpload2,SIGNAL("clicked()"),self.SignalMapper,SLOT("map()"))

self.SignalMapper.setMapping(self.ButtonUpload1, self.UploadStudentPhoto)
self.SignalMapper.setMapping(self.ButtonUpload2, self.UploadParentsPhoto)

But I am not sure about the below line where I need to pass SIGNAL("mapped()") to a function I wrote for file upload. How should I write the below line:
self.connect(self.SignalMapper,SIGNAL("mapped()"), self, self.UploadFile)

upload file function is below:
def UploadFile(self, ImagePath, ImageLabel):
    dir = os.path.dirname(".")
    formats = ["*.%s" % unicode(format).lower()\
        for format in QImageReader.supportedImageFormats()]
    self.fname = unicode(QFileDialog.getOpenFileName(self,"Image",dir,"Image (%s)" % " ".join(formats)))
    print self.fname
    ImagePath.setText(self.fname)
    ImagePath.selectAll()
    ImageLabel = QImage()
    ImageLabel.setPixmap(QPixmap.fromImage(ImageLabel))

I saw many QSignalMapper examples but I am not sure how exactly the variable is passed.
Please suggest.
Answer: Actually, It can pass a variable into connect  & SLOT, by use partial module in python;
For my opinion, I suggest use 'simple' (I think)  to implement, I will show you in code below;
from functools import partial
.
.
.
        self.StudentPhoto = QLabel() # I know you have this.
        self.ParentsPhoto = QLabel() # I know you have this too.
        self.UploadStudentPhoto = QLineEdit()
        self.UploadParentsPhoto = QLineEdit()
        self.connect(self.ButtonUpload1, SIGNAL("clicked()"), partial(self.UploadFile, self.UploadStudentPhoto, self.StudentPhoto))
        self.connect(self.ButtonUpload2, SIGNAL("clicked()"), partial(self.UploadFile, self.UploadParentsPhoto, self.ParentsPhoto))
.
.
.
    def UploadFile(self, ImagePath, ImageLabel):
        dir = os.path.dirname(".")
        formats = ["*.%s" % unicode(format).lower()\
            for format in QImageReader.supportedImageFormats()]
        self.fname = unicode(QFileDialog.getOpenFileName(self,"Image",dir,"Image (%s)" % " ".join(formats)))
        print self.fname
        ImagePath.setText(self.fname)
        ImagePath.selectAll()
.
.
.

Example reference : http://www.learnpython.org/en/Partial_functions
Official reference : https://docs.python.org/2/library/functools.html

Regards,


TypeError: Cannot read property 'files' of undefined

Question: Tenho seguinte trecho de código para upload storage firebse estou utilizando typescript.
uploadPhoto(photo) {
//Get File
this.file = photo.files[0]; // Erro nessa linha

this.metadata = {
  'contentType': this.file.type
};

//Create a storage ref
this.storageRef = firebase.storage().ref().child('images/');

// Upload file
this.storageRef.put(this.file, this.metadata);

}

ele dar seguinte erro:
TypeError: Cannot read property 'files' of undefined

Answer: Esse tipo de erro TypeError: Cannot read property 'files' of undefined geralmente ocorre por que o valor está perdido, seja por não passar o parâmetro ou por que ele não foi obtido ou setado. Se você percorrer o código desde o inicio, vai perceber que em algum momento esse valor foi perdido.
Comment: estou passando: uploadImage() {
    this.userProvider.uploadPhoto(this.photoField);
  }
Comment: Verifique o `this.photoField`. Ele deve estar como undefined.


NullPointerException/ Button findViewById

Question: Galera to com um problema nesse código: toda vez que eu coloco:
'Button botao = (Button) findViewById(R.id.botao_id);'

Ele para de funcionar, não roda mais no meu celular. E se eu tirar esse código ( e as coisas relacionadas a ele, ele volta a funcionar).
Pedi pro meu amigo testar na máquina dele e funciona perfeitamente.
Tentei ler algo relacionado a NullPointerException, mas não consegui resolver meu problema...
Java CODE:
package com.example.android.justjava;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.Button;

import android.widget.TextView;

import java.text.NumberFormat;

public class MainActivity extends AppCompatActivity {

    int quantity = 0;
    Button botao = (Button) findViewById(R.id.botao_id);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void increment(View view) {
        quantity = quantity + 1;
        display(quantity);
    }

      public void minus(View view) {
        if(quantidade>0) {
            quantidade -= 1;
            display();
        }
        if(quantidade==0){
            botao.setClickable(false);
            botao.setTextColor(Color.rgb(153,153,153));
        }
    }

    public void submitOrder(View view) {
        displayPrice(quantity * 5);
    }

    private void display(int number) {
        TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
        quantityTextView.setText("" + number);
    }

    private void displayPrice(int number) {
        TextView priceTextView = (TextView) findViewById(R.id.price_text_view);

    priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
    }
}

XML CODE:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/coffee"
android:gravity="center"
android:orientation="vertical"
tools:context="com.example.android.justjava.MainActivity">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="Compre Seu Café"
    android:textColor="#fff"
    android:textSize="50sp" />

<TextView
    android:id="@+id/textView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="16dp"
    android:gravity="center"
    android:text="Quantidade"
    android:textAllCaps="true"
    android:textColor="#fff"
    android:textSize="30sp" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal">

    <Button
        android:id="@+id/botao_id"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="8dp"
        android:clickable="false"
        android:onClick="decrement"
        android:text="-"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/quantity_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="0"
        android:textColor="#fff"
        android:textSize="30sp" />

    <Button
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:onClick="increment"
        android:text="+"
        android:textSize="30sp" />
</LinearLayout>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="16sp"
    android:layout_marginTop="16dp"
    android:gravity="center"
    android:text="Preço"
    android:textColor="#fff"
    android:textSize="30sp" />

<TextView
    android:id="@+id/price_text_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="R$0,00"
    android:textColor="#fff"
    android:textSize="30sp" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    android:onClick="submitOrder"
    android:text="Pedir"
    android:textSize="30sp" />

Erros encontrados no Android Monitor
07-22 15:45:46.260 18338-18338/com.example.android.justjava E/AndroidRuntime: FATAL EXCEPTION: main
                                                                          Process: com.example.android.justjava, PID: 18338
                                                                          java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.justjava/com.example.android.justjava.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2561)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
                                                                              at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                              at android.os.Looper.loop(Looper.java:154)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6123)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
                                                                           Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
                                                                              at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:120)
                                                                              at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:155)
                                                                              at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:31)
                                                                              at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:55)
                                                                              at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:33)
                                                                              at android.support.v7.app.AppCompatDelegateImplN.<init>(AppCompatDelegateImplN.java:33)
                                                                              at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:201)
                                                                              at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
                                                                              at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
                                                                              at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
                                                                              at com.example.android.justjava.MainActivity.<init>(MainActivity.java:17)
                                                                              at java.lang.Class.newInstance(Native Method)
                                                                              at android.app.Instrumentation.newActivity(Instrumentation.java:1100)
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2551)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
                                                                              at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                              at android.os.Looper.loop(Looper.java:154)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6123)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)

Answer: Você tem que colocar o findViewById(R.id.botao_id) dentro do método onCreate() de sua activity. Veja como deve ficar:
Button botao;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    botao = (Button) findViewById(R.id.botao_id);
}

Comment: Falta também o método `public void decrement(View view)` para esse botão.


Are components really faster compared to templates?

Question: I decided to compare speed of components with ko 3.2 versus other template engines by adding components test in the following jsperf:
http://jsperf.com/knockout-template-engines/19
The results are really puzzling me, since I see components to be 98% faster than regular templates. I feel I am doing something wrong, but unable to figure out.
Can some expert shed some light on this? Is this performance real or I am seeing incorrect benchmark results?
Comment: components load asynchronously
Comment: I was about to say @RPNiemeyer would be the person to ask :)
Answer: It's hard to compare async performance with the other templates, but I hacked up the ko component test case (very ugly hack, sorry) to check that it's done on a setInterval: http://jsperf.com/knockout-template-engines/21 just to get an idea.  It seems to perform comparably to the others.
A real-world example shows that this is not likely to be your performance bottleneck: https://metrics.wmflabs.org/static/public/dash/


Is my intuition behind the weight matrix correct for quantile regression?

Question: Motivating Question
I was asked by a colleague today why one would run a quantile regression on quantiles that are "extreme" (such as $.10$, $.90$, etc.), if there are too few observations in that quantile (say a total $n=200$ and the quantile contains some division of this number). This perplexed me, as this is the second time I've been asked this question but my way of explaining it may be limited. As it is my understanding, quantile regressions estimate conditional quantiles based on a weight matrix that observes all of the values in a distribution, and consequently the location of the quantile shifts the "fulcrum" of the weighting rather than only estimating that specific quantile's data points.
Indeed, when we run an OLS regression, we expect a naive estimate to be the mean of $y$, noted $\bar{y}$, and the conditional mean of $y$ to be the expected value of the conditional mean of $y$ given $x$, or $E(y|x)$. This is not estimated with just the values around the mean, but the entire distribution of values. Similarly for the quantile regression framework, we instead condition the expectation to be $Q(y|x)$ instead, where $Q$ is the conditional quantile of $y$. Because of the estimation method using absolute residuals rather than sums of squared residuals, my best guess of how to visualize this is to plot lines of residuals based on their weighting for a given distribution.
Solution
Here I have run some R code for a quantile regression which estimates $\tau = .25$, or the conditional 25th quantile. I have changed the size of the residual lines under the fitted line to resemble that the residuals here are given proportionate weights based on the fitting.
<code>#### Load Libraries ####
library(quantreg)
library(tidyverse)

### Sim Data ####
set.seed(123)
x <- rnorm(200)
y <- (.40 * x) + rnorm(200)
plot(x,y)

#### Fit Q25 Regression ####
qu <- .25
fit <- rq(
  y ~ x,
  tau = qu
)
summary(fit)

#### Plot ####
broom::augment(fit) %>%
  mutate(weight = ifelse(.resid > 0, "Higher","Lower")) %>%
  ggplot(aes(x=x,y=y))+
  geom_point(
    size = 3,
    color = "steelblue"
  )+
  stat_quantile(
    quantiles = .25
  )+
  geom_segment(
    aes(xend=x,
        yend=.fitted,
        linewidth = ifelse(weight == "Higher",
                           .25, .75),
        alpha = .3)
  )+
  theme_classic()+
  theme(legend.position = "none")+
  labs(x="Simulated X",
       y="Simulated Y",
       title="Weighted Observations for Q25")
</code>
Shown below:

Is this a correct way to visualize this? Is my understanding incorrect?
Edit
Whuber's advice provides a useful test case for my assumptions. Running the same regression with an extreme quantile of $\tau = .001$ gives us this:
<code>#### Load Libraries ####
library(quantreg)
library(tidyverse)

### Sim Data ####
set.seed(123)
x <- rnorm(200)
y <- (.40 * x) + rnorm(200)

#### Fit Q001 Regression ####
qu <- .001
fit <- rq(
  y ~ x,
  tau = qu
)
summary(fit)

#### Plot ####
broom::augment(fit) %>%
  mutate(weight = ifelse(.resid > 0, "Higher","Lower")) %>%
  ggplot(aes(x=x,y=y))+
  geom_point(
    size = 3,
    color = "steelblue"
  )+
  stat_quantile(
    quantiles = .001
  )+
  geom_segment(
    aes(xend=x,
        yend=.fitted,
        linewidth = ifelse(weight == "Higher",
                           .001, .999),
        alpha = .3)
  )+
  theme_classic()+
  theme(legend.position = "none")+
  labs(x="Simulated X",
       y="Simulated Y",
       title="Weighted Observations for Q001")
</code>
Which gives us this plot:

But this seems wrong on two fronts: 1) The values here are so extreme that there are literally no points where you can find residuals, which in the case I am considering this isn't reality (fitting to $\tau = .01$ gives similar results 2) the weighting of the lines now looks bad (perhaps based on poor coding) and so this doesn't instruct me further on what is wrong/right here.
Comment: Yes, I assume that because we use absolute residuals, we are weighting their magnitude based on where the quantile is fit, thus if there are a lower number of data points below $Q25$, then this is weighted appropriately to properly estimate the range of values that makes the residuals sum to zero in some sense.
Comment: Do you mean if the sum of the areas below equals the sum of the areas above?
Comment: What would be the equation that you expect to sum to zero? Do you just mean the [usual quantile loss](https://stats.stackexchange.com/a/629639/247274) function but without the absolute values? $$\sum_i \begin{cases}
      \tau( y_i - \hat y_i) & y_i - \hat y_i \ge 0 \\
      (1 - \tau)( y_i - \hat y_i), & y_i - \hat y_i < 0
   \end{cases}$$
Comment: Maybe "sum to zero" isn't the best way to explain that since I this is an OLS term. What I mean to convey through visualization is how the regression fit weights each data point based on location under/over the conditional quantile. In the OLS/Q50 sense we expect 50% of the values to lie above and below the regression line. With a Q25 regression, we expect 25% to fall below the line, where we weight this in some way OLS doesn't. So while I know how pinball loss generally works from previous explanations here (loss attributed to the sign of the residual), visualizing this weighting is unclear.
Comment: I believe that experimenting with a more extreme case will help you understand your colleague's point.  Try fitting, say, the 0.001 conditional percentile.
Answer: The OP wrote

As it is my understanding, quantile regressions estimate conditional quantiles based on a weight matrix that observes all of the values in a distribution,(...)

Two pieces of information on the matter

In the paper that introduced Quantile Regression, Koenker, R., & Bassett Jr, G. (1978). Regression quantiles. Econometrica, Theorem 3.1 tells us that the coefficient vector related to a quantile, is equal to a linear function of a subset of the sample.
Let $\{y,X\}$ denote the sample (dependent variable, regressor matrix), and let $h$ be a set containing some observation indices, with cardinality equal to the number of regressors (columns of $X$). So $\{y(h), X(h)\}$ represents some subset of the sample and $X(h)$ is a square matrix. Then Theorem 3.1 states, that for quantile probability $\tau$, the solution/optimizer vector is
$$\beta(\tau)^* = X(h)^{-1}y(h).$$
This, for example, means that if your regressor matrix has two columns (say, one constant and one variable), then the coefficient vector (for each $\tau$) will be determined by the above function of just two observations.

In Koenker's book "Quantile Regression" (2005), the author writes (p. 11)

One occasionally encounters the view that quantile regression estimators
must "ignore sample information" since they are inherently determined by a
small subset of the observations. This view neglects the obvious fact that all the
observations participate in which "basic" observations are selected as basic.

He refers to how the members of $h$ are chosen.
These properties of quantile regression come from the fact that it can be formulated as a linear programming problem.


Separable spaces in topology

Question: I have a few questions about separable space, as I'm trying to understand the meaning of the space having a countable dense subset:
1.Are separable spaces somehow linked to the set of real numbers (e.g. in terms of limitation of size)?
2.What properties do separable spaces have?
3.What purpose have separable spaces been used in the past in topology?
Any help will be appreciated.
Best regards,
Janne
Answer: A separable "metric" space has at most cardinality = c. (ie, cardinality of R)

Separable spaces in topology


Hbase client does not connect to local hbase server

Question: I am attempting to run simple Hbase client program which talks to Hbase server(standalone) to create a table and a single row.  However, unfortunately am seeing following exception while running through intelliJ.
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Initializing HBaseAdmin
log4j:WARN No appenders could be found for logger (org.apache.hadoop.security.Groups).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Hbase running, Creating table
Adding data into table
Exception in thread "main"  org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException: Failed 1 action: User: 1 time,
at org.apache.hadoop.hbase.client.AsyncProcess$BatchErrors.makeException(AsyncProcess.java:205)
at org.apache.hadoop.hbase.client.AsyncProcess$BatchErrors.access$500(AsyncProcess.java:189)
at org.apache.hadoop.hbase.client.AsyncProcess.getErrors(AsyncProcess.java:1042)
at org.apache.hadoop.hbase.client.HTable.backgroundFlushCommits(HTable.java:1037)
at org.apache.hadoop.hbase.client.HTable.flushCommits(HTable.java:1352)
at org.apache.hadoop.hbase.client.HTable.put(HTable.java:963)
at HbaseSample.main(HbaseSample.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Done

Client Program:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HBaseAdmin;

import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.*;

public class HbaseSample {
public static void main(String[] args) throws Exception {
    System.out.println("Initializing HBaseAdmin");
    Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.zookeeper.property.clientPort","2181");
    conf.set("hbase.master", "localhost:60000");
    HBaseAdmin admin = new HBaseAdmin(conf);
    try {
        HBaseAdmin.checkHBaseAvailable(conf);
        System.out.println("Hbase running, Creating table");
        HTable table = new HTable(conf, "User");
        Put put = new Put(Bytes.toBytes("msameer"));
        put.add(Bytes.toBytes("Info"), Bytes.toBytes("addr"), Bytes.toBytes("walnut creek"));
        System.out.println("Adding data into table");
        table.put(put);
    } finally {
        admin.close();
        System.out.println("Done");
    }
  }
}

My hbase-site.xml looks as follows:
<configuration>
<property>
  <name>hbase.rootdir</name>
  <value>file:///Users/msameer/Documents/Hbase/hbase-root</value>
</property>
<property>
  <name>hbase.zookeeper.property.dataDir</name>
  <value>/Users/msameer/Documents/Hbase/hbase-zookeper</value>
</property>
<property>
   <name>hbase.zookeeper.property.clientPort</name>
   <value>2181</value>
</property>
<property>
  <name>hbase.master</name>
  <value>localhost:60000</value>
</property>
</configuration>

Any help is very much appreciated.
Comment: what version of hbase?
Answer: Does your table already exist?  Because this code does not create a table:
HBaseAdmin.checkHBaseAvailable(conf);
System.out.println("Hbase running, Creating table");
HTable table = new HTable(conf, "User");

This will only use a table that already exists.  To create a table, you need to use HBaseAdmin:
HBaseAdmin.checkHBaseAvailable(conf);
System.out.println("Hbase running, Creating table");
HTableDescriptor des = new HTableDescriptor("User");
HBaseAdmin.createTable(des);

Take a look at the documentation for schema creation.  It also shows the updated API calls.  The classes starting with H are now deprecated.
Comment: Thanks very much Martin, yes the table was not created. Also, thanks for pointing to the right api docs.
Comment: your welcome.  note you can also upvote the answer if you like.
Comment: He don't have enough reputation to up vote. I agree that your answer is useful.
Comment: I will be sure to up vote once I have enough reputation. Just starting off on stack overflow.


"I-vi" in Major or "III-i" in Minor?

Question: There are some progressions that seem to move back and forth between a major key and its relative minor, like the "I-vi" progression (C, Am for example, two measures each.)
Most people would consider this a major progression (I do too), but I can't help but hearing both keys at the same time. For instance, the major third sounds also like the fifth of the relative minor. Not all progressions with a vi chord give a sense of minor tonality, but others really confuse me. For example (vi-IV-I-V) sounds also like (i-VI-III-IIX) : sometimes I feel like resolving to the minor tonic, other times to the major tonic.
Can one consider (i-VI-III-VII) a minor progression? Which is more correct from a theoretical standpoint? And how do you personally hear those progressions?
Answer: It is probably more likely that you're hearing deceptive cadences, which most commonly resolve from V-vi, but may in fact go to any chord.
I cannot speak to a particular progression because you haven't indicated what type of music you're listening to.
That said, sometimes (often) composers like to play with chord function for the very reason of your inquiry: it causes confusion and interest.  In order to determine the function of a chord or progression, there are a few things to help guide you:

Study more of their music - if you see this type of function reoccurring, chances are that it is stylistic and you can see it applied in different contexts.
If it is not current (modern day,) then learn more about the theory / practice of the time period it was written in.
Figure out the key of the section / piece where the progression occurs, if there is a key.  Deciphering the key will help determine the progression's function.
Look at how the notes in progression's chords are notated. If the notes in fact have a specific function, the notation should reflect that.

This list is not comprehensive nor chronological, but should help you get the ball rolling.
Lastly, "IIX" is not a roman numeral.  If you mean "8", then it would be written "VIII", but with chord progressions "8" means "1" so it would be easier to express it as "I".
Comment: There is no confusion. Am, F, C, G, (Am) is in natural A minor. G-Am is called a plagal or deceptive cadence, but those can just be regarded as names (whose choice reflects a particular musical doctrine). In fact the G-Am pull is very strong. The natural minor scale lacks the leading tone and so it does not support a V7-I cadence. It is a scale in its own right, and not something that is "based off" a relative major. The idea that the Ionian mode is "home" is historic revisionism.
Comment: I thought that a plagal cadence was IV - I, as in Amen. The cadence you feature is interrupted,usually ending on the relative minor.The Aeolian mode, aka natural minor, contains the same notes as the Ionian or major. However, it's rooted on the A  (in your example).The Ionian mode is usually thought of as "home" because it's the only full major mode - in the Western world.
Comment: @jjmusicnotes - 1st. para -"may in fact go to ANY chord "- bar the tonic- !!
Comment: I meant 7, now I fixed it. Thanks for answering. If I played the following progression to you : Am, F, C, G (no melody, 1,3,5,8 voicing) would you hear it as a minor or major progression?
Comment: That progression functions as a vi-IV-I-V in C major where the "Am" is not the one chord but the deceptive resolution from the "G" chord.  Just because the progression might begin with a minor chord doesn't mean that the first chord is also the "I" chord - those are two separate enterprises.
Comment: @Kaz, jjmusicnotes, Tim, you all explained the theoretical aspect of it. What I also wanted to know was how you heard it (all theory aside). And what about the C Am progression? It has no cadences, yet to me it sounds like each chord is in it's own key.
Comment: @Kaz - that is incorrect, the progression is clearly in C major.  A *plagal* cadence is from IV-I, not what you described.  The G-Am "pull" is strong because it is a deceptive cadence as the expectation is resolution to C major.  To Anthony - to answer your question, I hear it as a major progression.  When you isolate two chords it is easy to hear them as separate because there is no context for them.
Comment: @jjmusicnotes Hmm, I seem to have picked this loose/extended usage of plagal (not restricted to IV V) from somewhere. I have to fix that in the answer.
Comment: @Tim - by definition it is understood that a deceptive cadence may go to **any** chord *other* than the tonic.  http://www.merriam-webster.com/dictionary/deceptive%20cadence
Comment: This whole question can't help but make me think of Bob Marley... flip that progression around a bit to C,G,Am,F and you have No Woman No Cry (clearly C major, but you can play the hell out of Amin. blues over it regardless); or look at Redemption Song (G,Em,C,Am), two maj chords (I & IV) with their relative minors (G & Em with C & Am), you really have the freedom to make it either, the vi & iii are _both_ diatonic substitutions for I, sometimes you could call this "modal mixture" as well, put all the notes from all three chords on the staff together and the relationships are obvious.
Answer: Over a C Am progression, it is possible that the music changes mode from Ionian to Aeolian. Then, in effect, over that Am chord, the tonality has changed to A.  The written or improvised melodies in the music can support that by emphasizing the A note and the third and fifth above it.  Modal music can change tonality without changing the key signature. The modulation clues are weak in modal music, so of course it creates ambiguities for the listener. This is particularly true if the progressions are long, or if they linger on the same chord for many bars.
If you're writing out the chord changes in roman numerals, you have to pick a "home" which is labeled I. To do that, consider the music as a whole, and in particular how it starts and ends. If the music begins on and returns to the C Ionian mode, then you have a strong justification for defending the choice of C as the I note.
If you're analyzing music which shows strong signs of modulating, you may have to shift the identity of the I note. Or perhaps keep relating the notes to the original tonic, but show their functions within the new key, in parentheses.
For instance if music in C major music contains an A7 Dm secondary dominant, you can label these as VI7 II.  But in parentheses or whatever, you can also call it (V I) to show recognition that it's functioning as small embedded change of key to Dm.   The case for notating it this way is weakened if it's Am Dm rather than A7 Dm because the strong modulation signal is no longer there. Any sense of "we are in D minor, temporarily", if that is the intent, will have to be created by the music in less direct ways that are ambiguous.
Modes which do not have a leading tone do not support the V I cadence. In minor keys, we add the leading tone by altering to harmonic or melodic minor, and then we have V I.
When the V note of the relative Ionian occurs in a mode, before going to the tonic (of that mode) this is called a plagal cadence or interrupted/deceptive cadence, depending on the specific situation. However, this nomenclature is based on the assumption that the Ionian mode is the "master home" of modal music, and its V degree pervasively functions as a dominant, so that whenever it occurs, a cadence of some kind must be happening, and if it doesn't go to the I, it is somehow "false".
The term "plagal cadence" is useful in that everyone knows that it means, and therefore it communicates clearly. But in fact in music which is unambiguously in A natural minor, the G strongly pulls toward the A as a half step up, and has nothing to do with the G in C major that forms the V I cadence. It is a phenomenon in its own right.
The Ionian mode is not "home" and has not always been considered that; to believe so is historic revisionism.
Scales like Dorian and Mixolydian can be considered to exist in their own right, not simply as anagrams of the notes from the relative Ionian mode.
Comment: @Anthony The game of accepted answers and points and such doesn't matter so much. In music, there are multiple views on things and those do not usually contradict each other.
Comment: Usually I vi (in pop/rock) is given 2 or more bars per chord (it's sounds too boring with 1 bar/chord). I guess that's one of the reasons why it sounds like the vi chord is also a i chord. The song that confuses me the most is SRV's "Life Lithout You", it's two bars/chord and slow in tempo.
Comment: @Anthony - I don't support this answer as the correct answer to your question when it contains factual answers.  You should accept an answer because it is *correct* and not because it tells you what you want to hear.
Comment: @jjmusicnotes I forgot to accept yours, I wanted to accepted it right after you answered my comments. I believe your answer and Kaz's are complementary ; you explained from a classical standpoint, and Kaz gave a more recent (sort of) view.
Comment: StackExchange websites usually allow multiple accepted answers. Why can't a accept both here!? X( Now I remember I already had accepted jj's answer, but it was removed when I chose Kaz's
Comment: @Kaz - the points mean nothing to me; it is the principle that is important. To Anthony - my answer isn't "classical", it is the way music theory functions and is currently taught in accredited institutions. I am not sure where Kaz's view of modes is derived - modes even from the Baroque and earlier have been viewed and used "in their own right" - this is not a new concept.
Comment: @Kaz. Every mode has a leading note (tone). It's just that several of them are a whole tone below the tonic. I think what you mean is the leading note that is a semitone below the tonic.Again, you seem confused about the plagal cadence. Also - all the modes can be considered to exist in their own rights, but that rather depends on one's taste and experience in music.
Comment: @jjmusicnotes - often a question is posed by someone who doesn't know the answer, thus when a correct answer comes along, it's not recognised ! it's not like a teacher giving a test, already knowing what the answer should be !  Just a thought........
Comment: @Tim You're welcome to invent your own way of naming things in music that is consistent. My usage of "leading tone" is not my invention. What is called "leading tone" by mainstream music scholars is the semitone below the tonic. Scales that have a whole tone below the tonic do not have a leading tone. Their seventh is not called a leading tone but a "subtonic". If I'm confused about plagal cadences, you have to show that, not only say that it is the case. You may have some other view on these cadences which, on closer examination, might not conflict with mine.
Comment: @Kaz- the plagal cadence has only one sequence, IV-I, as in F-C in C major. As jjmusicnotes also states. I feel you're thinking of interrupted, or deceptive, as I mentioned earlier.Going from, say V-vi, is not regarded as plagal.I stand corrected about 'leading tone' and 'sub-tonic'. Thanks.
Comment: @Tim Amen, to that.
Comment: @Anthony No SE site allows more than one accepted answer.  You can choose the one that you find most helpful or none at all, and simply upvote.
Answer: Probably the strongest cadence is the perfect. So in a major key V-I will sound very final, as in G-C (more so if G7-C). In a minor key, V-I will feel stronger if it's E-Am, rather than Em-Am. To answer your question on a specific level: if it's the former, then a major feel is perceived; if the latter, E- or E7-Am, then it's going to feel minor. Going from G-Am hasn't the strong pull like G-C or E-Am, thus it's called "interrupted" — it's not the end, merely a break.
Answer: I don't believe there are major or minor progressions (unless ALL the chords in one are the same, obviously) as most progressions will contain both. The first chord OFTEN dictates whether it's in a  maj. or min.key, but a progression is just chords moving, usually within diatonic parameters.  Even if the chords/songs modulate, there is still a progression. Maybe a test would be to finish on a particular chord and ask the question "Does it sound/feel like it's come to an end?" If the answer is yes, then one could say the song is maj./min.,depending what sort of chord it 'ended' on.
Answer:
There are some progressions that seem to move back and forth between a
  major key and its relative minor, like the "I-vi" progression (C, Am
  for example, two measures each.)

There is no ambiguity in key here. Just because there is a minor chord in the progression does not influence key.

Can one consider (i-VI-III-VII) a minor progression?

You are somewhat mistaken on what chord progressions are. They are just a sequence of chords built on certain tone degrees of the scale.
Sometimes the chords are minor in a Major key and Major in a minor key. That just means that the details of the chord is either Minor Third / Perfect Fifth (Minor Chord) or Major Third / Perfect Fifth.
Don't confuse Major / Major chords with the Key tonality of the passage.

"I-vi" in Major or "III-i" in Minor?


Issue with XML Generating from C# Object

Question: I am trying to generate an XML file from an Object. I put a break  point before generating the XML file, so I can check the values. The object and its value look fine. However, after the XML file is generated, it is missing a key component, the code.
This is what I was expected to see.
<eDocument Code="UN" Cat="ST">
  <id myId="5"/>
</eDocument>

This is the actual xml file that is generated.
<eDocument Cat="EST">
  <id myId="5"/>
</eDocument>

This is the object that is being serialize to generate the xml file.
sDoc eDocument = new sDoc();
eDocument.Code = "UN";
eDocument.Cat = "ST";
eDocument.myId = new ID[1];
eDocument.myId[0].id= 5;

This is how I am saving the file
 string fileName= "student.xml";
 XmlSerializer serializeObject = new XmlSerializer(eDocument.GetType());
 TextWriter streamWritter = new StreamWriter(Server.MapPath(@"~/student/" + fileName));
 serializeObject.Serialize(streamWritter, eDocument); // I check the eDocument Object, and it has all the correct inforamtion
 streamWritter.Close();

Is there something that I am doing wrong here?
Comment: Show us the `sDoc` class.
Comment: Without showing the actual sDoc class code no-one can help you
Answer: You need to check the "Code" property in the sDoc class.
A property should be public read/write in order to be Xml-serializable. By default, if no attribute is applied to a public property, it is serialized as an XML element. In your case it's not serialized at all, which means something is wrong.
First check: is the property public in both read (get) and write (set)?
Second check: Isn't the field marked with [XmlIgnoreAttribute]?
And finally: Marking the Cat property with [XmlAttribute] will xml-serialize it as an attribute.
Comment: After reading your comment, I check my properties again. It was adding an additional attributes [System.ComponentModel.DefaultValueAttribute("UN")]. I removed it, and the code works fine.
Comment: Good to know, that's something I wouldn't be able to guess ;-).