Why rinetd is working locally but not working remotly?

Question: /etc/rinetd.conf
0.0.0.0 443 10.30.224.7 636
allow *

>lsop -i|grep rinetd
rinetd    27099        root    4u  IPv4 2553556       TCP *:https (LISTEN)

Also iptables -L -n returns nothings.
Still, if I try to telnet to localhost (or using the server IP) to port 443 it will work but if I try the same from another machine it will fail with telnet: Unable to connect to remote host: Connection timed out
So, there is something on that port but it does not want to respond.
What am I missing?
Comment: If the connection times out, that means no response is coming back from the network. That's almost always caused by a firewall. (Probably a software firewall on the destination machine.)
Comment: How does it fail? Do you get an error? If so, what error?
Comment: This would be very award as all machines I tested can connect directly to the destination one `10.30.224.7:636`.
Comment: Try changing 0.0.0.0 to your server IP address
Comment: @ManulaWaidyanatha I already tried this but there is no difference.
Comment: Have you actually got a service that is listening to telnet connections on port 443 on the receiving server. You can't telnet into a listening HTTPS server - it would naturally timeout.
Comment: In fact it is not a HTTP server on the other end. It is a LDAPS server which does respond to telnet. I am trying to use 443 port because this port is allowed by the corporate firewall. Still, I do want to mention that all these tests I made were not using any firewall, yet!
Comment: Does the telnet message come back right away or hang?  Can you use netcat to create a listener on 443 and test telnet again? It sounds like a firewall issue still.
Comment: depending on your firewall it might have an intrusion detection, and your "non-https" traffic gets blocked. Can you use the service from another station in the same subnet, possibly without any involvement of additional hardware?
Comment: any log in rinetd.log file?
Answer: "Connection timed out" usually indicates a firewall is in place. If it wasn't the firewall, it would say "Connection refused" or something similar (in case service isn't accessible). Run service iptables stop and if you are on RH based OS be sure to check SELinux and disable it for the time of debugging with setenforce 0.


NVARCHAR sizes in SQL Server 2005

Question: In SQL Server 2005 (not 7.0), is there any reason to use NVARCHAR(255) instead of 256 or some other number?
Is there any optimal size, and is there any reason to use powers of two?
(I will be storing Unicode data, so I have to use NVARCHAR)
Answer: In SQL Server 2005, no.  The only reason to use 255 is if you need to consider portability with other platforms.  Some other database flavors change the name of the type completely after 255 characters.
Answer: In SQL Server (2000 and earlier IIRC), the optimal (possibly even maximum) size of columns is dependent on the size of all columns together, excluding (n)text and image contents. I believe 8K is the 'natural' size of records in a table, so your column size added together should be something less than 8000 bytes.
From SQL Server 2005 an higher this isn't much of an issue, I believe.
Comment: The maximum size of a row in SQL Server is 8060 bytes, according to the maximum capacity specs in BOL.
Answer: The optimal size is the greatest length you will need to store your data.
Comment: Yes, but I don't know exactly how long it will be, and I'm wondering what to round to.  Two or three hundred characters sounds about right.
Comment: This should be the minimum length to store your data.
Answer: No, there is no advantage of choosing maximum field lengths that are powers of two.
It's a holdover from the old and crusty days of software development where strings less than 256 characters long were stored one way, and strings over 255 characters another way.
Answer: In SQL 2005+ there is a NVarChar(max) that uses that maximum size available to you. You can store up to 2GB in that. Its the same as NText
It doesnt really matter what you store as they are all pretty much the same

NVARCHAR sizes in SQL Server 2005


Resolução do jogo Sudoku dando loop infinito em C

Question: Possuo o seguinte código em C:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// Variáveis globais
int jogo_tabuleiro[9][9] = {0};

int func_quadrante(int quadrante, int numero) {
    int retorno_quadrante = 0;
    int linha_inicio, linha_final, coluna_inicio, coluna_final;

    if(quadrante == 0) {
        linha_inicio = 0;
        coluna_inicio = 0;

        linha_final = 2;
        coluna_final = 2;
    } else if(quadrante == 1) {
        linha_inicio = 0;
        coluna_inicio = 3;

        linha_final = 2;
        coluna_final = 5;
    } else if(quadrante == 2) {
        linha_inicio = 0;
        coluna_inicio = 6;

        linha_final = 2;
        coluna_final = 8;
    } else if(quadrante == 3) {
        linha_inicio = 3;
        coluna_inicio = 0;

        linha_final = 5;
        coluna_final = 2;
    } else if(quadrante == 4) {
        linha_inicio = 3;
        coluna_inicio = 3;

        linha_final = 5;
        coluna_final = 5;
    } else if(quadrante == 5) {
        linha_inicio = 3;
        coluna_inicio = 6;

        linha_final = 5;
        coluna_final = 8;
    } else if(quadrante == 6) {
        linha_inicio = 6;
        coluna_inicio = 0;

        linha_final = 8;
        coluna_final = 2;
    } else if(quadrante == 7) {
        linha_inicio = 6;
        coluna_inicio = 3;

        linha_final = 8;
        coluna_final = 5;
    } else if(quadrante == 8) {
        linha_inicio = 6;
        coluna_inicio = 6;

        linha_final = 8;
        coluna_final = 8;
    }

    for(int l_i = linha_inicio; l_i <= linha_final; l_i++) {
        for(int c_i = coluna_inicio; c_i <= coluna_final; c_i++) {
            if(jogo_tabuleiro[l_i][c_i] == numero) {
                retorno_quadrante = 1;
            }
        }
    }

    return retorno_quadrante;
}

int func_linha(int linha, int numero) {
    int retorno_linha = 0;

    for(int c = 0; c < 9; c++) {
        if(jogo_tabuleiro[linha][c] == numero) {
            retorno_linha = 1;
        }
    }

    return retorno_linha;
}

int func_coluna(int coluna, int numero) {
    int retorno_coluna = 0;

    for(int l = 0; l < 9; l++) {
        if(jogo_tabuleiro[l][coluna] == numero) {
            retorno_coluna = 1;
        }
    }

    return retorno_coluna;
}

void func_numeros(int numeros_quadrante) {
    // Preenchendo todo o tabuleiro (quadrante por quadrante)
    int linha_inicio, coluna_inicio, linha_final, coluna_final;
    int quadrante_tabuleiro = numeros_quadrante;
    int numero_novo;

    if(quadrante_tabuleiro == 0) {
        linha_inicio = 0;
        coluna_inicio = 0;

        linha_final = 2;
        coluna_final = 2;
    } else if(quadrante_tabuleiro == 1) {
        linha_inicio = 0;
        coluna_inicio = 3;

        linha_final = 2;
        coluna_final = 5;
    } else if(quadrante_tabuleiro == 2) {
        linha_inicio = 0;
        coluna_inicio = 6;

        linha_final = 2;
        coluna_final = 8;
    } else if(quadrante_tabuleiro == 3) {
        linha_inicio = 3;
        coluna_inicio = 0;

        linha_final = 5;
        coluna_final = 2;
    } else if(quadrante_tabuleiro == 4) {
        linha_inicio = 3;
        coluna_inicio = 3;

        linha_final = 5;
        coluna_final = 5;
    } else if(quadrante_tabuleiro == 5) {
        linha_inicio = 3;
        coluna_inicio = 6;

        linha_final = 5;
        coluna_final = 8;
    } else if(quadrante_tabuleiro == 6) {
        linha_inicio = 6;
        coluna_inicio = 0;

        linha_final = 8;
        coluna_final = 2;
    } else if(quadrante_tabuleiro == 7) {
        linha_inicio = 6;
        coluna_inicio = 3;

        linha_final = 8;
        coluna_final = 5;
    } else if(quadrante_tabuleiro == 8) {
        linha_inicio = 6;
        coluna_inicio = 6;

        linha_final = 8;
        coluna_final = 8;
    }

    for(int l_i = linha_inicio; l_i <= linha_final; l_i++) {
        for(int c_i = coluna_inicio; c_i <= coluna_final; c_i++) {
            numero_novo = rand() % 9 + 1;

            int verifica_quadrante = func_quadrante(quadrante_tabuleiro, numero_novo);
            int verifica_linha = func_linha(l_i, numero_novo);
            int verifica_coluna = func_coluna(c_i, numero_novo);

            if(verifica_quadrante == 1 || verifica_linha == 1 || verifica_coluna == 1) {
                c_i -= 1;
            } else {
                jogo_tabuleiro[l_i][c_i] = numero_novo;
            }
        }
    }
}

void func_tabuleiro() {
    for(int sla = 0; sla < 9; sla++) {
        func_numeros(sla);
    }

    printf("|=================================|\n| - | 1  2  3 | 4  5  6 | 7  8  9 |\n|=================================|\n");

    for(int linha = 0; linha < 9; linha++) {
        if(linha == 3 || linha == 6) {
            printf("|   |---------+---------+---------|\n");
        }

        for(int coluna = 0; coluna < 9; coluna++) {
            if(coluna == 0) {
                printf("| %d |", linha + 1);
            }

            if(jogo_tabuleiro[linha][coluna] == 0) {
                printf("   ");
            } else {
                printf(" %d ", jogo_tabuleiro[linha][coluna]);
            }

            if(coluna == 2 || coluna == 5) {
                printf("|");
            }

            if(coluna == 8)  {
                printf("|\n");
            }
        }

        if(linha == 8) {
            printf("|=================================|\n");
        }
    }
}

main() {
    srand(time(NULL)); // Inicializando função rand

    func_tabuleiro();
}

O meu objetivo é de preencher e resolver todo o tabuleiro seguindo as regras do jogo, ou seja, um número (de 1 a 9) não pode se repetir na mesma linha, coluna ou quadrante (3 por 3). Seguindo a minha lógica, era para estar funcionando, porém ele nunca resolve "de primeira" e na maioria das vezes entra em loop infinito. O que eu fiz foi: estou preenchendo quadrante por quadrante, assim posso verificar os quadrantes anteriores podendo evitar o preenchimento da matriz com números repetidos. Então criei três funções, uma para verificar se o número gerado já existe em um quadrante, outra para verificar a linha e a outra para coluna (cada uma retorna 1 se o número existir e 0 se não existir) e utilizo o retorno delas na seguinte verificação:
if(verifica_quadrante == 1 || verifica_linha == 1 || verifica_coluna == 1) {
    c_i -= 1;
} else {
    jogo_tabuleiro[l_i][c_i] = numero_novo;
}

Na condição acima eu verifico se o número já existe em alguma das áreas (quadrante, linha ou coluna), se o número existir ele decrementa do for referente à coluna e se não existir ele adiciona o número na matriz, ou seja, esse loop vai se repetir até ser gerado um número que não exista em nenhuma das áreas.
Estou utilizando o seguinte for dentro da função func_tabuleiro:
for(int sla = 0; sla < 9; sla++) {
    func_numeros(sla);
}

O código acima serve para ir preenchendo os nove quadrantes da matriz, quadrante por quadrante e após esse for eu apenas desenho o tabuleiro.
Assim como disse anteriormente, na maioria das vezes ele entra em loop infinito, ou seja, preciso recompilar o código várias vezes até ele conseguir gerar o tabuleiro. Abaixo está o resultado do máximo de quadrantes que ele consegue preencher (8) após várias recompilações do código (com o valor for(int sla = 0; sla < 8; sla++)), < 8 porque esse é o máximo que ele consegue, se eu alterar para < 9, ou seja, para preencher tudo, ele sempre fica em loop infinito (mesmo re-executando o código múltiplas vezes).

Como corrigir esse loop infinito para que o tabuleiro/matriz possa ser sempre preenchida da maneira correta logo na primeira execução?
Comment: Bom, eu não entendo a sua lógica, mas há mesmo algum potencial para entrar em loop infinito ai justamente porque você decrementa a variável `c_i `. Esse decremento não faz muito sentido pra mim (você poderia tentar explicá-lo?). Num cenário em que o seu valor acabou de se tornar `n`, por exemplo, esse decremento o faz se tornar `n-1` justamente antes de retornar ao laço - que vai fazer o valor voltar a `n`! Qual é o objetivo disso?
Comment: Outro problema potencialmente grave do seu código é que a escolha dos números é aleatória. Isso faz com que o seu algoritmo não seja determinístico, e por isso possa demorar muuuiiiitooo tempo (e parecer ser um loop infinito mesmo que não seja). Por exemplo, se as chamadas de `rand()` ficarem gerando 3, 7, 9, 3, 7, 9, 3, 7, 9, 3, 7, 9,... o seu algoritmo nunca irá terminar! Se a sua escolha de algoritmo é essa, o mais indicado é você usar uma lista com os números de 0 a 9 e ir removendo os utilizados da lista.
Comment: Então, @LuizVieira, eu utilizo o decremento na variável `c_i` para ele repetir o laço até ele gerar um número inexistente no quadrante, linha ou coluna para assim poder adicionar ele à matriz. Sobre a aleatoriedade, poderia explicar melhor essa lista de números (1 a 9)? Pois gostaria que fosse o mais aleatório possível...
Comment: Bom, se você precisa repetir mantendo o controle da variável `c_i`, deveria *preferencialmente* utilizar um `while` ao invés de um `for`. Como eu disse, há ai um **potencial** para loop infinito, não tô dizendo que é necessariamente o problema. De fato, o problema mais seguramente está na aleatoriedade. O que eu sugeri é você criar uma lista (em C um vetor mesmo serve) com os números de 0 a 9, organizá-los aleatoriamente (leia sobre permutação aleatória e dê uma olhada no último exemplo [dessa página](http://www.ime.usp.br/~pf/algoritmos/aulas/random.html)) e então ir utilizando-os um a um.
Comment: Poderia dar um exemplo de como utilizar o `while`? Pois estou utilizando o `for` para poder inserir o número gerado na posição correta... Em relação à permutação aleatória, devo utilizar ela pela possibilidade do `rand()` gerar números iguais mesmo aleatoriamente?
Comment: Colega, desculpe, esse site não é um fórum. Se vc tem dificuldades em construir um `while`, pode tentar pedir ajuda no [chat]. Sobre o `rand`, é justamente esse o ponto: aleatoriedade não inclui garantia de números diferentes. Se vc utilizar a permutação aleatória, ai *você* garante que os números serão diferentes.
Answer: Eu não analisei todo o código para ver se há outros problemas. Mas um potencial problema do seu código é que você faz o seguinte no trecho que faz a tentativa de montar cada coluna/linha (os dois for encadeados na chamada de func_numeros):

Sorteia um número aleatoriamente entre 0 e 9.
Procura se o número sorteado já foi utilizado.
Se o número sorteado ainda não foi utilizado, utiliza-o (e pula pro passo 5).
Se o número sorteado já foi utilizado, volta ao passo 1.
Continua o programa...

Bom, o princípio de um sorteio aleatório é que ele é... aleatório! Não há garantia de que você terá sempre números distintos. É uma questão de estatística elementar: todos os números no intervalo do sorteio têm a mesma probabilidade de ser sorteados a cada novo sorteio!
Por exemplo, você faz um sorteio e tira o número 3 (ele tem 10% de chance de ser sorteado, já que o intervalo é de 0 a 9). No próximo sorteio, a chance de tirar o número 3 novamente é: 10%! Tá certo que todos os outros números têm, juntos, 90% de chance de serem sorteados. Mas ainda existe a chance de sair o 3.

Veja esse exemplo de código no Ideone que gera 100 números
  aleatórios entre 0 e 9. Eu testei uma vez e obtive o seguinte
  resultado:
1 7 3 7 4 7 5 9 7 7 4 0 6 0 4 9 3 8 0 2 6 1 6 6 9 6 4 5 3 1 5 5 8 8 2 2 6 7 2 4 5 6 5 2 7 9 2 0 8 2 3 4 4 9 1 3 6 6 9 9 7 5 4 6 3 6 9 0 4 1 4 0 8 9 2 5 9 4 6 7 6 0 2 1 0 3 4 6 9 4 5 7 9 0 3 3 7 2 3 1
Pode-se observar, em negrito nessas 100 chamadas de exemplo, que foi
  necessário gerar 20 números (o dobro do necessário!) para que todos os
  números fossem obtidos (o último foi o número 2). Observe quantas
  vezes o número 7 foi produzido desnecessariamente.

Assim, esse seu algoritmo essencialmente funciona, mas ele tem um problema grave. Como você sorteia um novo número sem considerar os que já foram utilizados, o seu programa pode demorar muito, e esse muito pode ser mesmo tendendo ao infinito (ou ser suficientemente grande para te dar a impressão de que travou em loop). Pode parecer bobagem ou perfeccionismo se preocupar com esse repetições de números em um intervalo tão pequeno (0 a 9), mas se você considerar que o seu algoritmo procura se o número já existe na seção, na linha e na coluna, o custo computacional de fazer a busca por um número já sorteado fica bem caro.
A solução ideal então é que antes de iniciar esses cálculos (o seu laço for duplo), você monte uma lista com os números de 0 a 9, sorteie a ordem que eles ficarão (isto é chamado de permutação aleatória) e então vá utilizando um por um, removendo o número utilizado da lista (pode usar uma estrutura de dados de pilha, por exemplo).
Um exemplo de código que faz permutação aleatória em um vetor é esse:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int randomInteger(int low, int high)
{
    int k;
    double d;
    d = (double)rand() / ((double)RAND_MAX + 1);
    k = (int) (d * (high - low + 1));
    return low + k;
}

void permutacaoAleatoria(int v[], int n) {
    int r, k, t;
    for (k = n - 1; k > 0; k--) {
        r = randomInteger(0, k);
        t = v[k], v[k] = v[r], v[r] = t;
    }
}

void randomize()
{
    srand(time(NULL));
}

int main() {

    int nums[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    randomize();
    permutacaoAleatoria(nums, 10);
    int i;
    printf("Valores no vetor: [");
    for (i = 0; i < 10; i++)
        printf("%s%d", (i != 0 ? ", " : ""), nums[i]);
    printf("]");
    return 0;
}

Ele foi baseado nos exemplos dessa página. Veja executando no Ideone.
Comment: Obrigado pela resposta, fiz as mudanças no meu código em relação ao `while` e a permutação, porém agora o erro que ocorre é: ele preenche todo o tabuleiro, mas quando chega em uma posição em que o número não pode ser preenchido ele preenche com lixo e se eu prevenir esse lixo (vindo da `nums[]`) somente o último quadrante é preenchido... Devo criar outra pergunta para o meu problema ou editar a atual?
Comment: Olá Igor. Por nada. Crie outra pergunta. Este site não é um fórum. :) Lembre-se de adicionar na sua outra pergunta os trechos relevantes de código. Ah, e se essa resposta lhe foi útil, por favor considere marcá-la como aceita.


Improvement of regression model

Question: I am just learning R. I have developed a regression model with six predictor variables. While developing it, I found the relationships are not very linear. So, maybe because of this the predictions of my model are not exact.
Here is Headers of my data set:
1.bouncerate(To be predicted)
2.avgServerResponseTime
3.avgServerConnectionTime
4.avgRedirectionTime
5.avgPageDownloadTime
6.avgDomainLookupTime
7.avgPageLoadTime

Sample datasets:
28.57142857,4.132,0.234,0,0.505,0,14.168
42.85714286,3.356777778,0.090777778,0.077333333,0.459,0.105444444,14.78644444
0,3.372,0.1105,0.0015,0.425,0.1305,34.3425
33.33333333,3.583,0.218,0,0.385,0.649,11.816
66.66666667,2.438,0.234,0,0.3405,0,8.645
100,2.805,0.179666667,3.203666667,0.000333333,0.11,13.47066667
66.66666667,0.977,0,0.003,0,0,12.847
0,2.776,0,7.888,0,0,14.393
100,2.59,0.261,0,0.517,0,6.216

Here is the summary of my model:
Call:
lm(formula = y ~ x_1 + x_2 + x_3 + x_4 + x_5 + x_6)

Residuals:
     Min       1Q   Median       3Q      Max
-125.302  -26.210    0.702   26.261  111.511

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) 48.62944    0.27999 173.684  < 2e-16 ***
x_1         -0.67831    0.08053  -8.423  < 2e-16 ***
x_2          0.07476    0.49578   0.151 0.880143
x_3         -0.22981    0.06489  -3.541 0.000399 ***
x_4          0.01845    0.09070   0.203 0.838814
x_5          3.76952    0.67006   5.626 1.87e-08 ***
x_6          0.07698    0.01565   4.919 8.75e-07 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 33.76 on 19710 degrees of freedom
Multiple R-squared: 0.006298,   Adjusted R-squared: 0.005995
F-statistic: 20.82 on 6 and 19710 DF,  p-value: < 2.2e-16

plot with all single variable are below:

I have certain questions about this model:

Is there any way to improve the accuracy of this model?
Which of the values is most useful: residual standard error, degrees of freedom, multiple R-squared, adjusted R-squared, F-statistics, or p-values for choosing best model?
Is it appropriate to use polynomial transformations with these data?
In case I do use polynomial terms in my model, which degree is most appropriate?
Comment: Most of your questions cannot be answered without knowing what all those variables represent and without access to your data.
Comment: How did you find the relationships weren't linear?
Comment: and can any one suggest me which one is best attribute among these esidual standard error, degrees of freedom, multiple R-squared, adjusted R-squared, F-statistics, or p-values for choosing best model to choose the best model?
Answer: @Roland is correct that it's hard to say much without knowing what you're doing, substantively speaking.  However, there are a few remarks we can still make.  They fall into the categories: discovering why it's no good, making it better, and demonstrating improvement.
Diagnostics
R has good linear model diagnostics.  Apply them, and read up enough to know what they are telling you.  To see all the available ones
model <- lm(formula = y ~ x_1 + x_2 + x_3 + x_4 + x_5 + x_6)
plot(model, 1:6) ## all of them

Each addresses a possible failing.  You might check for linearity and interactions first because you've enough data to do something about them.
Making it better
You have lots of data.  This means that if there is non-linearity you can potentially learn its form from the data.  A generalised additive model (GAM) would be a good start and will probably work better than some random set of polynomials.  If you don't want or can't do that, then at least some splines might be helpful.
Also, work your way through the interactions that make sense.  These will generate apparent non-linearity and spoil predictions if not modeled.  Read up about R's formula interface to see how to specify them.
Polynomials can work, but without knowing what your data actually is it's hard to say whether they'd be a good idea.  Also hard to say, and for the same reasons, is whether your predictor variables might be usefully transformed (logged, etc.)
Confirming it's better
Since your only task is to make the model better then the only quantity worth working with is held-out prediction error.  Do whatever you do on a subset of the data then try it out on the held-out set.  (Iteratively this is cross-validation).  You have to decide what counts as 'doing better' prediction in the context of your problem, but a common choice is root mean squared error.  Here again I'm assuming that you actually do have data that is potentially conditionally normal, as your choice of lm implies.
Practically this would involve writing a function to compute that quantity (or one suitably like it) from a set of predictions and a set of held-out data points.  The do your fiddling around and optimizing the model on the other part of the data, use predict to get predictions on the held-out, and apply the function.
Note that performance on held-out data is not any of the quantities you are wondering about.  Those are all in-sample measures and will typically overestimate prediction performance on new data.
Caveats
Finally, note that prediction may just be hard.  You may not have the right variables: most likely some important ones are missing, and you can do nothing more about that without knowing what they are.
And that's about as much generic advice as can be given for a bunch of variables called $[y, x_1\ldots x_6]$...
Answer: Your analysis reports "19710 degrees of freedom ". Are you trying to use simple OLS to deal with time series data? If yes the answer to your question #3 is "0" as polynomial regressions in time are incorrect. Use fixed effects such as hour of the day , day of the week , holiday effects etc . Detect significant level shifts and/or local time trends and incorporate them as predictors. Detect anomalies and incorporate pulse indicators. Test for constancy of parametrs and constancy of variance (error) over time. In summary your r-sq suggests that you have incorrectly specified the model and are just finding significance due to your false sample size.

Improvement of regression model


Can it be considered as a statistical support for my hypothesis?

Question: I'd like to get statistical support for hypotheses concerning the effects of independent variables $D,CF,CT,P,H,LA,LP$ on $C$. For regressor sets $\{D,CF,CT,P,LA,LP\}$ and $\{D,CF,CT,H,LA,LP\}$ all the independent variables are statistically significant:
Call:
clogit(C ~ D + CF + CT + P + LA + LP + strata(Case), clog_data)

                       coef exp(coef)  se(coef)      z       p
D                 -5.91e-03  9.94e-01  7.21e-05 -81.94 < 2e-16
CF                 3.78e-03  1.00e+00  8.10e-04   4.67 3.0e-06
CT                 2.60e-04  1.00e+00  5.18e-05   5.02 5.2e-07
P                  6.07e-01  1.84e+00  3.32e-02  18.32 < 2e-16
LA                 8.71e-02  1.09e+00  2.41e-02   3.62 0.00029
LP                -8.93e-02  9.15e-01  1.83e-02  -4.89 1.0e-06

Likelihood ratio test=11528  on 6 df, p=0
n= 71403, number of events= 12339

Call:
clogit(C ~ D + CF + CT + H + LA + LP + strata(Case), clog_data)

                       coef exp(coef)  se(coef)      z       p
D                 -5.80e-03  9.94e-01  7.15e-05 -81.15 < 2e-16
CF                 7.87e-03  1.01e+00  7.73e-04  10.17 < 2e-16
CT                 3.13e-04  1.00e+00  5.10e-05   6.13 8.9e-10
H                 -9.47e-02  9.10e-01  2.01e-02  -4.71 2.5e-06
LA                 9.49e-02  1.10e+00  2.39e-02   3.97 7.2e-05
LP                -5.75e-02  9.44e-01  1.81e-02  -3.18  0.0015

Likelihood ratio test=11206  on 6 df, p=0
n= 71403, number of events= 12339

For the full set of regressors $\{D,CF,CT,P,H,LA,LP\}$, one of the independent variables $(H)$ is not statistically significant
Call:
clogit(C ~ D + CF + CT + P + H + LA + LP + strata(Case), clog_data)

                       coef exp(coef)  se(coef)      z       p
D                 -5.90e-03  9.94e-01  7.24e-05 -81.53 < 2e-16
CF                 3.73e-03  1.00e+00  8.16e-04   4.57 4.8e-06
CT                 2.61e-04  1.00e+00  5.18e-05   5.03 4.9e-07
P                  6.03e-01  1.83e+00  3.40e-02  17.74 < 2e-16
H                 -1.10e-02  9.89e-01  2.08e-02  -0.53 0.59625
LA                 8.68e-02  1.09e+00  2.41e-02   3.61 0.00031
LP                -8.95e-02  9.14e-01  1.83e-02  -4.89 9.9e-07

Likelihood ratio test=11528  on 7 df, p=0
n= 71403, number of events= 12339

Are my hypotheses statistically supported?
Update1: Correlation matrix
            Case     D     CF    CT    H     P     LP    LA     C
  Case      1.00    -0.01  0.00 -0.01 -0.01 -0.01  0.00 -0.01   0.00
  D        -0.01     1.00 -0.05  0.05  0.07  0.12  0.06  0.04  -0.35
  CF        0.00    -0.05  1.00 -0.18 -0.28  0.40  0.19  0.17   0.08
  CT       -0.01     0.05 -0.18  1.00  0.07 -0.03 -0.07 -0.04   0.00
  H        -0.01     0.07 -0.28  0.07  1.00 -0.31 -0.12 -0.12  -0.06
  P        -0.01     0.12  0.40 -0.03 -0.31  1.00  0.24  0.21   0.06
  LP        0.00     0.06  0.19 -0.07 -0.12  0.24  1.00  0.81   0.00
  LA       -0.01     0.04  0.17 -0.04 -0.12  0.21  0.81  1.00   0.01
  C         0.00    -0.35  0.08  0.00 -0.06  0.06  0.00  0.01   1.00

Update2: VIF
                      GVIF Df GVIF^(1/(2*Df))
D                 1.027972  1        1.013890
CF                1.210073  1        1.100033
CT                1.049540  1        1.024471
P                 1.245100  1        1.115841
H                 1.124559  1        1.060452
LA                2.684257  1        1.638370
LP                2.749423  1        1.658138
strata(Case)      3.470383  0             Inf
Warning message:
In vif.default(clogit(C ~ D + CF + CT + P + H +  :
No intercept: vifs may not be sensible.

Comment: What are your variables?  In particular, what are H and P? It looks like they might be colinear.
Comment: The problem is not limited to $H$ and $P$, as evidenced by the substantial changes in the estimates of $CF$ and $LP$ as $H$ and $P$ are added.
Comment: You didn't answer my question. Also, colinearity is not the same as correlation.
Comment: @Peter Flom I'm sorry. What would you like to know about $H$ and $P$?
Comment: I want to know what all your variables are, what your research question is, what you are trying to find out.  Like, is H blood pressure? Age? or what? And similarly for the other variables.
Comment: @Peter Flom Thank you for your attention to my question. $C$ is choice (1/0) made by customers depending on some factors. I'd like to check which factors affect customer's choice. May I ask you why do the nature of the variables and my research question matter here?
Comment: They always matter. It's hard to say why they matter in your specific case, because we don't know what they are.  But solving statistical problems without context is like boxing while blindfolded.  You might knock your opponent out or you might bash your had on the ring post
Comment: Thanks. All independent variables are continuous factors for choice $C$ which is binomial. Correlation between $H$ and $P$ is -0.31
Answer: With 12000+ events you are far from overfitting, so using the full set of regressors allows you to minimize potential problems from omitted-variable bias. In that full model, variable H does not pass the standard $p < 0.05$ test of statistical significance, while all the others do (even if you feel compelled to correct for multiple comparisons for the 7 coefficients). That's the model to focus on.
The results from the models that omit one of H and P aren't surprising, given the correlation matrix and the coefficients found for those two variables. They have a reasonably large negative correlation and regression coefficients of opposite signs. When you omit P from the regression, H then is able to pick up some of the influence of P even if its direct relation to outcome is minimal. That's consistent with omitted-variable bias in the regression omitting P. The simplest explanation is that H isn't closely related to outcome; it only appears to be if you ignore P, which is highly related both to outcome and to H.
VIF tells you how much the variance of the estimated coefficient might be inflated by correlations with other variables. A low VIF doesn't rule out omitted-variable bias.
This page is one of many on this site that discuss this general issue.
Comment: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/68102/discussion-between-8k14-and-edm).
Comment: Let me ask you once again.
$H$ and $P$ are product attributes and $C$ is the choice (1/0) the customer makes. Trying to catch the "inertia effect" of these attributes, I ran two conditional logistic regression including interaction terms $H:H0$ and $P:P0$, respectively, where $P0$ and $H0$ are the attributes for the product just purchased. The corresponding coefficient in the regression for $P$ is not statistically significant while for $H$ everything is fine. May I say that I have this effect for $H$ even if $H$ is not directly related to the outcome?
Comment: @8k14  It's possible to have a significant interaction effect without a significant main effect. If that's what your "conditional logistic regression" (evidently including information about a prior purchase) says, what you describe is OK. This, however, is a change from the model originally described in your question. With correlated predictors like these, changes in models may well lead to switches between which predictor is deemed "significant." A predictor can still be "directly related to the outcome" yet be deemed not "significant" due to collinearity, too few cases, etc.
Comment: @ EdM Thanks again for your answer but I have to say that didn't quite understand it. Is it legitimate to consider an interaction effect of a predictor that is not significant on its own?
What model change do you mean?
Comment: @8k14  It is OK to consider an interaction with a predictor that is not "significant" on its own; its interaction with another predictor might be hiding any overall effect of the predictor on its own. For "model change" I meant your inclusion of interaction terms like H:H0 in the conditional logistic regression in your comment; such terms don't seem to appear in the original models presented in the question. So if that's the case, the models presented in the question are different from the models discussed in your comment. But I might have misunderstood.
Comment: @ EdM Thanks a lot for your explanation. You are right, the predictor H is not in my base model. To check the inertia effect I include the interaction term H:H0. Should I include in the model the single term H as well? Without it all the regressors are statistically significant and H is not, similarly to the case of the base model.
Comment: @8k14 the usual rule to avoid omitted-variable bias is to include all predictors that might reasonably be expected to have individual relations to the outcome or to affect the relations of other predictors to outcome, if you can do so without overfitting. You have a very large number of events relative to the number of predictors, so overfitting is not an issue here. Your best approach would be to include all these predictors and an appropriate set of interactions in the final model.
Comment: @ EdM Thank you again. Do you mean that I should include the factor H along with the factor P in my base model even if the former is not statistically significant and affects the outcome mostly through the latter?
Comment: @8k14 absolutely, yes. Otherwise you run a risk of omitted-variable bias, at least.
Comment: Thanks a lot for the detailed answer. I think now the picture is clear for me. Back to my initial question: effects for all the independent variables except $H$ are statistically supported and effect for $H$ is not, right?
Comment: @8k14 Yes, that would be my interpretation of the analyses that you presented.
Comment: Thanks. On the other hand if I'm presented only with the second regression ($P$ omitted) I have solid reasons to believe that the hypothesis for $H$ is supported, right?
Comment: If you had no information about `P` and its relation both to outcome and to `H` then you might claim to have found statistical evidence for a role of `H` based on that limited model. That claim, however, would not be a good model of reality; with omitted-variable bias a "statistically significant" result can be grossly erroneous.
Comment: Thanks again. How can I know that this limited model is not a good model of reality? Are there any statistical methods for that or it's only in the nature of the process?
Comment: [This page](https://stats.stackexchange.com/q/30131/28500) suggests that if you have an "instrumental variable" you might be able to test for omitted-variable bias. I have no experience with instrumental variables. But that's for OLS, not logistic regression as in your example. In logistic regression you can have omitted-variable bias even if the omitted variable is uncorrelated to the predictors in your model.
Answer: You should check VIF because probably You have variables P and H highly correlated, which broke assumption of the regression in 3rd model.
If a information from one variable is incorporated to the model the second didn't has a chance to be significant.
Comment: The high correlation between `P` and `H` doesn't break any assumptions about the logistic regression, but as you point out it does make it difficult to separate out any individual contributions of those 2 variables to the outcome.
Comment: Thanks. VIFs and correlation matrix are now included in my question. I may be wrong but I don't see collinearity here.


Is conditional probability always meaningful

Question: Problem:
A bag contains $4$ red and $5$ white balls. Balls are drawn from the bag without replacement.
Let $A$ be the event that first ball drawn is white and let $B$ denote the event that the second ball drawn is red. Find
(i) $P(B\mid A)$
(ii) $P(A\mid B)$
My confusion is that should $P(A\mid B)=P(A)$
Can we say that in general if $P(A\mid B)$ exists then $P(B\mid A)$ should also exist?
Comment: Certainly both of these conditional probabilities exist, and the events $A$ and $B$ are _not_ independent (as they would be if $P(A\mid B)=P(A)$). ${}\qquad{}$
Comment: If the ball drawn is placed back into the bag, then A and B would be independent and P(A|B) = P(A). In your case it's not true.
Comment: If you think about your "probability space" as being all possible ways balls can be drawn out of the bag, then it makes sense because you then are asking questions about all possible sequences of ball drawings.
Answer: Let the event space be
$$\Omega=\{(r,r),(r,w),(w,r),(w,w)\}$$
the corresponding probabilities are
$$\frac{12}{72},\frac{20}{72},\frac{20}{72},\frac{20}{72}.$$
Then
$$Pr(A\cap B)=Pr((w,r))=\frac{20}{72}$$
and
$$Pr(B)=Pr(\{(r,r),(w,r)\})=\frac{12}{72}+\frac{20}{72}=\frac{32}{72}$$
and
$$Pr(A)=Pr(\{(w,r),(w,w)\})=\frac{40}{72}$$
so,
$$Pr(A\mid B)=\frac{Pr(A\cap B)}{Pr(B)}=\frac{\frac{20}{72}}{\frac{32}{72}}=\frac58.$$
and
$$Pr(B\mid A)=\frac{Pr(A\cap B)}{Pr(A)}=\frac{\frac{20}{72}}{\frac{40}{72}}=\frac12.$$

In general we cannot say that if $Pr(A\mid B)$ exists then $Pr(B\mid A)$ also exists. Let simply $Pr(A)=0<Pr(B)$. Then $Pr(A\mid B)=0$ but $Pr(B\mid A)$ is not defined.
Comment: Because we are sampling without replacement, the denominator in the probabilities should be $9\times 8$, not $9\times 9$.
Comment: Thx @ByronSchmuland. It was just a "continuous" typo.
Answer: In general:
$$P(B|A)P(A)=P(A\cap B)=P(A|B)P(B)$$
If you can find $P(A),P(B)$ and $P(A\cap B)$ then this enables you to find $P(A|B)$ and $P(B|A)$.
Note that $P(A|B)=P(A)$ leads to $P(A\cap B)=P(A)P(B)$ i.e. independence of $A$ and $B$.
In your question $A$ and $B$ are not independent.

Hints:

To find $P(B)$ realize that the $9$ balls all have equal probability to become the second ball drawn, and $4$ of them are red, so...
Actually finding $P(B|A)$ "directly" is somehow easyer than finding $P(A\cap B)$. If the first ball has been drawn and is white then there are $8$ balls left and $4$ of them are red, so...
Answer: $P(A \mid B) \neq P(A)$.
$$P(A \mid B)= \frac{P(A \cap B)}{P(B)} = \frac{\frac5{18}}{\frac59\times\frac48+\frac49\times\frac38} = \frac{5}{8}$$
We have $P(A)=\frac{5}{9}$. The intuition behind this is that $B$ makes it more likely that a white ball has been drawn the first time, because then $B$ is more likely.
The key in the problem is that the balls are drawn without replacement. Otherwise we would have $P(A \mid B) = P(A)$.

Conditional probability is always meaningful. $P(A \mid B)=P(A)$ also give information. It namely tells you that $A$ and $B$ are independent.
Answer:
Can we say that in general if $P(A\mid B)$ exists then $P(B\mid A)$
  should also exist?

Not necessarily. I modifiy your exercise.

A bag contains $4$ red and $5$ white balls. Balls are drawn from the
  bag without replacement.
Let $A$ be the event that first ball drawn is white and let $B$ denote the event that the second ball drawn is black. Find
(i) $P(B \mid A)$
(ii) $P(A\mid B)$

$P(B)=0$, therefore $P(A\mid B)=\frac{P(A \cap B)}{P(B)}$ is not defined.


Style guide for asymptotic notation

Question: There are two widely accepted forms of asymptotic notation:

$f(n) = O(g(n))$
$f(n) ∈ O(g(n))$

1 seems to be more widely used, but implies a symmetry between the two sides that just isn't there. 2 is less confusing in that way, but is less used.
Are there any commonly used mathematical style guides that recommend one over the other? Or at least ones that say something on the matter?
Comment: For example, $f(n)$ appearing there is not a number (as it seems to be) but abusive notation for a function $n \mapsto f(n)$.  Perhaps someone should propose notation $(n \mapsto f(n)) \in O(n \mapsto g(n))$.  No, please don't.
Comment: @TinMan There are no accepted "style guides" in maths.
Comment: Thanks—done! :)
Comment: 2. is a better notation, but 1. is almost always used. @TinMan
Comment: Lots of common and widely-used notation and terminology could be improved.  But changing it for that reason is almost never successful.
Comment: @LordSharktheUnknown I know. I'd be interested to know if there is a style guide that could back up that argument. I'd like to set a standard in a group, and arguments like "I like this better" don't hold much water.
Comment: @LordSharktheUnknown What about the AMS Style Guide?
Comment: Or the Mathematics section in Wikipedia's Manual of Style: https://en.wikipedia.org/wiki/Wikipedia_talk:Manual_of_Style/Mathematics ?
Comment: Both of those are guides for *typesetting*, not for notation.
Comment: @AntonioVargas There's a "Mathematical conventions" section on the Wikipedia page, with "Notational conventions" as a subsection.
Comment: Ah, you linked the talk page before so I didn't see it. That page may be a guide for writing math *on wikipedia*, but it's not a style guide for writing mathematics in general. I echo @LordSharktheUnknown 's comment that there are no **accepted** style guides in math.
Answer:
There is no commonly used mathematical style guide that provides a recommendation. But sometimes one of the great tells us reasons for his preferences. An interesting paper of this kind is Big Omicron and Big Omega and Big Theta by D.E. Knuth from 1976.
Comment: Just to quote what he says: "The equal sign here really means c (set inclusion), and this has bothered many people who propose that we not be allowed to use the = sign in this context. My feeling is that we should continue to use one-way equality together with O-notations~ since it has been common practice of thousands of mathematicians for so many years now, and since we understand the meaning of our existing notation sufficiently well."
Comment: @TinMan: I agree and I think that we can fully trust him, since he is not only a remarkable mathematician but also the man who gave us TeX. So, he *really* knows the things about good notation. :-)

Style guide for asymptotic notation


Paired t-test assumptions

Question: I would like to perform some paired t-test by using Wilcoxon tests. I am trying to figure out which one should be the assumptions that I need to make from before. From what I found so far I need to respect the following:

The two groups need to be independent.
The differences between the two samples need to be normally distributed.
The variables need to be measured at either the interval or ratio level of measurement.

My question is what exactly should I do for the two last bullets? Also, should I consider checking the constant variance? Is it also an assumption for paired t-tests?
Answer:
If you're doing a paired t-test, then the two groups most definitely should be related, often by measuring a before and after on the same subject.
This would be an assumption of the paired t-test. When this assumption is violated, the Wilcoxon signed-rank test is a viable nonparametric alternative. (This isn't quite true, because of the central limit theorem, but it's close enough for now.)
This makes sense to me, though I am open to being wrong.

I am not sure, however, that you're using the terminology that you intend to use. The paired t-test is a one-sample test; your sample is composed of the differences between pairs (such as after minus before). I think you have two samples that you want to compare, not paired samples. Please leave a comment with your setup.
Comment: My scenario is that I have two population performing a test, for example, a bachelor and master students playing a game and I want to figure out whether their time and performance is significantly different. When I perform t-test it shows that their mean is significantly different but I guess also I need to have some assumptions like the one I mentioned before I am to perform the tests.
Comment: As I suspected, you're not doing a paired test. A paired test would be something like evaluating the performance on a test of Brad, Ronald, and John before starting their master's degrees and then again after. You're doing two-sample testing. Yes, if you want to use the t-test, you should examine your data to make sure the assumptions are met. (Some have said that it's improper to examine your data, since that examination could be wrong, though relying on prior knowledge or intuition instead of examining the data doesn't seem practical.)
Comment: Then what exactly the constant variance means in that case. Should both population have similar variance?
Comment: @JoseRamon Both populations should have the same variance. The Welch test, which is the default "t-test" in R software, accounts for unequal variance.

Paired t-test assumptions


How to reshape input data correctly for input in CNN model?

Question: I have a CNN model, which input image size is (150, 150). I want to feed array-like data for predict function (tensorflow) like this:
fig = plt.figure(figsize=(1.5, 1.5))
plt.plot(time_values, signal_values, '-o', c='r')
plt.axis('off')
fig.canvas.draw()
data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))

And when I try:
CNN_model.predict(data)

I get an error:
WARNING:tensorflow:Model was constructed with shape (None, 150, 150, 3) for input Tensor("input_1:0", shape=(None, 150, 150, 3), dtype=float32), but it was called on an input with incompatible shape (None, 150, 3).
Traceback (most recent call last):

Why my shape is (None, 150, 3), but not (None, 150, 150, 3)?
Comment: In the last line, just directly write `data.reshape((1, 150, 150, 3))`
Comment: @SreekantShenoy thank you a lot. As I understood, the firtst value here (None, 150, 150, 3) is equal to ((1, 150, 150, 3))
Answer: Just add a new dimension to your array data:
data = data[None, :]

Its shape will then be (1, 150, 150, 3), as expected by tensorflow.


React application router

Question:
import React, { Component } from 'react';
import './App.css';
import {Switch,Route} from 'react-router-dom';
import 'bootstrap/dist/css/bootstrap.min.css';
import Navbar from './componants/Navbar';
import ProductList from './componants/ProductList';
import Details from './componants/Details';
import Default from './componants/Default';
import Cart from './componants/Cart';

class App extends Component {
  render() {
    return (
      <React.Fragment>
        <Navbar />
       <Switch>
         <Route exact path={'/'} Component={ProductList} />
         <Route path={'/Details'} Component={Details} />
         <Route path={'/Cart'} Component={Cart} />
         <Route Component={Default} />
        </Switch>
      </React.Fragment>
    );
  }
}

export default App;

Why <switch></switch> not working while I reach any page of my application?
Comment: Please be more specific about your question. What do you mean by "not working"? Error messages, screenshots, how does your `index.js` look like?
Answer: you need to specify like this
<Route exact path="/" component={PlaceOrder} />
<Route path="/updatepredicted" component={UpdatePredicted} />
<Route path="/kitchen" component={Kitchen} />

looks at the path

React application router


What's wrong with my GET request? (Commerce Services, REST)

Question: I'm developing a mobile app to connect with my Drupal Commerce (Kickstart) store, using a REST server.
When I do GET: endpoint/rest/product it retrieves the products list
<result is_array="true">
    <item>
        <revision_id>1</revision_id>
        <sku>TOT1-GRN-OS</sku>
        <title>Tote Bag 1</title>
        <revision_uid>1</revision_uid>
        <status>1</status>
        <log />
        <revision_timestamp>1423972403</revision_timestamp>
        <data />
        <product_id>1</product_id>
        <type>bags_cases</type>
        <language>und</language>
        <uid>1</uid>
        <created>1423972403</created>
        <changed>1423972403</changed>
        <title_field>Tote Bag 1</title_field>
        <commerce_price>
            <amount>1600</amount>
            <currency_code>EUR</currency_code>
            <data>                <components />
                </data>
        </commerce_price>
        ...
    </item>
    <item>
     ...
    </item>

Everything looks fine. I can even GET endpoint/rest/product?status=1 and it does filter well.
I'm trying to filter by commerce_price.amount:
GET endpoint/rest/product?commerce_price.amount=1600
but it's not working. I have no problems filtering by a first level key, but can't access second level ones and so on. What am I doing wrong?
Answer: From what I understand, querying only works on entity properties. That is why status works, commerce_price is a field and won't work. Checkout Services Entity API, it may do what you're looking for.
You may still be out of luck though. You alternatives will be to use services_views or write your own Services Resource.
Comment: Additionally, a commerce price is a different entity type to a commerce product. Being able to query by fields wouldn't be enough for this, you'd also need the api module to resolve the entity reference as well. Be nice, but I doubt anyone's gone to those lengths
Comment: @Clive I think you're exactly right. I updated my answer to mention services_views or a custom resource right after i posted my initial answer.


Atualizar uma Jtable que está numa JFrame a partir de um JDialog

Question: O que estou fazendo é um pouco mais longo, por isso vou encurtar o problema com um exemplo mais objetivo:
Tenho um form de cadastro e criei uma Jdialog modal com os campos que eu quero pesquisar. Quando eu pesquiso na JDialog gostaria de filtrar as informações na tabela que está na JFrame. O problema é que não está funcionando.
Segue código (neste caso o exemplo é com o setvisible que tb não está funcionando, acredito que seja o mesmo problema):
VISAO (Tela de pesquisa):
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    FrmCadUsuarios frm = new FrmCadUsuarios();
    frm.tbVisivel(true);
}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
    FrmCadUsuarios frm = new FrmCadUsuarios();
    frm.tbVisivel(false);
}

VISAO (form de cadastro):
public class FrmCadUsuarios extends javax.swing.JFrame {

    private JTable tbUsuarios;
    DefaultTableModel modelo = new DefaultTableModel();

    public FrmCadUsuarios() {
        initComponents();
        this.setLocation(550,250);
        criaTabela();
        jScrollPane1.setViewportView(tbUsuarios);

    }

    public void tbVisivel (boolean aa) {
        tbUsuarios.setVisible(aa);
    }

}

Chamo a JDialog assim:
private void tb_btn_pesquisarActionPerformed(java.awt.event.ActionEvent evt) {
  frmPesquisa pesq = new frmPesquisa(this,false);
  pesq.setVisible(true);
}

e tento atualizar uma JLabel na tela do main assim tem 2 botões, 1 deveria deixar a label visivel e a outra invisivel:
private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {
  FrmCadUsuarios frm = new FrmCadUsuarios();
  frm.tbVisivel(this, true);
}

private void btn3ActionPerformed(java.awt.event.ActionEvent evt) {
  FrmCadUsuarios frm = new FrmCadUsuarios();
  frm.tbVisivel(this, false);
}

O Construtor do form pesquisa (JDialog) está da seguinte maneira:
public frmPesquisa(java.awt.Frame parent, boolean modal) {
  super(parent, modal);
  initComponents();
  this.setLocation(1300,100);
}

Comment: Para fazer filtros em `JTable` você precisa usar a classe `TableRowSorter` passando seu `TableModel`. Adicione seu table model na pergunta para facilitar te responder.
Comment: Oi Diego! O problema é um pouco antes de chegar nisso. Não estou conseguindo implementar o Listener, por exemplo, se eu crio um JDialog com um textbox e um botao ok, queria atualizar o form principal com o conteudo deste, mas ele não vai. Já tentei de tudo. Vi exemplos de como funcionaria se fizesse o form só em código, mas estou usando a interface do NetBeans e não está saindo. Se puder ter um exemplo simples de como funcionaria seria ótimo. Obrigado :)
Comment: Ah sim, adicione na pergunta como você chama a jdialog no jframe, e como você retorna a pesquisa pra ele de volta. Com essas informações(além das que já tem) já dá pra te ajudar.
Comment: Sem problemas! Chamo a Dialog assim:
private void tb_btn_pesquisarActionPerformed(java.awt.event.ActionEvent evt) {
        frmPesquisa pesq = new frmPesquisa(this,false);
        pesq.setVisible(true);

    }
Comment: e tento atualizar uma Label na tela do main assim tem 2 botões, 1 deveria deixar a label visivel e a outra invisivel:

    private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {
        FrmCadUsuarios frm = new FrmCadUsuarios();
        frm.tbVisivel(this, true);
    }
Comment: private void btn3ActionPerformed(java.awt.event.ActionEvent evt) {
        FrmCadUsuarios frm = new FrmCadUsuarios();
        frm.tbVisivel(this, false);
    }
Comment: O Construtor do form pesquisa (JDialog) está da seguinte maneira:     public frmPesquisa(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setLocation(1300,100);
    }
Answer:
Como não foi informado se a pesquisa deve ser apenas uma
  determinada coluna ou em todas da JTable, este exemplo pesquisa
  em todas as linhas e em qualquer coluna.

A classe RowSorter é a responsável por tratar filtros e ordenações, mas para componentes como tabelas, há uma implementação dela chamada TableRowSorter, feita para trabalhar com o TableModel, o que facilita bastante adicionar pesquisa em tabelas. Adicione na mesma classe onde você constrói sua JTable um atributo como o abaixo:
private TableRowSorter tableRowSorter;

Depois de construir sua tabela, atribua o model que passou pra ela ao tableRowSorter, para que ele filtre baseado no mesmo model da tabela:
 this.tableRowSorter = new TableRowSorter(seuModel);

Ou caso você esteja usando DefaultTableModel e métodos anônimos e não criou um model próprio(apesar de altamente recomendado que você crie seu próprio TableModel):
 this.tableRowSorter = new TableRowSorter(suaTable.getModel());

Uma vez atribuido ao RowSorter em cima de qual model ele irá trabalhar, agora atribua este RowSorter a sua tabela:
suajTable.setRowSorter(this.tableRowSorter);

Agora, recomendo que você mude a forma como chama o JDialog, o segundo parâmetro desta classe é um booleano que informa se a janela é modal ou não, se você quer um modal, precisa passar true, dessa forma, o Frame fica bloqueado enquanto o modal estiver aberto:
frmPesquisa pesq = new frmPesquisa(this, true);

No seu modal(caso ainda não tenha feito isso), adicione um atributo do tipo String para armazenar o que for digitado para a pesquisa e crie um método que retorne esta variável. Este método que será retornado mais adiante para o Frame principal.
private String textSearch = "";//vazio pra evitar problemas com nullPointerException

...

   public String getTextSearch() {
    return this.textSearch;
}

No listerner do JButton do modal, você vai capturar o que foi digitado no JTextField e atribuir a variavel textSearch criada anteriormente, assim, ao fechar o modal, basta chamar o método getTextSearch() no Frame para receber a pesquisa a ser feita na tabela:
this.textSearch = this.seuTextField.getText();
this.dispose();// isso fecha o modal ao clicar no botao,
               // logo após capturar o texto digitado e retorna para o Frame

Agora, no seu JFrame principal, basta chamar o método criado no modal e passar para o RowSorter como um filtro:
String busca = modal.getTextSearch().trim();
tableRowSorter.setRowFilter(RowFilter.regexFilter("(?i)" + busca));

A expressão (?i) é um Pattern da linguagem que indica que a pesquisa será  case insensitive, ou seja, buscará pelo filtro, independente de encontrar maiúsculo ou minúsculo. Pode ser removido caso você não deseje este comportamento.

O trim() remove espaços em branco em volta da string retornada na pesquisa, e o setRowFilter aplica o filtro em forma de regex e exibe as linhas que conterem em seu conteúdo a pesquisa digitada.

Se o texto da pesquisa for encontrado mesmo que seja como forma parcial do conteúdo da linha(ex.: pesquisa 'eng', e na linha tem engasgado, ou engavetado), esta será retornada da mesma forma.

Veja um print de demonstração que fiz, para mostrar como funcionaria a pesquisa:

Nos links abaixo é possivel encontrar mais detalhes a respeito de filtros e ordenações em JTable, além de exemplos completos e funcionais.
how to search an element in a JTable java?
JTable Row filtering by JTextField value
How to Make Dialogs - Oracle Documentation
Ordenando e Filtrando Tabelas com o Java SE 6.0(DevMedia)
Implementando seu próprio TableModel(DevMedia)
Table Sorting and Filtering
How to Use Tables - Sorting and Filtering(Oracle)
Comment: @kirito a resposta lhe ajudou a resolver o problema? Seria interessante marca-la como escolhida, clicando no `v` ao lado, para que sirva de referencia para outros com problema semelhante.


Prove $aba^{-1}b^{-1}\in{N}$ for all $a,b$

Question: I am trying to prove the above with the conditions that N is normal to G and $G/N$ is abelian.
So then for $Na,Nb\in{G/N}, NaNb=NbNa$.  But $NaNb=Nab=Nba$, so then we know $ab=ba$, so G is abelian.
So if $ab\in{G}, N=abN(ab)^{-1}=abN(ba)^{-1}=baNa^{-1}b^{-1}....$ and i'm getting lost...
Answer: Since $G/N$ is abelian, for all $a,b\in G$ we have $NaNb=NbNa$, so $Nab=Nba$. It does not follow that $ab=ba$, but rather that $Naba^{-1}b^{-1}=N$, i.e. that $aba^{-1}b^{-1}\in N$.
Comment: Wait, so this just hit me...in G/N, N is the identity?  So then $N=Nab(Nab)^{-1}=NabNb^{-1}a^{-1}=NabNa^{-1}b^{-1}=Naba^{-1}b^{-1}$?  and what is $aba^{-1}b^{-1}$?
Comment: An *element* of $N$...
Comment: Oh, i see....any element of n implies that Na=N if a is in n?  Was my math right in the previous comment?
Comment: Yes, it was correct


C++ program terminate when entering more than 11 integer

Question: I have a program written in C++ that ask a user to enter his/her 11 digit
 mobile number. But when I enter the 11 digits, the program continue without
 executing the succeding code.
 string FriendName, FriendAdd,  EmailAdd;
 long MobileNumber, counter, counter1, counter2;
 //Create a new structure
 struct personData {
   string namePerson, addressPerson, emailAddress;
   long age;
   struct personData *next;
 };

//Initialize pointers to personData structure
typedef struct personData node;

node *firstRec, *currentRec, *tempRec, *tempRec2;

void InsertRec() {
  cin.ignore(200,'\n');

  cout<<"Enter your Friend's Name            : ";
  cin.ignore(1,'\n');
  getline(cin,FriendName);
  cout<<"Enter your Friend's Mobile Number   : ";
  cin>>MobileNumber;
  cout<<"Enter your Friend's Address         : ";
  cin.ignore(1,'\n');
  getline(cin,FriendAdd);
  cout<<"Enter your Friend's Email Add       : ";
  getline(cin,EmailAdd);
  cout<<endl<<endl;

  tempRec = new(personData);
  tempRec->namePerson = FriendName;
  tempRec->addressPerson = FriendAdd;
  tempRec->emailAddress = EmailAdd;
  tempRec->age = MobileNumber;
  tempRec->next=firstRec;
  //firstRec->next=tempRec;

  firstRec=tempRec;
}

Comment: Thanks for letting us know.  Was there a question?
Comment: I guess because you forget the cin.ignore you used so widely. I would recommend using cin.getline() instead for user inpput - and please: store the number not into a long variable but String instead
Comment: Phone numbers should be strings.
Answer: The size of integral types depends on target platform and compiler settings. Assuming that long is a 32-bit integer, it only supports 10 digits.
The maximum values for 32-bit integral types are:
signed: -2147483647 to 2147483647
unsigned: 0 to 4294967295
A better approach would be to store the mobile number as a string, not a number.
Comment: This is only true for a *32 bit* `long`.
Comment: @JustMaximumPower: And it's often 64-bit on x64. But that's irrelevant to the question - phone numbers are strings of (usually) digits, not integers.
Comment: @PaulR actually the fact that it doesn't work with 11 digit numbers tells me that long is 32 bit. However this entire discussion is pointless, like Mike already pointed out.
Comment: @PaulR long is (usually) 32bit on x86
Comment: @MikeSeymour my point was that I agree with you, and Mark was justified in assuming a 32 bit long.
Comment: @JustMaximumPower: nowhere in the OP's question or tags does it mention x86 or anything platform-specific which might allow you to infer a 32 bit architecture.
Answer: A phone number is not an integer, it is a string of numbers.
The maximum number a signed integer (for 32-bit integer, which is used depends on your platform and compiler)   can contain is +2,147,483,647. Which is 10 digits.
Comment: This is only true for a *32 bit* integer.
Answer: It is the problem of datatype you have chosen to take mobile number. After entering mobile number, print it again and see whether it shows same value or not.
Your 11 digit value exceeds long limit.


Azure Pipelines CI not triggering when pushing tags from Bitbucket

Question: I'm trying to do a proof of concept to redesign my CI/CD pipelines in Azure Pipelines (formerly known as VSTS). My codebase is in BitBucket.
I need a continuous integration build to be triggered when I push git tags to the remote repo.
The proof of concept works really well when I use Azure Repos (VSTS), it detects a change in the "branch" "refs/tags/current" and triggers the build.

But once I switch to BitBucket, it just doesn't work, no build is triggered.
So my question is:
How can I trigger a CI build in Azure Pipelines (VSTS) when pushing tags to my BitBucket repo?
Thanks!
Answer: No, we cannot achieve that for the service connection endpoints (BitBucket here) , CI only works when you push commits with new changes (The real file/code changes).
But push git tags only added tags to a commit, no any other new file changes be pushed to the remote repo.
So, if you want to trigger the CI build by pushing tags only, then it will not work...
I can think of is that you can add a insignificant file in source control (a *.txt file for example). Then edit/modify the file every time when you push tags. After finishing push tags, you need to push the new changes for the *.txt file, but it will generate a new commit...not the commit you added tags for it...
Comment: Hi Andy, thanks for the answer. Do you mean it doesn't work with Bitbucket only? Because with Azure Repos works like a charm. Another option would be adding a commit WITH a tag, and then push the commit along with the tag, but I need a way to detect the tag in the pipeline. Is there a way to do that?
Comment: @GustavoVargas Yes, I mean the service connection endpoints (`BitBucket` here), as far as I know no any way to achieve that.
Comment: Ok thanks Andy. Then I will think in another way to orchestrate the pipelines.
Comment: @GustavoVargas You can migrate from BitBucket to VSTS internal Git, or try syncing between BitBucket and VSTS internal Git. This blog for your reference : https://blogs.microsoft.co.il/leonj/2017/01/24/synchronizing-tfs-2015-and-vsts-with-github/#GITHUB_TFS
Answer: I got it to work by doing the following steps (This is using Github, though).
Go to the triggers for your pipeline in Azure DevOps:

Enter two branch specifications:
- refs/tags/*
- releases/*

PS: These needs to match whereever your repo hosting provider archives releases and tags.
Click Save (not Save & Queue)

Create a new tag on Github

Click the "Draft new release"

Enter the details for your release.
Pipeline picked up the new tag, and builds it
Comment: Hi Coreus, thank you for sharing this. Not sure if you tested on BitBucket. I tried the same setup with BitBucket, but VSTS is not triggered.


Walk/Car mode detection through skobbler API

Question: I want to implement a functionality in my iOS app that detects if the user is Walking or driving. Is there a way i can detect the modes in Skobbler. I am using the Skobbler 2.1. Please suggest something. Thanks :)
Answer: If you are navigating on a route then the used routing profile might be a good indicator of travel mode.
If you are in "free drive" mode then the only metric you get is the current speed - above a certain threshold you may assume that the user is driving (or biking?). Other than these 2 things I don't know what else you could do.


Add property to ProductVariationType via hook_entity_type_build()

Question: Hy guys,
I'm trying to implement a simple stock management in my e-commerce. The ProductVariation will have a stock_quantity field used to track product availability.
I would like that stock_quantity field is shown only if user checks an enable_stock_management checkbox on ProductVariation bundle edit page. I.e. /admin/commerce/config/product-variation-types/default/edit
In other words I would like to mimic Submission form settings, Menu settings, Display settings functionalities of Node's bundles.
By Google-ing a bit I think that hook_entity_type_build() is the hook to use. But, once I'm in the hook what I'm supposed to do in order to add the property I need and display it in the edit form?
 /**
  * Implements hook_entity_type_build().
  */
 function commerce_warehouse_entity_type_build(array &$entity_types) {
     /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
     $entity_types['commerce_product_variation_type']-> # ... And now?;
 }

Answer: Ends up that hook_entity_type_build() is not the right way to implement what I want. I found a solution usign ThirdPartySettingsInterface, which every ConfigEntityBase implements.
First I've altered ProductVariationType form via hook_form_alter() in order to add a checkbox to the form and register a new #enity_builder.
/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function MY_MODULE_form_BASE_FORM_ID_alter(&$form, FormStateInterface $form_state, $form_id) {
  /** @var ProductVariationTypeInterface $entity */
  $entity = $form_state->getFormObject()->getEntity();

  $form['warehouse_management'] = [
    '#type' => 'checkbox',
    '#title' => t('Enable warehouse management'),
    '#default_value' => $entity->getThirdPartySetting('commerce_warehouse', 'warehouse_management'),
  ];

  $form['#entity_builders'][] = 'MY_MODULE_entity_ENTITY_ID_builder';
}

Then I've defined my custom entity builder function where I register my third party setting. Pretty simple! This article helps me out a lot.
/**
 * Entity builder for commerce_product_variation_type entity.
 */
function MY_MODULE_entity_ENTITY_ID_builder($entity_type, ProductVariationTypeInterface $entity, &$form, FormStateInterface $form_state) {
  $entity->setThirdPartySetting('commerce_warehouse', 'warehouse_management', $form_state->getValue('warehouse_management'));
}


Webform, creating customized directories for uploaded files

Question: Newbie and my first question on here. I'm still learning Drupal. So apologies if I missed anything
Here is my issue
I am using Webform to create an upload page. The user enters an ID(text field) and uploads the file. The file gets uploaded to a private section on the server. Now I am trying to make sure that the file gets uploaded into this separate folder(named after the ID)( say all/private/ID/). Can I do that using a Webform ? For now, all I can use are basic tokens,not values I can grab from other fields(ex: %username) to create these directories.
If webforms are not the answer, what else would be a good method to go about it ?
Answer: Greetings welcome to the land of Drupal stuff :)
In general here are some tips:

creating a folder off of a textfield ID is going to be cumbersome. How will you know subsequent users aren't putting in the same ID and or overwriting eachothers files?
Webform has an API of available hooks. For instance look at webform_submission_presave() which allows you to change/capture a users submitted answer and alter it; you could likely alter the destination of the file to be saved, and assure the destination directory exists with a Drupal API function file_prepare_directory.

If you're looking for an all-in-one no code solution. Look at this issue queue PATCH for webform that looks like it supports custom tokens for upload files.
Comment: Thank your the suggestions.(Appreciate the warm welcome too). I will take a look into them.

I've already looked at the patch you linked to. From what I understand, the custom token support is ust limited to pre-existing basic tokens. The patch creates a directory as soon as you define it, so the tokens will already have to be predefined and existing before you can use it(So %useremail works but %post[key] does not work, it only creates a directory of the same name).


PDCurses wont compile on windows

Question: I am trying to compile PDCurses, but when it attempts to compile pdcscrn.c  it gives the error message
<code>../wincon/pdcscrn.c:93:5: error: unknown type name 'PCONSOLE_SCREEN_BUFFER_INFOEX'; did you mean 'PCONSOLE_SCREEN_BUFFER_INFO'?
     PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     PCONSOLE_SCREEN_BUFFER_INFO
../wincon/pdcscrn.c:95:5: error: unknown type name 'PCONSOLE_SCREEN_BUFFER_INFOEX'; did you mean 'PCONSOLE_SCREEN_BUFFER_INFO'?
     PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     PCONSOLE_SCREEN_BUFFER_INFO
../wincon/pdcscrn.c:97:8: error: unknown type name 'SetConsoleScreenBufferInfoExFn'
 static SetConsoleScreenBufferInfoExFn pSetConsoleScreenBufferInfoEx = NULL;
</code>
and there are also a lot more lines, but that is the first part. I am using GCC 8.2.0, and I compiling the wincon directory because I am on windows 10. Thanks.
Answer: This is addressed in wincon/README.md:

If your build stops with errors about PCONSOLE_SCREEN_BUFFER_INFOEX,
add the parameter "INFOEX=N" to your make command line and try again.
(This will happen with older compile environments.)

BTW, you should specify the exact toolset you're using, since AFAIK there's no such thing as raw GCC for Windows -- it'll be something like MinGW or Cygwin.

PDCurses wont compile on windows


XPath for multiple predicates

Question: I have a XML for eg.

    <c/>
    <c/>
    <c/>

I would like to fetch only 1st and 3rd child of  tag:
To fetch a single child i'm using
XPATH as.//a/b/c[1]
Can i fetch both [1] and [3] nodes with a single path without iterating over the parent node?
Answer: You could use this
.//a/b/c[position() = 1 or position() = 3]

XPath for multiple predicates


openlayers updating a layer based upon viewable area

Question: For a project we are wishing to use use openlayers. I know how to plot points and have a popup bubble. However since there is going to be quite a lot of points plotted on the map for the UK. What i am wanting to do is send the central point of the viewable area and in the backend send a layer update of all the points in the current viewable area. In openlayers is there anyway of doing this?
Answer: Yes. You can either use a WMS server to serve maps as images, or use the BBOX Strategy to only get the content within the viewport.


Is it possible to "join" a DownloadStringAsync operation?

Question: I have this code:
public static String Download(string address) {
    WebClient client = new WebClient();
    Uri uri = new Uri(address);

    // Specify a progress notification handler.
    client.DownloadProgressChanged += (_sender, _e) => {
        //
    };

    // ToDo: DownloadStringCompleted event

    client.DownloadStringAsync(uri);
}

Instead of having the rest of my code execute in the DownloadStringCompleted event handler when the download is complete, can I somehow Join this Async request? It will be housed in another thread (doing it this way so I have access to the download progress). I know that DownloadStringAsync can take a second parameter; an object called userToken in the manual. Could this be of use? Thank you,
Answer: You could use a manual reset event:
class Program
{
    static ManualResetEvent _manualReset = new ManualResetEvent(false);

    static void Main()
    {
        WebClient client = new WebClient();
        Uri uri = new Uri("http://www.google.com");

        client.DownloadProgressChanged += (_sender, _e) =>
        {
            //
        };

        client.DownloadStringCompleted += (_sender, _e) =>
        {
            if (_e.Error == null)
            {
                // do something with the results
                Console.WriteLine(_e.Result);
            }
            // signal the event
            _manualReset.Set();
        };

        // start the asynchronous operation
        client.DownloadStringAsync(uri);

        // block the main thread until the event is signaled
        // or until 30 seconds have passed and then unblock
        if (!_manualReset.WaitOne(TimeSpan.FromSeconds(30)))
        {
            // timed out ...
        }
    }
}

Comment: Your revision is even more perfect because I wanted the request to time out after a certain amount of time. Thanks again!!
Answer: My first thought would be to use DownloadString, the synchronous version of DownloadStringAsync.  However, it seems that you must use an async method to get the progress notification.  Okay, that's no big deal.  Just subscribe to DownloadStringCompleted and use a simple wait handle like ManualResetEventSlim to block until it completes.
One note, I am not sure if the progress notification is even raised for DownloadStringAsync.  According to MSDN, DownloadProgressChanged is associated with some of the async methods, but not DownloadStringAsync.
Comment: "...doing it this way so I have access to the download progress..."
Comment: @SimpleCoder: yeah, I realized my naive answer was wrong after I posted... fixed now, I hope!
Comment: No problem, thanks for the answer! I just tried out Darin Dimitrov's code and the event is indeed raised.


How to join arbitrary parts of url in Python?

Question: urljoin corrupts the data
from urllib.parse import urljoin
base = "https://dummy.restapiexample.com/api/v1"
tail = "/employees"
urljoin(base, tail)

returns
'https://dummy.restapiexample.com/employees'

eating "/api/v1".
Comment: That's not corrupted, that's correct according to the documentation.
Comment: @PeterWood np, so, whats the function that works normally?
Comment: `tail = "employees"`
Comment: Perhaps `str.join`?
Comment: @mkrieger1 This won't drop leading/trailing slashes as needed.
Comment: @PeterWood this fixes data, not function
Answer: base and tail are strings. ''.join([base, tail]) is one such way to join these strings:
>>> base = "https://dummy.restapiexample.com/api/v1"
>>> tail = "/employees"
>>> ''.join([base, tail])
'https://dummy.restapiexample.com/api/v1/employees'

Strings have a join method, which takes in a list of strings and returns a concatenated string from said list, with copies of the calling string separating the substrings which are copies of the strings in the list -- so, for example, '/'.join(['a','s','d','f']) returns 'a/s/d/f'. If '' calls this method, it simply returns the list concatenated into one string.


Facts about Ideals in Non-Commutative Rings

Question: Let $R$ be a unital, but not necessarily commutative ring.
Define its Jacobson radical $J$ to be the intersection of all maximal left ideals of $R$. Three questions:

Let $R$ have unique two-sided maximal ideal $I$. Must $I=J$?
Define $J'$ to be the intersection of all maximal two-sided ideals of $R$. Is $J' = J$?

3(a). Is every maximal left ideal a maximal ideal?
3(b). Is every maximal ideal a maximal left ideal?
My thoughts:

My lecturer seemed to assert this, but I don't see why this should be the case.
My guess is no. It does not even seem that we have an inclusion either way. Are there matrix rings that show $J \not\subset J'$ and $J' \not\subset J$?
I think no to both. (If the answers were yes, then item 2 would become trivial.)

3(a). No. A counterexample is: let $R$ be a matrix ring over a division ring $D$. Then $R$ is a simple ring; however it has a nonzero maximal left ideal.
3(b). I guess no, because even though a maximal two-sided ideal $K$ is a left ideal, and maximal among two-sided ideals, I don't see a reason why it should be maximal among left ideals. UPDATE: Actually, I'd like to correct my guess to 'yes'. Using Zorn's Lemma, a maximal left ideal $K'$ containing $K$ is contained in a maximal ideal $L$. Then $K=L$ (since $K$ is a maximal two-sided ideal and $L$ is proper two-sided-sided), which forces $K=K'$. Is this argument correct?
Definitions: https://en.wikipedia.org/wiki/Maximal_ideal
Answer:
No. Take $V$ to be a countable dimensional $F$-vector space, and consider the ring $End(V_F)$.
No. Same example as the previous point. There is only one maximal two-sided ideal in the intersection.
3a) As you said "no": square matrix rings over fields have only one maximal ideal (the zero ideal) but lots of nonzero maximal left ideals.
3b) No. A square matrix ring over a field is still a counterexample to that assertion. The zero ideal is a maximal two-sided ideal, and it is contained in many nonzero maximal left ideals.

Using Zorn's Lemma, a maximal left ideal $K'$ containing $K$ is contained in a maximal ideal $L$. Then $K=L$ (since $K$ is a maximal two-sided ideal and $L$ is proper two-sided-sided), which forces $K=K'$. Is this argument correct?

The first sentence is non sequitur. There is no reason for a maximal left ideal to be contained in any proper two-sided ideal of a ring. The square matrix ring over a field demonstrates this.


Echo 404 directly from nginx to improve performance

Question: I am in charge of production servers serving static content for a website. Those servers are constantly being crawled by bots looking for potential exploits (which isn't that much of a problem security-wise because no application can be reached behind the web server) but
generates thousands of 404 per day, sometimes per hour. I am looking into ways of blocking those requests but it's tricky (you want to make sure you don't block legitimate traffic and these bots are becoming more and more clever at looking like they're legit) and is going to take me a while to find an acceptable solution.
In the meantime I would like to reduce the performance impact of serving those 404 pages. Indeed we're using nginx which by default is configured to serve it's 404 page from the disk (This can be changed using the error_page directive but in the end the 404 will either have to be served from disk or from another external source (e.g. upstream application which would be worst)) which isn't ideal.
I ran a test with ab on my local machine with a basic configuration: in one case I echo a message directly from nginx so the disk isn't touched at all, in the other case I hit a missing page and nginx serves its 404 from disk.
server {
  # [...] the default nginx stuff
  location / {

  }
  location /this_page_exists {
     echo "this page was found";
  }
}

Here are the test results (my laptop has Intel(R) Core(TM) i7-2670QM + SSD in case you're wondering why they are so high):
$ ab -n 500000 -c 1000 http://localhost/this_page_exists
Requests per second:    25609.16 [#/sec] (mean)

$ ab -n 500000 -c 1000 http://localhost/this_page_doesnt_exists
Requests per second:    22905.72 [#/sec] (mean)

As you can see, returning a value with echo is 11% ((25609−22905)÷22905×100) faster than serving the 404 page from disk. Accordingly I would like to echo a simple 404 Page not Found string from nginx.
I tried many things so far but they all failed, essentially the idea was this:
location / {
  try_files $uri @not_found;
}
location @not_found {
  echo "404 - Page not found";
}

The problem is that as soon as the echo directive is used, the http response code is set to 200. I tried changing that by doing error_page 200 = 400 but that breaks the configuration.
How can I serve a 404 page directly from nginx? (without hacking the source which may be might next step)
Comment: Because they're bad tags and no one should use them. All three are ambiguous and add nothing to the categorization of the question.
Comment: Have you considered using fail2ban to catch and then block these at the firewall ?
Comment: It's one of the options I'm looking into but I'm really clueless about it, therefore installing/testing properly + releasing into production is going to take a while. As I said before echoing a `404` would be a `In the meantime` solution (which could turn out to be worthy of the effort in my opinion).
Comment: @MDMarra: my question is about serving `404` from `nginx` directly instead of the `disk` so as to improve `performance`, and you removed the `404`, `disk`, and `performance` tags I had set, why?
Answer: Actually, by default, nginx generates a 404 response internally.  It only serves a file from disk if you tell it to using an error_page directive.  If you want to control the format of the 404 page, instead of echo "404 - page not found";, you can use return 404 "404 - page not found"; (assuming you're using a somewhat recent version of nginx, I belive you need 0.9 or newer)
Comment: I've tested and it works. I was able to achieve `25329 req/sec` with that `404` method so there is definitely a performance improvement compared with the default 404.
Answer: Nginx echo module is what you need. But you should use it with error_page:
error_page 404 @echo_404;
location @echo_404 { echo "Not found"; }

You can make nginx close active connection by returning 444:
return 444;

This will close socket immediately without writing anything to the net.
The difference in your calculations is just a result of open_file_cache been not enabled. If you want it go faster tweak your system: accept filters, socket queue and buffers and so.
Comment: About the `echo`: I already tried it but as soon as I use `echo` the response code changes to `200`. About the `444`: that's even better performance wise (`28216 req/sec`), but I think returning a 404 is still important in that case as some genuine clients might try to access non-existing resources (broken links) in which case a 404 might be nicer than terminating the connection without returning any data


Following a CGPath with SKAction without starting from beginning of CGPath

Question: I have an SKShape node that represents an ellipse.  A player is placed on the current point of a Bezier Path that is based on the ellipse's CGPath:

I have two actions that the player node can perform.  The player can either follow the path clockwise or counterclockwise.
rotateCounterClockwiseAction = SKAction.followPath(counterClockwisePath.CGPath, asOffset: false, orientToPath: true, duration: 1)
rotateClockwiseAction = SKAction.followPath(clockwisePath.CGPath, asOffset: false, orientToPath: true, duration: 1)

When I start one of the actions as:
player.runAction(SKAction.repeatActionForever(rotateClockwiseAction), withKey: "ClockwiseRotation")

The player moves along the appropriate path and direction.  When I stop one of the actions:
player.removeActionForKey("ClockwiseRotation")

The player stops on the path where it was last moved to.  I want to be able to start either of the actions from the player's current point, and follow the same path, but right now, if I start either one of the actions again (after an action has already been started and stopped) the player jumps to the same starting point as seen in the picture and follows the path from there.  How can I get the player to follow the path from the point that it is already at?
Comment: you would have to create a new cgpath, same shape but starting with the point the player is at
Comment: I created my path with `let ellipse = SKShapeNode (ellipseOfSize: CGSizeMake(size.0, size.1))`, ie. not much experience in this area. Do you have some resource that might help me achieve this specifically?
Answer: You can achieve this easily by using the speed property of SKNode.
Instead of removing and recreating the action, you can pause and resume it by adjusting the speed value. This will cause your bezier path animation to resume from its current position.
// Set the player node's speed to 0.0 causing all actions to be paused.
[playerNode setSpeed:0.0];

...

// Then when you're ready to resume set the player node's speed back to 1.0.
// This will cause the action to continue from its current position.
[playerNode setSpeed:1.0];

Comment: I've got it working that way with redrawing the path based on the current position of the player on a circle, what I'm struggling with is redrawing when the path is an ellipse
Comment: This doesn't work because the player node has two actions attached to him. He can either rotate left or rotate right. If he rotates left and I pause, I can resume rotating left, but if I start rotating right he will begin at the start of the path or where the last rotate right path was paused.
Comment: I understand. It's a shame you can't reverse path following actions simply with a -1 speed. That way you would only need one action. I think I would be inclined to code the orbit without actions using sin/cos and keeping track of the current orbit position.


c# Xna turned off FixedTimeStep but still update calls max. 60 times

Question: Hi guys i just made a small Algorithm to display the fps to my screen.
        frames_temp++;
        frames_Time += (int)gameTime.ElapsedGameTime.TotalMilliseconds;
        if (frames_Time >= 1000)
        {
            frames = frames_temp;
            frames_temp = 0; frames_Time = 0;
        }

this code snipped is located in the Update-method. The frame variable stores the actual value drawn to the screen(just posting that code, to make sure there is no fault, eventhough i checked it already).
Now the problem is that i can't turn off the IsFixedTimeStep. I set it to false inside the constructor, initialize and even the update-method but still the programm limits my fps to ~60. I either put in a for() query into my update-method running many million loops without frame-drops to make sure its not my cpu beeing too slow .Another thing i already tried is to use my own timeSpan and the systemtime to get the elapsed time between the calls of Update(), wich gives me kinda the same output. Now it is 99% sure that update only runs 60 times a second.
So why can't i call the Update-Method as often as possible as it should be when IsFixedTimeStep is false
Ty for replies
Comment: its not your computer. the limit of 60 fps is to follow your monitor refresh rate. look at vertical syncing like ISun said.
Answer: I believe that you problem is Vertical Syncing, this function of the graphics device is locking the frame rate to your monitor refresh rate. To solve this problem you need to turn off VSync (SynchronizeWithVerticalRetrace) in the GraphicsDeviceManager:
graphicsDeviceManager.SynchronizeWithVerticalRetrace = false;
graphicsDeviceManager.ApplyChanges();

graphicsDeviceManager is your game's GraphicsDeviceManager
Answer: If I recall correct fixed timestep = false results in the update being called before the draw method, not calling it as often as possible. Therefore you should check wheter Vsync or something else is limiting your application to 60fps.


where to find a proof of the Lebesgue Density Theorem

Question: The other day I was browsing the site and found the question. I was trying to follow up with Topologieeeee, but clearly [s]he has not shown up for quite a while. So I wonder if anybody knows where to find the proof of the FACT referred in [s]he's question?
Thanks.
Edit
The FACT, from the old post, is the following:
Let $E$ be a Lebesgue measurable subset of $\mathbb{R}^n$. Almost every $x\in E$ satisfies $\lim\limits_{m(B)\to 0,~x\in B}\frac{m(B\cap E)}{m(B)}=1$ i.e. limit is taken over the ball $B$ containing $x$ with shrinking it.
Comment: Could you please add "*the FACT*" to your question to make it self-contained? This is called the [Lebesgue density theorem](http://en.wikipedia.org/wiki/Lebesgue's_density_theorem) and can be found e.g. in Rudin's *Real and Complex Analysis*. If you can access it, you can also have look at [this recent proof](http://www.jstor.org/stable/2695333) by C.-A. Faure.
Comment: This is exercise 25 on page 100 of Folland, Real Analysis, chapter "Differentiation on Euclidean Space".
Answer: This is called the Lebesgue Density Theorem.  With that knowledge in hand it should be easy to search for and find a proof.  I have made a nice proof, due to C.-A. Faure, from a recent Monthly article available here.
Comment: I'm very glad to see you're back! This is great.


topological sort of partial order into sorted sets

Question: Given a partial order of elements, one can use topological sorting to produce a sorted list of elements. For example, if we have the partial order A->B and A->C, then the possible topological sort results are [A,B,C] and [A,C,B].
I am interested in producing a sorted list of sets [$S_1, \ldots, S_k$] that satisfy the partial order (The sets $S_i$ partition the elements). Here, the requirements are:

for $i = 1 \ldots k-1$, $\exists e_1 \in S_i,e_2 \in S_{i+1}$ s.t. $e_1 < e_2$
for each set $S_i$, $\nexists e_1, e_2 \in S_i$ such that $e_1 < e_2$ or $e_2 < e_1$

In our example, the only correct sorted list of sets is [{A},{B,C}]. Given a partial order, how many possible sorted lists of sets exist? Is there a name for this kind of sorting? Any pointers are appreciated.
Comment: If condition (1) is strengthened to $e_1 < e_2$ for *all* $e_1 \in S_i,\, e_2 \in S_{i+1}$ then there is no correct answer for $\{a,b,c\}$ partially ordered by $a<b$. That's why Steven relaxed it to its current state.
Answer: First, we can deduce from 1. and 2. the condition
3$ $. for $i\le j$, $\nexists e_1\in S_i, e_2\in S_j$ such that $e_2<e_1$.
(If there were such elements, we could use a chain of elements provided by 1. to find elements contradicting 2. by transitivity.)
It follows that the list must be exactly as long as the longest chain(s). If it were any shorter, there would have to be elements in each longest chain contradicting 3. If it were any longer, 1. would imply the existence of a longer chain.
This suggests an algorithm for forming all possible sorted lists of sets. For each element $e$, let $l_e$ be the length of the longest chains in which $e$ occurs, and let $m_e$ be the index at which it occurs in these chains, i.e. $m_e=1$ if $e$ is the least element in these chains and $m_e=l_e$ if it is the greatest. The index $m_e$ is well-defined, since any two chains with different $m_e$ would yield a chain of length greater than $l_e$.
Now order the elements using the lexicographical order according to $(l_e,m_e)$, i.e. $d<e \Leftrightarrow l_d < l_e \lor (l_d = l_e \land m_d < m_e)$, and start with the greatest elements. The beginning is easy: $k$ has to be the greatest value of $l_e$, and there is only one possible placement for elements with that value of $l_e$ -- they have to go in $S_{m_e}$.
Then things get slightly more complicated. Each chain of length $l$ considered by itself can be placed in $\left(k\atop l\right)$ different ways, but there may be links between the chains that constrain their relative placement. To recursively generate all possible lists, you can go through the elements in the above order and place each element $e$ in all sets that are still allowed. Originally, the allowed sets will be $S_i$ with $m_e \le i \le m_e+k-l_e$. This may be further constrained by the placement of the immediate successors of $e$ in chains of length $l_e$, since $e$ must be placed below each of them, but the lexicographical ordering guarantees that there are no further constraints beyond these, so they're easy to keep track of.
So this is relatively straightforward to implement as an algorithm, but since the cross-constraints between the chains can be arbitrarily complicated, I think you're unlikely to find a nice expression for the number of possible lists.


How to use conditional aggregation on columns which have multiple values in SQL

Question:
I need to generate an output to show different role(from table2) as separate columns for an id(from table 1), but the role is not mandatory to be present in the table 2 and sometimes there can be multiple roles also. I am stuck here.
I have tried coalesce, but with that I am not able to get the multiple values into different column
SELECT
i.id,
i.name,
COALESCE(MAX(CASE WHEN r.ID = i.id THEN r.Role END), 'NA') AS Role,
COALESCE(MAX(CASE WHEN r.Role = rl.Role THEN rl.value END), 'NA') AS value,
COALESCE(MAX(CASE WHEN r.Role = rl.Role   THEN rl.value_2 END), 'NA') AS value_2

FROM
    employee_id AS i
    LEFT JOIN employee_role r ON r.id = i.id
    LEFT JOIN Role rl ON r.role = rl.role
GROUP BY
    i.id,
    i.name
Please find the table structure below:
Table 1: Employee_id
ID  Name
100021  Bob
100023  Tom
100024  Jim
Table 2: Employee_Role
ID  Role
100023  user1
100024  Beta_user
100024  user
Table 3: Role
Role         value  value_2
Beta_user    zz         56
user         23         ss
user1        sd         45
Required_Result
ID      Name    Role      value  value_2
100021  Bob     NA    NA     NA
100023  Tom     user1     sd     45
100024  Jim     Beta_user zz     56
100024  Jim     user      23     ss
Answer: As far as I can tell, no aggregation is necessary:
SELECT e.id, e.name, er.role,
       COALESCE(rl.value, 'NA') AS value,
       COALESCE(rl.value_2, 'NA') AS value_2
FROM employee_id e LEFT JOIN
     employee_role er
     ON er.id = e.id LEFT JOIN
     Role r
     ON er.role = r.role;


Darwin Streaming Server and iPhone streaming

Question: Is it possible to configure iPhone streaming (HTTP Live Streaming) on Darwin Streaming Server?
Answer: Yes, but it's not specifically for iPhone, it's just a regular H.264 in an mp4 wrapper streamed over https, only the resolution is specific, if you want it to be, to iPhone.


Can I still use Linear Regression assumptions test on a linear model with a Polynomial variable

Question: I have a multivariate linear model (y=x1+x2) which gives me the following results when using R's plot() function:

I can clearly see that the Normality and Linearity assumptions are not the best. Thus, I decided to add a 2nd degree polynomial variable to the model using poly() (which should give me a model such as y=x1^2+x1+x2) and got the following results:

I clearly see an improvement in both assumptions, however, that made me think: can I even do these two tests after I included the polynomial variable? Is the model still considered linear?
Comment: Yes, the model is still linear (in its parameters and that's what is important here). Yes, you can use these plots.
Comment: A linear regression model is defined as $\mathbf{y} = X\boldsymbol\beta + \boldsymbol\varepsilon$ where $X$ is the design matrix (all your x-variables) and $\boldsymbol\beta$ is the parameter vector. In the design matrix, a column can be squared values of another column, it won't change this basic, linear model. (Note that `poly` by default creates orthogonal polynomials.)
Comment: I am not well versed in R's specifics w.r.t. `poly()`, but assuming it adds a term that is polynomial in the _data_, you should be fine. A linear model is linear in the _parameters_, not necessarily in the _data_.
Comment: poly() is used on the model itself, e.i: y~poly(x1,2)+x2. The data stays untouched.
Comment: The term "linear" here has two meanings. One is that the model is a straight line. The other is that linear algebra can directly be used to solve for the coefficients in a technique named "linear regression". One is the name of a mathematical model, one is the name of a mathematical technique.
Comment: So does it mean that I can't use the plots?
Comment: Cool! Can you please explain when it won't longer be considered linear then? Because right now I am confused.
Answer:
Is the model still considered linear

To answer your question, recall the definition of a linear model.
Given a dataset composed of a vector $\mathbf{x} = \{ x_1, x_2,...,x_n\}$ of $n$ explanatory variables and one dependent variable $y$ we assume in this model that the relationship between $\mathbf{x}$ and $y$ is linear
$$ y = \beta_0 1 + \beta_1 x_1 + \beta_2 x_2 + ... + \beta_n x_n + \epsilon$$
Where $\beta_0$ is an intercept term and $\epsilon$ is the error variable, an unobserved random variable that adds "noise" to the linear relationship.
As @Roland points out, the linear relationship must hold in the parameters, not necessarily in the data. So nothing stops you from taking functions of the explanatory variables, and then performing the linear regression again. For example in your case, you could let:
$$ z_1 = x_1, \ z_2 = x_2, \ z_3 = x_1^2, \ z_4 = x_2^2$$
And then perform linear regression on $z$ as:
$$ y = \beta_0 1 + \beta_1 z_1 + \beta_2 z_2 + \beta_3 z_3 + \beta_4 z_4 + \epsilon $$
which is equivalent to
$$ y = \beta_0 1 + \beta_1 x_1 + \beta_2 x_2 + \beta_3 x_1^2 + \beta_4 x_2^2 + \epsilon$$

I clearly see an improvement in both assumptions

If your data shows signs of an underlying polynomial relationship between the explanatory variables, then fitting a linear regression model on polynomial variables will improve your model. As always, this comes with many advantages and disadvantages, some discussed in the posts linked below.
An example
Here is a toy example of trying to fit a linear regression model on a noisy sine curve. As you may know, the sine curve can be approximated by a sum of polynomials, so intuitively we would expect a polynomial linear regression model to do well under certain conditions:

More details
See these excellent posts for more details and explanations

Why is polynomial regression considered a special case of multiple linear regression?
Does it make sense to add a quadratic term but not the linear term to a model?
Polynomial regression using scikit-learn