Use Drush to update multi-site setup

Question: I have a multi-site setup where 3 different sites share the same codebase.  All of the modules are in the all/modules folder so they all have the exact same modules.  I want to update the modules and core for the codebase with drush but I can't find a way to do it.
There is no settings.php file in sites/default so drush is throwing an error.  Do I need to just create a dummy database so drush can connect and update the modules? Obviously I will have to run update.php on the sites after the updates are made.
The databases are separated, they just share modules and core.
Comment: Try `drush @sites `, works for me on a couple of multisite installs. I don't have aliases set up for those so I guess `sites` is a general alias
Comment: Why don't you want to separate the database?
Comment: Each site has a separate DB, they just share modules and core.
Comment: @Clive Hmm, that throws an error saying I need a higher bootstrap
Comment: Similar to  http://drupal.stackexchange.com/questions/45808/does-the-drush-up-command-work-on-multisite
Comment: @Clive When I run this `drush @sites pm-update`, I get this error. Could not find settings.php at sites/default/settings.php
Comment: @jsheffers I guess as you are using the different databases for all three sites therefor the `drush @sites pm-update` command is not working for you (as there is no common database). So may be you have to individually update the every site.
Answer: Instead of applying the updates to each individual site by using @sites which never worked, I was able to achieve it by running the updates on one specific site. Here is the code that worked for me:
drush -l example.com pm-update
example.com being the name of my symlink.  Side note: I did not have to create a drush alias for this to work.
Comment: This is the correct answer, presuming that you have the same modules enabled in each site.  If some of the other sites have additional modules enabled, you might miss those unless you pm-updatecode each site individually.  Also, it would be a good idea to copy the sites to dev, run the update there, test (!), then take the production sites offline, copy the code from dev, and run updatedb on all of the prod sites. Sometimes, an innocuous-looking update can take down a site, and there is no "undo" for updatedb!
Answer: Do you have 3 different sites/sitename.com/ directories? If so, you'll want to cd into each of them one at a time and run drush up in each.
The first time you run it it will download the new modules and run the update hooks on that site's DB and the next two times it will see that they're already downloaded so it will just run the update hooks on the other two sites' DB's.
Answer: I have a similar set up - multiple sites using the same codebase and different DBs. I use a shell script to run the same drush command through each site. The script is below - it's customised to my server set up. The relevant bits are:
My Drupal root directory is /var/www/drupal7
Each site (in drupal7/sites) contains ".d7." in the name.
The script below (called d7_all_sites) can run 3 drush commands on each of my sites: clear all caches, put sites in/out of maintenance mode, and update the database. The command is given by a parameter. So, when I update modules, I do this ...
$ d7_all_sites mm 1 ## puts all sites into maintenance mode
$ drush up ## updates the modules
$ d7_all_sites updb ## updates each site's DB schema
$ d7_all_sites mm 0 ## takes all sites out of maintenance mode

I'm a scripting novice, so any suggestions to improve the script are very welcome.
#!/bin/bash
# test that at least one parameter if given, else return error message & exit
if [ $# -eq 0 ]
then
echo -e "\n  You must supply a valid parameter ...\n    cc to clear caches.\n    mm [0 or 1] for maintenance mode (0=online, 1=offline).\n    updb to update databases.\n"
exit 2
fi
## clear all caches command
if [ $1 = "cc" ]
then
for SITE in `ls /var/www/drupal7/sites | grep ".d7."`;
do
echo
echo Clearing caches on $SITE ...
drush --uri=$SITE --root=/var/www/drupal7 cache-clear all
done
exit 0
fi
## maintenance mode
if [ $1 = "mm" ]
then
if [ $# -ne 2 ]
then
echo -e "\n  You must supply a parameter ...\n    0 for online.\n    1 for offline.\n"
exit 2
else
if [ $2 -eq 0 ]
then
text="online ..."
else
if [ $2 -eq 1 ]
then
text="offline ..."
echo -e "\n  You must supply a parameter ...\n    0 for online.\n    1 for offline.\n"
exit 2
fi
fi
fi
for SITE in `ls /var/www/drupal7/sites | grep ".d7."`;
do
echo
echo Putting $SITE $text
drush --uri=$SITE --root=/var/www/drupal7 vset --exact --yes maintenance_mode $2
done
exit 0
fi
# update databases
if [ $1 = "updb" ]
then
for SITE in `ls /var/www/drupal7/sites | grep ".d7."`;
do
echo
echo Checking $SITE for database updates ...
drush --uri=$SITE --root=/var/www/drupal7 --yes updatedb
done
exit 0
fi
# if no commands have been run, return an error message
echo -e "\n  You must supply a valid parameter ...\n    cc to clear caches.\n    mm [0 or 1] for maintenance mode (0=online, 1=offline).\n    updb to update databases.\n"

Answer: Here's what I do to update a multi-site setup:
for d in sites/*; do pushd $d; drush up -y; popd; done

Answer: It's in PHP, but this is what I use from inside my sites folder.
Example usage from the command line:
cd /path/to/drupal/sites
php drush_updates.php

The file:
<?php
/**
 * Run db updates on all of the sites in the multisite, using Drush
 */
print "\n\n***************************************************\n";
print "This script will find all of the site dirs and run drush updb -y on them.\n\n";

$start_dir = ".";
$files = scandir($start_dir);

foreach ($files as $file) {

  if (is_dir($file) && $file != "." && $file != ".." && $file != "all") {
    print "drush updb -y on $file...\n";
    chdir($file);
    system("drush updb -y");
    chdir("..");
  }
}

print "\n\n*******************************************\n";
print "Finished!\n\n";
?>

Use Drush to update multi-site setup


Selecionar uma lista de valores e dessa lista, selecionar o menor valor

Question: Estou querendo selecionar as 10 últimas inserções de uma tabela e dentre esses 10, retornar o menor valor. É possível fazer isso em uma única consulta?
Selecionando os 10 últimos valores:
<code>SELECT id_relevo FROM relevo
ORDER BY id_relevo DESC
LIMIT 10
</code>
Answer: Sendo direto, é possível fazer isso por exemplo utilizando uma subquerie.
<code> SELECT min(id_relevo) FROM
(SELECT id_relevo FROM relevo ORDER BY id_relevo DESC LIMIT 10) as minimo
</code>
Comment: É exatamente isso mesmo. Muito obrigada!


Some version of Itô isometry with conditional expectations

Question: Let $B = (B_t)_{t \geq 0}$ be a Brownian motion, $ \mathcal{F}=
 (\mathcal{F}_t)_{t \geq 0}$ the natural filtration associated to $B$, $u \in L^2_{a,T}$ (that is, $u$ is an stochastic process $u = (u_t)_{0 \leq t \leq T}$ adapted to $\mathcal{F}$ so that $\int_0^T E\left[u_t^2\right] dt < \infty$), and define $X = (X_t)_{0 \leq t \leq T}$ as
$$
X_t = \left(\int_0^t u_s dB_s \right)^2 - \int_0^t u_s^2 ds
$$
I'm trying to prove that $X$ is a martingale. To do so, I'm just going through the definition: if $t < r$, then it must hold that
$$
E\left[X_t - X_r | \mathcal{F}_r \right] = 0
$$
I've been to see, after some computations, that
$$
E\left[X_t - X_r | \mathcal{F}_r \right] = E\left[\left. \left(\int_r^t u_s dB_s \right)^2  \right| \mathcal{F}_r \right] - E\left[\left. \int_r^t u_s^2 ds  \right| \mathcal{F}_r \right]
$$
So it all reduces to prove that this last expression is zero. I like to think about this as some sort of Itô isometry, since this would trivially equal zero if the expectations were not conditional.
I've seen that this expression vanishes when we take, for instance, a simple stochastic process like $u_t = \mathbb{1}_{[0,T]}(t)$, and I feel that the proof of the general case must have something to do with the fact that the filtration arrives up to the same time the integrals integrals are taken from (specially after seeing this). Any ideas on how to finish this?
Thank you very much!
Answer: Let $G \in \mathcal{F}_r$. Using that
$$1_G \int_r^t u_s \, dB_s = \int_r^t 1_G u_s \, dB_s \quad \text{a.s.} $$
(see the lemma below) it follows from Itô's isometry that
$$\begin{align*} \int_G \left( \int_r^t u_s \, dB_s \right)^2 \, d\mathbb{P} &= \int \left( \int_r^t u_s 1_G \, dB_s \right)^2 \, d\mathbb{P} \\ &= \mathbb{E} \left( \left| \int_r^t u_s 1_G \, dB_s \right|^2 \right) \\ &= \int_r^t \mathbb{E}(u_s^2 1_G) \, ds \\ &= \int_G \left( \int_r^t u_s^2 \, ds \right) \, d\mathbb{P}. \end{align*}$$
As $G \in \mathcal{F}_r$ is arbitrary, this shows that $$\mathbb{E} \left( \left[ \int_r^t u_s \, dB_s \right]^2 \mid \mathcal{F}_r \right) = \mathbb{E} \left( \int_r^t u_s^2 \, ds \mid \mathcal{F}_r \right).$$

Lemma For any $G \in \mathcal{F}_r$ it holds that $$1_G \int_r^t u_s \, dB_s = \int_r^t 1_G u_s \, dB_s \quad \text{a.s.} \tag{1}$$

Proof: It is straight-forward to check that $(1)$ holds for simple functions $u$, i.e. functions of the form $$u(s) = \sum_{j=1}^n \xi_{j-1} 1_{[t_{j-1},t_j)}(s)$$
where $r \leq t_0 < \ldots < t_n \leq t$ and $\xi_{j-1} \in L^2(\mathcal{F}_{t_{j-1}})$. Now if $u$ is an $\mathcal{F}$-adapted process such that $\int_0^t \mathbb{E}(u_s^2) \, ds < \infty$, then there exists a sequence of simple functions $(u^{(n)})_{n \geq 1}$ such that $\int_0^t \mathbb{E}(|u^{(n)}(s)-u(s)|^2) \, ds \to 0$ as $n \to \infty$ and $\int_r^t u^{(n)}_s \, dB_s \to \int_r^t u_s \, dB_s$ in $L^2$. Then it follows (e.g. from Itô's isometry) that $\int_r^t u^{(n)}_s 1_G \, dB_s \to \int_r^t u_s 1_G \, dB_s$. Using that the assertion holds for each $u^{(n)}$ we obtain $$\begin{align*} 1_G \int_r^t u_s \, dB_s &= L^2-\lim_{n \to \infty} 1_G \int_r^t u^{(n)}_s \, dB_s \\ &= L^2-\lim_{n \to \infty} \int_r^t 1_G u^{(n)}_s \, dB_s \\ &= \int_r^t 1_G u_s\, dB_s. \end{align*}$$
Comment: Thank you very much for you answer! It is just what I needed :)
Comment: @AlejandroMolero You are welcome.
Comment: Hey Saz this is an old question but still; in the first of the last three equalities on the left hand side, shouldn't it be $1_G \int_r^t \color{red}{u_s} \, dB_s$ instead?
Comment: @RScrlli Yes, of course, thanks.


Econometrics advice needed on unpaired t-test

Question: There are responses of my school's alumni on the skills they perceive they acquired during the studies and are required from their job now. 18 skills evaluated from 1 to 5 (ordinal values, right?). Also they are 18 classes of graduation (around 30 responses from each year). There are also such attributes of the respondents as a master's degree, current status, so on. There is no regression model I could construct up to this moment, but I'm at least interested if the difference in averages of the skills between different groups are significant. I try R over and over. I managed only to tabulate the means for the groups. But then I'm lost.

Are there tests I should run the data through first?
How to know what distribution my data follows?
And what are the ways to see if the means differ significantly across the groups?
Is it possible without a regression model at all?
Comment: Welcome to this site! What is the question? As stated, it looks like it is about how to use R to perform two- or multiple-group comparisons (as you title suggests).
Comment: Thanks for editing my question. I made it more specific and added questions in the end.
Comment: Could you be more specific? I see at least five questions you included, all of them very broad, what makes quite unanswerable. Basically, your question could be summarized as "tell me everything one needs to know to analyze such data" what makes it too broad.
Answer: Ordinal responses on the Likert scale (1-5) are not quantitative, and you can't take, for example, a mean or average. There is no easily definable "distance" between a score of 4 and a score of 5, for example. You will have to look into some other types of statistics, depending on how deep you want to dig. Here is an interesting place to start, with some suggestions for ordinal or interval data:
http://www.ats.ucla.edu/stat/mult_pkg/whatstat/
Good luck!
Comment: I should add that you might want to look into frequency analysis - particularly contingency table analysis (tests of independence). Independent variable - Acquired/Required; Dependent variable(s) - ordinal values.


Hibernate features that aren't part of JPA

Question: Can you point out some Hibernate features that aren't part of the JPA specification? I've been searching for a while and could not find anything related to this topic.
Concrete examples would be helpful.
Answer: The javadocs for the hibernate specific annotations is probably a good place to start.
http://docs.jboss.org/hibernate/orm/4.1/javadocs/org/hibernate/annotations/package-summary.html


Computing number of points in elliptic curve through frobenius endomorphism

Question: I got the following question where I stuck at the moment. Given is the elliptic curve (EC) equation: $E: y^2+3xy+y=x^3+4x+4$ over the finite field ${\bf F}_5$
The first task is now to find out all possible points on the curve by just trying out all possible values for x.
For this I got the possible values: $E({\bf F}_5)=\{(2,0),(2,3),(4,1),P(inf)\}$ (don't know if its 100% correct)
P(inf) is the infinite point of the curve.
The next task is to find the characteristic polynomial of the Frobenius endomorphism and to use this in order to calculate the number of points in $E({\bf F}_{25}).$
In order to get the characteristic polynomial I found for the trace of the Frobenius endomorphism is: $\alpha_5=5+1-t=4,$ so must be $t=2.$
To get now to the char. polyn. I have to find the roots for the equation of the char. polyn.: $X(T)=T^2-tT+q=T^2-2T+5.$
But my problem is now, that I cannot find any roots that fit to this equation $T^2+2T+5.$ Maybe you can help me? Thank you!
Comment: the points are ok
Comment: Hello Ovomaltine! At which university do you study? I have the same exercise and I wonder if we are at the same uni. :)
Comment: It might be :) RUB
Answer: The roots of $T^2-2T+5$ are $\rho_{1,2}=1\pm 2{\rm i},$ so
$$\#E({\bf F}_{p^2})=p^2+1-(\rho_1^2+\rho_2^2)=26-(-6)=32.$$
Comment: you try to solve a problem with elliptic curves and you never seen the quadratic formula? (http://en.wikipedia.org/wiki/Quadratic_formula)
Comment: Thank you for this fast answer. Can you please give me a short hint how you got the solutions of 1+-2i as the complex roots of the char.polyn.? Thank you


Minimum Variance Estimators that Attain the Cramér-Rao lower bound

Question: The probability mass function of a negative binomial random variable $X$ is given by $$P(X=x\mid\theta)= {r+x-1 \choose x}(1-\theta)^x\theta^r$$ and $\Bbb E(X\mid \theta)=\frac{r(1-\theta)}{\theta}$.
Does this model admit a minimum variance unbiased estimator that attains the Cramér-Rao lower bound?
What I have tried:
I have worked out the maximum likelihood estimator $\hat{\theta}$ to be $\frac{r}{r+x}$  and the CRLB to be  $\Bbb V(\hat{\theta}) \geq \frac{1}{I(\theta)}= \frac{\theta^2-\theta^3}{r}$.
I know that if the estimator attains the CRLB then we know that we have found a Minimum Variance Unbiased Estimator. Also if the variance of the estimator is equal to the CRLB then it is an MVUE.  However I am unsure of how to calculate the variance of $\hat{\theta}$.
Thank you for your help!
Answer:
I know that if the estimator attains the CRLB then we know that we have found a Minimum Variance Unbiased Estimator. Also if the variance of the estimator is equal to the CRLB then it is an MVUE.

An UMVUE (Unformly Minimum Variance Unbiased Estimator) rarely attains the CRLB.
Moreover: if a family of rv's belongs to the exponential family (as it is the case) always exist an estimator that attains CRLB.
To verify that an estimator attains the lower bound there is a IFF condition:

An estimator $T$ attains CRLB iff there is a function $b(n,\theta)$
such that
$$\sum_{i=1}^n\frac{\partial}{\partial\theta}\log f(x_i;\theta)=b(n,\theta)[T-\mathbb{E}[T]]$$

In your case you have
$$\sum_{i=1}^n\frac{\partial}{\partial\theta}\log f(x_i;\theta)=\frac{nr}{\theta}-\frac{\Sigma_i X_i}{1-\theta}=\underbrace{-\frac{n}{(1-\theta)}}_{=b(n,\theta)}\Bigg[\overline{X}_n-\frac{r(1-\theta)}{\theta}\Bigg]$$
Thus $\overline{X}_n$ is UMVUE for $\mathbb{E}[X]$ and it attains CRLB

References taken from Mood Graybill Boes, McGraw Hill
Comment: I'm sorry I forgot to that for this problem it is a single observations meaning $n=1$ so in your last line of working would it not go to $\frac{r}{\theta}-\frac{1}{1-\theta}$ ?
Comment: @PadChipper : if $n=1$ you get $ \frac{r}{\theta}-\frac{X_1}{1-\theta}$ but the result does not change. Since you're new here, I would like to encourage you to click the check mark if this answer was helpful for you. It'll encourage others to answer your questions in the future


Confidence Levels for Mean of measured distribution

Question: I have measured some values. These values are already aggregates (in principle average values). The values have a "non-nice" distribution, for example . They come from different sources with different setups, however they all measure the same quantity.
I now want to calculate different things.

mean of the distribution - easy, done.
statistical error of the overall mean. Is it just $\frac{\sigma}{\sqrt{n}}$ with $\sigma = \sqrt{Var(\text{value})}$? If so, why? I have a physics background and there we argued that natural quantities are always Gaussian-distributed. Now this here is a technical measurement. I do not see how I could apply the Gaussian errors or the central limit theorem here as we don't sum independent random variables.
CLs for the mean. How would I calculate CLs that would say something like "with 95% confidence, the mean of the distribution lies within $[x-\sigma_-,x+\sigma_+]$". As you can see, I would like to have asymmetric CLs because our measurements can have upper and lower technical limits (for example, speed measurements will always be > 0) and I don't want the CLs to span the impossible value range.

And as I had some discussion with my colleagues about it (probably a new question, but still...): how can subsampling affect the calculated quantities (errors and CLs) and when should I do it? (short explanation is enough)
Thank you so much. xo.
Answer: Since it looks unlikely that your question will get an answer soon, I decided to have a go. This is part answer and part request for further clarification. The things I seek clarification of may give you some idea why you didn't get answers (besides the reduced presence of people around the start of January).
(Besides answering some of the question, this must go into an answer because there are far too many questions to fit into a comment, or even two.)

I now want to calculate different things.
mean of the distribution - easy, done.

Well, no, it's not done. You calculated something, sure, but it almost certainly wasn't what you just said. You can't calculate the mean of the distribution from which the data were drawn ($\mu$) unless you have the population -- and from your description it sounds like you have some kind of sample. So the thing you calculated would be a sample mean.
If that sample was a random sample* from the population of interest (and I'm not sure this is the case from your brief description) then your sample mean would be a reasonable way to estimate the population mean (the mean of the distribution).
For a random sample, the estimator $\bar{X}$ has the desired expected value ($E(\bar{X})=\mu$).
* certain kinds of non-random samples (e.g. where one identifies the subpopulations you indicate are present and then samples randomly within each of those) can be used but I'll avoid discussion of that unless it turns out to be necessary.

statistical error of the overall mean.

That depends on what "statistical error" means (it's not an especially standard term in statistics). If you mean "the standard error of the estimate of the population mean", that would be $\sigma/\sqrt{n}$, but note that you don't know $\sigma$ any more than you knew $\mu$. You can estimate it from the sample of course (typically by the sample standard deviation $s$), subject to the same requirement of random sampling.

there we argued that natural quantities are always Gaussian-distributed

That would seem highly unlikely to me (some such quantities would presumably be necessarily positive, for example). What was the basis of this argument?

Now this here is a technical measurement.

Your terminology is unfamiliar. Can you either avoid the jargon or explain its meaning? What's a technical measurement? What's a natural quantity? Why is there a distinction between them with respect to estimating a mean?
*Edit (much later): it occurs to me that you might be referring to a measurement using an instrument that has some measurement error. Is that the kind of thing you mean?*

I do not see how I could apply the Gaussian errors or the central limit theorem here as we don't sum independent random variables.

Now I am really confused. When you calculated a sample mean you didn't sum the observations along the way? Or are you saying the observations you averaged were dependent? (Or perhaps you mean to say that you didn't have very many values, in which case standardized means would not be close to normally distributed.)

measurements can have upper and lower technical limits

I'm not 100% sure what you're saying there. Do you just mean the variable being measured may be bounded (e.g bounded below, for things that are necessarily positive)?

how can subsampling

What kind of subsampling are you talking about? What is it precisely you're proposing to do?
Answer: First of all, the mean is not a good measure of location for everything. For uniform distributions, the average of Min$[X]$ and Max$[X]$ works better. For Cauchy distributions median works better, and properly trimmed mean better yet. For Pareto distributions with exponents $<1$, harmonic mean works better and the mean value is unphysical. I would test various measures of location of the data in an attempt to identify which of many would be more representative of location. Also, for an arbitrary f(x) provided that one such is listed, it may be possible to obtain a first moment and maybe even a second moment about the mean. But, it would still need testing for best location measure.
Second, the confidence intervals of data can be calculated directly from that data as quantiles. That is, assuming that the plot is from observed data, I would re-sample it with replacement n-fold to establish a distribution of mean values, and then take my confidence interval from that. If the curve is not from observed data, but does have an f(x), I would randomly sample f(x) to obtain n-fold means and then establish their confidence interval. I would not use that procedure for Cauchy or other fat-tailed distributions (e.g., Pareto with small magnitude exponents), for uniform distributions or other distributions for which the mean is not a good measure of location.  Confidence intervals of a location parameter would be a bit more complicated, because one has to find a proper location first. Next, if all else fails, the confidence intervals of a location parameter could be estimated from bootstrap. And, symmetric they would only exceptionally be.
Comment: Could you explain, or give an example, of your assertion "confidence intervals of data can be calculated directly from that data as quantiles"?  This is vague.  In many cases like the one in the question it is incorrect, but there are applications (such as nonparametric CIs for population quantiles based on simple random samples) where something like what you describe is a good procedure.  Could you therefore tell us what parameter these CIs are intended for,  which quantiles of the data you would use, and in what circumstances your approach could be expected to work well?
Comment: You describe a simple form of a bootstrap, but that important qualification is nowhere in your post.  Apparently your phrase "that data" really means the *bootstrap distribution* rather than the original data.
Comment: @whuber Yes, that was my intent, but for politeness sake I was not about to change the text until this interlocution ran its course. Now I shall.
Comment: @whuber Sure, assuming that the plot is from observed data, I would re-sample it with replacement $n$-fold to establish a distribution of mean values, and then take my confidence interval from that. If the curve is not from observed data, but does have an $f(x)$, I would randomly sample $f(x)$ to obtain $n$-fold means and then establish their confidence interval. I would not use that procedure for Cauchy or other fat-tailed distributions (e.g., Pareto with small magnitude exponents), for uniform distributions or other distributions for which the mean is not a good measure of location.
Comment: @Whuber Moreover, I would test various measures of location of the data in an attempt to identify which of many would be more representative of location. Also, for an arbitrary $f(x)$ provided that one such is listed, it may be possible to obtain a first moment and maybe even a second moment about the mean. But, it would still need testing for best location measure.


Create custom signup block with mailchimp module?

Question: I'm looking for code examples for creating custom mailchimp signup forms that use the mailchimp api integration provided by the mailchimp module.
Context: I have a D7 site using a standard embedded sign-up form for mailchimp. I just recently switched the site to https, which unfortunately causes some browsers (e.g. firefox) to throw a scary message when a user clicks the submit button on the sign-up form, because standard mailchimp embedded forms can only use http.
The mailchimp module uses the mailchimp API, which allows secure connections, so that's the obvious solution. And the mailchimp module automatically provides a block for each list. But the module makes assumptions that I don't want. So, instead of the automatic block provided by the mailchimp module, I'd like to create my own block(s) with a sign-up form that uses the api, so that I have more control over the look and feel of the form.
Also, I know the webform mailchimp module provides a mailchimp component for webform, (there's a good write up here) but I'd like to explore creating my own forms as a first step.
Comment: Just curious about the down vote. The help text for down voting says "does not show any research effort; it is unclear or not useful". For a question like this, am I expected to first try to code a solution myself, then post the code I'm trying to use (that presumably doesn't work)? Or is it OK to ask first if anyone has done it already?
Answer: In the end, this is what I did:

Installed the mailchimp module and connected drupal to a list in mailchimp using normal instructions and an API key that mailchimp provides.
Created a new custom module that creates and displays blocks using standard hook_block_info and hook_block_view code.
Created a very simple form with hook_form, with a companion submit function, hook_form_submit, and add this form to the block(s) created above.
In hook_form_submit, I open a connection to the mailchimp api with:
$q = mailchimp_get_api_object();

Then subscribe the user with:
<code>$success = $q->listSubscribe($list_id, $email, $merge_vars, 'html', TRUE, TRUE);
</code>
The above functions are documented in the mailchimp api.
So, in the end, I'm not really using the Drupal mailchimp module for anything other than providing access to mailchimp api over a secure connection (the drupal site is running https). The main advantage of this approach is complete control over the look and feel of the forms that appear in the blocks, and the actions taken when a user submits.
Another advantage: Because I'm using hook_form_submit to control processing once the form is submitted, I can add the form location (using request_path()) to the merge variables that are passed back to mailchimp. That way, the form is the same on every page that it appears, but the location is passed back to mailchimp as part of the sign-up process.
Answer: I did something similar to @Dave Bruns in my hook_form_submit but added in the mailchimp_addto_queue function so this gets triggered when cron runs.
<code>// Connect to MailChimp API.
$q = mailchimp_get_api_object();

// Send data to our Mailchimp list for this site.
$args = array(
  'list_id' => '91919191',
  'email' => $email,
  'merge_vars' => array('fname' => 'Lee', 'lname' => 'Woods'),
  'format' => 'html',
  'double_optin' => FALSE,
  'update_existing' => TRUE,
  'replace_interests' => TRUE,
  'confirm' => TRUE,
);
mailchimp_addto_queue('mailchimp_subscribe_process', $args);

mailchimp_subscribe_process($list_id, $email, $merge_vars, $double_optin, $format, $update_existing, $replace_interests, $confirm);
</code>


Understanding the Flash Player 10 Security Model for File Uploads

Question: I've been reading about the security restrictions for file uploads in Flash Player 10. According to the FileReference docs for upload(), the upload does not have to be triggered by a user-initiated action (the browse() does, but that's another story). If it did, that would force an awkward user experience for multi-file uploads, since only one upload can occur at once -- so the user would have to click (or press a button) once per file to initiate the upload, but only when the previous file had finished uploading.
The documentation for URLLoader.load(), on the other hand, states:

In Flash Player 10 and later, if you use a multipart Content-Type (for
  example "multipart/form-data") that contains an upload (indicated by a
  "filename" parameter in a "content-disposition" header within the POST
  body), the POST operation is subject to the security rules applied to
  uploads:
The POST operation must be performed in response to a user-initiated
  action, such as a mouse click or key press.

This Flash Security article corroborates the URLLoader documentation (see the "POST APIs" section).
The original whitepaper, however, does not state this -- only that a FileReference browse must be in response to a user-initiated action, not the (potentially URLLoader-driven) upload itself:

When a SWF file uses the FileReference.browse() and
  FileReference.upload() methods to upload a file to a server, Flash
  Player enforces two security rules:

FileReference.browse() must be called from within a user-event handler (mouse or keyboard event).

[...]
Flash Player enforces these same rules any time a
  networking API is called to perform a POST that appears to the server
  to contain an upload.

As far as I can tell from actual use of the URLLoader API to upload a file, the uploads indeed don't need to come from a user-initiated action; but, is this because I'm using a debug version of the player, or because the documentation is wrong? (Or something else?)
TL;DR: The documentation contains conflicting information, and I don't trust my field tests (in the face of docs that say they shouldn't work). Can URLLoader be used to upload a file without user interaction? Or only FileReference? (That would kill most file pre-processing possibilities, which is what I happen to be interested in doing!)
Answer: I believe that Adobe wants to have it so that you can NOT use URLLoader to upload a file without interaction.  I just think that they happened to not do it in the best way and you can get around it depending on how exactly you are using the URLLoader to upload the file (if you put a filename in the POST for the URLLoader it should error out, but you can get around that by Base64 encoding the file and sending that with the URLLoader to php).
Take a look at this post.  Read through the comments in there too they seem to address the issue.  Hopefully this helps a little bit.
Answer: You doesn't got errors, because you are running in debug. Got the same problem while working on my speedtest project.
So for the questions:

FileReference can't upload files without user interaction.
URLLoader can't upload files without user interaction if you are using POST, multipart/form-data and filename properties.
You can upload files with URLLoader if you are using content-type like application/octet-stream and putting the file body encoded (for example in base64) in you post request. That means, if you are using PHP, so you will work not with the $_FILES, but with the $_POST array, to get your file.
Working in debug mode on local machine, won't trigger the URLLoader restriction error.
Comment: As you have posted in your question, and according to adobe.com, `FileReference.browse()` must be called before `FileReference.Upload()`.
Comment: Ah, it's because of the Debug player! But, as far as I know, FileReference *can* upload files without user interaction (it just can't *browse* for them). I hate double standards.
Comment: Yep, I understand :-) But imagine the user clicks a "browse" button and selects 17 files through a `FileReferenceList`. Those 17 files can then be uploaded without further user interaction. But, if we want to modify them in some way before uploading them (say, resizing image files on the client), then the user would have to click 17 more times, once to initiate each (URLLoader) upload. That's what I meant by double standards. Of course, nobody's *actually* going to force their users to click 17 times when there're acceptable workarounds (such as Base64 encoding).
Comment: It isn'so. I was using MultiPowerUpload, so there to upload you need 2 clicks, the first for browse, then you can manage images, like crop or resize, and then the second click to upload all of them. If you wish, i'll post some part of code, how is it made.
Comment: Sure, I'm really curious how you got that to work! (The only way I can think of is to start all the uploads at once.)
Comment: It is made so: after user clicks the upload button, all files selected from `FileReference.Browse()` are sent in binary data to the server with `URLLoader` in one recursive function walking through filelist. Really no magic. For additional help an [MultipartUpload](http://code.google.com/p/nascomaslib/source/browse/trunk/src/be/nascom/flash/net/upload/UploadPostHelper.as?spec=svn62&r=62)  class is used to build correct http headers.
Comment: Just realized I never accepted an answer on this one. What I ended up doing is changing the content-type on my URLLoader upload to 'application/octet-stream', then sending an 'x-content-type' of 'multipart/form-data' which my custom script on the server detects and handles appropriately.


Gulp CSS minify & gzip + django-compressor not working

Question: I am trying to minify and compress my css (and later js) and serve it. To this end I first minify and compress it with gulp and then serve the gzipped files with django-compressor (so only http request will be made).
I pretty much followed this guide:
http://www.revsys.com/blog/2014/oct/21/ultimate-front-end-development-setup/
Using directly the gzipped files works good, however when I try to group them with django-compressor I get the following error:
<code>UncompressableFileError at /
UnicodeDecodeError while processing '..../static/mincss/filename.min.css.gz'
with charset utf-8-sig: 'utf8' codec
can't decode byte 0x8b in position 1: invalid start byte
</code>
Which corresponds with the compress tag on:
<code>    {% compress css %}
      <link rel="stylesheet" href="{{ STATIC_URL }}mincss/filename.min.css.gz">
...more files
    {% endcompress %}
</code>
I'm 99% sure that the gzipped generated files are correct. They are us-ascii (subset of utf-8) and they contain the *.min.css file.
My relevant settings (that I know of) for the issue are the same as the ones listed on the guide. The only difference is that on the guide he includes the css files like this:
<code>{% compress css %}
<link rel="stylesheet" href="{% static "stylesheets/main.css" %}" />
<link rel="stylesheet" href="{% static "stylesheets/some-other.css" %}" />
{% endcompress %}
</code>
But this way (though it works) doesn't use the gzipped files, not even the minified ones. What am I missing?
Comment: Do you have COMPRESS_ENABLED=True in your settings as well? It is easy to miss. It looks to me that django-compressor thinks you're passing it a raw CSS file rather than one already GZIP'd and minified, but that's just a guess.
Comment: Yes unfortunately I'm already passing it.
Answer: The included file must not contain the gzipped extension. Just providing the file name (*.css) compressor will automatically check and load de gzipped version of the file (needs to have the same name plus  .gz).
Be aware it will load the compressed files only on production (with debug=false and offline compression enable)


factorization of 2 numbers

Question: I tried to factor the numbers $1013^{13}+331\#$ and $98!+76!+54!+32!+1$ with GMP-ECM
because the quadratic sieve takes very much time. Perhaps someone factors
one of those numbers for me. The second number has a prime factor of 25 digits,
namely $1005693665747024080598971$. For those who are not familiar with the
number theory notations: $!$ is the factorial $n!=1\cdot 2\cdot 3\cdot\ldots\cdot n$ and $n\#$ is
the product of primes up to $n$: $n\#=2\cdot 3\cdot 5\cdot 7\cdot\ldots\cdot n$, if $n$ is a prime.
And please do not ask why I am interested in these factorization. It is
just curiousity because in the net it is stated that such numbers are already
quite easy to factor. Useful programs are GMP-ECM or msieve downloadable from
the net.
Comment: @draks... Mods can't do that anymore. The user has to contact SE directly http://math.stackexchange.com/help/user-merge
Comment: I assume (the other) Peter might be referring to the fact that 512-bit moduli are considered to be weak for crypto schemes like RSA due to being factorable withing reasonable time-frame.
Comment: The first, as 1013^13 + 331, gives 336 * prime number.  Prehaps the # stands for something different?
Comment: Wendy : Please read the whole text, I explained the '#'.
Comment: Peter, this is the third account you created: http://math.stackexchange.com/users/79589/peter , http://math.stackexchange.com/users/79596/peter and this one. Please ask a moderator to merge them! I flagged your account to draw a moderator's attention...
Comment: @DoubleAA, good to know. Peter, where was that stated in the net? Can you provide a link? How did you 1005693665747024080598971?
Answer: The first one took about 60 hours of NFS-ing on a moderately slow machine with unoptimized factoring settings while the machine was being used for other purposes too:
1013^13 + 331# = 13660997293197200778560512676198053659658942317253 *
469117945090530664165653254310752426123381482366114189309329070591871468575459348391

The other one took about 64 hours; the smallest factor being discovered by ECM pretty quickly and the rest of the time spent on NFS-ing (again, unoptimized, running in background, ...):
98!+76!+54!+32!+1 = 1005693665747024080598971 *
79146647927616255967923163095656379252005739066059813 *
118432315205629597504117998137752645490949757279339848413269947393226465090487

Altogether, this supports the statement that numbers of this size are quite easy to factor with current hardware. The time could be cut down to about one day on a dedicated, reasonably modern workstation and further cuts would be possible with better tuning of the factoring settings.

factorization of 2 numbers


How to calculate confidence interval for proportion of means

Question: I have a variable (v_1) calculated as the ratio of the mean for variable 2 (v_2) and variable 3 (v_3). How do I calculate a confidence interval for this ratio?

v_2<-c(1,5,6,3,4,9,7,3,2,5,6,7)
v_3<-c(7,11,22,5,4,3,8)

v_2_mean<-mean(v_2)
v_3_mean<-mean(v_3)

v_1<-v_2_mean/v_3_mean

Answer: This page on cross validated suggests that if you are willing to make the assumption of Gaussian distribution in both samples, the mratios package contains the function ttestratio() which will perform a t-test for the ratio. More importantly for you, it will also calculate a confidence interval:
v_2 <- c(1,5,6,3,4,9,7,3,2,5,6,7)
v_3 <- c(7,11,22,5,4,3,8)

mratios::ttestratio(v_2, v_3)$conf.int[1:2]

# [1] 0.3000213 1.6524510


Problemas com o this.router.navigate

Question: Olá,
meu problema é o seguinte, preciso deixar o dinâmico sempre que jogar um valor diferente na navegação, esse é meu código:
editarForm() {
const valor = ('X');
this.router.navigate(['/' + valor + '/edit/'], { relativeTo: this.route });

}
quando lanço um "valor" qualquer nessa função o resultado é o abaixo:
core.js:15723 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'edit'

Error: Cannot match any routes. URL Segment: 'edit'
    at ApplyRedirects.push../node_modules/@angular/router/fesm5/router.js.ApplyRedirects.noMatchError (router.js:2469)
    at CatchSubscriber.selector (router.js:2450)
    at CatchSubscriber.push../node_modules/rxjs/_esm5/internal/operators/catchError.js.CatchSubscriber.error (catchError.js:34)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (Subscriber.js:80)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (Subscriber.js:60)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (Subscriber.js:80)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (Subscriber.js:60)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (Subscriber.js:80)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (Subscriber.js:60)
    at TapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/tap.js.TapSubscriber._error (tap.js:61)
    at resolvePromise (zone.js:831)
    at resolvePromise (zone.js:788)
    at zone.js:892
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
    at Object.onInvokeTask (core.js:17289)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
    at drainMicroTaskQueue (zone.js:601)
    at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:502)
    at invokeTask (zone.js:1744)
No front para entenderem a ideia é o seguinte:
Comment: Pelo erro o problema não parece ser na variável, 2 coisas: utilize template strings para ficar mais legível o código `/${valor}/edit`, e tente colocar uma url que exista para ver se a página é carregada.
Answer: Precisas configurar as rotas no seu módulo de rotas.
No módulo:
{
     path: 'edit/:valor',
     component: SeuComponent,
},

No TS:
this.router.navigate(['edit', valor], { relativeTo: this.route.parent });

Problemas com o this.router.navigate


Error from a feature module build in Angular 2, regarding the scss file declared in styleUrls array

Question: This is the NgModule of my feature module:
<code>@NgModule({
    imports: [
        CommonModule,
        FormsModule,
        ReactiveFormsModule
    ],
    declarations: [
        CustomCardComponent,
        StyledDirective
    ],
    exports: [CustomCardComponent]
})

export class CustomCardModule {}
</code>
Inside the component:
<code>import {Component, OnInit, Input} from '@angular/core';
others imports

@Component({
    selector: 'my-custom-card',
    templateUrl: './custom-card.component.html',
    styleUrls: ['./custom-card.component.scss']
})

export class CustomCardComponent implements OnInit { ... }
</code>
The error is about the .scss file I'm declaring using styleUrls array, if I remove it the component works, on the other hand I get this error:
<code>/~/css-loader?sourceMap!./~/postcss-loader!./~/sass-loader!./~/raw-loader!./~/postcss-loader!./~/sass-loader!./src/myModules/custom-card-fmodule/custom-card.component.scss
Module build failed:
$cardWidth: 220px;
             ^
      Invalid CSS after "module.exports": expected "{", was '= ".panel-default >'
      in /Users/MyName/Development/Angular2/signup-app/src/myModules/custom-card-fmodule/custom-card.component.scss (line 1, column 15)
Error:
$cardWidth: 220px;
             ^
      Invalid CSS after "module.exports": expected "{", was '= ".panel-default >'
      in /Users/MyName/Development/Angular2/signup-app/src/myModules/custom-card-fmodule/custom-card.component.scss (line 1, column 15)
    at options.error (/Users/MyName/Development/Angular2/signup-app/node_modules/node-sass/lib/index.js:292:26)
 @ ./src/myModules/custom-card-fmodule/custom-card.component.scss 4:14-339
</code>
but the .scss file doesn't have any error, and this happens only for my custom module, it works perfectly for all other components (that are not feature-modules)
Answer: You need sass-loader, from this link:
https://github.com/AngularClass/angular2-webpack-starter/wiki/How-to-include-SCSS-in-components
<code>        Command line inside project folder where your existing package.json is:
            npm install node-sass sass-loader raw-loader --save-dev

    In webpack.common.js, search for "rules:" and add this object to the end of the rules array (don't forget to add a comma to the end of the previous object):

    {
      test: /\.scss$/,
      exclude: /node_modules/,
      loaders: ['raw-loader', 'sass-loader'] // sass-loader not scss-loader
    }
</code>


How should I test for autocorrelation in this time series context?

Question: I have data sets in which different people estimate a certain quantity. They potentially can see the estimates of anyone who participated before them, but in practice they're only likely to look at the last few estimates that were made before them. For that reason I am expecting some autocorrelation.
Here's an example in which 199 people (x-axis) made estimates mostly falling between 900 and 1300. There is little visual evidence of autocorrelation here, but autocorrelation does seem to be present in some of my other data sets.

I'm interested to test for the level of autocorrelation and if it is high to examine the effects of reducing it, either by providing different instructions to the participants or by performing some statistical manipulation to the data.
I'm familiar with testing for autocorrelation using the Durbin-Watson test in a regression context, but am not sure how to proceed here. Almost all google searches related to autocorrelation seem to relate to a regression context.
Comment: What about Breusch-Godfrey or Ljung-Box tests for autocorrelation? They are more general than the Durbin-Watson test and are applicable to raw data (and not only to residuals from a regression). What about looking at an ACF plot and seeing whether any of the ACF bars stick out of the confidence bound (which is drawn under the null of no autocorrelation)?
Answer: You could assume that if there is any autocorrelation at all, there will definitely be autocorrelation at lag 1. The null hypothesis to test would be that the data are white noise, and the alternative is that there is autocorrelation including $\rho(1) \neq 0$.
Therefore you can estimate the correlation at lag 1 and apply the standard t-based test for correlation. In the estimation you can only use non-overlapping pairs of samples $(1,2)$, $(3,4)$, … so that sample pairs are independent under H0. If you are worried about nonnormality, use Spearman correlation and use an appropriate test for that.
To avoid having to use non-overlapping pairs of samples, you could also determine the null distribution empirically by comparing the actual correlation to the distribution that arises in timeseries that are generated by resampling with replacement (testing the null hypothesis that the time series is stationary white noise).

Here are concrete results based on the actual data provided in a comment, analyzed using Matlab's corr and xcov. The timeseries of 197 samples is stored in the vector x.
lag-1 autocorrelation: to compute without overlap, so that the sample pairs are independent under the null hypothesis of white noise:
>> [rho, pval] = corr(x(1 :2: end - 1), x(2 :2: end))
rho =
       -0.0262418232219902
pval =
         0.797571094920343

Looking at the data we find that there are three outliers that may influence the test implemented in corr, which is designed for normally distributed data. To double check, we use the test based on the Spearman rank correlation:
>> [rho, pval] = corr(x(1 :2: end - 1), x(2 :2: end), 'type', 'Spearman')
rho =
       -0.0431684721353655
pval =
          0.67298135968005

The result is very similar to that based on Pearson correlation. We therefore have no evidence that there is autocorrelation at lag 1.
autocorrelation function: But maybe our assumption – that there if there is any autocorrelation at all, this will include lag 1 – is not correct. Let's look at the autocorrelation function:
[r, lags] = xcov(x, 'coeff');

figure
plot(lags, r, 'b.-')
ylim([-0.3 1.05])
xlabel lags
ylabel correlation

Now it looks like the autocorrelation at lag 1 is exceptionally small. The strongest autocorrelation is -0.215 at lag 21. Of course we cannot be sure that this is not just a randomly (negative-) large value. To test whether the autocorrelation at some other lag is significantly different from zero, we simulate stationary white noise with the same distribution as the data by resampling with replacement, and estimate the probability to find an autocorrelation larger than 0.215 or smaller than -0.215 at any non-zero lag:
[r, lags] = xcov(x, 'coeff');
mar = max(abs(r(lags > 0)))

for i = 1 : 100000
    xb = x(randi(n, n, 1));
    [rb, lags] = xcov(xb, 'coeff');
    marb(i) = max(abs(rb(lags > 0)));
end

pval = mean(marb >= mar)

The result is a p-value of 0.11 – much smaller, but still not significant w.r.t. the conventional level 0.05. From the distribution of simulated maximum-absolute-nonzero-lag-correlations marb we can determine the critical value of a test at a level of 0.05
>> rc = quantile(marb, 0.95)
rc =
         0.233023218494253

and visualize it

To conclude, according to this analysis, your data do not show a statistically significant amount of autocorrelation.
Comment: So, you're saying I should do a Pearson correlation between the vector [1,2,3,..., 199] and the vector with my estimates [942, 894, 1048, and so on until the final estimate]? If I do that for the data set I displayed above I get r(197) = .05, p = .44. Thus is .05 the point estimate for the level of autocorrelation?
Comment: @user1205901, no, in order to estimate the lag-1 autocorrelation with no overlap, use the indices 1, 3, 5, ... on the one side, and the indices 2, 4, 6, ... on the other side. This way for the estimation the data pairs (1, 2), (3, 4), (5, 6), ... are used.
Comment: If I do it that way it comes out as r = -.03, p = .80. So it's actually a negative correlation. Does that mean there is a a very slight (though non-significant) negative autocorrelation?
Comment: @user1205901, yes, it looks like that. If you can make your data available, I can take a look myself.
Comment: Thanks! Is this an acceptable format? http://pastebin.com/LHW5AKzt. I have other data sets too, but this is the one that matches the diagram above.


How to hide repeated content from search engines with CSS?

Question: I have a page structure for a website using fixed headers/footers around the main content. To keep things simpler for responsive design, I'm not using margins around the main content, I'm actually repeating the header/footer in the document - one in the fixed position, and once in the dynamic one. This means I don't need to worry about different heights on different devices.
However, I don't want the repeated content showing in search-engine results, so how can I hide it?
Answer: CSS doesn't hide anything from search engines.
For good practice, you should consider getting back to only one header/footer.
How about duplicating the header and footer with Javascript? You could use the jQuery <code>.clone()</code> method for this purpose.
Most search engine don't execute Javascript for their crawling.
Comment: I suspect you may be right; I was hoping that by 2014 I'd be able to address layout issues in CSS without leaning on JS.
Comment: Why don't you keep only a fixed header?
Comment: With a fixed header, I need to specify a margin for the content. As the header will have a different height depending on the viewport width, that forces me into using JS to adjust display properties. I'm starting to think I should have the header display once in-line, then make it fixed & patch margins on page ready / resize.
Comment: You could also use `em` units, so you don't have to bother changing all propeties. If the content's `margin-top` and header's `height` are in `em` units, you can change both by altering the content's `font-size` property.
Comment: Accepting this answer, since although it isn't what I want to hear, it is reality. However, the margin-top/height fix doesn't work quite so well if narrow width causes content to wrap. Going quiet now as I think this conversation has the potential to become long and rambling, and too specific to my needs.


STL trend of time series using R

Question: I am new to R and to time series analysis. I am trying to find the trend of a long (40 years) daily temperature time series and tried to different approximations. First one is just a simple linear regression and second one is Seasonal Decomposition of Time Series by Loess.
In the latter it appears that the seasonal component is greater than the trend. But, how do I quantify the trend? I would like just a number telling how strong is that trend.
     Call:  stl(x = tsdata, s.window = "periodic")
     Time.series components:
        seasonal                trend            remainder
Min.   :-8.482470191   Min.   :20.76670   Min.   :-11.863290365
1st Qu.:-5.799037090   1st Qu.:22.17939   1st Qu.: -1.661246674
Median :-0.756729578   Median :22.56694   Median :  0.026579468
Mean   :-0.005442784   Mean   :22.53063   Mean   : -0.003716813
3rd Qu.:5.695720249    3rd Qu.:22.91756   3rd Qu.:  1.700826647
Max.   :9.919315613    Max.   :24.98834   Max.   : 12.305103891

 IQR:
         STL.seasonal STL.trend STL.remainder data
         11.4948       0.7382    3.3621       10.8051
       % 106.4          6.8      31.1         100.0
     Weights: all == 1
     Other components: List of 5
$ win  : Named num [1:3] 153411 549 365
$ deg  : Named int [1:3] 0 1 1
$ jump : Named num [1:3] 15342 55 37
$ inner: int 2
$ outer: int 0

Answer: I wouldn't bother with stl() for this - the bandwidth for the lowess smoother used to extract the trend is far, far, to small resulting in the small scale fluctuations you see. I would use an additive model. Here is an example using data and model code from Simon Wood's book on GAMs:
require(mgcv)
require(gamair)
data(cairo)
cairo2 <- within(cairo, Date <- as.Date(paste(year, month, day.of.month,
                                              sep = "-")))
plot(temp ~ Date, data = cairo2, type = "l")

Fit a model with trend and seasonal components --- warning this is slow:
mod <- gamm(temp ~ s(day.of.year, bs = "cc") + s(time, bs = "cr"),
            data = cairo2, method = "REML",
            correlation = corAR1(form = ~ 1 | year),
            knots = list(day.of.year = c(0, 366)))

The fitted model looks like this:
> summary(mod$gam)

Family: gaussian
Link function: identity

Formula:
temp ~ s(day.of.year, bs = "cc") + s(time, bs = "cr")

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)  71.6603     0.1523   470.7   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
                 edf Ref.df       F p-value
s(day.of.year) 7.092  7.092 555.407 < 2e-16 ***
s(time)        1.383  1.383   7.035 0.00345 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.848  Scale est. = 16.572    n = 3780

and we can visualise the trend and seasonal terms via
plot(mod$gam, pages = 1)

and if we want to plot the trend on the observed data we can do that with prediction via:
pred <- predict(mod$gam, newdata = cairo2, type = "terms")
ptemp <- attr(pred, "constant") + pred[,2]
plot(temp ~ Date, data = cairo2, type = "l",
     xlab = "year",
     ylab = expression(Temperature ~ (degree*F)))
lines(ptemp ~ Date, data = cairo2, col = "red", lwd = 2)

Or the same for the actual model:
pred2 <- predict(mod$gam, newdata = cairo2)
plot(temp ~ Date, data = cairo2, type = "l",
     xlab = "year",
     ylab = expression(Temperature ~ (degree*F)))
lines(pred2 ~ Date, data = cairo2, col = "red", lwd = 2)

This is just an example, and a more in-depth analysis might have to deal with the fact that there are a few missing data, but the above should be a good starting point.
As to your point about how to quantify the trend - well that is a problem, because the trend is not linear, neither in your stl() version nor the GAM version I show. If it were, you could give the rate of change (slope). If you want to know by how much has the estimated trend changed over the period of sampling, then we can use the data contained in pred and compute the difference between the start and the end of the series in the trend component only:
> tail(pred[,2], 1) - head(pred[,2], 1)
    3794
1.756163

so temperatures are, on average, 1.76 degrees warmer than at the start of the record.
Comment: @andreas-h I wouldn't do that; the STL trend is over fitted. Fit the GAM with the AR() structure and interpret the trend. That will give a proper regression model which will be far more useful to you.
Comment: @pacomet - no, not really, unless you fit a model that accounts for autocorrelation in the residuals as I did above. You could use GLS for that (`gls()` in package nlme). But as the above shows for Cairo, and the STL suggests for your data, the trend isn't linear. As such, a linear trend would not be appropriate - as it doesn't describe the data properly. You need to try it on your data, but an AM like I show would degrade to a linear trend if that fitted the data best.
Comment: @GavinSimpson How exactly would I fit a model to STL's trend component? Do I just take the trend component, or do I need to fit the model to `trend + noise`?
Comment: Looking at the chart, I think there may be some confusion between Fahrenheit and Celsius.
Comment: Well spotted - I've been doing something similar for a few months and the data are in degree C. Was force of habit!
Comment: Thanks Gavin, a very nice and understandable answer. I'll try your suggestions.
Is it a good idea to plot the stl() trend component and make a linear regression?
Comment: @GavinSimpson Hello Gavin, I have a further question regarding to your answer. I would like to use 'visualised trend and seasonal trend' of the graph after 'plot(mod$gam, pages = 1)' as variation of my wind data for 12 years. some days were above average and some other days were below average. I want to use this trend for my formula as a variation but I couldn't recognise which value is for the graph because values in 'mod' were too many. Could you please show me to get simple numbers for the graph?
Answer: Gavin provided a very thorough answer, but for a simpler and faster solution, I recommend setting the stl function t.window parameter to a value that is a multiple of the frequency of the ts data. I would use the inferred periodicity of interest (e.g., a value of 3660 for decadal trends with diurnal resolution data). You may also be interested in the stl2 package described in the author's dissertation. I have applied Gavin's method to my own data and it is very effective too.

STL trend of time series using R


$x^{2n} + x^{2n-1} + x^ {2n-2} +\ldots+ x + 1$ is irreducible for any $n\in \mathbb N$ in $F_2[x]$. True or false?

Question: Will the  polynomials of the following set $A$  be irreducible in $F_2[x]$?
$A = [x^{2n} + x^{2n-1} + x^ {2n-2} + \ldots+ x + 1 : n\in \mathbb N]$
Can anyone please give me hints how to proceed?
Every term is there. I meant every polynomial of degree $2n$ has $2n+1$ terms.
Comment: I am asking this because you omitted $x^{2n-2}$ so maybe you should correct that and then my answer below should be an answer to your question
Comment: Are you intending to omit any terms among the $x^i$ and if yes then which?
Comment: No no every term is there. I mean every polynomial of degree $2n$ has $2n+1$ terms.@SorinTirc
Answer: It's false in general, for example for $n=4$ : $x^8+x^7+x^6+x^5+x^4+x^3+x^2+x+1 = (x^2+x+1)(x^6+x^3+1)$.
In general $\frac{x^n-1}{x-1}$ is irreducible iff n is prime(the cyclotomic poly) over $ \mathbb{Q}[X]$
Comment: I think it's intended to omit the terms $x^6, x^4, x^2$.
Comment: oh, didn't see that, but then I am not quite sure exactly which terms are omitted tbh
Comment: All the even terms are omitted except the first one.
Comment: and the last one $x^0$ then too maybe :) ? In whice case the n=2 poly is reducible :)
Comment: Can we say if a polynomial is irreducible in $\mathbb Q[x]$ so will be in $F_2[x]$?@SorinTirc
Comment: Can we say if a polynomial is irreducible in $\mathbb Q[x]$ so will be in $F_2[x]$?@Slade
Comment: "In general $\frac{x^n-1}{x-1}$ is irreducible iff n is prime(the cyclotomic poly) over $ \mathbb{Q}[X]$"  what is the significance of this line in my question? @SorinTirc
Comment: Well what you can say is that in order for a poly to be irreducible over $F_2$, it has to be irreducible over $\mathbb{Q}$ in the first place. It's an "if" relationship not an "if and only if relationship" and I thought I would just mention it. In your problem I proved that your poly is reducible over Q hence a fortiori over $F_2$


Tkinter play video and next window commands from one button

Question: I'm having trouble playing a video and moving to the next frame by clicking on one button. The problem is that the video starts playing at the beginning of the GUI, meaning that it has ended once you get to the right frame. I've tried to solve this by defining a function that only actually plays the video once the button is clicked. I can get it to move to the next frame and even print that the function is working but it won't play the video. To complicate things a bit, I've been working from different files and in classes. I've tried to slim down as much as possible with the following MWE:
page 1 as an overview page
page 2 as a first frame with the button
page 3 as a second frame with the MP4
page1 :
import tkinter as tk
from tkinter import *

from page2 import *

######Ensuring that the frames don't load as seperate windows but as frames over one another#######

class GUI(Tk):
    def __init__(self, *args, **kwargs):
        Tk.__init__(self, *args, **kwargs)

        # create a container for all the widgets (buttons, etc)
        window = Frame(self)
        window.pack(side="top", fill="both", expand=True)
        window.grid_rowconfigure(0, weight=1)
        window.grid_columnconfigure(0, weight=1)

        self.frames = {}

        # for loops for switching between pages
        for F in (Page2, Page3):
            frame = F(window, self)
            self.frames[F] = frame
            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(Page2)

    def show_frame(self, cont):
        frame = self.frames[cont]
        frame.tkraise()

if __name__ == "__main__":

    window = GUI()
    window.geometry("400x400")
    window.mainloop()

page2 :
import tkinter as tk
from tkinter import *

from page3 import *

class Page2(Frame):

    def __init__(self, parent, controller):
        Frame.__init__(self, parent)

        DF = Listbox(self, bg='#f8f8f8',height=30, width=70, highlightthickness=0, borderwidth=0)
        DF.place(x=0, y=0)

        nextpage = Page3(parent, controller)
        play = nextpage.play_video

        button = Button(
            DF,
            text="press",
            bg='#ffffff',
            height=4,
            width=30,
            command=lambda: [controller.show_frame(Page3),play.play_video()],
              )
        button.place(relx=0.5, rely=0.5, anchor=CENTER)

page3 :
import tkinter as tk
from tkinter import *
from tkVideoPlayer import TkinterVideo

class Page3(Frame):
    def __init__(self, parent, controller):
        Frame.__init__(self, parent)

        DF2 = Listbox(self, bg='green',height=30, width=70, highlightthickness=0, borderwidth=0)
        DF2.place(x=0, y=0)

        self.vid_player = TkinterVideo(DF2, scaled = True)
        self.vid_player.place(x=0, y=0)
        self.vid_player.load("Location_of_MP4.mp4")

        ###add this to play the MP4###
        #self.vid_player.play()

    def play_video(self):
        print("working")
        self.vid_player.play()

If you add the self.vidplayer.play() part you can tell that the MP4 isn't having problems. Just opening it from the function play_video seems to be not working.
I'm a bit stuck as I've tried a number of work-arounds to fix the issue. I'm flexible in the solution, e.g. it doesn't have to be a function to play the video. If possible it could also be played directly from the command=lambda or any other way. I've also tried to look for code that would reset the video to the start but haven't found that either.
Answer: After some time I've found a solution. In file two change the button command to a single function command

command=lambda:self.Function(controller),

Within that Function create a thread to simultaneously redirect to the 3rd page while also running a simulation. After the simulation redirect to the other frame
def FuncD(self, cont):
    cont.show_frame(page3)

    def thread_function(name):

        self.runcase()
        time.sleep(5)
        cont.show_frame(UC_Power2Plug_Results)

    thread = threading.Thread(target=thread_function, args=(1,))
    thread.start()

This should solve the one click two command issue. Add the following line to keep the video going
self.vid_player.bind("<<Ended>>",self.video_ended)

With this function behind the line of command
def video_ended(self, event=None):
    """ handle video ended """

    videoplayer = self.vid_player
    videoplayer.play()


Cant get tomcat to show webapp from deployed .war file

Question: I followed a tutorial and am trying to learn to make my own web app.  I am using Tomcat 8.0.47 and Spring MVC.  Issue is I can go to localhost:8080 and see that the server is on but I cant see my basic webapp running when visiting localhost:8080/CrunchifySpringMVCTutorial  page.  I made a WAR file and dropped it into the /webapps/ folder inside tomcat folder and console shows that it deployed the war file.  Any help is appreciated.
I am following this tutorial:  http://crunchify.com/simplest-spring-mvc-hello-world-example-tutorial-spring-model-view-controller-tips/
rather than paste all the files I decided to link the guide.  My set up is the same but cant figure out why it is not working. thanks.
Comment: What is a error that you are getting?
Comment: please share the error. If you are lauching the tomcat from eclipse share the console log. or if your tomcat is standalone or a service, please check the tomcat installation directory/logs/catalina.date.log. Also share the error displayed in browser when you launch your url.(specifically the error code.(eg: 403, 500 etc))
Comment: Also try with "localhost:8080/CrunchifySpringMVCTutorial/". the slash at the end is important
Comment: http://localhost:8080/CrunchifySpringMVCTutorial/  returns HTTP 404 error

type Status report

message

description The requested resource is not available.
Comment: standalone

06-Nov-2017 20:40:12.751 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 512 ms
06-Nov-2017 20:42:02.790 INFO [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive C:\Users\DinoJew\Documents\apache-tomcat-8.0.47\webapps\CrunchifySpringMVCTutorial.war
06-Nov-2017 20:42:02.848 INFO [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive C:\Users\DinoJew\Documents\apache-tomcat-8.0.47\webapps\CrunchifySpringMVCTutorial.war has finished in 58 ms
Answer: Looks like the issue was that I needed to add the CATALINA_HOME system variable to properly setup my tomcat server


How flexible is order of build phases for Xcode targets?

Question: Is it possible to configure the Build Phases of a target in Xcode 6.1 such that a Copy Files phase can occur before the Compile Sources phase?
Answer: As far as I can tell there is no way to reorder items using the GUI in Xcode. You can do it by editing the project.pbxproj file though.
If you open that file up in some text editor (not Xcode) and do a search for something like

Build configuration list for PBXNativeTarget

You'll find a section like this
/* Begin PBXNativeTarget section */
    9BDEC0D019881B9400AE439B /* MyProject */ = {
        isa = PBXNativeTarget;
        buildConfigurationList = 9BDEC0F019881B9400AE439B /* Build configuration list for PBXNativeTarget "MyProject" */;
        buildPhases = (
            6111D3671B56D2BB00DD7431 /* Show TODOs and FIXMEs as Warnings */,
            BAEE6F558B6BDB326F5B8D1F /* Check Pods Manifest.lock */,
            9BDEC0CD19881B9400AE439B /* Sources */,
            9BDEC0CE19881B9400AE439B /* Frameworks */,
            4C47C03A1ABD4DFE00D317B5 /* Copy baked database to bundle sqlite */,
            9BDEC0CF19881B9400AE439B /* Resources */,
            CDF5E3A80B5FDFCEA41B67FD /* Embed Pods Frameworks */,
            CF995761C5EAA8D1AAEBA463 /* Copy Pods Resources */,
        );
        buildRules = (
        );
        dependencies = (
            9B832FED19B76A45006D3347 /* PBXTargetDependency */,
        );
        name = MyProject;
        productName = MyProject;
        productReference = 9BDEC0D119881B9400AE439B /* MyProject.app */;
        productType = "com.apple.product-type.application";
    };

You can change the order of operations in the buildPhases list.
See how the first thing in my list is 6111D3671B56D2BB00DD7431 /* Show TODOs and FIXMEs as Warnings */,? That is a custom build phase script I added using the GUI and then moved that line up to be the first using Atom. Reopened the GUI and it was the second build phase after "Target Dependencies" (as was mentioned in the other answer).
Comment: fwiw, as of XCode 9.2, the "Target Dependencies" phase does not appear in this list, unfortunately.
Answer: Yes.
For existing phases such as "Copy" and "Compile" in your example:

View the Build Phases by selecting the Build Phases tab in the desired project's target
Then reorder phases (or elements of each phase) by dragging them using your mouse

Note: The "Target Dependencies" phase may not be reordered (at the time of this writing).
Comment: That doesn't work for me. Everytime I try to move one of the phases it snaps back immediately, see https://www.dropbox.com/s/aj9eil6cxix0zsu/xcode_cordova_prepare.mov?dl=0
Comment: I only seem to be able to drag items from the middle to the bottom. Therefore I have to shuffle them all down to the bottom until the thing I'm trying to insert higher is in the correct place.
Answer: In Xcode you can reorder the Build Phases in the GUI (XCode 6.4 and 7.1 beta), but sometimes the UI is somehow blocked. Try the following steps in order to unblock the UI:

click on Build Rules,
click on Build Phases,
move the desired phase one step at a time.
Comment: I was referring to Spencevail's statement, that the items can not be reordered. There has been for a long time (and still is) a bug in Xcode, that would prevent you from moving the rows. But if you switch tabs back and forth, the bug can be circumvented.
Comment: You are repeating @justin's answer, aren't you?
Answer: Ran into this problem with XCode 7.1.1 (maybe exists from XCode 7). I could not drag recently added Run Scripts to anywhere, found I could drag existing items to the bottom though.  So, if my items were
A
B
C
D (New runscript)

and I wanted to put D below A, first drag B to the bottom
A
C
D
B

and then drag C to the bottom
A
D
B
C

Hope that helps someone.


Small doubt about the connecting homomorphism on the long homology sequence

Question: When you consider the long homology sequence (of spaces $A,X$ , with $A$ subspace of $X$) you need to define an homomorphism from $H_q(X,A)$ to $H_{q-1}(A)$ to obtain the long homology sequence from the short one involving $0 \to H_q(A) \to H_q(X) \to H_q(X,A) \to0$.
The homomorphism you construct from $H_q(X,A) \to H_{q-1}(A)$ is the border homomorphism (it is an easy check that it is well defined in the quotient and its image can be thought in $H_{q-1}(X,A)$).
The main problem I see is that the homomorphism you construct is the zero one (and it does not make sense that you construct it if later is homomorphism zero). I mean, you know that the map from $H_q(A) \to H_q(X)$ is injective and the one from $H_q(X) \to H_q(X,A)$ surjective so by exactness you conclude that the kernel of this ''border'' map is the hole $H_q(X,A)$.
Any idea?
Comment: In fact the boundary map measures precisely the extent to which both of your claims fail to be true! That's why it's so important.
Comment: It's not true that the map $H_q(A) \to H_q(X)$ is injective, neither is it true that the map $H_q(X) \to H_q(X, A)$ is surjective.
Answer: The map on the chain level $C_*(A) \to C_*(X)$ might be injective, but the induced map on homology $H_*(A) \to H_*(X)$ need not be.  As an example, set $X = \Bbb R^2, A = S^1$.  Then the map $\Bbb Z \cong H_1(S^1) \to H_1(\Bbb R^2) \cong 0$ is necessarily zero.
Similarly, the map on homology  $H_*(X) \to H_*(X, A)$ need not be surjective.  Consider $X = [0,1]$ and $A = \{0,1\}$.  Then $H_1(X) \cong 0$ but $H_1(X,A) \cong \Bbb Z \not\cong 0$.
In both of these examples, you can check that the boundary map on homology is nontrivial.


Is there a way to extract to use emacs-clang-complete-async with a compilation database?

Question: emacs-clang-complete-async uses clang to provide C++ autocompletion in Emacs.
Of course, it needs the appropriate project CFLAGS (-I...) to work properly.
Some tools such as CMake, Ninja, etc. are providing a json file, the compilation database, containing the list of the command used to compile each file during the compilation process.
I would like to use the content of this file and give it to emacs-clang-complete-async somehow. Does anyone has already succeeded to do so?
Answer: I could not find any solution to this problem finally, keeping the question here in case the situation changes.


What is an ideal lattice?

Question: Can anyone describe in layman's terms what an ideal lattice is?  I've seen them mentioned in many places, but haven't found a good definition of what exactly they are, nor any good terms to know where to start my search to find more information.
I'm not exactly sure what a non ideal lattice might be either :P
Comment: https://en.wikipedia.org/wiki/Ideal_lattice_cryptography
Comment: When you say "layman's terms," what kind of layman are we talking about?
Comment: a programmer if that helps, trying to work his way towards understanding vector / dotproduct based homomorphic encryption (already understand the integer modulus version).  http://eprint.iacr.org/2012/078.pdf
Comment: I think to understand lattices, one needs to know a little abstract algebra (what a group is, what are subgroups/quotient groups), and a little bit about topological groups (for example $\mathbb{R}$ is a topological group; it has a topology (given by the notion of distance), and an algebraic operation (addition), and addition and subtraction are continuous with respect to this topology).
Answer: I don't know much about ideal lattices outside the definition, but I can start you off with what a lattice is.  If $n \geq 1$, a lattice in $V = \mathbb{R}^n$ is an additive subgroup of the form $$\Gamma = \mathbb{Z}v_1 + \cdots + \mathbb{Z}v_t$$ where $v_1, ... , v_t$ are linearly independent over $\mathbb{R}$.  If $t = n$, then $\Gamma$ is called a full lattice (many authors mean full lattice when they write lattice).  In other words, a lattice is a free abelian group (that is, an abelian group with a $\mathbb{Z}$-basis), with a basis which is also linearly independent over $\mathbb{R}$.
For example, if $V = \mathbb{R}$, then $\Gamma = \mathbb{Z} + \mathbb{Z}\pi$ is not a lattice, because the $\mathbb{Z}$-basis $1, \pi$ for $\Gamma$ is not linearly independent over $\mathbb{R}$.
But if $V = \mathbb{R}^3$, then $\Gamma = \mathbb{Z}(1,0,0) + \mathbb{Z}(1,0,1)$ is a lattice (of rank two).
Actually, there are several equivalent conditions for an additive subgroup $\Gamma$ of $V$ to be a lattice:
(i) $\Gamma$ is a lattice.
(ii) $\Gamma$ is a discrete subgroup (at every point $x$ in $\Gamma$, you can find an open set in $\mathbb{R}^n$ about $x$ which contains no other point of $\Gamma$)
(iii) Every bounded subset of $\mathbb{R}^n$ intersects $\Gamma$ at most at finitely many points.
You can also talk about quotient groups.  If $\Gamma$ is a lattice in $V = \mathbb{R}^n$, you can talk about the quotient group $V/\Gamma$.  For example, if we take $V = \mathbb{R}$ and the lattice $\Gamma = \mathbb{Z}$, then $V/ \Gamma = \mathbb{R}/\mathbb{Z}$ is really just the circle.  As a topological group, the circle is compact.  More generally, if $\Gamma = \mathbb{Z}v_1 + \cdots + \mathbb{Z}v_t$ for $v_1, ... v_t$ linearly independent over $\mathbb{R}$, you can extend $v_1, ... , v_t$ to a basis $v_{t+1}, ... , v_n$ for $V$.  Then the quotient group $V/\Gamma$ is $$(\mathbb{R}v_1 + \cdots + \mathbb{R}v_n)/(\mathbb{Z}v_1 + \cdots + \mathbb{Z}v_t) \cong \frac{\prod\limits_{i=1}^n \mathbb{R}}{\prod\limits_{i=1}^t \mathbb{Z} \times \prod\limits_{i=t+1}^n \{0\}} $$ $$ \cong \prod\limits_{i=1}^t \mathbb{R}/\mathbb{Z} \times \prod\limits_{i=t+1}^n \mathbb{R} $$ Thus $\Gamma$ is a full lattice if and only if $t = n$, if and only if $V/\Gamma$ is compact.  For detailed proofs, see J.S. Milne's excellent notes on algebraic number theory.
Comment: I'm not really following what you're saying for $\mathbb{Z} + \pi \mathbb{Z}$.  But since $9$ and $29$ are relatively prime integers, you have $9Z + 29Z = Z$, so that is a lattice.  More generally, if $n$ and $m$ are integers, then $nZ + mZ$ is equal to $dZ$, where $d$ is the greatest common divisor of $n$ and $m$.  Since $\{d\}$ is linearly independent over $\mathbb{R}$, $dZ$ is a lattice of rank one.
Comment: In your first example of Z+pi*Z, would I be correct in saying that it is not a lattice because 1 and 3 are not coprime?  Would 9Z+29Z be a lattice then?  Thanks!!

What is an ideal lattice?


How do you reconcile the definitions of multiple mutually independent events and multiple mutually independent random variables?

Question: 1) If $A, B, C$ are events then to prove mutual independence it's not enough to show $P(A,B,C)=P(A)P(B)P(C)$. You also have to show $P(A,B)=P(A)P(B)$ etc.
2) For random variables, the definition of mutual independence looks different. If $X,Y,Z$ are random variables, then it's enough to show $P(X,Y,Z)=P(X)P(Y)P(Z)$, for every possible value of $X,Y,Z$
The situation is different. In the random variable case each assignment of values to $X,Y,Z$ is a collection of events for which you'd have to show independence as in case 1).
case 2) of course follows from case 1). I am looking for a simple proof, since it seems like it should follow in a straightforward way. Most texts/PDFs simply state it without proof. For example, here
Answer: Your statement about the definition of independent random variables is
applicable only to discrete random variables and not for continuous
random variables since in the continuous case what A. Webb writes
as
$$\Pr(X=x,Y=y,Z=z)= \Pr(X=x) \Pr(Y=y) \Pr(Z=z)  \qquad \text{for all} ~x,y,z$$
is trivially satisfied with both sides having value $0$ for all
choices of $x,y,z$.
A more verbose alternative definition of the mutual stochastic independence of three events $A,B, C$ is that all eight
of the following identities must hold:
\begin{align}
\Pr(A\cap B\cap C) &= \Pr(A)\Pr(B)\Pr(C) \tag{1}\\
\Pr(A\cap B\cap C^c) &= \Pr(A)\Pr(B)\Pr(C^c)\tag{2}\\
\Pr(A\cap B^c\cap C) &= \Pr(A)\Pr(B^c)\Pr(C) \tag{3}\\
\Pr(A\cap B^c\cap C^c) &= \Pr(A)\Pr(B^c)\Pr(C^c) \tag{4}\\
\Pr(A^c\cap B\cap C) &= \Pr(A^c)\Pr(B)\Pr(C) \tag{5}\\
\Pr(A^c\cap B\cap C^c) &= \Pr(A^c)\Pr(B)\Pr(C^c)\tag{6}\\
\Pr(A^c\cap B^c\cap C) &= \Pr(A^c)\Pr(B^c)\Pr(C) \tag{7}\\
\Pr(A^c\cap B^c\cap C^c) &= \Pr(A^c)\Pr(B^c)\Pr(C^c) \tag{8}\\
\end{align}
which I hope will seem to you to be eerily akin to checking whether
$$\Pr(X=x,Y=y,Z=z)= \Pr(X=x) \Pr(Y=y) \Pr(Z=z)$$
holds for all $x,y,z$!
These $8$ equalities are a little redundant in that you don't
need to check on all of them; checking just a few suffices.
Note that $(1)$ is an equality that you need to check (you knew
that already!) but if you also verify that $(2)$ holds, then
you can add $(1)$ and $(2)$ to get that
$$\Pr(A\cap B) = \Pr(A)\Pr(B)\tag{9}$$ holds. Similarly,
after checking $(3)$, adding $(1)$ and $(3)$ shows that
$$\Pr(A\cap C) = \Pr(A)\Pr(C)\tag{10}$$ holds, and the sum
of $(1)$ and $(5)$ is $$\Pr(B\cap C) = \Pr(B)\Pr(C) \tag{11}$$
at which point you can stop.  But, $(1)$-$(8)$ are useful
to keep in mind when dealing with events and their complements:

the probability of an intersection is the product of the
  probabilities, regardless of whether we are dealing with
  mutually independent events or their complements or both.
Answer: Case 2 should read
\begin{equation}
\Pr(X=x,Y=y,Z=z)= \Pr(X=x) \Pr(Y=y) \Pr(Z=z)  \qquad \text{for all x,y,z}
\end{equation}
That this holds for any combination of $x,y,z$ is a strong condition. Recall that we get the marginal distribution of $X,Y$ by summing over $Z$
\begin{align}
\Pr(X=x,Y=y) &= \sum_z \Pr(X=x,Y=y,Z=z) &\qquad\text{marginal distribution}\\
&= \sum_z \Pr(X=x) \Pr(Y=y) \Pr(Z=z) &\qquad\text{assumed condition} \\
&= \Pr(X=x) \Pr(Y=y) \cdot \sum_z  \Pr(Z=z) \\
&= \Pr(X=x) \Pr(Y=y)
\end{align}
so pairwise independence follows. The continuous case is analagous.


Access nested property of an object

Question: I have to access property on object:
var jsonobj= {
    "first": {
        "second": 120
    }
}

How to check if second is available or not? jsonobj.hasOwnProperty() returns false if we check here.
If I want to change the value of second from 120 to 100, how can I achieve it?
Can I get a generalized solution, so that it works for any number of hierarchies?
Edit:
What if I don't know the name of the property?
Comment: `jsonobj.first.second = 100;` will do it. As to a generalised solution, how do you picture that working for duplicate property names? The object could have several properties that all reference other objects that each have their own `second` property, or the same property name could be used at several levels such that `obj.first.second.second.second` is not the same as `obj.first.second` - so which would you return? Also, this is _not_ JSON, it's an object (or nested objects) - [there's no such thing as a JSON object](http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/).
Comment: @nnnnnn : thanx for ur link. I just understood the difference between json and object literal! :)
Comment: Please note that the problem has **nothing** to do with JSON at all. It seems you are confusing JavaScript object literals (constructs of the JavaScript language syntax) with JSON (a language-independent data-exchange format, like XML or CSV). I will edit your question accordingly. See also: [There is no such thing as a "JSON object"](http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/).
Answer: If you want to check the existence of [the unique path to] a nested property [key], this function may help:
function keyPathExists(obj,keypath){
  var keys = keypath.split('.'), key, trace = obj;
  while (key = keys.shift()){
    if (!trace[key]){
      return null
    };
    trace = trace[key];
  }
  return true;
}

//usages
var abcd = {a:{b:{c:{d:1}}}};
keyPathExists(abcd,'a.b.c.d'); //=> 1
keyPathExists(abcd,'a.b.c.d.e'); //=> null
if (keyPathExists(abcd,'a.b.c.d')){
 abcd.a.b.c.d = 2;
}

Please read @nnnnnns comment, especially the provided link within it carefully.
Answer: Use typeof:
if(typeof jsonobj.first == 'undefined'){
    jsonobj.first = {};
}
if(typeof jsonobj.first.second == 'undefined'){
    jsonobj.first.second = {};
}
jsonobj.first.second = 100;

Comment: What if `first` isn't defined?
Comment: same, check for undefined, updated code
Answer: To change the value, you can use the "dot" notation - so try: jsonobj.first.second = 100
Answer: var jsonobj= {
              "first": {
                           "second": 120
                        }
           }

alert(jsonobj.first.second);

jsonobj.first.second = 100

alert(jsonobj.first.second);

Comment: What if i dont know the structure of the json object?
Comment: how would you change a property if you don't know the structure?... What if there is another property with the same name somewhere else in the object tree

Access nested property of an object


Existance of a matrix $B\in \mathcal M(2)$. Please suggest alternative ways.

Question:

Is there any theorem which help me to solve this question without long calculations?

My Try:
Let $B=
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
$ .The only possibilities of $A$ are $A=
\begin{pmatrix}
0 & 1 \\
0 & 0
\end{pmatrix}
\text{and}\;
\begin{pmatrix}
0 & 0 \\
1& 0
\end{pmatrix}$
Then I Tried to solve for $B^2=A$. i got the system is inconsistent.
But this method becoming complicated for doing (b) and (c). Can you help me to do in an alternative way?
I got an alternative way to (a). $A$ is nilpotent, So, $A^2=O$. So, $B^4=O$. So, B must be Nilpotent. But $B^2=O\neq A$. Hence, There is no such $B\in \mathcal M(2)$
Answer: First one is false,
Second and Third are true

Sufficient Hint for b :

$A$ is symmetric  implies $A$ is (orthogonally) diagonalizable  and $A$ is positive definite implies  all eigenvalues of $A$ are positive. So there exists, $P \in O(n,\Bbb R)$ such that $PAP^{-1}=PAP^t=\text{diag}(a_1,a_2,\cdots,a_n)$ where $a_i$'s are eigenvalues of $A$. From this, $A=P^t \text{diag}(a_1,a_2,\cdots,a_n) P$. Now set $B=P^T \text{diag}(\sqrt{a_1},\sqrt{a_2},\cdots,\sqrt{a_n})P$. Show that this $B$ works!

Use this hint to produce a suitable $B$ in the $c$ part and finish your problem!


Does a float3 in a constant buffer secretly add padding?

Question: I have a cbuffer in my shader.fx file, like so:
cbuffer lights : register (b1)
{
    float4 Light1Color;
    float3 Light1Direction;

    float4 Light2Color;
    float3 Light2Direction;

    float4 Light3Color;
    float3 Light3Direction;
}

I had some issues filling this cbuffer from my code, it ended up being an array of the following struct:
struct Light
    {
        public Color4 Color;
        public Vector3 Direction;
        //For whatever reason the constant buffer that we fill with this
        //light must have a bytesize that is a multiple of 16, so we add a float (4 bytes)...
        public float padding;
        public static int SizeInBytes = (4 * 4) + Vector3.SizeInBytes + 4;
}

I wrote the array into the cbuffer by using a DataStream(SharpDX). This DataStream was NOT happy when I didn't have the padding in my struct, but this padding is not there in my shader.
The resulting lights are correct, which to me means that this padding float that has been written is either ignored, or secretly added in the shader.fx during compilation.
Which one of those is true? If any?
Comment: Maybe this is explanation: https://msdn.microsoft.com/en-us/library/windows/desktop/bb509632%28v=vs.85%29.aspx `Each structure forces the next variable to start on the next four-component vector.`
Comment: @alex-farber Yes, this seems to be the explanation, it's a bit strange that it happens at all but I'm sure there are reasons.
Comment: The same alignment is used in OpenGL, this is for better performance.
Answer: See: 'Packing Rules for Constant Variables' (https://msdn.microsoft.com/en-us/library/windows/desktop/bb509632(v=vs.85).aspx)
... Additionally, HLSL packs data so that it does not cross a 16-byte boundary. Variables are packed into a given four-component vector until the variable will straddle a 4-vector boundary; the next variables will be bounced to the next four-component vector.
You could pack some components into 'unused' space with the packoffset modifier. However, this doesn't fit your data structure very well. (https://msdn.microsoft.com/en-us/library/windows/desktop/dd607358(v=vs.85).aspx).


I need to create a function that counts the number of different grades entered at the moment it just shows the most common grade

Question: Here is my code:
//input variables

var students = [];
var marks = [];

//output variables

var grade = [];
var topMark = 0;
var topStudent = "";
var botMark = 0;
var award = "";
var error = "";
var Acount = 0;
var Bcount = 0;
var Ccount = 0;
var Fcount = 0;

//Getting Name and Mark

var index = 0;
var i = 0;
var name = prompt("Enter student name","Harry");

while (name != ""){
    students[index] = name;
    index++;
    var mark = prompt("Enter Mark " + name)
    marks[i] = mark;
    i++;
    name = prompt("Enter student name", "John");
};

//Getting Grade

function getGrade(mark){

    if (mark < 50){
    grade = "F";
    } else if (mark < 70){
    grade = "C";
    } else if (mark < 83){
    grade = "B";
    } else {
    grade = "A";
    } return grade;

}

// Top Student Function

function topStudent(){

}

// Top Mark Function

function topMark(){

}

// Bottom Mark Function

function botMark(){

}

// A, B, C, and F Count Function

function getCountOf(grades, grade){
    var count = 0;
    for (var i = 0; i < grades.length; i += 1){
        var count = grades[i];
        if (grades[i] == grade) {
            count += 1;
            }
    }
    return count;
}

//Display Table

document.write("
")
document.write("
Student	Mark	Grade
");
for (var i = 0; i < students.length; i++){
    document.write("
" + students[i] + "	" + marks[i] + "	" + getGrade(marks[i]) + "
");
}
document.write("
");

// Display Bottom

if (students.length > 0){
    document.write("
");
    document.write("
");
    document.write("Top Student: " + topStudent);
    document.write("
");
    document.write("Top Mark: " + topMark);
    document.write("
");
    document.write("Bottom Mark: " + botMark);
    document.write("
");
    document.write("Number of A Marks: " + getCountOf(grade));
    document.write("
");
    document.write("Number of B Marks: " + getCountOf(grade));
    document.write("
");
    document.write("Number of C Marks: " + getCountOf(grade));
    document.write("
");
    document.write("Number of F Marks: " + getCountOf(grade));
}

I need help with the A, B, C, and F Count Function and how I am displaying it any help is welcome the display bottom is where I try and display the count of each grade A, B, C, and F but it only displays the mark most entered so if there are 3 A's 2 B's and a C it will display A next to all the counts.
Comment: is this a homework of somekind ?
Comment: `grade` is defined as an array at the top. Perhaps you got confused between `grades` and `grade`, variable names you've been using at multiple places with different meaning.
Comment: This is off-topic because there is no real question; you are simply soliciting help.
Answer: As Dan Kuida mentioned, I hope this isn't homework of some kind, but I've changed your code below. I would've given you a JSFiddle to work with, but those sites don't agree with document.write() functions. Here are the two sections you need to change.
// A, B, C, and F Count Function

function getCountOf(grade) {
  var count = 0;
  for (var i = 0; i < marks.length; i++) { // Could also use marks.forEach() here
    if (getGrade(marks[i]) === grade) {
      count++;
    }
  }
  return count;
}

You already have the marks saved and a function to convert them! No need for a grades array. Also note the ++ operator instead of the +=
// Display Bottom

if (students.length > 0) {
  document.write("
");
  document.write("
");
  document.write("Top Student: " + topStudent);
  document.write("
");
  document.write("Top Mark: " + topMark);
  document.write("
");
  document.write("Bottom Mark: " + botMark);
  document.write("
");
  document.write("Number of A Marks: " + getCountOf("A"));
  document.write("
");
  document.write("Number of B Marks: " + getCountOf("B"));
  document.write("
");
  document.write("Number of C Marks: " + getCountOf("C"));
  document.write("
");
  document.write("Number of F Marks: " + getCountOf("F"));
}

Comment: Thank you so much this is a big help was stuck on this problem for so long tried so many different ways and new I was close thanks for the answer!


Displaying the value of a string variable in ASP.Net markup

Question: Is it possible to take the value from a string variable from a code-behind file and display it in this markup?

People Authorized to Release Children for <TheVariableGoesHere>

The variable we would like to include is called strForename.
Protected Sub GridViewParentsSummary_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridViewParentsSummary.SelectedIndexChanged

    IntParentsID = GridViewParentsSummary.DataKeys(GridViewParentsSummary.SelectedIndex).Value
    strForename = GridViewParentsSummary.DataKeys(GridViewParentsSummary.SelectedIndex).Values("Forename")

    blnAddModeIsSelected = False

    Response.Redirect("AuthorizationForChildReleaseDetails.aspx")

End Sub

Answer: The way this would be accomplished is through a code behind method being called.
Something like this for C#

People Authorized to Release Children for <% =this.GetForename() %>

or this for VB.NET

People Authorized to Release Children for <% =Me.GetForename() %>

and in code behind C#
protected string GetForename()
{
    return GridViewParentsSummary.DataKeys(GridViewParentsSummary.SelectedIndex).Values("Forename");
}

or in VB.NET
Protected Function GetForename() As String
    Return GridViewParentsSummary.DataKeys(GridViewParentsSummary.SelectedIndex).Values("Forename")
End Function

Comment: Thanks everyone for the helpful comments and code samples. In order that I can learn more of what you know, are there any sites I can go to where tips and tricks such as this is listed? Thanks again. :-)
Comment: I can't say that I've learnt more at any site then I have at StackOverflow. Probably the biggest tip I can give you is to look at the top questions for both the month (http://stackoverflow.com/?tab=month) and week (http://stackoverflow.com/?tab=week)
Answer: You can do this by making your variable protected or public member and using it in the markup like this:
<%#strForename%> Make sure to call DataBind so the field is bound.
I see that you are doing a redirect at the end of your function, You cannot use the variable from page 1 into a redirected page unless you pass it somehow (as a Request parameter or session parameter)
Alternatively you can do a Server.Transfer and pass that in the context