data manipulation with na values

Question: My code are like that df2 DataFrame (toy data) :
import pandas as pd
import numpy as np

end = '20201117'

np.random.seed(107)
df = pd.DataFrame()
for i in range(10):
    start = np.random.choice(['20000101', '20100101', '20160101', '20121010'])
    df_tempo = pd.DataFrame({'product': 'p'+str(i),
                             'category': 'cat'+str(np.random.choice(4))
                             },
                            index=pd.bdate_range(start=pd.to_datetime(start),
                                                 end=end,
                                                 freq=np.random.choice(['D', 'W'])))

    df_tempo['valeur1'] = np.random.randint(50, 100, df_tempo.shape[0])
    df_tempo['valeur2'] = np.random.randint(100, 200, df_tempo.shape[0])
    df = pd.concat([df, df_tempo])
df = df.reset_index().rename(columns={'index': 'date'})

df2 = df.pivot(index='date', columns=['category', 'product'], values=['valeur1', 'valeur2'])

from this I would like to calculate the growth rate for 2020, 2019,..years
I tried :
df2.apply([
    lambda x: 100*x.valeur1[x.valeur1['2020'].last_valid_index()]/x.valeur1[x.valeur1['2019'].last_valid_index()]-100,
         ])

but get an error message with is (I would like to calculate different stat for valeur1 and valeur2) :
AttributeError: 'Series' object has no attribute 'valeur1'

so I did (it's not what I would like to do because as I said I would like to apply different stat on valeur1 and valeur2) :
df2['valeur1'].apply([
    lambda x: 100*x[x['2020'].last_valid_index()]/x[x['2019'].last_valid_index()]-100,
    lambda x: 100*x[x['2010'].last_valid_index()]/x[x['2009'].last_valid_index()]-100,

         ])

It works except that
lambda x: 100*x[x['2010'].last_valid_index()]/x[x['2009'].last_valid_index()]-100

because I have data series that have no data for 2010 and so return an error.
I tried then a dropna()but not help
Any ideas to help on these 2 problems ?
Answer: Since date is already the index of df2, pd.Grouper(freq="Y").last() can be used to retrieve the value on the last date. Is this what you are expecting?
Note: df2 = df2.groupby(pd.Grouper(freq="Y")).ffill() will fill the last date of each year with previous valid value(s). For this sample dataset, however, no difference was introduced.
Code
df_last = df2.groupby(pd.Grouper(freq="Y")).last()
out = df_last.diff() / df_last.shift() * 100

Result
print(out)

              valeur1                        ...    valeur2
category         cat0                  cat2  ...       cat0                  cat2
product            p0         p1         p2  ...         p7         p8         p9
date                                         ...
2000-12-31        NaN        NaN        NaN  ...        NaN        NaN        NaN
2001-12-31        NaN  62.000000 -35.869565  ...        NaN -37.113402        NaN
2002-12-31        NaN   8.641975  28.813559  ...        NaN  13.934426        NaN
2003-12-31        NaN -40.909091  19.736842  ...        NaN  30.935252        NaN
2004-12-31        NaN  25.000000 -30.769231  ...        NaN -18.131868        NaN
2005-12-31        NaN -20.000000  57.142857  ...        NaN -18.791946        NaN
2006-12-31        NaN  19.230769 -15.151515  ...        NaN  14.049587        NaN
2007-12-31        NaN  25.806452 -40.476190  ...        NaN  -5.072464        NaN
2008-12-31        NaN  -1.282051   4.000000  ...        NaN  32.824427        NaN
2009-12-31        NaN   7.792208  38.461538  ...        NaN  -9.770115        NaN
2010-12-31        NaN -33.734940 -26.388889  ...        NaN  12.738854        NaN
2011-12-31        NaN  29.090909  83.018868  ...        NaN -12.994350  43.442623
2012-12-31        NaN -19.718310 -40.206186  ...        NaN  -5.194805  13.142857
2013-12-31        NaN  17.543860  34.482759  ...        NaN  12.328767 -19.696970
2014-12-31        NaN   8.955224  23.076923  ...        NaN -22.560976 -18.867925
2015-12-31        NaN  -6.849315 -14.583333  ...        NaN  43.307087  23.255814
2016-12-31        NaN  33.823529  -7.317073  ...        NaN -22.527473  -6.289308
2017-12-31 -22.580645 -35.164835  -2.631579  ...  -8.176101  10.638298 -22.818792
2018-12-31  -6.944444  55.932203   5.405405  ... -30.821918   1.923077  35.652174
2019-12-31  14.925373  -8.695652  -1.282051  ...  70.297030  -6.918239  19.230769
2020-12-31   2.597403   8.333333 -20.779221  ... -28.488372  -6.081081 -17.204301

[21 rows x 20 columns]

Comment: Finally I found a solution with : ```lambda x: 100*x.valeur1['2020'].asof('2021')/x.valeur1['2019'].asof('2020')-100``` with find the last non na value before the date inside asof.  Also concerning the first problem I encountered I solve it with an inversion between index and columns ie with ```df.pivot(columns='date', index=['category', 'product'], values=['valeur1', 'valeur2'])```

data manipulation with na values


In what sense is Taniyama-Shimura the $n=2$ case of Langlands?

Question: As I understand it (If I'm imprecise, as I will likely be, please correct me), Langlands says roughly as follows:
For every representation $Gal(\mathbb{Q}) \rightarrow GL_n(\mathbb{C})$ we can form a function, called the associated $L$-function.
There is such a thing called an automorphic form, which in the $n=2$ case is just a modular form (is this right? I have a feeling that there's a subtlety missing here, but I will continue, as this is not yet the gist of my question). For each automorphic form we may associate a function, confusingly also called the associated $L$-function (except now it's associated to an automorphic form rather than a Galois representation).
Langlands says that we get the same set of functions from both of these constructions. (although, as I understand it, it doesn't really say much about what this bijection is)
However, Taniyama-Shimura is phrased in terms of elliptic curves! I'm trying to relate it to something I would recognize as being my rough sketch for Langlands in $n=2$ case.
It is true if an elliptic curve is defined over $\mathbb{Q}$ then one would get a representation of $Gal(\mathbb{Q})$ by its action on the vector space $H^1(E,\mathbb{Q}_l)$ (in the etale sense, for various prime $l$). But this is confusing to me: are all $2$-dimensional representations of this form? And what about this weird varying $l$ (shouldn't the representations ultimately be over $\mathbb{C}$ as in my statement of Langlands, or was that wrong?)?
And how does any of this relate to the phrasing of Taniyama-Shimura that says that any elliptic curve over $\mathbb{Q}$ has a rational map into it from some $X_0(N)$ with integer coefficients?
I hope you can help my confusion...
Edit:
Let me focus my question: in what sense does an elliptic curve give a 2-dimensional representation? (do you look at the first etale cohomology with coefficients in $\mathbb{Q}_l$ and then basechange to $\mathbb{C}$ and it turns out to be indep. of both $l$ and the embedding into $\mathbb{C}$?)
And secondly, do all two dimension (do I need the word "irreducible" here?) representations of the Galois group of the rationals arise from an elliptic curve in this way?
Comment: Regarding whether all $2$-dimensional Galois representations come from elliptic curves, see http://en.wikipedia.org/wiki/Serre_conjecture_(number_theory) . I don't think the answer is expected to be yes, but I would prefer that an expert comment on this... I remember being told that the even representations should be attached to Maass forms, not modular forms.
Comment: So is Taniyama Shimura only Langland for n=2 for the representations coming from elliptic curves?
Comment: I think so. (Again, not an expert opinion.)
Comment: Related: [Yoshida conjecture](https://mathoverflow.net/questions/40761/langlands-in-dimension-2-the-yoshida-conjecture).
Answer: Here are some answers to your various questions:
For the group $GL_2$, every cuspidal automorphic representation of $GL_2(\mathbb A)$ (here $\mathbb A$ is the adele ring of $\mathbb Q$) is generated by a uniquely determined newform, which (when normalized in a suitable fashion) is either a classical newform in the sense of Atkin and Lehner, i.e. a holomorphic cuspform of some weight $k \geq 1$ which is an eigenform for all the Hecke operators, and of minimal possible level for its associated system of Hecke eigenvalues, or else is a Maass newform (same as before but replace holomorphic cuspform of weight $k \geq 1$ by Maass form, which is an eigenform for the Laplacian with some eigenvalue $\lambda$).
There is a conjecture of Selberg that in the Maass form case, $\lambda \geq 1/4$.  This is still open (although there are known lower bounds that are close); it is an analogue "at infinity" of the Ramanujan--Petersson conjecture.  (More precisely, Langlands explained how to unify Selberg's conjecture with the Ramanujan--Petersson conjecture using the language of automorphic representations and the concept of "tempered" local factors. The local factor at infinity for a holomorphic newform is discrete series (or limit of discrete series in the weight one case), hence automatically tempered, but for Maass forms the local factor at infinity is unitary principal series, and then temperedness is a non-trivial additional condition.)
It has been proved (essentially by Eichler--Shimura when $k = 2$, by Deligne for the general case of $k \geq 2$, and by Deligne and Serre when $k = 1$) that holomorphic newforms give rise to two-dimensional Galois representations, and it is conjectured (but not proved in general) that $\lambda = 1/4$ Maass forms also give rise to two-dimensional Galois representations.  The Maass forms with $\lambda \neq 1/4$ (i.e. $\lambda > 1/4$ if Selberg's conjecture is true) are not expected to correspond to Galois representations.
What does "give rise to two-dimensional Galois representations" mean exactly? Let me explain.  (Note: from now on, to avoid circumlocutions, I will write affirmative statements, but in the Maass form $\lambda = 1/4$ case, these remain conjectural in general; in the holomorphic case they are all proved theorems.)
Actually what will happen is that the newform will correspond to a two-dimensional motive.  This motive has $\ell$-adic cohomology, for each $\ell$, and these will form a compatible system of two-dimensional $\ell$-adic representations of $G_{\mathbb Q}$.
This motive also has a Hodge structure, which has Hodge numbers $(0,0), (0,0)$ in the $\lambda = 1/4$ case, and $(k-1,0), (0,k-1)$ in the holomorphic case.
In the $\lambda = 1/4$ case, or in the holomorphic weight $1$ case, since the Hodge numbers are $(0,0), (0,0)$, the motive will come from a zero-dimensional variety, which is to say it will be a two-dimensional Artin motive, and so the
$\ell$-adic Galois representations can be consolidated into a single Artin
representation $G_{\mathbb Q} \to GL_2(\mathbb C)$.  However, in the holomorphic case when $k \geq 2$, the motive will come from a positive-dimensional variety, and so the $\ell$-adic representations will not be able to be simplified into a single Artin representation (e.g. because they will have infinite image, not finite image).
E.g. in the case $k = 2$, the Hodge numbers are $(1,0), (0,1)$, which says that the motive comes from a certain abelian variety.  The $\ell$-adic representations are then the $\ell$-adic Tate modules (or rather, their duals, if you want to be careful about the distinction betweeh cohomology and homology) of this abelian variety.
I now should say something about coefficients.  The Hecke eigenvalues of the newform will be algebraic numbers, and collectively they will generate a finite extension $E$ of $\mathbb Q$.  The motive attached to the newform will have $E$ acting as endomorphisms, and when I say it it two-dimensional, I mean it is two-dimensional over $E$.  Thus the $\ell$-adic representations will actually be two
dimensional $\lambda$-adic representations for each prime $\lambda$ of $E$, i.e. they will be representations $G_{\mathbb Q} \to GL_2(E_{\lambda})$.
E.g. if $k = 2$ and the newform $f$ has level $N$, then we can form the Jacobian
$J_1(N)$ of $X_1(N)$, and this has an action of $\mathbb T$, the Hecke algebra at level $N$.  The action of $\mathbb T$ on $f$ gives rise to a homomorphism
$\mathbb T \to E$ (sending $T_p$ to the $p$th Hecke eigenvalue of $f$), and
we may form $A_f:= E\otimes_{\mathbb T} J_1(N)$, which is an abelian variety well-defined up to isogeny.  It has dimension $[E:\mathbb Q]$ and endomorphisms by $E$, and so for each $\lambda$ we form its $\lambda$-adic Tate module,
and (the dual of) this is two-dimensional over $E_{\lambda}$, and is the $\lambda$-adic Galois representation attached to $f$.
In particular, if $k = 2$ and $E = \mathbb Q$ (i.e. all the Hecke eigenvalues of $f$ are rational numbers) then $A_f$ is an elliptic curve, and this is the association of elliptic curves to weight two newforms with rational Hecke eigenvalues.  (Note that in this case $f$ automatically has level $\Gamma_0(N)$ rather than $\Gamma_1(N)$, and so in the above we replace $X_1(N)$ and $J_1(N)$ by $X_0(N)$ and $J_0(N)$, which may be a little more familiar.)
Now suppose conversely that $M$ is a motive with endomorphisms by a number field $E$, irreducible and of dimension two over $E$.  It is conjectured that $M$ is attached to a newform.  In fact, we can determine the newform precisely (assuming it exists):
the ramification of $M$ will determine the level, and counting points on $M$ mod primes will determine the Hecke eigenvalues of the newform.   The Hodge numbers of $M$ (possibly after a Tate twist) will be $(i,0),(0,i)$ for some $i \geq 0$.
If $i > 0$, then the newform will have to be a weight $i + 1$ holomorphic newform.  If $i = 0$, then the newform will be either holomorphic weight one,
or a $\lambda = 1/4$ Maass form; to tell which, you have to look at the action of complex conjugation on the Hodge strucuture: if it is non-scalar (this is usually called "odd"), you are in the holomorphic case, while if it is scalar
(this is usually called "even") you are in the Maass case.  (The reason for "odd" and "even" is that in these case the determinant of complex conjugation on the $\ell$-adic cohomology is $-1$ resp. $+1$.)
Let's suppose that the motive $M$ comes from an elliptic curve $C$.  (I use $C$ rather than $E$ because $E$ was my notation for the field of coefficients.)
Then the Hodge numbers are $(1,0),(0,1)$, hence we expect there to be weight two newform $f$ such that $C = A_f$.  (Since $A_f$ is only defined up to isogeny, this equality should be understood as an isogeny.)  But if $C$ is isogenous to a factor of the Jacobian of $X_0(N)$ (which is what we are saying), then this implies (indeed is equivalent to) $C$ being a quotient of $X_0(N)$.
Sometimes things are phrased in terms of $L$-functions rather than motives (because motives are subtle to think about, and parts of the theory of motives remain conjectural).  In the elliptic curve case, though, everything is known, because Faltings proved the Tate conjecture, namely that two elliptic curves with the same $L$-function are isogenous.  Since you can read off the $L$-function from the $\ell$-adic Tate module, this says that even knowing that the $\ell$-adic Tate module of $C$ coincides with the $\ell$-adic Galois representation attached to $f$ (even for a single $\ell$) is enough to get
$C = A_f$.  (This is is why things are sometimes formulated in terms of $L$-functions, sometimes in terms of Galois reps., and sometimes in terms of motives --- the formulations are conjecturally all equivalent, and are known to be equivalent in the elliptic curve case.)
The preceding discussion shows that the general conjecture about going from two-dimensional motives to newforms is a generalization of Shimura--Taniyama.  It is known in the odd case (it follows from Serre's conjecture, proved by Khare, Wintenberger, and Kisin; see Cor. 0.5 of Kisin's paper).  It is open in general in the even case (just as the construction of motives, or Galois representations, from $\lambda = 1/4$ Maass forms is wide open).  (But note that it is proved in the case of solvable image, by Langlands--Tunnel --- see below.)

As I already noted: one can avoid talking about motives, and instead talk about compatible families of $\ell$-adic Galois reps. (more precisely, $\lambda$-adic Galois reps., if we fix our coefficient field $E$), or even $\ell$-adic (or $\lambda$-adic) reps. for a single choice of $\ell$ or $\lambda$.
There are arrows
$$\text{motives } \to \text{ compatible families of $\ell$-adic reps. } \to \text{ $\ell$-adic rep. for a fixed $\ell$} $$
given by passing to $\ell$-adic cohomology for all $\ell$, and then by picking out a particular $\ell$.  These maps are injective (the first conjecturally in general --- this is the Tate conjecture), but not surjective.  Not all compatible families come from a motive, and not every individual $\ell$-adic rep. sits in a compatible family.
There is a conjecture of Fontaine and Mazur which (conjecturally!) describes those $\ell$-adic reps. which come from motives. (Here $\ell$ is a fixed prime, and I could just as well be talking about $\lambda$-adic reps. here, but it is more traditional to say $\ell$-adic rather than $\lambda$-adic, even when the latter is what is meant.) In the two-dimensional case, for representations which are supposed to come from holomorphic newforms of weight $k \geq 2$, it is largely proved: see e.g. Thm. 1.2.4 (2), and also the discussion in Section 1.4, of this paper, as well as this paper of Kisin, and these papers
of Calegari.  (These papers all build on the work of Wiles and Taylor--Wiles.)
In the case of representations which are supposed to come from either weight one holomorphic forms or Maass forms with $\lambda = 1/4$, the situation is more complicated.  If you assume that the Galois rep. is odd and has finite image, then it is known to come from a weight one form; this follows from Serre's conjecture, as noted above.  However, it is supposed to be enough (according to Fontaine and Mazur) to assume that the $\ell$-adic representation has finite image on inertia at $\ell$ --- this should then imply that the whole image is finite.  However, this is not proved in general; I believe this result of Buzzard, which handles certain odd cases, is the best general result currently.
In the even case, if you assume that the image is finite and solvable, then Langlands--Tunnel give a $\lambda = 1/4$ Maass form giving rise to your Galois rep., but (still in the even case now), if the image is finite but non-solvable, or (even worse) if you just assume that the image of inertia at $\ell$ is finite, then the conjecture is wide-open.

Note that $2$-dimensional Artin (i.e. finite image) reps. are just a special case of all two-dimensional $\ell$-adic reps. (corresponding to $\lambda = 1/4$ Maass form or weight one forms --- at least conjecturally, in the even case), and the $\ell$-adic Tate modules of elliptic curves are just another special case of such reps.  Even if you write down all the $\ell$-adic reps. coming from all newforms, there are uncountably manner other irreducible two-dimensional $\ell$-adic reps. that don't come from motives at all.
Comment: Thank you for posting this: it is a very nice answer.
Comment: Every time I reread it I retain more. Thanks again for the answer!
Comment: @MattE : Wow, most interesting and beautiful answer, very big explanation, you are born to answer and help others sir, thanks a lot for being in this community, $+\infty$ votes to you.
Comment: So all Artin reps. are in $GL_2$? Does this mean that every symmetric group can be embedded in $GL_2$?
Comment: @simple: Dear simplequestions, No, $2$-dimensional Artin reps. are into $GL_2$; $n$-dimensional Artin reps. are into $GL_n$.  Not all symmetric groups can be embedded into $GL_2$; in fact the possible finite subgroups of $GL_2$ are very limited in nature.   In the preceding answer, it should be understood that everything is in the context of $2$-dim'l Galois reps., so *Artin rep.* always means *$2$-dimensional Artin rep.*  Regards,
Answer: All such questions are wildly volatile... :)  But/and fun... and, truly, productive, if one is not nervous.
Yes, to any complex repn of a galois group, we (originally, E. Artin, many decades ago) form an L-function.
The convenient conjecture (Langlands... quite stunning at the time) is that any such L-function (of an irreducible repn...) should be the L-function attached to a  cuspform on $GL_n$... Few cases of this are known.
At present, we have many more afms, and corresponding L-functions, than we have "Galois" L-functions... even though we are unable to prove that all the Galois L-functions are automorphic.
The Taniyama-Shimura conjecture (proven by Wiles-Taylor) is that the Galois repn L-functions attached to elliptic curves are the same as some afc L-fcns.
Yes, the natural repn of Galois groups is on etale or other cohomology groups, and appears to depend on "ell", but one is required to prove that the dependence is illusory... :)
On many considerations, at least amounting to the greater number of all modular forms of suitable senses... there are far more mfms/afms than Galois/motivic things, so "most" mfms/afms are not "motivic". This is not at all a "bad" thing,  or confusing, either, but requires reflection... [As usual, much more can be said, but I hope this is constructive...]
Edit: In response to further question, "do all 2D Galois repns occur as repn on $H^1$ of an elliptic curve over $\mathbb Q$?"... I do not think there is any prediction that that is the case, although that's not the particular thing on which I'd bet a large sum. I think such a conjecture would not be a very Langlands-y conjecture, anyway, because (as with Taniyama-Shimura) the point is that a Galois repn's L-function is ("also") automorphic. Elliptic curves over $\mathbb Q$ are an important source of such Galois repns.
Comment: But do all degree 2 representations (are we restricting ourselves to irreducibles?) appear as actions on the first cohomology (by whatever definition) of some elliptic curve?
Comment: Dear Nicole, Not all irred. two-dim'l $\ell$-adic reps. of $G_{\mathbb Q}$ come from elliptic curves; indeed, "most" don't.  Consider e.g. the two-dimensional reps. coming from wt. 2 forms with irrational Hecke eigenvalues (e.g. those on $\Gamma_0(23)$), or coming from forms of wt. $k \neq 1$.  More generally, there are two-dimensional reps. not coming from any modular forms at all.  See my answer for more details.  Regards,
Comment: @Nicole: Dear Nicole, This is just to (a) notify you of my comment above, and (b) correct "$k\neq 1$" to "$k \neq 2$" in that comment. Regards,


Accidentally compiled with -o and no executable name

Question: I accidentally compiled using clang -o file1.c file2.c instead of clang -o executable_name file1.c file2.c and now I have an executable with the name file1.c.
Is there any way to go back to what I had?
Comment: If the source file is still in the editor you can try saving it again, perhaps after a change to a comment so the editor has to save it.
Comment: This is one of the kinds of things that revision-control systems such as Git are good for.  Or more generally, backups.
Comment: ... back to the first comment, if there is a disaster my rule is to do *nothing* until I have some time to think about it. E.g. don't close the editor.
Comment: This has nothing to do with C. This is no different from recovering any other file that you accidentally deleted or overwrote.
Comment: Avoiding such issues is a reason to use `make` or a similar tool to build even simple programs, instead of writing compilation commands by hand.  Though I usually do that more for convenience and for protection from less consequential mistakes.
Comment: Otherwise using a backup may be the only option.
Comment: ... on that front, I don't use version control but I do copy the file extremely often, for that kind of reason, or in case i accidentally break something that was working. It takes a second to drag the file to make a copy. Make a little change, it's ok, copy that, make the next change and so on.
Comment: This is an excessively easy mistake to make.  A command-line C compiler could really stand to check for it.
Comment: Also build systems in general would work here.  Even a `build.sh` would have saved you here. Can't mess up `make` and wind up missing source code.  Typing build commands into terminal manually seems like a lot of extra work.
Comment: If you are at a workplace or school, they may also have backups running regularly that place snapshots of everything in your home directory in a `~/.snapshot` directory (the name may be something different). Search for it to see if there is something there: `find ~ -name file1.c`
Comment: I like `input files -o executable`; it seems more natural, and defaults to `a.out` if you miss specifying. (Not that it does any good in your situation.)
Comment: Ouch! Is file2.c totally independent of file1.c? Otherwise there should have been linker errors due to undefined references and no overwriting of file1.c.
Answer:
If you still have the file1.c open in your editor save it.  It may prompt you to confirm that you want to overwrite the newer file.
Some editors will create temporary files.  Vim, for instance, create *.swp files by default and you use use the :recover command to restore the file from it.
Restore the last version from your revision control.
Restore the last copy you backed up.


Dockerfile RUN command - no such file

Question: I have a problem running an executable in my Dockerfile.
It contains a command to download the 'gsoap' library from an internal service, then the following:
ENV PATH="/opt/tools/gsoap/v2.7.12/lnx_x64/bin:${PATH}"
RUN ls -la /opt/tools/gsoap/v2.7.12/lnx_x64/bin
RUN whereis soapcpp2
RUN ["soapcpp2", "-v"]

The ls command returns a result:
drwxr-xr-x 2 root root    4096 Mar  1 17:34 .
drwxr-xr-x 1 root root    4096 Mar  1 17:34 ..
-rwxr-xr-x 1 root root  610652 Mar  1 17:34 soapcpp2
-rwxr-xr-x 1 root root 4270809 Mar  1 17:34 wsdl2h

And whereis is happy too:
soapcpp2: /opt/tools/gsoap/v2.7.12/lnx_x64/bin/soapcpp2

But trying to run it gives:
standard_init_linux.go:195: exec user process caused "no such file or directory"

Whats going on here?
If I change to use the shell form:
RUN soapcpp2 -v

I get
/bin/sh: 1: soapcpp2: not found

Huh? whereis just told me its happy that soapcpp2 is on the PATH.
Answer: You need to copy your files in your Dockerfile, using either
ADD
or
COPY
https://docs.docker.com/engine/reference/builder/#add
and
https://docs.docker.com/engine/reference/builder/#copy
By the way, you seem to misuse RUN, maybe your last command should be either
a
CMD
or
ENTRYPOINT
https://docs.docker.com/engine/reference/builder/#cmd
https://docs.docker.com/engine/reference/builder/#entrypoint
See also
What is the difference between CMD and ENTRYPOINT in a Dockerfile?
Comment: As stated in the question: `It contains a command to download the 'gsoap' library from an internal service, then the following`
Comment: Post the whole Dockerfile
Comment: see also https://docs.docker.com/develop/develop-images/dockerfile_best-practices/ you should group your `RUN` to avoid various problems

Dockerfile RUN command - no such file


How to force flush old cache in visitor browser

Question: recetnly i changed cache plugin from WP fastest cache to WP Rocket. I had to move some inline JS codes to file. The issue is some repeat visitors can have old JS file in browser cache. Is there some way, how to force delete it, when they visit site?
Answer: My Idea would be to still put a reference to the old files like:
<code><script type="text/javascript" src="http://www.example.com/myOldFile.js?2"></script>
</code>
I haven't tested wether it works with deleted files. But it works with changed files. So my assumption is, that it also could work with a deleted one.
The index 2 after the question mark in the link will force the brower to reload the file and remove the old one from cache. You can change to index whenever a file was changed.
I've tested it on many browsers and WebView Objects (WKWebView and Android WebView).


Jquery get selected checkboxes

Question: Hi I'd like to get the list of selected checkboxes ina page, actually what I really need is th get the text of the element next to the checkbox which is a html element

the code is below and its not working
Here is my current jQuery:
$(document).ready(function () {
  $('#target').click(function () {
    alert("in");
    var checkValues = [];
    $('input[name=checkboxlist]:checked').each(function() {
      alert($(this)val());
      checkValues.push($(this)val());
    });
  });
});

Here is the HTML:

Structured Products<input type="checkbox" name="checkboxlist"

Global FID

PowerPoint Presentations<input type="checkbox" name="checkboxlist"

Global Deck

Test1<input type="checkbox" name="checkboxlist"

Test2<input type="checkbox" name="checkboxlist"

Test3<input type="checkbox" name="checkboxlist"

  <input type="checkbox" name="checkboxlist"

Credit Default Swaps Position

Test4<input type="checkbox" name="checkboxlist"

Test5<input type="checkbox" name="checkboxlist"

  <input type="checkbox" name="checkboxlist"

Thought Leadership<input type="checkbox" name="checkboxlist"

Fixed Income Perspectives<input type="checkbox" name="checkboxlist"

Public Policy Information and Regulatory<input type="checkbox" name="checkboxlist"

Regional FID<input type="checkbox" name="checkboxlist"

 <input type="checkbox" name="checkboxlist"

Global Rates<input type="checkbox" name="checkboxlist"

Global Credit Products<input type="checkbox" name="checkboxlist"

FX<input type="checkbox" name="checkboxlist"

Emerging Markets<input type="checkbox" name="checkboxlist"

Commodities<input type="checkbox" name="checkboxlist"

testcat<input type="checkbox" name="checkboxlist"

testcat<input type="checkbox" name="checkboxlist"

Answer: Your inputs need to be closed with a /> on the end to make your HTML valid, like this:
<input type="checkbox" name="checkboxlist" />

Then you can do jQuery like this to get an array of the text:
$(function () {
  $('#target').click(function () {
    var checkValues = $('input[name=checkboxlist]:checked').map(function() {
        return $(this).parent().text();
    }).get();
    //do something with your checkValues array
  });
});

You can see this working here
Since all you need is the parent's .text() with your layout, you can use .map() to quickly get an array of a property based on the selector.
Comment: To make the HTML valid doesn't require the slash, which the browser parser will ignore.
Comment: @Tim - At the very least, it has to be closed, why not do it in a XHTML valid way while you're at it? It's valid HTML with it, it's invalid XHTML without it...saying the browser will completely ignore it is an incorrect statement.  You're assuming his DOCTYPE, but `/>` works in *any* doctype, no assumptions made there.
Comment: OK, fair points, though using XHTML in general doesn't make a lot of sense.
Comment: Just to weigh in here, using XHTML makes a lot of sense.  To not use it because you don't have to is silly.
Answer: $("input[type=checkbox]:checked").parent().text()

Answer: First of all you have to close your checkbox tag
<input type="checkbox" name="checkboxlist"

should be
<input type="checkbox" name="checkboxlist" />

I think, from your HTML you can get the text of the lis which will be the desired text
$(function(){
    $('#target').click(function(){
        var selected = new Array();
        $("input:checkbox[name=checkboxlist]:checked").each(function(){
            var val = $(this).closest("li").text();
            selected.push(val);
        });
    });
});

Answer: You are not closing your input tags correctly. Also, $(this)val() should be $(this).val().
If you intend to obtain the text of li element which contains the input element, you can write as below:
$(this).parents("li:first").text();

Comment: There's a `.closest("li")` that makes this simpler ;)

Jquery get selected checkboxes


Select-object in CISCO IOS

Question: I am very new to CISCO IOS and have little to none experience. I was wondering if there is a way to run a command like show ip interface brief and then select exactly what you want and then redirect it through tftp. I've been able to export the output of the whole command through tftp. show ip interface brief | redirect tftp://IPAddress/output.txt So my question:

How can I select the bottom "loopback0" information below and redirect the output again?
I've tried redirecting the whole command and tried parsing it in powershell so I could make a csv but its way to messy.
Answer: I've always used Putty with session log enabled in order to get output from Cisco devices. Or if I was on Linux, I would just pipe my ssh session output in tee.
ssh me@cisco | tee -a outputfile.log

Now if you want to only show some lines in the output of your command, there are two things you can do;
1- Use grep. Yes, Cisco IOS comes with grep and it's regex capacity.
sh ip interface brief | grep loopback0

2- Use include. It's almost the same as grep...
sh ip interface brief | include loopback0

I like include better just because the abreviated version of it is simply "i".
sh ip interface brief | i loopback0

I'm not entire sure if you can pipe twice like this:
sh ip interface brief | i loopback0 | redirect tftp://IPAddress/output.txt

It worth noting that there is also begin and exclude that can help you filter out results of your command.
Comment: From what I've tried so far, it seems that you cant pipe twice... How else can I get this info?
Comment: The first two lines of the answer pretty much sums it up. With logging your SSH session you will have an exact copy of whatever commands and results you will send to the cisco device with the results. If you want to use scripting, then TCL is the way to go with Cisco.

Select-object in CISCO IOS


this value in JavaScript anonymous function

Question: Can anybody explain to me why A is true and B is false? I would have expected B to be true as well.
function MyObject() {

};

MyObject.prototype.test = function () {
    console.log("A", this instanceof MyObject);
    (function () {
        console.log("B", this instanceof MyObject);
    }());
}

new MyObject().test();

update:
since ecmascript-6 you can use arrow functions which would make it easy to refer to MyObject like this:
function MyObject() {

};

MyObject.prototype.test = function () {
    console.log("A", this instanceof MyObject);
    (() => {//a change is here, which will have the effect of the next line resulting in true
        console.log("B", this instanceof MyObject);
    })(); //and here is a change
}

new MyObject().test();

Comment: Welcome to functional scope in JavaScript.
Comment: @zzzzBov: That's not a closure.
Comment: No; it's not being used as a closure.  It's not closing over anything.  Scope is not really relevant.
Comment: You might want to use an additional pair of parens to improve readability: `( new MyObject() ).test()`
Comment: @SLaks, I've edited my comment to correctly reflect the usage of the anonymous function, although it *is* being used as a closure.
Comment: @zzzzBov Correct me if I'm wrong, but IIFE's can't form closures since they're invoked immediately. Only when a function survives (as a reference) the invocation of its outer function, only then we have a closure.
Comment: @ŠimeVidas: Wrong; using a variable in an IIFE still creates a closure. Even though it probably won't last beyond the parent scope, it's still a closure.  Also, the IIFE could cause itself to be called later if it's named.
Comment: @SLaks Assuming that it's a anonymous IIFE, that it doesn't declare any local variables, and that it doesn't contain any nested function declarations/expressions, would it be a closure in that case? (hypothetically speaking, unrelated to this question)
Comment: @ŠimeVidas: If it doesn't actually use any parent variables and doesn't call `eval`, it isn't a closure.
Comment: @SLaks Ah yes, of course. If the function uses its scope chain (if it accesses any of its outer scopes), then it's a closure.
Comment: @ŠimeVidas, SLaks, could one of you provide a third party definition of "closure" that you feel acceptably describes closures in JavaScript?
Comment: @zzzzBov I'm working on it in the [chat room](http://chat.stackoverflow.com/rooms/17) `:)`
Comment: @zzzzBov: See [this answer](http://stackoverflow.com/a/111200/21475)
Comment: @Cameron, so what's the definition? closures don't need to be returned from some function in order to retain a reference to it outside of its original functional scope. My definition of a closure is **"any block that *closes* (retains, remembers, stores reference to, etc) over the variables previously in scope, and allows for instantiation of new variables without polluting the parent's scope"**. I'm sure it's a naive definition, but it's a start.
Comment: @Cameron, [this answer states that all functions are closures in JS](http://programmers.stackexchange.com/questions/40454/what-is-a-closure).
Comment: @zzzzBov: That's a good definition.  However, instead of "previously in scope", I would say "from a parent scope".
Comment: @zzzzBov: Right, they don't need to be returned, but the key is that a function isn't (technically) a closure until it leaves its parent's scope (and, of course, references variables in its parent's scope).
Comment: Possible duplicate of [How does the "this" keyword work?](https://stackoverflow.com/questions/3127429/how-does-the-this-keyword-work)
Answer: Inside of your anonymous function this is the global object.
Inside of test, this is the instance of MyObject on which the method was invoked.

Whenever you call a function like this:
someFunction(); // called function invocation

this is always the global object, or undefined in strict mode (unless someFunction was created with bind** — see below)
Whenever you call a function like this
foo.someMethod();  //called method invocation

this is set to foo

**EcmaScript5 defines a bind function that allows you to create a function that has a pre-set value for this
So this
    var obj = { a: 12 };
    var someFunction = (function () { alert(this.a); }).bind(obj);
    someFunction();

Causes someFucntion to be invoked with this equal to obj, and alerts 12.  I bring this up only to note that this is a potential exception to the rule I mentioned about functions invoked as
someFunction();

always having this equal to the global object (or undefined in strict mode)
Comment: you can also set the `this` using `func.call(this, arg1, arg2..)`
Comment: The line `(function () { alert(this.a); }).bind(obj)` is exactly what I was looking for - binding context to an anonymous function. Works perfectly, +1
Answer: this is special. It refers to the object that the function is being called on behalf of (most commonly via dot syntax).
So, in the case of A, the function is being called on behalf of a new MyObject object. B is in a different function that isn't explicitly being called on behalf of any object, so this defaults to the global object (window).
In other words, this changes depending on how the function is called, not where or how it is defined. The fact that you're using an anonymous function (defined inside another function) is coincidental and has no effect on the value of this.
Comment: Your statement "`this` changes depending on how the function is *called*, not where or how it is defined", can be misleading. In fact, `this` is simply the called function's owner - and that is in itself always either is explicitly defined or defaults to the global object. `myVar.doSomething = doSomething;` defines the function `myVar.doSomething` as `doSomething` where `this` will always refer to `myVar` when calling `myVar.doSomething()`, regardless of where `myVar.doSomething()` is called from. Your statement might suggest otherwise.
Answer: In the anonymous function, this is bound to the global object (window in a browser environment).
There are various ways of accessing the instance:
var self = this;
(function () {
    console.log("B", self instanceof MyObject);
}());

or
(function () {
    console.log("B", this instanceof MyObject);
}).call(this);

Answer: this is set based on how you call the function.
Your anonymous function is a normal function call, so this is the global object.
You could write (function() { ... }).call(this) to explicitly call it with your this.
Comment: Well, I'm assuming strict mode, so... `:)`
Comment: ... so `this` is `undefined`.


'gradlew.bat' is not recognized as an internal or external command

Question: So i am trying to start a react native android project in windows 10 based on the Getting Start React Native.
I am stuck at the last step->react-native run-android

ps: Im using genymotion for my  android emulator marshmallow 6.0
Answer: Got it,
Add the file location to environment variable PATH
C:\Users\user\AppData\Local\Android\Sdk\tools\templates\gradle\wrapper
Comment: I do not have `templates/` directory in my `tools/` directory. I have tried the other solution (of adding `gradle` installation path) but have no success. I am missing `gradlew.bat`
Comment: However the `gradle -v` command works well, as I have added Gradle installation path to environment variable. I'm using Win 10.
Answer: Another version of the @Kai Jie findings, that works for me.
Compiling previous answers I did the following to get Android SDK and gradle working (You need gradle working anyway to compile your Android project):

Prerequisites. You have gradle installed in the folders like I found on my computer. Please, check it:
C:\Program Files\Android\Android Studio\gradle\gradle-X.X\

Set a new system variable (Control Panel\System and Security\System Advance system ->settings->environment variables-system variables). Do not forget to change a gradle version.
GRADLE_HOME   C:\Program Files\Android\Android Studio\gradle\gradle-X.X\

Add the following path to system paths (Control Panel\System and Security\System Advance system ->settings->environment variables-system variables):
%GRADLE_HOME%\bin

You might want to REBOOT your computer, to make sure, that the system sees the variables.
Check if gradle works properly with the terminal commands
$ gradle -v

Comment: I do not have `templates/` directory in my `tools/` directory. I have tried the other solution (of adding `gradle` installation path) but have no success. I am missing `gradlew.bat`. The `gradle -v` command works though.
Answer: If the environment variables are set. I found that you need to actually start gradle. Then you can use the gradlew command.
If you are learning from Spring.io. Their site says to just run
./gradlew build && java -jar build/libs/gs-spring-boot-0.1.0.jar

That will fail unless you first run
gradle

Intellij had me in the correct directory so I just deleted
./

and run
gradlew build && java -jar build/libs/gs-spring-boot-0.1.0.jar

The app started right up.
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.6.RELEASE)

Answer: if your gradlew.bat file is being generated but delete itself after a few second than it's a problem of your android studio .
steps to follow :
1 . open your android studio and click on configure.
2. Go to setting there.
3.Click on Build,Execution,Deployment => Build Tools => Gradle.
4. check Gradle user home if it's pointing to .gradle file location or not .If it's not than give the correct path of .gradle file like this in my case C:/Users/Your_PC_Name/.gradle .
5. And than create new reactproject.
Comment: Thank you , you saved me
Answer: You probably have to do something like:
./gradlew assembleDebug
Answer: Add code below to the bottom of build.gradle file
task createWrapper(type: Wrapper) {
    gradleVersion = '4.9'
};

then run gradle createWrapper in terminal
This will generate gradlew.bat file and corrospondinf gradlew files
Answer: in my case, I had a & sign in the name of the folder that I had put in the flutter project. removing it solved the problem for me.


Add "Request new Password" link to user logIn page

Question: I am using the Logintoboggan module to redirect users to the login page when they try to visit a page for which they don't have the permission to visit.
How do I add a Request new Password or Forgot Password? link to this page?
Answer: This should be already there as a link.
if it is a custom login page, you can add a link with "/user/password" href


Is it ever $i$ time?

Question: I am asking this question as a response to reading two different questions:
Is it ever Pi time?
and
Are complex number real?
So I ask, is it ever $i$ time?  Could we arbitrarily define  time as following the imaginary line instead of the real one?
(NOTE:  I have NO experience with complex numbers, so I apologize if this is a truly dumb question.  It just followed from my reading, and I want to test my understanding)
Comment: If time were imaginary some things would get weird. For example, if you accelerate at $50 \frac{mi}{hr^2}$ and the hours were imaginary numbers, then the $hr^2$ would end up flipping the sign of your acceleration. We know this doesn't happen physically, so imaginary time in this sense won't work.
Comment: If you take the Argand viewpoint, you're then asking if "time" can have more than one dimension... if it does have two dimensions, then there's a way to interpret $i$...
Comment: "following a complex line" - it's a "real line", but a "complex plane"... ;)
Comment: If you think of the complex plane, at 12:00 both hands point to $i$.
Comment: @J.M -- I thought that complex numbers formed a plane, but that imaginary numbers were on a line (and the plane came from combining the imaginary with the real)... Oh, maybe I should have said "imaginary line?"
Answer: Yes; if you'll refer to the Wikipedia page on Imaginary Time, you'll see that imaginary time is a useful concept in quantum mechanics.
EDIT: As an aside, your question is very far from dumb. The desire to generalize anything and everything to complex numbers (and, for the number theorists out there, to $p$-adic numbers) has shown, historically, to be a natural and very fruitful instinct.
Answer: In the Wikipedia article titled Paul Émile Appell, we read that "He discovered a physical interpretation of the imaginary period of the doubly periodic function whose restriction to real arguments describes the motion of an ideal pendulum."
The interpretation is this: The real period is the real period.  The maximum deviation from vertical is $\theta$.  The imaginary period is what the period would be if that maximum deviation were $\pi - \theta$.

Is it ever $i$ time?


When using the boxes module, is it possible to export the region and visibility settings?

Question: I just installed the Boxes module and I added a box to my feature.  The box description and body were exported successfully, but the region settings (where in the theme(s) the box appears) and the visibility settings (show block on specific pages, etc.) were not.
How can I export the placement information for boxes as well?
Answer: Ah, I just realized there is an issue for this in the boxes queue.  As of May 2012, the issue has been resolved and this is now possible.


Forgotten account password

Question: I kept my passwords recorded but the location on my PC where I kept this went missing. I now can't get into Windows Server 2008 R2 as I can't remember the administrator or named account credentials and have no password reset disk. This is on a VM (VM Player - which btw is temp till I get Hyper-V).
How can I get back in? If I make AD can I join the server to AD and then set a domain account?
Answer: Check out the How-To-Geek's Tutorial on how to do exactly what you want. Note: This will require a using a LiveCD (Linux) but trust me it's very easy.
Comment: The fact that it's a VM doesn't make much difference.  Rather than create a physical CD and boot from that you'll just mount the ISO from within VMware and boot from that instead.
Comment: I will try this. One question - does the fact that I am using a VM change anything?
Answer: You have to know an administrative account to join an Active Directory.
There are a number of free password reset bootable disks available.  I've used several for years with no trouble but none on 2k8.  I don't know if they will work or not so you will want to seek other opinions.
Comment: The default setting is that any user account can join a PC to an AD Domain. But this still wont get him an Admin account in the domain.
Answer: Try Hiren CD.. This will surely work..
www.hiren.info/pages/bootcd

Forgotten account password


Loss functions for regression proof

Question: I'm using Bishop's Pattern Recognition and Machine Learning. In section 1.5.5, loss functions for regression, namely the squared loss, is discussed.
$\mathbb{E}[L] = \displaystyle\int\int \{ y(x)-t\}^{2}p(x,t) dx dt $
The book makes the following remark:
$\{ y(x)-t\}^{2} = \{y(x) - \mathbb{E}[t|x] + \mathbb{E}[t|x] - t \}^{2}
\\ = \{y(x) - \mathbb{E}[t|x] \}^{2} + 2\{y(x) - \mathbb{E}[t|x]\}\{\mathbb{E}[t|x]-t\} + \{\mathbb{E}[t|x]-t\}^{2}$
The resulting expression shown above is substituted into the loss function, integrated over $t$, and then it is seen that the cross-term (the second term) vanishes. The result obtained is:
$\mathbb{E}[L] = \displaystyle\int\int \{ y(x)-t\}^{2}p(x,t) dx dt \\ = \displaystyle\int \{y(x) - \mathbb{E}[t|x] \}^{2} p(x) dx + \displaystyle\int \{\mathbb{E}[t|x]-t\}^{2} p(x) dx$
What I don't understand is the algebra involved to get the final result. Why does the cross-term vanish? For the last term, how are you bringing $t$ outside the integral over $t$? Perhaps I am missing something here, could someone care to explain?
Comment: I don't have the book, but is this perhaps Eq. (1.90) on p. 47?https://www.microsoft.com/en-us/research/wp-content/uploads/2016/05/prml-errata-1st-20110921.pdf
Comment: That is, the errata above corrects "the integrand of the second integral" to $var[t\mid x]$, which would make sense here but I cannot verify that the erratum is referring to the same equation as this question.
Answer: I would like to explain the way I understood it, explaining each and every step on the way.
Assumptions:

$g(x,t)$ is a function of x and t.
$p(x,t)$ is a joint distribution over $x$ and $t$.

Basic formulas:
$$\mathbb{E}_t[g|x] = \int_t{g(x,t)p(t|x)\mathop{dt}} \ (\mathbb{E}_t[g|x] \text{ is a function of $x$ and constant w.r.t. } t) \tag{1}\label{1} $$
$$\mathbb{E}_t[t|x] = \int_t{t.p(t|x)\mathop{dt}} \tag{2}\label{2}$$
$\operatorname{var}_t[t|x] = \int_t{(t - \mathbb{E}_t[t|x])^2p(t|x)\mathop{dt}} = \mathbb{E}_t[(t - \mathbb{E}_t[t|x])^2 | x] \tag{3}\label{3}$
$$
\eqalign{\mathbb{E}_t[f(x)g(x,t)|x]
&= \int_t{f(x)g(x,t)p(t|x)\mathop{dt}} \\
&= f(x)\int_t{g(x,t)p(t|x)\mathop{dt}} \\
&= f(x) \ \mathbb{E}_t[g|x] }
\tag{4}\label{4}$$
$$\mathbb{E}_t[f(x)|x] = f(x) \tag{4a}\label{4a}$$
$$\mathbb{E}_{x,t}[g] = \mathbb{E}_x[\mathbb{E}_t[g|x]] \tag{5}\label{5}$$
We derive the last formula above.
$$
\eqalign{
\mathbb{E}_{x,t}[g]
&= \int_x\int_tg(x,t)p(x,t)\mathop{dx}\mathop{dt}\\
&= \int_x\int_tg(x,t)p(x)p(t|x)\mathop{dx}\mathop{dt}\\
&= \int_x p(x)\int_t g(x,t)p(t|x)\mathop{dt}\mathop{dx}\\
&= \int_x \mathbb{E}_t[g|x]p(x)\mathop{dx}  \text{  (using \ref{1}) }  \\
&= \mathbb{E}_x [\mathbb{E}_t[g|x]] \\
}
$$

Derivation of the expected loss:
Represent the Loss function in the form as below. Please notice the subscript $t$ in the $\mathbb{E}_t$ notations. This was omitted in the book, but I added it here for clarity.
$$
\eqalign{
L(x,t) &= (y(x)-t)^{2} \\
&= (y(x) - \mathbb{E}_t[t|x])^{2} + 2(y(x) - \mathbb{E}_t[t|x])(\mathbb{E}_t[t|x]-t) + (\mathbb{E}_t[t|x]-t)^{2} \\
&= L_1 + 2L_2 + L_3
}
$$
Hence the joint expectation can be represented as:
$$
\eqalign{
\mathbb{E}_{x,t}[L]
&= \mathbb{E}_{x,t}[L_1] + 2\mathbb{E}_{x,t}[L_2] + \mathbb{E}_{x,t}[L_3]
}
$$
We derive the 3 expectations:
$$
\eqalign{
\mathbb{E}_{x,t}[L_1]
&= \mathbb{E}_{x,t}[(y(x) - \mathbb{E}_t[t|x])^{2}] \\
&= \mathbb{E}_x[ \ \mathbb{E}_t[(y(x) - \mathbb{E}_t[t|x])^{2} | x] \ ] \ \ \text{  (using \ref{5}) } \\
&= \mathbb{E}_x[(y(x) - \mathbb{E}_t[t|x] )^{2}]  \text{  (using \ref{4a}, as the operand is a function of $x$ only)} \\
}
$$

$$
\eqalign{
\mathbb{E}_{x,t}[L_2]
&= \mathbb{E}_{x,t}[(y(x) - \mathbb{E}_t[t|x])(\mathbb{E}_t[t|x]-t)] \\
&= \mathbb{E}_x[ \ \mathbb{E}_t[\{(y(x) - \mathbb{E}_t[t|x])(\mathbb{E}_t[t|x]-t)\} \ | \ x] \ ] \text{  (using \ref{5}) } \\
&= \mathbb{E}_x[ \ (y(x) - \mathbb{E}_t[t|x]) \ \mathbb{E}_t[(\mathbb{E}_t[t|x]-t) | x] \ \ ] \ \text{  (using \ref{4} on the inner expectation)}
}
$$
Considering only the inner expectation:
$$
\eqalign{
\mathbb{E}_t[(\mathbb{E}_t[t|x]-t) | x]
&= \mathbb{E}_t[\mathbb{E}_t[t|x] | x] - \mathbb{E}_t[t|x] \text{ (using inearity of $\mathbb{E}$)} \\
&= \mathbb{E}_t[t|x] - \mathbb{E}_t[t|x]  \text{  (using \ref{4a} as $\mathbb{E}_t[t|x]$ is a function of $x$)}\\
&= 0
}
$$
Therefore,
$$
\eqalign{
\mathbb{E}_{x,t}[L_2]
&= \mathbb{E}_x[ \ (y(x) - \mathbb{E}_t[t|x]) \ \cdot \ 0 \ ] \\
&= 0
}
$$

$$
\eqalign{
\mathbb{E}_{x,t}[L_3]
&= \mathbb{E}_{x,t}[(\mathbb{E}_t[t|x]-t)^{2}] \\
&= \mathbb{E}_x[ \ \mathbb{E}_t[(\mathbb{E}_t[t|x]-t)^{2} | x] \ ]  \text{  (using \ref{5}) } \\
&= \mathbb{E}_x[\operatorname{var}_t[t|x]] \text{  (using \ref{3}) }
}
$$
Putting them all together and expressing the $\mathbb{E}_x$ terms as integrals under $x$, we get the following form:
$$
\mathbb{E}_{x,t}[L] = \int_x (y(x) - \mathbb{E}_t[t|x])^2 p(x)\mathop{dx} + \int_x \operatorname{var}_t[t|x] p(x) \mathop{dx}
$$
Note: As mentioned by @Juho Kokkalla, the erroneous last term in the book is corrected in the errata.
Answer: This proof is easier if you iterate expectations. You want to show that $\mathbb{E}(y|x)$ is in a sense the best predictor of $t$, so you want to show that
$$
\mathbb{E}[(y(x) - t)^2] \ge \mathbb{E}[\{\mathbb{E}(t \vert x) - t\}^2]
$$
for any $y(x)$.
It's easier to first consider $\mathbb{E}[(y(x) - t)^2 \vert x]$. If you do this and apply the trick you mentioned above (adding and subtracting a conditional expectation), you can get
\begin{align*}
&\mathbb{E}[(y(x) - t)^2 \vert x] \\
&= \mathbb{E}[\{y(x) - \mathbb{E}[t|x] \}^{2}\vert x] + 2\mathbb{E}[\{y(x) - \mathbb{E}[t|x]\}\{\mathbb{E}[t|x]-t\}\vert x] + \mathbb{E}[\{\mathbb{E}[t|x]-t\}^{2}\vert x] \\
&= \{y(x) - \mathbb{E}[t|x] \}^{2} + 0 + \mathbb{E}[\{\mathbb{E}[t|x]-t\}^{2}\vert x] .
\end{align*}
Notice that the cross term here becomes $0$ when you do this because of linearity and the fact that you can pull out any $x-$measurable random variables from the conditional expectation. For more details, see whuber's comment below.
And then you finally get the desired result by taking expectations again (with respect to $p(x)$). No differentiation needed.
Comment: +1 It's nice to see a brief rigorous argument. (But one has to guess what you mean by "$f(x)$" at the end.) Because the crucial part of the analysis isn't the linearity of expectation, but why the cross term disappears, you might want to elaborate on that. Writing $g(x)$ for $y(x)-\mathbb{E}[t|x]$, I believe you are saying that$$\eqalign{\mathbb{E}[g(x)\ (\mathbb{E}[t|x]-t)\mid x]&=g(x)\ \mathbb{E}[\mathbb{E}[t|x]-t]\mid x]\\&=g(x)\left(\mathbb{E}[\mathbb{E}[t|x]\mid x]-\mathbb{E}[t\mid x]\right)\\&=g(x)\left(\mathbb{E}[t|x]-\mathbb{E}[t|x]\right)\\&=0.}$$
Comment: @whuber yes that's right. And I'll make the change from $f(x)$ to OP's notation $p(x)$.

Loss functions for regression proof


Mass translate taxonomy terms

Question: I have around 400 taxonomy terms; very complicated hierarchical stuff.
I wonder if anyone knows about a plugin (taxonomy manager style) that can help me do it without having to dive into taxonomy and translated one by one.
Thanks !
Answer: Translation Table:

This module presents your taxonomy terms or menu items in a table, and
  each language has a corresponding column. Just fill out the
  translations and click Save.

Mass translate taxonomy terms


Splitting data - specific case

Question: I'm trying to split some data, the data is in this form...
['20150406,34.4800,34.8100,34.2300,34.4200,21480500', '20150407,34.5400,34.8900,34.5100,34.6300,14331200']

The first item in each string in the list is a date, I am trying split the data at a chosen date. But have the whole string... For example if my chosen date was 2015-04-07 the above data would split like this...
['20150406,34.4800,34.8100,34.2300,34.4200,21480500']

['20150407,34.5400,34.8900,34.5100,34.6300,14331200']

This also has to work for lists with lots of strings in the same form as this...
Comment: Can there be many dates the same? Can you add an example for multiple elements?
Answer: Use next() and enumerate() to find the position of the string with the desired date, then slice:
>>> d = '20150407'
>>> l = [
...     '20150406,34.4800,34.8100,34.2300,34.4200,21480500',
...     '20160402,34.1,32.8100,33.2300,31.01,22282510',
...     '20150407,34.5400,34.8900,34.5100,34.6300,14331200',
...     '20120101,2.540,14.8201,32.00,30.1311,12331230'
... ]
>>> index = next(i for i, item in enumerate(l) if item.startswith(d))
>>> l[:index]
['20150406,34.4800,34.8100,34.2300,34.4200,21480500', '20160402,34.1,32.8100,33.2300,31.01,22282510']
>>> l[index:]
['20150407,34.5400,34.8900,34.5100,34.6300,14331200', '20120101,2.540,14.8201,32.00,30.1311,12331230']

Couple notes:

next() would through a StopIteration exception if there will be no match - you should either handle it with try/except or provide a default value, -1 for example:
next((i for i, item in enumerate(l) if item.startswith(d)), -1)

to check if the date matches a desired one, we are simply checking if an item starts with a specific date string. If the desired date comes as a date or datetime, you would need to format it beforehand using strftime():
>>> from datetime import datetime
>>> d = datetime(2015, 4, 7)
>>> d = d.strftime("%Y%m%d")
>>> d
'20150407'

Comment: You can add a `","` to the string and it will match the exact substring
Answer: I think you want a groupby, grouping strings that don't start with the date and ones that do so the date delimits the groups:
l = ['20150406,34.4800,34.8100,34.2300,34.4200,21480500', '2015010,34.5400,34.8900,34.5100,34.6300,14331200'
    , '20150407,34.5400,34.8900,34.5100,34.6300,14331200']
dte = "2015-04-07"

delim = dte.replace("-","") + ","
from itertools import groupby

print([list(v) for k,v in groupby(l,key=lambda x: not x.startswith(delim))])

[['20150406,34.4800,34.8100,34.2300,34.4200,21480500', '2015010,34.5400,34.8900,34.5100,34.6300,14331200'],   ['20150407,34.5400,34.8900,34.5100,34.6300,14331200']]

The groupby will keep splitting the data as many times as there are strings the start with the date.
Answer: by extend from alecxe answer:
The code can split original list to couple sublist by input date.
l = [
...      '20150406,34.4800,34.8100,34.2300,34.4200,21480500',
...      '20160402,34.1,32.8100,33.2300,31.01,22282510',
...      '20150407,34.5400,34.8900,34.5100,34.6300,14331200',
...      '20120101,2.540,14.8201,32.00,30.1311,12331230',
...  '20150407,34.5400,34.8900,34.5100,34.6300,14331200',]

index = [i for i, item in enumerate(l) if item.startswith(d)]
[l[i:j] for i, j in zip([0]+index, index+[None])]

output:
[['20150406,34.4800,34.8100,34.2300,34.4200,21480500', '20160402,34.1,32.8100,33.2300,31.01,22282510'], ['20150407,34.5400,34.8900,34.5100,34.6300,14331200', '20120101,2.540,14.8201,32.00,30.1311,12331230'], ['20150407,34.5400,34.8900,34.5100,34.6300,14331200']]

Splitting data - specific case


How frequently do GitHub run git-gc on repositories?

Question: Assuming that GitHub occasionally run git-gc how frequently does this occur?
Answer: GitHub Support responded to this question on Twitter in 2013.

We run git gc at most once per day, triggered automatically by a push.
Comment: It's not as precise an answer as I'd like but unless you know better it's as good as they've ever communicated. The answer isn't incorrect, isn't misleading and has value. If any of those things weren't true I'd happily remove the answer.
Comment: So, "at most"  ... but it does not explain. One could infer that it's run once per push in a 24 hr period, but still not explicit. And what about now, 7 years later and post-acquisition?
Answer: just tested that a new commit push won't trigger the gc process


How to load entity by UUID from url argument?

Question: Usually routes have {entity_type} in their routes's path and Drupal loads the entity by its ID.
I need to load entities by their UUID, so the path would look like /node/0ff3b31b-5abb-4377-bb00-af71882e38a4.
Is it possible to have a route that allows to load entities by their UUID? Do I need to create a ParamConverter class for this?
Answer: Yes, you need your own param converter for this, the default implementation can only load by UUID.
Loading by UUID is less performant as long as the primary ID is still a serial ID, this means that it first needs to do an entity query to fetch the ID and then load that.
Comment: There's this issue on DO: [Make it possible to link to an entity by UUID](https://www.drupal.org/node/2353611).


problem concerning ideal of Z[X]

Question: let $a$ a complex number , and  $f$  be an irreducible polynomial  with integer coefficients such that : $ f(a)=0$

1) Show that the set : $\{ g(a) \mid g \in  \mathbf{Z}[X]\}$ is a ring isomorphic to $\mathbf{Z}^{n}$  respect to their group structure where $n=\deg f$
2) show that every  non null Ideal of the previous ring is isomorphic to $\mathbf{Z}^{n}$ respect to their group sturcture

Help me to solve these questions with some hints please :)
Comment: You also want $f$ to be monic, I think (What is the rank of $\mathbf Z[\frac 12]$?).
Comment: Is $f$ in $\mathbf Q[X]$? What does $\mathbf Q(a)/\mathbf Q \in \mathbf Z[X]$ mean?
Comment: @mathfan: "Show that $Q(a)/Q\in Z[X]$ is a ring isomorphic to..." What?! First, what is $Q$ and what is $Q(a)$? Second, if $Q(a)/Q$ is an element of $Z[X]$, then it's a polynomial, not a ring.
Comment: @ arturo Magidin : sorry it is a latex problem :  the set { Q(a)/Q \in Z[X]}  is the set of images of a by all polynomials in Z[X]
Comment: @mathfan: No, it's a concept problem: if something is an *element* of a polynomial ring, then chances are that it is a polynomial, **not** a ring itself. What set?  What is $Q$? (To get `{` and `}` to show up, you need to use `\{` and `\}`, but even with them, $\{Q(a)/Q \in Z[x]\}$ is still confused and confusing).
Comment: @mathfan Ah. This is commonly denoted $\mathbf Z[a]$. In this case, you probably want $f$ to have integer coefficients.
Comment: Ok it must be a misuderstanding , because I'm french and I use french notations , I meant by this set : Z[a] which is the ring generated by : a^0=1,a,a²,a^3...  I hope you understand me and I apologize again
Comment: This question is in my opinion hopelessly garbled.  The OP needs to check his/her sources and ask a much clearer question.  As Dylan has pointed out, even with all the help given by others in clarifying the question, it seems to be false as stated: e.g. it is false for $f(x) = 2x-1$.  I have voted to close.
Comment: @mathfan: Being French has nothing to do with your plight in this case. First you had problems with TeXifying. That's ok, if you have never done that. But you are still leaving out an awful lot of assumptions. We could try an guess that you 1) want $f$ to be monic (as Dylan suggested), 2) the ring operations that you left out are those of the complex numbers, 3) you are *only* referring to the additive structure in both your questions. Please edit or this may end up in the waste basket.
Answer: What you are trying to construct is the quotient ring $\mathbb{Z}[x]/(f(x))$, which is the ring of polynomials, modulo the equivalence where two polynomials which differ by a multiple of $f(x)$ are viewed the same.  The ring structure is inherited by the ring structure of $\mathbb{Z}[x]$.  Let $R$ be the ring you defined in your question.  If you have worked with quotient rings before, then a good first step is to verify that the map $\mathbb{Z}[x]/(f(x))\to R\subset\mathbb{C}$ defined by $g(x)\mapsto g(a)$ is an isomorphism (or, by the first isomorphism theorem, that the kernel of the map $\mathbb{Z}[x]\to \mathbb{C}$ given by evaluation at $a$ is exactly the ideal generated by $f(x)$.
The second step is to try to show that $\mathbb{Z}[x]/(f(x))\cong \mathbb{Z}^n$ as abelian groups, where $n$ is the degree of $f(x)$.  For this to hold, you MUST have that that $f(x)$ is monic.  In this case, $1,x,x^2,\ldots, x^{n-1}$ will be a basis for the ring viewed as an abelian group.
To understand the ideals, it is helpful if you know that subgroups of free abelian groups are free (this follows from the structure theorem for finitely generated abelian groups, but an independent proof is given here, which does not require finite generation).  Then, it suffices to show that if $g(x)$ is a polynomial not in $(f(x))$, then $g(x), xg(x), x^2(g(x), \ldots, x^{n-1}g(x)$ are all $\mathbb{Z}$-linearly independent in the ring.  This requires the fact that $\mathbb{Z}[x]$ is a unique factorization domain.
Comment: @Aaron What "requires $\mathbb Z$ is a UFD", and why?
Comment: Aaron ,in the source of this problem they don't mention that f is monic , so i got stuck on the first question , can you give a counter example with f a non monic polynomial? , thank you very much
Comment: If you take $f(x)=2x-1$, your ring is $Z[1/2]$, which contains all the dyadic rationals.  This is not even finitely generated as an abelian group: if you take any finite generating set, you can only get the denominators to be as large as the largest denominator of a generator.  The problem is that you can't divide a polynomial by an arbitrary polynomial when you're working over $\mathbb{Z}$ and still get a remainder of smaller degree (with integer coefficients).  However, the division algorithm works fine if you divide by a monic polynomial.  This is the key to step 2.
Comment: @Bill That was a typo.  I meant $\mathbb{Z}[x]$.  Essentially, we need that the element $f(x)\in \mathbb{Z}[x]$ is not only irreducible but prime.  That way, if some non-zero linear multiple of $h(x)g(x)$ with $\deg(h)<n$ were in $(f(x))$, we could find a lower degree minimal polynomial for $a$, and so the multiples of $x^kg(x)$ of $g(x)$ above must be linearly independent.
Answer: This is pretty confused.
First: it's not enough to just give a set and ask about "ring structure" or "group structure"; you need to say what the operations are. Presumably, you want the operations to be inherited form $\mathbb{C}$ (where the values of $g(a)$ lie).
Second: the problem is incorrect as stated because you have placed no condition son $f$. Take $f(x) =x-\pi$, a polynomial that is irreducible in $\mathbb{C}[x]$ (you never said what kind of polynomial it was, and since you open by considering complex numbers, the obvious interpretation would be that $f$ is a polynomial with complex coefficients). Then $a=\pi$ satisfies the desired condition, but the set $\{g(a)\mid g(x)\in\mathbb{Z}[x]\}$ is isomorphic to $\mathbb{Z}[x]$, and its additive group is free abelian of countably infinite rank, and not isomorphic $\mathbb{Z}^1$, as the statement requires.
So presumably, you want $f(x)$ to be a polynomial with integer or rational coefficients. (Which?) But even more is required, as Pete's comment shows.
So my first hint (nay, strong suggestion), which is very applicable to all math problems is: make sure you write down all the hypothesis!
Now: part (1) has two parts: you want to show that the set is a ring (under the addition and product of complex numbers); and you want to show that as an abelian group it is free of rank $n=\deg f$.
For the first part of part 1, you need to show that the set is nonempty, and that if $g(a)$ and $h(a)$ are in the set, then so is $g(a)-h(a)$; i.e., that you can find a polynomial $k(x)\in\mathbb{Z}[x]$ such that $k(a)$ evaluates to the same thing as $g(a)-h(a)$. This shows it's a subgroup of $\mathbb{C}$. Then you need to show that it is closed under multiplication: if $g(a),h(a)$ are in the set, then so is $g(a)h(a)$; that is, there is a polynomial $k(x)\in\mathbb{Z}[x]$ such that $k$, evaluated at $a$, equals the product of the values of $g$ and $h$ when evaluated at $a$. This part should be easy.
For the second part, try showing that the group is freely generated by $1$, $a$, $a^2,\ldots,a^{n-1}$; you'll need to figure out exactly what the correct conditions on $f$ are supposed to be, otherwise this is going to be very hard (if not false; see above).
For part 2, suppose that you have a nonzero element in the ideal, and think about what happens when you multiply it by $1$, $a$, $a^2$, $a^3,\ldots,a^{n-1}$.

problem concerning ideal of Z[X]


Devo usar int_least8_t ou int_fast8_t?

Question: Estou estudando os limites de tipos que o c++ 11 trouxe e observei que existe oficialmente vários tipos de inteiros.
Além da declaração comum int agora eu posso declarar:

int8_t
int_fast8_t
int_least8_t

Nesta pergunta tem uma explicação boa de cada tipo.
Considerando uma plataforma em que o int tenha tamanho de 10 bits.O tipo int8_t não conseguiria ter exatamente 8 bits.
O que é melhor para eu escolher, int_fast8_t ou int_least8_t?
Comment: Existe alguma plataforma em uso com byte de 10 bits?
Comment: Não sei dizer. Conheço poucas arquiteturas. A pergunta é mais teórica do que prática. Estou curioso em saber as regras que estão envolvidas em toda a tomada de decisão do compilador.
Answer: Na verdade, até que tenha um motivo para escolher alguma coisa diferente de int, deve escolhê-lo.
Se quer usar um char, use-o. Ele tem sempre 1 byte. E duvido que encontre uma plataforma ativa que que o byte seja diferente de 8. Certamente nenhum é menor que 7, ou C padrão não pode funcionar, afinal ele precisa poder representar pelos menos 95 caracteres diferentes. E seria o único caso onde o int_fast8_t não seria um char, mas na prática isso não existe.
Lá na pergunta fala que o int_least8_t é sempre um char. Ele pode ser usado para dar uma semântica diferente e indicar com mais clareza que ali não é um char e sim um inteiro com pelo menos 8 bits. Na prática muda nada.
Quer escolher para que? Sem uma definição do problema, qualquer solução pode ser boa.
Se vai desenvolver para várias plataformas e precisa garantir que em todas tenham a melhor performance possível para o inteiro de pelo menos 8 bits quase sempre será um int. Eu não "perderia tempo" e usar algo assim se não for comprovado que é absolutamente necessário.
C e C++ exigem que o int tenha pelo menos 16 bits e não pode ser maior que o long int. Se realmente tiver 10 bits, a implementação não é padrão, então qualquer coisa pode acontecer de acordo com a vontade do implementador, mas na prática não é mais a linguagem C ou C++.
Em tese cada implementador da linguagem pode colocar o que quiser nesses tipos para cada plataforma que ele gere código, desde que obedeça a regra da especificação, e estar dentro do padrão. Na dúvida escolherão o int que é bem comum, mas não obrigatório ser do tamanho da palavra do processador.
Na verdade, a pergunta é mais imaginária do que teórica.
Coloquei no GitHub para referência futura.
Comment: Editei, mas talvez tenha piorado :)
Comment: Fiz uma pequena edição na pergunta para mudar o tipo de char para int. Poderia editar sua resposta de acordo?
Comment: Não tem problema, acredito que ficou melhor, ainda mais destacando que esse problema é mais teórico que prático.
Answer:
O que é melhor para eu escolher, int_fast8_t ou int_least8_t?

int_least8_t é o menor tipo inteiro com pelo menos 8 bits, deve escolhê-lo se se prioriza espaço (memória)
int_fast8_té o mais rápido tipo com pelo menos 8 bits, deve escolhê-lo se prioriza tempo (performance)

Estas definições estão presentes para explicitar as intenções ao escolher o tipo. Uma biblioteca matemática que requer alta performance pode preferir o int_fast8_t, e uma biblioteca que precisa guardar muitos dados pode preferir o int_least8_t. Como ambos tipos garantem 8 bits de precisão, o programador tem certeza que pode realizar cálculos na faixa [-128, 127] com o int_fast8_t, e registrar valores entre [-128, 127] com o int_least8_t.
Na maioria dos processadores pessoais (onde costumo programar) ambos tipos mapeiam para o signed char, mas supondo que eu desenvolva um programa e depois desejo portá-lo para outra plataforma (como compilar um jogo para algum celular ou video-game), o compilador (ou programador) pode alterar o tipo int_fast8_t para algum mais rápido no novo processador, aumentando a performance das funções matemáticas sem alterar o funcionamento do código nem outras partes do programa.

(isso pode soar óbvio para quem fala inglês, mas expandir o nome dos tipos ajuda:)

int_least8_t : tipo_inteiro_pelo_menos_8
int_fast8_t : tipo_inteiro_rápido_8
Comment: @jlHertel pena ter ficado muito parecido (não era a ideia), mas esse é o motivo pelo qual os tipos foram inventados/definidos.
Comment: Se é um int não-unsigned, o máximo não seria 127 em vez de 255? (supondo complemento de 2)
Comment: Você meio que respondeu a mesma coisa que a pergunta no SOen. Mesmo assim dei +1 por complementar a pergunta e servir de referencia caso mais algum usuário tenha dúvida.
Comment: @marcus sim! Corrigido!

Devo usar int_least8_t ou int_fast8_t?


How to export shares so that users don't create file as root

Question: I am trying to export home directories from my NAS to ubuntu clients - the server is a TrueNAS Scale, which is Debian based.
Kerberos works, so users get the proper tickets to authenticate to the server.
My main goal is that users can mount their home dirs off the server.
I have a share called home on the server with one directory per user. The home directory is owned by root, and the subdirectories are owned by the users.
However, if I don't use maproot nor mapall, even if I manage to mount the share, the user can't write anything to his folder if mounting /home/folder.
If I use maproot=root, the user mounts it, but everything he writes is saved as root.
I am lost here, but it seems there might be a problem with the id mapping. The uid/gid of the files are the same across server and client, the right names showing, etc. This makes me believe that the mapping is correct - however, when using maproot=root, why I end up having access to folders that don't belong to me, and why everything I create with that user is owned by root?
How I can properly export this so that I get root squashed, as well as that the users only get access to their own directories?
Comment: Assuming Kerberos is actually being used, there should be _no_ "map" options needed for this to work, rather than adding more and more options. Is the initial mount done by root or by the user? Was your client machine's krb5.keytab accidentally left world-readable? When a user tries to access the mount for the first time, does the client's machine rpc.gssd show any activity, and does a ticket for nfs/yournas show up in their personal ticket cache (klist)?
Comment: Thanks @user1686. It seems that the problem was idmapd.conf that didn't have a "Local-Realms" option configured correctly.
Answer: The problem was that /etc/idmapd.conf didn't have a Local-Realms configured, which was necessary since the domain of the client isn't the same as the server.


Explaining The Shape Of An Absolute Value Graph

Question:
I don't understand why the shape of the graph would be like this, for the give equation. Why wouldn't the shape resemble that of a normal quadratic graph $(abs(x)+3)^2$?
Comment: You can see that the x and y axes are not scaled equally. The graph iz zoomed too much. Put the scaling correctly, and you will see that it resembles a quadratic graph with som non-smooth behaviour in x=0.
Answer: It does resemble two portions of a normal quadratic graph, glued together. Just check the values at integers: $9, 16, 25, \ldots$.
However, the apexes of the parabolas are  in the cut-off parts.
To better see the relation, you may want to graph $(x+3)^2$ and $(-x+3)^2$ concurrently.
Answer: $y=(|x|^2+3)^2= x^2 +6|x| +9.$
1) $x \ge 0: $
$y=x^2 +6x +9 =(x+3)^2$
2) $x \lt 0$:
$y = x^2-6x +9=(x-3)^2$
1) $y= (x+3)^2$, is a parabola with  vertex at $(-3,0)$.
For $x\ge 0$ you get the right hand branch of your drawing.
2) $y= (x-3)^2$, is a parabola with vertex at $(3,0)$.
For $x\lt 0$ you get the left hand branch of your drawing.


Cloud code aftersave method not working

Question: I just need help to trigger my aftersave method in cloud code. I am new to parse.
The following are the steps I followed
1) I save one class named "Send" in my android code using send.save()
2) I have set up a cloud directory in my windows by following
     https://parse.com/apps/quickstart#cloud_code/unix
3) I have created a method like this in main.js
<code> Parse.Cloud.afterSave("Send", function(request) {
    var userQuery = new Parse.Query("User");

    userQuery.get(request.object.get("name"), {

    success: function(user) {
          Parse.Cloud.useMasterKey();

                console.log("success");
                alert("success");

            },
            error : function(error) {
               console.log("error" + error);
            }
    });
  });
</code>
4)I have deployed my cloud code using parse deploy
5) When I save the send object it gets saved to the Parse DB. But the aftersave function not getting called or I cannot see anything happening. Can anyone guide me whats missing?
Help is much appriciated.
Answer: When you set master key inside success callback, i don't think it has any meaning to it. Try setting it before:
<code>Parse.Cloud.afterSave("Send", function(request) {
   Parse.Cloud.useMasterKey();
   var userQuery = new Parse.Query("User");

   userQuery.get(request.object.get("name"), {

      success: function(user) {

         console.log("success");
         alert("success");

        },
        error : function(error) {
           console.log("error" + error);
        }
   });
});
</code>
Also, please note that in your Parse.com "Core" interface, you have a button on the left named "Logs", when you enter this one, you get detailed log of all your cloud code activity. When you look there you can easily track your success or errors.

Cloud code aftersave method not working


How to train recognizing chords by ear ?

Question: How should I train my ears to recognize different 'flavours' of chords ?
I mean especially recognizing what fourth/fifth notes were added to the chord (beyond the minor/major triads) such as 7#9 etc. (I'm not trying to recognize the absolute pitch however).
Comment: Have you done any other ear training? I highly recommend interval training as a first step.
Comment: Take the book "Jazz Improvisation No. 1" by Mehegan. Play through all the examples on the piano. Repeat until your ear starts to recognize the flavors of the chords.
Answer: MusicTheory.net has a flash application to practice chord recognition. It doesn't go into more complex chords like 7#9, but it presents 10 chords (typical four-note chords and triads). That's a starting point. There must be applications supporting more "advanced" chords but I'm not aware of them, so I typically end up programming my own.
Comment: this indeed is useful ! Even though it 'only' has 10 types of chords, I'll first practice to get a reasonable rate of correct answers there.
Answer: I once heard from a pianist that the chord you know is what you will hear in a song. This means that if you hear a song and hear a Dominant #5b9 and you were very familiar with dimished chords you will first interpret the chord you heard as a diminshed chord my advise is to learn the different chords. Go to apassion4jazz.net (something like that). You will see a lot of chords there. Start practicing them and get accustomed to their distinct sounds. When you hear any of them in a song you will most likely stand a better chance of picking them. Taking risk is borne out of passion. Passion is almost equal to success. Cheers.
Comment: As a player of many years I can say that accustomization has not helped me recognize chords. I do know that for some it comes easily, obviously there's a lot you're born with. As for learning, I'm still trying.
Answer: Full disclosure: I do have perfect relative pitch, and a kind of perfect pitch for a few notes. So your experience may differ from mine.
My recommendation would be to play with how chords are arranged. If you break apart, for instance, a C major with a minor 7th, you have 4 notes (generally speaking... piano experience here): C, E, G, and Bb. When played one at a time with each sustaining through to the end, you can clearly hear what notes are being added and then afterward hear what the full chord sounds like. So how I learned to recognize chords was to play them broken apart like this and recognize initially the increment from the 1st to the nth, and then just check pitch to tell whether the nth was higher or lower. With practice and repetition, this gets pretty fast, so that now I can hear a chord and am generally spot-on with what it is, and most of the time what key it's in.
As a side note, this makes it easier to tell instantly whether an instrument is out of tune, before any playing actually happens. Once you've trained your brain to listen for these things, just two notes played can give you a good idea of how well-tuned the strings may be.
Answer: This site - Tunelark.com has some really nice educational games where you can practice identifying different sets of chords. I found it super helpful. You can also level up and unlock new sets of chords which is cool. You can also go straight to the demo form this link https://www.tunelark.com/demo/chords/basic-triads


Votable node content type in D7

Question: I'm trying to figure out the best way of creating a content type that allows for creating nodes that can be assigned to a group and can be voted for in competition with the other nodes in that group. I started writing a module for it by using the Fields API, Node API and Voting API but I want to check to see if I can use an existing module to do this before I get too far into the project.
For example, I want to create a content type called "contestant" and give the content type 3 different brackets it can be assigned to. Then when I create the contestent content and select one of those brackets, the content becomes votable and is ranked against other pieces of content within that bracket.
Any references to existing modules or suggestions would be awesome.
Answer: I'm not sure I totally follow what you're trying to achieve, but Fivestar is a very flexible module
https://drupal.org/project/fivestar
I use it to vote for a few different content "dimensions" (2-3 votable fields) and then with views you can output it as a table with click sorting by any one of the ratings fields.

Votable node content type in D7


Changing the default "View" page when user logs in?

Question: In Drupal 6 when a user logs in, they are presented with a completely useless page that has no information other than how long the user account has existed.
How do you edit this? Can you embed a view or something there? How would I make a Homebox the default tab? (I've tried using Tab Tamer to hide and disable the tab, but no effect -- still has the lousy "History" info.).
Thanks!
Answer: I think the Login Destination module may help you.
Answer: If you are using Panels/Pages you can enable the user_view page (admin/build/pages/edit/user_view) and add views or whatever else you want there.
Comment: Having now done a lot more Drupal development, I'd probably use this approach now.
Answer: The Login Tobogan module will let you direct users to something else when they log in. It has lots and lots of configuration options.
Or you could use a Panel to override the display of the user profile and put the other views you want there.


Erro ao realizar rota android : AndroidHttpClient: Leak found

Question: Pessoal Estou com o seguinte erro :
08-24 22:52:53.529 9872-9880/br.com.anjodarua E/AndroidHttpClient: Leak found
                                                                   java.lang.IllegalStateException: AndroidHttpClient created and never closed
                                                                       at android.net.http.AndroidHttpClient.<init>(AndroidHttpClient.java:156)
                                                                       at android.net.http.AndroidHttpClient.newInstance(AndroidHttpClient.java:142)
                                                                       at br.com.anjodarua.MainActivity$2.run(MainActivity.java:352)

Esse metodo é o click do meu botao quando eu vou pesquisar, passe as rotas na
mao para evitar trabalho
 public void getRouteByGMAV2(View view) throws UnsupportedEncodingException{
        EditText etO = (EditText) findViewById(R.id.edt_origem);
        EditText etD = (EditText) findViewById(R.id.edt_destino);
        String origin = URLEncoder.encode(etO.getText().toString(), "UTF-8");
        String destination = URLEncoder.encode(etD.getText().toString(), "UTF-8");

        getRoute(new LatLng(-20.195403, -40.234478), new LatLng(-20.304596, -40.291813));
    }

o erro da no meu método getRoute na linha AndroidHttoClient segue
// WEB CONNECTION
    //public void getRoute(final String origin, final String destination){
    public void getRoute(final LatLng origin, final LatLng destination){
        new Thread(){
            public void run(){
                        /*String url= "http://maps.googleapis.com/maps/api/directions/json?origin="
                                + origin+"&destination="
                                + destination+"&sensor=false";*/
                String url= "http://maps.googleapis.com/maps/api/directions/json?origin="
                        + origin.latitude+","+origin.longitude+"&destination="
                        + destination.latitude+","+destination.longitude+"&sensor=false";

                HttpResponse response;
                HttpGet request;
                AndroidHttpClient client = null;
                client = AndroidHttpClient.newInstance("route",MainActivity.this);

                request = new HttpGet(url);
                try {
                    response = client.execute(request);
                    final String answer = EntityUtils.toString(response.getEntity());

                    runOnUiThread(new Runnable(){
                        public void run(){
                            try {
                                //Log.i("Script", answer);
                                list = buildJSONRoute(answer);
                                drawRoute();
                            }
                            catch(JSONException e) {
                                e.printStackTrace();
                            }
                        }
                });

            }
            catch(IOException e) {
                e.printStackTrace();
            }
        }
    }.start();
}

Porem o meu json vem populado , quando ele vai retornar o "lines" ele da o erro indicado acima , segue o json
 // PARSER JSON
    public List<LatLng> buildJSONRoute(String json) throws JSONException{
        JSONObject result = new JSONObject(json);
        JSONArray routes = result.getJSONArray("routes");

        distance = routes.getJSONObject(0).getJSONArray("legs").getJSONObject(0).getJSONObject("distance").getInt("value");

        JSONArray steps = routes.getJSONObject(0).getJSONArray("legs").getJSONObject(0).getJSONArray("steps");
        List<LatLng> lines = new ArrayList<LatLng>();

        for(int i=0; i < steps.length(); i++) {
            Log.i("Script", "STEP: LAT: "+steps.getJSONObject(i).getJSONObject("start_location").getDouble("lat")+" | LNG: "+steps.getJSONObject(i).getJSONObject("start_location").getDouble("lng"));

            String polyline = steps.getJSONObject(i).getJSONObject("polyline").getString("points");

            for(LatLng p : decodePolyline(polyline)) {
                lines.add(p);
            }

            Log.i("Script", "STEP: LAT: "+steps.getJSONObject(i).getJSONObject("end_location").getDouble("lat")+" | LNG: "+steps.getJSONObject(i).getJSONObject("end_location").getDouble("lng"));
        }

        return(lines);
    }

    // DECODE POLYLINE
    private List<LatLng> decodePolyline(String encoded) {

        List<LatLng> listPoints = new ArrayList<LatLng>();
        int index = 0, len = encoded.length();
        int lat = 0, lng = 0;

        while (index < len) {
            int b, shift = 0, result = 0;
            do {
                b = encoded.charAt(index++) - 63;
                result |= (b & 0x1f) << shift;
                shift += 5;
            } while (b >= 0x20);
            int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
            lat += dlat;

            shift = 0;
            result = 0;
            do {
                b = encoded.charAt(index++) - 63;
                result |= (b & 0x1f) << shift;
                shift += 5;
            } while (b >= 0x20);
            int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
            lng += dlng;

            LatLng p = new LatLng((((double) lat / 1E5)), (((double) lng / 1E5)));
            Log.i("Script", "POL: LAT: "+p.latitude+" | LNG: "+p.longitude);
            listPoints.add(p);
        }
        return listPoints;
    }

Answer: Tente ao finalizar seu AndroidHttpClient usando client.close() para encerra-lo.

AndroidHttpClient created and never closed

Esta mensagem acima diz que foi criado uma variváel do tipo AndroidHttpClient  mas nunca fechado. Suponho que seja isso. Use o código abaixo e adapte as suas necessidades:
try {
    HttpResponse response = client.execute(request);
    return new ByteArrayInputStream(new EntityUtils.toByteArray(response.getEntity()));
} catch (IOException e) {
    e.printStackTrace();
} finally {
    client.close();
}

Verifique também se você está dando permissão a INTERNET no seu manifest. E se tratando de Android 6.0, verifique as questões de Controlar as permissões do seu de app.
<uses-permission android:name="android.permission.INTERNET"/>


Which soccer player played for the most national teams?

Question: Alfredo Di Stéfano back in the 50's-60's played for Argentina, Colombia, and Spain. Many soccer players played for 2 teams, but that's the only case I know of someone playing for 3 teams. Was he the player who played for the most national teams or was there another one?  Which soccer player played for the most national teams?
Comment: I saw the title and was going to suggest Di Stefano as an answer. I don't know of any other footballer who played for three different national teams, but that doesn't mean there isn't one. Just to complicate matters, [Di Stefano's appearances for Colombia aren't recognised by FIFA](https://en.wikipedia.org/wiki/Alfredo_Di_St%C3%A9fano#Colombia), as the country wasn't a member of FIFA at the time.
Comment: Apparently he isnt the only one https://en.wikipedia.org/wiki/Neil_Kilkenny
Comment: Looking at the Wikipedia article, shouldn't the question say that he played for Spain (rather than Uruguay)?
Comment: @Martin I don't know how I didn't catch that, I've submitted an edit to fix it.
Comment: There is a Wikipedia article [List of nationality transfers in association football](https://en.wikipedia.org/wiki/List_of_nationality_transfers_in_association_football) - however, according to [the talk page](https://en.wikipedia.org/wiki/Talk:List_of_nationality_transfers_in_association_football), there are several issues with that list.
Comment: @Martin I agree with you. The vast majority of the players on that list don't seem to have actually played for the team they were originally eligible for.
Answer: Examples of player who played for three countries.

As mentioned in the question, Alfredo Di Stéfano played for Argentina and Spain. In addition to that, he played for Columbia - although those matches aren't in the official FIFA records.
László Kubala played for Czechoslovakia, Hungary and Spain. Kubala also played for Catalonia - however, this team is not a member of FIFA/UEFA.

If we also count caps at the youth level:

Daniel Brailovsky played for Uruguay at youth level and later represented Argentina and Israel.
Neil Kilkenny represented England and Ireland at the youth level, and later played for Australia.
Demitrius Omphroy played for USA and Panama at youth level, as a senior for Phillippines.
Herolind Shala played for Norway (youth level), Albania and Kosovo.
Alex Zahavi played for Portugal, USA, Israel - in all three cases at the youth level.

Sources:

Wikipedia article FIFA eligibility rules (current revision).
Wikipedia article List of sportspeople who competed for more than one nation (current revision).
Wikipedia articles of individual players.
#FootballTrivia: These footballers played for more than one country
Comment: This answer was intentionally made [community wiki](https://sports.meta.stackexchange.com/tags/community-wiki/info) - feel free to edit it if you have some suitable additions.
Comment: The Wikipedia article [List of sportspeople who competed for more than one nation](https://en.wikipedia.org/wiki/List_of_sportspeople_who_competed_for_more_than_one_nation#Men%E2%80%99s_Football_(soccer)) lists Sweden U21, Albania and Kosovo for Loret Sadiku, however the [article about the player](https://en.wikipedia.org/wiki/Loret_Sadiku) ([current revision](https://en.wikipedia.org/w/index.php?title=Loret_Sadiku&oldid=934306537) does not mention any caps for Albania.
Answer: Di Stefano played for both Spain and Argentina and even Puskas played for Hungary and Spain.
Even Platini turned out  in a match for Kuwait.


If $n$ is a natural number and $n$ is a $4th$ power and a $5th$ power prove it is a $20th$ power.

Question:
If $n$ is a natural number and $n$ is a $4th$ power and a $5th$ power
  prove it is a $20th$ power. (Hint: Use fundamental theorem of arithmetic).

I can't do this problem and am looking for advice.
I know you can express $n$ as two different numbers $x,y$ say one to the $4th$ power the other to the $5th$ power. And each of these can be expressed as the product of increasing prime numbers.
I somehow need to get that there exists a number such that when you put it to the $20th$ power you get $x$.
It looks like I'm very close in my writings but I can't seem to make that vital last step.
I'm guessing it has something to do with manipulating the different equations for $x$.
Any help?
Comment: Consider the prime factorization of $n$
Answer: Hint: $n=\prod p_i^{\alpha_i}$.
Since $n=x^4=y^5$, what can we say about the factorizations of $x^4,y^5$, and consequently about $\alpha_i$?
Comment: $(\prod p_i^{\alpha_i})^{\frac{1}{4}}=x$ and $(\prod p_i^{\alpha_i})^{\frac{1}{5}}=y$.
Comment: Hmmmm so can we take the product $xy$ and get $(\prod p_i^{\alpha_i})^{\frac{1}{20}}=t$. So this is the number we want?
Comment: Either that, when you need to state that $4|\alpha_i$ else $x$ is not an integer. Note, though, that exponents add when multiplying, so your property for $t$ doesn't hold. Else you could simply write $x^4=\prod p_i^{4\beta_i}$, and the fundamental theorem tells you that $4\beta_i=\alpha_i$, and then...
Answer: Consider any prime factor $p$ of $n$. $n$ will be divisible by some positive power $k$ of $p$, so $p^k \mid n$, taking the maximum $k$.
Since $n$ is a fourth power, we know that $p^{k/4} \mid \sqrt[4]n$ - so $4 \mid k$. And since $n$ is a fifth power, we know that $p^{k/5} \mid \sqrt[5]n$ - so $5 \mid k$.
Therefore we also know that $\text{lcm}(4,5) \mid n$, and since $\gcd(4,5) = 1$, that means that $20 \mid k$.
Since this is true for any prime divisor on $n$, all the prime power exponents in the prime decomposition of $n$ will be divisble by $20$ and hence $n$ is a $20^{th}$ power.
Answer: Note that $n^5=x^{20}$ and $n^4=y^{20}$ so that $$n=\frac {n^5}{n^4}=\left (\frac xy\right)^{20}$$
And you may know a way to prove that if $q$ is a rational number with $q^r=n$ where $r$ and $n$ are positive integers, then $q$ is an integer. Or it is easy to prove this special case.
This doesn't use the fundamental theorem of arithmetic directly, but it is there in the background of the second paragraph. And I've left that key part of the proof to you. But I thought showing how $n$ can be directly expressed as the twentieth power of something might be of interest.