Apache performance issue, after "1000 total children" Apache no longer responds to HTTP requests. Not MaxClients issue?

Question: Hoping someone can point me in the right direction as I've spent the last week trying to figure out where the "issue" is but haven't been able to, tried posting to the Apache users mailing lists but wanted to bounce it off here as well.
Running Apache 2.2.3 mod_php on CentOS 5.8.
At the same time every day when traffic is heavy we are having an issue where Apache no longer responds to any HTTP requests.
It sounded like a standard MaxClients being reached issue, but that doesn't seem to be the case.
Also, logging into the machine during this time the load average is under 1, and there is still plenty of RAM available.
Reviewing /var/log/httpd/error_log I've noticed the following patterns:
[Mon Apr 30 07:00:34 2012] [info] server seems busy, (you may need to increaseStartServers, or Min/MaxSpareServers), spawning 32 children, there are 0 idle, and 905 total children
[Mon Apr 30 07:00:35 2012] [info] server seems busy, (you may need to increase StartServers, or Min/MaxSpareServers), spawning 32 children, there are 0 idle, and 937 total children
[Mon Apr 30 07:00:36 2012] [info] server seems busy, (you may need to increase StartServers, or Min/MaxSpareServers), spawning 32 children, there are 0 idle, and 969 total children
[Mon Apr 30 07:00:37 2012] [info] server seems busy, (you may need to increase StartServers, or Min/MaxSpareServers), spawning 32 children, there are 35 idle, and 1001 total children

[Mon Apr 30 07:00:42 2012] [debug] mpm_common.c(663): (70007)The timeout specified has expired: connect to listener on [::]:80

[Mon Apr 30 07:00:49 2012] [debug] mpm_common.c(663): (70007)The timeout specified has expired: connect to listener on [::]:80

[Mon Apr 30 07:00:56 2012] [debug] mpm_common.c(663): (70007)The timeout specified has expired: connect to listener on [::]:80

[Mon Apr 30 07:01:03 2012] [debug] mpm_common.c(663): (70007)The timeout specified has expired: connect to listener on [::]:80

A few times a day, right after 1000 total children Apache stops responding and has to be restarted in order to work again.
I've reviewed the error_log from a few weeks back and it's the same pattern, the server hits 1000 total children and then immediately spits out the
[debug] mpm_common.c(663): (70007)The timeout specified has expired: connect to listener on [::]:80 error message and stops responding.
Yet the load on the server is quite low...
Even if I try and request a simple index.html file it times out.
Here is the relevant section from the config:
Timeout 45
KeepAlive On
MaxKeepAliveRequests 10000
KeepAliveTimeout 3

<IfModule prefork.c>
StartServers      80
MinSpareServers   50
MaxSpareServers  120
ServerLimit     3500
MaxClients      3500
MaxRequestsPerChild  2000
</IfModule>

Anyone know why the magic number of children Apache is able to reach is 1000 before it stops processing more requests?
Or how to make sense of the (70007)The timeout specified has expired: connect to listener on [::]:80 message?
What "timeout specified" is it referring to?
I've double check Max Open Files, it previously was at 1024 but now its at 16384, still the same problem.
Comment: Just out of curiosity, how big is the average apache process and how much RAM does that machine have?
Answer: It is a long shot, but I have had problems like this one. I don't remember exactly what error message it was, but the reason for the problem has always been a buggy PHP program which created recursive requests (i.e. the program requests a URL which in turn re-requests the same URL etc). I have seen this for example in connection with ErrorDocument settings, where the document which should have handled the error was buggy or non-existing and which triggered an error.
You can easily verify if this could be the problem in your access.log: You should have plenty of requests from your server's IP address, all in a very short time. This works until you hit the MaxClients setting or until your system runs out of resources. The only fix is to fix the PHP program in question.
Answer: Timeout 45

I believe it is referring to this timeout. It could be that something is opening the connection, then not doing anything (i.e. the client isn't sending anything after opening the connection or maybe a script of yours isn't closing the connection after writing data to the client) and Apache waits for 45 seconds before giving up. It then closes the connection. You could lower this so Apache times out dud connection attempts quicker but the better solution would be to try and determine why this happens in the first place.
http://httpd.apache.org/docs/2.1/mod/core.html#timeout
Maybe also check out this page for general performance issues?
http://httpd.apache.org/docs/current/misc/perf-tuning.html
Comment: Thanks, but that doesn't explain why this happens every day as soon as the server hits 1000 total children.
I've never seen a (70007)The timeout specified has expired: connect to listener on [::]:80 error message in Apache before. Why would it timeout when trying to load even a simple index.html file?
Comment: I can only assume as it reaches 1000 connections it might be running out of resources so is unable to spawn connections/process your PHP/Java/whatever quick enough. Some of these connections then start timing out (giving you those messages in the log). I can only hypothesise as I don't know what machine/OS is nor any performance stats.
Answer: Check if Apache's KeepAlive is on and what the value of KeepAliveTimeout is. It really should not be more than 3 seconds. It will keep the specific process/thread assigned to the client for that time.
Then grep httpd's conf dir for 1000 to see if that number is set somewhere.
grep -r '1000' /etc/httpd/conf
grep -r '1000' /etc/httpd/conf.d

Aside from that, it could be a case where your php code is (wrongly) keeping each process/thread that's handling it alive indefinitely and you're running out of them.


Transformar em função

Question: Tenho este código que traz os dados do usuário no meu banco de dados:
$resultado = mysqli_query($conexao, "select * from usuarios where id= {$id}");
$dado = mysqli_fetch_assoc($resultado);

echo $dado['nome'];
echo $dado['sobrenome'];

Como faço para transformar este trecho em uma função?
Answer: Então, consegui aqui.. Fiz da seguinte maneira:
//Função
function dadosUsuario($id, $conexao) {
    $resultado = mysqli_query($conexao, "select * from usuarios where id= {$id}");

    return mysqli_fetch_assoc($resultado);
}

e para chamar a função usei:
$dado = dadosUsuario($id, $conexao);

echo $dado['cidade'];
echo $dado['estado'];

Comment: Curiosamente a sua é a melhor resposta :) Só aprenda formatar melhor. Edite veja as opções de formatação existentes.
Comment: Obrigado @Mineiro
Answer: Somente transformando seu trecho de código em funçao:
function getUserById ($userId)
{
    $user = new User();
    $resultado = mysqli_query($conexao, "select * from usuarios where id= {$userId}");
    $dado = mysqli_fetch_assoc($resultado);

    echo $dado['nome'];
    echo $dado['sobrenome'];
}

Ou, se quiser a função com retorno, para reaproveitar o código:
function getUserById ($userId)
{
    $user = new User();
    $resultado = mysqli_query($conexao, "select * from usuarios where id= {$userId}");
    $dado = mysqli_fetch_assoc($resultado);

    return $dado;
}
//usar a informação retornada:
$user = getUserById("5001");
echo $user['id'];
echo $user['nome'];
echo $user['sobrenome'];

Comment: Obrigado pela sua resposta @DouglasOak, porém estou utilizando ainda php procedural. Estou criando um sistema para estudo mesmo deste paradigma e depois vou estudar orientação a objetos. Por enquanto estou separando as funções em um arquivo separado. Você teria um exemplo só de transformar essas linhas em uma função?
Comment: Sim, vou editar a resposta
Answer: Para criar uma função basta colocar tudo dentro de uma function:
function bsucarUsuarioId($id) {
$resultado = mysqli_query($conexao, "select * from usuarios where id= {$id}");
$dado = mysqli_fetch_assoc($resultado);

return echo $dado['nome'] + $dado['sobrenome'];
}

Transformar em função


convergence of function in $L^1$ metric

Question: I need to prove that
$$
  f_n(x) = \left\{
    \begin{array}{cc}
      (1-\frac{2}{n})-(n-2)x & \text{if}\; 0\le x \le \frac{1}{n} \\
      0 & \text{if} \;\frac{1}{n}\le x  \le 1
    \end{array}\right.$$
converges to
$$
  g(x) = \left\{
    \begin{array}{cc}
      1 & \text{if}\; x = 0 \\
      0 & \text{if} \;\text{otherwise}
    \end{array}\right.$$
where $L^1$ metric is defined to be
$$\int_0^1 \left|f(x) -g(x) \right| dx $$
I could show that $f_n \rightarrow g$ as $n\rightarrow \infty$ when $x\in (0,1]$. But the problem is when $x=0$.
Can I just say that as integration is continuous case, the integration at $x\in[0,1]$ is equivalent to when $x\in(0,1]$?
Alternatively, I have tried to show
$\left|f_n(0) - g(0) \right| <\varepsilon$. I think this is wrong because $\left|\cdot \right|$ is Euclidean matric, not $L^1$ matric.
Comment: Think you need an integration interval from 0 to 1. There's no pointwise convergence in your metric, so the value at a single point (like x=0) is irrelevant.
Answer: Just compute $\|f_n-g\|_{L^1}=\|f_n\|_{L^1}$. The graph of the function $f_n$ is a triangle with $f_n(0)=1-2/n$ and $f_n(1/n)=0$. Thus $$\|f_n\|_{L^1}=\frac{1}{2}\left(1-\frac{2}{n}\right)\frac{1}{n}\leq \frac{1}{2n}.$$
Therefore $\lim_{n\to\infty}\|f_n\|_{L^1}=0$ and the claim follows.
Comment: You don't need to plug in $x=0$ at all. The $L^1$ metric integrates out the $x$ dependence.
Comment: Yes, This is what I have done, so it is not necessary to show that $|f_n(0)-g(0)|_{L^1} = |2/n|_{L^1} =0 $ as $n \rightarrow \infty$.?

convergence of function in $L^1$ metric


Como armazenar a classe PxFixedJoint em um vector

Question: Eu estou tentando armazenar a classe PxFixedJoint em um std::vector com o método push_back. Mas o vetor fica sempre vazio, simplesmente não adiciona nada.
A baixo o código.
// C++
// Declaração do vector para armazenar os joints
std::vector<physx::PxFixedJoint*> m_lpJoints;

// Criando um joint
physx::PxFixedJoint* joint = physx::PxFixedJointCreate(*physics, m_pPhysicsBody, physx::PxTransform(-offset), _target, physx::PxTransform(offset));

// Armazenando
m_lpJoints.push_back(joint);

// Verificando o tamanho do vetor
std::cout << "size: " << m_lpJoints.size() << std::endl;

Comment: Conseguiu resolver o problema? Pois aparentemente não tem nada de errado com o código.
Answer: Resolvido
Eu simplesmente armazenei a classe PxJoint ao invés de PxFixedJoint. Como PxJoint é um classe abstrata, eu posso converter para PxFixedJoint quando eu quiser.


std::map on gcc 3.2.3 Red Hat Linux 3.2.3-20

Question: I am an ATE engineer in a semiconductor company and I need to develop as well as maintain test programs. Recently I would like to add a config file parsing function in the ATE platform. However, the standard test platform is not up-to-date (I am not sure whether this caused the problem).
I checked some resources and found several candidates: getpot(http://getpot.sourceforge.net/), inih(https://github.com/benhoyt/inih). With both, I could use directly compile and run on my windows 7 with gcc 4.8.1. However I would have to use it on my ATE Red Hat 3.2.3. I can not change the platform (like update the gcc version, install new packages), but I could include all necessary codes as raw files.
Here is what I have tried with inih:
1: I copied the codes to shared folder (between host windows and virtual redhat machine). On windows, I make it to compile and run correctly. However, on red hat it shows error as below . Here is the part which showed error:
string INIReader::Get(string section, string name, string default_value) const
{
    string key = MakeKey(section, name);
    return _values.count(key) ? _values.at(key) : default_value;
}

I just tried to modify it to implement std::map::at as below:
template<typename T1, typename T2, typename T3, typename T4>
T2 mapAt(std::map<T1, T2, T3, T4>& m, const T1& key)
{
    typeof(m.begin()) mit = m.find(key);
    if (mit == m.end() || mit->first != key)
    {
        throw std::out_of_range("map::at");
    }
    return mit->second;
}

string INIReader::Get(string section, string name, string default_value) const
{
    string key = MakeKey(section, name);
    return _values.count(key) ? mapAt(_values, key) : default_value;
}

and still it generates error as below:

2:when I add the sources in the job file, I have comfirmed that there is tab instead of 8 blank on the line, still it showed missing separator error.
Comment: According to the [GCC](https://gcc.gnu.org/releases.html) web site, GCC 3.2.3 was released on 2003-04-23.  That's getting to be antique (and has been for quite a few years).  If you can't upgrade the compiler, downgrade the source code so it will work with the old version of the standard.
Comment: Hi Jonathan, understand and this is what I am trying to do--downgrading. Just that I am no expert on C++, thus I came here for advice/help.
Comment: Please do not update questions with follow up questions. Your issue has been solved by one of the answers. Accept it and ask a new question with your follow up. Otherwise it is hard to follow what is going on.
Answer: The error is indicating that the function std::map::at does not exist in your environment.
This function is introduced in C++11, so your old GCC version does not support it.
Try to replace this function with alternatives, like std::map::find or similar.
Answer: You could implement std::map::at yourself, for exmaple:
#include <iostream>
#include <stdexcept>
#include <map>

template<typename T1, typename T2, typename T3, typename T4>
T2 mapAt(std::map<T1, T2, T3, T4>& m, const T1& key)
{
    typeof(m.begin()) mit = m.find(key);
    if (mit == m.end() || mit->first != key)
    {
        throw std::out_of_range("map::at");
    }
    return mit->second;
}

int main()
{
    std::map<int, int> mp;
    mp[2] = 3;
    std::cout<<mapAt(mp, 2)<<std::endl;
    std::cout<<mapAt(mp, 3)<<std::endl; // will raise an exception
    return 0;
}

Sorry I implemented the template incorrectly (this is incorrect for std::string and sorry I don't how to correct it). Here is a degraded version. It restricts type of map but should work on every C++ version.
std::string& mapAt(std::map<std::string, std::string>& m, const std::string& key)
{
    std::map<std::string, std::string>::iterator mit = m.find(key);
    if (mit == m.end() || mit->first != key)
    {
        throw std::out_of_range("map::at");
    }
    return mit->second;
}

Comment: HI, I have put the original part of code which showed up errors. So in order to add implement this std::map::at myself, I just need to copy your T2 part of code and modify the original at to mapAT? Or is there any other necessary work?
Comment: @Jinstrong, you need to `#include ` if you want to simulate how `std::map::at` deals with missing items, or you can just simply return the default value as your code does (under this circumstance `stdexcept` is not necessary). And you need to change `_values.at(key)` to `mapAt(_values, key)`. Remember to copy from `templateINIReader::_Values' to 'std::map<std::string------'. Seems the type is not always string.
Comment: What's your definition of _values?
Comment: from the header file, _values is a private value, as you can see the source code here.  https://github.com/benhoyt/inih/blob/master/cpp/INIReader.h
Comment: I described it in Chat.
Answer: Your implementation of mapAt accepts its first argument as non-const reference:
T2 mapAt(std::map<T1, T2, T3, T4>& m, const T1& key)

yet you try to call it from inside the const method INIReader::Get, where _values are treated as a constant map.
It is generally better to declare ref-arguments as consts provided you do not have a clear intention to modify them.
Comment: Thank you. I didn't find the mistake.
Answer: I tried suggestions here and still some issues remain. So I put forward an issue on the project's github repo and the writer gave a validated solution. It is to change _values.at(key) to _values.find(key)->second.
I just checked and confirmed that it works here. You can go to this site (https://github.com/benhoyt/inih/issues/49) for the detailed discussion.
Still, thanks for involvement and discussion here.


Define a differential 1-form $\omega:\mathbb R^2 \to \Lambda_1(\mathbb R^2)$ by $\omega(a,b)=adx+bdy.$ Compute: $\int_{\Phi|_{[0,1]}}\omega$

Question:
Let $\Phi : \mathbb R \to \mathbb R^2$ and $\Phi(t)=(t^3,t^4)$. Define a differential 1-form $\omega:\mathbb R^2 \to \Lambda_1(\mathbb R^2)$ by $\omega(a,b)=adx+bdy.$
Compute: $\int_{\Phi|_{[0,1]}}\omega$

My idea:
$ \frac{\partial\Phi}{\partial t}(a,b)=(3t^2,4t^3)$
$J_Φ(a, b)= \begin{pmatrix} 3t^2 \\ 4t^3 \end{pmatrix}$
$ω(Φ(a, b))(J_Φ(a, b))=adx\begin{pmatrix} 3t^2 \\ 4t^3 \end{pmatrix}+bdy\begin{pmatrix} 3t^2 \\ 4t^3 \end{pmatrix}=a3t^2+b4t^3$
Then $\int_{\Phi|_{[0,1]}}\omega=\int_{0}^{1}a3t^2+b4t^3$ ?
Is this correct so far? If not how do I proceed?
Comment: Yes it's correct, although you are missing a $dt$.
Answer: Your approach is correct (aside from the missing $dt$), but it's computationally more natural to make the symbolic substitutions
$$
\begin{aligned}
  x &= t^{3}, \\
  dx &= 3t^{2}\, dt;
\end{aligned}
\qquad
\begin{aligned}
  y &= t^{4}, \\
  dy &= 4t^{3}\, dt.
\end{aligned}
$$
Thus
$$
\int_{\Phi[0,1]} \omega = \int_{0}^{1} (3at^{2} + 4bt^{3})\, dt = a + b.
$$
Comment: Yes! The fact that differentials play well with algebraic manipulations is one of the main reasons I prefer to do all of my multivariable calculus in terms of differentials rather than in terms of partial derivatives.


WordPress: CODE to define column width for single row of table

Question: WordPress: Seeking a way to change column widths and concatenate columns on individual rows in a WordPress table w/ HTML.
Example: https://synergycbd.com/catalog/
Tried:

ACDC ~ The ultimate CBD medicine:

This strain...

and

ACDC ~ The ultimate CBD medicine:

This strain...

'Would like this row to appear in one column in the table and to be the full width of the table.  Other rows to contain multiple columns of defined widths.
Many Thanks ~:~ Jacob
Answer: SOLUTION: Remove designated row from table altogether.  Took a few minutes.  MANY THANKS!


Show that $\sum_{m\leq x , (m,d)=1}\frac{\mu^2(m)}{\phi(m)}\geq \frac{\phi(d)}{d}(\log[x]+1)$

Question: Show that $$\sum_{m\le x , (m,d)=1}\frac{\mu^2(m)}{\phi(m)}\geq \frac{\phi(d)}{d}(\log[x]+1)$$
I want to use the fact that $$\sum_{m\le x , (m,d)=1}\frac{\mu^2(m)}{\phi(m)}=\sum_{m\le x}  \sum_{r|(m,d)}\frac{\mu^2(m)}{\phi(m)} \mu(r)=\sum_{r|d}\sum_{k\le x/r}\frac{\mu^2(rk) \mu(r)}{\phi(rk)}$$
but I don't know how to do next.
Any hints are appreciated. Thanks!
Comment: The function [x] denotes the biggest number less or equal to x
Comment: If the result holds for $d=1$, then the result holds in general. But, proving the result for $d=1$ seems difficult. It is easy to see $\log x$ is the main term of the asymptotic, but the constant $1$ seems very strong.
Comment: When $d=1$ it's equivalent to prove that, let $n$ be the floor function of $x$ and prime $p_r<n<p_{r+1}$ $$\dfrac{p_1p_2\dots p_r}{(p_1-1)(p_2-1)\dots (p_r-1)}\ge \log n + 2$$ and the right-handed side is less than $\log 2p_r+2$ if we use Bertrand's postulate, but I think it's strong to prove and not sure when we use the postulate it will surpass the bound or not. Yet, I believe it's true whenever $p_r\ge 17$
Answer: Definition: $\displaystyle f(n) = \prod_{p|n} p$, which means $f(n)$ is the product of all primes in $n$.
$\displaystyle \sum_{m\le x,\gcd(m,d)=1} \frac{\mu^2(m)}{\phi(m)}$
$\displaystyle =\sum_{m\le x,\gcd(m,d)=1,f(m)=m} \prod_{p|m} \frac{1}{p-1}$, if some prime has a power more than 1, then $\mu(m)=0$.
$\displaystyle =\sum_{m\le x,\gcd(m,d)=1,f(m)=m} \prod_{p|m} \frac{\frac{1}{p}}{1-\frac{1}{p}}$, changed into the form of a geometric series summation.
$\displaystyle =\sum_{m\le x,\gcd(m,d)=1,f(m)=m} \prod_{p|m} \sum_{k\ge 1}\frac{1}{p^k}$, geometric series summation.
$\displaystyle =\sum_{m\le x,\gcd(m,d)=1,f(m)=m} \sum_{f(n)=m}\frac{1}{n}$, expanded the multiplication.
$\displaystyle \ge \sum_{m\le x,\gcd(m,d)=1,f(m)=m} \sum_{f(n)=m,n\le x}\frac{1}{n}$, changed the range of $n$.
$\displaystyle = \sum_{n \le x,\gcd(n,d)=1} \frac{1}{n} \sum_{m=f(m)=f(n),m\le x} 1$, reordered the sum.
$\displaystyle = \sum_{n \le x,\gcd(n,d)=1} \frac{1}{n}$, since the right side, $m$, has only one value, and $m = f(d) \le d \le x$
$\displaystyle = \frac{\phi(d)}{d}\prod_{p|d}\frac{1}{1-\frac{1}{p}}\sum_{n \le x,\gcd(n,d)=1} \frac{1}{n}$, for what we are going to prove, we break up 1.
$\displaystyle = \frac{\phi(d)}{d}(\prod_{p|d}\sum_{k\ge 0} \frac{1}{p^k})\sum_{n \le x,\gcd(n,d)=1} \frac{1}{n}$, geometric series summation, same as above.
$\displaystyle = \frac{\phi(d)}{d}(\sum_{f(q) | f(d) } \frac{1}{q})\sum_{n \le x,\gcd(n,d)=1} \frac{1}{n}$, geometric series summation.
$\displaystyle = \frac{\phi(d)}{d} \sum_{f(q) | f(d) } \sum_{n \le x,\gcd(n,d)=1} \frac{1}{nq}$
$\displaystyle \ge \frac{\phi(d)}{d} \sum_{t\le x}\frac{1}{t}$, now every $t\le x$ has only one way to be represented as $t=nq$ where $f(q) | f(d),\gcd(n,d)=1$.
$\displaystyle \ge \frac{\phi(d)}{d} \log([x]+1)$.
Proof complete.


Back to previous page with header( "Location: " ); in PHP

Question: The title of this question kind of explains my question. How do I redirect the PHP page visitor back to their previous page with the header( "Location: URL of previous page" );
Comment: header('Location: ' . $_SERVER['HTTP_REFERER']);
Comment: According to this source https://www.w3schools.com/php/php_superglobals_server.asp, it's not reliable because not all vendors support it
Answer: try:
header('Location: ' . $_SERVER['HTTP_REFERER']);

Note that this may not work with secure pages (HTTPS) and it's a pretty bad idea overall as the header can be hijacked, sending the user to some other destination. The header may not even be sent by the browser.
Ideally, you will want to either:

Append the return address to the request as a query variable (eg. ?back=/list)
Define a return page in your code (ie. all successful form submissions redirect to the listing page)
Provide the user the option of where they want to go next (eg. Save and continue editing or just Save)
Comment: Stranger things have happened :)
Comment: @Col so you can prove a practical problem with this?
Comment: Using the referer, after prior testing whether it's set and valid, in a defined page-to-page context can be a perfectly acceptable practice - the vast majority of browsers sends a proper HTTP_REFERER along.
Comment: @Madmartigan that sounds like really weird behaviour, the only hint I can see on the 'net causing it is some redirection problems. Anyway, I agree that using the referer is not the way if you need 100% safety
Comment: @Col I've use this in production when I had to get something done for a demo. As you can see from my answer, I provide three other solutions I would turn to instead of the redirection based on HTTP_REFERER.
Comment: @Col I grepped three daily logs: Yesterday's, and from two days last year. I see nothing but empty ones, `-`, or `http://` URLs
Comment: @Col are you playing a joke with me? How many browsers do you know that suppress the referer? The OP is asking about a page on the same site.
Comment: @Col All I can find on the issue is [this](http://stackoverflow.com/questions/2668821/which-browsers-do-not-send-referer-information) and [this](http://en.wikipedia.org/wiki/Referrer#Referrer_hiding). Unless you can provide proof of a significant number of browsers that by default don't send referer information when switching from one page on the same domain to the other, I call bullshit.
Comment: @Pekka: I realize this is old news, but Chrome returns `favicon.ico` for `$_SERVER['HTTP_REFERER']` for me very frequently, so I have to agree that method is useless in the real world.
Comment: @Madmartigan that sounds like an improperly set up redirection though. To my knowledge, HTTP_REFERER is not broken.
Comment: @Pekka heck, just grep your access log for referers which doesn't start from "http://". And where would it take all these users?
Comment: @Pekka empty referer will cause blank screen out from this code.
Comment: @Pekka I am tired of this. Go try it in real, with logging all improper referers. Then come back and we will continue
Comment: @Pekka: favicons are a strange case though, the way they're loaded and cached (I still don't understand all the details). In fact, just putting one in your webroot without a reference to it in your HTML will load it in the browser tab. And, like I said for this case, just Google Chrome was doing it. `HTTP_REFERER` is not "broken", it just shouldn't be used for this. You can't assume it's the last "page" a user visited, could be any resource. I'm guessing that Chrome was fetching the icon more than it needed to or something. Not sure what you mean by "improperly set up redirection"
Answer: Its so simple just use this
header("location:javascript://history.go(-1)");

Its working fine for me
Comment: This can cause the previous page to be served from browser cache.
Comment: This sounded really clever, but in FF10 I get `"Corrupted Content Error

          The page you are trying to view cannot be shown because an error in the data transmission was detected."` So this is basically unusable.
Comment: Wesley Murch, Its working fine for me in almost every major browser included the one you've mentioned. Its only work for you only in case you came to the page having something in history.
Answer: Just a little addition:
I believe it's a common and known thing to add exit; after the header function in case we don't want the rest of the code to load or execute...
header('Location: ' . $_SERVER['HTTP_REFERER']);
exit;

Comment: It's just "" for me.
Answer: You have to save that location somehow.
Say it's a POST form, just put the current location in a hidden field and then use it in the header() Location.
Answer: Just try this in Javascript:
 $previous = "javascript:history.go(-1)";

Or you can try it in PHP:
if(isset($_SERVER['HTTP_REFERER'])) {
    $previous = $_SERVER['HTTP_REFERER'];
}

Answer: Storing previous url in a session variable is bad, because the user might right click on multiple pages and then come back and save.
unless you save the previous url in the session variable to a hidden field in the form and after save header( "Location: save URL of calling page" );
Comment: why can't we just use the $_SERVER['http_referrer']?
Answer: I know this question focuses specifically on headers, but in case anyone would like to do it inside a button, this would suffice.
<button type="button" class="btn btn-default" onclick="javascript:history.go(-1)">Back</button>

Comment: The OP specifically asked for a PHP solution


File timestamp not changing even with touch

Question: I have the following problem. I have a bash script that uses wget to get a few files from the build server, and then scp's them over to the production system: Here is the relevant snippet:
#Several of these lines
wget -nv -O birt_reports.zip "http://buildserver:8111/guestAuth/repository/download/bt6/.lastFinished/birt_reports.zip"

#files in the for loop left out for simplicity
for upload_file in "birt_reports.zip"; do

    scp -B -i /root/$keyfile  $upload_file $user@gateway:/home/$user/deploy_staging
    touch $upload_file
done

Even with the touch in there the time shown in ls -l of the directory is the time the file was first created. If I do the wget outside the bash script or the touch outside the bash script, the time updates correctly.
What could the issue be?
Comment: I assume the account has write permissions on the file..
Comment: Yes, it is run as root.
Answer: Using the bellow command it is supose to set the timestamp of the file to your system current datetime:
touch -t `date +%y%m%d%H%M.%S` /path/to/filename

You could try it instead of the plain touch command alone.
Also when you run your bash script run with:
bash -xv your_bash_script.bash

also try using the full path of your commands, to verify the full path of the command do:
whereis touch
Since you could be using this without a shell enviroment using the full path is more recommended to make sure it will run every command without problems.
Answer: perhaps /bin/touch -m $upload_file is better suited, as it changes the modification time to the current time.
Answer: Is the file being properly scp'ed?
(I can't comment on your question post)
If not, then I think you're missing something to the uploaded file path within the for loop for both commands. Prix points out the way to check the actual commands.
Comment: Yes, oddly the file does correctly copy.


How to tell if page is being called from a fetch()?

Question: With jQuery the Ajax function sets the header HTTP_X_REQUESTED_WITH , so with PHP I could do:
if(filter_input(INPUT_SERVER, 'HTTP_X_REQUESTED_WITH') === 'XMLHttpRequest')
{ ... }

And this will tell me the page has been requested using Ajax.
Now I'm wanting to change the Ajax function to fetch(). I've looked through the default headers that it sets and I can't find anything that I can use to to tell if the request is being sent from a fetch.
I could set the header myself:
fetch('/get/login', {
    headers: {
        'X-Requested-With': 'fetch',
    },
})
.then(function(response) { ... }

However it isn't ideal to be writing that header out for every fetch. What are my options here? Is there a better way to tell if the request is being made through a fetch?
Comment: Append a parameter to URL that acts a flag to indicate this is how it was retrieved. `fetch('/get/login?fetch', {`
Comment: actually, expecting the header to exist all is expecting the wrong thing (there is *zero* guarantee that jQuery even adds that header). If you need to filter based on the method you're calling data from, you'd kind of doing web content serving wrong, but if you absolutely must, just add that header yourself, and make a function that you call that wraps the `fetch` call and the header binding so you don't call `fetch` but that function instead, so you have one function you need to update, ever.
Answer: No, there is nothing else you can rely on.
Theoretically you shouldn't give your server different behaviour depending on request method; that should be orthogonal to the content defined by your system's back-end.
But, if you're desperate, I quite like your existing solution; you could wrap it in a function for brevity.
Answer: Since you are relying on the client side to pass the data, couldn't you pass a POST variable inside body? Passing a header via javascript is no more secure than simply passing an additional field. (https://davidwalsh.name/fetch)
fetch('/get/login', {
    body: JSON.stringify({
        source: : "fetch"
    }),
})
.then(function(response) { ... }


How to calculate $\int_{-\infty}^{\infty} \Phi(y+c)^{k-1}d(\Phi(y))$?

Question: How to calculate $\int_{-\infty}^{\infty} \Phi(y+c)^{k-1}d(\Phi(y))$? When I check the list of integrals of Gaussian functions, I only find $k-1=2$.
Comment: Use numerical methods.  The integrand is very nicely behaved and it's simple to predict where most of its mass lies.
Answer: Let $X_0, X_1, \cdots, X_{k-1}$ denote $k$ independent unit-variance normal random variables, and suppose that $E[X_0]=0$, and $E[X_i]=-c$, $1 \leq i \leq k-1$. Let $C$ denote the event that $X_0 > \max_i X_i$. Then,
$$P(C\mid X_0 = y) = P(\max_i X_i \leq y) = \prod_{i=1}^{k-1}P(X_i \leq y) = [\Phi(y+c)]^{k-1}.$$
Consequently,
$$P(C) = \int_{-\infty}^\infty [\Phi(y+c)]^{k-1}\,\mathrm d[\Phi(y)]
= \int_{-\infty}^\infty [\Phi(y+c)]^{k-1}\phi(y)\,\mathrm dy$$
where $\phi(y)$ is the standard normal density function.  As whuber says in a comment, there is no closed-form expression for the value of this integral but it is nicely behaved and amenable to numerical evaluation. Evaluating integrals of this type is of great interest to communications engineers -- more truthfully, accurate evaluation of $1-P(C)$ is of great interest to communications engineers-- because $1-P(C)$ corresponds to the probability of error in orthogonal signaling.  See, for example, this answer of mine for some details.
Answer: This integral is equal to $\mathbb{E}(\Phi^{k-1}(Y+c))$ for $Y$ follows the distribution $\mathcal{N}(0,1)$.
By applying this answer  with $a = 1, n = k-1$, we can have a closed-form expression for the integral via a multivariate normal probability.
$$\color{red}{\text{Integral} =\mathbb{E}(\Phi^{k-1}(Y+b)) = \Phi_{k-1} \left(\mathbf{l}, \mathbf{u};\mathbf{0}_{k-1};\Sigma   \right)}$$
with

$\Phi_{k-1}() $ the multivariate normal probability
$\mathbf{l} \in \mathbb{R}^{k-1}$ vector with all elements are equal to $-\infty$
$\mathbf{u} \in \mathbb{R}^{k-1}$ vector with all elements are equal to $b$
$\mathbf{0}_{k-1} \in \mathbb{R}^n$ vector of $0$
$\Sigma \in \mathbb{R}^{(k-1) \times (k-1)}$, its elements can be defined in $(4)$ of the answer
Comment: +1 But although expressing this in terms of $\Phi_k$ can be useful, I doubt that anyone would consider $\Phi_k$ a "basic function", hence your expression is really not "closed-form"
Comment: @JarleTufto I know there is at least one [published paper](https://www.sciencedirect.com/science/article/abs/pii/S1062940818306028), written by a professor, state that formulas composing of many multivariate normal probabilities $\Phi_n$ are 'closed-form'.


jQuery .delegate() and .undelegate() is not working in chrome 56 and above versions

Question: Please let me know the alternate function for this..
$("#_body").undelegate('click').delegate(".class> a",'click',function(){

I want to toggle the portlet on live click.
Thanks
Answer: Try on() and off() like:
$("#_body").off('click').on(".class> a",'click',function(){
  // your code here
});

Using jQuery on()
In jQuery 1.7, on() method was introduced which is an effort to simplify and merge most event bindings functions into one unified consistent API. If you are interested to see how on() replaces the functionality of all these event methods, open the jQuery 1.7.1 source code (https://github.com/jquery/jquery/blob/1.7/src/event.js#L965) and you will find that bind(), live() and delegate() all point to the on() method.
Comment: Thanks, but even this is not working. The click is not responsive for live click, bind unbind and on and off functions. Is there is any other function?


Deletar table>tr com Ajax e PHP

Question: Fala galera, to com uma duvida aqui.. quero poder deletar uma linha da tabela com Ajax apenas clicando em um botão sem precisar carregar a tela.. já pesquisei e tentei fazer mais não deu certo.. tenho o seguinte código html:

    <?= $client['name']; ?>
    <?= $client['email']; ?>
    <?= $client['tell']; ?></
    <button id="delete" class="glyphicon glyphicon-remove"></button>

e java script:
$("#delete").click(function(){
    var id = $(this).attr("id");
    var request = $.ajax({
        type: "POST",
        data: "id="+id,
        url: "/removeClient",
        dataType: "json"
    });

    return false;
});

a parte do php eu resolvo.. quero apenas receber um $_POST['id'] e passar para o methodo que ira deletar o registro. Agradeço!
Answer: Consegui resolver aqui da seguinte forma..
$(function() {
    $(".delete").click(function(){
    var element = $(this);
    var id = element.attr("id");
    var info = 'id=' + id;

    if(confirm("Deseja realmente Deletar cliente id:   " + id)) {
        $.ajax({
            type: "POST",
            url: "/removeClient",
            data: info,
            success: function () {
            }
        });

        $(this).parents("#show").animate({backgroundColor: "#003"}, "slow").animate({opacity: "hide"}, "slow");
    }

    });
});

esta funcionando e deleta a row apos a o confirm retornar true, porem gostaria de saber como posso personalizar esse confirm, ou utilizar algum modal.
Answer: Primeiro coloque um id na sua tr, e muda o delete de id para classe, e coloco um atributo data com o id no button
   <tr class="tr_<?= $client['id']; ?>">
        <?= $client['name']; ?>
        <?= $client['email']; ?>
        <?= $client['tell']; ?></
        <button data-id="<?= $client['id']; ?>" id="delete" class="delete glyphicon glyphicon-remove"></button>

Ai faça a requisição, e faça com que o php devolva 1 para deletado, e 0 para erro.
$(document).on('click', '.delete', function () {
    var id = $(this).data('id');
    $.ajax({
        type: "POST",
        url: "pagina.php",
        data: {id: id},
        dataType: 'json',
        success: function (data)
        {
            var retorno = data;

            if(retorno === 1){
               $('.tr_'+id).empty().hide();
            }else{
               alert('erro no php');
            }
        }
    });
});

Não testei o código, mas acho que se não estiver certo, ta bem próximo.
Comment: Cara fiz igual teu código mais não funcionou, e nem retorna nada no console nem o ('erro no php').. tentei alterar algumas coisas mas nada.. x=
Comment: Testei e o código é isso mesmo, você ta fazendo alguma coisa errada, provavelmente está faltando alguma coisa na tabela, ou o caminho para o php não está correto.
Answer: Na resposta do AP ....... porem gostaria de saber como posso personalizar esse confirm, ou utilizar algum modal.

As Bibliotecas
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

SCRIPS
//função disparada ao clicar no botão relativo a linha
$(function() {
    $(".delete").click(function(){
        var element = $(this);
        id = element.attr("data-id");
            if(id){
                //conteudo do paragrafo

 dentro do modal
                $("#resultado").html("Tem certeza que quer excluir o id "+id);

                //abre o modal com a pergunta acima
                $("#myModal").modal('show');
             }
    });
});

//função disparada ao clicar no botão deletar do modal
function checkDeletar() {
    jQuery.ajax({
    url: "/removeClient"",
    data: 'id=' + id,
    type: "POST",
    success:function(data){

        /* oculta a linha */
        $('.tr_'+data).hide();

        //oculta o modal
        $("#myModal").modal('hide');

    },
    error:function (){
        alert('erro');
    }
    });
}

HTML

       <tr class="tr_<?= $client['id']; ?>">
            <?= $client['name']; ?>
            <?= $client['email']; ?>
            <?= $client['tell']; ?>
            <button data-id="<?= $client['id']; ?>" id="delete" class="delete glyphicon glyphicon-remove"></button>

                     <button type="button" class="close" data-dismiss="modal">X</button>

                      <button type="button" class="btn btn-primary btn-sm" onClick="checkDeletar()">Deletar</button>

                     <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>

Deletar table>tr com Ajax e PHP


How do I use the inputs of 2 separate spinners

Question: I'm trying to build an app that takes 2 inputted redox pairs from 2 spinners to display information about the cell that could be made from these chemicals such as what would be used as the anode/cathode, the reduction potential of each half-reaction and the cell etc.
My issue is I haven't been able to find any way to take the input of both the spinners to be able to make the calculations, only have both spinners do the same thing.
My current code is this:
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener{

Spinner spinner1, spinner2;
ArrayAdapter adapter;

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

    adapter = ArrayAdapter.createFromResource(this, R.array.pairs, android.R.layout.simple_spinner_item);

    spinner1 = (Spinner) findViewById(R.id.spinner1);
    spinner1.setAdapter(adapter);
    spinner1.setOnItemSelectedListener(MainActivity.this);

    spinner2 = (Spinner) findViewById(R.id.spinner2);
    spinner2.setAdapter(adapter);
    spinner2.setOnItemSelectedListener(MainActivity.this);
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    String choice1 = parent.getItemAtPosition(position).toString();
    double first = 0;
    double second = 0;
    double anode;
    double cathode;
    if (choice1 == getResources().getString(R.string.MnO4)){
        first = 0.60;
        Toast.makeText(parent.getContext(), choice1, Toast.LENGTH_SHORT).show();
    } else if (choice1 == getResources().getString(R.string.Cl)) {
        first = 1.36;
        Toast.makeText(parent.getContext(), choice1, Toast.LENGTH_SHORT).show();
    }
    if (first > second) {
        cathode = first;
        anode = second;
    } else {
        cathode = second;
        anode = first;
    }
    double cellValue = anode - cathode;

}

@Override
public void onNothingSelected(AdapterView<?> parent) {

    }
}

I'm very new to android studio so any help is greatly appreciated.
Thanks
Comment: I don't know if it's the best practice, but what I'll do is declare local variables that I set values on each spinners onItemSelected callback. Like, spinner1 got variable1 and spinner2 got variable2
Comment: Why are you using the same adapter for both spinners?\
Answer: I suggest that you use anonymous classes to handle the onItemSelected. That way you can handle the selection of each Spinner independently.
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    adapter = ArrayAdapter.createFromResource(this, R.array.pairs, android.R.layout.simple_spinner_item);

    spinner1 = (Spinner) findViewById(R.id.spinner1);
    spinner1.setAdapter(adapter);
    spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                // Do what you need to do with spinner1 info
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

    spinner2 = (Spinner) findViewById(R.id.spinner2);
    spinner2.setAdapter(adapter);
        spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                // Do what you need to do with spinner2 info
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
}

Now you can remove the Override method:
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

and you can remove implements :
implements AdapterView.OnItemSelectedListener


opscenter REST API when authentication is enabled

Question: I enabled authentication on my opscenter node as per this . I've a python script that periodically invokes opscenter actions through the Opscenter REST APIs. From the REST API documentation, it looked like all I had to do was invoke these methods with basic HTTP auth (see this). But these calls always failed with a "user must be logged in" error.
After poking around the javascript that runs when I use the opscenter's web frontend, I figured that I must actually invoke the login method to create a session and use that session to invoke other methods, such as:
session = requests.Session()
login_body = '{"username": "%s", "password": "%s"}' % (opsc_uname, opsc_pwd)
login_resp = session.post("http://{url}/login".format(url=opsc_url), data=login_body).json()
clusterconf = session.get("http://{url}/cluster-configs".format(url=opsc_url)).json()

Is the api documentation (that claims to use basic http auth) wrong? Or am I doing something incorrectly? The opscenter version I'm using is 5.1.1
Answer: You figured it out correctly, OpsCenter 5.1 uses sessions instead of basic auth. You've been looking at 5.0 docs, that's why it wasn't documented. Here's a correct link.
Answer: In addition to the documentation link the user "arre" has posted above when you implement that method ensure you dont include the { } curly braces, so for example use
curl -H 'opscenter-session: d6c5e198b9b5ffeab9fd8dea6fb012aa' http://127.0.0.1:8888/permissions/user

Instead of
curl -H 'opscenter-session: {d6c5e198b9b5ffeab9fd8dea6fb012aa}' http://127.0.0.1:8888/permissions/user


Zoom in Anychart using anychart.resource()

Question: I'm converting from using anychart.ganttResource() to using anychart.resource(), since I need overlapping tasks for my resources.
In anychart.ganttResource() we used zoomTo to get the timeline to match filter on the period shown, but according to the api reference this only Works for Gantt or Maps.
Do anyone know how to set "an end date" for timeline in resource, or how to control to timeline / calendar ?
Regards Anja
EDIT:
Using https://playground.anychart.com/gallery/8.0.1/Gantt_Charts/Server_Status_List I figured out how to get overlapping task in a ganttresource chart
Answer: Unfortunately, as December of 2017 AnyChart 8.0.1 doesn't provide such feature for Resource Chart. After the chart loading, visible range of the Resource chart is always anchored to the beginning of the xScale.
Comment: Thanks for the fast reply. If I use the Gantt Ressource Chart, can I then have overlapping tasks for the resources? (like in this https://playground.anychart.com/gallery/8.0.1/Resource_Charts/Development_Team_Plan_(Time_Tracking_On) ), If so  can you provide me with an example?
Comment: Actually, the resource chart in this demo doesn't contain overlapping tasks. Every activity represents how many hours per day any resource is busy. Several activities stacked in a column means that this resource is busy several times by different tasks and during different periods of a day. Gantt resource provides overlapping, two overlapped periods look like a single one. An example of such behavior you may find in this example - https://jsfiddle.net/v2gwp7L7/ .   Server1 actually has three periods, but the 1st and 2nd are overlapped.


SQL, Calculate Data Between Rows Using Lag

Question: I have a Play table and it has columns possession and clock.  I want to return all plays where the possession is 'away' and calculate the time elapsed between the previous play and the selected play.  The problem is, using my query, the lag function is calculating elapsed time on a set of only plays where 'away' has possession and not a set of all plays.
select (lag(clock, 1) over () - clock) from plays where possession = 'away';

How do I make the lag(clock, 1) refer to the set of all plays, not just those where possession = 'away'?
Comment: `lag()` without an `order by` in the `over()` clause doesn't make sense. Rows in a relational database are not sorted, so without specifying a sort order getting the "previous" row is not possible in a consistent manner.
Answer: I think you just want a subquery:
select p.*
from (select p.*, (lag(clock, 1) over () - clock) as diff
      from plays p
     ) p
where possession = 'away';

Comment: thanks that worked great for me.  i had to adjust it slightly for it to work, select p.*
from (select possession, (lag(clock, 1) over () - clock) as diff
      from plays
     ) p
where possession = 'away';


ReferenceError: navigation is not defined

Question: i am newbie to react native, When i add a button for navigation, it show that navigation is not defined. I need some help.
import { Image,  Button,StyleSheet, Text, View, ScrollView, SafeAreaView, ImageBackground, } from 'react-native';
import { NavigationContainer, NavigationHelpersContext, StackNavigator, useNavigation} from '@react-navigation/native';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import 'react-native-gesture-handler';
import { createStackNavigator } from '@react-navigation/stack';

import HelloWorldApp from "./scholarship.js"

const HomeScreen = () =>
{
   <Button title="sample" onPress={()=> navigation.navigate('Scholarship')}></Button>
}
const Scheme = createStackNavigator();

function myScheme({navigation})
{
    <Scheme.Navigator>
        <Scheme.Screen name="Scholarship" component={HelloWorldApp}/>
    </Scheme.Navigator>
}

export default HomeScreen;```

Answer: Use your Home component Like:-
const HomeScreen = ({navigation}) => {
  ........................
  .........
  }

this sholud solve your problem. the navigation lies in the props of the component
so to use is like navigation.navigate('') you have to destructure it from props.
like i did above .
Answer: According to React Navigation documentation you should use useNavigation hook:
import { useNavigation } from '@react-navigation/native';

const HomeScreen = () =>
{
   const navigation = useNavigation();
   return (
      <Button title="sample" onPress={()=> navigation.navigate('Scholarship')}></Button>
   );
}


How to create enum object from its type and name of the value?

Question: I have a type (System.Type) of an enum and a string containing enumeration value to set.
E.g. given:
enum MyEnum { A, B, C };

I have typeof(MyEnum) and "B".
How do I create MyEnum object set to MyEnum.B?
Answer: MyEnum enumValue = (MyEnum)Enum.Parse(typeof(MyEnum), "B");

You also have a case-insensitive overload.
Answer: I assume you don't have access to MyEnum, only to typeof(MyEnum):
void foo(Type t)
{
   Object o = Enum.Parse(t, "B");
}

Answer: You can do this with generics. I created a Utility class to wrap this:
public static class Utils {
    public static T ParseEnum<T>(string value) {
        return (T)Enum.Parse(typeof(T), value, true);
    }

Then invoked like:
string s = "B";
MyEnum enumValue = Utils.ParseEnum<MyEnum>(s);


Erro ao checar a versão do Apache Cordova

Question: Quando eu vou checar a versão do Apache Cordova no Ubuntu aparece a mensagem abaixo.

<code>Error: EACCES: permission denied, open '/home/henrique/.config/configstore/insight-cordova.json'
You don't have access to this file.
</code>

Como eu resolvo?
Comment: Relacionado: [**Erro de "EACCES" ao utilizar o Cordova no OS X**](https://pt.stackoverflow.com/questions/135950)
Comment: Tente esse comando: `sudo chown -R henrique /home/henrique/.config/configstore/`
Comment: Consertou o problema, obrigado!!!
Answer: Você deve alterar o proprietário dos arquivos do diretório:
<code># Se estiver usando distribuições Linux
/home/NOME_DO_USUARIO/.config/configstore/

# Se estiver utilizando Mac
/Users/NOME_DO_USUARIO/.config/configstore/
</code>
Basta executar o seguinte comendo no terminal:
<code># Se estiver usando distribuições Linux
sudo chown -R NOME_DO_USUARIO /home/NOME_DO_USUARIO/.config/configstore/

# Se estiver utilizando Mac
sudo chown -R NOME_DO_USUARIO /Users/NOME_DO_USUARIO/.config/configstore/
</code>
Explicação

sudo: Indica que o comando será executado pelo root.
chown: Altera o proprietário de um diretório ou arquivo.
-R: Esse parâmetro indica que a alteração será de forma recursiva.
NOME_DO_USUARIO: Altere para o nome do seu usuário.


Is $\nabla F(x, y, z)\cdot \hat y$ related to the derivative of $F$ in the direction of $y$-axis?

Question: Let $F:\mathbb{R}^3\to\mathbb{R}$ be a $C^2$ function. I was wondering what is exactly
$$\nabla F(x, y, z)\cdot \hat y,$$
where "$\cdot$" denotes the dot product and $\hat{y}$ is the unit vector in the direction of $y$-axis.
Intuitively, I would say that it is something related to the derivative of $F$ along the direction of $y$, but I am not sure about that.
Could someone please help to understand that? Any example would be really appreciated, too.
Thank you.
Answer: Simply,
$$\nabla F\cdot \boldsymbol e_y=\begin{bmatrix}\frac{\partial F}{\partial x} \\ \frac{\partial F}{\partial y} \\ \frac{\partial F}{\partial z}\end{bmatrix}\cdot\begin{bmatrix}0 \\ 1 \\ 0\end{bmatrix} \\ =0\cdot \frac{\partial F}{\partial x}+1\cdot \frac{\partial F}{\partial y}+0\cdot\frac{\partial F}{\partial z} \\ =\frac{\partial F}{\partial y}$$
Comment: K.defaoite, I had that suspicion.. Thank you!
Comment: While the answer is correct, I think it is worth mentioning that what you do is called a directional derivative. In this case a directional derivative along the y axis.


PSAD Firewall/ UDP flood?

Question: Well I'm actually trying to block a UDP Flood on the Application port because the string "getstatus" is causing my application to make large output due to a small input to the attacker's IP.
I installed PSAD firewall to do the job.
psad -S shows 3000,000 logged packets at the application port and top ports in Scan but does not block the IP of the attacker however other IP Addresses with small number of connections are dropped. I'm thinking that since output is also being made to the attacker, this is why its not getting blocked because iptables rate-limiting is also exactly doing the same thing and not blocking the IP where outgoing connection is also made.
Any guesses why it won't work?
Answer: Okay the case here was that the rate was actually higher than 200/s so this is why the firewall wasn't working. This was because the packets were no longer new  (--state NEW ).

PSAD Firewall/ UDP flood?


How would these chords from "When Christmas Comes to Town" be analyzed?

Question:
Hi everyone.
I'm analyzing "When Christmas Comes to Town", which is one of my favorite holiday songs.
The image shows the last four measures of the bridge section. The bridge is in E♭-minor, while the rest of the song is in E♭-major.
I'm trying to figure out how to analyze the final two measures of the bridge section. The last measure seems to be a straight-forward ii7 - V7 back to I in the next measure.
There are two ways I thought of analyzing the final two measures:

The B7 (enharmonic to C♭7) almost seems to be acting like a Ger+6 chord, although it moves to ii7 (or ii7add11) before resolving to V7. The melody of the final measure of the bridge has the note B♭, which would be the note of resolution if the B7 is acting as a Ger+6 chord.

Another way I thought of looking at this was to consider the F♯m7 and B7 as a ii7 - V7 of ♭II (F♭-major, or E major), and this (eventually) resolves to the tritone substitution of ♭II (which would be a regular V7).

Do these analyses make sense? Is there a better way to analyze these measures that I haven't considered? I'd love to hear any thoughts on this. Thanks in advance, and happy holidays!
Comment: It is my long-held opinion that there is no functional difference in the analysis of an augmented sixth and that of bII7/V, so for me your two ways are in essense one and the same
Comment: I agree with Judy, as far as I also interpreted the Ger aug 6 just as bVI before I learnt to know  the development of the  aug 6. As far as I see your analysis is correct.
Answer: This is a sequence of ii-V7 progressions:

Fm-Bb7-Ebm

F#m-B7- ??? is actually Gbm-Cb7 -> Bb7 (Bb suspended by Fm7-B7sus)

and Cb7 is actually Cb,Eb,Gb,A = the German sixth chord functionally resolving to Bb:
Explanation:
ab,cb,eb,gb=ivm7 of Eb-minor, cb,eb,gb,ab=first inversion. Cb,eb,gb,a=augmented56 (=German6th) resolving to ii-V7 of Eb.
Resume:
The Ger6 analysis is rather a classical analysis, while the other one is common in pop music.
Answer: F♯m7, B7 is a ♭5 substitution for Cm7, F7, which is standard 'cycle of 5ths'.
This also illustrates the strength of the ii7, V7, (I) progression.  You can jump to just about any place and, as long as you follow that pattern it sounds OK.   (See 'Giant Steps'.)
If you want it as a 'rule of thumb', a short functional sequence (and you can't get much more functional than ii7, V7) can be effectively preceded by the same sequence a semitone up.  Stick it in your bag of tricks.


Minimum sample size in each strata of stratified random sampling

Question: I am performing stratified random sampling on a population (country) containing ~20 strata (states). I need to calculate mean of the population. I also know the proportion of the strata. My question is: Should I have a minimum sample size (say >=30) in each strata/state? I have greater than 30 samples for the country, but I do not have greater than 30 samples for each state. My assumption is since I am calculating mean for the population (country), at a state level, I can as well have 1 or 2 samples.
Will this be an issue in estimating the means? Please let me know.
Thanks!
Answer: Minimum sample size is useful once you consider that units might not respond.  However, if you make it too large your design is going to be less efficient.  If you aim for about $5$ reponding units should be enough.  Bump this up with an assumed response rate $5/rr $.  $30$ is more than enough - but will probably mean you are putting sample where it isn't needed for a good estimate of the total


Convert url to lower case using htaccess except query string

Question: Am struggling with a htaccess problem.
I need to convert all the URLs from uppercase to lowercase. But the query string alone should be the same.
For example,
www.tESTUrl.com/sOMePath/?q=SomeStringHere

should be converted as,
www.testurl.com/somepath/?q=SomeStringHere

Please help to fix this. Thanks in advance.
Answer: First You have to add this to your httpd.conf:
RewriteMap lc int:tolower

Then paste the below code into your .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^[^A-Z]*[A-Z].*
RewriteRule ^ ${lc:%{REQUEST_URI}} [L,R=301]

This code redirct the url like from
www.tESTUrl.com/sOMePath/?q=SomeStringHere
to   www.testurl.com/somepath/?q=SomeStringHere
Comment: `REQUEST_URI` do not contain the domain name, only the URL path.
Answer: First you need to add this line in your httpd.conf to define a RewriteMap for handling lower case conversion:
RewriteMap lc int:tolower

Then add this rule in your root .htaccess:
RewriteEngine On

RewriteRule ^(.*?[A-Z]+.*)$ /${lc:$1} [L,NE,R=302]

This will not affect QUERY_STRING.
Comment: Thanks @anubhava.. Please let me know where should I exactly place the RewriteMap ?? Sorry I am new to it.
Comment: It can be placed at the bottom of `httd.conf`. You will need to restart Apache after that change.
Comment: Let me check it. Thanks
Comment: Sorry anubhava its not working.. I am using xampp.. Windows OS.. Anything else should I do..?
Comment: Did you restart Apache after adding this line? This is properly tested rule and working on my side.
Comment: Yes I restarted.. Can you please tel me whether I need to enclose the RewriteMap code in any  tag like that..?
Comment: no it doesn't need any `` block. I just placed `RewriteMap lc int:tolower` as the very last line in my `httpd.conf` and restarted. Then I placed rewrite rule in my root .htaccess and it worked. Do you have other rules also in your .htaccess?
Comment: No.. htaccess is empty
Comment: First verify whether your `.htaccess` is enabled or not, by putting same garbage (random) text on top of your `.htaccess` and see if it generates 500 (internal server) error or not?
Comment: Yes I checked it.. Its enabled.. When I am adding some garbage text its showing error..
Comment: @anubhava Ya working this code for me, but it removes the subfolder name too like "sOMePath". plz check it
Comment: That is not being done using this redirect rule. You may have some other rules doing this subfolder removal.
Answer: I believe tweaking the answer given here can handle the www.tESTUrl.com/ hostname part of the equation:
RewriteCond %{HTTP_HOST} !^(.+\.)?(.+)?$
RewriteRule ^(.*)$ ${lowercase:%{HTTP_HOST}}/$1 [R=301,L]

And then I believe this should work for the sOMePath/ path:
RewriteMap lc int:tolower
RewriteRule (.*?[A-Z]+.*)/?(.*)$ ${lc:$1}/?q=$2 [R]

Answer: RewriteCond %{REQUEST_URI} ^[^A-Z]*[A-Z].* [OR]
RewriteCond %{QUERY_STRING} ^[^A-Z]*[A-Z].*
RewriteRule ^ ${lc:%{REQUEST_URI}}?${QUERY_STRING} [L,R=301]

The second line is not necessary but helpful if you want to lowercase the query string in the future. I just put this here to be complete.
You have to add this to your httpd.conf:
RewriteMap lc int:tolower

Comment: Can you please tel me whether I need to enclose the RewriteMap code in any  tag like that..?
Comment: You can put it in the VirtualHost entry: "

  RewriteMap lc int:tolower" ....


Django template not rendering time correctly

Question: I have datetime object that I need to show in two different timezones. In the backend, I use astimezone() to change the original datetime tzinfo, this is the code:
print("event.date_start: %s" % event.date_start)
print("event.date_start.hour: %s" % event.date_start.hour)
print("event.date_start.tzinfo: %s" % event.date_start.tzinfo)

user_timezone = pytz.timezone("America/Guayaquil")
print("user_timezone: %s" % user_timezone)

event_user_timezone = event.date_start.astimezone(user_timezone)
print("event_user_timezone: %s" % event_user_timezone)
print("event_user_timezone.hour: %s" % event_user_timezone.hour)

This code prints the datetimes correctly, event.date_start is in UTC time, 18hrs - event_user_timezone is in "America/Guayaquil", 13hrs.
event.date_start: 2020-11-17 18:00:00+00:00
event.date_start.hour: 18
event.date_start.tzinfo: UTC
user_timezone: America/Guayaquil
event_user_timezone: 2020-11-17 13:00:00-05:00
event_user_timezone.hour: 13

However, when rendering the html, with this code:

    {{ event.date_start|date:"h:i A" }} ({{ owner_profile.timezone }})

    {{ event_user_timezone|date:"h:i A" }} {{ logged_user_profile.timezone }}

both times are displayed as 6pm. Why?
Comment: Did you set `USE_L10N` to `True`?
Answer: The date filter is specifically designed to undo what you did, as it is marked as "expects_localtime", which then goes to django.utils.timezone.template_localtime.
You don't have to do the things you do in the view, instead you should work with the date filter and the tag timezone, which then sets the correct timezone for a given block.
{% timezone owner_profile.timezone %}

    {{ event.date_start|date:"h:i A" }} ({{ owner_profile.timezone }})

{% endtimezone %}
{% timezone logged_user_profile.timezone %}

    {{ event.date_start|date:"h:i A" }} {{ logged_user_profile.timezone }}

{% endtimezone %}


Pull logs from remote server into elasticsearch

Question: The short question is: Is it possible to pull logs (within logfiles) from a remote server and ingest them into the ELK stack.
The long story is the following:

We have a setup with a DMZ which is publically facing
We have an intranet environment which hosts alot of internal systems, including the ELK stack
Due to security regulations we cannot establish connections (on IP level) from the DMZ towards the intranet.
We can however establish connections from the intranet towards the DMZ

Due to this setup, we cannot follow the normal route of installing a Filebeat on the server where the logs are stored and push the messages towards our logstash installation.
What we would like to do is something that looks somewhat like the following:

Filebeat or any other process gathers the logs on the server inside the DMZ
On this server there is some process (Filebeat, logstash, another elasticsearch instance?) which keeps those information in a local store
This tool (whatever it might be in the end) listens on a port which is available from the intranet
Another tool inside the intranet connects to the DMZ tool and pulls all gathered logs for further processing.

Our investigations sofar only resulted in solutions which push the log information to either logstash or elasticsearch.
One thing we do not want to do is to use fileshares to make the logfiles available directly from the intranet.
Our question is whether what we have in mind is possible at all and if so, what tools and with which setup we would accomplish this.
Answer: You can try the following using Kafka as a message broker
On your DMZ server you will have filebeat collecting logs and sending to a logstash instance, this logstash instace will then output your logs to kafka.
It is a simple pipeline with a beats input, your fitlers and a kafka output, if you don't want to do any enrichments on your data, you can send your logs direct to kafka from filebeat.
Your kafka broker will then listen on a port and wait for any consumer to connect and consumes the messages.
On your intranet you will need a logstash instance with a pipeline using the kafka input, this pipeline will act as a kafka consumer and will pull your messages, you can then use the elasticsearch output to store then in your intranet elasticsearch cluster.
For more information read the kafka documentation, and the documentation for the kafka input and kafka output in the logstash documentation.
Comment: Kafka is a nice workaround for this. It will require an additional piece of infrastructure, but I guess that is the tradeoff we have to take. Thanks for the hint! (I found another solution which is pretty much the same way to go, just using another elasticsearch instance to buffer the messages). But I like the Kafka way more, it feels like less configuration / setup footprint than another elasticsearch install.


Como remover apenas a scrollbar horizontal da página?

Question: Estou criando uma aplicação em Electron e preciso remover da página a scrollbar horizontal. Eu tentei utilizar o código CSS abaixo, porém ele remove também o scrollbar vertical.
::-webkit-scrollbar {
    display: none;
}

Answer: Isso não remove o scroll, ele oculta, se for para remover o certo seria aplicar direto no elementos:
html, body {
    overflow-x: hidden;
}

Aplicamos em ambos porque no Chrome e no Firefox geralmente é (ou era) diferente o elemento que possui o scrollbar padrão
Devo ressaltar, se tem um scrollbar horizontal que não devia existir é porque tem um elemento que estar excedendo a largura da página, então usar coisas como overflow é só gambiarra, você tem que IDENTIFICAR o elemento que esta ultrapassando os limites do view-port usando o DevTools do seu navegador

Aperte F12 (geralmente) e abra o DevTools
Role a página ao máximo que puder para a direita
Selecione a ferramenta de selecionar elementos:
Vá passando o mouse no lado direito da página, você irá com certeza encontrar o elemento
Answer: Poderia tentar dessa forma, JeanExtreme002.
::-webkit-scrollbar {
overflow-y:hidden;
}
Comment: O espaço em branco onde fica o *scrollbar* ainda permance. O que eu quero é o *scrollbar* completamente removido.


content tab inside content tab jquery

Question: I have this fiddle that have tab content my problem is how should i insert another set of tab content inside.
js
$(document).ready(function(){

    $('ul.tabs li').click(function(){
        var tab_id = $(this).attr('data-tab');

        $('ul.tabs li').removeClass('current');
        $('.tab-content').removeClass('current');

        $(this).addClass('current');
        $("#"+tab_id).addClass('current');
    })

})

Image below show what I want to achieve hope this make sense
Answer: Check in this fiddle for a solution to your problem. The idea was to stop propagating the click event of the nested tabs group to the parent tab group. For this reason, I use the  e.stopPropagation() function on the click event. This prevents, the click event of the parent tabs group and the correct functionality of the child tabs group. Hope it helps!
('ul.tabs2 li').click(function(e){
    e.stopPropagation();
    var tab_id = $(this).attr('data-tab');

    $('ul.tabs2 li').removeClass('current');
    $('.tab-content').removeClass('current');

    $(this).addClass('current');
    $("#"+tab_id).addClass('current');
})

Answer: http://www.adipalaz.com/experiments/jquery/nested_accordion_demo.html
This is a good example of having an accordion within an accordion.
Hope this helps!

content tab inside content tab jquery


Python Kivy Float Layout

Question: I have very little experience with Python and Kivy. I am helping my little nephew with his quest to build a game using the two. We are stuck at something that seems simple.
Consider following code:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import NumericProperty, ReferenceListProperty,\
    ObjectProperty
from kivy.vector import Vector
from kivy.clock import Clock
from random import randint
from kivy.graphics import Color, Ellipse, Rectangle
from kivy.uix.floatlayout import FloatLayout
import math

class Fly(Widget):
    pass

class Stick(Widget):
    pass

class FlyBox(Widget):
    pass

class GameArea(FloatLayout):
    pass

class FlyApp(App):
    def build(self):
        gameArea = GameArea()
        flyBox = FlyBox()
        flyBox.canvas.add(Rectangle(pos_hint={'x': 0, 'y': .3}, size_hint=(1, .3)))
        flyBox.canvas.add(Color(1, 0, 0))
        gameArea.add_widget(flyBox)
        return gameArea

if __name__ == '__main__':
    FlyApp().run()

it produces following output:

What we were trying to achieve was:

The FlyBox's height should be 1/3rd the height of the GameArea's height.
The FlyBox's width should be same as GameArea's width.
The FlyBox's x coordinate should be 0 and its y coordinate should be 1/3rd the height of GameArea.

i.e. if the game area were to be divided into 3 equal sized horizontal bands, the FlyBox should be the middle band. And as the size of game area changes (due to resizing of window), the FlyBox's size and position should change relatively.
We are trying to avoid using a .kv file and instead do everything in Python.
Answer: You only need to use size_hint_y property to set the correct height (1/3rd the parent height) and pos_hint property to position it in the center.
Using kivy languaje:
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder

kv_text = '''
<GameArea>:
    Widget:
        id: flybox
        size_hint_y: 1/3
        pos_hint: {'x': 0, 'center_y': .5}
        canvas.before:
            Color:
                rgba: 1,1,1,1
            Rectangle:
                pos: self.pos
                size: self.size
'''

class GameArea(FloatLayout):
    pass

class FlyApp(App):
    def build(self):
        Builder.load_string(kv_text)
        return GameArea()

if __name__ == '__main__':
    FlyApp().run()

Output:

Python Kivy Float Layout


How to Close FiddlerCore when windows is Shutting Down

Question: I would Like to Close The Fiddler When windows is Shutting Down  Fiddler.FiddlerApplication.Shutdown(), I have no idea how to do this if some one can help me out it would be really Great.
What My application Does is It Uses the Fiddlercore and Intercept the traffic
and it works Good But when the Application is not Closed Properly or if the Operating restarts its the Internet wont work because the FiddlerApplications is not Shutdown Properly.
Note : this is not a Winform Application its a Console Application
Answer: The solution is to get an event raised when the console application closes and from that event handler you can properly dispose the Fiddler application.
One possible solution can be found here:
"On Exit" for a Console Application


The scrollbar of  will disappear during the animating? any ideas to solve this?

Question: It looks during the animating of the pre tag, the scrollbar of pre will disappear, but appears later when animation is over. how can i make it appear in whole animation?

test it: www.gbin1.com

Comment: you can't really put a scroll bar on a changing width/height without some serious coding... Why would someone scroll while it was animating?
Answer: change your css properties to
pre {
  overflow:scroll !important;
}

as done in this example
http://jsfiddle.net/vTBV4/
however, the !important flag may not work in all browsers :( but as far as i know, this is the only way to ensure that the scroll is visible, as jquery animate implicitly sets the inline style overflow: hidden on the element to be animated.
Another option might be to create and animate a parent container instead of the
.


Delete specific part of string

Question: I'm using Pascal scripting to return a string based on a registry entry but I need to delete a specific part of that string.
Here's the current code:
function GetDirName(Value: string): string;
var
  InstallPath: string;
begin
  // initialize default path, which will be returned when the following registry
  // key queries fail due to missing keys or for some different reason
  Result := '{pf}\LucasArts\Star Wars Battlefront II\RegistryFailed';
  // query the first registry value; if this succeeds, return the obtained value
  if RegQueryStringValue(HKLM, 'SOFTWARE\LucasArts\Star Wars Battlefront II\1.0', 'ExePath', InstallPath) then
    Result := InstallPath
  // otherwise the first registry key query failed, so...
  else
  // query the second registry value; if it succeeds, return the obtained value
  if RegQueryStringValue(HKLM, 'SOFTWARE\Wow6432Node\LucasArts\Star Wars Battlefront II\1.0', 'ExePath', InstallPath) then
    Result := InstallPath
end;

The part that I need to remove from the returned string is \BattlefrontII.exe and it is always located at the very end of the string.
Example of what the returned string currently is: C:\Program Files (x86)\LucasArts\Star Wars Battlefront II\GameData\BattlefrontII.exe
Example of what I need the returned string to look more-or-less like: C:\Program Files (x86)\LucasArts\Star Wars Battlefront II\GameData
Any help is appreciated.
P.S. I am entirely new to Pascal; I'm only using it to compile an installer using Inno Setup Compiler
Comment: I've reverted your edit, as you modified the question being asked after you received an answer to the original. Please don't do that; it invalidates previous answers, can make the person who answered look pretty foolish, and in some cases can cost them reputation, none of which is very nice to those spending time trying to help you. If you have a new question, post a new question."I've changed my code (it's now this new code) and it still doesn't work. It now has this different problem." is a new question. This is not "evolve my code" - it's question and answer.
Comment: OT: never query explicitly `Wow6432Node` registry path. Instead use a direct path and `HKLM32` or `HKLM64` for root keys. Their descriptions you can find in the [`[Registry]`](http://www.jrsoftware.org/ishelp/index.php?topic=registrysection) section.
Comment: Any reason for this? (Note: My installer is only reading registry entries, not writing any.)
Comment: It's easier for you to maintain but what's more important is that you'll be using system redirector which will redirect you to the right registry view path. Who knows, maybe Microsoft decide to rename `Wow6432Node` to `Wow1234Node` which will be meant as a redirection node, and since that time you'll be out of luck with your hardcode.
Comment: One would expect the "EDIT:" bit to render that all nil, but whatever I guess. My bad. Not used to this style of forums. As for my issue, I believe the problem is solved. Will let you know (with a new question :D) if issues persist. HUGE thanks to you all. :)
Answer: Looks like what you want is ExtractFilePath:
function ExtractFilePath(const FileName: string): String;

Description: Extracts the drive and directory parts of the given file
  name. The resulting string is the leftmost characters of FileName, up
  to and including the colon or backslash that separates the path
  information from the name and extension. The resulting string is empty
  if FileName contains no drive and directory parts.

See the list of functions for more useful stuff.
In your case, you could put this:
Result := ExtractFilePath(Result);

At the end of your function.
Edit: to be extra explicit:
function GetDirName(const Value: string): string;
var
  InstallPath: string;
begin
  // initialize default path, which will be returned when the following registry
  // key queries fail due to missing keys or for some different reason
  Result := ExpandConstant('{pf}\LucasArts\Star Wars Battlefront II\RegistryFailed');
  // query the first registry value; if this succeeds, return the obtained value
  if RegQueryStringValue(HKLM, 'SOFTWARE\LucasArts\Star Wars Battlefront II\1.0', 'ExePath', InstallPath) then
    Result := InstallPath
  // otherwise the first registry key query failed, so...
  else
  // query the second registry value; if it succeeds, return the obtained value
  if RegQueryStringValue(HKLM, 'SOFTWARE\Wow6432Node\LucasArts\Star Wars Battlefront II\1.0', 'ExePath', InstallPath) then
    Result := InstallPath;

  // return only the path
  Result := ExtractFilePath(Result);
end;

Comment: Thanks for the info. But how exactly would I implement this? (Normally I'd be able to figure this kind of thing out myself but I'm still extremely new to the syntax and language itself.)
Comment: It's fairly simple. Edited.
Comment: >implying I know what I am doing in the very least --- No but um, I still don't understand; putting that at the end of my function brings up an error while compiling. One sec while I try a few things.
Comment: >nowhere near 4chan
>implying things at me -- edited to be extra explicit :)
Comment: @user3639133, you were close :-) You were just missing `;` at the end of the statement which prevented you from compiling.

Delete specific part of string


Importando e limpando diversos arquivos de textos em R

Question: Estou trabalhando em um conjunto de entrevistas que obtive de um banco de dados no meu trabalho, cada um em um arquivo de texto separado (um arquivo normal com uma transcrição em várias linhas).
Cada entrevista fará parte de data frame como uma variável. Os metadados de cada entrevista estão em um data frame diferente. Tenho que importar os textos para ele (uma entrevista inteira por linha). São mais de 700 arquivos de texto a serem importados.
A questão é que existem muitas linhas repetidas nos arquivos originais das entrevistas e, devido ao número de arquivos, importar um por um e usar x <- unique (x) está fora de questão. Eu escrevi o código abaixo para tentar importá-los:
files <- list.files(path="path/to/the/files", pattern="*.txt", full.names=TRUE)
folder <- "path/to/the/folder"
clean_text <- function(myfile){
  n <- length(myfile)
  myfile <- c(stringr::str_remove_all(myfile[-n], "[\n].*"),
              myfile[n])
  myfile <- unique(myfile)
  myfile <- paste0(myfile, collapse = "\n")
  myfile
}
texts <- ldply(clean_text(files),  read_file)

Mas, em vez de ter com algo assim:
Tudo o que tenho é o caminho para meus arquivos
View(texts)
V1
path/to/my/files/file1 path/to/my/files/file2

Estou aberto a qualquer solução.
Atualização
Aqui está um fluxo de trabalho do que eu tenho sido incapaz de fazer:

Ler 700 arquivos de texto de um diretório (esses são arquivos de
texto sem formatação com linhas separadas por \n)
Excluir as linhas
repetidas
Importa-los para R. Pode ser um vetor de uma coluna no
qual cada texto é uma variável.

Atualização 2
Consegui evoluir até ter o texto em uma lista, onde cada um é um character:
 str(teste)
List of 3
 $ : chr [1:205] "Hello " ...
 $ : chr [1:581] "hello little buns  ...
 $ : chr [1:849] "- Hello everybody," ...

Mas não consigo exportar cada um desses elementos da lista dentro de uma única célula de uma data frame. Já revirei o Google.
se alguém pudesse ajudar, ficaria grato.
Comment: Bem-vindo ao StackOverflow em Português! Infelizmente, esta pergunta não pode ser reproduzida por quem for tentar respondê-la. Por favor, [dê uma olhada neste link](https://pt.meta.stackoverflow.com/questions/6700/como-fazer-uma-pergunta-reproduz%C3%ADvel-em-r/6701#6701) e veja como fazer uma pergunta reproduzível em R. Assim, as pessoas que desejarem te ajudar conseguirão fazer isto da melhor maneira possível.
Comment: Olá, obrigado. mas eu não posso fazer upload dos dados pq eles pertencem a universidade em que trabalho, só posso usa-lo em citações de trabalho. Fora isso não tem muito mais que eu consiga mudar acima.
Comment: Então talvez a melhor opção seja contratar um consultor em R e assinar um contrato NDA com ele. Acho muito difícil encontrar alguma solução gratuita na internet com tão pouca informação a respeito do teu problema. Afinal, sequer sabemos qual é a estrutura dos arquivos texto, como, por exemplo, de onde sai a informação de nome, idade, gênero e entrevista dos sujeitos.
Comment: Eu não preciso de nada disso, so preciso colocar os 700 textos sem linhas duplicadas em um data frame, no qual cada variável (linha) é um dos textos. Todo o resto eu já consigo fazer
Comment: texto simples com linhas duplicatas -> célula da dataram (sem linha duplicada).
V1
texto1 sem linhas duplicadas
texto 2 sem linhas duplicas
texto 3 sem linhas duplicas
 Um por um é fácil fazer, não acho solução para 700 textos de uma vez
Comment: Oi Marcus, coloquei um update no Post. Se vc puder ajudar
Comment: Para obter linhas únicas, se estiver em linux ou com um sistema que tenha o comando unix/linux `awk`, `awk '!_[&0]++' infile > outfile` é mais rápido que o `unique` do R.
Comment: Oi.. muito obrigado! Tem como rodar em todos os arquivos de uma vez so?
Answer: Se percebi a pergunta (duvido que tenha) talvez o seguinte código consiga resolver o problema.
A função abaixo utiliza o comando unix/linux awk para remover as linhas de texto duplicadas. Os ficheiros limpos são escritos em ficheiros com o mesmo nome dos ficheiros de entrada mas com o prefixo pref = "out" nos seus nomes.
clean_text2 <- function(file, pref = "out"){
  out <- file.path(dirname(file), paste0(pref, basename(file)))
  args <- c("'!_[$0]++'", file, ">", out)
  system2("awk", args)
}

lapply(files, clean_text2)

Comment: Muito obrigado pela ajuda. Tentei rodar o código acima em um diretório com 3 arquivos (01.txt, 02.txt e 03.txt). Na seguinte sequência:
files_captions <- dir(path="/path/to/texts", full.names=TRUE)
folder_captions <- "/path/to/texts"
lapply(files_captions, clean_text2)
e recebi o seguinte erro:
sh: out/path/to/texts/01.txt: No such file or directory
sh: out/path/to/texts/02.txt: No such file or directory
sh: out/path/to/texts/03.txt: No such file or directory
alguma dica?
Comment: @user12774787 Veja agora com a modificação.
Comment: Obrigado novamente. O output desta vez foi:
> str(teste05)
List of 50
 $ : int 2
 $ : int 2
 $ : int 2
Answer: Obrigado a todos. Aparentemente consegui resolver o problema com a seguinte função. Fiz um teste numa amostra de 10 arquivos e deu certo. Depois testo com todos e dou um feedback.
files <- list.files(path="path/to/you/files", pattern="*.txt", full.names=TRUE)
import.and.clean <- function(myfiles){
  tmp <- lapply(myfiles, read_lines)
  tmp2 <- purrr::map(tmp, unique)
  tmp3 <- purrr::map_chr(tmp2, paste0, collapse = "\n")
  return(tmp3)
}
my.vector <- import.and.clean(files)


GWT set the visibility of Widget using CSS visibility property

Question: I have a GWT Button which contains the setVisible function.  The setVisible causes the button, or any widget, to disappear by setting its style to display: none via a "hidden" class included in the default styles.
myButton.setVisible(false); //Just sets style="display: none"

I need a clean method that would instead set visibility: hidden.  This is easily accomplished by setting the style attribute.
myButton.getElement().setAttribute("style", "visibility: "+((isVisible) ? "visible" : "hidden");

The problem with doing it this way is that it overrides the current style (not set by the class of course).  Does anybody know of a better way to do this?
Answer: You can do it this way:
myButton.getElement().getStyle().setVisibility(isVisible);

In general, if you want to change only one style, use .getElement().getStyle() instead of setting a style attribute.


Unable to store Hive Metastore server and hive shell

Question: I updated hive-site.xml with all of the required properties, but I am not able to understand from where this error is occurring. How do I connect metastore to hive shell and to start hive? Before updating meta-store properties hive shell is working properly.
Can anyone solve this error?

[hadoop@hduser conf]$ hive --service metastore
      Starting Hive Metastore Server
      17/01/02 18:01:01 WARN conf.HiveConf: HiveConf of name hive.metastore.local does not exist
      org.apache.thrift.transport.TTransportException: Could not create ServerSocket on address 0.0.0.0/0.0.0.0:9083.
        at org.apache.thrift.transport.TServerSocket.(TServerSocket.java:109)
        at org.apache.thrift.transport.TServerSocket.(TServerSocket.java:91)
        at org.apache.thrift.transport.TServerSocket.(TServerSocket.java:83)
        at org.apache.hadoop.hive.metastore.TServerSocketKeepAlive.(TServerSocketKeepAlive.java:34)
        at org.apache.hadoop.hive.metastore.HiveMetaStore.startMetaStore(HiveMetaStore.java:5968)
        at org.apache.hadoop.hive.metastore.HiveMetaStore.main(HiveMetaStore.java:5909)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
      Exception in thread "main" org.apache.thrift.transport.TTransportException: Could not create
  ServerSocket on address 0.0.0.0/0.0.0.0:9083.
        at org.apache.thrift.transport.TServerSocket.(TServerSocket.java:109)
        at org.apache.thrift.transport.TServerSocket.(TServerSocket.java:91)
        at org.apache.thrift.transport.TServerSocket.(TServerSocket.java:83)
        at org.apache.hadoop.hive.metastore.TServerSocketKeepAlive.(TServerSocketKeepAlive.java:34)
        at org.apache.hadoop.hive.metastore.HiveMetaStore.startMetaStore(HiveMetaStore.java:5968)
        at org.apache.hadoop.hive.metastore.HiveMetaStore.main(HiveMetaStore.java:5909)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:136)

hive-site.xml:
<code> <property>
    <name>hive.exec.scratchdir</name>
    <value>/tmp/hive</value>
    <description>HDFS root scratch dir for Hive jobs which gets created with write all (733) permission. For each connecting user, an HDFS scratch dir: ${hive.exec.scr$
  </property>
  <property>
    <name>hive.exec.local.scratchdir</name>
    <value>/tmp/${user.name}</value>
    <description>Local scratch space for Hive jobs</description>
  </property>
  <property>
    <name>hive.downloaded.resources.dir</name>
    <value>/tmp/${user.name}_resources</value>
    <description>Temporary local directory for added resources in the remote file system.</description>
  </property>
<property>
    <name>hive.scratch.dir.permission</name>
    <value>733</value>
    <description>The permission for the user specific scratch directories that get created.</description>
  </property>
 <property>
    <name>hive.metastore.warehouse.dir</name>
    <value>hdfs://localhost:54310/usr/local/hive</value>
    <description>
    Local or HDFS directory where Hive keeps table contents.
    </description>
</property>
<property>
  <name>hive.server2.thrift.port</name>
  <value>10000</value>
  <description>Port number of HiveServer2 Thrift interface.
  Can be overridden by setting $HIVE_SERVER2_THRIFT_PORT</description>
</property>

<property>
    <name>hive.metastore.local</name>
    <value>true</value>
    <description>
    Use false if a production metastore server is used.
    </description>
</property>
<property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://localhost:3306/metastore</value>
  </property>
  <property>
    <name>javax.jdo.option.ConnectionUserName</name>
    <value>hiveuser</value>
  </property>
 <property>
    <name>javax.jdo.option.ConnectionPassword</name>
    <value>hive</value>
  </property>
  <property>
    <name>javax.jdo.option.ConnectionDriverName</name>
    <value>com.mysql.jdbc.Driver</value>
  </property>
  <property>
    <name>datanucleus.autoCreateSchema</name>
    <value>false</value>
  </property>
  <property>
    <name>datanucleus.fixedDatastore</name>
    <value>true</value>
  </property>

<property>
    <name>datanucleus.autoStartMechanism</name>
    <value>SchemaTable</value>
  </property>
  <property>
    <name>hive.metastore.uris</name>
    <value>thrift://192.168.122.1:9083</value>
  </property>
  <property>
    <name>hive.metastore.schema.verification</name>
    <value>false</value>
  </property>
</code>
Comment: value of `hive.metastore.uris` isn't : `thrift://localhost:9083` ?
Comment: you can either give localhost or ipaddress
Answer: it seems like port 9083 is busy or your metastore is not running as service try some another port


Como colocar uma palavra inteira dentro de um char?

Question: Como    faço para   colocar   uma palavra com letras    e    números    dentro    de    um     char?    Por exemplo    colocar    nele    a    placa    de    um  carro    ABC-1234.
char a = ABC1234;
char b = DFG0000;

printf("1ª placa %s\n",a);
printf("2ª placa %s\n",b);

Dá erro no código. Como eu procedo?
Comment: Para podermos te ajudar, [forneça um código Mínimo, Completo e Verificável](https://pt.stackoverflow.com/help/mcve).
Comment: blz vou alterar a pergunta
Comment: Pelo que você está dizendo, parece ser o caso de [marcar uma resposta como aceita](http://meta.pt.stackoverflow.com/questions/1078/). Aqui não escrevemos "resolvido" na questão. Se tem uma resposta que realmente te ajudou, marque-a como aceita. Se chegou sozinho à solução, poste a solução como resposta. Assim o conteúdo fica mais organizado e fácil de ser encontrado futuramente por outras pessoas com problemas parecidos.
Answer: Conhece a diferença entre caracter e string? O tipo char é um caracter, portanto aceita apenas informação escalar. Você quer uma informação vetorial, deveria usar uma string para esse caso. No caso, em C, isso seria algo como char placa_a[] = "ABC0123";
Aproveitando também, o parâmetro %s do printf não espera receber uma variável escalar, mas um ponteiro de caracteres. Você obterá resultados estranhos caso sua aplicação não feche grosseiramente com uma falha de segmentação para o uso que você deu.

Outro ponto: strings constantes em C se declaram entre aspas. Portanto, se eu quiser inicializar a variável chamada placa_a com uma palavra, eu precisa fazer:
placa_a = "ABC1234";

Essa inicialização pode ser feita para a definição de placa_a como um ponteiro como também como sendo um vetor.
Então, as opções seriam:
// inicializando um vetor
char placa_a_vetor[] = "ABC0123";
// inicializando o ponteiro junto da declaração
char *placa_a_ptr = "ABC0123";

// primeiro declarando, depois inicializando
char *placa_a_ptr_delayed;
placa_a_ptr_delayed = "ABC0123";

Leitura recomendada:

Na prática, qual a utilidade dos ponteiros em C?
Comentário distinguindo ponteiro e referência
Qual a diferença em instanciar, inicializar e declarar uma variável?
Comment: muito obrigado pela ajuda
Answer: Cara basicamente você não pode fazer isso com um char "normal", uma variável deste tipo é feita para armazenar apenas um caractere, logo para você poder armazenar uma cadeia de caracteres (string) em uma variável é necessário que você utilize uma string, esta que seria equivalente a um vetor (array) do tipo char em C.
Para declarar uma string é muito fácil, você primeiro necessita ter em mente quantas letras a palavra que você deseja armazenar tem, após isso é só você declarar a variável igual você declararia um vetor, só que utilizando char é claro, é muito importante ressaltar que no final de toda as string vai o caracterizar '\0', este simboliza que sua string chegou ao final, logo quando for fazer a contagem de quantas letras a palavra que deseja armazenar tem, para poder criar a string, lembre-se de sempre somar um a ais no resultado final, este que será reservado ao '\0'.
ex:
#include <stdio.h>

int main ()
{
    char strNumPlaca[50] = "ABC - 03257";

    printf("%s", strNumPlaca); /*   use %s ao invés de %c, pois isso simboliza
                                    que você esta utilizando uma string.    */

    return 0;
}

Para ajudar na sua compreensão aqui esta um link:
http://linguagemc.com.br/string-em-c-vetor-de-caracteres/
Comment: ss, mas eu achei que iria ficar muita coisa para explicar para ele, então de inicio isso era suficiente
Comment: Você não precisaria declarar o tamanho da string `strNumPlaca` para esse caso em específico. O compilador C fará o ajuste automaticamente para você, de modo que ela seja de tamanho 11 (3 letras, 4 números, 3 caracteres de formatação e o terminador nulo). Claro, se for a ideia reutilizar essa string em um contexto que se necessite 49 caracteres e o terminador faz sentido declarar o tamanho...
Answer: Sobre sua questão tem 2 pontos a entender, vamos lá.
1º Para a declaração de um char com alguns caracteres, sejam eles especiais, números, o que você achar melhor, é necessário o uso de chaves [] e um número, ou variável (se forem N valores, e se o valor de N já tiver sido escolhido), varia de acordo com a necessidade, e ainda precisa colocar seus caracteres dentro de aspas duplas, assim char palavra[3] = "sim";.
2º Se você quer concatenar uma string, utiliza-se a função strcat, que funciona com a biblioteca string.h.
Espero ter ajudado