How can a Function be a Superposition of Infinite Functions?

Question: In learning about Fourier series, they were presented to me (informally) as a way to 'break down' a function into a series of discrete 'constituent' functions. This makes perfect sense to me. However, in a Fourier transform, they seem to be broken down into an infinite number of functions - my question is, how is this possible? In summing this infinite number of constituent functions (to synthesize the original function), won't you end up with something that has infinite amplitude?
Comment: Fair enough, but the main idea is that convergence of series and integrals occurs when the terms that are accumulated decay fast enough.  And this is true in both the countable and uncountable cases.  Not all functions have Fourier transforms, because the integral does not always converge.  A simple *sufficient* condition that is used in practice is that the Fourier transform exists for functions that are absolutely integrable and of bounded variation.
Comment: What is the sum of $\sum_{i > 0} 2^{-i}$?
Comment: Perhaps I should've rephrased my question - I understand that it may be composed of an infinite number of **discrete** functions (so a countably infinite number). However, I'm more confused as to how there can be an **uncountable infinity** of constituent functions.
Comment: Really, there is no such thing as an infinite sum. The so-called infinite sums are limits of finite sums. Without a topology or some other notion of closeness, such things cannot be defined.
Answer: The heuristic short answer is that the integral used in the Fourier transform assigns infinitesimally small weight to each of the functions added up (just as we imagine an integral as an infinite sum of infinitesimal strips that add up to a finite area).
One possible longer answer is that one sees this occur when we try to "derive" the Fourier transform from Fourier series. Recall that if $f$ is a (sufficiently nice) complex-valued function that is periodic on an interval of length $L$, we can take the Fourier coefficients for $f$ as
$$ f_k = \int_{-L/2}^{L/2} e^{-2\pi i k x/L} f(x) \, dx, $$
and then Fourier's Theorem states
$$ f(x) = \frac{1}{L}\sum_{k=-\infty}^{\infty} f_k e^{2\pi i kx/L}. $$
My impression is you're happy with this idea, although the normalisation of the coefficients I chose looks a bit strange at the moment.
Now, we want to see what happens if we let $f$ have longer and longer period. We first make a notational adjustment: let $\omega=k/L$, and let $\tilde{f}(\omega) = \tilde{f}(k/L) = f_k $. At the moment $\tilde{f}(\omega)$ is a function a discrete set of values, but the distance between neighbouring elements of this set is $1/L$, so it gets smaller and smaller. So now we have
$$ \tilde{f}(\omega) = \int_{-L/2}^{L/2} e^{-2\pi i\omega x} f(x) \, dx. $$
No drama here: taking $L \to \infty$ just turns this into $\int_{-\infty}^{\infty} e^{-2\pi i\omega x} f(x) \, dx $, which is of course the Fourier transform. Conceptually, this isn't any different from the Fourier series integral: it's just that we have a different variable. On the other hand, the other equation has become
$$ f(x) = \frac{1}{L}\sum_{\omega L=-\infty}^{\infty} \tilde{f}(\omega) e^{2\pi i \omega x} = \frac{1}{L}\sum_{k=-\infty}^{\infty} \tilde{f}\left(\frac{k}{L}\right) e^{2\pi i k x/L}. $$
Ah, but this is a Riemann sum! As $L \to \infty$, it tends to $\int_{-\infty}^{\infty} e^{2\pi i \omega x}\tilde{f}(\omega)  d\omega $, which is of course the inverse Fourier integral. (Handling the infinite interval here is a bit tricky, but this makes total sense if $\tilde{f}(\omega)$ was only nonzero on a finite interval, where we would see a normal sort of finite Riemann sum apply.)
The moral of the story is that the $1/L$ in the Fourier sum formula turns out to be vital in decreasing the weight of each term in the series in just the right way to turn it into the Riemann sum of an integral, and this is one not-particularly-rigorous way of deriving the form of the inverse Fourier integral.
Comment: Yes, $f$ eventually has such a long period that you can't tell it's periodic. It's helpful to remember that long period $\implies$ closely spaced possible frequencies: it's the same as the rule that scaling $x$ leads to the inverse scaling in $\omega$.
Comment: This may or may not help: https://en.wikipedia.org/wiki/Characteristic_function_(probability_theory)
Comment: Both Fourier series and integrals work best when talking about "convergence in mean square" (i.e $f_n \to f$ if $\int \lvert f - f_n \rvert^2 \to 0$). This is much weaker than uniform (or even pointwise) convergence in general, which is what you need when talking about specific values of a function. Remember that even a discrete Fourier series does not necessarily sum to the value of the $f$ at a given point (if $f$ is discontinuous, and the series converges, it takes the average of the points on both sides).
Comment: Thanks, that helped a lot! Just to clarify - when you start taking the limit of L to infinity, you're 'stretching' the bounds so that the function does not have to periodic?
Comment: After thinking on this a while, it seemed to me that the Fourier transform of a function is analogous to a continuous probability distribution (i.e. does it mean anything to say that $F(\omega) = 3$ other than to compare it to the value of F at another location?), while a Fourier series is like a discrete probability distribution. Is this correct?
Comment: I wasn't quite able to understand it (I haven't studied too much probability in depth), but what I took from it is that the Fourier transform of a density function somewhat reveals the 'identity' of that function? Does this imply that how I thought of the transform function is correct?


how to handle form authentication in IE7&IE8

Question: Hi I am using IE7 and IE8 browser for running web appliction. I have login in the web application go on the next page. if have copy the url of the next page, and open new browser and paste url, then open directly next page. I mean my form authentication is not working. please help how to handle this issue.
Comment: I like how you're blaming IE for this
Comment: Rephrase your question, it makes no sense.
Answer: I don't know enough about asp.net to give exact code, but your login page should create a new session if it isn't already created.
When the logic behind the authentication form verifies the username/password, it should set a session variable to mark the user as logged in.
Pages which require login should then check for that session variable, and redirect to the login page if not set.
Hope that helps!
Comment: @Aman - forms authentication is done by a cookie stored in the `browser` (unless you create a persistent one). So if you log in with IE8, then open say IE7, you are not automatically logged in. This has nothing to do with IE, it's how cookie-based authentication works.
Comment: I have done all these thing on the page load. I mean check sessiion null on the page load but problem is in IE7 and 8 session main in different browser on the same machine.


It is safe to store custom information in the data field of a commerce_order or commerce_line_item entity?

Question: I have this
 line_item = commerce_line_item_load($form_state['line_item']->line_item_id);
            dpm($line_item);
            $line_item->data['data_custom']['name'] = $form_state['values']['name'];
            $line_item->data['data_custom']['phone'] = $form_state['values']['phone'];
entity_save('commerce_line_item', $line_item);

It is save? In theory I'm only the only one to work with this data, other modules should not even care about that being there, right?
Comment: They "should" not, correct. You can't blindly guarantee that of course, modules sometimes misbehave. In theory you should be fine
Comment: Yes, ty for the response
Answer: Yes, you can do that.
That information is commonly used to store context or other information. For instance, you can use the $order->data to store transaction IDs or other relevant information that you might want to use later on in the lifecycle of the order. In some cases, $line_item->data might store remote keys or other information related to that line item specifically.
Just be very careful that you don't store something in there that you wouldn't want to otherwise store in your database: credit card numbers or other things that you wouldn't want if your security were ever compromised or a database backup fell into the wrong hands.
Comment: Ty for your response :)


How to find maximum likelihood estimates of an integer parameter?

Question: H.W. Question:

$x_1,x_2,\ldots,x_n$ are independent Gaussian variables with mean $\mu$ and variance $\sigma^2$. Define $y = \sum_{n=1}^{N} x_n$ where $N$ is unknown. We are interested in estimation of $N$ from $y$.

a. Given  $\hat N_1 = y/\mu$ determine its bias and variance.
b. Given $\hat N_2 = y^2/\sigma^2$ determine its bias and variance.
Ignoring the requirement for $N$ to be an integer
c. Is there an efficient estimator (look at both $\mu = 0$ and $\mu \ne 0$)?
d. Find the maximum likelihood estimate of $N$ from $y$.
e. Find CRLB of $N$ from $y$.
f. Does the mean squared error of the estimators $\hat N_1,\hat N_2$ attain CRLB when $N\to \infty$?

If anyone could direct me to the solution of the following problem it would be great.
Thanks,
Nadav
Comment: Because $N$ is integral, you can't (directly) use Calculus to find the minimum.  If this is your obstacle, then please present your work in your question so we can focus on where you actually need help.
Comment: If $X_i$ are normal, then $Y = \sum_I Xi$ and $\hat N = Y/\mu$ are normal. What are mean and variance of  $\hat N\,?$ That should finish the problem. // In practice, I suppose it makes sense to round $\hat N$ to an integer. That could make a slight difference in mean and variance. You could find out how much difference by simulation.
Comment: What is the distribution of $Y = \sum_i X_i\,?$
Comment: It doesn't say. I suppose it will also be distributed as Gaussian variable since it's a sum of Gaussian variables
Comment: Wouldn't the $Var(N_{estimated})$ will be the $Var(y)/\mu$? Same logic for the mean
Comment: In general, given $E(X)$ and $Var(X),$ what are $E(aX)$ and $Var(aX)\,?$
Comment: $aE(x)$ and $aVar(x)$
Comment: Since you mentioned you have learned about Maximum Likelihood, then surely you have written an expression for the likelihood of $N:$ what did you obtain?  What has prevented you from applying ML to this expression to find an estimate of $N$?
Comment: @whuber I tried applying as if it were the mean or the variance. taking the density function -> take the log of that function -> differentiate with respect to N. my problem is that i'm left with only constants, hence no ML estimate, i'm struggling with that result as you imply.
Comment: @whuber I added it in my question
Answer: You started well by writing down an expression for the likelihood.  It is simpler to recognize that $Y,$ being the sum of $N$ independent Normal$(\mu,\sigma^2)$ variables, has a Normal distribution with mean $N\mu$ and variance $N\sigma^2,$ whence its likelihood is
$$\mathcal{L}(y,N) = \frac{1}{\sqrt{2\pi N\sigma^2}} \exp\left(-\frac{(y-N\mu)^2}{2N\sigma^2}\right).$$
Let's work with its negative logarithm $\Lambda = -\log \mathcal{L},$ whose minima correspond to maxima of the likelihood:
$$2\Lambda(N) = \log(2\pi) + \log(\sigma^2) + \log(N) + \frac{(y-N\mu)^2}{N\sigma^2}.$$
We need to find all whole numbers that minimize this expression.  Pretend for a moment that $N$ could be any positive real number.  As such, $2\Lambda$ is a continuously differentiable function of $N$ with derivative
$$\frac{d}{dN} 2\Lambda(N) = \frac{1}{N} - \frac{(y-N\mu)^2}{\sigma^2N^2} - \frac{2\mu(y-N\mu)}{N\sigma^2}.$$
Equate this to zero to look for critical points, clear the denominators, and do a little algebra to simplify the result, giving
$$\mu^2 N^2 + \sigma^2 N -y^2 = 0\tag{1}$$
with a unique positive solution (when $\mu\ne 0$)
$$\hat N = \frac{1}{2\mu^2}\left(-\sigma^2 + \sqrt{\sigma^4 + 4\mu^2 y^2}\right).$$
It's straightforward to check that as $N$ approaches $0$ or grows large, $2\Lambda(N)$ grows large, so we know there's no global minimum near $N\approx 0$ nor near $N\approx \infty.$  That leaves just the one critical point we found, which therefore must be the global minimum.  Moreover, $2\Lambda$ must decrease as $\hat N$ is approached from below or above.  Thus,

The global minima of $\Lambda$ must be among the two integers on either side of $\hat N.$

This gives an effective procedure to find the Maximum Likelihood estimator: it's either the floor or the ceiling of $\hat N$ (or, occasionally, both of them!), so compute $\hat N$ and simply choose which of these integers makes $2\Lambda$ smallest.
Let's pause to check that this result makes sense.  In two situations there is an intuitive solution:

When $\mu$ is much greater than $\sigma$, $Y$ is going to be close to $\mu,$ whence a decent estimate of $N$ would simply be $|Y/\mu|.$  In such cases we may approximate the MLE by neglecting $\sigma^2,$ giving (as expected) $$\hat N = \frac{1}{2\mu^2}\left(-\sigma^2 + \sqrt{\sigma^4 + 4\mu^2 y^2}\right) \approx \frac{1}{2\mu^2}\sqrt{4\mu^2 y^2} = \left|\frac{y}{\mu}\right|.$$
When $\sigma$ is much greater than $\mu,$ $Y$ could be spread all over the place, but on average $Y^2$ should be close to $\sigma^2,$ whence an intuitive estimate of $N$ would simply be $y^2/\sigma^2.$  Indeed, neglecting $\mu$ in equation $(1)$ gives the expected solution $$\hat N \approx \frac{y^2}{\sigma^2}.$$

In both cases, the MLE accords with intuition, indicating we have probably worked it out correctly.  The interesting situations, then, occur when $\mu$ and $\sigma$ are of comparable sizes.  Intuition may be of little help here.

To explore this further, I simulated three situations where $\sigma/\mu$ is $1/3,$ $1,$ or $3.$  It doesn't matter what $\mu$ is (so long as it is nonzero), so I took $\mu=1.$  In each situation I generated a random $Y$ for the cases $N=2,4,8,16,$ doing this independently five thousand times.
These histograms summarize the MLEs of $N$.  The vertical lines mark the true values of $N$.

On average, the MLE appears to be about right.  When $\sigma$ is relatively small, the MLE tends to be accurate: that's what the narrow histograms in the top row indicate.  When $\sigma \approx |\mu|,$ the MLE is rather uncertain.  When $\sigma \gg |\mu|,$ the MLE can often be $\hat N=1$ and sometimes can be several times $N$ (especially when $N$ is small).  These observations accord with what was predicted in the preceding intuitive analysis.

The key to the simulation is to implement the MLE.  It requires solving $(1)$ as well as evaluating $\Lambda$ for given values of $Y,$ $\mu,$ and $\sigma.$  The only new idea reflected here is checking the integers on either side of $\hat N.$  The last two lines of the function f carry out this calculation, with the help of lambda to evaluate the log likelihood.
lambda <- Vectorize(function(y, N, mu, sigma) {
  (log(N) + (y-mu*N)^2 / (N * sigma^2))/2
}, "N") # The negative log likelihood (without additive constant terms)

f <- function(y, mu, sigma) {
  if (mu==0) {
    N.hat <- y^2 / sigma^2
  } else {
    N.hat <- (sqrt(sigma^4 + 4*mu^2*y^2) - sigma^2) / (2*mu^2)
  }
  N.hat <- c(floor(N.hat), ceiling(N.hat))
  q <- lambda(y, N.hat, mu, sigma)
  N.hat[which.min(q)]
} # The ML estimator

Comment: I could not have asked for a better explanation. Thank you very much, you literally covered everything!
Comment: I took the derivative of the negative log likelihood function as you suggested and attempted to obtain the following expression: $C(N)\times(g(y)-N)$ I managed to do that on $\mu = 0$ but not on $\mu != 0$ this is why we had a unique positive solution on  $\mu != 0$?
Comment: I don't think so.  I find it easier to reparameterize the problem in terms of $\theta=1/N,$ because then the derivative of the log likelihood is a quadratic function of $\theta.$
Comment: now I need to tell whether an efficient estimator exists(for $\mu != 0$ and $\mu = 0$). I know that if an estimator is unbiased and answers the CRLB than its efficient. I know its unbiased, but taking the second derivative of the L function seems to get me no where.
Comment: Ignore the fact that $N$ is integral: that is, allow the estimate to be the global minimum of the negative log likelihood function.  Go on from there.
Answer: The method whuber has used in his excellent answer is a common optimisation "trick" that involves extending the likelihood function to allow real values of $N$, and then using the concavity of the log-likelihood to show that the discrete maximising value is one of the discrete values on either side of a continuous optima.  This is one commonly used method in discrete MLE problems involving a concave log-likelihood function.  Its value lies in the fact that it is usually possible to get a simple closed-form expression for the continuous optima.
For completeness, in this answer I will show you an alternative method, which uses discrete calculus using the forward-difference operator.  The log-likelihood function for this problem is the discrete function:
$$\ell_y(N) = -\frac{1}{2} \Bigg[ \ln (2 \pi) + \ln (\sigma^2) + \ln (N) + \frac{(y-N\mu)^2}{N\sigma^2} \Bigg]
\quad \quad \quad
\text{for } N \in \mathbb{N}.$$
The first forward-difference of the log-likelihood is:
$$\begin{equation} \begin{aligned}
\Delta \ell_y(N)
&= -\frac{1}{2} \Bigg[ \ln (N+1) - \ln (N) + \frac{(y-N\mu - \mu)^2}{(N+1)\sigma^2} - \frac{(y-N\mu)^2}{N\sigma^2} \Bigg] \\[6pt]
&= -\frac{1}{2} \Bigg[ \ln \Big( \frac{N+1}{N} \Big) + \frac{N(y-N\mu - \mu)^2 - (N+1)(y-N\mu)^2}{N(N+1)\sigma^2} \Bigg] \\[6pt]
&= -\frac{1}{2} \Bigg[ \ln \Big( \frac{N+1}{N} \Big) + \frac{[N(y-N\mu)^2 -2N(y-N\mu) \mu + N \mu^2] - [N(y-N\mu)^2 + (y-N\mu)^2]}{N(N+1)\sigma^2} \Bigg] \\[6pt]
&= -\frac{1}{2} \Bigg[ \ln \Big( \frac{N+1}{N} \Big) - \frac{(y + N \mu)(y-N\mu) - N \mu^2}{N(N+1)\sigma^2} \Bigg]. \\[6pt]
\end{aligned} \end{equation}$$
With a bit of algebra, the second forward-difference can be shown to be:
$$\begin{equation} \begin{aligned}
\Delta^2 \ell_y(N)
&= -\frac{1}{2} \Bigg[ \ln \Big( \frac{N+2}{N} \Big) + \frac{2 N (N+1) \mu^2 + 2(y + N \mu)(y-N\mu)}{N(N+1)(N+2)\sigma^2} \Bigg] < 0. \\[6pt]
\end{aligned} \end{equation}$$
This shows that the log-likelihood function is concave, so its smallest maximising point $\hat{N}$ will be:
$$\begin{equation} \begin{aligned}
\hat{N}
&= \min \{ N \in \mathbb{N} | \Delta \ell_y(N) \leqslant 0 \} \\[6pt]
&= \min \Big\{ N \in \mathbb{N} \Big| \ln \Big( \frac{N+1}{N} \Big) \geqslant \frac{(y + N \mu)(y-N\mu) - N \mu^2}{N(N+1)\sigma^2} \Big\}.
\end{aligned} \end{equation}$$
(The next value will also be a maximising point if and only if $\Delta \ell_y(\hat{N}) = 0$.)  The MLE (either the smallest, or the whole set) can be programmed as a function via a simple while loop, and this should be able to give you the solution pretty quickly.  I will leave the programming part as an exercise.
Comment: I appreciate your time and the thorough explanation. Thank you @Ben !
Answer: Comment: Here is a brief simulation in R for $\mu = 50, \sigma = 3,$
which should be accurate to 2 or three places, approximating the
mean and SD of $Y.$ You should be able to find $E(Y)$ and $Var(Y)$
by elementary analytic methods as indicated in my earlier Comment.
If we had $N = 100$ then $E(\hat N)$ seems unbiased for $N.$
N = 100;  mu = 50;  sg = 3
y = replicate( 10^6, sum(rnorm(N, mu, sg))/mu )
mean(y);  sd(y)
[1] 99.99997
[1] 0.6001208
N.est = round(y);  mean(N.est);  sd(N.est)
[1] 99.9998
[1] 0.6649131

Comment: If you would like to understand the potential for bias, don't use large $N:$ try a small value.  $N=1$ is especially interesting :-).  So is the case $\mu=0.$
Comment: Thank you Bruce!
Comment: May I ask one more question? Now i'm asked if there is an efficient estimator regarding what I found, it also states that we now ignore the requirement for N to be an integer. what does it mean that it is not an integer anymore? how would I find the log Likelihood for such a case?


SonataMediaBundle Usage with custom entities

Question: I'm using Symfony2 with Sonata bundles (Sonata-Admin and Sonata-Media) to develop my CMS project.
I setup my admin classes for my custom bundle and it's working well. I need to attach images into my entities and view them in their user pages. But I have a problem with SonataMediaBundle to use in my custom entities. I'm trying to add a field to AdminController of my entity class and also create a manyToOne relationship in my entity definition.
I never got it work and generally gives "Entity was not found" Exception (Doctrine\ORM\EntityNotFoundException class)
I couldn't find an article except on SonataMedia Documentation and couldn't solve this problem. Is anyone know a good article to read and understand the whole concept of SonataMedia Bundle?
Some more information about my code is below:
MyEntity.orm.yml
PRJ\Bundle\PRJBundle\Entity\MyEntity:
type: entity
table: my_table
fields:
    id:
        id: true
        type: integer
        unsigned: false
        nullable: false
        generator:
            strategy: IDENTITY

# Other fields eliminated

manyToOne:
    picture:
        targetEntity: Application\Sonata\MediaBundle\Entity\Media
        joinColumns:
                name: Picture_id
                referencedColumnName: id
        orphanRemoval: false
lifecycleCallbacks: {  }

Actually this code is working on both Admin panel and user pages but I couldn't make it work on admin pages when admin user is editing the record or entering new record.
Also please correct me if I'm wrong, I'm assuming that I can generate an admin class for my custom entity that is attaching pictures. I'll add a field and define it as foreign key to media__media table in my database, and create necessary definitions on my Entities. At last I will be able to upload new pictures via SonataMediaBundle when creating new entities. Admin User will enters entity details and presses the upload button and chooses a picture, upload button works with SonataMedia bundle and uploads image to SonataMedia bundle's table also the new record will be created in my bundle's table and associated with newly created media.
I hope I could described my problem well and thank you.
Answer: If you're using custom entity classes with SonataMediaBundle, you need to specify them in config.yml:
sonata_media:
    class:
        media: MyVendor\MediaBundle\Entity\Media
        gallery: MyVendor\MediaBundle\Entity\Gallery
        gallery_has_media: MyVendor\MediaBundle\Entity\GalleryHasMedia


Could not find a test logger with AssemblyQualifiedName, URI or FriendlyName 'nunit'

Question: I am trying create a nunit test results xml file and attach it to a test run of my build in dev ops. I have the NUnit3TestAdapter.3.13.0 package installed in my test project and reference this in console options of the VS test task (test task is version 2).
packages.config:

I have tried various combinations in the "other console options" field including "/TestAdapterPath:." or not stating the test adapter path at all. I have also tried moving the test adapter part into the "path to custom test adapters" field as "$(Build.SourcesDirectory)\packages\NUnit3TestAdapter.3.13.0\build\net35".
However, each time the tests task returns the error:
<code>Microsoft (R) Test Execution Command Line Tool Version 16.9.1
Copyright (c) Microsoft Corporation.  All rights reserved.
vstest.console.exe "C:\VSTSBuild\agentB\_work\2\s\SomeService.Tests\bin\SomeService.Tests.dll"
/Settings:"C:\VSTSBuild\agentB\_work\_temp\41oiukcwga4.tmp.runsettings"
/EnableCodeCoverage
/Logger:"trx"
/TestAdapterPath:"C:\VSTSBuild\agentB\_work\2\s"
/logger:nunit /TestAdapterPath:C:\VSTSBuild\agentB\_work\2\s\packages\NUnit3TestAdapter.3.13.0\build\net35
Starting test execution, please wait...
##[error]Could not find a test logger with AssemblyQualifiedName, URI or FriendlyName 'nunit'.
</code>
Answer: That same error was solved on my end by adding a reference to this NuGet package:
NunitXml.TestLogger
Its description is:
Xml logger for NUnit v3 compliant xml report when test is running with "dotnet test" or "dotnet vstest".
Comment: While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference.  Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/29895845)
Comment: I have been running this as a PR build. The only changes in my PR are adding test categories:
`[TestFixture(Category = "UnitTest")]`

and the NunitXml.testLogger package - which has made changes in my packages.config:
``

and csproj of my test project:
``
Comment: Would it make a difference if I checked in the NunitXml.TestLogger, then edited the build as in my original screen shot and then run a build (ie not from a PR)?
Answer: I encounter the same issue for Xunit. You need to add package XunitXml.TestLogger


Python xml.etree - how to search for n-th element in an xml with namespaces?

Question: EDIT
Looks like I wasn't clear enough below. The problem is that if I use node positions (eg. /element[1]) and namespaces, xpapth expressions do not work in xml.etree. Partially I found my answer - lxml handles them well, so I can use it instead of xml.etree, but leaving the question open for the future reference.
So to be clear, problem statement is:
XPath expressions with positions and namespaces do not work in xml.etree. At least not for me.
Original question below:
I'm trying to use positions in xpath expressions processed by findall function of xml.etree.ElementTree.Element class. For some reason findall does not work with both namespaces and positions.
See the following example:
Works with no namespaces
>>> from xml.etree import ElementTree as ET
>>> xml = """
...             <element>
...                 <system_name>TEST</system_name>
...                 <id_type>tradeseq</id_type>
...                 <id_value>31359936123</id_value>
...             </element>
...         """
>>> root = ET.fromstring(xml)
>>> list = root.findall('./system_name')
>>> list
[<Element 'system_name' at 0x0000023825CDB9F0>]
>>> list[0].tag
'system_name'
>>> list[0].text
'TEST'
###Here is the lookup with position - works well, returns one element
>>> list = root.findall('./system_name[1]')
>>> list
[<Element 'system_name' at 0x0000023825CDB9F0>]
>>> list[0].text
'TEST'

Does not work with namespaces
>>> xml = """
...             <element xmlns="namespace">
...                 <system_name>TEST</system_name>
...                 <id_type>tradeseq</id_type>
...                 <id_value>31359936123</id_value>
...             </element>
...         """
>>> root = ET.fromstring(xml)
>>> list = root.findall(path='./system_name', namespaces={'': 'namespace'})
>>> list
[<Element '{namespace}system_name' at 0x0000023825CDBD60>]
>>> list[0].text
'TEST'
###Lookup with position and namespace: I'm expecting here one element, as it was in the no-namespace example, but it returns empty list
>>> list = root.findall(path='./system_name[1]', namespaces={'': 'namespace'})
>>> list
[]

Am I missing something, or is this a bug? If I should use any other library that better processes xml, could you name one, please?
Comment: You need to use an actual prefix. It does not work with an empty string in the `namespaces` dictionary: `root.findall(path='./x:system_name', namespaces={'x': 'namespace'})`
Answer: It works as in the doc defined:
Please try this syntax:
ns = {'xmlns': 'namespace'}

for elem in root.findall(".//xmlns:system_name", ns):
    print(elem.tag)

Remark:
even with empty key, but I assume this is not the correct usage.
ns = {'': 'namespace'}

for elem in root.findall(".//system_name", ns):
    print(elem.tag)

If you have only one namespace definition, you can also use {*}tag_name:
for elem in root.findall(".//{*}system_name"):
    print(elem.tag)

Also postional search of the child works fine:
ns = {'': 'namespace'}

for elem in root.findall("./system_name", ns):
    print(elem.tag)

Comment: It works when you're not using positions in the xpath. With positions it stops:
>>> list = root.findall(path='./system_name[1]', namespaces={'': 'namespace'})
>>> list
[]
Comment: No, it works on my environment, 3.11, remove `xpath =`


/etc/resolv.conf is getting overwritten

Question: I have set up my own bind9 DNS server and put into my /etc/resolv.conf
nameserver 127.0.0.1
domain mydomain.local

and put the same content into /etc/resolvconf/resolv.conf.d/head
still the dns fails once in a while and additional information (the ones from my hoster) are magically written into the etc/resolv.conf. Am I missing any service how manages this file and conflicts with bind9?
Answer: If you're using DHCP, the DHCP server can tell you what resolvers to use. If you want to manually configure resolvers, I'd suggest manually configuring IP addresses as well. Otherwise, assuming the filesystem supports it, set the /etc/resolv.conf file immutable. (chattr +i on Linux.)
Comment: sure, I do not use any DHCP and even set, but I will try the immutable

/etc/resolv.conf is getting overwritten


Scheduled task not created with silent installation

Question: I've created a setup file using InstallShield Limited Edition, and I have a custom action that creates a scheduled task in the "After Setup Completed Success dialog" custom actions folder for installation:
schtasks.exe /create /xml "[INSTALLDIR]\task definition.xml" /tn "My Task"

If I run the setup as administrator, or I start it from a system context, everything goes fine.
However, if I run it silently, with the /S /v/qn command line parameters, everything works except for the task, which is not created.
How can I create the task also with a silent installation?
Answer: Lots of reason this could happen.  If for example you have this running as a custom action in your UI sequence,  the UI sequence doesn't run under a silent install.  You would need to put it in the Execute sequence.
Comment: I moved the custom action under "After Register Product" and now it works, thanks!


How can I stop endlessly repeating redis & sidekiq log at development.log

Question: ruby on rails v126.96.36.199 + sidekiq v6.2.1 + redis + redis.rb(4.2.5)
I installed redis with homebrew.
/usr/local/etc/redis.conf is not changed.(after installed)
When I start my rails process with foreman, Redis log like below is repeating endlessly. More weird thing is this is logging at development.log file. not redis.log or sidekiq .log file.
How can I stop this?
<code>  Redis (2114.20ms) BRPOP queue:default 2
  Redis (2114.77ms) BRPOP queue:default 2
  Redis (0.99ms) MULTI >> INCRBY stat:processed 0 >> INCRBY stat:processed:2021-04-08 0 >> EXPIRE stat:processed:2021-04-08 157680000 >> INCRBY stat:failed 0 >> INCRBY stat:failed:2021-04-08 0 >> EXPIRE stat:f                ailed:2021-04-08 157680000 >> UNLINK MacBook-Pro.local:11781:d7d3324224d3:workers >> EXPIRE MacBook-Pro.local:11781:d7d3324224d3:workers 60 >> EXEC
  Redis (0.28ms) PING
  Redis (0.57ms) MULTI >> SADD processes MacBook-Pro.local:11781:d7d3324224d3 >> EXISTS MacBook-Pro.local:11781:d7d3324224d3 >> HMSET MacBook-Pro.local:11781:d7d3324224d3 info {"hostname":"MacBook-Pro.local","                started_at":1617864827.601102,"pid":11781,"tag":"appname","concurrency":10,"queues":["default"],"labels":[],"identity":"MacBook-Pro.local:11781:d7d3324224d3"} busy 0 beat 1617864892.789145 rtt_us 442 quiet true rss 97384 >> EXPIRE MacBook-Pro.local:11781:d7d3324224d3 60 >> RPOP MacBook-Pro.local:11781:d7d3324224d3-signals >> EXEC
  Redis (0.55ms) SREM processes MacBook-Pro.local:11781:d7d3324224d3 >> UNLINK MacBook-Pro.local:11781:d7d3324224d3:workers
  Redis (1.07ms) INFO
  Redis (3.99ms) MULTI >> INCRBY stat:processed 0 >> INCRBY stat:processed:2021-04-08 0 >> EXPIRE stat:processed:2021-04-08 157680000 >> INCRBY stat:failed 0 >> INCRBY stat:failed:2021-04-08 0 >> EXPIRE stat:f                ailed:2021-04-08 157680000 >> UNLINK MacBook-Pro.local:11856:14ee4c3dc8a2:workers >> EXPIRE MacBook-Pro.local:11856:14ee4c3dc8a2:workers 60 >> EXEC
  Redis (2.34ms) PING
  Redis (0.35ms) MULTI >> SADD processes MacBook-Pro.local:11856:14ee4c3dc8a2 >> EXISTS MacBook-Pro.local:11856:14ee4c3dc8a2 >> HMSET MacBook-Pro.local:11856:14ee4c3dc8a2 info {"hostname":"MacBook-Pro.local","                started_at":1617864953.844983,"pid":11856,"tag":"appname","concurrency":10,"queues":["default"],"labels":[],"identity":"MacBook-Pro.local:11856:14ee4c3dc8a2"} busy 0 beat 1617864953.8558872 rtt_us 2498 quiet false rss 94800 >> EXPIRE MacBook-Pro.local:11856:14ee4c3dc8a2 60 >> RPOP MacBook-Pro.local:11856:14ee4c3dc8a2-signals >> EXEC
  Redis (2056.61ms) BRPOP queue:default 2
  Redis (2056.98ms) BRPOP queue:default 2
  Redis (2056.59ms) BRPOP queue:default 2
</code>
Comment: I changed /usr/local/etc/redis.conf like this : ```logfile /dev/null``` but result is same.
Answer: the cause was the gem 'cacheflow'
I added cacheflow for memcached debug, but I didn't catch it can affect to redis/sidekiq
https://github.com/ankane/cacheflow#features has a solution.
<code>Cacheflow.silence_sidekiq!
</code>


How to read ActiveRecord configuration from own gem?

Question: I need to call "establish_connection" method from my own gem, but ActiveRecord::Base.configurations is [].
I made work around:
module Bitrix
  class Database < ActiveRecord::Base
    @config = YAML.load(File.read('config/database.yml'))
    self.abstract_class = true
    establish_connection @config["bitrix_#{Rails.env}"]
  end
end

But why I can't access to AR config without opening file directly? I tried to use establish_connection :"bitrix_#{Rails.env}" and got this error:

/usr/local/var/rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/connection_specification.rb:257:in `resolve_symbol_connection': 'bitrix_development' database is not configured. Available: [] (ActiveRecord::AdapterNotSpecified)
Answer: All config is available in:
Rails.application.config.database_configuration

So you'd have:
db_config = Rails.application.config.database_configuration
db_config['development']

Answer: Opening any file is not needed here. ActiveRecord needs however proper configuration to know how to connect to given database, e.g:
{"template"=>"template0", "adapter"=>"postgresql",
"encoding"=>"UTF8", "database"=>"database", "pool"=>50,
"username"=>"rails", "password"=>nil}

Loading database.yml parses yaml into hash with environment names as keys and their configurations as values.
config = YAML.load(File.read('config/database.yml'))
establish_connection config["bitrix_#{Rails.env}"]

returns more or less the same hash with adapter, user and password which are essential to connect to database.


Slick - MySQL Syntax Error

Question: I'm using the Play Framework (2.3.1) together with Slick (play-slick version 0.8.0-M1) and a MySQL Database (5.5.28).
One of my queries results in a MySQLSyntaxErrorException:
Preparing statement: select x2."id", x2."course_id", x2."trainee_id", x2."transaction_id" from "trainee_grouptraining_GroupBooking" x2 where x2."course_id" = 1

The problem appears to be with the double quotation marks, since other queries work just fine and they use single quotation marks like the following:
Preparing statement: select x2.`id`, x2.`courseLanguage`, x2.`date`, x2.`description`, x2.`duration`, x2.`kind`, x2.`maxParticipants`, x2.`name`, x2.`courseType_id`, x2.`trainer_id` from `Course` x2 where x2.`id` = 1

What can i do about this?
Comment: Are you using the type-safe api? There may be something wrong with your driver setup. Are you casting anything?
Comment: Im not casting and I'm not sure what you mean by type-safe api. Could you please tell me how to find out if somethings wrong with driver setup?

This is in my application.conf:

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/sportify_dev"
db.default.user=root
db.default.password=""
Comment: could you provide a minimal sample project on github that reproduces the problem?
Answer: I guess you are importing
scala.slick.driver.JdbcDriver.simple._

You should import
scala.slick.driver.MySQLDriver.simple._

instead.
Answer: MySQL is using per default backticks to quote identifiers. You could use the SQL Mode ANSI_QUOTES to enable double quotes

ANSI_QUOTES
Treat " as an identifier quote character (like the ` quote
  character) and not as a string quote character. You can still use "`"
  to quote identifiers with this mode enabled. With ANSI_QUOTES enabled,
  you cannot use double quotation marks to quote literal strings,
  because it is interpreted as an identifier.

or simply use backticks.
Comment: Setting it to ansi_quotes mode did work. However i still think it's strange that slick sometimes uses backticks and sometimes quotation marks.

Slick - MySQL Syntax Error


Questions on Jordan forms

Question: I am studying Jordan form of a matrix from wiki. I am wondering how could two matrices have same eigenvalues with same multiplicities, but have different Jordan form?
Also, if two matrices have different Jordan forms, does this mean that these two matrices are not similar?
Thank you so much!
Comment: (1) Zero matrix and $(0, 1; 0, 0)$ have the only eigenvalue zero with algebraic multiplicity 2, and are not similar (2) Yes, that's correct.
Comment: @PeterFranek You should make that an answer.
Answer:
how could two matrices have same eigenvalues with same multiplicities, but have different Jordan form?

Zero matrix $\begin{pmatrix}0 & 0 \\ 0 & 0\end{pmatrix}$ and $\begin{pmatrix}0 & 1 \\ 0 & 0\end{pmatrix}$ have the only eigenvalue (zero) with algebraic multiplicity 2, but they are not similar. The zero matrix is not similar to any non-zero matrix.
In general, Jordan matrix consists of blocks with $\lambda_i$'s on the diagonal and $1$'s above the diagonal (if the block size is larger than 1); you can have more blocks with the same $\lambda_i$. The number and structure of all the blocks determine the similarity class. The zero matrix consists, in this language, of two diagonal blocks $1\times 1$, and the second matrix above of one block $2\times 2$.

Also, if two matrices have different Jordan forms, does this mean that these two matrices are not similar?

Yes, that's correct.
Comment: I thought that "multiplicities" in the question referred to  "algebraic multiplicity". If it referred to the geometric multiplicity, then the correct counter-example is that of Will Jagy.
Answer: For both matrices below, the characteristic polynomial is $(x-3)^4$ and the minimal polynomial is $(x-3)^2.$ However, they are not similar, the Jordan normal forms are different. The exponents in the minimal polynomial tell us only the size of the largest Jordan block with a given eigenvalue. They do not tell us the full partition of Jordan block sizes. Below, for $A$ we have $2 + 2$ but for $B$ we have $1+1+2.$
$$ A \; = \;
 \left(  \begin{array}{cccc}
 3  &  1  &  0  &  0 \\
 0  &  3   &  0  &  0 \\
 0  &  0  &  3   &  1  \\
 0  &  0  &  0   &  3
\end{array}
  \right).
  $$
$$ B \; = \;
 \left(  \begin{array}{cccc}
 3  &  0  &  0  &  0 \\
 0  &  3   &  0  &  0 \\
 0  &  0  &  3   &  1  \\
 0  &  0  &  0   &  3
\end{array}
  \right).
  $$
I do not see how to get such an example in dimension 3 or 2, so in those dimensions characteristic and minimal polynomials suffice. Note that these examples are not diagonalizable, they are already in Jordan Normal Form, these are the best that can be done.
Answer: There is something called the Jordan decomposition, (or Jordan-Chevalley decomposition)
which says that every linear operator $T$ can be written uniquely as $T=S+N$ where $S$ is diagonalizable (over an algebraically closed field, over a general field just semisimple) and $N$ is nilpotent. Now the eigenvalues and their multiplicities determine and are determined by $S$. But there are still many possiblities for $N$. That is there may be vectors that are mapped into eigenspaces without being eigenvectors themselves.

Questions on Jordan forms


loop through data using a label component C#

Question: I want to loop through some data I'm getting from a query using a label component.
This is my code to get the data and read it:
private void populatelblDesc()
    {
        conn.Open();
        string query;
        query = "select de.emp_username, poc.order_no , poc.company_id_no from dc_emp de, purch_order_carton poc";
        OracleCommand cmd = new OracleCommand(query, conn);
        OracleDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            lblDesc.Text = dr["emp_username"].ToString();
        }
        dr.Close();
        conn.Close();
    }

That query returns:
**EMP_USERNAME**          **ORDER_NO**        **COMPANY_ID_NO**
Werner                    1                   1
Chris                     2                   1
Mike                      1                   2
Marc                      3                   1

Now I want to use my NEXT button to go through the data. And each individual column in query must display in separate labels. So on load the 1st label will display "Werner",2nd label "1", 3d label "1". Hitting next will display "Chris" in 1ste label, 2nd label "2"and 3d label "1" hitting next again will display "Mike" etc etc
Can someone help me with this please?
Comment: On each `dr.Read()` condition you will get a next record..
Answer: use a BindingSource in combination with DataTable and DataBindings.
Either drop one on your form and set bs.DataSource to the table or create one dynamically.
var table = new DataTable();
table.Load(reader);
var bs = new BindingSource(table, null);
lblDesc.DataBindings.Add("Text", bs, "emp_username"),

btnNext.Click += ()
{
    bs.MoveNext();
};

btnPrev.Click += ()
{
    bs.MovePrevious();
};

You can even drop a BindingNavigator on your form and set bindingNavigator1.BindingSource to your BindingSource. It will manage the First/Previous/Next/Last logic without a single line of code.
Answer: Save your Values in a list somewhere:
List<String> LabelTextList = new List<String>();
private void populatelblDesc()
{
    conn.Open();
    query = "select emp_username from dc_emp";
    OracleCommand cmd = new OracleCommand(query, conn);
    OracleDataReader dr = cmd.ExecuteReader();
    while (dr.Read())
    {
        this.LabelTextList.add(dr["emp_username"].ToString());
    }
    dr.Close();
    conn.Close();
}

then use a integer value, starting with 0 and increase / decrease it by clicking next / prev
int i = 0;
public void next(){
    if (i+1 < this.LabelTextList.Count())
       lblText.text = this.LabelTextList[++i];
}
public void prev(){
    if (i-1 >= 0)
        lblText.text = this.LabelTextList[--i];
}

Add some validations if you are getting bellow 0 or greater than list size and you are done.
Comment: Thanks. This works! Just 2 questions. When I get to the last value and hit next again i'm getting an exception: "Specified argument was out of the range of valid values.Parameter name: index" Thats obviously because there is no more data, but how do I fix that?

And then last question: I've got a different form where i need to do the same thing but with a larger query. Every time I run it I get "IndexOutOfRange"...
Comment: Thanks that's perfect. I'm going to edit my entire question a bit. I thought that was enough and it would help me but I'm running into other issues. If you have the time please read through my question again. Many thanks already!
Comment: just adapt the solution, and use 2 other counter like j and k. Then fill the other labels in the same way, start with j = 1 and K=2 ofc. Also the boundaries needs to be fixed then (if i-1 < count -2)
Comment: Thanks. Got it to work. I added another question. :) Please read.


Stop main/current thread and let callbacks finish

Question: In essence I have a piece of code somewhat like:
function closeServerGracefully() {
  setTimeout(process.exit, 1000);
}

if (failingCondition) {
  logger.log('error', 'Fatal error exiting because failingCondition', closeServerGracefully);
}

logger.log('info', 'Everything is ok!');

(The last argument to logger.log is a callback function that gets called after the message is logged, I'm using winston)
However, if failingCondition does in fact become true my app outputs this:
Fatal error exiting because failingCondition
Everything is ok!

Then of course it crashes a few moments later because the problem wasn't caught properly.
How can I stop (or pause or kill) the execution of the "main" thread after that if statement is entered?
Answer: You can't stop main thread, you just can simulate "stop"
What's the equivalent of Java's Thread.sleep() in JavaScript?
You can try to do it without stopping:
if (failingCondition) {
  logger.log('error', 'Fatal error exiting because failingCondition', closeServerGracefully);
} else {
  logger.log('info', 'Everything is ok!');
}

Comment: Obviously my example is short, I don't want to have to put the succeeding 1000+ lines of code into an else block
Comment: make else block an / lib / module / function etc.
Comment: What do you mean?
Answer: It is happening because the last log method is getting called before the timeout.
Things you can try:
You can try using a else there. So "Everything is ok!" will not logged if failingCondition is true.
If you are using this inside a method, you should try using a return; after logger.log() within the if block.
If you are trying to catch an exception, you should use a try/catch block.
Hope it helps!


How to find all ways in which a Unix user account is locked

Question: I occasionally find myself in a situation where an undermaintained system has an account that's been locked out.  The problem is that there are a variety of ways in which an account can be locked out, each with their own method of being unlocked.
It's not that the account is being locked improperly, just unexpectedly, but finding the correct lock to reset is difficult.
My most recent attack of this problem was on a SUSE system, and it turned out that the password had expired (which wasn't initially known because the login attempts were not through a system that provided that sort of feedback), and then also locked due to failed login attempts.
Is there a list somewhere of all of the different possible account locks and how to disable them?  I'm intending for actual brokenness, such as home directory access problems, corrupt PAM libraries, etc., to be out of scope for this question.
Answer: You can use passwd to gather some information e.g. if an account is locked
passwd -S user
user LK 2012-11-06 0 99999 7 -1 (Password locked.) (CentOS)
user L 01/22/2013 0 99999 7 -1 (Ubuntu)

The chage utility will provide information about the various timers on an account e.g. for an unexpired password
chage -l user
Last password change                                    : Nov 12, 2012
Password expires                                        : never
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 0
Maximum number of days between password change          : 99999
Number of days of warning before password expires       : 7

for an expired password
chage -l user
Last password change                                    : password must be changed
Password expires                                        : password must be changed
Password inactive                                       : password must be changed
Account expires                                         : never
Minimum number of days between password change          : 0
Maximum number of days between password change          : 22
Number of days of warning before password expires       : 33

The passwd and chage utilities also list many of the account locks.
You can use getent to pull the information directly from the relevant database for examination
getent passwd user
user:x:505:505::/home/passtest:/sbin/nologin  <-- denied login
getent shadow user
user:!!:0:0:22:33:44::   <-- this is locked

Answer: In general: no.
Iain's answer is a good summary of how to query the password aging systems, but missed out all sorts of things.  For example:

Someone trying to log in via ssh could be prohibited by directives in the sshd configuration.
A system may be configured to only allow members of a certain netgroup to login.
The local PAM configuration may require explicit group membership to log in, or may only permit a particular list of users.
What looks like a locked account may turn out to be home directory access problems.
Someone may have created /etc/nologin, which for some applications (e.g., ssh) will lock out all users.

In other words, there are many ways for an account to be locked out that have nothing to do with the passwd file.  Your best bet is to check /var/log/secure or the distribution-appropriate local analog.
Comment: I was intending my question to assume that things were not "broken" and that the user had been able to log in before.  That is, that some system functioning properly locked out the account.  These are good points, but I'll update the question to be a little more explicit.
Answer: In addition to the aforementioned, passwd chage and getent, there's also pam_tally2
If the number of failed login attempts is above the allowable limit (which is set in /etc/pam.d/password-auth), you'll have to do pam_tally2 --user=foo --reset before they can login again.
Answer: Following script would give you a short description of all users and their status (locked or not)
cat /etc/passwd | cut -d : -f 1 | awk '{ system("passwd -S " $0) }'

Comment: That only checks one of the ways in which an account can be locked.


Accounting for uncertainty in a mixed-effects regression

Question: I have calculated an effect size along a dataset of experiments distributed worldwide through a mixed-effects meta-regression. The effect size in the dataset depends on climate (y ~ temperature + precipitation):
meta <- metafor::rma(es, var, data=df, mods= ~ 1 + precip + temp))
As I have data for temperature and precipitation for virtually all points on Earth, I have upscaled this effect and standard error (SE) globally, that is, applying the model to predict the effect for all points on Earth, thus creating a gridded map:
pred <- predict(meta, newmods = cbind(s.df$precipitation, s.df$temperature))

This upscaled map of SE thus represent the meta-analysis derived uncertainty. What this SE does not reflect is the uncertainty derived from the fact that the number of experiments in the dataset used to run the meta-regression is obviously limited, yet I predict the effect globally, even in areas not covered by experiments. In particular, it is very obvious in the dataset that tropical ecosystems are not well represented, with just a couple of experiments in the dataset. Therefore, the upscaled effect should be more uncertain in tropical regions, but in the current version, SE is not particularly higher in the tropics than in other areas, because the model just depends on climate, not ecosystem representativeness. I would like to add a further level of uncertainty to SE based on the number of studies per type of ecosystem in the dataset. The idea is that ecosystems that are poorly sampled should have a higher SE than ecosystems with plenty of measurements in the dataset.
Ecosystem type does not appear to explain variation in the effect, but this could just be the consequence of the low sample size of some ecosystem types. Regardless, ecosystem type should be forced to be included in the model somehow so that poorly sampled ecosystems show larger uncertainty. How can I do this? Should I include ecosystem type as a random effect?
Comment: At the moment this question is a bit unclear.  You have a "gridded dataset" of estimated SE values of an effect.  What are the variables that define the grid?  Is it a grid of the different ecosystems, or is it something else?  Did the number of observations in each ecosystem form a part of the initial estimation of the SE values for the effect, or are they new information that is independent of this?
Comment: What variable is the SE measurement for?  What kind of model was this?  Some kind of regression-type model?
Comment: I hope is clearer now
Comment: Just to help you clarify this question, the answer will depend a great deal on what you have already done when fitting the model.  Most models will automatically take account of the number of data points you put into them without requiring any special weighting.  If you are adding exogenous information on the number of data points, that will usually be added in within the model by a weighting parameter.  So if you can give a better idea of what you've already done, them I'm sure people on here can help you a lot better.
Comment: Hi Ben, the current model does not reflect the type of spatial uncertainty related to the representation of ecosystem types. I have updated my Q including more background. Thanks for your ideas for a clearer Q
Comment: I don't think weighting is the answer. You may want to add a variable into your model that classifies your regions by ecosystem. Then run a random effects meta-analysis model. The variance terms that you include in your effects should incorporate the uncertainty present in each sample. By adding a ecosystem 'category' variable to your model you should be able to get out separate estimates by type. If, as you say, the tropical category has fewer measurements, you should see larger model-based standard errors for the estimates pertaining to that region.
Comment: Would you add 'Biome' as a moderator or as a random effect? i.e.: mod1 <- rma.mv(es, var, data=df, random= ~1|Biome, mods= ~ 1 + MAP + MAT) or mod2 <- rma.mv(es, var, data=df, mods= ~ 1 + MAP + MAT + Biome)?
Comment: @MattBarstead please help
Comment: `metafor::rma` is a *specific* function in R. Could you more *generally* explain your model and how you currently calculate SE?
Comment: What I currently understand is that you model something based on temperature and precipitation levels, but that you would also like to use, in addition, the ecosystem. Is that right? In particular you do not want the model predictions to be influenced by ecosystem, but only the standard error of the predictions?
Comment: When I upscale the effect globally, I am projecting the effect to areas (ecosystems) in which we don't really know the behaviour of the system because no measurements have been taken there. Therefore, a quantification of uncertainties has to be accompanied with the upscaled effect, with areas (ecosystems) not sampled showing large uncertainties.
Comment: I do not really get the term 'upscale the effect', as well as how and where 'ecosystem' is placed in your model. I see that you used 'temp' and 'precip' in your model. Where does 'ecosystem' suddenly come from (what is it, how do you measure it, etc)? And why did you not place 'ecoystem' in your model when it is supposed to have a moderating effect?
Comment: @MartijnWeterings that's exactly the point of my question, I don't know how to include "ecosystem" in the model in order to account for the uncertainties associated with the low sample size in some types of ecosystems. Upscaling means simply predicting the effect globally even though the model was developed using data for just a few locations. To do so, we need globally available data for the predictors of the model. Therefore, when upscaling, there is uncertainty associated with the fact that you don't know the behaviour of the system in some regions (in this case, ecosystems).
Comment: This is not a statistical question: "I don't know how to include "ecosystem" in the model". You can build your statistical model based on the idea that your measured '$y$' is a linear function of 'precipitation' and 'temperature'. However to make any conclusions on the statistics based on an 'unknown' effect of ecosystem, *without assumptions about the influence/role of ecosystem in the model* makes no sense. You have to specify these assumptions before making any argument (/calculation) about the statistics.
Comment: You have to specify the role of ecosystem. Prior expectations matter. Even when you are doing a frequentist analysis (in that case the priors are just called assumptions). Compare for instance with the role of some other, likely unimportant, variable. Say, whether the country for which the prediction is made has a 'z' in it's name. If you do not specify the way in which the ecosystem can/cannot have an effect, then you can not extrapolate/scale the predictions while taking the role of the ecosystem into account.
Comment: MartijnWeterings I am really explaining things as clear as I am able to given my current skills, but your replies seem to just focus on criticising the way I word my question rather than trying to help. Even when the question was less clear, @MattBarstead found the key to try to help me and refocus the whole thing. I will wait and see if he can give me more clues now that I have advanced a little
Answer: If you add ecosystem as a main/interaction random effect then the model will indeed incorporate additional parameters for the variability of the dependent variable as function of ecosystems. This allows you to incorporate additional modes of uncertainty for predictions. This will be based on:

different predicted $\hat{y}$ Since you assume that ecosystems can have an effect, the model will also, likely, make the effects different. (But as you say this does not appear to be so much the case and your fit will give little significant effects. This is no problem) If you make some manual custom made model then you can have the effect size the same and just the error of the estimates vary as function of the ecosystem (heteroskedasticity, which is easy if you apply fixed weights for different ecosystems and a bit more difficult if the weights are unknown)
and also different standard error for $\hat{y}$, because the means, or $E(\hat{y})$, are being estimated with variations of sample size.
Answer: To address this comment explicitly as an extension of your original question:

Would you add 'Biome' as a moderator or as a random effect? i.e.: mod1
  <- rma.mv(es, var, data=df, random= ~1|Biome, mods= ~ 1 + MAP + MAT)
  or mod2 <- rma.mv(es, var, data=df, mods= ~ 1 + MAP + MAT + Biome)?

My instinct would be to incorporate biome as a moderator (i.e., as a predictor of your random effects). Using the predict function and feeding your model the relevant data (which would now include three variables), and specifying the levels= argument, you should get a series of estimates and intervals (specified to your level of uncertainty). For biomes that contain more variability in their effect sizes (either as a function of small samples or as a result of greater variation overall) you should see wider intervals. Those intervals can be incorporated into simple tables or even included in graphics, depending on your final goals.
Comment: The standard error is often related to a *single* estimate of variance $\hat{\sigma}$ multiplied with additional terms including the independent variables. If the regression and determination of the SE is carried out according to this standard format (ie. assuming homogeneous variance), then there will be no influence of the 'greater variation overall' in a certain ecosystem, and only the sample size has an effect on the error estimate of the predictions.
Comment: I agree to a degree but it depends on how the data are structured/collected. In a world in which there are multiple distinct effect sizes for each biome, each with their own unique sample (say a set of measurements from the Amazon, from a jungle in sub-Saharan Africa, and from a rainforest in Indonesia), the variability in those point estimates as well as the variability in their variance terms (i.e., the SEs of each effect from each sample) would contribute to the model-based SE for that biome no?
Comment: You can estimate a point estimate SE in several different ways, but the standard is, I believe, assuming a *single*, $\hat\sigma$, estimate of the deviation. This means that a *multiple/hereogeneous* deviation is not taken into account. Still, variations of the SE occur because the estimates of fit curves and predictions do not only depend $\hat\sigma$ but also on the number in the sample (where the fits/means improve if you have larger samples, but predictions will always be susceptible to the error term $\sigma$ ).
Comment: Thanks for your responses. I seem to understand both of you suggest adding ecosystem type ("Biome") as a moderator, which should produce large SE values in biomes with lower sample size. Great. What I don't understand is why you both seem to disagree in some aspects. What are the differences you are discussing? I will start a bounty again so you can have the extra reputation you deserve for helping me out.
Comment: From a technical point, I can't still manage to make the predict function work. "Biome" is categorical, with > levels(df$Biome)
[1] "Boreal_Forest"    "Cropland"         "Grassland"        "Shrubland"
[5] "Temperate_Forest" "Tropical_Forest"
Comment: pred.mv <- predict(meta.mv,
+                       newmods = cbind(s.df$precipitation, s.df$temperature, s.df$Biome))
Error in predict.rma. Dimensions of 'newmods' do not match dimensions of the model.
Comment: I am assuming for your second question that your object meta.mv was run with the categorical variable included? If not that would be something that needs to happen first. If so I wonder how metafor handles categorical variables. You may have to dummy code them manually but I don't know off the top of my head. Would need to check into the documentation. Those are my first two quick takes for the practical side of things. I haven't had a chance to respond more thoroughly to the conceptual side of things just yet and will try to do so some time this week.


Using drupal-scaffold correctly

Question: I am in the process of starting new projects using drupal/recommended-project over the Drupal composer project template. One of the differences I have noted is that the Drupal scaffold tool fires every time even when just installing a new module or theme.
In this case, I get write permission warnings about settings.php, and I have other concerns such as .htaccess or robots.txt being replaced.
I read some of the docs and added this in my composer.json file:
<code>"drupal-scaffold": {
    "locations": {
        "web-root": "docroot/"
    },
    "file-mapping": {
        "[web-root]/sites/default/settings.php": false,
        "[web-root]/.htaccess": {
            "mode": "replace",
            "path": "assets/drupal/.htaccess"
        }
    }
},
</code>
This prevents settings.php from being touched, and replaces the .htaccess file from Drupal with one containing our modifications. The drawback that I see here is if .htaccess had some security changes, I would have to do a manual diff and put the custom rewrite rules back in.
Is this the proper way to use drupal-scaffold?
Comment: @Kevin – drupal-composer/drupal-project uses drupal/core-composer-scaffold as well now.
Answer: I use the patch method mentioned on https://www.drupal.org/docs/develop/using-composer/using-drupals-composer-scaffold#toc_4
e.g:
<code>"name": "my/project",
...
"scripts": {
  "post-drupal-scaffold-cmd": [
    "cd docroot && patch -p1 <../patches/htaccess-ssl.patch"
  ]
}
</code>
Then if the core file changes it will either merge correctly or the patch will fail and you'll see that in your composer command and can make the relevant changes to your patch

Using drupal-scaffold correctly


Python setuptools override version from command line

Question: I am setting up a continuous delivery system for a python project, and I am trying to figure out how to set the ENTIRE version string of the project build via egg_info.
I am using thoughtworks GO which has a built in version tracking label called GO_PIPELINE_LABEL. I would like to invoke the setup_tools egg building command with this version as an argument completely overriding the version in setup.py.
eg:
GO_PIPELINE_LABEL='22.214.171.124' python setup.py egg_info --tag-build=$GO_PIPELINE_LABEL bdist_egg

seems to result in
'dist/myproject-0.0.01.2.3.4-py2.7.egg'

It always seems to concat the setup.py version and the command line one. My setup.py looks like this:
import os
from setuptools import setup, find_packages
from setuptools.command.install import install

ROOT_DIR = os.path.dirname(__file__)
SOURCE_DIR = os.path.join(ROOT_DIR)

# python setup.py egg_info -rb14 bdist_egg rotate -m.egg -k5
# python setup.py egg_info --tag-build=22.214.171.124 bdist_egg

version = ''

setup(name='myproject',
    version=version,
    description='baa',
    author='Me',
    firstname.lastname@example.com',
    packages=['submodule', 'another.submodule'],
    package_data = {
                       '': ['*.xsd'],
                       },
    install_requires=['cmd2',
                    'dnspython',
                    'ordereddict',
                    'prettyprint',
                    'pycontrol',
                    'simplejson',
                    'suds',
                    'pyparsing<2.0.0',
                    'urllib3',
                    'lxml',
                    ]
    )

I have tried nulling / removing the version variable in my setup.py, but whatever I do seems to result in a concatenation of the version values, and a null seems to equate to '0.0.0'. Anyone know how I can utilize setup_tools and set my version string?
Thanks,
K
Answer: You could try providing the version as a positional command line argument then deleting it before executing setup:
import sys
from setuptools import setup

version = sys.argv[1]
del sys.argv[1]

setup(name='myproject',
    version=version,
    ...

Then you'd execute it like so:
python setup.py '18.104.22.168' egg_info

Answer: One option is to parse option and set the version like below just before calling setup
from optparse import OptionParser
parser = OptionParser("")
parser.add_option("--tag-build", dest="version")
(info,a)=parser.parse_args()
version = info.version
print "version is ", version

Comment: This DOES NOT WORK and will break the easy_install setup.py script.


Função async retornando antes do resultado

Question: Tenho essa função em JS, utilizando biblioteca Forge, para geração de par de chaves. O problema que ao tentar utilizar a função async para realizar a geração, a função está retornando antes de gerar o resultado.
function generateKeys(keySize, storageName) {
    var rsa = forge.pki.rsa;
    // var keys = forge.pki.rsa.generateKeyPair(keySize);
    var p1 = rsa.generateKeyPair({bits: keySize, workers: -1}, function(err, keypair) {
        var privateKey = keypair.privateKey;
        var publicKey = keypair.publicKey;
        sessionStorage.setItem(storageName, JSON.stringify(privateKey));

        var csr = forge.pki.createCertificationRequest();
        csr.publicKey = publicKey;
        csr.sign(privateKey);

        // convert certification request to PEM-format
        var certReqPem = forge.pki.certificationRequestToPem(csr);
        console.log(certReqPem);
        return certReqPem;
    });
};

Recebo esse retorno no meu HTML para encaminhar para um form PHP, porém, está vindo NULL, mas se eu mandar printar, eu vejo que ele manda Null, e depois printa no console
Answer: Pode tentar usar async/await da seguente maneira
function async generateKeys(keySize, storageName) {
    var rsa = forge.pki.rsa;
    // var keys = forge.pki.rsa.generateKeyPair(keySize);
    var keypair = await rsa.generateKeyPair({bits: keySize, workers: -1});
    var privateKey = keypair.privateKey;
    var publicKey = keypair.publicKey;
    sessionStorage.setItem(storageName, JSON.stringify(privateKey));

    var csr = forge.pki.createCertificationRequest();
    csr.publicKey = publicKey;
    csr.sign(privateKey);

    // convert certification request to PEM-format
    var certReqPem = forge.pki.certificationRequestToPem(csr);
    console.log(certReqPem);
    return certReqPem;
};

Comment: Ah consegui, o problema que eu estava chamando isso em outra função no HTML, ai coloquei async nela também, e await como dito anteriormente, funcionou, valeu.
Comment: No HTML está assim: var publicKeyPem = generateKeys(keySize, "privateKeyPem"); Quando faço console.log nessa variavel, está vindo uma promessa no estado pending.
Comment: Por isso ao ser uma promise, vc tem que executar com async/await para fazer a execuçao da promesa aguardando seu fim [funçoes async](https://developer.mozilla.org/pt-PT/docs/Web/JavaScript/Reference/Statements/async_function)
Comment: Hum, você diz utilizar .then? estou tentando, mas sem muito sucesso
Comment: Nao, VC pode Fazer con eu indico na resposta, com async e await
Comment: Eu fiz como está ali, ele está retornando uma promessa, como disse na primeira resposta
Comment: Na primera resposta vc nao faze `var publicKeyPem = await generateKeys(keySize, "privateKeyPem");`
Comment: com o await da este erro: SyntaxError: await is only valid in async functions and async generators, o que é bem estranho, pois a função está declarada como async
Comment: Pegue a funçao para ajudar
Answer: Não é necessário async/await para o cenário que você deseja. O problema está na utilização da sobrecarga incorreta para o que necessida, da função 'rsa.generateKeyPair'.
Você pode utilizar a mesma função rsa.generateKeyPair sem necessidade de passar um callback e está tudo resolvido.
Abaixo envio o código e com um teste logo abaixo (só copiar e colar):
function generateKeys(keySize, storageName) {

    var rsa = forge.pki.rsa;
    // var keys = forge.pki.rsa.generateKeyPair(keySize);
    var keypair = rsa.generateKeyPair({bits: keySize, workers: -1});

    var privateKey = keypair.privateKey;
    var publicKey = keypair.publicKey;
    ssessionStorage.setItem(storageName, JSON.stringify(privateKey));

    var csr = forge.pki.createCertificationRequest();
    csr.publicKey = publicKey;
    csr.sign(privateKey);

    // convert certification request to PEM-format
    var certReqPem = forge.pki.certificationRequestToPem(csr);

    return certReqPem;
};

Testando:
const x = generateKeys(...);

console.log(x);

Comment: Realmente funciona, meu questionamento é o seguinte: necessito de desempenho, qual abordagem mais correta? Parece que a async é mais rápida
Comment: Então Vinicius, isso é muito relativo e depende também se a biblioteca que você está utilizando possui o recurso assíncrono ou você necessitaria fazer um wrap para retorno de uma Promise.

Você ganha desempenho com recursos assíncronos quando faz sentido você colocar tarefas para execução em paralelo. Mas no seu caso, você precisa aguardar o retorno da chave para continuar o seu programa, então não existe a necessidade de tarefas paralelas.

Recomendo, se desejar, a leitura desse artigo: https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Statements/funcoes_assincronas
Comment: Acho que a minha resposta está correta e a que você marcou como correta está errada, porque o 'await' recomendado na resposta do amigo é irrelevante e não era necessário, mesmo a função sendo async. Tire o 'await' e comprove, isso porque a função 'generateKeyPair' não retorna uma Promise para necessitar de 'await'


Composition of pushout remains a pushout

Question: $\require{AMScd}$ Define groups and homomorphismes as below. I am supposed to show, that given the left and the right rectangle are pushouts/amalgames, then the outer/big one is a pushout/amalgame aswell.
$$
\begin{CD}
G @>f>> G' @>f'>> G''\\
@VgVV @VVg'V @VVg''V \\
H @>h>> H' @>h'>> H''
\end{CD}
$$
Does that mean that I have to show that the following diagram is a pushout?
$$
\begin{CD}
G @>f' \circ f>> G''\\
@VgVV @VVg''V \\
H @>h' \circ h>> H''
\end{CD}
$$
If so, do I have to show that the different pushouts $H''$ of the right rectangle and the big rectangle coincide? I.e.
Given $H'$ and $H''$ are pushouts, they are defined as
$H':= G'*_{G}~H$ and $H'':= G'' *_{G'}~H'$.
Given my previous thought process do I now have to show that (where $\newcommand{\ngenl}{\mathopen{\vartriangleleft}}
\newcommand{\ngenr}{\mathopen{\vartriangleright}}\ngenl S \ngenr$ denotes the normal subgroup generated by $S$):
$$
\begin{align*}G''*H/ \ngenl (f'\circ f)(x)g(x)^{-1} \forall x \in G\ngenr & =: G'' *_{G}~H \\
& \stackrel{!}{=}G'' *_{G'}~H'\\
&= G'' *_{G'}~(G' *_{G}~H)\\ &=
\frac{G''*(G'*H/\ngenl f(x)g(x)^{-1} \forall x\in G\ngenr)}{\ngenl f'(\bar{x})g'(\bar{x})^{-1} \forall \bar{x}\in G'\ngenr}
\end{align*}
$$
And if so how do I continue ?
Comment: Try to use universal property of pushouts in order to show that the outer square is a pushout.
Comment: I tried to improve the readability of the last bit. I also suggest replacing the $\forall$'s by $\mid$'s, as in @DanielSchepler's comment.
Answer: Unfortunately I do not understand at all what your formula with the many triangles at the end means. But it is probably simpler than what you are trying to do. You just check that the outer rectangle has the universal property of a pushout.
Let $T$ be any group. Using that both little squares are pushouts you can make the following computation.
\begin{align*}
Hom(H'',T) &= \{(a,b)\in Hom(G'',T)\times Hom(H',T)\mid a\circ f' = b\circ g'\} \\&= \{(a,c,d)\in Hom(G'',T)\times Hom(G',T) \times
Hom(H,T)\mid d\circ f = c\circ g\wedge a\circ f' = (c,d)\circ g'\} \\&=\{(a,c,d)\in Hom(G'',T)\times Hom(G',T) \times
Hom(H,T)\mid d\circ f = c\circ g\wedge a\circ f' = d\}
\\&=
\{(a,c)\in Hom(G'',T) \times
Hom(H,T)\mid a\circ f'\circ f = c\circ g\}
\end{align*}
I have inserted a few extra-steps in the middle. It is less complicated than it looks like. Just start with two arrows $c:H\to T$ and $a:G''\to T$ such that $c\circ g = a \circ f'\circ f$, and try to find an induced arrow $H''\to T$ using the universal properties of the two squares. Then you check that the arrow you get is the one and only arrow which fits, and you are done.
Comment: Maybe the OP was working in the category of groups, and used the left and right triangle symbols in place of `\langle` and `\rangle` ?  (Though I would also have used a `\mid` where the OP used `\forall` .)
Comment: Oh, or maybe using the triangle symbols might be notation for forming "the normal subgroup generated by" as opposed to just "the subgroup generated by"?  Going out on a limb there...
Comment: Yeah, it was the notation our prof introduced to say that it is "the normal subgroup generated by"


Animate.css - How does it work? How to make it work automatically?

Question: I'm trying to implement bounceinUp from https://daneden.me/animate/ to my website.
Instead of clicking on the button, I'm trying to put it in div box that will automatically do the above after 2-3 seconds.
HTML

Testing

CSS
@-webkit-keyframes bounceInUp {
    0% {
        opacity: 0;
        -webkit-transform: translateY(2000px);
    }

    60% {
        opacity: 1;
        -webkit-transform: translateY(-30px);
    }

    80% {
        -webkit-transform: translateY(10px);
    }

    100% {
        -webkit-transform: translateY(0);
    }
}
@-moz-keyframes bounceInUp {
    0% {
        opacity: 0;
        -moz-transform: translateY(2000px);
    }

    60% {
        opacity: 1;
        -moz-transform: translateY(-30px);
    }

    80% {
        -moz-transform: translateY(10px);
    }

    100% {
        -moz-transform: translateY(0);
    }
}

@-o-keyframes bounceInUp {
    0% {
        opacity: 0;
        -o-transform: translateY(2000px);
    }

    60% {
        opacity: 1;
        -o-transform: translateY(-30px);
    }

    80% {
        -o-transform: translateY(10px);
    }

    100% {
        -o-transform: translateY(0);
    }
}

@keyframes bounceInUp {
    0% {
        opacity: 0;
        transform: translateY(2000px);
    }

    60% {
        opacity: 1;
        transform: translateY(-30px);
    }

    80% {
        transform: translateY(10px);
    }

    100% {
        transform: translateY(0);
    }
}

.bounceInUp {
    -webkit-animation-name: bounceInUp;
    -moz-animation-name: bounceInUp;
    -o-animation-name: bounceInUp;
    animation-name: bounceInUp;
}
#animateTest {
    -webkit-animation-duration: 1s;
    -webkit-animation-delay: .2s;
    -webkit-animation-timing-function: ease;
    -webkit-animation-fill-mode: both;
    -moz-animation-duration: 1s;
    -moz-animation-delay: .2s;
    -moz-animation-timing-function: ease;
    -moz-animation-fill-mode: both;
    -ms-animation-duration: 1s;
    -ms-animation-delay: .2s;
    -ms-animation-timing-function: ease;
    -ms-animation-fill-mode: both;
    -o-animation-duration: 1s;
    -o-animation-delay: .2s;
    -o-animation-timing-function: ease;
    -o-animation-fill-mode: both;
    animation-duration: 1s;
    animation-delay: .2s;
    animation-timing-function: ease;
    animation-fill-mode: both;
}

I think this is the javascript though it's not displayed on the page (and there are not tutorial from what I searched in regards to javascript).

Anyway, when I do this, it does nothing to it. I was wondering what I did wrong? I'm sorry if this sounds very easy question, I'm just starting out with learning HTML and javascript.
Thanks in advance,
Comment: first of all you have an extra bracket } in your CSS for .bounceInUp You need to remove it in order for CSS to work
Comment: did that already, there was suppose to be #animateTest in between the css! I will edit it in!
Answer: here is the fiddle of your code - http://jsfiddle.net/yd79L/1/
Your problem is that you forgot to call the function after you created it. Also remember that if you want a function to go 'cycles' - it should call itself from within
Also in your code you had only (x) as the argument for a function and you need to specify the name of a class that you want to use
    function testAnim(x) {
    $('#animateTest').removeClass().addClass(x);
    var wait = window.setTimeout( function(){
        $('#animateTest').removeClass(x);
        }, 1300
    );
window.setTimeout(function(){ // this code calls the function and makes it cycle
testAnim(x);
}, 2000 );
}

testAnim('bounceInUp');

Comment: thank you so much! it worked like a charm! but I was wondering what I should change to make the animation appear later than it is right now (not the animation speed, I mean the timing of when this animation appears?) THANK YOU AGAIN!
Comment: well, in the code above, the timing for between the animation is the second setTimeout() function. So try to increase the number in that function. Remember 2000 equals 2 seconds, based on this you can increase it to a number that you want.


How to hide the last record for each person?

Question: Using crystal report 9
Example
<code>   PersonID    Date
3405    28-02-2009
3405    29-02-2009
3406  25-02-2009
3406  30-02-2009
</code>
So on…,
I want to hide the last record for each personid
<code>Expected Output

3405 28-02-2009
3406 25-02-2009
</code>
So on…,
How to write a formula for this condition?
Answer: In your Detail section's Suppress formula, use this :
<code>(NextIsNull({SomeTable.PersonID}))
OR
({SomeTable.PersonID} <> Next({SomeTable.PersonID}))
</code>
Note that this will only hide the row from the report visually, but if you have any subtotals based on the records displayed then you'll need to use running totals instead of regular summary totals (which would still include the hidden data).


The prime spectrum in multiple variables - a basic example/question

Question: So in algebraic geometry, the prime spectrum of the ring of polynomials over a field $k$ is isomorphic to the set of $k$-homomorphisms from the ring of polynomials to $k$, and we do this by using the fact that the residue field (localise w.r.t. some prime ideal, then mod out the ideal generated by this in the localisation) is isomorphic to $k$, and hence any polynomial goes to an element of $k$, via the equivalence relations. This all makes sense as the ideal generated by a prime ideal of the polynomial ring in its localisation is clearly maximal, but I'm stuck on a very basic example:
Let $\mathbb{C}[x,y]$ be the polynomial ring over the complex numbers and $(x-1)$ be the prime ideal. What number does $y$ go to? A $\mathbb{C}$-algebra homomorphism is defined completely by its action on the generators of the polynomial ring (so just the $n$ variables, and taking $n=2$ we get $x\mapsto1$, but $y\mapsto?$), but I can't figure out how this works in this simple case. It should maybe be zero (otherwise how do you invert $1 + y$?), but I don't know. Can anyone explain this?
Comment: As Akhil Mathew's answer shows, your first sentence is not correct.  This is why you are stuck; you are trying to prove something that is not true (as Qiaochu's Yuan's comment shows).
Comment: The quotient C[x, y]/(x - 1) is isomorphic to C[y], not to C.
Answer: The maximal ideals in a polynomial ring of an algebraically closed field $k$ is isomorphic to the set of $k$-homomorphisms from the polynomial ring into $k$. (This is the Nullstellensatz.) This is not true for arbitrary prime ideals, nor is it true for nonalgebraically closed fields. (Consider for instance the ideal $(X^2 +1) \subset \mathbb{R}[X]$; this morally wants to correspond to the points $\pm i$, but it doesn't, since those don't live in the reals. Nonetheless, it happens that the scheme $\mathrm{Spec} \mathbb{R}[X]$ includes all prime ideals, so it includes a copy of $\pm i$ glued together, if you want to call it that.) In the terminology of algebraic geometry, one would say that the point you described is not "rational over $\mathbb{C}$." Such points do exist, and make schemes of even finite type over an algebraically closed field different from varieties.
(Fortunately, it turns out that closed points alone determine many topological properties---the precise statement is that the closed points (or maximal ideals) are dense in any constructible sets.)
Comment: would you explain the first line how that isomorphism is?


Proving a sequence defined by a recurrence relation converges

Question: How can I prove that this iterative sequence converges to $2$? Can I use the convergence definition?
$$a_{n+1} = \frac{a_n}{2} + \frac{2}{a_n},\qquad  a_0 = 4  $$
Thanks for the help.
Answer: Overall outline:

Show that $(a_n)_n$ is monotone decreasing, and positive, and hence convergent.
Show that the only limit possible is positive and satisfies $\ell = \frac{\ell}{2}+\frac{2}{\ell}$
Conclude.

Detailed outline: let $f\colon (0,\infty)\to (0,\infty)$ be the function defined by $f(x) = \frac{2}{x}+\frac{x}{2}$.

Observe that $a_n > 0$ for all $n\geq 0$ (e.g., by induction, but it's immediate).
Show that $f$ has a unique minimum on $(0,\infty)$, and that this minimum is $2$.
This implies $a_{n+1} = f(a_n) \geq 2$ for all $n\geq 0$.
Observe that $a_{n+1}-a_n = \frac{2}{a_n} - \frac{a_n}{2} \leq 0$ (e.g., by studying the function $g(x) = \frac{2}{x}-\frac{x}{2}$ on $[2,\infty)$). This gives you the monotonicity of $(a_n)_n$.
Now that you know that the sequence converges to some $\ell \geq 2$, by continuity of $f$ this limit must satisfy $\ell = f(\ell)$. Solve the equation, and conclude.


How to show the fixed field is a subfield

Question: Given and extension $K$ of a field $F$, and a subgroup $H \leq \text{Gal}(F/K)$, how can I show that the fixed field of $H$ given by:
$$\{ x\in F : \varphi(x) = x\;\; \forall \varphi\in H \}$$
is a subfield of $F$ containing $K$?
Answer: You show that it contains 0, 1, and is closed under field operations ($+,-,\cdot,(\cdot)^{-1}$). These follow because we're looking at being fixed by a homomorphism.
Also showing that it contains $K$ follows by definition of the Galois group.


Table Pager Rendered in an Ajax Callback Shows White Page

Question: I have the callback function below that renders a table with a pager. Every page of the table is 20 rows. Below is the code:
function myid_print_all_submitted_id_callback($form, &$form_state){
    $table_html = '';
    $rows = array();

    // Build the sortable table header.
    $header = array(
        'idnumber' => array('data' => t('ID Number'), 'field' => 'idnumber'),
        'student' => array('data' => t('Student'), 'field' => 'student'),
        'status' => array('data' => t('Lacking ID Information | Status'), 'field' => 'status'),
    );

    $query = db_select('student', 't1',array('target' => 'import'));
    $result = $query
        ->fields('t1', array('idnumber','student','status'))
        ->condition('t1.studid', 1 ,'=')
        ->extend('TableSort')->extend('PagerDefault')->limit(20)
        ->execute();

    foreach($result as $record){
        $rows[] = array(
            'idnumber' => $record->idnumber,
            'student' => $record->student,
            'status' => $record->status,
        );
    }

    $table_html = theme('table', array('header' => $header, 'rows' => $rows)) . theme("pager");

    //Build the table
    $form['table'] = array(
        '#type' => 'item',
        '#markup' => $table_html,
        '#empty' => t('Table has no row!'),
        '#prefix' => '
',
        '#suffix' => '
',
    );
    return $form['table'];

}
It looks like the image below:

When I click the next page it shows a blank page:

Where did I go wrong? It was redirected to http://184.108.40.206/myid/system/ajax?page=1, when it must be redirected to http://18.104.22.168/myid/user/1/myid_print?page=2.
I was guessing it is because the table pager was not loaded yet because it was rendered by a callback function. Any suggestions/solutions on how to solve it?
Answer: This sounds like a known bug in core:
Pager, tablesort links in a form point to system/ajax when reloaded via AJAX
https://www.drupal.org/node/1181370
Someone has offered up a "quick fix" in comment #22:

As a quick fix I overrode theme_pager_link() to set the url of my AJAX-loaded pager to the page url instead of $_GET['q'] (which was system/ajax).

[Edit...]
I haven't tested this, but give it a try:

In your callback function, save the current path in a session variable:

$_SESSION['page_path'] = current_path();

Copy and paste this function into your *.module file:

/**
 * Implements hook_theme_registry_alter().
 */
function YOUR_MODULE_NAME_theme_registry_alter(&$theme_registry) {
  $theme_registry['pager_link']['theme path'] = drupal_get_path('module', 'YOUR_MODULE_NAME');
  $theme_registry['pager_link']['function'] = 'YOUR_MODULE_NAME_pager_link';
}

Copy the theme_pager_link() function into your *.module file.
Rename the function YOUR_MODULE_NAME_pager_link.
In the function, replace the following line:

$attributes['href'] = url($_GET['q'], array('query' => $query));

with:
if (isset($_SESSION['page_path'])) {
  $attributes['href'] = url($_SESSION['page_path'], array('query' => $query));
}
else {
  $attributes['href'] = url($_GET['q'], array('query' => $query));
}

Clear the caches.
Comment: Where will I override theme_pager_link()?
Comment: Please guide me on how to do this.
Comment: I've added some steps in my answer. I haven't tested it, but it should work.
Comment: not working with me....Why?
Comment: current_path() returns system/ajax? why?
Comment: Where are you calling `current_path()`?
Comment: In the ajax callback function.
Comment: Sorry, busy week. A couple of things to try: 1) Change `$_SESSION['page_path'] = current_path();` to `$_SESSION['page_path'] = isset($_SESSION['page_path']) ? $_SESSION['page_path'] : current_path();`, OR 2) Instead of `current_path()` try `strtok($_SERVER["REQUEST_URI"],'?');`. The first should only set your session variable once, when the form first loads; the second just grabs the raw URI and strips away the query string.


Interval Notation of the Following Logarithmic Inequality

Question: So after trying to solve the following inequality, log(x) + log(2-x) < 1
I couldn't end up with any answer since as I tried to solve here are my results
First I got my reference equation ( to be used in the number line )
log(x)+log(2-x)<1
As I tried solving it
x(2-x)<10
x(2-x)-10<0
x^2 + 2x -10 <0
I multiply both sides by negative 1
x^2 - 2x + 10 > 0
But as you can see the following is not factorable.
I decided to try using Symbolab and Wolfram to see what was the Interval notation and it answered (0,2)
Can someone please help enlighten me or atleast point me in the right way to solve the following inequality
Many thanks!!
Comment: here is an introduction to MathJax http://meta.math.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference
Answer: $\log(x)$ is defined for $x>0$
and $\log(2-x)$ is for $2-x>0\iff x<2$
So, we need $0<x<2$
Now $x(2-x)<10\iff x^2-2x+10>0$
Now for real $x,x^2-2x+10=(x-1)^2+9\ge9>0$
Can you take it from here?
Comment: Yes! Thanks I understood it now!
Answer: For $x\in(0,2)$ we have:
$$\log (x)+\log(2-x)=\log[x(2-x)].$$
Since $x(2-x)$ has roots of $0$ and $2$, its maximum is at $1$. Thus $x(2-x)\leq 1$. Therefore $$\log(x)+\log(2-x)\leq \log(1)= 0<1$$ for all $x\in(0,2)$.


Get all the words between two specific words in python

Question: I have some string like these:
The pizza is so hot
Today I bought an hot and tasty pizza

I need to extract all the words between pizza and the adjective hot in python. How can I do??
These are an example of the output.
is so
and tasty

Please take in mind that the attribute (pizza for example) and the adjective (hot for example) could be a multi-token word.
That's what I tried:
  attribute = re.search(values[0], descrizione, re.IGNORECASE)
  value = re.search(names[0], descrizione, re.IGNORECASE)
    if (attribute):
        print (attribute.group())
        print (descrizione.find(attribute.group()))

    if (value):
        print (value.group())
        print (descrizione.find(value.group()))

Comment: Can pizza and hot appear multiple times in a line?  How should it handle that?
Comment: @BrendanAbel no. They can't :D
Comment: Do you need to find the words in multiple strings, or just the two?
Comment: Multiple strings not only 2... The adjective can be before the attribute or after the attribute
Comment: sounds like a good use for pyparsing
Answer: A different approach, you can define your "from/to" patterns as you desire.
>>> import regex
>>> rgx = regex.compile(r'(?si)(?|{0}(.*?){1}|{1}(.*?){0})'.format('pizza', 'hot'))
>>> s1 = 'The pizza is so hot'
>>> s2 = 'Today I bought an hot and tasty pizza'
>>> for s in [s1, s2]:
...     m = rgx.findall(s)
...     for x in m:
...         print x.strip()

is so
and tasty

Comment: line 82, in
    rgx = re.compile(r'(?si)(?|{0}(.*?){1}|{1}(.*?){0})'.format(attribute.group(), value.group()))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 190, in compile
    return _compile(pattern, flags)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 242, in _compile
    raise error, v # invalid expression
Comment: You need to use the regex module. Not re.
Comment: This will not work for Python 3.9 - I believe you should indeed use the *re* module.
Answer: I think a good solution would be to make use of split, and the '|' character in regex.
strs = []
strs.append('The pizza is so hot')
strs.append('Today I bought a hot and tasty pizza')
item = 'pizza'
adj = 'hot'
rets = []

for str_ in strs:
    ret = re.split(item + '|' + adj, str_, re.IGNORECASE)
    rets.append(ret[1].strip())

This works because when we consider the two strings individually we get a list with three elements.
ret = re.split(item + '|' + adj, strs[0], re.IGNORECASE)
print ret
['the ', ' is so ', '']

ret = re.split(item + '|' + adj, strs[1], re.IGNORECASE)
print ret
['Today I bought a ', ' and tasty ', '']

Since we know that both words can only occur once in the string, we can reliably take ret[1] as the result, because the string should only be split twice: once when we find one of the words, and again when we find the other. The OR character let's us split the list without knowing the order of the words ahead of time.
Answer: x="""The pizza is so hot
Today I bought an hot and tasty pizza
wow pizza and another pizza"""
print [j for i,j in re.findall(r"(pizza|hot)\s*(.*?)\s*(?!\1)(?:hot|pizza)",x)]

Try this with re.findall.


MySQL left join count not showing all entries from left table

Question: I have two tables: vcases(id,statusCategoryID,userID) and vstatuses(id,category).
I'm trying to display a dashboard where user can see number of cases they submitted under each category.
I tried left join but I'm not getting all the category names for a particular user.
This is what I'm doing:
SELECT vs.name as `catName`
      , COUNT(vs.name) as `count`
  FROM vstatuses vs
  LEFT
  JOIN vcases v
    ON vs.id = v.statusCategoryID
 WHERE v.userID = 2
 GROUP
    BY vs.names
 ORDER
    BY vs.id

I want to display like this
+----------------------------------------+
| Category | Submitted | Opened | Solved |
| Count    |    3      |   1    |   0    |
+----------------------------------------+

But I'm getting this
+-------------------------------+
| Category | Submitted | Opened |
| Count    |    3      |   1    |
+-------------------------------+

I want to include the categoryName even if there is no case under that category.
Comment: Change WHERE to AND
Answer: The filter should be with the ON clause
 LEFT JOIN vcases v ON vs.id=v.statusCategory AND v.userID = 2

Otherwise it's as if it's an INNER JOIN


Pass event object to directive

Question: I would like to pass the event object to a function in a directive
I have this in question.page.html
<ion-content appHideHeader [header]="header" [scrollEvents]="true">

and I have this in hide-header.directive.ts
@Directive({
  selector: '[appHideHeader]'
})
export class HideHeaderDirective {
  @Input() header: HTMLElement;

  constructor() { }

  @HostListener('ionScroll')onContentScroll(e) {
    console.log('scroll');
    console.log(e);
  }

}

when I scroll, I get this in the console
scroll
undefined

I tried this and it did not work (which make sense)
<ion-content appHideHeader [header]="header" [scrollEvents]="true" (ionScroll)="onContentScroll($event)">

So, I would like to pass $event to onContentScroll() function in the directive. How can I do that?
Answer: HostListener takes two argument first one is type of eventName,second one is array of values. you can pass $event like this
Try this:
@HostListener('ionScroll', ['$event'])onContentScroll(e) {
    console.log('scroll');
    console.log(e);
  }

Pass event object to directive


How to run select query on columns having comma separated values

Question: I know how to separate comma-separated column values into different columns. However, my question is how to query these columns in a where condition. I have a sample table named 'Details' below.
    User      Department
    ----      ----------
    User1     Admin, Accounts
    User2     Admin
    User3     Admin, Finance

Suppose I want to query the user who is in an Admin but not in Finance.  As you can see, User1 and User2 satisfy the condition, but User3 doesn't.
How can I build a select query to get the User3 as result
I know the 'like' operator can be used, but not sure how.
SELECT USER
FROM DETAILS
WHERE DEPARTMENT LIKE "Admin"||"Accounts"
AND NOT LIKE "Finance";

Answer: Use the operator LIKE:
SELECT USER
FROM DETAILS
WHERE ',' || DEPARTMENT || ',' LIKE '%,' || 'Admin' || ',%'
  AND ',' || DEPARTMENT || ',' LIKE '%,' || 'Finance' || ',%'
  AND ',' || DEPARTMENT || ',' NOT LIKE '%,' || 'Accounts' || ',%';

Or the function INSTR():
SELECT USER
FROM DETAILS
WHERE INSTR(',' || DEPARTMENT || ',', ',' || 'Admin' || ',') > 0
  AND INSTR(',' || DEPARTMENT || ',', ',' || 'Finance' || ',') > 0
  AND INSTR(',' || DEPARTMENT || ',', ',' || 'Accounts' || ',') = 0;

This will work if there are no spaces after each comma in the column DEPARTMENT.
See the demo.
Comment: That worked out well !
Answer: You're asking a question about a problem with the database design.  The problem disappears when the design error is rectified.
Specifically, your database is not 1NF: not in First Normal Form.  The department is not a scalar value, but represents a repeating group.  1NF requires all repeating groups be eliminated.
Normal forms were invented to help database designers define databases that can be fully exploited by SQL.  In the case of repeating groups, SQL has no operator for the nth value in a group (especially not in SQLite, where the repeating group is just a string).
To normalize your table, create this:
User      Department
----      ----------
User1     Admin
User1     Accounts
User2     Admin
User3     Admin
User3     Finance

Now your query can be written using existential quantification.  In SQL, that takes the form of where not exists (...)
Comment: I understand the discrepancy in DB design, but unfortunately, my privilege is limited to SELECT operations only. What you pointed out is the right way.


Create a Block to display Titles - even pages, view-pages, articles

Question: In my theme I need to hide the title of content, even the content-type pages and the Views page, and put it in a separate block placed in an other region than the content one.
I figured out how to pick the title from the content-type pages (plain-simple as is) but I figure some difficulties on the View Pages.
How can I hide the title of the node or the page view in the content and put in a block of another region?
Thanks for every answers!
Answer: Welcome to Drupal answers.

How hide a title? There are a lot of questions that have been answered about this topic. Here one of them.
How put the title in a block? You have different ways to achive this goal. if you only want to display the title with a content-type and the title is always in the same place, i would create a template for this content-type.
Another way to do it, you should build a module that declare a block. The content of this block(the title of the node) has to to be rebuild when a page is requested.
Comment: Thank you for the reply Rufein. Sadly, the most difficult task for me is how to manage Views Page.