What is *cuivre* for a trumpet

Question: Cuivre in French means copper, I think.
In music it seems to be the name of the family of Brass instruments. Correct me in this if it is wrong.
In Sibelius, the trumpet has a property (regulated by a dial) called cuivre. What does it mean cuivre in this case?
The dial appears little in the instrument that is open. It is in Sibelius 7, though.
Answer: Well, that may be a literal word-for-word translation, but the French for "brass" is ALSO cuivre (or specifically, cuivre jaune). Brass, of course, is an alloy that contains copper at varying levels.
The name for "the brass (instruments)" in French is les cuivres.
As for the dial you are seeing, I am unable to find that on my copy of Sibelius 6, running under either the English or French localization. Can you provide a screenshot of the setting in context?
EDIT:
After seeing this in context and doing a bit more research, it appears that in addition to the language definitions above, cuivre is also used as an indication for brass players to play with a "brassier" tone (i.e. harsh or overblown... you'll know it when you hear it--think drum corps. playing). So yes, it is a change in the sound, although not directly related to the proportion of copper in the brass alloy in this case -- just an emulation of a slightly different playing technique that results in a desired tone.
The Sibelius 7 instrument library pulls this property out of the regular instrument into one that can be adjusted independent of other variables (in older versions, you would expect to hear a brassy or overblown tone come into effect with an unreasonably high dynamic level like fff.)
Comment: Just want to add here that *cuivré* is primarily used for horns to indicate to play with a "brassier" sound (that quintessential horn sound we love in movies!) Trumpets don't really do that sort of thing.
Comment: I am using Sibelius7. Could it be that instruments are sometimes made with different types of brass (changing the proportion of copper) and somehow they are trying to model the change in the sound? Just guessing.
Comment: The proper french term for brass (the alloy) is not *cuivre* but *laiton*. And *son cuivré* takes an accent. *Son cuivre* is weird and doesn't really mean anything.
Answer: Use your ears.
A few instruments in Sibelius 6 and 7 have these additional knobs in the mixer, designed to let the user modify the sound of the sampled instrument in some way. The most meaningful way to answer your question is this: What do you hear when you change the setting on the knob and play the music? Can you describe what it sounds like when the knob is turned all the way down, or set half-way, or turned all the way up?
Comment: The question is more about what is it, or maybe how is it actually done in the instrument. It is a different question what sound am I hearing than what is producing that sound.

What is *cuivre* for a trumpet


Prove that Trace is a bounded operator, and find its norm.

Question: I'm trying to prove that the trace of a matrix $\tau:\mathcal M_{n\times n}(\mathbb R)\to \mathbb R$ is a bounded operator, i.e. there is $K>0$ s.t. $|\tau(M)|\leq K\|M\|,$ where $$\|M\|=\sup_{|x|_2= 1}|Mx|_2,$$
where $|\cdot |_2$ denote the euclidian norm of $\mathbb R^n$. Find $$\|\!|\tau\|\!|:=\sup_{\|M\|=1}|\tau(M)|.$$
I'm very confused with all these norms.

Attempts

For the fact that $\tau$ is continuous, it's quite easy since $$|\tau(M)|\leq |M_{11}|+...+|M_{nn}|\leq n^2 \mathcal N_1(M),$$
where $$\mathcal N_1(M)=\sum_{1\leq i,j\leq n}|M_{ij}|.$$
I know that $\mathcal N_1$ is a norm on $\mathcal M_{n\times n}(\mathbb R)$, and since all norms on $\mathcal M_{n\times n}(\mathbb R)$ are equivalent, there is $P>0$ s.t. $\mathcal N_1(M)\leq P\|M\|$. Therefore, setting $K=n^2P$, we get $$|\tau(M)|\leq K\|M\|,$$
as wished.

I have no idea on how computing $|\!\|\tau\|\!|$. I suspect that $|\!\|\tau\|\!|=n^2$, but I have no idea on how to compute it. Any idea ?
Comment: Does this answer your question? [Every linear operator $T:X \to Y$ on a finite-dimensional normed space is bounded](https://math.stackexchange.com/questions/2983050/every-linear-operator-tx-to-y-on-a-finite-dimensional-normed-space-is-bounde)
Comment: You should mention which norm $\|M\|$ you are using on the matrices. Is it their operator norm considered as maps $\Bbb R^n\to\Bbb R^n$?
Comment: **Hint :** if $(e_1, ..., e_n)$ denotes the standard basis of $\mathbb{R}^n$, then $$\tau(M)=\sum_{i=1}^n \langle Me_i,e_i \rangle$$ Now use Cauchy-Schwarz.
Comment: @FShrike: As written in my OP, $\|M\|=\sup_{|x|_2=1}|Mx|_2$ where $|\cdot |_2$ denote the euclidian norm on $\mathbb R^n$.
Comment: @TheSilverDoe:  Applying C-S yields $$|\tau(M)|\leq n\sum_{i=1}^n |Me_i|_2=n(|M_{1i}|+...+|M_{ni}|)\leq n^2 \sup_{k=1,...,n}|M_{ki}|\leq n^2\|M\|.$$ Now, which matrix $M$ could I take s.t. $\|M\|=1$ and $\tau(M)=n^2$ ? I thought $M_{ij}=n\delta _{ij}$ for all $i,j$, but I don't see how to prove $\|M\|=1$, any idea ?
Answer: I think C-S yields
$$
|\tau(M)| \le \sum_{i=1}^n|\langle Me_i,e_i\rangle| \le \sum_{i=1}^n |Me_i|_2 |e_i|_2 \le \sum_{i=1}^n\|M\| = n \|M\|.
$$
For $M=I_n$ we have $\tau(M)=n$ and $\|M\| =1$. Hence $||| \tau |||=n$.
Comment: Please search for duplicates before answering! (=:
Comment: @SummerChild Yes, the link you found shows that $\tau$ is continuous, but say's nothing on the quantity of $|||\tau|||$. In the original question $|||\tau|||=n^2$ was presumed, which is wrong. This was the reason for my answer.
Comment: @SummerChild In fact I did. Searched under "trace norm" and found the corresponding answer with respect to the Frobenius norm, but not exactly the version above.  I agree that its maybe a dublicate, but I don't search for hours.
Comment: The search took me less than a minute, I just entered: ` "finite dimensional" AND "bounded" AND "operator" `.


Common statistical tests as linear models

Question: (UPDATE: I dived deeper into this and and posted the results here)
The list of named statistical tests is huge. Many of the common tests rely on inference from simple linear models, e.g. a one-sample t-test is just y = β + ε which is tested against the null model y = μ + ε i.e. that β = μ where μ is some null value - typically μ=0.
I find this to be quite a bit more instructive for teaching purposes than rote learning named models, when to use them, and their assumptions as if they had nothing to do with each other. That approach promotes does not promote understanding. However, I cannot find a good resource collecting this. I am more interested in equivalences between the underlying models rather than the method of inference from them. Although, as far as I can see, likelihood ratio tests on all these linear models yield the same results as the "classical" inference.
Here are the equivalences I've learned about so far, ignoring the error term $\varepsilon \sim \mathcal N(0, \sigma^2)$ and assuming that all null hypotheses are the absense of an effect:
One-sample t-test:
$y = \beta_0 \qquad \mathcal{H}_0: \beta_0 = 0$.
Paired-sample t-test:
$y_2-y_1 = \beta_0 \qquad \mathcal{H}_0: \beta_0 = 0$
This is identical to a one-sample t-test on pairwise differences.
Two-sample t-test:
$y = \beta_1 * x_i + \beta_0 \qquad \mathcal{H}_0: \beta_1 = 0$
where x is an indicator (0 or 1).
Pearson correlation:
$y = \beta_1 * x + \beta_0 \qquad \mathcal{H}_0: \beta_1 = 0$
Notice the similarity to a two-sample t-test which is just regression on a binary x-axis.
Spearman correlation:
$rank(y) = \beta_1 * rank(x) + \beta_0 \qquad \mathcal{H}_0: \beta_1 = 0$
This is identical to a Pearson correlation on rank-transformed x and y.
One-way ANOVA:
$y = \beta_1*x_1 + \beta_2*x_2 + \beta_3*x_3 +... \qquad \mathcal{H}_0: \beta_1, \beta_2, \beta_3, ... = \beta$
where $x_i$ are indicators selecting the relevant $\beta$ (one $x$ is 1; the others are 0). The model could probably be written in matrix form as as $Y = \beta * X$.
Two-way ANOVA:
$y = \beta_1 * X_1 + \beta_2 * X_2 + \beta_3 * X_1 * X_2 \qquad \mathcal{H}_0: \beta_3 = 0$
for two two-level factors. Here $\beta_i$ are vectors of betas where one is selected by the indicator vector $X_i$. The $\mathcal{H}_0$ shown here is the interaction effect.
Could we add more "named tests" to this list of linear models? E.g., multivariate regression, other "non-parametric" tests, binomial tests, or RM-ANOVAs?
UPDATE: questions have been asked and answered about ANOVA and t-tests as linear models here on SO. See this question and tagged related questions.
Comment: I think these comparisons are appropriate but that at some point there are also subtle differences. E.g. take the one-way ANOVA: where a linear regression will provide you with the coefficients and in most software packages the *significance per coefficient* with Wald tests (which might not be appropriate), an ANOVA will provide a single p-value indicating whether any one of the coefficients is significantly different from zero. A Likelihood Ratio Test between a null model and the regression model of interest might be more comparable. As such, I wouldn't completely equalize these tests/models.
Comment: Fair enough, but inference aside, do note that regression models also provide added flexibility when handling non-linearity (although transformations might be also tested with these 'named tests', splines are a different matter) or handling heteroscedasticity, not even mentioning the family of generalized models which also handle non-continuous dependent variables. Nonetheless, I can see explaining the named tests as restrictive variations of regression models for teaching purposes can have merit, so +1
Comment: Is Spearman rank correlation really a linear model ?
Comment: @MartinDietz: Yes, after rank-transforming x and y, it is linear. R code: `x = rnorm(100); y = rnorm(100); summary(lm(rank(x) ~ rank(y))); cor.test(x, y, method='spearman')`
Comment: Good point; I updated the question, saying that "I am more interested in equivalences between the underlying models rather than the method of *inference* from them." Likelihood-ratio tests on the one-way ANOVAs and interaction terms yields identical p-values as the "classical" analyses as far as my testing goes.
Answer: Not an exhaustive list but if you include generalized linear models, the scope of this problem becomes substantially larger.
For instance:
The Cochran-Armitage test of trend can be formulated by:
$$E[\mbox{logit} (p) | t] = \beta_0 + \beta_1 t \qquad \mathcal{H}_0: \beta_1 = 0$$
The Pearson Chi-Square test of independence for a $p \times k$ contingency table is a log-linear model for the cell frequencies given by:
$$E[\log (\mu)] = \beta_0 + \beta_{i.} + \beta_{.j} + \gamma_{ij} \quad i,j > 1 \qquad\mathcal{H}_0: \gamma_{ij} = 0, \quad i,j > 1$$
Also the t-test for unequal variances is well approximated by using the Huber White robust error estimation.


Parallel octaves in left hand chords

Question: In classical / romantic harmony, are parallel octaves allowable in left hand chords?  When and why?  For example, in Chopin's Nocturne Op. 9 No. 2, right at the beginning, there are parallel G-A-G.  This is not a case of voice doubling, since the octaves disappear in the second measure.
Comment: A copy of the bars would be helpful. As you say G and A, I'm looking up the sheet but I can find only octava in  bar 32.
Comment: I don't recall G-A-G octaves in the Nocturne neither!
Answer: Yes, here these octava parallels are allowed. (You may mean the rules of strict voice leading in a 4 part-harmony.)
In a piano piece like this in romantic or classic music you don't mind the rule of forbidden parallels, doubling of voicing can take every where (left and right hand), except this would actually be a 4 part setting.
The piano  can play the role of an orchestra as well as a string quartet.
Comment: One way of looking at it is that parallel octaves in this setting are not two separate voices, but just one strengthened voice.
Comment: Exactly. Even in classical counterpoint, unison passages were always permissible. The prohibition against parallel octaves concerns instances between two voices that are *supposed* to be independent.

Parallel octaves in left hand chords


How best to explain partial order over vectors?

Question: I have the following notational issue:
Given a vector space $\mathbf{V}$, I have a partial order such that for all $\mathbf{v},\mathbf{w} \in \mathbf{V}$:
iff for all components $v_i$ of $\mathbf{v}$ and  $w_i$ of $\mathbf{w}$
$$v_i\leq w_i$$
then
$$\mathbf{v} \leq \mathbf{w}$$
Is there a  well known way of stating this partial order ?
Comment: I'd say the word "component-wise" would describe this well, but you should give the fully written out definition the first time you use it, and then you can use your chosen symbol, or that term, thereafter.
Comment: Presumably it is a vector space $\mathbf V$.  I think you have stated it well.  You might use a different symbol for the comparison between vectors like $\mathbf v \preceq \mathbf w$ using \preceq
Comment: The problem is not clarity, it is the space it will occupy to mention. I was wondering if there is just a name for this, so i could write  we have "xxx" partial order on $\mathbf{V}$, and we denote it with $\leq$
Comment: You also need to specify a basis in $\mathbf{V}$ for this to work. The components depend on a basis.
Comment: The way you stated it seems clear to me.
Answer: I had not heard of this concept before, but searching for "componentwise partial order" brought up the "product order", which seems to be what you want.
I'm not an order theorist, but if you didn't know of a name for this offhand, your audience may not know this definition of "product order", so it would be good to give the definition in whatever you are writing, anyway.


Write data from Textbox into text file in ASP.net with C#

Question: I have a textbox where a user can input their email, what I want to do is make it so that when they click a submit button. That email will be saved into a text file ( on my server ) called emails.txt
I managed to get this working using System.IO and then using the File.WriteAll method. However I want to make it so that it will add the email to the list ( on a new line ) rather then just overwriting whats already in there.
I've seen people mention using Append, but I can't quite grasp how to get it working.
This is my current code (that overwrites instead of appending).
public partial class _Default : Page
{
    private string path = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        path = Server.MapPath("~/emails.txt");
    }

    protected void emailButton_Click(object sender, EventArgs e)
    {
        File.WriteAllText(path, emailTextBox.Text.Trim());
        confirmEmailLabel.Text = "Thank you for subscribing";
    }
}

Answer: You can use StreamWriter to get working with text file. The WriteLine method in true mode append your email in new line each time....
using (StreamWriter writer = new StreamWriter("email.txt", true)) //// true to append data to the file
{
    writer.WriteLine("your_data");
}

Answer: From the official MSDN documentation:
using (StreamWriter w = File.AppendText("log.txt"))
{
   MyWriteFunction("Test1", w);
   MyWriteFunction("Test2", w);
}

Answer: Use StreamWriter in Append mode. Write your data with WriteLine(data).
using (StreamWriter writer = new StreamWriter("emails.txt", true))
{
    writer.WriteLine(email);
}

Answer: Seems like a very easy question with a very easy answer: Open existing file, append a single line
If you post the current code, we can modify that to append instead of overwrite.


Getting ID from div in React.js

Question: So I'm trying to retrieve data in a div attribute in react. JSFiddle shows the problems I'm having. this.state.value is set to an empty string after the event fires.
I started off using the data-* attribute for the div after reading another stack overflow post, but I cannot use jQuery, so I switched to id. Any ideas?
JSFiddle
class GettingAttributes extends React.Component {
  constructor(props) {
    super(props)
    this.state = {value: 'Hello!'};

    this.bar = this.bar.bind(this);
  }

  bar(e){
    this.setState({value: e.target.id})
  }

  render() {
    return (

{this.state.value}

    );
  }
}

Answer: Use
e.currentTarget.id

instead of
e.target.id

.currentTarget will target the element that actually contains the event listener. In your scenario, .target is the p tag with the text in it, which doesn't have an id to set in your state.
Answer: You can do it by id as well as data-* attributes. But the preferred method is by data-* attributes.
Please consider this JSFiddle link of your solution.
You should set ref on the element from which you want to extract the data and then you can use it to set data in state. IN code if you replace onClick={this.bar} with onClick={this.barById} then code will extract data from id while in former case it will extract data from data-* attributes.
Answer: the reason why you are unable to select the id property is that the current e.target is the child of the
, which is
. Here is a proposed solution that works:
class GettingAttributes extends React.Component {
  constructor(props) {
    super(props)
    this.state = {value: 'Hello!'};

    this.bar = this.bar.bind(this);
  }

  bar(e){
    this.setState({value: e.target.id})
  }

  render() {

    return (

        {this.state.value}

    );
  }
}

ReactDOM.render(<GettingAttributes />, document.querySelector("#app"))

You may also solve this by adding the click handler to the
 element:

{this.state.value}

Using e.currentTarget.id will quickly solve your problem, just know what the currentTarget stands for instead of Target alone. Good luck!

Getting ID from div in React.js


How to calculate overlap between empirical probability densities?

Question: I'm looking for a method to calculate the area of overlap between two kernel density estimates in R, as a measure of similarity between two samples. To clarify, in the following example, I would need to quantify the area of the purplish overlapping region:
library(ggplot2)
set.seed(1234)
d <- data.frame(variable=c(rep("a", 50), rep("b", 30)), value=c(rnorm(50), runif(30, 0, 3)))
ggplot(d, aes(value, fill=variable)) + geom_density(alpha=.4, color=NA)

A similar question was discussed here, the difference being that I need to do this for arbitrary empirical data rather than predefined normal distributions. The overlap package addresses this question, but apparently only for timestamp data, which doesn't work for me. The Bray-Curtis index (as implemented in vegan package's vegdist(method="bray") function) also seems relevant but again for somewhat different data.
I'm interested in both the theoretical approach and the R functions I might employ to implement it.
Comment: I would be very concerned about the risk of arbitrariness in this method. Depending on the kernel bandwidth, the computed overlap between *any* two datasets could be made to equal any chosen value in the interval $(0,1)$. The default bandwidths are not optimized for this purpose and therefore conceivably could give surprising, arbitrary, or inconsistent results. Datasets with natural bounds (such as non-negative data or proportions, etc.) would further introduce unwanted edge effects. What to do instead? Start with the reason for this calculation: what is this "similarity" intended to mean?
Comment: "quantify the purple area" is a problem in estimation, not in hypothesis testing, so you cannot hope to "accomplish this using a standard citable statistical ***test***". You contradict yourself. Please clarify what you *actually* want. If all you want is an estimate of the area of overlap of two KDEs, that's a simple calculation.
Comment: @Glen_b thanks for the comment, helped to clarify my non-statistician thinking. I believe the area of overlap between KDEs is indeed what I'm looking for -- I've edited the question to reflect that.
Comment: The same question appeared a few months later but referred to intersection points however there were some valid notes which could be taken into consideration. In the referred question  is about two empirical distributions. I add the link as this post only answers this via kernel density estimation and for normal distributions. The link below I think extends on the question for pairs of empirical distributions. stats.stackexchange.com/questions/122857/… –  Barnaby 7 hours ago
Answer: The area of overlap of two kernel density estimates may be approximated to any desired degree of accuracy.
1) Since the original KDEs have probably been evaluated over some grid, if the grid is the same for both (or can easily be made the same), the exercise could be as easy as simply taking $\min(K_1(x),K_2(x))$ at each point and then using the trapezoidal rule, or even a midpoint rule.
If the two are on different grids and can't easily be recalculated on the same grid, interpolation could be used.
2) You might find the point (or points) of intersection and integrate the lower of the two KDEs in each interval where each one is lower. In your diagram above you'd integrate the blue curve to the left of the intersection and the pink one to the right by whatever means you like/have available. This can be done essentially exactly by considering the area under each kernel component $\frac{1}{h}K(\frac{x-x_i}{h})$ to the left or right of that cut-off point.
However, whuber's comments above should be clearly borne in mind -- this is not necessarily a very meaningful thing to do.
Comment: These methodology suggestions makes sense, thanks very much for your answer. I will work on implementing this in R, but as a novice I would be interested in suggestions on how to code this cleanly.
Comment: How do you calculate the error associated with method one and method 2?
Comment: In normal circumstances, both will be miniscule compared with the error in the kernel density estimates, so I wouldn't worry too much. Error bounds can be calculated on trapezoidal methods and other numerical integration of course - such calculations are pretty standard - but it's pointless worrying given that KDEs have large uncertainties. Method 2 will be accurate to accumulated rounding error of the calculations.
Answer: For the sake of completeness, here's how I ended up doing this in R:
# simulate two samples
a <- rnorm(100)
b <- rnorm(100, 2)

# define limits of a common grid, adding a buffer so that tails aren't cut off
lower <- min(c(a, b)) - 1
upper <- max(c(a, b)) + 1

# generate kernel densities
da <- density(a, from=lower, to=upper)
db <- density(b, from=lower, to=upper)
d <- data.frame(x=da$x, a=da$y, b=db$y)

# calculate intersection densities
d$w <- pmin(d$a, d$b)

# integrate areas under curves
library(sfsmisc)
total <- integrate.xy(d$x, d$a) + integrate.xy(d$x, d$b)
intersection <- integrate.xy(d$x, d$w)

# compute overlap coefficient
overlap <- 2 * intersection / total

As noted, there is inherent uncertainty and subjectivity involved in the KDE generation and also in the integration.
Comment: There is now a package on CRAN called `overlapping` that estimates the area of the overlap of 2 (or more) empirical distributions. Check out the documentation here: https://www.rdocumentation.org/packages/overlapping/versions/1.5.0/topics/overlap
Comment: @mmk can you do this for 2D densities?
Comment: Total should be: total = integrate.xy(d$x, d$a) + integrate.xy(d$x, d$b) - integrate.xy(d$x, d$w), which can be confirmed by using the package overlapping.
Answer: First, I might be wrong but I think your solution wouldn't work in case where there is multiples points where the Kernel Density Estimates (KDE) intersect.
Second, although the overlap package was created for use with timestamp data, you can still use it to estimate the area of overlap of any two KDEs. You simply have to rescale your data so that it range from 0 to 2π.
For exemple :
# simulate two sample
 a <- rnorm(100)
 b <- rnorm(100, 2)

# To use overplapTrue(){overlap} the scale must be in radian (i.e. 0 to 2pi)
# To keep the *relative* value of a and b the same, combine a and b in the
# same dataframe before rescaling. You'll need to load the 'scales' library.
# But first add a "Source" column to be able to distinguish between a and b
# after they are combined.
 a = data.frame( value = a, Source = "a" )
 b = data.frame( value = b, Source = "b" )
 d = rbind(a, b)
 library(scales)
 d$value <- rescale( d$value, to = c(0,2*pi) )

# Now you can created the rescaled a and b vectors
 a <- d[d$Source == "a", 1]
 b <- d[d$Source == "b", 1]

# You can then calculate the area of overlap as you did previously.
# It should give almost exactly the same answers.
# Or you can use either the overlapTrue() and overlapEst() function
# provided with the overlap packages.
# Note that with these function the KDE are fitted using von Mises kernel.
 library(overlap)
  # Using overlapTrue():
   # define limits of a common grid, adding a buffer so that tails aren't cut off
     lower <- min(d$value)-1
     upper <- max(d$value)+1
   # generate kernel densities
     da <- density(a, from=lower, to=upper, adjust = 1)
     db <- density(b, from=lower, to=upper, adjust = 1)
   # Compute overlap coefficient
     overlapTrue(da$y,db$y)

  # Using overlapEst():
    overlapEst(a, b, kmax = 3, adjust=c(0.8, 1, 4), n.grid = 500)

# You can also plot the two KDEs and the region of overlap using overlapPlot()
# but sadly I haven't found a way of changing the x scale so that the scale
# range correspond to the initial x value and not the rescaled value.
# You can only change the maximum value of the scale using the xscale argument
# (i.e. it always range from 0 to n, where n is set with xscale = n).
# So if some of your data take negative value, you're probably better off with
# a different plotting method. You can change the x label with the xlab
# argument.
  overlapPlot(a, b, xscale = 10, xlab= "x metrics", rug=T)

Answer: An alternative method for empirical estimation is to use the ROC (Receiver Operating Curve) technology for the estimation. The Youden threshold gives us an empirical estimate for the main point of intersection   (see https://journals.lww.com/epidem/Fulltext/2005/01000/Optimal_Cut_point_and_Its_Corresponding_Youden.11.aspx and https://math.stackexchange.com/questions/2404750/intersection-normal-distributions-and-minimal-decision-error/2435957#2435957).
The Youden threshold is the threshold where the sum of test sensitivity and specificity is maximized and the sum of the error rates (False positive Rate and False Negative Rate) is minimized. The overlap is equal to this minimal sum of error rates.
library(UncertainInterval)
simple_roc2 <- function(ref, test){
  tab = table(test, ref) # head(tab)
  data.frame(threshold=paste('>=',rownames(tab)),
             ref0 = tab[,1],
             ref1 = tab[,2],
             FPR = rev(cumsum(rev(tab[,1])/sum(tab[,1]))), # 1-Sp
             TPR = rev(cumsum(rev(tab[,2])/sum(tab[,2]))), # Se
             row.names=1:nrow(tab))
}
a <- rnorm(10000)
b <- rnorm(10000, 2)
test=c(a,b)
ref=c(rep(0, length(a)), rep(1, length(b)))
# table(test, ref)
res = simple_roc2(ref, test)
res$FNR = 1-res$TPR # 1-Se
pos.optimal.threshold = which.min(res$FPR+res$FNR)
optimal.threshold=row.names(table(test, ref))[pos.optimal.threshold] # Youden threshold
plotMD(ref, test) # library(UncertainInterval) # includes kernel intersection estimate
abline(v=optimal.threshold, col='red')
overlap1(a, b)
(overlap2 = min(res$FPR+res$FNR))

In this case, this non-parametric estimate has a slight tendency of under estimation of the true value. This roc-technique only handles a single (main) point of intersection. It is not dependent on any specific distribution. Make sure that distribution b has the higher values (mean(b) > mean(a)).
Repeatedly eyeballing plots produced by plotMD shows that with 2 * 100 cases the sample overlap differs considerably. Most differences are due to sample differences, but, dependent on the distributions, all methods have conditions in which they do not work properly. Using a gaussian kernel density is sensitive to spikes in the data, which can be underestimated. Kernel density methods are dependent on the fine-tuning parameters given to the density function. The roc-method has no parameters, but it assumes a single point of intersection. Consequentially,  it may overestimate overlap when an additional point of intersection is present (the critical point is the presence of more than one  point of intersection, not variance). This overestimation may be negligible when this secondary point of intersection is at the tails of both distributions.
How to make sense of the different methods and suggestions? Devising a test is most simple when we know the true value of two distributions.
The true value of the overlap for the two normal distributions is easy to calculate. The point of intersection is simply the mean of the two means of the distributions, as they have equal variance: 1. The true overlap is then 0.3173105:
(true.overlap = pnorm(1,2,1)+ 1-pnorm(1,0,1))

See https://stackoverflow.com/questions/16982146/point-of-intersection-2-normal-curves/45184024#45184024 for a general method to calculate the point of intersection for two normal distributions.
In the original problem, there is a mix of a normal and a uniform distribution. The true value is in that case:
    true.value=sum(pmin(diff(pnorm(0:3)),1/3))

Running a simulation can show us which estimation method produces estimates that are closest to the true value:
library(sfsmisc)
overlap1 <- function(a,b){
  lower <- min(c(a, b)) - 1
  upper <- max(c(a, b)) + 1

  # generate kernel densities
  da <- density(a, from=lower, to=upper)
  db <- density(b, from=lower, to=upper)
  d <- data.frame(x=da$x, a=da$y, b=db$y)

  # calculate intersection densities
  d$w <- pmin(d$a, d$b)

  # integrate areas under curves
  total <- integrate.xy(d$x, d$a) + integrate.xy(d$x, d$b)
  intersection <- integrate.xy(d$x, d$w)

  # compute overlap coefficient
  2 * intersection / total
}

library(overlap)
library(scales)
# For explanation of the next function see the answer of S. Venne
overlapEstimates =function(a, b){

  a = data.frame( value = a, Source = "a" )
  b = data.frame( value = b, Source = "b" )
  d = rbind(a, b)

  d$value <- scales::rescale( d$value, to = c(0,2*pi) )

  a <- d[d$Source == "a", 1]
  b <- d[d$Source == "b", 1]

  overlapEst(a, b, kmax = 3, adjust=c(0.8, 1, 4), n.grid = 500)
}

nsim=1000; nobs=100; m1=4; sd1=1; m2=6; sd2=1; poi=5
(true.overlap= 1-pnorm(poi, m1, sd1)+pnorm(poi,m2,sd2))
out=matrix(NA,nrow=nsim,ncol=4)
set.seed(0)
for (i in 1:nsim){
  x <- rnorm( nobs, m1, sd1 )
  y <- rnorm( nobs, m2, sd2 )

  out[i,1] = overlap1(x,y)
  out[i,2] = overlapping::overlap(list( x = x, y = y ))$OV
  out[i,3] = overlapEstimates(x,y)['Dhat4']
  out[i,4] = roc.overlap(x,y)
}
(true.overlap=pnorm(poi,m2,sd2)+1-pnorm(poi,m1,sd1))
colMeans(out-true.overlap) # estimation errors
apply(out, 2, sd) # # sd of the estimation errors
apply(out, 2, range)-true.overlap
par(mfrow=c(2,2))
br = seq(-.33,+.33,by=0.05)
hist(out[,1]-true.overlap, breaks=br, ylim=c(0,500),
     xlim=c(-.33,.33), main='overlap1');
abline(v=0, col='red')
hist(out[,2]-true.overlap, breaks=br, ylim=c(0,500),
     xlim=c(-.33,.33), main='overlapping::overlap')
abline(v=0, col='red')
hist(out[,3]-true.overlap, breaks=br, ylim=c(0,600),
     xlim=c(-.33,.33), main='overlap::overlapEst')
abline(v=0, col='red')
hist(out[,4]-true.overlap, breaks=br, ylim=c(0,500),
     xlim=c(-.33,.33), main="ROC estimate");
abline(v=0, col='red')

In this case, especially the function overlapping::overlap has a tendency of (slight) under-estimation, while overlap1 shows the least estimation error. Estimates that use the density function in one way or another, can produce better or worse results dependent on the parameters given to the density function. The roc method does not have parameters, which can be an advantage.
It is always wise to carefully look at a plot of the overlapping distributions and to devise a relevant testing method whether the technique for overlap estimation works as expected for the kind of data that you have. Especially techniques that systematically produce estimates that are often too low or to high are better not used.
Comment: (1) Your initial analysis concerns *theoretical* distributions, not empirical ones; and it implicitly assumes they have equal variances (as well as being Normal). (2) This post does not appear to answer the question.
Comment: @whuber Thank you for your comment. You are right, the first analysis is additional, and shows a simple way to evaluate the different estimate methods. However, the roc method is an assumption free method for estimating the overlap of two empirical distributions and offers a complete answer on the original question. Not even a gaussian kernel has to be used, as is implicitly applied in the first method (overlap1). You may want to evaluate this method and compare it with the other ...


Busca mongodb em PHP

Question: Estou com dificuldades em retornar os registros por um filtro de data. Tenho o seguinte documento JSON:
{
        "_id": "111090485635468_1098582396886267",
        "1098582396886267_1098592810218559": {
            "fb_id": "1098582396886267_1098592810218559",
            "created_time": {
                "date": "2016-07-28 20:32:06.000000",
                "timezone_type": 1,
                "timezone": "+00:00"
            },
            "from": {
                "picture": {
                    "height": 261,
                    "is_silhouette": false,
                    "url": "https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-xaf1\/v\/t1.0-1\/p148x148\/13179438_970835299696887_7000909019670413123_n.jpg?oh=b4f9ecf8f00f8cb22a02874ec0bc7d96&oe=5815B673&__gda__=1479588815_6a2efe74184209e4b419783f02250c5d",
                    "width": 148
                },
                "name": "Jhonathan Vinicius",
                "id": "1020748971372186"
            },
            "message": "Uma string qualquer...",
            "comment_count": 7,
            "like_count": 11,
            "last_update": "29\/07\/2016 22:36:13"
        }

Preciso filtrar todos os registros entre datas, tentei algo do tipo:
...
  $user = $c_users->find(   ['_id.fb_id.created_time.date' => [ '$gte'=> "2016-01-29 00:00", '$lt' => "2016-07-30 00:00" ] ]);
....

E não me retorna nada. Fico grato quem puder colaborar!
Comment: Se aqui `[ '$gte' => ...` a intenção era passar um valor pela variável, mude para `[ '"{$gte}"' => ... `. O mesmo em `$lt`
Comment: Pode explicar o porque essa estrutura de documento? Ao meu ver `1098582396886267_1098592810218559` poderia ser um array de objetos... esse id seria um post?
Answer: A sua referência ao campo está errada. Ao invés de _id.fb_id.created_time.date, use 1098582396886267_1098592810218559.created_time.date.
$user = $c_users
    ->find([
        '1098582396886267_1098592810218559.created_time.date' => [
            '$gte'=> '2016-01-29 00:00',
            '$lt' => '2016-07-30 00:00',
        ]
    ]);

Comment: Não sei se está correto... _id não é um objeto
Comment: @gmsantos bem notado, corrigi a resposta.
Comment: O problema é que essa query só vai funcionar nesse caso específico. Vejo que o problema é mais em baixo, na forma que está modelado o objeto.

Busca mongodb em PHP


exclude zeros in Numpy quantile calculation of rows of an array

Question: I have a 2D-array with zero values in each row.
[[5, 3, 2, 0, 0, 1, 6, 9, 11, 1, 4, 1],
 [0, 0, 12, 0, 1, 0, 0, 2, 0, 30, 2, 2],
 [120, 2, 10, 3, 0, 0, 2, 7, 9, 5, 0, 0]]

Is there a way to calculate the 0.75 quantile of each row by excluding the zero values in the calculation ?
For example, in the second row, only 6 non-zero values[12,1,2,30,2,2] should be used in the calculation. I tried using np.quantile() but it will includes all zero values in the calculation. It seems that Numpy don't have masked array np.ma version of quantile() also.
Answer: You can replace the zero values with nan and pass the array into np.nanquantile() to compute the quantile of non-nan values
>>> arr = np.array([[5, 3, 2, 0, 0, 1, 6, 9, 11, 1, 4, 1],
                    [0, 0, 12, 0, 1, 0, 0, 2, 0, 30, 2, 2],
                    [120, 2, 10, 3, 0, 0, 2, 7, 9, 5, 0, 0]], dtype='f')

>>> arr[arr==0] = np.nan
>>> arr
[[  5.   3.   2.  nan  nan   1.   6.   9.  11.   1.   4.   1.]
 [ nan  nan  12.  nan   1.  nan  nan   2.  nan  30.   2.   2.]
 [120.   2.  10.   3.  nan  nan   2.   7.   9.   5.  nan  nan]]

>>> arr_quantile75 = np.nanquantile(arr, 0.75, axis=1)  #by row-axis
>>> arr_quantile75
[5.75 9.5  9.25]

np.nanquantile() compute the qth quantile of the data along the specified axis, while ignoring nan values[source]


Como deixar o NodeJS rodando como serviço?

Question: Estava dando uma pesquisada por aqui e encontrei apenas soluções para linux, deixar o servidor rodando pelo dos não é nada seguro, pois a qualquer momento poderá haver uma queda.
A questão é, existe algum método para deixar o NodeJS rodando como serviço? E caso o servidor caia, existe uma forma dele "restartar" automaticamente?
Answer: A solução para isso chama-se : Windows Service
Por padrão, o seu site Node.js ficará executando enquanto a janela do console que iniciou seu site estiver funcionando. Se você fechar ela, ou seu servidor reiniciar, já era, seu site vai ficar fora do ar até que você execute o npm start de novo.
Para que isso não aconteça, você deve instalar seu site como um Windows Service. Para fazer isso, primeiro instale o módulo node-windows globalmente:
npm install -g node-windows

Agora rode o seguinte comando (dentro da pasta do seu projeto) para incluir uma referência deste módulo ao seu projeto:
npm link node-windows

Depois, dentro do seu projeto Node.js (na raiz) crie um arquivo service.js com o seguinte conteúdo:
var Service = require('node-windows').Service;

// Create a new service object
var svc = new Service({
  name:'Nome da sua Aplicação',
  description: 'Apenas uma descrição',
  script: 'C:\\domains\\sitenodejs\\bin\\www'
});

// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
  svc.start();
});

svc.install();

Troque as propriedades name e description de acordo com seu gosto, mas atente à propriedade script nesse código, que deve conter o caminho absoluto até o arquivo JS que inicia sua aplicação. No meu caso, como estou usando express, estou apontando para o arquivo www que fica na pasta bin do projeto (curiosamente ele não possui extensão, mas é um arquivo).
Se você fez tudo corretamente, vá até Ferramentas Administrativas > Serviços (Administrative Tools > Services ou services.msc no Run/Executar do Windows) e seu serviço vai aparecer lá com o name que definiu ali no script, lhe permitindo alterar suas configurações de inicialização, dar Start, Stop, etc.
Caso precise remover esse serviço (para instalar uma versão mais atualizada, por exemplo) rode o comando abaixo no cmd:
SC STOP servicename
SC DELETE servicename

Espero que ajude :)


Correct notation for cross-level interaction

Question: I am wondering if I am using the correct notation for a multilevel model with a cross-level interaction (i.e., a multilevel model with an interaction between level 1 and 2 covariates).
Let $Y_{tj}$ be a test score of the $jth$ student at time $t$. For simplicity, let $gender$ be the only level two (i.e., student level) covariate, and let $months$ be the only level 1 (i.e., repeated observation level) covariate.
Typically in the context of cross-level interactions, which in this example is an interaction between $gender$ and $months$, the interaction is a random effect and can be denoted using the notation below.
(Level-1 model)
$Y_{tj} = \beta_{0j} + \beta_{1j}months + r_{tj}$, where $r_{tj} \tilde{} N(0,\sigma^2)$
(Level-2 model)
$\beta_{0j} = \gamma_{00} + \gamma_{01}gender + u_{0j}$, where $u_{0j} \tilde{} N(0,\tau_{00})$
$\beta_{1j} = \gamma_{10} + \gamma_{11}gender + u_{1j}$,  where $u_{1j} \tilde{} N(0,\tau_{10})$
I am not interested in estimating $\tau_{10}$. Or, put differently, I want the coefficient corresponding to $months$ to be fixed. Given this, is the below notation correct?
$Y_{tj} = \beta_{0j} + \beta_{1}months + r_{tj}$, where $r_{tj} \tilde{} N(0,\sigma^2)$
(Level-2 model)
$\beta_{0j} = \gamma_{00} + \gamma_{01}gender + u_{0j}$, where $u_{0j} \tilde{} N(0,\tau_{00})$
$\beta_{1} = \gamma_{10} + \gamma_{11}gender$
Any comments on my notation are welcome! Though I would also appreciate references to articles estimating such cross-level interactions.
Comment: Interaction terms would have to contain both "month" and "gender", e.g. "gender:month". But you don't seem to include them...
Answer: As @Frank notes in a comment, what you show in your question does not evaluate  an interaction between months and gender. If we follow the Wikipedia naming of levels, Level 1 represents the observations at the individual level.* All "fixed-effect" predictors would be included at that level. Your Level-1 model thus should include both of those predictors individually, plus an interaction term between them if that's what you want.
Level 2 then allows for the intercepts and regression coefficients at Level 1 to differ depending on which group or individual is being observed. If you don't want to allow the coefficient(s) for months to differ among individuals, don't include a corresponding random effect.

*When you call the student-level observations "Level 2" you seem to be defining the levels differently from how Wikipedia does. In Wikipedia, Level 1 represents the individual-level observations. I find the numbering of levels to be more confusing than helpful. For me, the form of a linear mixed model represented by Equation 2 in the R lme4 vignette better captures the joint combination of fixed and random effects in a mixed model.
Comment: @Student100 I keep getting confused by the level numbering, cross-level terminology, and all that. So I try to avoid such things. If you use lme4 and are careful with how you name the random factors, all takes care of itself. You just specify the fixed-effect predictors and choose the random-effects structure you want. Having the level hierarchy well defined does help with setting up Bayesian mixed models.
Comment: Thanks, the lme4 vignette really helped clarify things. Though, according to the article below, my interpretation of what a cross-level covariates is correct.                                                                                Peugh, J. L. (2010). A practical guide to multilevel modeling. Journal of school psychology, 48(1), 85-112.


What is texture, according to classical music theory?

Question: Texture in a sound-design, acoustic, and sound engineering context refers to the harmonic content of a sound, its timbre.
Now that I'm starting to dive into classical music theory, it seems that texture has a different meaning. It seems to refer to movement, pitch, rhythm, voices.
So, what is texture for classical music theory? What is texture in a classical music context?
Comment: @WheatWilliams Added more context to the question.
Comment: have you seen the wiki article?
Comment: Could you give more details about what you are trying to define, or perhaps quote something you have read, in context?
Answer: My music theory book best put the definition of texture as "The way melodic, rhythmic, and harmonic are woven together in a composition."
By this definition the texture of a piece is a combination of all the pieces that make up music, but looking at them all together instead of separately. A composer will use each of these to define their music so the texture tells in general terms what the piece is like without completely diving into rhythm, melody, or harmony.
The relative terms to describe texture in the classical senses are density which can be thin (few voices) or think (many voices) or anywhere in between and range which can be narrow or wide or anywhere in between. There is some grey area in these terms though as some people will see things differently like some people may seem two octaves as a wide range and some may call it a narrow range because of different interpretations.
The more concrete classical textures are monophonic, polyphonic,  homophonic, and homorhythmic which all describe the melody/harmony relationship.


Overwrite a specific VBO action processed message

Question: I am using VBO to perform bulk operations on my view. I have 2 core VBO actions and 2 custom actions.

Publish comment
Unpublish comment
Publish resource
Unpublish resource

When the Apply action button is clicked with none of the grid row is selected, I get this error message.

Select one or more comments to perform the update on.

I would like to rewrite this error message as An attachment has to be selected to perform this action.
How can I achieve this? I am aware of hook_views_bulk_operations_finish(), but it doesn't overwrite a specific action.
Answer: You could try the following:

Define your own ViewsField plugin that extends the CommentBulkForm (that is where that message comes from)

<?php

namespace Drupal\your_module\Plugin\views\field;

use Drupal\views\Plugin\views\field\BulkForm;

/**
 * Defines a custom comment operations bulk form element.
 *
 * @ViewsField("custom_comment_bulk_form")
 */
class CustomCommentBulkForm extends CommentBulkForm {

  /**
   * {@inheritdoc}
   */
  protected function emptySelectedMessage() {
    return $this->t('An attachment has to be selected to perform  this action.');
  }

}

Expose your plugin to views:

function your_module_views_data() {

  $data['comment']['custom_comment_bulk_form'] = [
    'title' => t('Custom comment operations bulk form'),
    'help' => t('Add a form element that lets you run operations on multiple comments, with custom messages.'),
    'field' => [
      'id' => 'custom_comment_bulk_form',
    ],
  ];

  return $data;
}

Finally, overwrite (or override) your (views.view.) Comments configuration so that your existing 'Comment: Comment operations bulk form' field is forced to use your ViewsField plugin. One way to overwrite would be via drush:

drush cset views.view.comment \
  display.default.display_options.fields.comment_bulk_form.field \
  custom_comment_bulk_form

That would eventually allow you to set your own custom message:

Good luck!
Comment: This message is used (and shared) by the various actions available via the CommentBulkForm ViewsField plugin.
Comment: That would need a separate question I believe.
Comment: Got a question. I have created the ViewsField plugin inside my module at this path - mymodule\src]plugin\views\field\custom_comment_bulk_form.php. But this path is nowhere referenced, neither in hook_views_data() nor in the config file. So how will my custom plugin file be read?
Comment: also I get to see "Error: Class 'Drupal\views\Plugin\views\field\BulkForm\CommentBulkForm' not found in include()" error from the plugin. :(
Comment: nm, this worked like a charm!! thanks a lot!
Comment: If i want to update the message of other actions like "delete comment" or "unpublish comment" can i use the above mentioned solution?
Comment: can you add a sample for updating "Delete comment" message? I want to update it mainly from View bulk operations module perspective
Comment: https://drupal.stackexchange.com/questions/308652/alter-action-processing-results-message-for-a-specific-action - I have this almost working except i'm struck with a condition. would you mind checking this question? thanks


adding dynamic data to MPAndroidChart

Question: Can anyone explain with a simple example on how to add the data dynamically to the chart which is already drawn. I tried with the details in the github link to add the data, but couldn't do so. A very short example or link is also fine. Thanks
Answer: You can download the project here https://github.com/PhilJay/MPAndroidChart/archive/master.zip
Open the project, and in MPChartExample, you have the file DynamicalAddingActivity.java.

You need to create the chart:
Add dataSet (your line(s)) with the values (please view the example in
addDataSet() method in MPChartExample project).
After you can do a CountTimerDown that add a new Entry, for the
dataset.

<code>/** each 5 seconds **/
new CountDownTimer(5000, 1000) {

     public void onTick(long millisUntilFinished) {
     }

     public void onFinish() {
        double randomValue = 19.0 + (Math.random() * (21.0 - 19.0));
        int indexOfMyLine = 0;

        Entry newEntry = new Entry((float) randomValue, indexOfMyLine);
     }
</code>
}.start();

adding dynamic data to MPAndroidChart


Determine unknown probabilities from sample of multinomial distribution

Question: Let there be a bag with arbitrarily many balls in k colours (presume we know k). There is a set (but unknown) probability p1, p2... pk of drawing a ball of a given colour. I take a sample of g balls (replacing each ball after drawing it), and get some frequency count of each colour.
Based on this sample, how might I go about:

expressing my confidence/uncertainty that the observed frequencies reflect the underlying probabilities p1, p2... pk (i.e., putting error bars around the relative frequencies observed); and
calculating the expected value of p1, p2... pk.

I understand that this will involve a multinomial distribution, but all examples I can find go the other way round (i.e., determining the probability of making a given draw from a bag with known colour probabilities). This Wikipedia page (https://en.wikipedia.org/wiki/Checking_whether_a_coin_is_fair) provides the relevant formulas for binomial distributions, but I can't see how to extend these to multinomials.
Many thanks for any assistance!
Comment: (1) can be answered with standard Binomial confidence intervals: just focus on one color at a time.  The principal reason to use a multinomial approach, if at all, would be if you want a *simultaneous confidence set* for the $p_k.$  (2) doesn't make sense, because the $p_k$ are parameters: they don't have expected values.  The expectations of the observed relative frequencies equal the $p_k.$  Could you clarify what you are asking?
Comment: @whuber Thanks so much for having a look at this, and you're quite right that I used 'expected value' inappropriately. I think I just wanted to compute the estimator of the true probability  (with error values etc), and that seems easy enough for a binominal distribution. Re: multinomials, I've done some research on simultaneous confidence intervals, and that seems unnecessary for present purposes, so binomials it is. Thanks for the help!
Answer: To answer 1 and 2, use the Dirichlet distribution as the conjugate prior distribution before observing the data $g$.  With no data, assume a uniform prior, which means initializing the distribution parameters as $\alpha_1 = \alpha_2 = \dots = \alpha_k$.  Thus if $p = (p_1, \dots, p_k)$ are the prior probabilities as you denote, then $p \sim Dir(k, \alpha)$, where $\alpha = (\alpha_1, \dots, \alpha_k)$.  If $(x|p) \sim Cat(k,p)$ where $Cat$ is the categorical distribution and $x = (x_1, \dots, x_k)$ is the observed data, then $(p|x, \alpha) \sim Dir(k, \alpha +c)$ where $c = (c_1, \dots, c_k)$ are the number of occurrences in the data in each category.
After obtaining the posterior distribution for $p$ with parameter $\alpha' = \alpha + c$, to express the uncertainty of each $p_i$, you can calculate $Var(p_i)$ which is given as
$$ Var(p_i) = \frac {\alpha'_{i}(\alpha'_{0}-\alpha'_{i})}{{\alpha'_{0}}^{2}(\alpha'_{0}+1)}$$ where $$\alpha'_0 = \sum_{i=1}^k \alpha'_i.$$
To calculate the expected value for each $p_i$, we can use the formula
$$E(p_i) =  \frac{\alpha'_i}{\alpha'_0}.$$
All of this can be seen on the linked Wikipedia page.


Custom submit button text

Question: I have a  classic contact form. I can add for example some custom placeholder like this :
function my_theme_form_contact_message_about_your_project_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    // placeholder
    $form['field_contact_name']['widget'][0]['value']['#placeholder'] = t('Saisir votre nom');

}

It works very well and I can also easily modify wrapper, name, etc.
But for a reason I can't understand, I am not able to modify the text of the submit button.
Here is what I've tried among a lot of things and I think it should be the right thing (as seen on other answers) :
$form['actions']['submit']['#value'] = 'hello world!';

Here is the html of the button :
<button data-drupal-selector="edit-submit" class="button button--primary js-form-submit form-submit btn-primary btn" type="submit" id="edit-submit" name="op" value="Envoyer">Envoyer</button>

I use a custom theme based on Bootstrap theme.
Of course, I can do it with jQuery :
$('#edit-submit').text('lorem ipsum');

But I would like to know how to do it the Drupal way.
EDIT :
The solution is :
form['actions']['submit']['#value'] = 'hello world!';

It works on a clean Drupal install but not on the website I am currently working on.
Answer:
Do you know why it is not working ?

Because it seems to me that you're playing the guessing game.
How about installing the Devel and adding kint($form) to inspect the $form array?
You will see its
$form['actions']['submit']['#value'] = t('Post Comments');

Comment: Before asking, I've already tried `$form['actions']['submit']['#value'] = t('Post Comments');` (as seen on other answer) and it didn't work. I should have mentioned this in my question. I will install Devel.
Comment: Hello you're right. I've already tested your solution before asking. Since, it didn't work, I asked here form more information. So, I've tried on a clean Drupal install and it works. It doesn't work on the website I am currently working on for some specific reason I need to find (I didn't create this web site, only creating a new theme).
Comment: I've found the issue on the website : there is a CustomController where I found code about forms and it was overriding my code : `$build['contact_form']['actions']['submit']['#value'] = 'lorem ipsum';` Sorry to have disturbed you, not easy to work on a website you don't know.

Custom submit button text


Jquery hover without ID

Question: When I move my mouse over one flag, all the other flags switch to hover. But what I want is only the current element switches to hover.

My Js function here under
$(".linkhover").hover(
  function(){
    $(".hover1").hide();
    $(".hover2").show();
  },

  function(){
    $(".hover1").show();
    $(".hover2").hide();
  }
);

Is it a smart way to hover only the current element without using dedicated ID ?
Comment: I think you need **$(this)**... $(this).find('.hover1').hide();
Comment: You can use `this` to select the element that fired the event or `event.target` to select the element targeted by the event. Read more https://www.sitepoint.com/javascript-this-event-handlers/
Comment: You could accomplish this with pure css: https://jsfiddle.net/zgs2xu84/
Answer: Use $(this) to limit the selector to only those found within the current .linkhover element (not tested).
$(".linkhover").hover(
    function(){
        $(this).find(".hover1").hide();
        $(this).find(".hover2").show();
    }, function(){
        $(this).find(".hover1").show();
        $(this).find(".hover2").hide();
    }
);

Answer: The problem is that you are selecting all the .hover1 and .hover2.
Try this change:
$(".linkhover").hover(
    function () {
        $(this).find(".hover1").hide();
        $(this).find(".hover2").show();
    },
    function () {
        $(this).find(".hover1").show();
        $(this).find(".hover2").hide();
    }
);

This way you show/hide the elements inside the .linkhover being hovered.

Jquery hover without ID


Using views_query_alter() hook to dynamically add a OR "where" to a Search API View?

Question: We have a Search API View that we need to dynamically include results to the query that where filtered out.
The use case is that the Search Index View shows a filtered list of node but we have a checkbox to "Include National Listings" where nodes that are marked as "National" should show in the results even if the do not meet the current search or facet filters.
The below code is probably on the right track but it filters all results and produces no output:
 if ($view->id() == 'services_search_index'){

    $query->setGroupOperator('OR');
    $query->setWhereGroup('OR', 1);
    $operator = '=';
    $field = 'field_resource_location_type';
    $value = 'National';
    $query->addWhere(1, $field, $value, $operator);

  }

Here's the Views Query output with the above alter added:
Index: services
Keys: NULL
Conditions:
  field_resource_location_type = 'National'
Sorting: administrative_area ASC, title ASC
Options: array (
    'search_api_view' => 'object (Drupal\\views\\ViewExecutable)',
  )

Answer: You may be overwriting your original "where" by forcing the index of 1. The method setWhereGroup() will return a unique Where group id if you don't specify one.
if ($view->id() == 'services_search_index') {
  // Accept any where group success.
  $query->setGroupOperator('OR');
  // Get a unique where group id.
  $groupId = $query->setWhereGroup('AND');
  $operator = '=';
  $field = 'field_resource_location_type';
  $value = 'National';
  // Add a new condition group for filtering.
  $query->addWhere($groupId, $field, $value, $operator);
}


Descobrir se pessoas não compareceram

Question: tenho uma tabela chamada armários que registro o numero do armario , nome do dono , e tenho outra tabela que registro a entrada dos alunos, porém se alguém que tenha armário falte por 10 dias preciso avisar, eu consigo trazer todo mundo que compareceu no periodo, como fazer para descobrir quem não compareceu ?
SELECT idcad,data_presenca FROM armario
INNER JOIN presenca ON armario.idcad = presenca.id_cad
WHERE data_presenca BETWEEN CURRENT_DATE()-10 AND CURRENT_DATE()

Answer: Pelo que entendi:
SELECT armario.idcad FROM armario
LEFT OUTER JOIN presenca ON armario.idcad = presenca.id_cad
WHERE data_presenca < CURRENT_DATE()-10

Answer: Tente com subselect e not exists
SELECT armario.idcad
FROM armario
Where not exists (select null
                  From presenca
                  Where armario.idcad = presenca.id_cad
                  And data_presenca > CURRENT_DATE()-10)

O select inferior verifica para um "idcad" quem teve presença nos últimos 10 dias , data maior que "hoje" menos 10 , o superior que não está neste grupo "Not" , ou seja os seus faltantes , gente que pelo visto perdeu o armário ... :)
Comment: Funcionou certinho, mas ainda tenho duvidas de como funciona o código, mas já me ajudou bastante e pesquiso aqui mais sobre o assunto, Muito obrigado !
Comment: Editei o texto , veja lá.
Comment: Amigo, apareceu um problema, esse código funcionou certinho até a vida do mês, porém agora ele não está considerando se o pessoal estava presente no mês passado, onde pode estar o problema ?
Comment: Não vejo pq pideria dar errado em viradas de mês. Tem um exemplo ?

Descobrir se pessoas não compareceram


Erro ao executar uma app no Android Studio

Question: Importei um projeto do eclipse para o Android Studio (versão 1.3.2), até ai tudo certo, mas ocorreu umm erro quando tentei executar o programa:

Error:Execution failed for task ':dexDebug'.
   com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_73\bin\java.exe'' finished with non-zero exit value 2

Alguém pode me ajudar a resolver esse problema?
Comment: Para migrar o projeto também precisa ser feito algumas alterações, dê uma olhada: http://pt.stackoverflow.com/questions/47417/erro-ao-importar-projeto-eclipse-para-android-studio
Comment: Já tentou atualizar a versão do Android Studio? a versão corrente é 1.51.
Comment: Sim, já tentei a atualizar, porém continua dando o mesmo erro.
Comment: Eu já criei os arquivos gradles do projeto.
Comment: Eu começaria instalando o Java 7, que é a versão com suporte do Android.
Answer: Tenta o seguinte:
no gradle do teu projeto dentro das dependencies adiciona:
dependencies {
 compile 'com.android.support:multidex:1.0.1'
}

dentro de android faz
android {
 dexOptions {
        preDexLibraries = false
        incremental true
        javaMaxHeapSize "4g"
    }

 defaultConfig {
        multiDexEnabled true
    }
}

Depois volta a sincronizar o gradle seguido de um clean ao projeto.


What is the cheapest hardware synthesizer, or where are schematics for DIY?

Question: I have been looking into hardware synthesizers a lot, but have no where NEAR enough money to buy the MIDI to CV (already have a MIDI keyboard I got a while back ago), VCO, VCF/VCA, and then stuff for my own effects (like mixers, delay, reverb, echo, sequencers, etc.). Can someone give me (and I don't mean as an opinion, I want minimal or better to make SOME sound but cheaply) some pointers to cheap, functional synth modules I can purchase?
Also, I would be glad if someone commented some links to schematics for DIY synths (already found some VERY minimal oscillators online, but nothing more) as I am into electronics and would be glad to do it myself, also.
Comment: Anything against softsynths? They can be had as cheaply as possible, i.e., for free, if you take a bit of time with something like PureData or CSound. (I'm leaving aside VSTs and just talking about programmes with which you can muck about at a fairly low level _without_ having to code oscillators, etc.) Then all you need is a MIDI port for your system (if you haven't already got one), and those are cheaper than _any_ DIY analogue synth. If that doesn't suit, what is your budget?
Comment: Can you re-word this so it's more on-topic? If you can take out asking for specific products and perhaps ask where to look to get started in hardware synthesizers?
Answer: Don't think of it as "I already have the keyboard", because you'll be reducing your options. The big majority of synths come with keyboard, and few have a keyboardless model. I'll include keyboardless models here, but don't get too fixated, you might find another option to be better.
First note that you don't need a MIDI to CV module to control hardware synths, since most are MIDI compatible. Only specific modular systems need MIDI to CV conversion, but if you don't have the money for a MIDI to CV module chances are that you don't have the money for the full modular system.
The Portable-11 from synthesizers.com, for example, is at 1,700 USD, and I think it's the cheapest good quality modular you can get (it includes the MIDI to CV convertor). The MIDI to CV alone is around 260 USD.
But you don't have to go modular. There are many non-modular analog synthesizers out there that are MIDI compatible. We can look at some quality budget models like:

Arturia MicroBrute 300 USD.
Dave Smith Mofo (keyboardless) 400 USD
Moog Minitaur (keyboardless) 500 USD
Novation Bass Station II 500 USD.
Akai Timbre Wolf (4 note polyphony) 500 USD.
Pittsburgh Modular System 10.1 (keyboardless, semi-modular, includes MIDI to CV)

Polyphony is not common in analog synths, and when found it is very limited and probably expensive. The timbre wolf above has 4 voice polyphony, the other are monophonic.
If you want more polyphony, and other extras, you want to check virtual analog synths, which are digital and emulate the analog quality. The cheapest quality options are:

Waldorf Rocket (monophonic, keyboardless) 300 USD
Korg microKORG (4 note polyphony) 400 USD
Waldorf Blofeld (25 note polyphony, keyboardless) 500 USD
Novation MiniNova (18 note polyphony) 500 USD
Roland JD-Xi (128 note polyphony) 500 USD
Roland System 1 (polyphony varies by type) 600 USD

Virtual analog synths often include extras like effects, sequencers, vocoder, more oscillators, more modulators and modulation capabilities, more polyphony and voices, etc. They might not be able to perfectly emulate some analog dynamics though (filters can sound very different). So, if you are going for a very specific analog sound, make sure that specific model of virtual analog synth can produce it before buying it.
In general, it's a good idea to test and listen to the synth and make sure you love its sound before buying it.
And regarding schematics, if you want to go the DIY route, you should take a look at this book:

Make: Analog Synthesizers

It is very accessible and easy to follow, teaches you to build a basic subtractive synth: LFO, VCA, VCF, VCO, LFO, etc. It should be the less expensive option, if you can get a good price for the components, but it's also the less flexible model. The experience of building one is more than worth it if you are into this kind of stuff.
You might also want to consider going software synth. There are many excellent software synths and synthesis environments, including virtual analog software synths, many of which are free. Can't get cheaper than that!
You already have a MIDI keyboard, you already have a computer, so you are already good to go. You can buy a MIDI control surface to control the synth, if mouse and keyboard is not your thing.
There are countless software synths out there, this should be a good starting point:

Musictech top free software synths list.
GTPS top free software synths list.
Tutsplus top free software synths list.
Comment: I do like software to make music, but my nerdy, electronic-tinkering-loving self loves hardware and has decided to build his own. It is WAY cheaper, and I learn more and have some fun while building them.
Comment: @CelloCoder It's a very good idea, you'll learn a lot about synthesis, in a depth that is not possible in other way. Who knows, maybe you become the next Moog!
Comment: I think I will buy that Make book soon, and your answer told me the most and helped me with different options. Thanks!
Answer: It's probably hard to get anything cheaper than the Korg Monotron series. The Korg Monotribe is a bit more expensive, but is more full featured. Does not come store equipped with MIDI, but is prepared internally and can be modded for MIDI.
Comment: What I mean, though, is I already have a MIDI keyboard but I want to find cheap yet functional modules that I can patch together. I want to at least be able to build a basic patch that makes some noise when I press a key...even if it is monophonic (as long as I don't spend so much I wish I would have made it polyphonic). I am thinking about just building my own synths from scratch with electronics.
Comment: @CelloCoder: For this setting, your option from my answer is modding the Monotribe.
Answer: Try searching for CGS Synth (Ken Stone's modular synthesizer), Music From Outer Space (Ray Wilson) and general searches like "Modular Synth DIY" for schematics.
Note, I think a MIDI to CV unit might be quite a difficult project - though note I've never built one.
Comment: I was thinking the same of the MIDI to CV. I already saw CGS Synth, and am getting ready to order the parts I don't already have (Like certain chips, certain capacitors I may not have, PCBs, etc.). I may have to buy a MIDI to CV, though.
Answer: Another neat little option if you already have the midi controller is the MeeBlip anode.  It is open source hardware, too, so you could (in theory) just get the schematics and build it yourself.  It's monophonic and super basic, but is tiny and fun.
Answer: Here you can find some from my collection of modules schematics: https://ru.pinterest.com/deliandiver/all-about-modular-synth-schematics/


Form Submit Issue

Question: Below is my form submit statement for my site.  I know that the query works by it self however it does not seem to be setting the variable correctly.  Does anybody see why this would not work, or am I going about this the wrong way?  Basically my module uploads a file and then on submit this function query's the DB for the upload path and needs to set that value to be a drupal variable.  Any Ideas?
function background_audio_form_submit($form, $form_state) {
$result = db_query("SELECT uri
                   FROM `file_managed`
                   WHERE `filemime` = 'audio/mpeg'
                   LIMIT 1");

return $result;

variable_set('background_audio_upload_path', $result-->uri);

}

Answer: A couple of things:

You're returning the $result variable from the function before calling variable_set so that bit of code will never run.
You have a slight syntax error in your variable set code, $result-->uri (you should change it to: $result->uri)

This code should work:
function background_audio_form_submit($form, $form_state) {
  $result = db_query("SELECT uri
               FROM `file_managed`
               WHERE `filemime` = 'audio/mpeg'
               LIMIT 1");

  variable_set('background_audio_upload_path', $result->uri);
}

The return from a form submit function is never used in Drupal so there's no need to perform the return at all.
EDIT
Just one other thing, if you're uploading the file in a custom form using a managed_file element then you'll have the file ID of the uploaded file available in your submit function. You could then use file_load() to get the file object and URI without having to use a custom query. Assuming your element is defined as $form['audio_file'] the following should work:
function background_audio_form_submit($form, $form_state) {
  $fid = $form_state['values']['audio_file'];

  $file = file_load($fid);

  variable_set('background_audio_upload_path', $file->uri);
}

Form Submit Issue


Can not post on facebook wall other than Me ios

Question: i have integerated facebook sdk latest, i create App on developer with my acoount ABC ....and use Facebook App id . All is fine if i loging in my Ios app with my ABC account to loging with facebook.it post on my wall successfully .
But if i use any other Account to loging with facebook . i loged in successfully but when i post i got error .
**I am getting this erro**r
Error Domain=com.facebook.sdk Code=5 "The operation couldn't be completed. (com.facebook.sdk error 5.)" UserInfo=0x22689930 {com.facebook.sdk:HTTPStatusCode=403, com.facebook.sdk:ParsedJSONResponseKey={
    body =     {
        error =         {
            code = 200;
            message = "(#200) The user hasn't authorized the application to perform this action";
            type = OAuthException;
        };
    };
    code = 403;
}, com.facebook.sdk:ErrorSessionKey=, expirationDate: 2014-08-15 08:56:01 +0000, refreshDate: 2014-06-16 10:10:43 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(
    status,
    permission
)>}
For Posting
-(void) post:(NSString *)postString
{
<code>if (FBSession.activeSession.state == FBSessionStateOpen|| FBSession.activeSession.state == FBSessionStateOpenTokenExtended)
{
    NSArray *permissionsNeeded = @[@"publish_stream"];
    [FBRequestConnection startWithGraphPath:@"/me/permissions"
                          completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                              if (!error){
                                  NSDictionary *currentPermissions= [(NSArray *)[result data] objectAtIndex:0];
                                  NSMutableArray *requestPermissions = [[NSMutableArray alloc] initWithArray:@[]];
                                  for (NSString *permission in permissionsNeeded){
                                      if (![currentPermissions objectForKey:permission]){
                                          [requestPermissions addObject:permission];
                                      }
                                  }

                                  if ([requestPermissions count] < 1){
                                      [FBSession.activeSession requestNewPublishPermissions:requestPermissions
                                                                            defaultAudience:FBSessionDefaultAudienceFriends
                                                                          completionHandler:^(FBSession *session, NSError *error) {
                                                                              if (!error) {
                                                                                [self makeRequestToUpdateStatus:postString];
                                                                              } else {
                                                                                NSLog(@"%@",[error description]);
                                                                              }
                                                                          }];
                                  } else {
                                      [self makeRequestToUpdateStatus:postString];
                                  }

                              } else {

                                   NSLog(@"%@",[error description]);
                              }
                          }];
}
else
{

}
</code>
}
For Login
-(void)loginToFacebook
{
    NSLog(@"the facebook login called ");
    if (!(FBSession.activeSession.state == FBSessionStateOpen  || FBSession.activeSession.state == FBSessionStateOpenTokenExtended)){
         NSArray *permissions = [[NSArray alloc] initWithObjects:
                                @"publish_stream",
                                nil];
<code>    [FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {

    dispatch_async( dispatch_get_main_queue(), ^{
        [self sessionStateChanged:session
                            state:status
                            error:error];
         });

    }];
 }
</code>
else
    {
    }
}
Comment: Can you post some of your code?
Answer: Hm, the message indicates you do not request the correct permissions from the user.
Perhaps you requested more before, and therefore it still works with your ABC account, because you 'authorized' the app already with that account at that time. So Facebook still sees that ABC authorized the app to post on the wall.
Edit: added the instructions below in response to your comments:
You can find a list with permissions you can ask for here. Note that with API v 2.0 if you ask for more than a few basic permissions (and posting on a wall is not such a basic permission) you will need to have Facebook 'approve' your app (unless you started your app before April 2014, in which case you can probably keep using v1.0 and not need approval until April 2015).
De-authorizing your own app can be done by logging in as that user, go to settings (menu top right), choose applications at the left and click the 'x' next to your application.
Comment: i think so . when i login with other user it display u have allready autherized. what shuld i do now ?
Comment: Well, you could de-authorize your app (you can do this via the Facebook website), then re-authorize when you have adjusted your code to ask for the correct permissions
Comment: i did not get your point . facebook website means from facebook developer portal of from from device plaese clear . and i just want to share on user wall so what will be the correct permission
Answer: Steps
<code> https://developers.facebook.com/apps
 Select Your App then follow steps.

 in **Settings** -> Basic
  1. add contact Email
  2. Bundle id
  3. Url Scheme Suffix (like Your app name)

 Then Save

 In **Status & Review**

 1.Do you want to make this app and all its live features available to the general public?
  Set Yes

 May be Useful
</code>


Any modification of a .less file breaks Flask app, resulting in Program file not found: lessc

Question: I am having an issue where a Flask app using flask_assets can't find lessc after a modify a certain .less file, and even changing it back to the original does not help.
I have been trying to use this tutorial to learn about using Blueprints to organize a Flask application: https://hackersandslackers.com/flask-blueprints/
app structure
├── application
│   ├── assets.py
│   ├── home
│   │   ├── home.py
│   │   ├── __pycache__
│   │   │   └── home.cpython-38.pyc
│   │   ├── static
│   │   │   └── less
│   │   │       ├── home.less
│   │   │       └── variables.less
│   │   └── templates
│   │       └── index.jinja2
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── assets.cpython-38.pyc
│   │   └── __init__.cpython-38.pyc
│   ├── static
│   │   ├── dist
│   │   │   └── css
│   │   │       ├── home.css
│   │   │       ├── products.css
│   │   │       ├── profile.css
│   │   │       └── style.css
│   │   ├── img
│   │   │   ├── avatar.png
│   │   │   ├── favicon.png
│   │   │   └── logo.png
│   │   └── src
│   │       └── less
│   │           ├── nav.less
│   │           ├── style.less
│   │           └── variables.less
│   └── templates
│       ├── analytics.jinja2
│       ├── layout.jinja2
│       └── navigation.jinja2
└── wsgi.py

init.py
"""Initialize Flask app."""
from flask import Flask
from flask_assets import Environment

def create_app():
    """Create Flask application."""
    app = Flask(__name__, instance_relative_config=False)
    app.config.from_object('config.Config')
    assets = Environment()
    assets.init_app(app)

    with app.app_context():
        # Import parts of our application
        from .home import home
        from .assets import compile_static_assets

        # Register Blueprints
        app.register_blueprint(home.home_bp)

        # Compile static assets
        compile_static_assets(assets)

        return app
        ```

        assets.py
        ```
        from flask import current_app as app
from flask_assets import Bundle

def compile_static_assets(assets):
    assets.auto_build = True
    assets.debug = False
    common_less_bundle = Bundle('src/less/*.less',
                                filters='less,cssmin',
                                output='dist/css/style.css',
                                extra={'rel': 'stylesheet/less'})
    home_less_bundle = Bundle('home_bp/less/home.less',
                              filters='less,cssmin',
                              output='dist/css/home.css',
                              extra={'rel': 'stylesheet/less'})

    assets.register('common_less_bundle', common_less_bundle)
    assets.register('home_less_bundle', home_less_bundle)
    if app.config['ENV'] == 'development':  # Only rebuild bundles in development
        common_less_bundle.build()
        home_less_bundle.build()
    return assets

home.py
"""General page routes."""
from flask import Blueprint, render_template
from flask import current_app as app

# Blueprint Configuration
home_bp = Blueprint('home_bp', __name__,
                    template_folder='templates',
                    static_folder='static')

@home_bp.route('/', methods=['GET'])
def home():
    """Homepage."""
    products ="example"
    return render_template('index.jinja2',
                           title='Flask Blueprint Demo',
                           subtitle='Demonstration of Flask blueprints in action.',
                           template='home-template',
                           products=products)

and the problem file, home.less
@import 'variables.less';

.home-template {

  &.page {
    .products {
      display: none !important;
    }
  }

  .container {
    .resource-links {
      margin-top: 10px;

      .resource-link {
        margin: 4px 0;
        color: #8a91a7;
        line-height: 1;
      }
    }

    .products {
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      margin-top: 30px;

      .product-preview {
        padding: 2%;
        box-shadow: 0 0 5px rgba(65, 67, 144, 0.15);
        max-width: 28%;
        width: 30%;
        background: white;
        margin-bottom: 20px;
        display: block;
        text-align: center;
        transition: @transition;

        &:hover {
          background: #5dbad7;
          color: white !important;
          opacity: 1;

          * {
            color: white !important;
          }
        }

        .product-image {
          height: 110px;
          margin: 0 auto 20px;
          display: block;
          @media (max-width: 600px) {
            width: 90%;
            height: unset;
          }
        }

        .name {
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          display: -webkit-box;
          width: -webkit-fill-available;
          width: -moz-available;
          width: stretch;
          overflow: hidden;
          text-overflow: ellipsis;
          font-weight: 500;
          font-size: .9em;
          height: 42px;
        }

        .price {
          color: #5f6988;
          margin-top: 5px;
          font-size: 1.1em;
          font-weight: 600;
        }
      }
    }
  }

  h2 {
    margin-bottom: 0 !important;
  }
}

When home.less is freshly pasted from the git download to my simplified version, the app runs as expected.
$ python3 wsgi.py
 * Serving Flask app "application" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:5001/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 213-702-582
127.0.0.1 - - [21/May/2020 14:26:01] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [21/May/2020 14:26:02] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [21/May/2020 14:26:02] "GET /static/dist/css/home.css?99706b81 HTTP/1.1" 304 -
127.0.0.1 - - [21/May/2020 14:26:02] "GET /static/img/logo.png HTTP/1.1" 304 -
127.0.0.1 - - [21/May/2020 14:26:02] "GET /favicon.ico HTTP/1.1" 404 -

Now, what really wierds me out, is that if I make any modification to home.less, even just adding a space, saving, removing the space, and then saving again, the less filter cannot be found:
 * Serving Flask app "application" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:5001/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 213-702-582
127.0.0.1 - - [21/May/2020 14:28:09] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/home/james/.local/lib/python3.8/site-packages/webassets/filter/__init__.py", line 510, in subprocess
    proc = subprocess.Popen(
  File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'lessc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/james/Downloads/flask-blueprint-tutorial-master_reduced/application/home/home.py", line 15, in home
    return render_template('index.jinja2',
  File "/usr/lib/python3.8/site-packages/flask/templating.py", line 137, in render_template
    return _render(
  File "/usr/lib/python3.8/site-packages/flask/templating.py", line 120, in _render
    rv = template.render(context)
  File "/usr/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/usr/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/usr/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "/home/james/Downloads/flask-blueprint-tutorial-master_reduced/application/home/templates/index.jinja2", line 1, in top-level template code
    {% extends "layout.jinja2" %}
  File "/home/james/Downloads/flask-blueprint-tutorial-master_reduced/application/templates/layout.jinja2", line 9, in top-level template code
    {% block pagestyles %}{% endblock %}
  File "/home/james/Downloads/flask-blueprint-tutorial-master_reduced/application/home/templates/index.jinja2", line 4, in block "pagestyles"
    {% assets "home_less_bundle" %}
  File "/home/james/.local/lib/python3.8/site-packages/webassets/ext/jinja2.py", line 187, in _render_assets
    urls = bundle.urls(calculate_sri=True)
  File "/home/james/.local/lib/python3.8/site-packages/webassets/bundle.py", line 833, in urls
    urls.extend(bundle._urls(new_ctx, extra_filters, *args, **kwargs))
  File "/home/james/.local/lib/python3.8/site-packages/webassets/bundle.py", line 767, in _urls
    self._build(ctx, extra_filters=extra_filters, force=False,
  File "/home/james/.local/lib/python3.8/site-packages/webassets/bundle.py", line 618, in _build
    hunk = self._merge_and_apply(
  File "/home/james/.local/lib/python3.8/site-packages/webassets/bundle.py", line 543, in _merge_and_apply
    hunk = filtertool.apply(hunk, filters_to_run, 'input',
  File "/home/james/.local/lib/python3.8/site-packages/webassets/merge.py", line 280, in apply
    return self._wrap_cache(key, func)
  File "/home/james/.local/lib/python3.8/site-packages/webassets/merge.py", line 222, in _wrap_cache
    content = func().getvalue()
  File "/home/james/.local/lib/python3.8/site-packages/webassets/merge.py", line 255, in func
    getattr(filter, type)(data, out, **kwargs_final)
  File "/home/james/.local/lib/python3.8/site-packages/webassets/filter/less.py", line 139, in input
    self._apply_less(_in, out, source_path)
  File "/home/james/.local/lib/python3.8/site-packages/webassets/filter/less.py", line 131, in _apply_less
    self.subprocess(args, out, in_)
  File "/home/james/.local/lib/python3.8/site-packages/webassets/filter/__init__.py", line 520, in subprocess
    raise FilterError('Program file not found: %s.' % argv[0])
webassets.exceptions.FilterError: Program file not found: lessc.
127.0.0.1 - - [21/May/2020 14:28:10] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/home/james/.local/lib/python3.8/site-packages/webassets/filter/__init__.py", line 510, in subprocess
    proc = subprocess.Popen(
  File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'lessc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/james/Downloads/flask-blueprint-tutorial-master_reduced/application/home/home.py", line 15, in home
    return render_template('index.jinja2',
  File "/usr/lib/python3.8/site-packages/flask/templating.py", line 137, in render_template
    return _render(
  File "/usr/lib/python3.8/site-packages/flask/templating.py", line 120, in _render
    rv = template.render(context)
  File "/usr/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/usr/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/usr/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "/home/james/Downloads/flask-blueprint-tutorial-master_reduced/application/home/templates/index.jinja2", line 1, in top-level template code
    {% extends "layout.jinja2" %}
  File "/home/james/Downloads/flask-blueprint-tutorial-master_reduced/application/templates/layout.jinja2", line 9, in top-level template code
    {% block pagestyles %}{% endblock %}
  File "/home/james/Downloads/flask-blueprint-tutorial-master_reduced/application/home/templates/index.jinja2", line 4, in block "pagestyles"
    {% assets "home_less_bundle" %}
  File "/home/james/.local/lib/python3.8/site-packages/webassets/ext/jinja2.py", line 187, in _render_assets
    urls = bundle.urls(calculate_sri=True)
  File "/home/james/.local/lib/python3.8/site-packages/webassets/bundle.py", line 833, in urls
    urls.extend(bundle._urls(new_ctx, extra_filters, *args, **kwargs))
  File "/home/james/.local/lib/python3.8/site-packages/webassets/bundle.py", line 767, in _urls
    self._build(ctx, extra_filters=extra_filters, force=False,
  File "/home/james/.local/lib/python3.8/site-packages/webassets/bundle.py", line 618, in _build
    hunk = self._merge_and_apply(
  File "/home/james/.local/lib/python3.8/site-packages/webassets/bundle.py", line 543, in _merge_and_apply
    hunk = filtertool.apply(hunk, filters_to_run, 'input',
  File "/home/james/.local/lib/python3.8/site-packages/webassets/merge.py", line 280, in apply
    return self._wrap_cache(key, func)
  File "/home/james/.local/lib/python3.8/site-packages/webassets/merge.py", line 222, in _wrap_cache
    content = func().getvalue()
  File "/home/james/.local/lib/python3.8/site-packages/webassets/merge.py", line 255, in func
    getattr(filter, type)(data, out, **kwargs_final)
  File "/home/james/.local/lib/python3.8/site-packages/webassets/filter/less.py", line 139, in input
    self._apply_less(_in, out, source_path)
  File "/home/james/.local/lib/python3.8/site-packages/webassets/filter/less.py", line 131, in _apply_less
    self.subprocess(args, out, in_)
  File "/home/james/.local/lib/python3.8/site-packages/webassets/filter/__init__.py", line 520, in subprocess
    raise FilterError('Program file not found: %s.' % argv[0])
webassets.exceptions.FilterError: Program file not found: lessc.

What could be going on here?
At first I thought it might be a cache issue, but deleting the __pycache__ did not help.
Comment: I would recommend reading the docs for https://webassets.readthedocs.io/en/latest/ as that looks like whats trying to compile the less files
Comment: But that shouldn't change no matter what I do to with the python and css files, right? I cannot understand why re-saving a file would make the difference between lessc being found or not.

Is it possible that in the case where it works, lessc isn't even being called?
Comment: you need to install lessc so you can compile your less files it looks like
Comment: Then why would it have worked the first time around? Why would adding and then removing a space from the .less file result in lessc not being found (or why did it work without lessc before)?
Comment: I dont have any of those answers... maybe initially it used a different method to build less -> css, or maybe initially the css is really there(but your ide or something is hiding it and showing you the less file only) ... are you using babel to translate less to css directly in the html? or are you including css files? but the error message clearly states it cannot find lessc (which it uses to compile less -> css)
Comment: Thanks. I am just including css files. Do you know how I can get the app to print the path it is looking for lessc on each time it is called?
Comment: its looking in `%PATH%` or `$PATH`  (depending on os)  you can probably do `npm install -g lessc`
Answer: OK, well, I found a solution, but I really don't understand why it works.
If I change assets.py to explicitly create the environment, trivial modifications to home.less no longer result in the inability to find lessc.
New assets.py
from flask import Flask, current_app as app
from flask_assets import Environment, Bundle

def compile_static_assets(assets):
    app = Flask(__name__)
    assets = Environment(app)
    assets.auto_build = True
    assets.debug = False
    common_less_bundle = Bundle('src/less/*.less',
                                filters='less,cssmin',
                                output='dist/css/style.css',
                                extra={'rel': 'stylesheet/less'})
    home_less_bundle = Bundle('home_bp/less/home.less',
                              filters='less,cssmin',
                              output='dist/css/home.css',
                              extra={'rel': 'stylesheet/less'})

    assets.register('common_less_bundle', common_less_bundle)
    assets.register('home_less_bundle', home_less_bundle)
    if app.config['ENV'] == 'development':  # Only rebuild bundles in development
        common_less_bundle.build()
        home_less_bundle.build()
    return assets

It makes sense to me that instantiating the environment with the right packages loaded is necessary for the less filter to work. But I am still mystified by the fact that this only became a problem after adding (and then removing) a single space from less.css.
I think I must not understand the pipeline of how flask_assets applies filters. I've taken a gander at the docs, but it is not obvious to me.


How to solve problems with AppxPackaging.dll (Windows App Certification Kit)?

Question: We receive the follow error message on building an UWP application.

Task 'ValidateAppxManifest' failed. Retrieving the COM class factory
  for component with CLSID {5842A140-FF9F-4166-8F5C-62F5B7B0C781} failed
  due to the following error: 8007045a A dynamic link library (DLL)
  initialization routine failed. (Exception from HRESULT: 0x8007045A).

{5842A140-FF9F-4166-8F5C-62F5B7B0C781} pointed to AppxPackaging.dll. The registry HKEY_CLASSES_ROOT\CLSID\{5842a140-ff9f-4166-8f5c-62f5b7b0c781}\InProcServer32 exists.
The build system is a docker with Windows Server Core and Visual Studio 2017.
How can I receive more information over the underlying problem?
Which components must be installed that the "Windows App Certification Kit" is work?
Answer: The AppxPackaging is part of the Windows Kits installation of the SDK. The error hints at a missing dependency.
We used procmon (eg. choco install procmon) to try to find out which dependency that was. You have to set a filter in Path contains Appx and run the build job.
Note: if the build job runs in a Docker Container as you described you have to run procmon on the host, not the container.
The process list filled up with a lot of information up to the point the AppxPackaging.dll is loaded. It then stated, that a AppxSip.dll was looked up at the Path destinations, but was not found (Result: NAME NOT FOUND). So we checked the system for this dll.
We did find a corresponding file in the Windows Kits subfolder C:\Program Files (x86)\Windows Kits\10\bin\10.0.17134.0\x86 and added this path the the $env:Path environment. Then it worked out.


Make a time series data in R

Question: I have a numeric variable and a date which includes just year and month, I was wondering how I can have a time series data.
A<-c(1,2,3,4,55,66,7,88,88,99,99,55,56,6,7,7,8)
Date<-c("1999-01","1999-02","1999-01","1999-10","1999-10","1999-01","1999-01","1999-11","1999-11","1999-01","1999-05","1999-03","1999-12","1999-4","1999-01","1999-12","1999-2")
Data<-data.frame(A,Date)

Answer: May be we could use read.zoo
library(zoo)
read.zoo(Data, FUN = as.yearmon, format = "%Y-%m", index.column = 2)

Make a time series data in R


How to get web server error logging output from phpunit functional tests?

Question: The 500 errors generated during phpunit tests aren't showing up in the Apache error logs. Where are those errors logged?
Comment: It's basically wherever your PHP instance is configured to log errors - https://stackoverflow.com/questions/12834583/where-can-i-find-error-log-files-for-php has some useful info for locating and setting the location
Answer: I found out what's going on. Instead of letting Apache log the 500 error, phpunit is returning the error message as HTML markup to the call to $this->drupalGet($path).