Obter a frequencia a partir de um vetor no dominio da frequencia

Question: Estava olhando os seguintes tópicos:
https://stackoverflow.com/questions/7674877/how-to-get-frequency-from-fft-result
https://stackoverflow.com/questions/7649003/jtransforms-fft-in-android-from-pcm-data
Neles é explicado como realizar a transformada para poder obter a frequência de um som. Ele usa uma biblioteca que toma como entrada um vetor double no domínio do tempo e retorna um vetor no domínio da frequência usando o metodo realForwardFull();
Então se eu tenho um vetor no dominio do tempo (audioDataArray), cada posição desse vetor tem um valor de magnitude e ao fazer a transformada, o vetor fica no dominio da frequencia:
DoubleFFT_1D.realForwardFull(audioDataArray);

No domínio do tempo cada posição é a magnitude e o índice indica o tempo(x=índice; y = magnitude) pelo que pude entender. No domínio da frequência,  depois de aplicar a transformada, os valores de cada posição do vetor continuam a ser a magnitude(y)? O que representa os índices?

Para encontrar a frequência fundamental ele faz a conta a seguir para cada posição do vetor e compara para ver qual tem maior valor (magnitude):
Magnitude = sqrt(re*re + im*im)

Achando o índice que tem maior magnitude ele faz seguinte conta para achar a frequência fundamental:
Frequency = Fs * i / N

where:
Fs = sample rate (Hz)
i = index of peak
N = number of points in FFT (1024 in this case)

Não entendi essa conta: Por que para achar a frequência fundamental tem que multiplicar o índice pela taxa de amostragem e dividir pelo numero de posições do vetor?
Answer: Vamos lá gafanhoto lol
A transformada de Fourier vai lhe retornar unidades reais e imaginárias, é muito importante que você entenda de números complexos e matemática discreta.
Respondendo suas dúvidas:

No domínio do tempo cada posição é a magnitude e o índice indica o
  tempo(x=índice; y = magnitude) pelo que pude entender. No domínio da
  frequência, depois de aplicar a transformada, os valores de cada
  posição do vetor continuam a ser a magnitude(y)? O que representa os
  índices?

Y = retorno dos valores computados pela transformada de Fourier, valores dos componentes espectrais, estes valores podem ser utilizados para achar a Magnitude, para isso é preciso extrair a parte real e imaginária dos valores retornados pela transformada, para encontrar a magnitude a partir dos valores da transformada é necessário calcular a raiz quadrada da parte real ao quadrado mais a parte imaginária ao quadrado...
(sqrt((real(FFT).*real(FFT))+(imag(FFT).*imag(FFT))))

Portanto o Y inicial não é a magnitude o Y é o retorno da transformada, a magnitude você encontrou com a equação acima, você ainda pode utilizar uma equação derivada da mostrada acima e converter os valores em decibéis, também pode utilizar os valores da transformada para calcular diferentes tipos de descritores, ou ainda encontrar a fase do sinal analisado.
X = Índices de cada componente espectral calculado, isso quer dizer que quando você olha um plot das magnitudes no domínio da frequência, você está observando todas as frequências que compõe seu sinal e suas respectivas magnitudes, portanto x = período, isso é muito importante, a transformada de Fourier de um sinal periódico gera um espectro discreto no domínio da frequência, ou seja, é extremamente útil para fazermos análises em  sinais que se repetem em um intervalo de tempo T, claro pode ser utilizado para encontrar padrões de frequências em qualquer tipo de informação/dado.
O índice X(pense como período) possui uma ordem de resolução que depende totalmente do tamanho da amostra analisada pela Transformada de Fourier, se você enviar uma amostra de tamanho igual a 4096 terá uma ordem de resolução de 2.4414e-04 =  0.00024414062, em suas aulas básicas de física você deve se lembrar que a frequência e o período de uma onda é igual f = 1/T aplicando teremos  1/4096 = 0.00024414062, quanto menor a ordem de resolução, mais preciso será a periodicidade...

Não entendi essa conta: Por que para achar a frequência fundamental
  tem que multiplicar o índice pela taxa de amostragem e dividir pelo
  numero de posições do vetor?

Com o valor da taxa de amostragem nas mãos + o número de amostras do vetor enviado para Fourier é possível saber quais são as frequências correspondentes em cada X
Portanto cada índice corresponde a uma frequência, vamos imaginar que você gere 4096 componentes espectrais e que a taxa de amostragem do seu áudio seja de 44100hz, isso te daria uma ordem de resolução = 44100/ 4096 = 10,7666015625hz ou se preferir (1/4096) * 44100 = 10,7666015625hz
Isso quer dizer que a precisão de cada componente está perto de 11hz de diferença, a grosso modo você pode estar errando uma frequência na exatidão de 11hz em cada um dos 4096 índices/componentes, antes disso você tem que saber que existe um teorema chamado Nyquist, ele define que para reconstruir um sinal com mínimo de perda de informação a frequência amostrada deve ser igual ou maior a duas vezes a maior frequência do espectro desse sinal, se nossa frequência de amostragem é 44100hz então a maior frequência possível dentro deste sinal vai ser 44100/2=22050hz, mas e ai como saber quais frequências eu vou ter em cada componente espectral da série fourier:
  índice/componente 1 -> 10,7666015625000hz

  índice/componente 2 -> 21,5332031250000hz

  índice/componente 3 -> 32,2998046875000hz

  índice/componente 4 -> 43,0664062500000hz

  índice/componente 5 -> 53,8330078125000hz

    …

    …

    …

  índice/componente  2047 -> 22039,2333984375hz

  índice/componente  2048 – > 22050hz

Opa chegamos no componente 2048 que é a máxima frequência permitida pelo teorema de Nyquist.
isso te lembra alguma coisa Fs * i / N ? É a equação derivada para saber qual é a frequência correspondente de um determinado índice, quer tentar ?
Fs = 44100
N = 4096
i= ?

vamos aplicar na fórmula:
44100*1/4096 = 10.7666
44100*2/4096 = 21.5332
44100*3/4096 = 32.2998
44100*4/4096 = 43.0664

Então imagine agora que o pico da magnitude aconteceu no índice número 90, então de novo usando a fórmula 44100*90/4096 = 968.9941hz
Não sei se você sabe, mas o método acima não é nada recomendado na utilização de afinadores e captura de frequências,  o pico da magnitude nem sempre compõe a percepção correta de uma determinada frequência isso se deve ao fenômeno psicoacústico, mas esse é outro assunto, existem diferentes métodos de capturas de frequências no domínio do tempo e no domínio da frequência.
Respondendo as dúvidas dos comentários

Pode me recomendar algum livro ou curso online para me inteirar mais
  sobre o assunto. Quero me aprofundar sobre esse assunto de
  processamento de áudio

Aqui no Brasil não conheço cursos para engenharia de som, fora existe universidades conceituadas nesse assunto, o principio para manipulação de áudio que aprendi foi no meu curso de engenharia da computação, estudando análise de sinais na matéria de processamento digitais, o curso de engenharia elétrica aborda o tema de maneira mais completa, existe alguns cursos em áudio que eu recomendo na internet, princípios de engenharia de som e processamento de sinais voltado para música se prepare para entender de matemática...

Qual a equação para encontrar os valores em decibéis a partir do Y
  inicial que foi retornado pela transformada?

20 * log10((sqrt((real(FFT).*real(FFT))+(imag(FFT).*imag(FFT)))))

Se x é o período, então por exemplo, um vetor de 4096 posições com
  dados capturados a uma taxa de amostragem de 44100 terá em cada
  posição dados referente a 0,092879818 segundos (4096/44100
  =0,092879818 segundos) . Então se eu fizer 1/ 0,092879818 = 10,7666 Hz, seria a frequência de cada posição do vetor sendo 10,7666 Hz a
  menor e 44097,536 Hz (10,766 * 4096) a maior frequência que posso
  guardar?

para um sinal amostrado em 44100hz e com número de pontos 4096 a menor frequência é de 10,7666hz e maior será 22050hz
índice/componente  2048 – > 22050hz

por causa do teorema de Nyquist

Então se a ordem de resolução é de aproximadamente 10,766 Hz, ele não
  conseguiria distinguir uma frequência de 450 Hz de uma de 445Hz?

Exatamente, existem maneiras de amenizar esse problema aplicando interpolação parabólica dos índices vizinhos.

Não entendi por que você dividiu 1/4096 e achou essa ordem de
  resolução. Essa ordem de resolução é em relação a frequência ou ao
  período?

Frequência e Período são equivalentes, se você tem o período de um sinal você consegue saber a frequência, se você tem a frequencia de um sinal você consegue saber o período...

Com o vetor no domínio do tempo teria como eu saber quais frequências
  tem menor db e eliminá-las do vetor para se obter maior precisão na
  identificação da frequência com a transformada de fourier? Quais
  opções eu tenho para melhorar a identifiação da frequencia?

Improvável de fazer isso, mas você pode capturar frequências diretamente no domínio do tempo, existem diversos algoritmos para encontrar pitch/frequência sem a necessidade de utilizar a transformada de fourier, algumas técnicas, autocorrelation, ASDF, AMDF YUN eu gosto muito da AMDF escrevi um código e deixei open source no tarsos, só fiz o básico e não implementei alguns segredos nele, mas você pode usar como base para fazer o seu, alias os especialista e eu também prefiro algorítimos no domínio do tempo para encontrar frequências em áudios monofônicos.  Existem outros tipos de algoritmos no domínio da frequência que são melhores do que apenas achar o pico da magnitude, procure por subharmonic summation, Cepstrum e autocorrelação no domínio da frequência alguns deles possuem patentes e ninguém demonstra a mágica em código aberto;

Você disse que esse não é o melhor modo de se obter a frequência.
  Quais outros modos eu poderia utilizar, além desse que determina a
  frequência através da magnitude. Porque realmente eu vi um
  espectrograma de uma flauta e mesmo tocando uma nota, por exemplo,440
  Hz, a maior magnitude foi do segundo harmônico , 880Hz. Isso aconteceu
  com duas notas que não me recordo agora. Ou seja, realmente a
  frequência da maior magnitude não representa a frequência da nota

Utilize algoritmos mais inteligentes do que somente pegar o pico da magnitude, procure pelos algoritmos indicados na resposta anterior, o erro que você descreveu da flauta é conhecido como erro de oitava, os algoritmos citados acima também podem sofrer do mesmo problema, um detector de frequência esperto consegue lidar com isso, alias esse tipo de problema é complicado de contornar, é tão complicado que existe patentes descrevendo como pegar o pitch(frequência) correto, uma maneira de fazer isso é observar se o maior pico possui submúltiplos inteiros com uma certa magnitude equivalente do maior pico, se um sinal for periódico o período com pico maior(P) vai possuir outro pico com uma amplitude equivalente em 2*P...(guarde esse segredo com carinho rsrs)
Comment: Cara, muito obrigado mesmo por responder...achei que ninguém ia responder...obrigado mesmo...ajudou demais.Percebi que você domina o assunto e eu estou apenas começando como pode perceber...rsrs. Pode me recomendar algum livro ou curso online para me inteirar mais sobre o assunto. Quero me aprofundar sobre esse assunto de processamento de áudio.
Comment: Qual a equação para encontrar os valores em decibéis a partir do Y inicial que foi retornado pela transformada?
Comment: Se x é o período, então por exemplo, um vetor de 4096 posições com dados capturados a uma taxa de amostragem de 44100 terá em cada posição dados referente a 0,092879818 segundos (4096/44100 =0,092879818 segundos) . Então se eu fizer 1/ 0,092879818 = 10,7666 Hz,  seria a frequência de cada posição do vetor sendo 10,7666 Hz a menor e 44097,536 Hz (10,766 * 4096) a maior frequência que posso guardar?
Comment: Então se a ordem de resolução é de aproximadamente 10,766 Hz, ele não conseguiria distinguir uma frequência de 450 Hz de uma de 445Hz?
Comment: Não entendi por que você dividiu 1/4096 e achou essa ordem de resolução. Essa ordem de resolução é em relação a frequência ou ao período?
Comment: Com o vetor no domínio do tempo teria como eu saber quais frequências tem menor db e eliminá-las do vetor para se obter maior precisão na identificação da frequência com a transformada de fourier? Quais opções eu tenho para melhorar a identifiação da frequencia?
Comment: Você disse que esse não é o melhor modo de se obter a frequência. Quais outros modos eu poderia utilizar, além desse que determina a frequência através da magnitude. Porque realmente eu vi um espectrograma de uma flauta e mesmo tocando uma nota, por exemplo,440 Hz, a maior magnitude foi do segundo harmônico , 880Hz. Isso aconteceu com duas notas que não me recordo agora. Ou seja, realmente  a frequência da maior magnitude não representa a frequência da nota.
Comment: @L.J tentei responder as dúvidas na minha resposta dá uma olhada lá


caractére opcional em máscara com Jquery maskedInput não funciona

Question: Em um formulário que estou desenvolvendo, um dos campos que o usuário precisa preencher é o de celular, e como o celular de algumas regiões do Brasil possuem 9 dígitos estou usando a biblioteca jQuery MaskedInput para formatar a entrada de dados.
O problema é que quando eu crio a máscara $("#celular").mask("(99) 9999-9999?9"); o caractére ? aparece no input desta forma (__) ____-____?_, o que não era para acontecer.
Eu utilizei esta mesma formatação em um sistema anterior que funcionou perfeitamente, não consigo entender porque neste caso não está funcionando.
O plugin que estou usando é esse aqui digitalbush.com/projects/masked-input-plugin
Alguem poderia me ajudar?
Comment: poderia colocar o código q tens até agora?
Comment: Posta seu código pois fiz um teste com sua mascara e funciona, da uma olhada = https://jsfiddle.net/4xon0s6e/
Comment: No HTML está assim:

E no javascript está assim:
$(document).ready(function(){
    $("#celular").mask("(99) 9999-9999?9");
});

O que eu acho estranho que é em um outro sistema meu está funcionando tudo ok, e neste aqui ele fica (__) ____-____?_
Comment: [Aqui](http://codepen.io/caio1511/pen/aOeGKG) também funcionou. Pode dar mais detalhes do seu código?
Answer: Pelo seu exemplo era para funcionar.
Já trabalhei em vários projetos e sempre que usamos um plugin de mascara, damos preferencia para http://igorescobar.github.io/jQuery-Mask-Plugin/
Esse eu garanto, e modo de usar é muito parecido, na minha opinião é o melhor!
Abraço
Espero ter te ajudado


Regular expression for W3C compliant URLs?

Question: I'm trying to find a regular expression for a URL that will be compliant with the W3C standard for the HTML5 "url" input type (to be used in JavaScript).
See the W3C specification of the requirements.
Two possibilities:

I found this other StackOverflow question about URL regexes which looks quite promising:
There exists an HTML5 form validation jQuery plugin - which is supposed to emulate HTML5 form validation functionality.

This script uses the following regular expression:
/(https?|ftp):\/\/(((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?/

I don't know about the rest of this, but at first glance it at best seems to fail on the "potentially surrounded by spaces" part of the specification.
Has anyone else tried to do this before? Does anyone know where I could find a compliant regex?
Ta, Robin.
Comment: Actually, that would work fine if the URL was surrounded by spaces. If you anchored it to the beginning and end of the string (by adding `^` at the beginning and `$` at the end) then your concern would be valid. And you should anchor it -- otherwise someone could put an illegal character at the beginning or the end of the string, and you would still report a successful match.
Comment: Thanks Joe. But that's exactly what I mean, it's hardly a complete regex for the "url potentially surrounded by spaces" as it could be surrounded by anything. What I'd really like is the most complete RegEx solution I can find.
Comment: Actually I found another topic that seems to sort of answer this. The W3C spec basically says that the URL must comply with RFC3986 and RFC3987. I haven't read them myself, but [this topic](http://goo.gl/TbFHG) purports to have a solution which looks like it probably complies with both standards. And to make it comply with the "potentially surrounded by spaces" I just need to add `\s*` to either end. However, I'm still not 100% sure that a) this actually complies or b) whether it complies with both RFC3986 and RFC3987 or just one of them? I'd welcome further input from an expert.
Answer: Right I think I have the answer. I found another StackOverflow question that contained what seems to be a very good RegEx for RFC 3987. I can't be sure because I haven't gone through the spec in detail or anything, but I think it's compliant.
I had to refactor it a bit to work in JavaScript - I removed the curly braces from the character declarations and replaced \x with \u but now I'm pretty sure it works. I also added \s* to the beginning and end to comply with that part of the W3C specification.
Here's the final regex. If anyone tries it and has any problems, or thinks it should be different in any way let me know - I'm going for the most accurate solution possible here:
/^\s*[a-z](?:[-a-z0-9\+\.])*:(?:\/\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\._~\uA0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\u10000-\u1FFFD\u20000-\u2FFFD\u30000-\u3FFFD\u40000-\u4FFFD\u50000-\u5FFFD\u60000-\u6FFFD\u70000-\u7FFFD\u80000-\u8FFFD\u90000-\u9FFFD\uA0000-\uAFFFD\uB0000-\uBFFFD\uC0000-\uCFFFD\uD0000-\uDFFFD\uE1000-\uEFFFD!\$&\'\(\)\*\+,;=:])*@)?(?:\[(?:(?:(?:[0-9a-f]{1,4}:){6}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|::(?:[0-9a-f]{1,4}:){5}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:[0-9a-f]{1,4}:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|v[0-9a-f]+[-a-z0-9\._~!\$&\'\(\)\*\+,;=:]+)\]|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}|(?:%[0-9a-f][0-9a-f]|[-a-z0-9\._~\uA0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\u10000-\u1FFFD\u20000-\u2FFFD\u30000-\u3FFFD\u40000-\u4FFFD\u50000-\u5FFFD\u60000-\u6FFFD\u70000-\u7FFFD\u80000-\u8FFFD\u90000-\u9FFFD\uA0000-\uAFFFD\uB0000-\uBFFFD\uC0000-\uCFFFD\uD0000-\uDFFFD\uE1000-\uEFFFD!\$&\'\(\)\*\+,;=@])*)(?::[0-9]*)?(?:\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\._~\uA0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\u10000-\u1FFFD\u20000-\u2FFFD\u30000-\u3FFFD\u40000-\u4FFFD\u50000-\u5FFFD\u60000-\u6FFFD\u70000-\u7FFFD\u80000-\u8FFFD\u90000-\u9FFFD\uA0000-\uAFFFD\uB0000-\uBFFFD\uC0000-\uCFFFD\uD0000-\uDFFFD\uE1000-\uEFFFD!\$&\'\(\)\*\+,;=:@]))*)*|\/(?:(?:(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\._~\uA0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\u10000-\u1FFFD\u20000-\u2FFFD\u30000-\u3FFFD\u40000-\u4FFFD\u50000-\u5FFFD\u60000-\u6FFFD\u70000-\u7FFFD\u80000-\u8FFFD\u90000-\u9FFFD\uA0000-\uAFFFD\uB0000-\uBFFFD\uC0000-\uCFFFD\uD0000-\uDFFFD\uE1000-\uEFFFD!\$&\'\(\)\*\+,;=:@]))+)(?:\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\._~\uA0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\u10000-\u1FFFD\u20000-\u2FFFD\u30000-\u3FFFD\u40000-\u4FFFD\u50000-\u5FFFD\u60000-\u6FFFD\u70000-\u7FFFD\u80000-\u8FFFD\u90000-\u9FFFD\uA0000-\uAFFFD\uB0000-\uBFFFD\uC0000-\uCFFFD\uD0000-\uDFFFD\uE1000-\uEFFFD!\$&\'\(\)\*\+,;=:@]))*)*)?|(?:(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\._~\uA0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\u10000-\u1FFFD\u20000-\u2FFFD\u30000-\u3FFFD\u40000-\u4FFFD\u50000-\u5FFFD\u60000-\u6FFFD\u70000-\u7FFFD\u80000-\u8FFFD\u90000-\u9FFFD\uA0000-\uAFFFD\uB0000-\uBFFFD\uC0000-\uCFFFD\uD0000-\uDFFFD\uE1000-\uEFFFD!\$&\'\(\)\*\+,;=:@]))+)(?:\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\._~\uA0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\u10000-\u1FFFD\u20000-\u2FFFD\u30000-\u3FFFD\u40000-\u4FFFD\u50000-\u5FFFD\u60000-\u6FFFD\u70000-\u7FFFD\u80000-\u8FFFD\u90000-\u9FFFD\uA0000-\uAFFFD\uB0000-\uBFFFD\uC0000-\uCFFFD\uD0000-\uDFFFD\uE1000-\uEFFFD!\$&\'\(\)\*\+,;=:@]))*)*|(?!(?:%[0-9a-f][0-9a-f]|[-a-z0-9\._~\uA0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\u10000-\u1FFFD\u20000-\u2FFFD\u30000-\u3FFFD\u40000-\u4FFFD\u50000-\u5FFFD\u60000-\u6FFFD\u70000-\u7FFFD\u80000-\u8FFFD\u90000-\u9FFFD\uA0000-\uAFFFD\uB0000-\uBFFFD\uC0000-\uCFFFD\uD0000-\uDFFFD\uE1000-\uEFFFD!\$&\'\(\)\*\+,;=:@])))(?:\?(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\._~\uA0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\u10000-\u1FFFD\u20000-\u2FFFD\u30000-\u3FFFD\u40000-\u4FFFD\u50000-\u5FFFD\u60000-\u6FFFD\u70000-\u7FFFD\u80000-\u8FFFD\u90000-\u9FFFD\uA0000-\uAFFFD\uB0000-\uBFFFD\uC0000-\uCFFFD\uD0000-\uDFFFD\uE1000-\uEFFFD!\$&\'\(\)\*\+,;=:@])|[\uE000-\uF8FF\uF0000-\uFFFFD|\u100000-\u10FFFD\/\?])*)?(?:\#(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\._~\uA0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\u10000-\u1FFFD\u20000-\u2FFFD\u30000-\u3FFFD\u40000-\u4FFFD\u50000-\u5FFFD\u60000-\u6FFFD\u70000-\u7FFFD\u80000-\u8FFFD\u90000-\u9FFFD\uA0000-\uAFFFD\uB0000-\uBFFFD\uC0000-\uCFFFD\uD0000-\uDFFFD\uE1000-\uEFFFD!\$&\'\(\)\*\+,;=:@])|[\/\?])*)?\s*$/i

Comment: `\u10000` et al don't work in JavaScript regex - it only supports four-digit `\u` escapes and works against UTF-16 code units rather than characters. You'd have to break out the non-BMP character ranges out into their UTF-16 surrogate expansions, which would be extraordinarily painful.
Comment: Some checks need to be done before testing random strings on this regex to avoid overusing the cpu. I had an instance where a string containing comma-separated urls was tested against it and drove the process to hog the cpu at 100%.
Comment: Eslint is saying "bad escape sequence" on each occurrence of `\uA0-`.
Answer: Your link provides your answer:

A string is a valid URL potentially surrounded by spaces if, after stripping leading and trailing whitespace from it, it is a valid URL.

So, you could manually strip the whitespace and then apply your regular expression, or use this one:
/\s* ...your regex here... \s*/

to account for leading and trailing whitespace
Comment: No no I'm not strugling to manage the "potentially surrounded by spaces" bit. That's easy. I want to have a fully compliant regex.
Comment: Sure... so does adding the `\s*` at the start and the end satisfy?
Comment: That was kinda what I was asking. Anyway, having done further research I don't think the RegEx I posted in the original post was specific enough, but I think I found one which is, and I've added an answer containing it.


My p-values increase when adding variables: is the model still valid?

Question: Forewarning- I'm not a very advanced in regression.
(Updated with 2 edits)
I'm running multiple regressions with Excel and noticed that my p-values are becoming insignificant when adding more variables.  My model is very simple.
N=9
with a statistically significant variable, then I add another variable (which by itself is significant) and the p-value jumps into non-significant land.
I've read that this could be because of multicollinearity: should I be concerned with this since I'm only using the model to predict? How do I confirm this in Excel, and if so is my model not valid?
Edit - Thanks for your input guys:
My process is to test each variable one by one, and if it registers a significant p value (less than .05) and a high R2'd then I keep it in the model and add another variable.
This is where I am getting confused, as I add another variable the R2 (and adjusted R2) increase but the p values both increase above .05 (but independently are less that .05).
What does this mean? Is there any way to run a good multiple regression model in excel using a small sample size (N of 9-15) for prediction without the above problem.
Thanks again.
Edit #2 - I read through some of the other threads and a recurring theme is that this happens b/c of collinearity.  I did a VIF test and the value is 1.97 which is below 2.5 so doesn't set off any alarms.
So if my two variables don't have collinearity, whats happening to the p values? i.e. both are significant independently but only 1 is when I regress both variables?
Comment: If your sample size is 9, then multiple regression is a real strain. Examples could be imagined in which it works fine, but usually the experience will be similar to yours. The P-values are a health warning that you do not have a sample size large enough to do what you are trying. As well as being very cautious, don't fit anything that you can't support graphically, which may well mean trying at most two predictors.  (Using a model just to predict makes no difference here; an untrustworthy model is untrustworthy regardless of your motive.)
Comment: This is a FAQ: please take a look at our [higher-voted threads on regression and significance](http://stats.stackexchange.com/search?tab=votes&q=regression%20significant).
Comment: Thanks, I read though some of these and added an edit to my original post.
Comment: Yes, this is a collinearity issue.  But *strong* collinearity is not actually needed: see the example I presented at http://stats.stackexchange.com/a/14528, for instance. Collinearity is not needed at all to explain the reverse effect (when introducing a new variable suddenly makes an "insignificant" variable significant): http://stats.stackexchange.com/a/28493. You should both (a) study "stepwise regression" (which is what you're trying to do) and (b) [search our site](http://stats.stackexchange.com/search?q=stepwise+regression) to learn why you should look for better procedures.
Comment: Are we talking about the same issue? Introducing my new variable doesn't make an "insignificant" variable significant. But the other way around, adding a variable makes a previously signifcant variable insignificant (While the regression as a whole still being significant.  Or, or, or is it the same difference? - Thanks
Comment: @NickCox, I think that is the right answer here. Why not make it 'official'?
Answer: What you are describing is a variant of stepwise model building, which, whether based on the p-values of individual predictors, or on measures of overall model performance like $R^{2}$ or AIC results in a host of problems rendering inference from such models suspect:

deflated p values
inflated overall model performance values
inflated coefficients
inflated F statistics for the whole model
highly probable exclusion of true predictors
highly probable inclusion of false predictors

Most of these problems arise because you are neither accounting for nor reporting the string of invisible "conditional on all these previous rejection decisions" at each step of the model building process.
So how to build a model if not by a stepwise approach? By theoretically justifying your model variables a priori and embrace reporting negative effects for a given model (i.e. don't just report coefficients with p-values below your significance threshold).

References
Babyak, M. A. (2004). What you see may not be what you get: A brief, nontechnical introduction to overfitting in regression-type models. Psychosomatic Medicine, 66:411–421.
Henderson, D. A. and Denison, D. R. (1989). Stepwise regression in social and psychological research. Psychological Reports, 64:251–257.
Huberty, C. J. (1989). Problems with stepwise methods—better alternatives. Advances in Social Science Methodology, 1:43–70.
Hurvich, C. M. and Tsai, C.-L. (1990). The impact of model selection on inference in linear regression. The American Statistician, 44(3):214–217.
Lovell, M. C. (1983). Data mining. The Review of Economics and Statistics, 65(1):1–12.
Malek, M. H. and Coburn, D. E. B. J. W. (2007). On the inappropriateness of stepwise regression analysis for model building and testing. European Journal of Applied Physiology, 101(2):263–264.
McIntyre, S. H., Montgomery, D. B., Srinivasan, V., and Weitz, B. A. (1983). Evaluating the statistical significance of models developed by stepwise regression. Journal of Marketing Research, 20(1):1–11.
Pope, P. T. and Webster, J. T. (1972). The use of an $F$-statistic in stepwise regression procedures. Technometrics, 14(2):327–340.
Rencher, A. C. and Pun, F. C. (1980). Inflation of R$^2$ in best subset regression. Technometrics, 22(1):49–53.
Romano, J. P. and Wolf, M. (2005). Stepwise multiple testing as formalized data snooping. Econometrica, 73(4):1237–1282.
Sribney, B., Harrell, F., and Conroy, R. (2011). Problems with stepwise regression.
Steyerberg, E. W., Eijkemans, M. J., and Habbema, J. D. F. (1999). Stepwise selection in small data sets: a simulation study of bias in logistic regression analysis. Journal of clinical epidemiology, 52(10):935–942.
Thompson, B. (1995). Stepwise regression and stepwise discriminant analysis need not apply here: A guidelines editorial. Educational and Psychological Measurement, 55(4):525–534.
Wilkinson, L. (1979). Tests of significance in stepwise regression. Psychological Bulletin, 86(1):168–174.
Comment: @NickCox Thank you for the reference Nick, will keep it in the comments, since I haven't read it, and have read the above bibliography. In fairness, though, Frank *is* in (and linked!) the bibliography I provided. :)
Comment: Very helpful, but a bibliography on stepwise without Frank Harrell's _Regression modeling strategies_ (Springer NY 2001) is like Hamlet without ... (actually more like Macbeth without Macbeth).
Answer: If your sample size is 9, then multiple regression is a real strain.
Think that even with two predictors $X_1, X_2$ and a response variable $Y$, you are estimating three parameters (constants to be estimated) $\beta_0, \beta_1, \beta_2$ in a function like $\beta_0 + \beta_1 X_1 + \beta_2 X_2$. Loosely, but genuinely, you don't have much information to do that. Many statistical accounts advise as rules of thumb having many more data points per parameter than that.
Consider also the fact that two distinct points define a straight line uniquely, so that $Y = \beta_0 + \beta_1 X_1$ could always be fitted exactly with two such data points, regardless of whether the model makes scientific or practical sense or would be turn out to be a good approximation for a much larger dataset. This can be extended to three distinct points in a three-dimensional space being enough to fit a plane uniquely: that is the case $\beta_0 + \beta_1 X_1 + \beta_2 X_2$ again.  You can get intuition for this case by holding three fingers of two hands in the air and imagining a plane through them. It can then be extended more generally to fitting a linear regression function in any space. That becomes impossible for most of us to visualise, but the algebra generalises to your being able to fit at most 8 predictors to 9 data points, but such a perfect fit would be spurious and totally sensitive to any quirks in a dataset. Much of the point of fitting any regression is that the data points all have a vote and there is limited democracy insofar as points extreme in some sense will be often countered by others. (Often, but not always....)
This is just a matter of geometry, but statistically it can be worse, even much worse. If your predictors are correlated with each other, as they usually will be (it's hard to imagine datasets in which relevant variables are related to the response but unrelated to each other, unless that is a consequence of an experimental set-up), then it is difficult enough in general to work out the underlying relationship reliably. It's harder still to do that with very small samples. This problem goes under various names, including multicollinearity.
Examples could be imagined in which it works fine, but usually the experience will be similar to yours. The $P$-values are a health warning that you do not have a sample size large enough to do what you are trying.
So, what to do?

Try to get more data if you can. That's easy to say, but it's really important to realise that it's the only good solution. There is no statistical or Hogwarts spell to fit complicated models well to very small datasets. But naturally, this may not be practical for all kinds of simple reasons.
Be very cautious, and in particular don't fit anything that you can't support graphically. This is always good advice, but it is more than usually true with a model fitted to few data points for which programs may solemnly produce outrageous nonsense.
As a rule of thumb, try at most two predictors.

(Using a model just to predict makes no difference here; an untrustworthy model is untrustworthy regardless of your motive.)
Answer: There are many ways to compare how well models perform relative to each other in statistics.  For a simple linear regression you should consider comparing your two models AIC values. The lower the AIC the better. Rule of thumb typically is that a change of 2 in AIC is substantial.
Comment: True in general, but AIC is not especially practical in this case with a sample size of 9 and MS Excel as platform.
Comment: @Néstor Your last sentence I think exaggerates. My comments are tailored to the OP and the level of this question: if you recommend outright learners to use AIC, then you are right in principle, but that's disputable pedagogy. Better to add your own answer if you think answers so far are missing important dimensions.
Comment: Why not, @NickCox? You can always use the AICc anyways. The OP clearly wants to do model comparison (i.e., see if adding more variables is "supported" by the data), and by far the simplest choice is the AIC (or AICc). By the way, I would also add to the answer (and call the attention of to the OP) that comparing p-values between models makes absolutely no sense.
Comment: @Sensed another simple statistic to look at is adjusted $R^2$ (not $R^2$!!) higher the better. This should be easily available even in excel.


'Fixing' PearsonFitML to fit to a Pearson V distribution

Question: I am using the pearsonFitML function in the PearsonDS package to do maximum likelihood estimation of parameters in R.
I am particularly interested in fitting Pearson Type 5 distributions to my data. Does anyone know how I can 'fix' this function so it only tries fitting a type 5 distribution? This may just be a straightforward issue of syntax but I've been playing round for a while and haven't got this sorted yet!
Many thanks,
Faith
Comment: Pearson Type V distribution [is an inverse-gamma distribution](http://en.wikipedia.org/wiki/Pearson_distribution#The_Pearson_type_V_distribution) therefore it is not difficult to code it in R without using this package. You can find the code in this question: [Maximum Likelihood Estimation of Inverse Gamma Distribution in R or RPy](http://stats.stackexchange.com/questions/31934/maximum-likelihood-estimation-of-inverse-gamma-distribution-in-r-or-rpy) (which happens to be yours!!!).
Comment: Hi Procrastinator! Thanks for your response - I have used this other method (from my previous question) but the results of the parameter estimation are poor. When the pearsonFitML fits as a type V, it works really well.
Comment: Could you please clarify in what sense the parameter estimation is poor? Are you aware of the command `optim`?
Comment: Apologies, I'm getting mixed up (tried quite a few methods recently!). It actually doesn't seem to work with the data I use and throws out the error "Error in optim...non-finite finite-difference value [3]". I've tried varying the starting parameters and limiting the lower and upper values. Hence moving over to the pearsonFitML method. I am aware of the command optim and have played around a little with the options for this (although perhaps not in the most scientifically objective way!). Thanks again for your speedy response!
Answer: Pearson Type V distribution is the inverse-gamma distribution. This question was previously answered in your question Maximum Likelihood Estimation of Inverse Gamma Distribution in R or RPy using the command fitdistr. If you do not trust this estimation, you can try direct optimisation of the likelihood function using the command optim.
The folowing code shows how to do this using simulated data. If you post your sample, I can adjust the code and perhaps we can see what is causing trouble in the optimisation step.
rm(list=ls())
# Required packages
library(MCMCpack)

# Simulated data
set.seed(1)
data = rinvgamma(n=250, shape = 5, scale = 2) + 2

hist(data)

# log-likelihood
ll = function(par){
if(par[1]>0 & par[2]>0 & par[3]<min(data)) return( -sum(log(dinvgamma(data-    par[3],par[1],par[2]))) )
else return(Inf)
}

# MLE
mle = optim(c(5,2,2),ll)
params = mle$par

# Fit
hist(data,probability=T,ylim=c(0,2.5))
points(seq(2,4.5,0.001),dinvgamma(seq(2,4.5,0.001)-params[3],params[1],params[2]),type="l",col="red")

I hope this helps.
Comment: Huge thanks Procrastinator, code works like a charm! I want to fit a Pearson V as I'm looking at landslide areas which are thought to follow and inverse gamma pdf. I'm now investigating whether other features of landslides do the same. So, although other distributions may be appropriate, it's good to start out comparing like for like . I didn't immediately share my data as this is unpublished work and I couldn't even do a fit to synthetic data. Also, I was originally just looking for a solution to fixing pearsonFitML (which is probably a simple syntax thing!) although I got a better answer!:)
Comment: Wow thanks Procrastinator- you're fast!The only problem is that I'm using three parameters (shape = 1.4, scale = 0.00128 and location = -0.000132). You can simulate this data in R by generating from a two parameter inverse gamma and adding the location to each value. Is there a way of adjusting your code to take this into account. Thanks again!
Comment: @Faith I have modified the code to include a location parameter. Please, have a look.
Comment: Thanks, will be away from my computer for the next hour or so but will check it upon return. Thanks again! :)
Comment: +1 for Procrastinator's.  Whenever i see a question with a fixed methodology in mnd without any discussion of the data I am curious as to why the restriction to a Pearson V distribution makes sense.  I did a simulation study where I used only Pearson VII multivariate distributions.  My justification was that they have elliptic shaped contours of constant probability (like the multivariate Gaussian) and have a single parameter that controls tail behavior.  This makes it easy to modify the tail shape in the simulations to compare (in my case) classification error rate estimators.
Comment: It would be interesting to know Faith's motivation for type V.
Comment: @MichaelChernick Thanks for this. Indeed, it happens many times that the OP asks about a specific methodology but, due to confidentiality reasons, they do not show the data set and then it is difficult to tell how adecuate this model may be or to give further suggestions.
Comment: @Procrastinator sure i appreciate the confidentiality aspects of work.  I have worked for the US Army, Air Force and Department of Energy.  But often a sketch of the problem can help.  In this case the reason for Pearson V may or may not be connected to the data or there may not be a strong reason to pick it.


GWT UiBinder CSS styling

Question: I declare some colors for the border of a VerticalLayout panel, like in:
<ui:style>
    .onMouseOverBorderColor {border-color: red; border-style: outset}
    .onMouseOutBorderColor {border-color: black; border-style: outset}
</ui:style>

Then i want to change the color of the panel's border according to the position of the mouse, and i add to the constructor of my widget the following:
    clickable.addMouseOverHandler(new MouseOverHandler() {

        @Override
        public void onMouseOver(MouseOverEvent event) {
            GWT.log("mouse over");
            border.setStyleName("onMouseOverBorderColor");
        }

    });
    clickable.addMouseOutHandler(new MouseOutHandler() {

        @Override
        public void onMouseOut(MouseOutEvent event) {
            GWT.log("mouse out");
            border.setStyleName("onMouseOutBorderColor");
        }

    });

But ... nothing happens! What i do wrong?
Code after suggestion (does not work):
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
    xmlns:g="urn:import:com.google.gwt.user.client.ui">

    <ui:style>
        .fontStyleTitle {font-weight: bold }
        .border {border-color: black; border-style: outset}
    .border:hover {border-color: red; border-style: outset}
    </ui:style>

    <g:FocusPanel ui:field="clickable">
            <g:VerticalPanel ui:field="border" borderWidth="1" styleName="style.border">
                <g:Image ui:field="myImage"/>
                <g:Label ui:field="myTitle" horizontalAlignment="ALIGN_CENTER" styleName="{style.fontStyleTitle}"/>
            </g:VerticalPanel>
    </g:FocusPanel>

</ui:UiBinder>

and the java class:
public UiWidget(String path, String theTitle) {
        initWidget(uiBinder.createAndBindUi(this));
        GWT.log(URL_PREFIX+path);
        myImage.setUrl(URL_PREFIX+path);
        myTitle.setText(theTitle);
        myImage.setSize(IMG_WIDTH, IMG_HEIGHT);
        /*
        clickable.addMouseOverHandler(new MouseOverHandler() {

            @Override
            public void onMouseOver(MouseOverEvent event) {
                GWT.log("mouse over");
            }

        });
        clickable.addMouseOutHandler(new MouseOutHandler() {

            @Override
            public void onMouseOut(MouseOutEvent event) {
                GWT.log("mouse out");
            }
*/
}

Answer: By default all the styles declared in a UiBinder are obfuscated.
It means your style 'onMouseOverBorderColor' will propably become something like 'GLX0QCICAR'.
But when in your JAVA code you do:
border.setStyleName("onMouseOverBorderColor");

your border element will really have the style 'onMouseOverBorderColor'.
So 2 solutions:
Use external to not obfuscate style names:
<ui:style>
    @external onMouseOverBorderColor onMouseOutBorderColor;
    .onMouseOverBorderColor {border-color: red; border-style: outset}
    .onMouseOutBorderColor {border-color: black; border-style: outset}
</ui:style>

Use the obfuscated style in your JAVA code:
<ui:style type="your.package.name.UiWidget.MyStyle">
    .onMouseOverBorderColor {border-color: red; border-style: outset}
    .onMouseOutBorderColor {border-color: black; border-style: outset}
</ui:style>

public class UiWidget {
    ...
    public interface MyStyle extends CssResource {
        String onMouseOverBorderColor();
        String onMouseOutBorderColor();
    }

    @UiField
    protected MyStyle style;

    public UiWidget(String path, String theTitle) {
        ...
        clickable.addMouseOverHandler(new MouseOverHandler() {
            @Override
            public void onMouseOver(MouseOverEvent event) {
                border.setStyleName(style.onMouseOverBorderColor);
            }
        });
        ...
    }
}

Answer: You can't refer to the css styleName like this. In your example the stylename in <ui:style> can only be used as such in the ui binder file because it's obfuscated by GWT. You should put the style in a CSSResource. And place the style in a css file instead of the uibinder file and set the css resource stylename instead of the plain string.
But if you only want to change some css you could also use the hover selector without any code needed:
<ui:style>
    .border {border-color: black; border-style: outset}
    .border:hover {border-color: red; border-style: outset}
</ui:style>

and set the border style on you widget in the uibinder file as an attribute: styleName="{style.border}"
Comment: You forgot the braces: `styleName="{style.border}"`
Comment: thanks for the suggestion, i changed my code - as shown in my original post - but i do not see the desired effect. Is the code right?

GWT UiBinder CSS styling


Erro ao iniciar IIS Express Web Server - Error 0x80070020

Question: Após deixar o Visual Studio uma noite em modo debug parado em uma linha, não consegui mais executar a aplicação web localmente por causa de um erro no IIS Express.
Tentei parar o IIS Express e reabrir Visual Studio, mas não resolveu.
Answer: Conforme essa postagem de um blog:

O erro de código 0x80070020 significa ERROR_SHARING_VIOLATION, que no caso do IIS Express (ou IIS) significa que a porta que o IIS está tentando escutar está sendo usado por outro processo.

Para descobrir qual aplicação está usando a porta, basta executar o comando netstat no cmd com a seguinte sintaxe: netstat -ao | findstr número_da_porta_que_está_pesquisando

O parâmetro a é responsável por exibir todas as conexões e portas ouvidas.
  O parâmetro o é responsável por exibir o ID do processo associado com a conexão.

Executando o comando acima:
C:\Users\Daniel>netstat -ao | findstr 49286
TCP    [::1]:49286            Daniel:49286           ESTABLISHED     4280

Após descobrir o ID do processo, que é exibido na última coluna do retorno do comando, basta pesquisar o nome dele usando tasklist:
C:\Users\Daniel>tasklist /FI "PID eq 4280"
Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
firefox.exe                   4280 Console                    1    601.012 K

Ou pode apenas matar o processo com taskkill:
C:\Users\Daniel>taskkill /PID 4280

Comment: Acho  mais simples parar a porta.
Comment: Como faz isso ?
Answer: No meu caso foi o site default que estava rodando e usando a porta da aplicação. Foi só parar o site, aproveitei para executar o VS em modo administrador.


Assigning security groups different ranges

Question: Is it possible to assign a security group in windows 2008 a specific DHCP scope?
Meaning, let's say we have 2 groups, employees and managers in the superscope Company.  Assuming that each user is distinctly in either group and there are no overlaps, would it be possible to assign members of the security group employees a dhcp address in the range 192.168.1.0/24 and managers 192.168.2.0/24 ?
The DHCP server is the same server.
This is on Windows SBS 2008 if it makes any difference
If it is possible, how do you go about setting it up.
TIA
Comment: Some quantity of 802.1x and dynamic VLAN assignment can probably do waht you want in an ugly and hackish fashion (since the PC will need an IP address prior to a user logon). Likely you can accomplish your intended end-goal (which probably has something to do with Internet bandwidth allocation or filtering / monitoring of web site access) w/o doing it via assigning certain IP addresses to "people" (which is a fundamentally hard problem, since "people" don't have IP addresses).
Answer: The base problem is that Active Directory doesn't consider "IP address" to be a property for 'people'. It barely considers that for Machines, if only because that's how it determines which 'Site' you are in. To the best of my knowledge there is no native way to accomplish this using pure Microsoft tools.
As Evan said, the process flow for this solution has these steps:

User Login
Some watchdog process notices this, and triggers a...
Dynamic VLAN change for that ethernet jack, based on what security group the user is in (doubtlessly obtained via LDAP query, since this'll have to be a non-Microsoft product that does this)
The local machine is forced to request a DHCP address somehow.
The DHCP server assigns it an IP address based on the network the computer is on.

Steps 2-4 are the problems that'll require custom engineering. During the changeover from startup IP to running IP that machine will be effectively offline, which can muck up any number of events that happen on-login. Supporting this will require a managed switching environment with these kinds of features, and almost definitely an 802.1x solution as they're in the best position to do these kinds of network reconfigs on the fly.


Feeds is not importing images into subfolders

Question: I'm trying to import external nodes from html pages. all working fine but i just cannot make image getting saved in a subfolder.
am mapping a uri value "public://posts/2014/03/4587214.jpg" to "image:uri" and i want the file to be saved in "sites/default/files/posts/2014/03/4587214.jpg" but the file is getting saved in "sites/default/files/posts/4587214.jpg" instead . ("posts" is the value of the subdirectoy in the content type)
any advice on how to make feeds save images in subfolders ? (and create these on fly if do not exist)
i can do it by hacking "feeds/mappers/file.inc" and changing the value of $destination variable as follows:
<code>case 'uri':
if ($v) {
try {
/* patch - start */
/* added to allow subfolder destination */
$uri = $v->getValue();
$uri_target = file_uri_target($uri);
$uri_scheme = file_uri_scheme($uri);
$uri_path_info = pathinfo($uri_target);
$destination = file_stream_wrapper_uri_normalize($uri_scheme . "://" . $uri_path_info['dirname']);
/* patch - end */
$file = $v->getFile($destination);
</code>
but i was wandering if this can be done without hacking feeds source files
Answer: My solution to a similar problem was installing FileField module and in the content type design, put the attached files (as images in the example) in a structured folder by tokens.
This way, when feeds grab the image and attach to node, file_fields module gets the task and put the image into a folder as you mention by design.
It's also helpful when you add single content, not bulk import operations.Everything organized just as you plan.


Detecting front facing camera and capturing image, android?

Question: I want to capture image from the front facing camera.
Is there a way to detect front facing camera?
I searched a lot and the all the answers I found are quite old 2-3 yrs old.
Do I have to make a custom camera for it or is there any other way?
Comment: http://stackoverflow.com/questions/22338037/android-using-front-facing-camera-to-take-a-picture
Comment: http://androideasylessons.blogspot.in/2012/09/open-front-camera-in-android-program.html
Answer: With the help of these links I was able to create my own front camera to take pictures

Android using front facing camera to take a picture
Access front camera
Android developer camera

Here is the link to final project
Custom Front Camera


Determine the Galois group of $ F(x^5) \subset F(x) $

Question: I'm rather new to Galois theory and have been given this exercise:
Suppose $ F $ is respectively equal to $ \mathbb{Q}, \mathbb{C}, \mathbb{F}_5 $ (the third one is just the 5-element field). My task is to determine the Galois group of $ F(x^5) \subset F(x) $.
I am able to prove a theorem which tells us that the order of this extension is $ 5 $. The fundamental theorem of Galois theory tells us that the Galois group of an extension is of the same order, in this case  $ 5 $, provided the extension is Galois. If it isn't, then the group is of smaller order.
I'm not sure how to check whether this extension is Galois - if it was, the answer would be obvious, since there's only one group of order $ 5 $.
The thing that gets me is how to see whether this extension is Galois - and, if not, what the Galois group might be.
I'd appreciate some help
Comment: If (and only if) the characteristic of $F$ is $5$ it's not separable.
Comment: If $F$ does not contain all 5th roots of unity, it is not normal.
Answer: Hints:
We have that $\;x\;$ is a root of $\;p(t)=t^5-x^5\in\Bbb F(x^5)[t]\;$ , which is a polynomial of degree five.
Over $\;\Bbb Q,\,\Bbb C\;$ the roots of $\;p(t)\;$ are $\;x^5,\,x^5w,\,x^5w^2,\,x^5w^3,\,x^5w^4\;$ , with $\;w\;$ a (primitive) root of unity of order $\;5\;$
Over $\;\Bbb F_5\;$ we have that in the extension $\;\Bbb F_5(x)/\Bbb F_5(x^5)\;$, we have
$$t^5-x^5=(t-x)^5$$
Note: the last decomposition is true in $\;\Bbb F_5(x)[t]\;$ !
Thus, in this last case the extension isn't even separable...
Comment: So in case where $ F = \mathbb{F}_5$, the Galois group can be of any order up to $ 4$, right? How do I determine which one it might be?
Comment: @Jytug In that case I'm not sure whether we can continue to call it "Galois Group" as, per definition, the extension cannot be Galois....but there's still an automorphisms group, (whether we call it Galois group or not), and since any such automorphism *must* map a root of that polynomial to another root, **but** there is only one such root, the autom. group is trivial, I think.


socket programming serialized objects

Question: i am having a very weird situation in my code which i dont understand i am sending an object lets say O through a socket then i am changing the value of a variable in the object and sending it again but the second time when i print it on the client side, i am getting the same values as in the 1st object.
client code:
 while(true){
             try{
             order=(Order)ois.readObject();

            System.out.println(order);

             }

server code:
public void sendOrder(Order o){
    try {
        out.writeObject(o);

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

main method:
Server_Socket ss=new Server_Socket();
    ss.sendOrder(o);
    o.add(r2);
    ss.sendOrder(o);

The value is definitely changing on the serverside before i send it, but i dont understand why on the client side its not showing that r2 added in the object.
Answer: The objects are being cached by the ObjectOutputStream. To prevent this, call ObjectOutputStream.reset() after each write. If you are sending simple objects that don't contain other objects, use writeUnshared() instead of writeObject().
Comment: @AlexLynch No, it isn't "Java's way of telling you it's not super good practice to be writing mutable objects" at all. It is Java's way of implementing the Object Serialization Specification, which provides that object graphs are transmitted correctly, including cyclic graphs. It is impossible to implement that without some kind of 'handle' system that remembers what has already been transmitted and plants handles to those objects instead of retransmitting them.
Comment: @yahh Call it whenever you want to send a fresh copy rather than every time if you like, but the overhead is pretty minimal.
Comment: would using reset everytime make that much of a difference on the timing
Comment: as a note on this, java caches for the objects for a reason. it's java's way to telling you that it's not super good practice to be writing mutable objects over a socket. sadly, i couldn't tell you exactly why.
Comment: @EJP can you point me to a resource that explains the process and reasoning more in-depth? i am interested, but don't fully understand based on your comment.
Comment: @AlexLynch The [Object Serialization Specification](http://docs.oracle.com/javase/6/docs/platform/serialization/spec/serialTOC.html)?
Answer: The objects are being cached by the IOStreams.  To fix this, create a deep clone on the server prior to sending the object back.  When the client pulls the object from the stream, it will have a different instance id and it will actually deserialize and instantiate the object on the client side.
Fun stuff.
Comment: Much too complex and error-prone. A far simpler solution exists.

socket programming serialized objects


How to compress SQL file correctly on CentOS?

Question: I have a database whose size is roughly 3.1 Gb according to PhpMyAdmin.
I would like to dump and compress it with gzip.
This is a very similar answer to what I'm trying to do:
https://serverfault.com/a/804273/326635
Here is my command:
mysqldump -u myuser -p mydb | gzip -9 -c > db.gz

It works, I got the gz file. But it is over 3 Gb so the compression doesn't seem to be working. What do I wrong, how can I get a smaller file with gzip?
Answer: The size of your mysqldump file is not going to be the same as your database size as reported by PHPMyAdmin.
First, create the dump file with the command:
mysqldump -u myuser -p mydb > dumpfile.sql

Record how large the file is. Then, compress the dump file with the command:
gzip -9 dumpfile.sql

Then compare the size of that new file.
Comment: Size of the SQL file in bytes is: 3,600,943,947

Size of the Gzip file in bytes is:   324,598,653
Ok, this seems solved the problem. Maybe I wrongly counted the bytes?


LilyPond lyrics affecting horizontal spacing in score

Question: While attempting to typeset a piece of baroque vocal music, I've come upon this issue where lyrics cause uneven spacing of the notes in other voices in the score. For example, the 2nd violin on the final beat of bar 2 here (notice how the final eighth note is quite further from its neighbour than the previous one?):

Admittedly, since this is a score and not a performing part, it's not that dramatic, but it's still an eye sore, and very much something I'd rather do without. Looking at the documentation, there's proportional notation (see here), but that looks like it would be much too extreme of a solution (particularly given the presence of 32nd notes, in the given example but elsewhere as well).
So the question is, what (if that is even possible) can be done here to fix this issue?
I'd copy the LilyPond code, but it's rather large, and most of it is rather routine and probably irrelevant to the issue. Here though is (the relevant bit of) the music so you don't have to copy that:
\language "deutsch"

%% Music

global = {
    \key a \minor
    \time 4/4
}

violinoIPart = {
\relative c'' { e4. d8 c4. h8 | a4. a8 h c d4~ | d8 c c8. h16 cis2 | R1 | }
}

violinoIIPart = {
\relative c'' { c4. h8 a2 | e4 a gis8 a h a | e'2 e4 e, | R1 | }
}

cantoIPart = {
\relative c'' { \autoBeamOff R1*4 | }
}

cantoIIPart = {
\relative c' {  \autoBeamOff r4 e4~ \melisma e8 fis32[ gis a gis] a4~ | a8 h32[ c d c] d4 \melismaEnd r h8 d | gis, a a8. gis16 a2 | R1 }
}
cantoIIText = \lyricmode {\set fontSize = #-0.5
Ach __ mein herz -- lie -- bes Je -- su -- lein,
}

altoPart = {
\relative c' {  \autoBeamOff R1*2 | r2 r4 a~ | a4 r2. | }
}
altoText = \lyricmode {\set fontSize = #-0.5
Ach __ mein herz -- lie -- bes Je -- su -- lein,
}

continuoPart = {
\relative c { a2 a'~ | a4 f e d | e2 a, |\break R1 }
}

I should note, I'm using a custom notation font, but from checking it myself (by resetting to the default font), that has no effect on the issue.
Answer: There is a snippet that tries to make LilyPond favor the spacing of notes at the cost of moving lyric words around.
https://lsr.di.unimi.it/LSR/Item?id=1154
% Snippet author: Jean Abou Samra <firstname.lastname@example.com>
% Original thread: https://lists.gnu.org/archive/html/lilypond-user/2022-11/msg00087.html
%
% This snippet gets rid of uglinesses in note spacing caused by lyrics.
% By default, LilyPond always puts a lyric word exactly centered under
% the note it attaches to. When there is a long lyric word, LilyPond reserves
% space between notes so that there will be no collisions in the lyrics.
% However, this can lead to uneven note spacing. This snippet completely
% removes the presence of lyrics in note spacing so that it is natural
% according to the note lengths, and uses a spacing algorithm that shifts
% lyrics automatically in order to avoid collisions.
%
% Some technical comments follow.
%
% The spacing problem is set up as a quadratic optimization problem. Each
% lyric word has a strength value (by default, all words have a strength
% of 1.0). The demerit associated to a lyric word is s(x-p)², where s
% is the strength, x is the X coordinate and p is the ideal X coordinate
% where the lyric word would be centered on its associated note. An
% acceptable solution is a solution where no lyric words collide. The
% weight of a solution is the sum of the demerits for each of the words.
% Solving the lyric spacing problem means finding an acceptable solution
% of minimal weight.
%
% In practice, words should not touch each other, but maintain a minimum
% distance between each other (controlled by LyricSpace.minimum-distance
% and LyricHyphen.minimum-distance). This is reduced to the form above
% by widening one of the two words for each LyricSpace or LyricHyphen
% grob, by the amount given by the minimum-space property.
%
% The algorithm to solve the lyric spacing problem uses dynamic programming
% and runs in linear time. We add words one by one from left to right. After
% adding each word, the problem given by the words added so far is solved.
% The base case (zero words) is trivial. To add a word, it is very intuitive,
% and not hard to prove, that the following technique works: if adding
% the word at its optimal position produces no collision, then keep it
% there; else, make this word 'push' on its left neighbor and move these
% two words simultaneously to the left until the optimal position for
% these two words together is reached; if this still produces a collision
% then add the third word and consider the three words stuck together, etc.
% Note that once two words have been stuck together, they won't need
% to be taken apart again: they will be adjacent ("stuck") in the final
% configuration.
%
% Written in this form, this algorithm looks quadratic. While probably
% acceptable in usual scores, this might become a problem with ly:one-line-breaking.
% However, with a bit of simple algebra, you can see that optimizing for two
% words stuck together (and, by extension, any finite number of words stuck
% together) is equivalent to optimizing for one single (imaginary) combined
% word, of which the length is the sum of the two lengths, the strength is
% the sum of the strengths, and the optimal coordinate is given by a simple
% formula (see the code). Therefore, instead of simultaneously considering
% two words stuck together, you can replace them with just one fresh problem
% variable. At each word added during the algorithm, there is a constant processing
% overhead, plus an overhead linear in the number of times a word is newly
% stuck to a group, forming a new group. If you imagine that all words start
% out black, and every word becomes white as soon as its group is stuck to
% the group on the left, it is clear that the total number of "add to group"
% operations is linear in the number of words. At the end, there is a
% step to compute the offset of each word from that of its group, which
% is made linear by caching the offset of a group as soon as it is
% visited. In this way, the total number of operations is linear.
%

% #(ly:set-option 'compile-scheme-code)

#(use-modules (ice-9 match)
              (ice-9 hash-table)
              (oop goops))

%% convenience stuff:

#(define-syntax-rule (transform! lval proc)
   (set! lval (proc lval)))

#(define ->
   (make-procedure-with-setter
    (lambda (instance . path)
      (let loop ((instance instance) (path path))
        (match path
          ((slot)
           (slot-ref instance slot))
          ((slot . rest)
           (loop (slot-ref instance slot)
                 rest)))))
    (lambda (instance . args)
      (let loop ((instance instance) (args args))
        (match args
         ((slot new)
          (slot-set! instance slot new))
         ((slot . rest)
          (loop (slot-ref instance slot)
                rest)))))))

#(define-class <lyric-variable> ()
   (ideal #:init-keyword #:ideal)
   (extent #:init-keyword #:extent)
   (strength #:init-keyword #:strength)
   (tied-to #:init-value #f)
   (tied-offset #:init-value #f)
   (final #:init-value #f))

#(define (merged-variable! group var)
   (let* ((delta (- (interval-end (-> group 'extent))
                    (interval-start (-> var 'extent))))
          (new
           (make <lyric-variable>
                 #:ideal (/ (+ (* (-> group 'strength)
                                  (-> group 'ideal))
                               (* (-> var 'strength)
                                  (- (-> var 'ideal)
                                     delta)))
                            (+ (-> group 'strength)
                               (-> var 'strength)))
                 #:extent (cons (interval-start (-> group 'extent))
                                (+ (interval-end (-> group 'extent))
                                   (interval-length (-> var 'extent))))
                 #:strength (+ (-> group 'strength)
                               (-> var 'strength)))))
     (set! (-> group 'tied-to) new)
     (set! (-> group 'tied-offset) 0)
     (set! (-> var 'tied-to) new)
     (set! (-> var 'tied-offset) delta)
     new))

#(define (propagate! variables)
   (match variables
     ((var)
      variables)
     ((var group . rest)
      (let ((have-overlap (<= (+ (-> var 'ideal)
                                 (interval-start (-> var 'extent)))
                              (+ (-> group 'ideal)
                                 (interval-end (-> group 'extent))))))
        (if have-overlap
            (let ((merged (merged-variable! group var)))
              (propagate! (cons merged rest)))
            variables)))))

#(define (finalize! variables)
   (define (finalize-one! var)
     (unless (-> var 'final)
       (set! (-> var 'final)
             (if (-> var 'tied-to)
                 (begin
                  (finalize-one! (-> var 'tied-to))
                  (+ (-> var 'tied-to 'final)
                     (-> var 'tied-offset)))
                 (-> var 'ideal)))))
   (for-each finalize-one! variables))

#(define (solve-lyric-spacing-problem! variables)
   (fold
    (lambda (var groups)
      (propagate! (cons var groups)))
    '()
    variables)
   (finalize! variables))

#(define (respace-lyrics! grob)
   (let ((elt-array (ly:grob-object grob 'elements #f)))
     (when elt-array
       (let* ((elts (ly:grob-array->list elt-array))
              (refp (ly:grob-system grob))
              (with-iface (lambda (iface)
                            (filter (lambda (g)
                                      (grob::has-interface g iface))
                                    elts)))
              (words (filter (lambda (word)
                               (interval-sane? (ly:grob-extent word word X)))
                             (with-iface 'lyric-syllable-interface)))
              ;; Includes both LyricHyphen and LyricSpace
              (constraints (with-iface 'lyric-hyphen-interface))
              (variables (map
                          (lambda (word)
                            (let* ((xalign (ly:grob-property word 'self-alignment-X))
                                   (coord (ly:grob-relative-coordinate word refp X))
                                   (orig-ext (ly:grob-extent word word X))
                                   (align-point (interval-index orig-ext xalign))
                                   (ideal (+ coord align-point))
                                   (extent (coord-translate orig-ext (- align-point)))
                                   (strength (or (assq-ref (ly:grob-property word 'details)
                                                           'strength)
                                                 1.0)))
                              (make <lyric-variable>
                                    #:ideal ideal
                                    #:extent extent
                                    #:strength strength)))
                          words))
              (word-to-variable (alist->hashq-table (map cons words variables))))
         (for-each
          (lambda (constraint)
            (let ((added (ly:grob-property constraint 'minimum-distance))
                  (left-var (hashq-ref word-to-variable (ly:spanner-bound constraint LEFT))))
              (when left-var
                (transform! (-> left-var 'extent)
                            (lambda (e) (cons (interval-start e)
                                              (+ (interval-end e) added)))))))
          constraints)
         (solve-lyric-spacing-problem! variables)
         (for-each
          (lambda (word variable)
            (let* ((xalign (ly:grob-property word 'self-alignment-X))
                   (orig-ext (ly:grob-extent word word X))
                   (align-point (interval-index orig-ext xalign)))
              (ly:grob-translate-axis!
               word
               (- (-> variable 'final)
                  (ly:grob-relative-coordinate word refp X)
                  align-point)
               X)))
          words
          variables)))))

% A StanzaNumber is side-positioned against lyric words.
% Its X-offset will be computed before line breaking, with
% default offset values, then these values will change, so
% we have to update it.
#(define (recompute-offset-with-moved-lyrics! grob)
   (let ((support (ly:grob-object grob 'side-support-elements #f)))
     (when support
       ;; Make sure each LyricText in the support goes to its
       ;; updated location.
       (for-each
        (lambda (word)
          (let ((axis-group (ly:grob-parent word Y)))
            (ly:grob-property axis-group 'after-line-breaking)))
        (ly:grob-array->list support))
       (let* ((parent (ly:grob-parent grob X))
              (coord (ly:grob-relative-coordinate grob parent X)))
         (ly:grob-translate-axis!
          grob
          (- (ly:side-position-interface::x-aligned-side grob)
             coord)
          X)))))

\layout {
  \context {
    \Lyrics
    \override LyricText.extra-spacing-width = #'(+inf.0 . -inf.0)
    \override LyricSpace.springs-and-rods = ##f
    \override LyricHyphen.springs-and-rods = ##f
    \override VerticalAxisGroup.after-line-breaking = #respace-lyrics!
    \override StanzaNumber.after-line-breaking = #recompute-offset-with-moved-lyrics!
  }
}

doReserveSpace =
\once {
  \revert LyricSpace.springs-and-rods
  \revert LyricHyphen.springs-and-rods
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% EXAMPLE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\language "english"

struct = {
  \numericTimeSignature
  \key bf \major
  \time 3/4
  s2.*5 \break
  s2.*5 \break
}

nb = \markup { \small \italic "n.b." }

melody = \relative {
  \clef treble
  \dynamicUp
  R2.*4 |
  d'8\mp ef f4. d8 |

  d4 \once \phrasingSlurDashed c2_\(^\nb |
  d8\) ef f4 bf, |
  c2. |
  d8\< ef f4. f8 |
  g8 a bf2\mf |
}

pianoRH = \relative {
  \clef treble
  d''8 ef f4 <f,c'>8 f' |
  << { g8 a bf2 } \\ { <bf, d>2. } >> |
  << { ef4 c8 d ef bf } \\ { g2 g4 } >> |
  << { d'4. ef8 c4 } \\ { <ef, gf>2. } >> |
  <c' f>4 <f, d'>2 |

  << { d'4 c } \\ { <ef, gf>2 } >>  ef'8 c' |
  <d, bf'>4 <bf f'>2 |
  <gf d'>4 c ef8 c' |
  <d, bf'>4 f c8 f, |
  << { d'2. } \\ { bf8 a g2 } >> |
}

pianoLH = \relative {
  \clef treble
  bf8 f' ~ f4 a, |
  g8 d' bf' a g d |
  \clef bass
  c,8 g' ef'2 |
  ef,8 bf' c2 |
  bf,8 f' bf4 d |

  ef,8 gf bf c ef4 |
  bf,8 f' d'4 f |
  ef,8 c' ef gf ~ gf4 |
  bf,,8 f' d'4 a |
  g8 d' bf a g d |
}

melodyWordsDefault = \lyricmode {
  \set stanza = "1."
  Would I know my Sav -- ior
  %% The higher the details.strength property, the harder the algorithm
  %% tries to place the lyric syllable close to its ideal position, at the
  %% expense of other lyric syllables nearby.  Try outcommenting this
  %% override to see the effect.
  %\once \override LyricText.details.strength = 100
  %% \doReserveSpace can be used to exceptionally reserve space between the
  %% two following lyric words (in spite of the snippet turning this off).
  %% Try outcommenting to see the effect.
  %\doReserveSpace
  Wrapped in swad -- dling
  bands,
  Ly -- ing in a man -- ger bed, Light of hea -- ven 'round His head?
}

#(set-global-staff-size 19)
\paper {
  ragged-last = ##f
  ragged-bottom = ##t
  ragged-right = ##f
  ragged-last-bottom = ##t
  tagline = ##f
}

\layout {
  \context {
    \Lyrics
    \override LyricText.font-size = #0
    \override LyricHyphen.font-size = #-0.5
    \override LyricHyphen.padding = #0.15
    \override LyricHyphen.length = #0.6  %#0.4
    \override LyricHyphen.minimum-length = #0.66
    \override LyricHyphen.minimum-distance = #1 %0.15
    \override LyricHyphen.thickness = 2.0
    \override LyricHyphen.dash-period = 8.0
    \override LyricExtender.minimum-length = #0
    \override LyricExtender.right-padding = #0.5
    \override LyricSpace.minimum-distance = #1
    \override VerticalAxisGroup.nonstaff-relatedstaff-spacing.padding = #1
  }
}

\score {
  <<
    \new Staff <<
      \struct
      \new Voice = "melody" \melody
    >>
    \new Lyrics \lyricsto melody \melodyWordsDefault
    \new PianoStaff <<
      \new Staff = "pianoRH" <<
        \struct
        \pianoRH
      >>
      \new Staff = "pianoLH" <<
        \struct
        \pianoLH
      >>
    >>
  >>
  \layout {}
}

Comment: Ok, so once I made sure to run the correct version, yeah, this works exactly as intended, and pretty much corresponds to the "way to make LilyPond prefer more consistent spacing of beamed notes automatically" mentioned by benrg in his answer below.
Comment: This looks very promising but when I attempt to compile the example it gives me a few errors. Are there any other required elements which might be missing from the snippet?
Comment: No, if you just copy/paste all the snippet code, code and example, it should compile. What's your LilyPond version? It should work under 2.24 or 2.25.
Comment: (This is why you should preferably use `\version` statements in the example code when asking questions.)
Answer: You can't satisfy every aesthetic constraint simultaneously—a large readable underlay font, consistent alignment of syllables, consistent note-head spacing, and economical use of horizontal space. I don't know how to make LilyPond do a better job automatically, but here are some things you could do:

If you want to improve the spacing at the cost of inconsistent lyric alignment, you can change the latter manually with \tweak, e.g.
Ach __ \tweak self-alignment-X #RIGHT mein herz -- lie -- bes Je -- su -- lein,

or using a macro for readability:
rightalign = \tweak self-alignment-X #RIGHT \etc
[...]
  Ach __ \rightalign mein herz -- lie -- bes Je -- su -- lein,

You could try tweaking X-offset instead, which gives more flexibility at the expense of more trial and error to find the best number.

If you want to widen the spacing of the beamed eighths to be more consistent (but only in that beamed group, not score-wide), you can do it manually like this:
violinoIIPart = \relative c'' {
    c4. h8 a2 | e4 a
    \newSpacingSection \override Score.SpacingSpanner.spacing-increment = 5
    gis8 a h a
    \newSpacingSection \revert Score.SpacingSpanner.spacing-increment
    | e'2 e4 e, | R1 |
}

Again, you could hide the long incantations in macros. There may be a better way to do this. There may even be a way to make LilyPond prefer more consistent spacing of beamed notes automatically (without widening the spacing of everything uniformly), but I didn't find one in the documentation or a few web searches.

The current development branch (2.25) has added font-stretch, which can be used to select a horizontally condensed font variant for all underlay or for individual syllables. Example usage (untested):
narrower = \tweak font-stretch #'condensed \etc
[...]
  Ach __ \narrower mein herz -- lie -- bes Je -- su -- lein,

Answer: Typesetting that page without manual line breaks results in this:

Two measures per line looks reasonably tight already; at every vertical moment the horizontal spacing is about as close as you would want it to be for one reasons or another.
The spacing is being set by: the 32nd notes in the Canto 2, then the 8th notes in the Violono 2, the lyrics for the Canto 2, the 32nd's in the Alto, and then the Canto 2's lyrics again.
There isn't really anywhere to squeeze any extra horizontal space from to fit it all onto one line, without causing the distortions you are seeing.

If you really want some more space to even things out a bit better, I guess all you can do is either change where the line breaks are (with \break), or change the staff size or the paper size.
I suppose another option would be to move the word "mein" in the lyrics over a little bit to the left.  How to do this can be seen in this answer (you'll also want to use the \once command), but I probably wouldn't recommend that for this particular case.
Comment: The thing is, the irregular spacing of the 8th notes in the violin is present even if I add a line break after the third measure (it does appear to be fixed if the break is after the second measure, but then we run into the opposite problem, the horizontal spacing being too loose...).  Lyrics spacing does seem to help, but it's a bit clumsy, time-consuming as it needs to be done manually, and replaces one evil with - admittedly, a less noticeable one - another one [text slightly misaligned]


$f(n) = f(2n)$, and $f(2n + 1) = f(n) + 1$, find expression of such $f$

Question: The question is
a. $f(n) = f(2n)$
b. $f(2n + 1) = f(n) + 1$,
with $f(1)=1$, find expression of such $f$ that defined on positive integers
Got an initial idea about the pattern but find the difficulty to find the exact form. It's related to exponent of 2 (obviously). the number of times it can be expressed as addition of 2 exponents
for example, for $13 = 2^3+2^2+2^0, f(13) = 3$
and $16=2^4, f(16)=1; 15 = 2^3+2^2+2^1+2^0, f(15)=4$
in other words, it's the sum of all digits in its binary form, right? if so what's the formula of it.
during such time as I wrote my thoughts down, it seems I come up with a formula
$$a-\sum_{i=1}^\infty  \lfloor a/2^i\rfloor.$$
which seems to be the answer to the question
Comment: You don't need to describe the formula only using symbols. You could say "$f(n)$ is the digit sum of the binary representation". If you really wanted, you could say "If $ n = (a_1 a_2 a_3 \ldots a_n )_2$, then $f(n) = \sum a_i$.". $\quad$ And yes, that's the correct description of the function. How have you tried to prove it?
Comment: If you have a formula, why don't you try induction?
Comment: @TeresaLisbon I tried to prove it with induction, but runs into difficulty dealing with floor function
Comment: For curiosity, I found back a nice result about the series $\sum\limits_{n=1}^\infty \frac{bitcount(n)}{n(n+1)}=2\ln(2)$ https://math.stackexchange.com/a/4025339/399263 where I used explicitely the formulas proposed here for $f$.
Comment: What are the domain and codomain of $f$? Are they both positive integers?
Comment: @VTand yes thanks for mentioning I forgot to add it.
Comment: @CalvinLin Thanks for your suggestion! I'm new with math description. I tried to prove it with induction just now, but ran into difficulty dealing with floor function which I'm not really familiar with.
Comment: Try doing the induction using words not just symbols. Just write it out, and see how far you can get. "EG If n=2k is even, then f2k) is equal to .... so by the induction hypothesis ... hence we have shown that f(2k) is the digit sum of the binary representation".
Comment: After this problem you might want to check out Legendre's formula which is related to what you've worked out in your representation.
Comment: @CalvinLin this function is often referred to as $\operatorname{bitcount}(n)$
Comment: @Samual If $a_k$ are the binary digits of $\,a = \overline{a_na_{n-1}\dots a_1a_0}\,$ then $a = \sum 2^k a_k$ and $a_k = \left\lfloor \frac{a}{2^k}\right\rfloor \bmod 2$ so you have an explicit formula for each bit, and you can simply sum them up. Are you looking for some kind of "better" formula, and "better" in what sense?
Comment: @dxiv I would really like to see other f expression as well. The major issue I'm currently stuck is how to rigorously prove the result.
Answer: Expanding on my comment, let the binary representation of $a$ be $\,\overline{a_na_{n-1}\dots a_1a_0}\,$ with $\,a_k \in \{0,1\}\,$, then $\,a = \sum_{k \ge 0} 2^k a_k\,$ and $\,a_k = \left\lfloor \frac{a}{2^k}\right\rfloor \bmod 2\,$, so the sum of binary digits can be written as $\,\sum_{k \ge 0} \left(\left\lfloor \frac{a}{2^k}\right\rfloor \bmod 2\right)\,$.
Using the identity $\,n \bmod 2 = n - 2 \left\lfloor \frac{n}{2} \right\rfloor\,$ leads to the form in OP's question:
$$
\require{cancel}
\begin{align}
\sum_{k \ge 0} \left(\left\lfloor \frac{a}{2^k}\right\rfloor \bmod 2\right) &= \sum_{k \ge 0} \left( \left\lfloor \frac{a}{2^k}\right\rfloor - 2 \left\lfloor \frac{a}{2^{k+1}}\right\rfloor \right)
\\ &= \sum_{k \ge 0} \left( \left\lfloor \frac{a}{2^k}\right\rfloor - \left\lfloor \frac{a}{2^{k+1}}\right\rfloor \right) - \sum_{k \ge 0} \left\lfloor \frac{a}{2^{k+1}}\right\rfloor
\\ &= \left(\left\lfloor \frac{a}{2^0}\right\rfloor - \cancel{\left\lfloor \frac{a}{2^1}\right\rfloor} + \cancel{\left\lfloor \frac{a}{2^1}\right\rfloor} - \bcancel{\left\lfloor \frac{a}{2^2}\right\rfloor}  + \bcancel{\left\lfloor \frac{a}{2^2}\right\rfloor} - \dots\right) - \sum_{k \ge 1} \left\lfloor \frac{a}{2^{k}}\right\rfloor
\\ &= a - \sum_{k \ge 1} \left\lfloor \frac{a}{2^{k}}\right\rfloor
\end{align}
$$
Answer: By successive division by $2$ you get:

$f(2^nx)=f(2^{n-1}x)=\cdots=f(x)$

$f(2^n(2x+1))=f(2x+1)=f(x)+1$

Also we will need $f(0)$:

$f(1)=f(1+2\times 0)=f(0)+1$ and since $f(1)=1$ then $f(0)=0$

Let's write $n$ in its binary form $n=\sum\limits_{i=1}^M 2^{\alpha_i}$ with $\alpha_i>\alpha_j$ for $i>j$
Said otherwise $n$ has $M$ bits set to $1$.
Then notice that $n=2^{\alpha_1}(1+\sum\limits_{i=2}^M 2^{\alpha_i-\alpha_1})=2^{\alpha_1}(1+2\underbrace{\sum\limits_{i=2}^M 2^{\alpha_i-\alpha_1-1}}_x)$
Since $\alpha_i>\alpha_1\iff \alpha_i\ge \alpha_1+1\iff \beta_i=\alpha_i- \alpha_1-1\ge 0$ then $x=\sum\limits_{i=2}^M 2^{\beta_i}$
And you have your induction on the value of $M$ i.e. $f(n)=f(x)+1$ with $x<n$ having $M-1$ bits set to $1$.
The process terminates when the next number is $0$ aka. $M-M=0$ bits set to $1$, which corresponds to $f(n)=\underbrace{f(0)}_0+\underbrace{1+1+\cdots+1}_\text{M terms}=M=\operatorname{bitcount}(n)$.

Here is an alternative approach we will show that $f$ and bitcount coincide on all integers:
Let define $g(n)=f(n)-\operatorname{bitcount}(n)$
It is not difficult to show that $\operatorname{bitcount}$ obeys the same relations than $f$, indeed a multiplication by $2$ just shift all the bits to the left and add a zero to the right, this doesn't change the bitcount so $\operatorname{bitcount}(2n)=\operatorname{bitcount}(n)$. And for $2n+1$ it is not a zero we add to the right but a one, so the bit count is raised by $1$ and $\operatorname{bitcount}(2n+1)=\operatorname{bitcount}(2n)+1=\operatorname{bitcount}(n)+1$.
We have $g(0)=g(1)=0$ to start our induction and we will assume it is true up to $n$.

$n=2p$ then $g(n+1)=f(2p+1)-\operatorname{bitcount}(2p+1)=(f(p)+1)-(\operatorname{bitcount}(p)+1)=g(p)=0$ by induction since $p<n$.

$n=2p+1$ then $g(n+1)=f(2p+2)-\operatorname{bitcount}(2p+2)=f(p+1)-\operatorname{bitcount}(p+1)=g(p+1)=0$ by induction since $p+1<n$.

This terminates our induction and we conclude $g(n)=0$ for all $n$.

Finally here is a computational expression of $f$ (& is the bitwise AND operator):
$f(n)=\min\{\ i\mid u_i=0\text{ where } u_0=n,\ u_{i+1}=u_i \mathbin{\&} (u_i-1)\}$


Sujective, injective and bijective proof.

Question: Let $A$ and $B$ be sets and let $f:A\rightarrow B$ and $g: B\rightarrow A$ be functions.

Suppose that $f$ is injective, and $g$ is a left inverse of $f$. Prove that $g$ is surjective.

So I have this:
Let $a \in A$, then $g∘f(a)=g(f(a))=g(b)=a$. Therefore this means that for any $a \in A$ there is a $b$ such that $g(b)=a$. Hence, $g$ is surjective.

Suppose that $f$ is surjective, and that $g$ is a right inverse of $f$. Prove that g is injective.

For all $y \in B$, there is an $x \in A$ such that $f(x)=y$. Then $(f∘g)(y)=I_A(y)=y$. Let be $x=g(y)\in A$. Then $x=g(y) \in A$, $f(x)=y$
Did I prove that g is injective?

Suppose that $f$ is bijective, and that $g$ is an inverse of $f$. Prove that g is bijective.

How do I prove the last one?
Comment: 1) is good but I don't like to flow g(f(a))=g(b)=a.  It's acceptable but it seems a jump.  And b was never introduced.  I'd say: "Let $a \in A$ and let $b = f(a)$.  Then $g(b) = g(f(a)) = a$. So $g$ is surjective"  Its the same thing but flows more natural with the definitions and conclusion.
Comment: A function $g$ is an inverse of $f$ if and only if...
Comment: Um... you'd do 3) exactly to same way you did 1 and 2.  Except... you don't have to.. $f$ is bijective means $f$ is surjective and injective and g is a right and left inverse and you've proven that therefore g if surjective by 1) [f is injective and g is a left inverse] and that g is injective by 2) [f is surjective and g is a right inverse] so ... what's left to prove?
Answer: $2$. I did not understand your proof. Let's prove it. To prove that $g$ is injective, we must show
$$g(x)=g(y)\Rightarrow x=y$$
for all $x,y\in B$. If there are $x,y\in B$ such that $g(x)=g(y)$, then
$$x=(f\circ g)(x)=f(g(x))=f(g(y))=(f\circ g)(y)=y.$$
$3$. Since $g$ is an inverse of $f$, then $g$ is a left and right inverse of $f$. For $1$ and $2$, we have that $g$ is surjective and injective, that is, $g$ is a bijection.
Answer: Let $A$ and. $B $ be sets and $f : A \rightarrow  B$ and $g : B \rightarrow A$ be functions.
1)Suppose $f$ is injective, and $g$ is a left inverse of $f$. Prove that $g$ is surjective.
NB. Possibly $f(A) \subset B$. So, a little more precise, $g$ is left inverse of $f$ on $f(A)$.
Let $a \in A $, and $b =  f(a)$,  then $g(b) = g(f(a)) = a$ , since $g$ is left inverse of $f$  on  $f(A)$,  hence $g$ is surjective.
2) Suppose $f$ is surjective and $g$ is right inverse of $f$. Prove that $g$ is injective.
$f(A) = B$, since $f$ is surjective.
Let $x,y \in B$, $x \ne y$ , and consider $g(x), g(y)$.
Since $g$ is right inverse of $f$:
$x = f(g(x)) \ne  y = f(g(y))$, hence the arguments of the function $f$ are not equal,  i.e. $g(x) \ne g(y)$, $g$ is injective.
3) Answer by Rafael Hollande.


onclick function in an image which is dynamically created is not working

Question: Hi I just created a table dynamically, its working fine, but I need a on click on imageId. So what I did is:
document.getElementById("imageId").addEventListener("click", function () {
    alert("hello");
});

but it is not working, I don't need any jquery only using JavaScript.
The code creating table dynamically is given below and it is working fine.
var body = document.body,
    tbl = document.createElement('table'),
    tableId = document.createAttribute('id');

tbl.style.width = '100%';

for (var i = 0; i < 3; i++) {
    var tr = tbl.insertRow();
    tr.style.height= '40px';
    var timetd = tr.insertCell();
    var tdcompany = tr.insertCell();
    var chatsymbol = tr.insertCell();
    var amounttd = tr.insertCell();
    tdcompany.innerHTML = "abc";
    timetd.innerHTML = "ss";
    chatsymbol.innerHTML = '';
    amounttd.innerHTML = total  + '';
}

Comment: My guess is that the `addEventListener` is called before your image is added to the DOM. To be sure we need to know the execution order of you code snippets.
Comment: another pattern to try is adding your event listener to a parent element (which is already on the page) instead of directly adding it to the img itself.
Comment: There already was similar question and the problem was solved. See [the question](http://stackoverflow.com/questions/14258787/add-event-listener-on-elements-created-dynamically)
Answer: If you try with this code:
var myElement = document.getElementById("imageId");
if (myElement) {
      document.getElementById("imageId").addEventListener("click", function () {

   alert("hello");

});
} else {
    alert("Element does not exist yet");
}

you will see an alert telling you that the element does not exist yet. You need to make sure that when you try to add the handler the element exists. You can use a load handler for that purpose.
Answer: Try these i hope it will work for dynamical images it is working for me.
in place of 'img_id' give the id of those images click will work fine.
$('#img_id').on('click', function () {
             alert("Image Success");
    });


What subdomains does an Exchange 2013 SSL certificate require?

Question: I need to order a SSL certificate for an Exchange 2013 server.
I am going to order an UC Certificate from Comodo Group Inc.
I understand that I need to specify the below subdomains whilst ordering:

autodiscover.
mail.

Are there any other subdomains that I need to specify for an Exchange 2013 server? I ask because an UC Certificate allows 3 subdomains so this leads me to think that I am missing one.
Comment: The server FQDN. (aka exchange.domain.com)
Comment: @yagmoth555 AFAIK that is `mail.` (the same as our Outlook Web App subdomain which is 2. in the question), or am I missing something? The address that Outlook Anywhere uses, right?
Answer: Yes, typically mail and autodiscover will be all you need if mail.yourdomain.com is your Exchange FQDN.
See the Exchange 2013 Digital Certificates and SSL documentation which states:

Best practice: Use the Exchange certificate wizard to request certificates*
There are many services in Exchange that use certificates. A common
  error when requesting certificates is to make the request without
  including the correct set of service names. The certificate wizard in
  the Exchange Administration Center will help you include the correct
  list of names in the certificate request. The wizard lets you specify
  which services the certificate has to work with and, based on the
  services selected, includes the names that you must have in the
  certificate so that it can be used with those services. Run the
  certificate wizard when you've deployed your initial set of Exchange
  2013 servers and determined which host names to use for the different
  services for your deployment. Ideally you'll only have to run the
  certificate wizard one time for each Active Directory site where you
  deploy Exchange.
Instead of worrying about forgetting a host name in the SAN list of
  the certificate that you purchase, you can use a certification
  authority that offers, at no charge, a grace period during which you
  can return a certificate and request the same new certificate with a
  few additional host names.

It further goes on to state:

Best practice: Use as few host names as possible
In addition to using as few certificates as possible, you should also
  use as few host names as possible. This practice can save money. Many
  certificate providers charge a fee based on the number of host names
  you add to your certificate.
The most important step you can take to reduce the number of host
  names that you must have and, therefore, the complexity of your
  certificate management, is not to include individual server host names
  in your certificate's subject alternative names.
The host names you must include in your Exchange certificates are the
  host names used by client applications to connect to Exchange. The
  following is a list of typical host names that would be required for a
  company named Contoso:
Mail.contoso.com  This host name covers most connections to Exchange, including Microsoft Outlook, Outlook Web App, Outlook
  Anywhere, the Offline Address Book, Exchange Web Services, POP3,
  IMAP4, SMTP, Exchange Control Panel, and ActiveSync.
Autodiscover.contoso.com   This host name is used by clients that support Autodiscover, including Microsoft Office Outlook 2007 and
  later versions, Exchange ActiveSync, and Exchange Web Services
  clients.
Legacy.contoso.com   This host name is required in a coexistence scenario with Exchange 2007 and Exchange 2013. If you'll have clients
  with mailboxes on Exchange 2007 and Exchange 2013, configuring a
  legacy host name prevents your users from having to learn a second URL
  during the upgrade process.
Comment: Thanks for your answer. I've always been confused about `.local` addresses. Does the `.local` also need a SSL certificate? I remember when we ran an older version of Exchange server we always used to get warnings about SSL certificates when a new user on LAN would add an e-mail account as it would use a `.local` address.
Comment: No public CA will issue a certificate for `.local` so no.  If there is a need for internal clients to connect using a hostname like `mail.domain.local` then use the CA Server on your domain controller to issue certificates for your local domain.  Best would be to have internal and external DNS zones so you can resolve mail.yourdomain.com correctly with both internal and public IP addresses.
Answer: A word of advice. CAs are phasing out issuing UC Certs for .local so ideally you should move over your domain.com.
Multi domain SSL certs are generally cheaper than a UC Cert also and will soon serve the same purpose.
The standard ones for SBS are mail.contoso.com, remote.contoso.com and autodiscover.contoso.com.
For a regular Exchange environment mail.contoso.com and autodiscover.contoso.com are what's required. Don't forget to add autodiscover.contoso.com to your external domain DNS records here. I have seen owa.contoso.com but honestly it isn't needed.
Answer: To install the UC certificate on Exchange Server 2013, you need to mull over autodiscover, mail and OWA sub domains.

owa.yourdomain.com requires for outlook web access
mail.yourdomain.com require for a mail server's hostname
autodiscover.yourdomain.com for auto-configuration of the email clients respectively.

You should evaluate your requirements before generate CSR and configure SSL on Exchange Server 2013.


PyCharm pip install googlesearch giving error

Question: I am new to web scraping. I am using PyCharm IDE and on python 2.7 version.
I am getting the following error while installing the google search package in PyCharm.

ERROR: Could not find a version that satisfies the requirement google search (from versions: none)
  ERROR: No matching distribution found for google search

I am not getting this error in other packages like BeautifulSoup, Scrapy and Pandas.
I tried upgrading version python 3.8/ 3.4 but the error persists.
Any pointers/ help is appreciated. Many thanks in advance.
Comment: have you try installing package manually ?  using "pip install package" command ?
Comment: yes, I have tried, but that too fails with same message
Answer: Try installing
pip install google-search

Comment: I successfully installed google-search but the below commands donot work:

#from google-search import search

from googlesearch.googlesearch import GoogleSearch
#from google import googlesearch
Answer: The name of the package is google-search, so the following command will work :
pip install google-search

For next time, just googling the package will guide you to https://pypi.org/ where you can find the correct installation command.
Answer: Try to install google package:
pip install google

and then use googlesearch module, check the following reference:
https://www.geeksforgeeks.org/performing-google-search-using-python-code/
Also you can use google-seach package directly. for this one try to install google-search package:
pip install google-search

Comment: I have successfully installed google and and google-search but not sure how to import the search package in that.
Comment: None of these lines work after installing google and google-search

from google-search import search
from googlesearch.googlesearch import GoogleSearch
from google import googlesearch
Comment: After install google package by " pip install google ", to import google search module, try: " from googlesearch import search "

following resource is very helpful: https://www.geeksforgeeks.org/performing-google-search-using-python-code/