Using set notation, define the set of even natural numbers between 100 and 500.

Question:
Using set notation, define the set of even natural numbers between 100 and 500.

This is what I have so far:
$P$ is even numbers so the set of natural numbers between 100 and 500 would be
$$P = \{x:x \in\mathbb  N, 100 < x < 500\}$$
Would this be correct?
Comment: @Harry: You say "I don't know how you would characterise an even interger", but you must have a concept of "even integer". What is this concept? For example, you might know that 14 is an even integer. How do you justify that believe? If you know how to express the argument that 6, 14 and 9002 are all even integers, then you know how to characterize it. The only thing left to do is replace that definition with set theoretical language. But go step by step.
Comment: Your set includes $101$, which is odd. Also note that there are many ways of describing the set.
Comment: Welcome to Stack Exchange, @Harry. If one of the answers below answers your question, you should accept it (click the check mark next to the appropriate answer). That does two things. It lets everyone know your issue has been resolved, and it gives the person that helps you credit for the assist. See [here](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) for a full explanation.
Comment: if $N$ is the set of natural numbers, then your set includes all natural  numbers between 1 and 500.
Comment: So how would I write it? P = {x:x ∈ N, 100 ≤ x ≤ 500}
Comment: No. This description still includes 101. How would you characterise an even integer? (There are a few ways.)
Comment: Tbh I don't know how you would characterise an even interger.
Comment: $2 \mid n$ is one way ('two divides $n$').
Comment: @Harry: I would suggest $\{2x|x\in \mathbb N\wedge 200\le 2x\le500\}$.
Answer: Here is one way:
$\begin{align}
P= \{
&102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, \\
&136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, \\
&170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202, \\
&204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, \\
&238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, \\
&272, 274, 276, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, \\
&306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, \\
&340, 342, 344, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 366, 368, 370, 372, \\
&374, 376, 378, 380, 382, 384, 386, 388, 390, 392, 394, 396, 398, 400, 402, 404, 406, \\
&408, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, \\
&442, 444, 446, 448, 450, 452, 454, 456, 458, 460, 462, 464, 466, 468, 470, 472, 474, \\
&476, 478, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498 \}
\end{align}$.
Another slightly shorter way:
$P= \{ n \in \mathbb{N} | 100 < n < 500 \text{ and } \sin ( n {\pi \over 2} ) = 0 \}$.
Inspired by Charlotte's answer:
$P= (2 \mathbb{N}+\{100\}) \setminus (2 \mathbb{N}+\{498\})$.
Et iterum (Haskell's take on Ross' answer):
<code>[2*x | x <- [51..249] ]
</code>
Comment: ... you're not wrong.
Comment: @rubik: It is just shorthand, if $\square$ is some binary operation, then $A \square B = \{ a \square b | a \in A, b \in B \}$. Then $\{a,b\}+ \{c,d\} = \{a+c,a+d,b+c,b+d\}$.
Comment: @HenningMakholm: Why would I want to 'trick the OP...'??? You are seeing darkness where there is none.
Comment: I like this${}{}{}$
Comment: @Meelo: If I do, I will be arrested by the MathJax police...
Comment: @HenningMakholm: Your comment seems harsh when the intent was to help by providing some alternatives (one light hearted). If you follow the comment trail you will note that I have attempted to guide the OP before answering. (In addition, albeit you could obviously not be privy to this, I had a number of email exchanges with the OP clarifying and expressing the OP's intent in the OP's desired manner.) I don't care about the -2, but am dismayed by your perception.
Comment: I did think of this but thought it was too simple lol
Comment: Is the addition of sets a commonly accepted notation? What would $\{a,b\}+\{c,d\}$ result in?
Comment: @Dave: $\{a, b, c, d\}$?
Comment: @copper.hat: A mapping over the set (in this case an addition) shouldn't be written like this: $2\mathbb{N} + 100$?
Comment: @rubik That would be union, and that is not at all what is meant in the post.
Comment: Why the downvote?
Comment: @copper.hat: That makes sense, thanks for the explanation!
Comment: If you want to use set builder notation, I suggest the variation on this answer (where $\vee$ is "or")
$P=\{x\in \mathbb N:x= 102 \vee x = 104 \vee x = 106 \vee x = 108 \vee \ldots\}$
Comment: Downvoted because the answer seems to be trolling the OP rather than trying honestly to tell him what he needs to know. It is all well and good to show there are multiple ways to slice this cake, but clearly he's trying to do it the _straightforward_ way yet failing, and that deserves an answer that addresses his initial misconception. (If his misconception had been "there is a single correct way to write this", this would be a great answer, but I don't see that being the case).
Comment: @copper.hat: As far as I can see, _all_ the proposals here are "light-hearted", as you term it. I would call them "unnecessarily comples". If you have a different purpose with your answer than attempting to trick the OP into writing his set in a more obfuscated way than he needs to, you have failed to indicate what that purpose could possibly be. Feel free to be "dismayed" by having your trolling of the OP called out -- my sympathy is entirely on his side, not on yours.
Comment: The first (i.e. enumerating) variant certainloy does not deserve a downvote, the one unnecessarily invoking the sine function probably does. On the other hand, anyone using setbuilder notation for the set of even numbers between 100 and 103 *would* deserve being punished. - Which raises the problem: Where is limit at which one *should* switch from enumerating to setbuilder?
Comment: @HagenvonEitzen: 42, of course :-).
Answer: For something very close to your proposal, you could say $$P=\{2x:x \in \Bbb N, 50 \lt x \lt 250\}$$  The $2x$ is one way to get rid of the odd numbers.
Comment: @Harry: The protocol is that if you are happy with an answer that you accept it. There is no hurry, just letting you know ;-).
Comment: Ahhh thank you, this is exactly the solution i was looking for :)
Comment: thank you all for the help :) trying to learn this atm and the guides ive been given haven't been much help
Comment: Good luck. Its a bit intimidating. My rule is generally ask forgiveness not permission...
Answer: Let $\mathbb N=\{1,2,3,...\}$. You want a set which includes the even members of $\mathbb N$ that lie between 100 and 500. Well, a member $n$ of $\mathbb N$ is even precisely when $n=2k$ for some $k\in\mathbb N$.
So $\{n\in\mathbb N:(\exists k\in \mathbb N)(n=2k)\text{ and } 100<n<500\}$ works.
(use the weak inequality $\leq$ if you want to include 100 and 500 in the set).
Comment: What does the k stand for?
Comment: What I am saying in the parentheses is "$n=2k$ for some $k\in\mathbb N$."
Comment: Ahhh ok thank you for the help :)
Comment: This notation is more useful than the other expressions since it offers many advantages in proving something.
Answer: I would tend to use one of;
$P = \{ n \in \mathbb{N}: 100 < n < 500, 2\mathop{|}n \}$
or
$P = \{n \in \mathbb{N}: \text{$n$ even}, 100 < n < 500 \}$
The latter I suppose is slightly less formal, but it would be perfectly normal to see it used in a lecture or talk, say, and it is probably the clearest possible when speaking or reading.
Note $m \mathop{|} n$ means that $m$ divides $n$, i.e. $n$ is an integer multiple of $m$.
Comment: I think it would be better to use $\&$, $\wedge$, or "and" instead of the commas.
Comment: Another similar alternative would be to use $n \equiv 0 \pmod 2$ as the predicate.
Comment: I have always seen `|` used as an equivalent for `such that`, so at first this confused me.
Answer: The most succinct way I know is
$$\{x|100\leq x \leq 500, x\in2\mathbb{Z}\}$$
Inspired by copper.hat and NicolajK, inter alia, here are some further valid answers:
$$\left\{2x+100\Bigg|\prod_{i=0}^{200}(x-i)=0\right\}$$
$$\{x|x\text{ is an even integer between 100 and 500}\}$$
$$\left\{x\Bigg|x=\frac{p^{(2n)}(0)}{p^{(2n-1)}(0)}, n\in\mathbb{N}\right\},\quad p(x)=\sum_{i=100}^{500}x^i$$
$$\{x|x=\log_2[G:H],\,H\subseteq G,\,|H|\leq 2^{100},\,|G|=2^{500}\},
\quad G\text{ is a group}$$
$$\begin{aligned}&\{((q\text{ incr})0)|\exists p\in\mathbb{H},
\\&q=
\\&\lambda pfx.((\lambda MNfx.N(Mf)x)(\lambda MNfx.(NM)fx)f(f(f(f(fx))))f(f(x)))f((pf)pfx)
\\&\text{and}
\\&\lambda M.\lambda N.(\lambda n.n(\lambda x.(\lambda ab.\lambda b))
(\lambda ab.a))(\lambda mn.n(\lambda nfx.n(\lambda gh.h(fg))(\lambda u.x)(\lambda u.u)\\& m) M N)q(\lambda MNfx.(NM)fx)f(f(f(f(fx))))f(f(f(x)))f((pf)pfx)\}\end{aligned}$$
where $\mathbb{H}=\{\lambda fx.x,\lambda fx.fx,\lambda fx.f(fx),\lambda fx.f(f(fx)),\dots\}$.
Comment: I like this. It has inspired me.
Comment: Me too, it looks like the first solution i had in my mind $\{x|100\leq x \leq 500, \frac{x}{2}\in\mathbb{N}\}$
Comment: I would +1 again if I could. Quidquid Latine dictum sit viditur altum. With apologies to Fr. Roderick, my latin teacher.
Comment: :-) ${}{}{}{}{}$
Comment: Nikolaj, with k. @kai: If you write the arithmetic operation $\tfrac{x}{2}$, you should maybe specify a sensible domain for $x$ to range over. $\mathbb Q$ will be the shortest answer.
Comment: $\{x|\text{x, integer, non est a duobus divisibilis, et maior quam centum, et minus quam quingenti}\}$
Answer: Computer scientists know that any binary number that is greater than zero is even, if the least significant bit is zero
$$ \{x:x \in \Bbb N, 100 \lt x \lt 500, x=(b_8\dots b_10)_2\} $$
Cryptographers might do it like this
$$ \{x:x \in \Bbb N, 100 \lt x \lt 500, x\equiv 0\ (\mathrm{mod}\ 2)\} $$
Answer: Some more versions:

$\{x\in 2\Bbb N|100<x<500\}$ or $\{x\in 2\Bbb Z|100<x<500\}$
$2\Bbb N \cap (100;500)$ or $2\Bbb Z\cap (100;500)$
Answer: Using remainder classes, you can express it as
$$
P = \lbrace 100 + [n]_{400} \mid n \in \mathbb{N} \rbrace
$$
Which is equal to
$$
P = 100+\mathbb{Z}_{400}
$$
Answer: If we really want short, we could do this:
$$2\mathbb Z\cap[100,500]$$
If you need the set brackets:
$$\{x:x\in 2\mathbb Z\cap[100,500]\}$$
where $[a,b]=\{x:x\in \mathbb R \land a \le x \le b\}$, the normal sense of $[a,b]$
Answer: A few more ways to express it:
$P=\{x\in\mathbb{N}:100<x<500\land\lfloor\frac{x}{2}\rfloor=\frac{x}{2}\}$
$P=\{x\in\mathbb{N}:100<x<500\land x\equiv0\mod{2}\}$
$P=\{x\in\mathbb{N}:100<x<500\land\frac{x}{2}\in\mathbb{N}\}$
Answer: $\{|n| \mid n\in E, 100<|n|<500\}$
where
$E\equiv\{\emptyset\}\cup\{x\mid\exists (y\in E).\,x=\left(y\cup\{y\}\cup\{y\cup\{y\}\}\right)\}$
Comment: @charlotte: The solution is skipping every second number in the [von Neumann model](http://en.wikipedia.org/wiki/Ordinal_number#Von_Neumann_definition_of_ordinals) of N. Given any finite set $X=\{a,b,\dots,s,t\}$ with cardinality $n$, the set $\mathrm{succ}(X):=X\cup\{X\}=\{a,b,\dots,s,t,X\}$ has cardinality $n+1$ (as no set in standard set theory contains itself, see [this axiom](http://en.wikipedia.org/wiki/Axiom_of_regularity)). So $\mathrm{succ}(\mathrm{succ}(Y))$, which is $Y\cup\{Y\}\cup\{Y\cup\{Y\}\}$, adds the cardinality by $2$. The set $E$ is generated by $\emptyset$ of size $0$.
Comment: @charlotte: I've discussed these concepts in my online notebook, see [successor set](http://axiomsofchoice.org/successor_set), followed by [first infinite von Neumann ordinal](http://axiomsofchoice.org/first_infinite_von_neumann_ordinal), followed by [natural number](http://axiomsofchoice.org/natural_number). I try to elaborate on the axioms in the entry [set theory](http://axiomsofchoice.org/set_theory) and I say something on models [here](http://axiomsofchoice.org/univalence_axiom) (skip right to the Motivation section).
Comment: This is beautiful. So if there's a set $y$ of order $n-2$ in $E$, then $x$ has order $(n-2)+1+1 = n$. Can you prove, though, that there are no odd-ordered elements in the set?
Comment: @charlotte: No, you're right I was sloppy. To guarantee there are no extra sets in it, I need to add the condition that the $y$'s are also of the form $y'∪{y'}∪{y'∪{y'}}$ for some $y'$ in $E$. I mirrored the von Neumann construction of the countable set of ordinals - I can give you some more references on these constructions if you like.
Comment: Sure, but I won't be able to really get into it until my exams are done.
Answer: Here is another way that has not yet been suggested here:
$$P=\{n\in\mathbb{N}|[100<n<500]\wedge[(-1)^n=1]\}$$
Answer: I think this is a common way of listing a set of even numbers:
$P=\{2x + 100:x\in\mathbb{N}, 0\leq x\leq 200\}$
This just means:
Let P be the set of numbers yielded from "2x + 100" where x is a natural number and x is between 0 and 200 (inclusive).
If you start evaluating 2x + 100 with the numbers from 0 to 200, you get:

2(0) + 100 = 100
2(1) + 100 = 102
...
2(200) + 100 = 500
Comment: I don't think "$x\in[0\le x \le 200]$" is standard notation. What is "$x\in$" supposed to achieve here?
Comment: Oh, I see your point, I'm being redundant. Thanks, I'll edit my answer.
Answer: $$ \left\{ x \mid x \in \mathbb{N},\ 2 \mid x,\ 100 \leq x \leq 500 \right\} $$
Since you haven't specified, I'm assuming between 100 and 500 is inclusive.
$2 \mid x$ means $2$ is a divisor of $x$, or alternatively, $x$ is evenly divisible by $2$.
Answer: This is a more longwinded approach to help clarify what's going on. But be explicit in how you define 'between'. In this sense, between could be interpreted as $100 \leq x \leq 500$ or $100 < x < 500$. As long as you are explicit about your assumption, you're fine.
The sentence "Define the set of even natural numbers between 100 and 500" can be broken into several components:

P = {even natural numbers between 100 and 500}
P = {elements of x in natural numbers such that (x is even) AND (x is greater than 100) AND (x is less than 500) }
P = $ \{ x \in \mathbb{N} : (\exists k \in \mathbb{N} \quad x = 2k) AND (x > 100) AND (x < 500) \} $
P = $ \{ x \in \mathbb{N} : (\exists k \in \mathbb{N} \quad x = 2k) \land [(x > 100) \land (x < 500)] \} $

This way makes the inequality $100 < x < 500$ explicit using the logical and operator.


How can I hide search results until the user submits the exposed form?

Question: I have a fairly straightforward view, which exposes a simple keyword filter to the user.
Currently, when I first land on the page containing this view, all records are displayed (i.e., the search results are unfiltered).
How can I alter this behavior, so that no search results are displayed until the user has entered a keyword and submitted the form?
(I'm converting an old Drupal 7 site to Drupal 8. On the D7 site, the view does not show search results when I first land on the page. Is this a difference in behavior between the Views implementation in D7 and D8? I can't find anything in the D7 site to suggest that this difference in behavior is caused by a module.)
Comment: Could you just make the keyword filter required?
Comment: Thanks for the suggestion. I tried this, but it resulted in the "no results found" message being displayed on the initial page view, which isn't what I want.
Answer: You can change that under Advanced Views options (third column): Exposed form style:

After you choose Input required, you can adjust further options, including the text to display before any filters are active:

If you're using Better Exposed Filters module it has an option for it too:

Input required
  Only display results after the user has selected a
  filter option.

It hasn't changed since D7, it works the same in D8 as it did in D7.


Suggestions for dependent multivariate and multi-outputs model

Question: I have multiple predictors (ram, cpu, I/O etc.) (depended!) and looking for a model with multivariate outputs (I am trying to predict the same input fields given partial inputs).
I have tried some models but cant find a model that will fit the data requirements.
For example, lasso regression does not fit because it does not have a multi input-output version.
Decision Tree regression does not fit because my inputs are dependent..
any suggestions?
Thanks in advance!
Comment: Lasso has the option Family="mgaussian". You can handle multivariate outputs with that.
Answer: You can use LASSO linear regression with multiple outputs (or with a multivariate output), simply writing $Y=X\beta+\varepsilon$ where $Y$ is a matrix such that each column of $Y$ corresponds to one output (or one coordinate of your multivariate output) and $\beta$ is a coefficient matrix whose columns correspond to coefficients giving the corresponding column of $Y$.
Or if you're in trouble with matrices, then simply fit one LASSO linear model per coordinate of your multivariate output.
Comment: all right! will try that


Matching expansion of an ODE: $\epsilon y'' + xy' + y = 0$

Question: I am trying to solve a boundary layer problem using matched expansion
$$\epsilon y'' + xy' + y = 0$$
where the boundary condition is
$$y(0) = 1, y(1) = 1$$
and $x\in (0,1)$.
So far, I have the outer solution by solving $xy'+y=0$, it gives
$$y_0=\frac{1}{x}$$
and introducing $x=\epsilon X$ to get the inner solution $$Y'' + \epsilon XY' + Y = 0$$
Apparently, for $x>0$, there is a boundary layer at $x=0$. The inner solution I get is
$$Y_0 = C(X-1)$$
Obviously, classical matching doesn't work since both solution will go to infinity. I also tried intermediate matching, but everything looks weird. Just wondering is there another right boundary layer?
So could anyone give me some hints? Thanks.
Comment: Please explain in more detail why you chose $x=ϵX$ and why the resulting equation is not the unbalanced $Y''+ϵXY'+ϵY=0$
Answer: I suppose that the OP expect a method of solving of the Physicists kind. That is not what I intend to do. So, what follows might be considered not as an answer but as a comment (Too long to be edited in the comments section).
By the way, that is the opportunity for me to express my admiration for the Physicist's methods to easily find very good approximate solutions, which would require arduous purely analytical calculus. The below purely mathematical approach is a play but is certainly not recommended for concrete application.
$$\epsilon y'' + xy' + y = 0$$
The general solution is :
$$y(x)=e^{-x^2/(2\epsilon)}\big(c_1+c_2\:\text{erfi}(x/\sqrt{2\epsilon}) \big)$$
Function erfi : http://mathworld.wolfram.com/Erfi.html
With conditions $y(0)=y(1)=1$ :
$$\boxed{y(x)=e^{-x^2/(2\epsilon)}\left(1+(e^{1/(2\epsilon)}-1)\frac{\text{erfi}(x/\sqrt{2\epsilon})}{\text{erfi}(1/\sqrt{2\epsilon})} \right)}$$
This is the exact solution, valid on the whole range $0\leq x \leq 1$.
$$ $$
APPOXIMATE on $x<\epsilon\ll 1$ :
For $\epsilon$ small, that is $X=1/\sqrt{2\epsilon}$ large :
erfi$(X)\simeq \frac{e^{X^2}}{\sqrt{\pi}\:X}\left(1+\frac{1}{2X^2}+O(\frac{1}{X^4}) \right)$
erfi$(1/\sqrt{2\epsilon})\simeq \sqrt{\frac{2}{\pi}}e^{1/(2\epsilon)}\sqrt{\epsilon} \left(1+\epsilon+O(\epsilon^2) \right)$
$$y(x)\simeq e^{-x^2/(2\epsilon)}\big(1+\sqrt{\frac{\pi}{2\epsilon}} \left(1-\epsilon+O(\epsilon^2) \right)\text{erfi}(x/\sqrt{2\epsilon})\big)$$
For $\frac{x^2}{2\epsilon}<1$ :
$e^{-x^2/(2\epsilon)}\simeq 1-\frac{x^2}{2\epsilon}+O\left(x^4/\epsilon^2 \right)$
erfi$(x/\sqrt{2\epsilon})\simeq \frac{2}{\sqrt{\pi}}\frac{x}{\sqrt{2\epsilon}}\left(1+\frac13\frac{x^2}{2\epsilon}+O(x^4/\epsilon^2) \right)$
$$y(x)\simeq \left(1-\frac{x^2}{2\epsilon}+O\left(x^4/\epsilon^2 \right)\right)\left(1+\sqrt{\frac{\pi}{2\epsilon}} \left(1-\epsilon+O(\epsilon^2) \right) \frac{2}{\sqrt{\pi}}\frac{x}{\sqrt{2\epsilon}}\left(1+\frac13\frac{x^2}{2\epsilon}+O(x^4/\epsilon^2) \right)\right)$$
After simplification :
$$y(x)\simeq 1+\frac{x}{\epsilon}(1-\epsilon+...)\left(1+\frac{x^2}{6\epsilon}+...\right) \quad\text{in}\quad 0\leq x<\epsilon\ll 1.$$
This is a better approximate than $y(x)\simeq 1+\frac{x}{\epsilon}$.
$$ $$
APPROXIMATE on $\quad \epsilon\ll x\leq 1$ :
$X=x/\sqrt{2\epsilon})$ is large.
erfi$(X)\simeq \frac{e^{X^2}}{\sqrt{\pi}\:X}\left(1+\frac{1}{2X^2}+O(\frac{1}{X^4}) \right)$
erfi$(x/\sqrt{2\epsilon})\simeq \frac{e^{x^2/(2\epsilon)}}{\sqrt{\pi}\:x}\sqrt{2\epsilon}\left(1+\frac{\epsilon}{x^2}+O(\frac{\epsilon^2}{x^4}) \right)$
$y(x)\simeq e^{-x^2/(2\epsilon)}\left(1+\sqrt{\frac{\pi}{2\epsilon}} \left(1-\epsilon+O(\epsilon^2) \right)\frac{e^{x^2/(2\epsilon)}}{\sqrt{\pi}\:x}\sqrt{2\epsilon}\left(1+\frac{\epsilon}{x^2}+O(\frac{\epsilon^2}{x^4}) \right)\right)$
After simplification :
$$y(x)\simeq \frac{1}{x}\left(1-\epsilon+...\right)\left(1+\frac{\epsilon}{x^2}+... \right)$$
We find again the result $y(x)\simeq \frac{1}{x}$ .
A more accurate approximate in the range close to $x=1$ would require the change of variable $\xi=1-x$ and the series expansion of the above exact solution for $\xi\to 0$.
Comment: Like you said, I am looking for a "Physicists" way to solve this. Your solution makes me feel like a "reverse-engineering".
Comment: @TurbJet : You still get the full equation $Y''(X)+XY'(X)+Y(X)=0\implies Y'(X)+XY(X)=C$ for the inner solution at the boundary layer at $x=0$, thus you can not avoid the $\operatorname{erfi}$ terms.
Comment: Matched asymptotic expansions are a technique of mathematicians just as well as physicists


Yii2. Date validation rule wrong format

Question: I have such validation rule
['birthdate', 'date', 'format' => 'Y-m-d'],

and passing such value 2002-03-11, but recive validation error The format of Birthdate is invalid.
What am I doing wrong?
Answer: I have installed intl extenstion. It has fixed an issue.
Comment: @ShaigKhaligli actually, not. Inside the Yii2 Date core validator was if this extension installed and else with some code and this part gave an error.

Yii2. Date validation rule wrong format


Páginas minificadas e processamento para cada requisição

Question: Se eu desejo minificar uma página em HTML a partir do PHP eu estarei mais ganhando ou perdendo?
De forma mais clara: quero manter a formatação e a praticidade para quando editar a página, preservando a edentação. Mas também me preocupo com o carregamento da página, uma vez que no desenvolvimento ela está a se tornar mais pesada do que eu gostaria, logo uma solução é minificar e economizar alguns KBs retirando tudo o que é desnecessário ao usuário fazer o download da página. Da mesma forma com CSS e JS.
Mas como queria fazer isso com o PHP (gerar um output retirando os lixos), queria saber se eu perderia mais tempo processando a página do que se ela não tivesse minificada e fosse realizado o download.
Entendo que isso dependa de diversos fatores, mas gostaria de considerar grandes volumes de informações (cerca de 2MB não minificado e 1.2MB minificado), o que são quase 60% de diferença no tamanho. Quais são os fatores que deixariam o processamento da página para ser minificada lenta?
Existem outras opções para deixar a página leve?
Comment: Realmente, só medindo a performance do seu caso específico pra saber, mas minificar *on-the-fly* a cada requisição não parece uma boa ideia em termos gerais. Você chegou a considerar a opção de guardar as páginas minificadas em *cache* por um período?
Comment: Vale a pena "minificar" o HTML se você quer economizar ao máximo em largura de banda. O processamento é rápido e é muito bom principalmente para conexões lentas. Em PHP, é fácil, basta usar uma combinação de `ob_start` para pegar o HTML original + `str_replace` para eliminar os espaços e quebras de linhas + `preg_replace` para eliminar os comentários. Se você não usar tokens CSRF ou redirecionamentos, você pode fazer cache do HTML no servidor. Mas tem algumas prioridades antes disso, como Gzip, HTTP cache, otimizar imagens, combinar JS e CSS, usar CSS sprites, usar um CDN se possível, etc
Comment: Não sei se 'chachear' as páginas é uma boa ideia, ela é atualizada com certa frequência diária de forma inconstante e imagino eu que isso geraria problemas nesse caso específico.
Comment: Editei minha resposta esclarescendo sua dúvida
Answer: Você já tem o site rodando em algum URL público (ou você pode abrir temporariamente pra Internet pública pra testar)? Você pode usar o PageSpeed Insights; ele vai te dar uma noção mais precisa sobre onde ganhar performance.
A minha experiência pessoal é que você tem que garantir primeiro que o seu servidor está comprimindo os arquivos que ele envia; isso vai te dar um ganho de performance muito maior que tirar indentação, a um custo em eletricidade e fosfato muito menor.
Comment: Eu não tenho controle sobre o servidor por ser algo muito longe da minha alçada, mas concordo contigo!
Answer: Você deve Minificar e Compactar (note que são coisas diferentes) os HTML, CSS e JS de seu site juntamente com as imagens, porém trabalho com Templates Dwoo mantenho uma versão sem a minificação para trabalho e outra minificada, note que as páginas são dinâmicas mesmo assim elas permanecem minificadas já que o template esta minificado.

Minificar: Seria remover os espaços em brancos (também retiro algumas aspas iúteis (quando são inúteis, ex: quando há somente uma classe no atributo class)) (geralmente reduz 15%).
Compactar: Seria compactar mesmo, usando Gzip, habilitado nativamente no Nginx (geralmente reduz uns 50%).
Junção de arquivos: Faça a junção de Todos os arquivos .css e .js em um único arquivo (Quando for distribuir a página) incluindo arquivos de bibliotecas (fique atento a interferências entre variáveis), o Framework Rails faz isso de forma quase transparente aos usuários.

Ferramentas:
PageSpeed Insights
HTML Compressor (Possui Muitas opções avançadas de compressão de HTML).
Compress My code (Comprime HTML, CSS e JS).
OBS: esclarecendo as duvidas: Quando falo "Compactação" seria compactação do arquivo em si (tipo .rar .zip) onde ao final do processo (compactação Gzip e descompactação) não há modificação do seu conteúdo do arquivo. já na minificação não há a compactação do arquivo .js e .css (tipo .rar .zip) e sim uma remoção de conteúdo inútil para o browser.
Comment: Agora fiquei confuso. kk
Minificação não seria uma forma de compactação? Sempre tive essa impressão.

O meu objetivo é não tirar a produtividade, então, possivelmente teria uma pasta para desenvolvimento e a pasta root. A root carregaria os arquivos minificados automaticamente, me evitando o trabalho de precisar minificar o arquivo toda vez que ele ficasse pronto. Não estou usando nenhum Framework server-side por uma limitação do projeto.
Comment: Opa esclarecendo as duvidas: Quando falo "Compactação" seria compactação do arquivo em si (tipo .rar .zip) onde ao final do processo não a modificação do seu conteúdo do arquivo.


Why autocovariances could fully characterise a time series?

Question: I read in John Cochrane's Time Series for Macroeconomics and Finance that:

Autocovariance can fully charaterize the time series [joint distribution].

I do not fully understand the connection between covariance and joint distribution here.  Can someone please explain that?
Comment: I would bet he assumes the process is *Gaussian,* right?
Comment: White noise by itself does not guarantee the result you need; you need _Gaussian_ white noise.
Comment: @whuber, yes, he uses ARMA model to illustrate, and assume error term always as white noise.
Answer: A stationary Gaussian process is completely characterized by the combination of its mean, variance and autocorrelation function.  The statement as you read it is not true.  You need the following additional conditions:

The process is stationary
the process is Gaussian
the mean $μ$ is specified

Then the entire stochastic process is completely characterized by its autocovariance function (or equivalently its variance  $σ^2$ + autocorrelation function).
This simply relies on the fact that any multivariate Gaussian distribution is uniquely determined by its mean vector and its covariance function. So given all the conditions that I stated above the joint distribution of any $k$ observations in the time series has a multivariate normal distribution with mean vector having each component equal to $μ$ (by stationarity) each component has variance $σ^2$ (again by stationarity) and the covariance components are given by the corresponding lagged covariances in the autocovariance function (again stationarity comes in because the autocovariance only depends on the time difference (or lag) between the two observations whose covariance is being taken.
Comment: (+1) I think this is said implicitly in condition (1) but you also require that $\mu$ is constant, right?
Comment: @Macro Yes stationarity, even weak sense (covariance) stationarity requires a constant mean and a constant variance.
Comment: @MichaelChernick, then we could reproduce the joint distribution of stochastic process (or simulate stochastic process itself) by having its mean and autocovariance?
Comment: @Flyingpig Yes for any subset of the variables as long as it is a stationary Gaussian process. it doesn't have to be an AR, MA or ARMA process. It only has to be a stationary Gaussian process. It should not be a surprise. This is a well known property for multivariate normal distributions.
Comment: @Macro I guess the condition constant mean is redundant in the required conditions that I gave.  I just mentioned it because to completely characterize the stochastic process you need to know what the value is for the mean and variance and not just that they are both constant.


How would you unpack a 32bit int in Python?

Question: I'm fairly weak with structs but I have a feeling they're the best way to do this. I have a large string of binary data and need to pull 32 of those chars, starting at a specific index, and store them as an int. What is the best way to do this?
Since I need to start at an initial position I have been playing with struct.unpack_from(). Based on the format table here, I thought the 'i' formatting being 4 bytes is exactly what I needed but the code below executes and prints "(825307441,)" where I was expecting either the binary, decimal or hex form. Can anyone explain to me what 825307441 represents?
Also is there a method of extracting the data in a similar fashion but returning it in a list instead of a tuple? Thank you
st = "1111111111111111111111111111111"
test = struct.unpack_from('i',st,0)
print test

Comment: You say you have a large string of binary data. Are you sure that's a string of ones and zeros, or do you mean something like `'\x25\x90\x14\x0d'`?
Answer: Just use int
>>> st = "1111111111111111111111111111111"
>>> int(st,2)
2147483647
>>> int(st[1:4],2)
7

You can slice the string any way you want to get the indices you desire. Passing 2 to int tells int that you are passing it a string in binary
Comment: It says I can accept your answer in 6 minutes but I'm leaving work now, look forward to it tomorrow morning pal


Different response status codes for ConstraintViolationException

Question: So. In my spring app, In service I validate some objects, and if it invalid, throw ConstraintViolationException
Set<ConstraintViolation<ImageRequest>> violations = validator.validate(imageRequest);
    if (!violations.isEmpty()) {
        throw new ConstraintViolationException(violations);
    }

and in @ControllerAdvice it handled by
@ExceptionHandler(ConstraintViolationException.class)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
ValidationErrorResponse onConstraintValidationException(
        ConstraintViolationException e) {
    ValidationErrorResponse error = new ValidationErrorResponse();
    for (ConstraintViolation violation : e.getConstraintViolations()) {
        error.getErrors().put(
                violation.getPropertyPath().toString(), violation.getMessage());
    }
    return error;
}

The problem is that sometimes I need return different status codes of response for ConstraintViolationException(It depends on type of object on which generated ConstraintViolationException). How can i achieve it? P.S. Sorry for English
Answer:
remove @ResponseStatus(HttpStatus.OK)

Approach A

@ExceptionHandler(ConstraintViolationException.class)
@ResponseBody
ValidationErrorResponse onConstraintValidationException(
        ConstraintViolationException e, HttpServletResponse response) {
    ValidationErrorResponse error = new ValidationErrorResponse();
    for (ConstraintViolation violation : e.getConstraintViolations()) {
        error.getErrors().put(
                violation.getPropertyPath().toString(), violation.getMessage());
    }
    response.setStatus(..based on some condition set status code ..);
    return error;
}

Approach B(IMHO: much better)

@ExceptionHandler(ConstraintViolationException.class)
ResponseEntity<ValidationErrorResponse> onConstraintValidationException(
        ConstraintViolationException e) {
    ValidationErrorResponse error = new ValidationErrorResponse();
    for (ConstraintViolation violation : e.getConstraintViolations()) {
        error.getErrors().put(
                violation.getPropertyPath().toString(), violation.getMessage());
    }
    return ResponseEntity.status(..desired status..).body(error);
}

Comment: I understand that I can make decision which status code of response will be in the mehtod which handle ConstraintViolationException, but I would like that methot which handle ConstraintViolationException didn't have any logic of which status code of response shoud be. Is there I way I can define my custom Exception with a Set> and handle this custom Exception in @ContollerAdvice?
Comment: @frigoshor just create a custom exception with set of constraint violations and handle this exception


Mapping Excel Columns to Parent-Child JSON

Question: I have a CSV input like this:
Column1,Column2,Column3,Column4,Column5
a,b,c,d,e
a,b,f,,
a,g,h,i,
j,k,l,,
j,k,m,n,
o,,,,

And I'm trying to transform that into a JSON output that complies with this format (http://bl.ocks.org/mbostock/raw/4063550/flare.json) so I can leverage d3.js to visualize the parent-child tree (http://bl.ocks.org/mbostock/4063570).
I'm looking to visualize my data exactly like that example, but I don't have/need weights. If need be, I can add a common first-level parent. Just looking to visualize the tree(s).
Largest depth is always 5.
I was playing around with doing some array stuff in PHP (after reading in with fgetcsv()), but I was bumbling around and could use some help.
PHP or Javascript solution preferred, since that's all I can work with through my work computer setup. I really appreciate the help!
Comment: [`d3.nest()`](https://github.com/mbostock/d3/wiki/Arrays#d3_nest) is what you need for transforming the flat array to a nested structure. Before that, [`d3.csv.parse()`](https://github.com/mbostock/d3/wiki/CSV#parse) is how you transform your CSV to a flat array of objects (assuming it's been loaded already).
Comment: @meetamit: Ahh why didn't I think of that. Silly me, and thanks a bunch!
Answer: It sounds like you're looking for a tree structure where your data looks like the following:
          a            j      o
         / \          /
        b   g        k
       / \   \      / \
      c   f   h    l   m
     /         \        \
    d           i        n
   /
  e

if so, the following javascript code should do what you want:
var csv = //CSV CONTENT HERE
  , data = parseCSV(csv)
  , structure = toJSONStructure(data)
  , formattedForD3 = toNameChildFormat(structure)

console.log(formattedForD3)

function parseCSV(csv) {
    return csv.split('\n').slice(1).map(function(line) {
        return line.split(',')
    })
}

function toJSONStructure(data) {
    var structure = {}
    data.forEach(function(line) {
        var o = structure
        line.forEach(function(val) {
            if(val) o = o[val] = o[val] || {}
        })
    })
    return structure
}

function toNameChildFormat(structure) {
   return Object.keys(structure).map(function(key) {
       return {
           name:key,
           children:toNameChildFormat(structure[key])
       }
   })
}

JSFiddle Demo


How to use GraphQL for enterprise applications

Question: A short introduction before my question:
I am currently in the planning stage of developing an enterprise application where there are many services each with a huge amount of business logic.
I was recently introduced to and asked to incorporate  GraphQL

I frankly don't see the point. It seems like a wrapper over a
database. If we write what data we want in a declarative way, GraphQL
gives us the data in a neat JSON format. To me it makes no difference
to a proper NoSQL query.
JavaScript heavy applications are less secure due to business logic
presented to client browser where it can be tweaked to change the
behavior. GraphQL tends to rely on such applications where the front
end directly communicates with the data. Where as traditional NoSQL queries can run from a server after obtaining required information from the client.

Question:
If GraphQL directly obtains the data from the database and presents it, how can I implement GraphQL to handle middleware tasks, business logic like back-end validations, complex business checks, batch processes etc?
If not, then is it just a Declarative library on top of database queries?
Answer:
If GraphQL directly obtains the data from the database and presents
it, how can I implement GraphQL to handle middleware tasks, business
logic like back-end validations, complex business checks, batch
processes etc?

GraphQL doesn't directly obtain the data from the database.  The GraphQL implementation is exposed via an endpoint that is no different than any other endpoint, meaning that you can use any middleware, authentication stacks, validation, etc. that you want.  It's also database-agnostic.  So again, you can use whatever combination of database, ORM, etc you want.

If not, then is it just a Declarative library on top of database
queries?

Not quite.  There are two main parts of a GraphQL implementation - the schema and the resolvers.  The schema simply defines the shape of your data and the resolvers do the heavy lifting.  The resolvers are the layer of logic that defines how to fetch and transform the data for every field defined in the schema.  More on resolvers below.

How is it different than using a NoSQL database?

The main selling point of GraphQL is that is lets the consumer define exactly the data that they need.  For flat (i.e. non-nested) data, this might not be a big deal.  But it becomes more and more of an advantage when you start dealing with more heavily-nested data.  For example, let's say you have a GraphQL query that looks like:
<code>query {
  user(userId: "some_user_id") {
    ...userData
    projects {
      ...projectData
      assets {
        ...assetData
      }
    }
  }
}
</code>
We're fetching a user, the projects for that user, and the assets for each of those projects and we can specify exactly what fields we want at each level.  A user may have 15 fields, but maybe we only want two or three of them.  The same may go for projects and assets.  Since GraphQL resolvers are smart, we don't have to worry about which fields are actually requested in any given query.  Only the fields requested as part of the query will be returned.  And if a field is resolved via an asynchronous function, that function will only be executed if that field is requested.
In the end, the client gets back JSON that matches the shape of the query, but (I hope) we would never store nested data like this in a NoSQL database.  There are also tools like dataloader that make it easier to optimize queries via batching and caching.

GraphQL tends to rely on such applications where the front end
directly communicates with the data.

As you can gather from above, this is not the case.


Google Doubleclick - custom video source after initial load

Question: I'm trying to polite load a video for a HTML5 creative served though google Doubleclick Studio and running into some issues
                    <video id="myVideo">
                      <source src="video.mp4" type="video/mp4">
                    </video>

This works fine
Now, when I try to dynamically add the source
'HTML'

                    <video id="myVideo">
                    </video>

'JS'

                    source = document.createElement('source')
                    source.setAttribute('type', 'video/mp4')
                    source.setAttribute('src', 'video.mp4')
                    video.appendChild(source)

Doubleclick will give me this error
GET https://s0.2mdn.net/ads/richmedia/studio/pv2/60863002/20181009012818318/video.mp4 404

I suspect this is related to where Doubleclick stores the assets during initial load, because when I try to log the 'src' attribute using the first method, I get this tongue twister:
https://gcdn.2mdn.net/videoplayback/id/0173366851186f65/itag/15/source/doubleclick/ratebypass/yes/mime/video%2Fmp4/acao/yes/ip/0.0.0.0/ipbits/0/expire/3683521965/sparams/id,itag,source,ratebypass,mime,acao,ipbits,expire/signature/79EA6270A42AF05325924BB711068AE6A1943312.29D8F6E2DB82F38750A45593094A36C9BBC74D04/key/ck2/file/file.mp4

This explains the 404, however, I don't have this problem on my local PC.
How do I tell Doubleclick where to find my video.mp4 file so I can load it after the initial load
Comment: Specify an absolute URL …?
Answer: When a video is uploaded to DoubleClick Studio, it's type is listed as a Video Bundle in the Assets listing. DoubleClick actually transcodes the video into multiple formats and bitrates automatically.
In production mode, when you request the video using a relative URL in your banner it will return a 404 as you have experienced.
DoubleClick Enabler SDK contains a method named Enabler.getUrl. This only works in live mode (including DC Studio preview mode) and will return an absolute URL from their CDN. When testing locally you still need to reference the file relatively like normal.
To assist with this there is another method in the SDK called Enabler.isServingInLiveEnvironment which allows you to determine whether you are in "live" mode or not.
Here's an example of combining the two SDK calls to request the correct video URL for the current environment.
function getVideoUrl(filename) {
    if (Enabler.isServingInLiveEnvironment()) {
        return Enabler.getUrl(filename);
    } else {
        return filename;
    }
}

myVideo.src = getVideoUrl('myVideo.mp4');


Como adicionar um icone ao botão no xamarin?

Question: Galera, eu deparei com uma coisa boba aqui mais que me deixou garrado, gostaria de colocar um ícone em um botão dentro do layout do meu aplicativo, portanto não estou conseguindo fazer, abaixo o código do meu botão... alguém poderia me dizer como fazer isso??
 <Button Text="Criar Chamado"
                    TextColor="White"
                    BackgroundColor="#800000"
                    Clicked="btnLogin_Clicked"
                   />

Answer: Você pode usar a propriedade Image do buttons e prover um recurso disponível na sua plataforma específica. Assim:
<Button Text="Criar Chamado"
        TextColor="White"
        BackgroundColor="#800000"
        Image="nome_arquivo_imagem.png"
        Clicked="btnLogin_Clicked"/>

No caso do android, por exemplo, deve existir um arquivo nome_arquivo_imagem.png no diretório \Resources\drawable
Comment: Que maravilha! Pode contar com a ajuda da comunidade, sempre que possível estarei participando!
Comment: Valeu cara, não imaginava que fosse tão simples assim!!
Comment: tu está me ajudando muito, da hora... pois to iniciando agora com com xamarin


Derivation of EPE in "The elements of statistical learning "

Question: I am currently trying to read the "Elements of Statistical Learning", by Efron, Hastie, and Tibshirani, and already at the beginning there is a bit above my level in mathematics.
I have 3 questions regarding the move from (2.9) to (2.10):

What is the meaning of integrating with respect to Pr(dx,dy) instead of with respect to dx,dy by themselves?

Since this is an indefinite integral, shouldn't there be a constant C or something afterwards?

This is more about the intuition behind this: why is the expected value of the loss function f is the same as the area beneath the function (that is, the integral of f)?
Comment: If you're finding ESA too tricky (and it can be quite dense), can I recommend maybe having a look at "An Introduction to Statistical Learning" by Robert Tibshirani and Trevor Hastie instead?
Comment: Agreed with @Paul. Probability with Martingales by Williams or Probability and Measure by Billingsley are two excellent references if you want to understand the probability theory underlying machine learning.
Comment: If these formulas are not clear to you, it might be useful to work through the book alongside a solid reference in elementary probability, such as Grimmett and Stirzaker.
Comment: https://en.wikipedia.org/wiki/Multiple_integral
Comment: @Xi'an is it ok now? :)
Comment: @Machineepsilon would you say that reading "An Introduction to Statistical Learning" before "elemnts of statistical learning" will help me in the specific goal of **better understaning the math** in "E.O.S.L" ?
Comment: @Xi'anI understand this. I learn math subjects as I encounter them. Is there any good resource that comes to mind for you that introduces this subject well?
Answer:

what is the meaning of integrating with respect to Pr(dx,dy) instead of with respect to dx,dy by themselves?

You are missing the notion that this is an expectation, that is, the average value of $(Y-f(X))^2$ under the joint distribution of $(X,Y)$. (Using Pr is clearly not the most inspired choice!)

since this is an indefinite integral, shouldn't there be a +C or something afterwards?

This is a regular integral and not an anti-derivative. The authors did not put the domain of integration on the integral sign, as is common when this domain does not suffer from possible confusion.

this is more about the intuition behind this: why is the expected value of the loss function f is the same as the area beneath the
  function (that is, the integral of f)?

First, $f(X)$ is not the loss function but the transform of the random variable $X$. The loss function is $(Y-f(X))^2$. Second, the integral of the loss function under the probability measure is its average or averaged value. This is the definition for expectations.
About this entire excerpt, one way to look at it is to see it as a probabilistic version of the Pythagorean theorem: the average square distance between $Y$ and $f(X)$ is the sum
$$\mathbb{E}[(Y-f(X))^2]=\mathbb{E}[(Y-\mathbb{E}[Y|X])^2]+\mathbb{E}[(\mathbb{E}[Y|X]-f(X))^2]$$
since the terms $(Y-\mathbb{E}[Y|X])$ and $(\mathbb{E}[Y|X]-f(X))$ are orthogonal in this probabilistic sense.
Comment: @MoranReznik you should look into the difference between a Riemann integral and a Lebesgue integral. Expectations are the latter.
Comment: thank you. I would like to explain why in my mind the integral of the loss function ins't the averaged value, so you can tell me where im getting it wrong. As far as I know, integrals are about taking infinitely many sums. in this case, summing up the results of every combination of P(X ,Y) in the loss function. While, expected value is more or less the same except that after you summed up the values of the loss function you than devide by the number of times you generated the loss, somthing that isn't done in integrals. Sholudent this diffrence give other results in those exprestions?

Derivation of EPE in “The elements of statistical learning ”


force maven to use different java version

Question: I have my existing project that uses Java 1.8
My JAVA_HOME is set to Java 1.8
As a result maven is using Java 1.8 , which is fine
Now our project has decided to start using SonarQube 9.x which runs on Java 11
In addition to run any scan / analysis of our code - it needs Java 11 as well
So here is what I need to be doing :
#1 Compile code using default jdk ( 1.8 ) ( mvn clean install )
#2 Run sonar scan using jdk 11 ( mvn sonar:sonar )
To execute #2 need maven to use jdk 11 while to execute #1 need maven to use jdk 1.8.
After reading various questions on SO came across 'toolchain'
So added toolchains.xml into my 'm2' folder :
<?xml version="1.0" encoding="UTF-8"?>
<toolchains>

 <toolchain>
  <type>jdk</type>
  <provides>
   <version>1.11</version>
   <vendor>sun</vendor>
  </provides>
  <configuration>
   <jdkHome>C:\construction\tools\jdk-11.0.12</jdkHome>
  </configuration>
</toolchain>
<toolchain>
 <type>jdk</type>
 <provides>
  <version>1.8</version>
  <vendor>sun</vendor>
 </provides>
 <configuration>
  <jdkHome>C:\Program Files\Java\jdk1.8.0_191</jdkHome>
 </configuration>
</toolchain>

Added toolchain plugin in my projects pom.xml
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-toolchains-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <goals>
                      <goal>toolchain</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <toolchains>
                    <jdk>
                        <version>1.11</version>
                        <vendor>sun</vendor>
                    </jdk>
                </toolchains>
            </configuration>
        </plugin>

Now when I run maven clean install can see in logs that java 11 'seems' to be used :

[INFO] --- maven-toolchains-plugin:1.1:toolchain (default) @ TreeSurveyAPI ---

[INFO] Required toolchain: jdk [ vendor='sun' version='1.11' ]
[INFO] Found matching toolchain for type jdk: JDK[C:\construction\tools\jdk-11.0.12]

[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ TreeSurveyAPI ---
[INFO] Toolchain in maven-compiler-plugin: JDK[C:\construction\tools\jdk-11.0.12]
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 11 source files to C:\construction\xxx\XYZ-main\target\classes

So it 'seems' that maven along with toolchain is using Java 11 to compile the code .
However after executing javap against compiled class file indicates Major version as 52 ( Java 8 )
javap -verbose Abc.class | findstr "major"

So here are my questions :
#1
in the above case since toolchain points to java 11 shouldnt the code be compiled with java 11 ? why is it using java 8 ?
#2
How can I conditionally use java 8 Vs java 11 ( compile and build using java 8 and run sonar task using java 11 ) ?
Thanks
Comment: Wouldn't it be better to configure Java 8 just for the maven compile plugin? Then the build could run on Java 11 in both cases.
Comment: Use JDK11 for build and define `--release` or via `maven.compiler.release` the target for the class files...that works perfectly fine...is easier etc. I would even think to go to build with JDK17 instead of JDK11...
Comment: This is exactly the situation we have to deal with in our enterprise, and from my initial research, I believe (without testing yet) that the previous comment illustrates the basic strategy that should likely work. Note that you can also set the "release" property in the configuration of "maven-compiler-plugin", instead of setting the "target" and "source".
Comment: Are you running mvn clean install from your IDE or from the terminal?
Comment: from the command prompt
Answer: You can run your project on java 11 also.
It will run java 8 code no problem for 99% of the cases.
This is what I would do. Therefore, upgrading the projects java version seems to be the easiest solution.
If this does not work, check out this answer
Also, if you need to be able to quickly change JVM versions for various tasks and in various folders, you can use this tool
Comment: thanks for the response but we are in a micoroservices world with 120+ api so running on java 11 will involve extensive regression which we do not want to do . Unfortunately in our environment introduction of  this tool / new tool will be a challenge and it also seems to need additional work to get it to work on windows . I thought toolchain should help in changing jdk to be used ...
Comment: Got it. Then check out this answer https://stackoverflow.com/a/20787334/2599899
Comment: Which regressions? Is the written code so heavily JDK specific or uses internals?
Comment: thanks @ArthurKlezovich , however the answer in the so link is referring to change JAVA_HOME , now that would imply ( in my case ) to use default JAVA_HOME ( jdk1.8) to compile and build war / jar / ear which is fine , however in the next step I need to run sonar scan so need to change JAVA_HOME to JDK11 , I cannot do this manually and when I had tried to do this via command prompt ( with administrator priveleges ) it still would refuse to change to jdk11
Comment: @khmarbaise in an earlier project we were forced to move our code from 1.6 to 1.7 ( code and project was inherited ) and one subtle bug introduced in production was the code was using reflection to get a list of methods and then firing calls to each of the method . The unfortunate part was that the code relied on reflection api to always return the methods in class in specific order ( which was the behaviour in 1.6 ) but after the issue cropped up in production ( and causing a lot of bad PR for me and our team ) , it was found that in jdk 1.7 reflection method order is not guaranteed ....
Comment: That sounds you seemed to have missing tests...which identified such things...in particular if you have made the experience...
Comment: no the tests were present for regression , thing is on every startup of the jvm the order of methods could / would change , so tests were performed and it passed , even after it failed in prod , we were only able to reproduce it after restarting the component multiple times and then once in a while we were able to reproduce
Answer: There are two main aspects to understand:

The Maven toolchains plugin enables us to separate the JDK/JRE version being used for the projects building Maven plugin execution runtime from the JDK version being used to compile AND to run the surefire plugins running the JUnit tests.

The Maven compile plugins configuration <target> (user property maven.compiler.target) JAVA version defines the code and class JAVA version the compiler will create - BUT this does NOT guarantee that your code will run 100% on that target versions actual JAVA runtime (s. below under the risk headline).

Both topics have to be well understood in terms of risks and pre-requisites.
The most common required scenario is like this:
Maven build execution requires JAVA version ATarget classes compiled require JAVA version B
In your questioned case you have to meet:

Use JAVA 11 for Maven build execution to meet SonarQube plugin requirements
Use JAVA 1.8 to compile and JUnit test your code

The correct configuration to meet this requirement is:

Define your JAVA_HOME being used to run the Maven build process to the JDK 11 home
=> meets your question #2
Configure your toolchains plugin to make use of the JDK 1.8 home
Configure the maven-compiler-plugin

...
  <configuration>
    <source>1.8</source>
    <target>1.8</target>
  </configuration>
...

=> 2. and 3. meet your question #1
Potential risk if not configuring a separate toolchain
If you run the build with JDK 11 without having defined a separate JDK 8 by the toolchain, then your compiled classes will be compliant to JDK 8, if you configure the maven-compiler-plugin target to 1.8,
__ BUT __

You compile your code vs. the JDK 11 API (JDK's rt.jar) - and by this your code would even get compiled if it is using JAVA 11 API's that are NOT available on JAVA 8 or did have been modified vs. JAVA 8.
=> Your project goes risk to fail late on JAVA 8 runtime with unexpected and suspicious class not found or method missing exceptions.
JUnit tests may endup different as if they would have been run within a JAVA 8 runtime.


I did 'ifdown eth0' and...I can't connect my instance

Question: I should have run ifdown eth0 && ifup eth0, but I just ran ifdown eth0.
Can I connect to my instance and run ifup eth0? What should I do?
Answer: I don't think there is anything to do other than rebooting the machine or connect to the console...
Answer: Once you have shut down the Ethernet interface the only way to bring it back online is either explicitly by running ifup  on the console or rebooting the instance.
There is no remote way to bring up an interface that has been shut down.
(Assuming this is a single if device, which seems fair given if another up if existed you would already have connected via it and run if up.)


Smallest subring of $\mathbb Q$ containing $3/10$

Question:
Let $R$ be the smallest subring of $\mathbb Q$ (the field of rational numbers) that contains $3/10$ ($R$ doesn't have to be a unital ring). Does $1 \in R$?

Is the desired smallest subring this one: $R_1=\{\frac{3a}{10^b},a,b \in \mathbb Z \}$ or this one: $R_2=\{\frac{3^ca}{10^b},a,b,c \in \mathbb Z \}$? Either case, $1 \notin R_i$, because $3\nmid10^b$, correct?
Comment: Oh wait, actually they are not the same. $R_2$ allows $c=0$, giving $a/10^b$.
Comment: Isn't $R_1=R_2$ since you can put powers of $3$ into $a$?
Comment: I was wondering the same thing!
Answer: Your $R_1$ is not a ring because it is not closed under multiplication.
Your $R_2$ contains $1$ (for $a=1, b=c=0$).
However, if you modify $R_2$ to $\{\frac{3a}{10^c}\mid a\in\Bbb Z, c\in\Bbb N\,\}$, you are fine. Even if this should turn out not to be the smallest such ring, it is sufficient to know that it is a sub-ring containing $\frac3{10}$ and not containing $1$;  the smallest can only contain less elements.
Comment: Why is $\mathbb R_1$ not closed under multiplication?
Comment: Very strange final comments: 1) "if this should turn out not to be the smallest such ring"; it turns out to be the smallest one; 2) "the smallest can only contain less elements"; I wonder what this could mean for infinite rings like these.
Comment: Actually, if my $R_1$ is not a ring, then your $R_2$, shouldn't be also not a ring?
Comment: Like you, I originally thought that the minimal ring needs $c\in\mathbb N$, not $c\in\mathbb Z$. But in fact that is an illusion $-$ they define the same object.


How to make search on all fields (title and tags as well as body)?

Question: The built in search engine in Drupal 7 doesn't search on the title or tags fields, just on the body of the node. I need to be able to search on all fields.
What is the best module to install for this if I'm running Drupal on Apache on Windows?
Answer: One thing you can do to control which fields are included in your search index is to go to your specific content type's 'Manage Display' page.
So go to Structure --> Content types --> Your content type --> Manage display.
On that screen, you'll see a collapsed section called 'Custom Display Settings'.  Just click on it to expand it.  You should see that you can check to enable the 'Search index' display to be customized (Usually only the teaser or summary is included for customization by default).  Check the 'Search index' box and save:

That will provide you with a brand new "Search index" tab on this screen.  Click on it and start customizing which fields you want to be included for this content type's search index:
Comment: but the only thing is that the "Title" field is not one which is available on this page to put as visible .  what can we do to make the title be included in the search as well?
Comment: By the way, not regarding this answer of course, since it may not have solved your entire problem, but just in general on the StackExchange sites, I wanted to point out that you can accept or upvote answers that help you by using the check mark or arrows next to answers. I just notice you have never accepted an answer, and that may be because your issues were never fully resolved, which is totally fine, but if it's just an education thing, I wanted to explain that practice!
Comment: The title should be searched by default actually. And make sure you rebuild your search index after making changes like the above, so the new fields are picked up!
Comment: thank you !! I couldnt find this anywhere on the drupal site
Comment: You're most welcome!
Comment: thanks , I dont understand why even when I rebuild mysearch engine and run cron and update,  my search doesnt find all of the items until the next day!
Comment: Diana, I'm not sure why that's happening. It could actually be a caching issue (not just on the Drupal end, but on the server end too, perhaps)? Maybe others can chime in here.
Comment: it wont let me vote up since I dont have a reputation of at least 15 . so please increase my reputation so I can vote for your answer !
Comment: Very helpful. Thanks. Not sure why, but it didn't actually fix my problem. Nonetheless, seems like a step in the right direction.


How to calculate probability distribution for combination of functions

Question: please excuse (or change, if possible) the title if it doesn't make sense.
I have a problem which is something like this:
You have a variable $i$ which starts at $i=1$. You also have a target number of $j$, and you have an n-sided die (in my case $j=6$ and $n=6$ but ideally i'd like to be able to solve this generally.)
Now you repeatedly roll the n-sided die, each time the die the lands on a number greater than $i$ you increment $i$ by 1. This stops once $i=j$.
I've already calculated the mean number of rolls until $i=j$ as:
$$\sum_{x=n-(j-1)}^{n-1} \frac{n}{x}$$
Now i'd like to be able to produce a probability distribution of how many rolls until $i=j$. I'm currently only looking at $j=6$ and $n=6$ and have come up with a solution, however it is very manual.
I can model the probability of raising $i$ from 1 to 2 (assuming 6-sided die) in $x$ rolls as:
$$p_1(x)=\frac 16^{x-1}\times \frac 56 $$
Similarly the probability of raising $i$ from 2 to 3 in $x$ rolls
$$p_2(x)=\frac{2}{6}^{x-1}\times \frac 46 $$
(I'll skip the definition of $p_3(x)$ to $p_5(x)$)
Now for the probability of raising $i$ from 1 to 6 in just 5 rolls would be
$$p_1(1) \times p_2(1) \times ... \times p_5(1)$$
But what I need to do next is the probability of raising $i$ from 1 to 6 in 6 rolls, I realise I need to do something like:
$$p_1(2) \times p_2(1) \times ... \times p_5(1) + p_1(1) \times p_2(2) \times ... \times p_5(1) + ... \times p_4(1) \times p_5(2)$$
(Not sure if I removed too much from the above equation but essentially the sum of all the different products of $p_{1-5}$ where the arguments to the functions add up to 6, does that make sense?)
And then the above but for all arguments summing to 7 and on to Infinity.
So I'm wondering how to generalise this last step? It seems to be that it could/should be able to be represented as a function. Maybe there is something similar that already exists?
Thank you in advance. Let me know if i need to edit the question to clarify anything :)
Comment: Am I right in thinking the generalised geometric distributions would look like: $$p_l(x) = {\frac l n}^{x - 1} \times \frac {n-l}{n} $$ and so I would want to sum from $l=1$ to $l=j$?
Comment: After reading through that I understand exactly what you mean by it being an "ordered" coupon collection problem, thank you! This is a generalised form of a dice mechanic for "Insanity" in a tabletop RPG "Cuthulu Dark" (http://catchyourhare.com/files/Cthulhu%20Dark.pdf) inspired by this post on reddit https://www.reddit.com/r/RPGdesign/comments/8msbxs/stats_question_regarding_cthulhu_dark/?st=JHT20DF6&sh=8fd47248 yeah i hope so, I have some reading to do but I'll post anything relevant to your question as a comment :)
Comment: It seems like you have the sum of j-1 geometric distributions, each with parameter $\frac {n-i}n$? In fact I feel like it is almost an ordered coupon collection problem.
Comment: @Tony Hellmuth thanks for your comment. That seems to make sense, when you say the sum of geometric distributions, are you referring to convolution (as desscribed here https://en.m.wikipedia.org/wiki/Convolution)? Also for the $\frac{n-1}{n}$ parameter, does that miss out the fraction that is taken to the power of $x-1$?
Comment: I think you are better off understanding the basis of your formula! Have a read of this: http://www.randomservices.org/random/urn/Coupon.html
Comment: Thanks I will take a look at that! :)
Comment: Awesome, no worries :) I happen to be working on a similar type of problem! (https://math.stackexchange.com/questions/2795397/random-sum-in-coupon-collection). Can I ask how you thought of this? Hopefully we can help each other :P
Answer: Clearly you need $j \le n$
As Tony Hellmuth says in the comments, this is closely related to the Coupon Collector's problem. You can make the relationship even closer if you start with $i=0$, which has the effect of adding $1$ to the number of throws.  Doing that, I believe you can say that the probability that the first time $i=j$ is the $r$th throw is $$ S_2(r-1,j-1) \frac{ n!}{(n-j)! n^r}$$ where $S_2(a,b)$ is a Stirling number of the second kind
For $n=j=6$ it gives probabilities like this table for varying $r$ starting at $i=0$ (if starting from $i=1$ then subtract $1$ from each $r$); in the tail $\mathbb P(R=r+1) \approx \frac56 \mathbb P(R=r)$.  The expected value is $14.7$, median is $13$ and mode is $11$.
<code>r       Prob(R=r)

1       0
2       0
3       0
4       0
5       0
6       0.0154321
7       0.0385802
8       0.0600137
9       0.0750171
10      0.0827689
11      0.0843943
12      0.0816093
13      0.0760425
14      0.0689872
15      0.0613674
16      0.0537917
17      0.0466281
18      0.0400747
19      0.0342160
20      0.0290645
21      0.0245899
22      0.0207390
23      0.0174480
24      0.0146506
25      0.0122827
26      0.0102849
27      0.0086036
28      0.0071917
29      0.0060077
30      0.0050162
31      0.0041867
32      0.0034932
33      0.0029139
34      0.0024302
35      0.0020264
36      0.0016896
37      0.0014085
38      0.0011742
39      0.0009787
40      0.0008158
41      0.0006799
42      0.0005667
43      0.0004723
44      0.0003936
45      0.0003280
46      0.0002734
47      0.0002278
48      0.0001899
49      0.0001582
50      0.0001319
</code>
Comment: You are correct. It looks like it is how long it takes to collect exactly j-1 unique coupons.
Comment: Hi @Henry thanks for your answer! I'm having trouble seeing how you got to the answer, I've looked at both https://math.stackexchange.com/questions/1609459/coupon-collectors-problem-using-inclusion-exclusion and http://www.mathematik.uni-stuttgart.de/~riedelmo/papers/coupon-stirling.pdf but cannot see the link. As Tony mentioned in his comment this problem seems to be an _ordered_ coupon collection problem, as I have to roll a 2 before any 3's count toward being collected. Could you expand on your answer some more?
Comment: @Henry After reading more on Stirling numbers of the second kind, I can see how they're related to this problem. If we take $S_2(6, 5)$ that gives us the number of possible combinations to arrange the arguments for the $P_n$ functions in my post? Thanks for giving me something to look at. I'm still trying to work out how to apply those actual numbers to the functions and sum the results, but your answer is beginning to be understood my end :)
Comment: @allouis: As I read your question "*each time the die the lands on a number greater than $i$ you increment $i$ by $1$*" you do not have to roll any $2$s exactly, it is just that to get from $i=1$ to $i=2$ you have to roll more than $1$ and this has probability $\frac{n-1}{n}$.  This is the same as in the coupon collector's problem where to get from $1$ coupon type to $2$ coupon types you have probability $\frac{n-1}{n}$ of finding a new type of coupon with each new coupon.
Comment: Yes! It's taken me a good nights sleep to reconcile this in my head, but you're right, the order doesn't matter because we're getting the same smaller probabilities as we collect coupons. The bit I'm having trouble with now is the use of $S_2$ as on the surface that gives too many combinations, the way I am interpreting it is that the stirling numbers give the number of combinations of products as described in the last block of LaTeX in my question. However, as we're only concerned with the length of the sets generated from partitioning, it seems we will have too many combinations, am I wrong?
Comment: Also something that concerns me is that in my question I say that I'm planning on using $n=6, j=6$ but plugging that into your solution leaves me dividing by $0$ does your solution only work for $n \gt j$?
Comment: @allouis: If $n=j$ then $(n-j)!=0!=1$ so you are not dividing by $0$
Comment: @Henry my b, I parsed that wrong


I need a excel formula that will move data from one sheet to another if two different characteristics are met

Question: So on the attached sheet you can see table 1 and table 2.

Table 2 will be on a separate worksheet from table 1.I need a formula the will copy columns A,B,F and H over to the other worksheet into table 2 if column H is greater then 0 and column F is HW1,HW3,HW6,HW10 or final.
Any help would be greatly appreciated. Don't really know where to start. I guess I should have mentioned that I am new to excel and have been self teaching trying to learn this. I have tried if formulas and match formulas but i can't get anything to work. Unfortunately it seems like you have to be an expert to ask a question on this site.
Comment: *I need a formula* Bad start. Please, post whay you've tried and show some effort.
Comment: If you don't want to help you don't have to. Not sure why this is a bad start if your new to excel and trying to learn some stuff. It's hard to show a whole lot of effort when you don't really know where to begin.
Answer: If one has the dynamic array formula FILTER():
<code>=FILTER(CHOOSE({1,2,3,4},A:A,B:B,F:F,H:H),(H:H>0)*((F:F="HW1")+(F:F="HW3")+(F:F="HW6")+(F:F="HW10")+(F:F="Final")))
</code>
Comment: I will try this and see if i can get it to work. This is the first real spreadsheet that i have built. I am a newb at excel but doing my best to learn it as i go.
Comment: this will only work if you have an office 365 subscription.  Otherwise I would recommend the use of vba.
Comment: Thank you scott but this company only has excel 2016 so It won't work but i do appreciate you trying.
Comment: VBA is like Japanese to me I am trying to figure out the regular excel functions LOL. Any help you could provide i would greatly appreciate.


Sum of Zetas Inequality

Question: I am here because I am unsure about how to prove the following:
$$s-1 \geqslant \sum_{n=2}^{s-1}\zeta(n)\, \left\lbrace s\mid s\in\mathbb{Z^{+}},\, s\geqslant 2 \right\rbrace$$
where $\zeta(n)$ denotes the Riemann Zeta function. I believe it to be true, given the conditions, but I have not come up with a method sophisticated enough to prove such an inequality. Thank you.
Comment: Hint: use https://math.stackexchange.com/questions/1433797/why-does-the-sum-n1-zetan-1-1/1433807#1433807
Comment: Hi Thomas. Thank you for your hint, but I'm still a little bit lost because I don't know how to use that information to prove the inequality. I'm trying to prove for finite $s$, and I don't quite see the connection. Thank you, once again.
Answer: Notice that
$$
\begin{align}
\sum_{k=2}^\infty(\zeta(k)-1)
&=\sum_{k=2}^\infty\sum_{n=2}^\infty\frac1{n^k}\\
&=\sum_{n=2}^\infty\sum_{k=2}^\infty\frac1{n^k}\\
&=\sum_{n=2}^\infty\frac1{n^2\left(1-\frac1n\right)}\\
&=\sum_{n=2}^\infty\left(\frac1{n-1}-\frac1n\right)\\[6pt]
&=1
\end{align}
$$
Thus, for finite $s$,
$$
\begin{align}
1
&\gt\sum_{n=2}^{s-1}(\zeta(k)-1)\\
&=\sum_{n=2}^{s-1}\zeta(k)-(s-2)
\end{align}
$$
Therefore,
$$
s-1\gt\sum_{n=2}^{s-1}\zeta(k)
$$
Comment: The finite sum is less than $1$ because the first term missing from the infinite series is $\zeta(s)-1\ge\frac1{2^s}$. This means that $$\sum_{k=2}^{s-1}(\zeta(k)-1)=1-\sum_{k=s}^\infty(\zeta(k)-1)\le1-\frac1{2^s}\lt1$$ The second step follows since $$\sum_{k=2}^{s-1}1=s-2$$ The last inequality is simply the previous with $s-2$ added to both sides.
Comment: Oh my word, thank you so much, Robjohn! I wasn't sure if we were allowed to perform the last three steps. Would you mind if I asked why we were able to do that? Thanks to both of you, again!
Comment: Understood. Thanks, Robjohn, for helping me again. Have a great day.

Sum of Zetas Inequality


SCCM - does captured image HW = deployed?

Question: Im hoping to use SCCM 2012 R2 to image a slew of machines that will be ordered over the next year. There will be several different vendors which implies different NICs, graphics, RAM, etc.
My question: does the machine that the OS image is captured from have to be the same as what it gets deployed to? IE could I use a VM to create the captured image? Or do I need to create a different image for every piece of hardware?
Comment: @NathanC This is news to me and `sysprep`. We build a single image, on a VM no less, and deploy it to many different vendor models and hardware.
Comment: @jscott - Same here. Things got a lot better in the Windows Vista / 7 timeframe, in terms of generalizing images and deploying them to differing hardware. (The only hiccups I've had have related to deploying desktop PC images onto laptops where the underlying hardware is *vastly* different.)
Comment: At the very least you'd need an image from each vendor. Windows is *very* cranky about differing hardware and could cause booting issues depending on the hardware.
Comment: @jscott - I have had similar experiences as well.
Comment: Agreed with @EvanAnderson; yes, SCCM uses .WIM images which are consistently very reliable with the /generalize. The only exception to this I have experienced being with Laptops (usually network adapters) and with the 4th gen Intel boards.
Answer: Unless you want to go download new drivers for NICs, display adapters, sound cards, etc., etc.,  each time you get a new model or brand of computer, then you will need to slipstream drivers into your images.  Also you need to think about whether you'll use WDS (Windows Deployment Server), or MDT (Microsoft Deployment Toolkit).  WDS is great for smaller companies that can't use full blown SCCM and don't have hundreds or thousands of computers to image each year.  MDT is great for experienced users who know how to make detailed Task Sequences that will allow you to add all your drivers and applications and other tweaks based on WMI Queries.  You capture info from WMI Queries off of the machines which you want to image, which can then target certain computers and grab certain driver packages based on what those machines are; meaning, you use WMI queries to get certain information off of a computer then put that in your MDT Task Sequence to look for these types of computers when you start the imaging.  If these types of computers are detected then a detailed Task Sequence is kicked off that grabs the right drivers for your particular model of computer.  That way you don't have to have dozens of images as you've described in your question.  My experience with MDT has been pretty good, and using Dell computers in general has also given me good luck.
You don't need a different image for each piece of hardware, just a different set of driver packages per chipset, or per model.  Typically a Dell X9000 (just a fake model for this example) will have the same chipset on all X9000 models with some variance based on when they are manufactured and/or purchased.  If you buy 20 of them though, you should be alright to capture one image then go to the Dell website and look for the Driver CAB for the X9000 or whatever the real model is and download it and add it to your driver packages on your MDT server then add it in as part of a Task Sequence.
Please see this for an in-depth look at MDT so you can get a better grasp on what you'll need.
Answer: You can capture one image and deploy it to different hardware by creating different task sequences containing the appropriate drivers for each model .
See Introduction to Operating System Deployment in Configuration Manager.
Answer: Capturing from a VM is actually better than using a physical computer. The VM allows you to take a snapshot right before you run sysprep. A month later you can boot from that snapshot, update all of the software, run sysprep and capture again. SCCM will detect and inject the proper drivers into the image at deployment time.
For SCCM I implore you to read Kent Agerlund's System Center 2012 R2 Configuration Manager: Mastering the Fundamentals. You can find older Kindle versions for $10.
Answer: Actually, though you can get much more specific about it, a deployment share will automatically use whichever driver it first detects that applies to the hardware in question. While it isn't necessarily recommended, you can simply load all of the drivers for devices into an unorganized deployment share and the deployment will still succeed. See scenario 1 – total chaos here on Johan Arwidmark's blog.
A more up to date resource to introduce you to MDT is the Windows 8.1 Deployment Jump Start at Microsoft Virtual Academy. The content in the video is relevant to anyone deploying any Windows operating system. I would urge anyone who works with Windows deployment who has not yet seen it to give it a watch. Johan and other experts in Windows deployment chime in on the issues facing Windows deployment and how they can be resolved.
Also, it is strongly recommended to use a virtual machine for a reference machine to avoid driver conflicts between the image and the destination hardware.
Comment: Agreed. Johan's "total control" organization of drivers is the way to go, if not a little OCD-ish.


RRD Tool Graph is not generating correct for one week and yearly

Question: I have a case where I have collected SNMP data and stored it via rrdtool.
for daily and weekly graph is coming correct but when i see monthly and yearly it is showing only that day portion not correct graph as shown below.
Daily Graph code is : (working correct)
/usr/bin/rrdtool graph /opt/elitecore/ManageEngine/AppManager11/working/graphs/daily-tps.png -v "TPS" -t "TIME" DEF:tps1=/root/graphs/Total_TPS.rrd:TPS:MAX -s -86400 CDEF:tps2=tps1,300,* LINE1:tps2#ff0000:TOTAL_TPS GPRINT:tps2:LAST:"Cur: %5.2lf" GPRINT:tps2:AVERAGE:"Avg: %5.2lf" GPRINT:tps2:MAX:"Max: %5.2lf" GPRINT:tps2:MIN:"Min: %5.2lf\t\t\t"
Monthly Graph code is : (not coming graph as expected)
/usr/bin/rrdtool graph /opt/elitecore/ManageEngine/AppManager11/working/graphs/monthly-tps.png -v "TPS" -t "WEEK" DEF:tps1=/root/graphs/Total_TPS.rrd:TPS:MAX -s -2592000 CDEF:tps2=tps1,300,* LINE1:tps2#ff0000:TOTAL_TPS GPRINT:tps2:LAST:"Cur: %5.2lf" GPRINT:tps2:AVERAGE:"Avg: %5.2lf" GPRINT:tps2:MAX:"Max: %5.2lf" GPRINT:tps2:MIN:"Min: %5.2lf\t\t\t"
Yearly Graph code is : (not coming graph as expected)
/usr/bin/rrdtool graph /opt/elitecore/ManageEngine/AppManager11/working/graphs/yearly-tps.png -v "TPS" -t "MONTH" DEF:tps1=/root/graphs/Total_TPS.rrd:TPS:MAX -s -31536000 CDEF:tps2=tps1,300,* LINE1:tps2#ff0000:TOTAL_TPS GPRINT:tps2:LAST:"Cur: %5.2lf" GPRINT:tps2:AVERAGE:"Avg: %5.2lf" GPRINT:tps2:MAX:"Max: %5.2lf" GPRINT:tps2:MIN:"Min: %5.2lf\t\t\t"
Kindly let me know if i am doing any wrong.
yours Faithfully
Jignesh Dholakiya
Comment: It would be helpful if you could include the images for the non-working graphs, and also the structure of the RRD file (using `rrdtool info`).  This would let us seeif the problem relates to incorrect RRA definitions, and to see visually what you mean by the graph being wrong.

For example, it may be that the MAX RRA is simply not long enough to hold a year's worth of data in all the available resolutions.
Comment: Dear Steve, Thanks for your response.. unfortunately i am unable to upload images as i have require 10 reputation for the same. could you please let me know how can i check rrdtool information... i am using linux system where i have installed RPM for rrdtool and using the rrdtool from crontab schedule.
Comment: use `rrdtool info foo.rrd` to obtain the RRD structure of the `foo.rrd` file, which will show us the interval, the number of RRAs defined, and their lengths.  Although you cannot uplaod images yet, you should be able to use free online services like `photobucket.com` to upload an image and post a URL here to view it.
Comment: Dear Steve,

Thanks for your favourable reply. below is Graph link.

Graph Link
http://s45.photobucket.com/user/jkdholakiya/media/TPS_zpsbe5f5d8f.png.html

Sincerely Thanks,
Jignesh Dholakiya.
Comment: Dear Steve,

below is the rrdtool info commnand output.

rrdtool  info Total_TPS.rrd
filename = "Total_TPS.rrd"
rrd_version = "0003"
step = 300
last_update = 1410433802
header_size = 584
ds[TPS].index = 0
ds[TPS].type = "ABSOLUTE"
ds[TPS].minimal_heartbeat = 600
ds[TPS].min = 0.0000000000e+00
ds[TPS].max = 5.0000000000e+02
ds[TPS].last_ds = "24"
ds[TPS].value = 2.2656499547e-01
ds[TPS].unknown_sec = 0
rra[0].cf = "MAX"
rra[0].rows = 1500
rra[0].cur_row = 1390
rra[0].pdp_per_row = 1
rra[0].xff = 5.0000000000e-01
rra[0].cdp_prep[0].value = NaN
rra[0].cdp_prep[0].unknown_datapoints = 0
Answer: Answer
The graph only shows five day's worth of data in the graphs because that is all the data there is in your RRD.  Your RRD is configured to automatically discard any data older than this.
Explanation
The graphs show that your RRD currently only has 6 days' worth of data to display.  As you cannot graph data which you do not have, the graphs show what they do have, and nothing for the rest.
Your rrdtool info gives this for RRA definitions (trimmed for clarity):
step = 300
rra[0].cf = "MAX"
rra[0].rows = 1500
rra[0].pdp_per_row = 1
rra[0].xff = 5.0000000000e-01

This means that you have a single RRA, type MAX, which has 1pdp per row and 1500 rows.
As a result, your RRA is (step)x(pdp per row)x(number of rows) long, which is 1500x300 seconds, which is a little over 5 days.
Since your RRD only has a single RRA, all of your graph functions will use this one -- doing additional consolidation on the fly if necessary.  Thus all your graphs use this single RRA.
However, your RRA is only 5-and-a-bit days long.  Therefore, data will be expired and discarded when it is this old.  As a result, only the last 5-and-a-bit days' worth of data are available at any time for graphing, which is what you see in the graphs.
Solution:
You need to keep the data for longer.  There are two ways to do this --

Increase the length of the existing RRA
Create additional RRAs to hold the consolidated data for the lower-resolution graphs.

Option 1 is the simplest, as you can use rrdtool tune to grow the size of RRA number 0.  However, it is very expensive in disk space (since you will be keeping the detailed data for the entire time period), plus it is expensive in CPU (RRDtool will have to consolidate on the fly when making yearly graphs).  This option is only recommended if you really need the high-resolution data for the entire period -- such as if you are calculating 95th Percentiles, for example.
Option 2 is the best.  You add a new RRA, with the same CF but more pdp_per_row, for each graph you will be wishing to create.  For a Weekly graph, use pdp_per_row=6 (for a half-hour consolidation), for Monthly use 24 (two-hourly) and for Yearly, use 288 (daily consolidation).  As time goes by, the data will be consolidated up into these new RRA, and the graph functions will use them in preference.  This is less computationally expensive, and uses less disk space; however you lose the high-resolution data over time, and your historical data will not be automatically consolidated into the new RRAs.  Also, you cannot just add a new RRA to an existing RRD file -- you will need to either create a new RRD, or use a tool such as rrdmerge.
Comment: Dear Steve, Thanks for your excellent answer. i would like to follow option 2 for weekly and yearly graph. could you let me know is there any way to create new RRA without loosing my current data ?  Thanks !! Jignesh Dholakiya
Comment: There's no easy way.  However, if you create a new RRD file with all the correctly sized RRAs, you can then use the rrdmerge utility included with Routers2 to merge the two -- it will preserve the old data where possible. See http://www.steveshipway.org/software


Saxophone articulation - interpreting symbols

Question: I have a number of pieces that feature the following articulation symbols (highlighted in red; last bar of Andy Firth's "The Bullfrog Bounce"):

I've asked my teacher how to play them, but his explanations were very vague. Since I do not know even what they're called, it is impossible for me to find any materials. The articles I've discovered do not feature either symbol.
Comment: https://en.wikipedia.org/wiki/Marcato
Comment: https://www.dolmetsch.com/musictheory21.htm#accent
Answer: ∧ (Italian "martellato") is a symbol used to denote a strong accent, usually a rhythmic thrust followed by a decay of the sound. > (Italian "marcato") is a "lighter" version of the same accent. In jazz scores, like the one in the question, it usually also means that the note is supposed to be played for approximately 2⁄3 of its normal duration.
With the saxophone, the effect can be achieved by adjusting the embouchure or introducing a drop in the jaw.
I'd like to thank Your Uncle Bob and replete for providing the links explaining those symbols.
Comment: Be aware that some people call the `^` a marcato, and `>` an accent. Just to make life confusing.
Comment: @Albrecht_Hügli it will matter the first time someone says "play that with an accent" and the OP only knows it as a marcato. So, I think it's a valid point.
Comment: @endorph, thank you. It made the Wikipedia article more confusing indeed.
Comment: it doesn't matter how you call it, the meaning and interpretation is correct. There are lots of different spellings by different languages and in other countries or other styles.
Comment: Dolmetsch has  pretty good page on accents: https://www.dolmetsch.com/musictheory21.htm#accent


Showing that $f(x)/x$ is decreasing on $[0, \infty) $

Question: I want to prove that if $f:[0, \infty) \to [ 0, \infty )$,$f(0)=0$ and $f(x)>0$ for all $x>0$, $f$ is increasing and $f'$ is decreasing then $f(x)/x$ is decreasing for $x>0$.
Here's my attempt:
Let $x,y \in (0, \infty)$ and suppose that $x\le y$. By the mean value theorem, we have that $f(x)/x=f'(c)$ and $f(y)/y=f'(d)$ for some $c \in (0, \infty)$ and some $d \in (0, \infty)$. If we show that $c\le d$, we'll be done because then $f'(d)\le f'(c)$, i.e., $f(y)/y \le f(x) /x$. So assume that $d<c$. Then $f'(c) \le f'(d)$.
I haven't been able to proceed from here. Hints would be appreciated.
Answer: A slight modification of your idea works: For $0 < x < y$ use the mean-value theorem not on the intervals $[0, x]$ and $[0, y]$, but on $[0, x]$ and $[x, y]$. Then
$$
 \frac{f(x)}{x} = f'(c) \, , \, \frac{f(y)-f(x)}{y-x} = f'(d)
$$
with $c \in (0, x)$ and $d \in (x, y)$, so that $f'(c) \ge f'(d)$. It follows that
$$
 \frac{f(x)}{x}  \ge \frac{f(y)-f(x)}{y-x}
$$
which is equivalent to $\frac{f(x)}{x} \ge \frac{f(y)}{y}$.

Another option is to use that a function with decreasing derivative is concave, so that for $0 < x < y$
$$
f(x) \ge \frac{y-x}{y}f(0) + \frac{x}{y}f(x) = \frac{x}{y}f(y) \, .
$$
Comment: I think I had almost completed the problem using the first idea. (I didn't post that attempt here.) Thanks for the response!
Answer: $f(x)=\int_0^{x} f'(t)dt \geq \int_0^{x} f'(x)dt =xf'(x)$. Hence $\frac d {dx} (\frac {f(x)}x )=\frac {xf'(x)-f(x)} x \leq 0$ and this implies that $\frac {f(x)}x$ is decreasing.
Comment: I was thinking along those lines too but I couldn't get it. Thanks.


Problemas ao inicializar um tipo dentro de uma consulta com LINQ

Question: Estou passando pelo seguinte problema, estou montando uma API para uma aplicação de forum e essa API precisa de um endpoint que retorne uma coleção de Forum que possuem a propriedade ParentId nula. Então montei o seguinte endpoint:
[AllowAnonymous]
[HttpGet]
[Route("toplevel")]
public async Task<IHttpActionResult> GetAllTopLevel(int page = 1, int pageSize = 15)
{
    var data = Db.Forums
        .Where(f => !f.ParentId.HasValue)
        .OrderByDescending(f => f.Name)
        .Skip((page - 1) * pageSize)
        .Take(pageSize)
        .Select(f => new ForumDTO
        {
            Id = f.Id,
            Name = f.Name,
            SubForums = f.SubForums.Select(sf => new ForumDTO
            {
                Id = sf.Id,
                Name = sf.Name
            }).ToList()
        }).ToList();

    return Ok(data);
}

Mas estou tendo problemas no Select desse LINQ, que está causando uma NotSupportedException com a seguinte mensagem de erro:

The type 'ZigForum.Models.DTOs.ForumDTO' appears in two structurally incompatible initializations within a single LINQ to Entities query. A type can be initialized in two places in the same query, but only if the same properties are set in both places and those properties are set in the same order.

Classe Forum:
public class Forum
{
    public Forum()
    {
        SubForums = new List<Forum>();
        Posts = new List<Post>();
    }

    public int Id { get; set; }
    public int? ParentId { get; set; }
    public string Name { get; set; }
    public DateTime Created { get; set; }

    public virtual Forum Parent { get; set; }
    public virtual ICollection<Forum> SubForums { get; set; }
    public virtual ICollection<Post> Posts { get; set; }
}

Classe ForumDTO:
public class ForumDTO
{
    [JsonProperty("id")]
    public int Id { get; set; }

    [JsonProperty("parent_id")]
    public int? ParentId { get; set; }

    [JsonProperty("name")]
    public string Name { get; set; }

    [JsonProperty("created")]
    public DateTime? Created { get; set; }

    [JsonProperty("parent")]
    public ForumDTO Parent { get; set; }

    [JsonProperty("subforums")]
    public List<ForumDTO> SubForums { get; set; }

    [JsonProperty("posts")]
    public List<PostDTO> Posts { get; set; }
}

Já tentei algumas coisas também, como por exemplo inicializar a propriedade SubForums com null, já que na mensagem de erro anterior fala que um tipo só pode ser inicializado em dois lugares se em ambos os lugares valores forem atribuídos às mesmas propriedades e na mesma ordem. Fazer isso me pareceu comprimir com as exigências:
[AllowAnonymous]
[HttpGet]
[Route("toplevel")]
public async Task<IHttpActionResult> GetAllTopLevel(int page = 1, int pageSize = 15)
{
    var data = Db.Forums
        .Where(f => !f.ParentId.HasValue)
        .OrderByDescending(f => f.Name)
        .Skip((page - 1) * pageSize)
        .Take(pageSize)
        .Select(f => new ForumDTO
        {
            Id = f.Id,
            Name = f.Name,
            SubForums = f.SubForums.Select(sf => new ForumDTO
            {
                Id = sf.Id,
                Name = sf.Name,
                SubForums = null // Note que fiz a alteração aqui
            }).ToList()
        }).ToList();

    return Ok(data);
}

Mas me resultou em outro erro:

Unable to create a null constant value of type 'System.Collections.Generic.List`1[[ZigForum.Models.ViewModels.ForumDTO, ZigForum, Version=18.104.22.168, Culture=neutral, PublicKeyToken=null]]'. Only entity types, enumeration types or primitive types are supported in this context.

Alguém poderia me ajudar por favor? Não sei mais o que fazer.
Comment: já tentou `SubForums = new List()`?
Comment: @TobyMosque também não funciona, é uma restrição do LINQ to Entities
Comment: normalmente eu uso o `AutoMapper` para preencher as minhas DTO/Contratos, postei uma resposta com um exemplo.
Answer: Você não pode inicializar um objeto dentro de uma expressão Linq. Simples assim.
Mas, há como contornar:
public class ForumDTO
{
    // Propriedades

    public static ToForumDTO(Forum f)
    {
        return new ForumDTO
        {
            Id = f.Id,
            Name = f.Name,
            SubForums = f.SubForums
        }
    }
}

E consome no seu Linq assim:
 .Select(ForumDTO.ToSubForum).ToList();

Answer: Estou vendo que a sua Entidade e o seu DTO tem as mesmas propriedades com tipos compativeis e o mesmo nome.
Neste caso, você pode tentar usar o AutoMapper para fazer o mapeamento para você.
abaixo segue um exemplo usando LINQ para Objetos, mas deve funcionar sem problemas com LINQ to Entities.
Entidade
public class Forum
{
    public Forum()
    {
        this.SubForums = new List<Forum>();
    }

    public Guid ID { get; set; }
    public string Nome { get; set; }
    public Guid? ParentID { get; set; }

    public virtual Forum Parent { get; set; }
    public virtual ICollection<Forum> SubForums { get; set; }
}

DTO
[DataContract]
public class ForumDTO
{
    [DataMember]
    public Guid ID { get; set; }
    [DataMember]
    public string Nome { get; set; }
    [DataMember]
    public Guid? ParentID { get; set; }

    [DataMember]
    public ForumDTO Parent { get; set; }
    [DataMember]
    public IList<ForumDTO> SubForums { get; set; }
}

Global.asax - Registrando os Maps
protected void Application_Start()
{
    Mapper.CreateMap<Forum, ForumDTO>();
}

Consulta
var forums = new List<Forum>();
PopularForums(ref forums);

var data = (
    from forum in forums
    where !forum.ParentID.HasValue
    select Mapper.Map<ForumDTO>(forum)
).ToList();

Se mesmo assim não dê certo, você pode fazer um ToList() antes de fazer o map.
var forums = new List<Forum>();
PopularForums(ref forums);

var lista = (
    from forum in forums
    where !forum.ParentID.HasValue
    select forum
).ToList();

var data = Mapper.Map<List<ForumDTO>>(lista);

Você pode ver o exemplo completo no DotNetFiddle, note que ele serializa a arvore completa dos forums, indepedente do numero de parentes e subarvores.
Comment: Interessante, vou tentar fazer dessa forma utilizando AutoMapper, mais tarde te dou um retorno, pois não vou poder testar isso agora.
Answer: Crie um conversor estático explícito na sua classe ForumDTO que converta o Fórum para o ForumDTO e na sua instrução select use-o. Também seria interessante você substituir boa parte dos métodos por instruções LINQ que imitam o SQL.
Answer: Pode sim inicializar um objeto dentro do select.
Dá uma olhada nesse código, funciona perfeitamente.
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
    public static void Main()
    {
        const int page = 1;
        const int pageSize = 15;

        var forums = new List<Forum>
        {
            new Forum
            {
                Id = 1,
                Name = "Forum 1",
                Created = DateTime.Now,
                SubForums = new List<Forum>
                {
                    new Forum {Id = 2, ParentId = 1, Name = "Forum 2"},
                        new Forum {Id = 3, ParentId = 1, Name = "Forum 3"}
                }
            }
        };

        var data = forums
            .Where(f => !f.ParentId.HasValue)
            .OrderByDescending(f => f.Name)
            .Skip((page - 1)*pageSize)
            .Take(pageSize)
            .Select(f => new ForumDTO
                    {
                        Id = f.Id,
                        Name = f.Name,
                        SubForums = f.SubForums.Select(sf => new ForumDTO
                                                       {
                                                           Id = sf.Id,
                                                           Name = sf.Name,
                                                           SubForums = null
                                                       }).ToList()
                    }).ToList();

        foreach (var d in data)
        {
            Console.WriteLine(d.Name);

            if (d.SubForums.Count <= 0) continue;

            foreach (var subForum in d.SubForums)
            {
                Console.WriteLine("\t"+ subForum.Name);
            }
        }
    }
}

public class Forum
{
    public Forum()
    {
        SubForums = new List<Forum>();
    }

    public int Id { get; set; }
    public int? ParentId { get; set; }
    public string Name { get; set; }
    public DateTime Created { get; set; }
    public virtual Forum Parent { get; set; }
    public virtual ICollection<Forum> SubForums { get; set; }
}

public class ForumDTO
{
    public int Id { get; set; }
    public int? ParentId { get; set; }
    public string Name { get; set; }
    public DateTime? Created { get; set; }
    public ForumDTO Parent { get; set; }
    public List<ForumDTO> SubForums { get; set; }
}

https://dotnetfiddle.net/071eSl
Comment: Cara, você esta usando o Linq em uma collection normal, o problema dele é porque ele esta usando linq to entity onde _"o linq vira uma consulta SQL"_, ou seja o _provider_ não está conseguindo interpretar o linq.
Comment: Tenta assim: https://dotnetfiddle.net/ULn8ny

Só restando passar o Db.
Não tenho como testar aqui, mas pode funcionar.
Comment: Lol, eh diferente, ele está usando outro provider para linq, **EF**
Comment: O problema dele está no ````ToList()```` dentro do linq,