Who Are The Bayesians?

Question: As one becomes interested in statistics, the dichotomy "Frequentist" vs. "Bayesian" soon becomes commonplace (and who hasn't read Nate Silver's The Signal and the Noise, anyway?). In talks and introductory courses, the point of view is overwhelmingly frequentist (MLE, $p$ values), but there tends to be a tiny fraction of time dedicated to admire Bayes formula and touch upon the idea of a prior distribution, usually tangentially.
The tone employed to discuss Bayesian statistics oscillates between respect for its conceptual underpinnings, and a hint of skepticism regarding the chasm between lofty objectives, and arbitrariness in the selection of the prior distribution, or eventual use of frequentist maths after all.
Sentences such as "if you are a hard-core Bayesian..." abound.
The question is, Who are the Bayesians today? Are they some select academic institutions where you know that if you go there you will become a Bayesian? If so, are they specially sought after? Are we referring to just a few respected statisticians and mathematicians, and if so who are they?
Do they even exist as such, these pure "Bayesians"? Would they happily accept the label? Is it always a flattering distinction? Are they mathematicians with peculiar slides in meetings, deprived of any $p$ values and confidence intervals, easily spotted on the brochure?
How much of a niche is being a "Bayesian"? Are we referring to a minority of statisticians?
Or is current Bayesian-ism equated with machine learning applications?
... Or even more likely, is Bayesian statistics not so much a branch of statistics, but rather an epistemological movement that transcends the ambit of probability calculations into a philosophy of science? In this regard, all scientists would be Bayesian at heart... but there would be no such thing as a pure Bayesian statistician impermeable to frequentist techniques (or contradictions).
Comment: I would also like to know! My feeling is that "Bayesians" is often a term used by those that doesn't like that type of statistics. I'm a huge fan of Bayesian data analysis, but I don't consider myself a *Bayesian*, in the same way I don't consider myself a *Matrix-algebraist*.
Comment: @Count Some of the literature with which I am familiar (in risk communication and related psychology--Kahneman, Slovic, Tersky, *et al.*) shows that people do not use mathematically correct procedures to reason about probabilities. For a popular account of some of this, see Kahneman's *Thinking, Fast and Slow.* The logical implication of your comment, then, is that humans are not "complex lifeforms."
Comment: The apparent division is, in some ways, imaginary. Sometimes people just like to fall into a them-and-us approach. I get the impression that after a few years nobody cares any more. The "philosophies" are not contradictory of each other. Frequentists do not have a magic recipe for finding good estimators. But given two estimators, they might have a criterion for deciding which estimator is best. (Even then, two frequentists might disagree with each other and use different criteria. But I digress). ...
Comment: Just to note-- MLEs are based too on likelihoodist methods and not purely frequentist.
Comment: ... (continued)  A hardcore frequentist, in search of a class of estimators from which to select the "best" one, might reasonably decide to consider the class of all Bayesian estimators (i.e. priors) and therefore use the estimator (prior) that is best according their "objective" criterion. Is such a person frequentist (because of how they select the best estimator), or Bayesian (because they consider only Bayesian estimators as candidates)? Does anyone care? I guess many such people call themselves Bayesian, even though they may be wrong in their self-assignment.
Comment: All complex lifeforms are Bayesians, the brain has evolved to implement algorithms based on Bayesian reasoning.
Comment: @CountIblis, how do you know this? I haven't seen research that proves it
Comment: @whuber We need to distinguish between "reasoning" and acting e.g. based on intuition, but which can also be based on reasoning. If people act on the basis of cognitive biases, then we need to consider where those cognitive biases came from, presumably they were programmed into our brains due to natural selection. So, you could say that in such cases the prior used assigns probabilities to certain hypothesis that are almost equal to 1, so that additional evidence makes little impact.
Comment: Related: *[What is Bayes' theorem all about?](http://stats.stackexchange.com/questions/672)* - "The significance of Bayes theorem is largely due to its proper use being a point of contention between schools of thought on probability. ... Bayesian (... probability as being subjective degrees of belief) Bayes' theorem provides the cornerstone for theory testing, theory selection ..., by plugging their subjective probability judgments into the equation, and running with it. To a frequentist (that interprets probability as limiting relative frequencies), this use of Bayes' theorem is an abuse..."
Comment: FWIW, I think essentially everyone in machine learning is a Bayesian, in practice if not in terms of what they would call themselves.
Comment: Here is a community that calls themselves Bayesians (also rationalists): [LessWrong](http://lesswrong.com/)
Comment: I would add Probabilistic Graphical Models to this list.
Comment: See [this related question](http://stats.stackexchange.com/questions/20558/where-did-the-frequentist-bayesian-debate-go)  on the whereabouts of the Frequentist-Bayesian debate.
Comment: A friend of mine was wearing a t-shirt "Crazy Rich Bayesians," which is a joke referencing a popular movie. Another buddy of mine (not a statistician) thought that it was referring to Bay area Asians.
Answer: I'm going to take your questions in order:

The question is, Who are the Bayesians today?

Anybody who does Bayesian data analysis and self-identifies as "Bayesian". Just like a programmer is someone who programs and self-identifies as a "programmer". A slight difference is that for historical reasons Bayesian has ideological connotations, because of the often heated argument between proponents of "frequentist" interpretations of probability and proponents of "Bayesian" interpretations of probability.

Are they some select academic institutions, where you know that if you go there you will become a Bayesian?

No, just like other parts of statistics you just need a good book (and perhaps a good teacher).

If so, are they specially sought after?

Bayesian data analysis is a very useful tool when doing statistical modeling, which I imagine is a pretty sought-after skill, (even if companies perhaps  aren't specifically looking for "Bayesians").

Are we referring to just a few respected statisticians and mathematicians, and if so who are they?

There are many respected statisticians that I believe would call themselves Bayesians, but those are not the Bayesians.

Do they even exist as such, these pure "Bayesians"?

That's a bit like asking "Do these pure programmers exist"? There is an amusing article called 46656 Varieties of Bayesians, and sure there is a healthy argument among "Bayesians" regarding many foundational issues. Just like programmers can argue over the merits of different programming techniques. (BTW, pure programmers program in Haskell).

Would they happily accept the label?

Some do, some don't. When I discovered Bayesian data analysis I thought it was the best since sliced bread (I still do) and I was happy to call myself a "Bayesian" (not least to irritate the p-value people at my department). Nowadays I don't like the term, I think it might alienate people as it makes Bayesian data analysis sound like some kind of cult, which it isn't, rather than a useful method to have in your statistical toolbox.

Is it always a flattering distinction?

Nope! As far as I know, the term "Bayesian" was introduced by the famous statistician Fisher as a derogatory term. Before that it was called "inverse probability" or just "probability".

Are they mathematicians with peculiar slides in meetings, deprived of any p values and confidence intervals, easily spotted on the brochure?

Well, there are conferences in Bayesian statistics, and I don't think they include that many p-values. Whether you'll find the slides peculiar will depend on your background...

How much of a niche is being a "Bayesian"? Are we referring to a minority of statisticians?

I still think a minority of statisticians deal with Bayesian statistics, but I also think the proportion is growing.

Or is current Bayesian-ism equated with machine learning applications?

Nope, but Bayesian models are used a lot in machine learning. Here is a great machine learning book that presents machine learning from a Bayesian/probibalistic perspective: http://www.cs.ubc.ca/~murphyk/MLbook/
Hope that answered most of the questions :)
Update:

[C]ould you please consider adding a list of specific techniques or premises that distinguish Bayesian statistics?

What distinguish Bayesian statistics is the use of Bayesian models :) Here is my spin on what a Bayesian model is:
A Bayesian model is a statistical model where you use probability to represent all uncertainty within the model, both the uncertainty regarding the output but also the uncertainty regarding the input (aka parameters) to the model. The whole prior/posterior/Bayes theorem thing follows on this, but in my opinion, using probability for everything is what makes it Bayesian (and indeed a better word would perhaps just be something like probabilistic model).
Now, Bayesian models can be tricky to fit, and there is a host of different computational techniques that are used for this. But these techniques are not Bayesian in themselves. To namedrop some computational techniques:

Markov chain Monte Carlo

Metropolis-Hastings
Gibbs sampling
Hamiltonian Monte Carlo

Variational Bayes
Approximate Bayesian computation
Particle filters
Laplace approximation
And so on...

Who was the famous statistician who introduced the term 'Bayesian' as derogatory?

It was supposedly Ronald Fisher. The paper When did Bayesian inference become "Bayesian"? gives the history of the term "Bayesian".
Comment: Great post! One thing, however, that I would disagree with is your answer to the "Are they some select academic institutions, where you know that if you go there you will become a Bayesian?" question. If you go to Duke's stat department, you will become a Bayesian.
Comment: Man, if I got an upvote for every question I've answered here I would have... 12 upvotes :)
Comment: Oh wow, I remember you from the post about celebrity heights on Andrew Gelman's blog! I'm looking forward to reading, "46656 Varieties of Bayesians".  Thank you for a good answer!
Comment: Very good! I like that you dropped the word 'cult'. I was hesitant lest anybody was offended. Some of my questions were just meant to be prompts... in the end, I am trying to learn about statistics, and I was curious to understand the dichotomy from the inside.
Comment: A comment: there are many things that are labeled as "Bayesian" and people tend to confuse them (and do in this very Q&A!). A non complete list:  The Bayesian Brain hypothesis (a brain is basically doing Bayesian stats), Bayesian philosophy of science, Bayesian statistics, Bayesian view of probability, Computational methods for doing Bayesian statistics, etc. Surely many of these are related (say Bayes. probability and Bayes. stats), but you don't have to buy them all! E.g. I think the Bayesian Brain is highly suspect but embrace Bayesian statistics as a useful and practical *technique*.
Comment: Pure programmers program in ML because pure programmers, being pure, have no side effects.  Monads are for the weak.
Comment: @RasmusBååth Who was the famous statistician who introduced the term 'Bayesian' as derogatory? And, could you please consider adding a list of specific techniques or premises that distinguish Bayesian statistics? For instance under the 'machine learning' heading to avoid disrupting the layout of your answer?
Comment: @RasmusBååth Alla sätt är bra utom de dåliga.
Comment: That great machine learning book is written by Kevin Murphy. He is totally Bayesian. I didn't learn any Frequentist stuffs from his class.
Answer: Bayesians are people who define probabilities as a numerical representation of the plausibility of some proposition.  Frequentists are people who define probabilities as representing long run frequencies.  If you are only happy with one or other of these definitions then you are either a Bayesian or a frequentist.  If you are happy with either, and use the most appropriate definition for the task at hand, then you are a statistician! ;o)  Basically, it boils down to the definition of a probability, and I would hope that most working statisticians would be able to see the benefits and disadvantages of both approaches.

hint of skepticism regarding the chasm between lofty objectives, and
  arbitrariness in the selection of the prior distribution, or eventual
  use of frequentist maths after all.

The skepticism also goes in the other direction.  Frequentism was invented with the lofty objective of eliminating the subjectivity of existing thought on probability and statistics.   However, the subjectivity is still there (for example in determining the appropriate level of significance in hypothesis testing), but it is just not made explicit, or often just ignored.
Comment: Frequentists cannot assign a value to P(H|O) as the truth of a particular hypothesis has no long run frequency, it is either true or it isn't.  As a result, we can only attach probabilities to some (possibly fictitious) population of experiments from which the one we actually observed was drawn, or "reject H0" or "fail to reject H0" at a particular significance level.  Unfortunately either approach leaves possibilities for misinterpretation as what we actually want from the test is exactly P(H|O).  Both approaches have their uses, but it is important to understand their limitations.
Comment: This I don't understand. You can define probability as representing long run frequencies, yet believe in a hypothesis only when its P(H|O) is high and know that P(O|H) (p-value) tells you little. (If you live long enough with enough introspection, you can directly count the frequency of having been right.)
Comment: Is there any other field of math whose practitioners hold themselves hostage to philosophy? Regardless, in practice, essentially the same questions come up again and again. E.g., "did this person commit murder." The unique identity of the accused is irrelevant (just as we ignore the physical details of a particular die roll). Given the thousands of murders committed each year (and the thousands more innocently accused), any set of circumstances will likely have occurred more than once. What isn't frequentist about deciding someone's guilt? Yet to use p-value would be a grave injustice.
Comment: "Yet to use p-value would be a grave injustice." not only that, it would be a fallacy (specifically "the p-value fallacy").  The problem is that the analysis will not involve the long run frequency of guilt for a matching set of previous crimes (for which we may not know the true guilt or innocence).  The analysis that the human beings will perform will be a Bayesian one describing degrees of plausibility.  Trying to dress it up as a frequentist analysis is likely to obfuscate things with no benefit.
Answer: Today, we're all Bayesians, but there's a world beyond these two camps: algorithmic probability. I'm not sure what's the standard reference on this subject, but there's this beautiful paper by Kolmogorov on algorithmic complexity: A. N. Kolmogorov, Three approaches to the definition of the concept "quantity of information", Probl. Peredachi Inf., 1965, Volume 1, Issue 1, 3–11. I'm sure there's an English translation.
In this paper he defines the quantity of information in three ways: combinatorial, probabilistic and (new) algorithmic. Combinatorial directly maps to frequentist, Probabilist doesn't directly correspond to Bayesian, but it's compatible with it.
UPDATE:
If you're interested in the philosophy of the probability then I want to point to a very interesting work "The origins and legacy of Kolmogorov's Grundbegriffe" by Glenn Shafer and Vladimir Vovk. We sort of forgot everything before Kolmogorov, and there was a lot going on before his seminal work. On the other hand, we don't know much about his philosophical views. It's generally thought that he was a frequentist, for instance. The reality's that he lived in Soviet Union in 1930', where it was quite dangerous to venture into philosophy, literally, you could get in existential trouble, which some scientist did (ended up in GULAG prisons). So, he was sort of forced to implicitly indicate that he was a frequentist. I think that in reality he was not just a mathematician, but he was a scientist, and had a complex view of applicability of probability theory to reality.
There's also another paper by Vovk on Kolmogorov's algorithmic approach to randomness: Kolmogorov's contributions to the foundations of probability
Vovk has created a game-theoretic approach to probabilities - also very interesting.
UPDATE 2:
Here's a Bayesian, actually, a professor from one of the universities in Washington, DC. He was trying to make a point that we should elect politicians who update their beliefs based on experiences, new observations. Here $P(B|E)$ is the posterior belief $B$, after the new experience $E$; $P(E|B)$ is the prior. He was trying to explain this to Colbert/Stuart "Rally for Fear" participants.

UPDATE 3:
I also wanted to point to something in Kolmogorov's original work that's not commonly known for some reason (or easily forgotten) by practitioners. He had a section about connecting the theory to reality. In particular, he set two conditions for using the theory:

A. if you repeat the experiment many times then the frequency of occurrence will differ by only a small amount from the probability, practically certainly
B. If probability is very small, then if you conduct the experiment only once then you can be practically certain that the event will not occur

There are different interpretations of these conditions, but most people would agree that these are not the pure frequentist's views. Kolmogorov declared that he follows von Mises' approach to certain extent, but he seemed to indicate that things are not as simple as it may appear. I often think of condition B, and can't come to a stable conclusion, it looks slightly different every time I think about it.
Comment: @AntoniParellada, it's intended to be a joke :)
Comment: Is your first hyperlink what you intended?
Comment: @Aksakal [Kolmogorov in English](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CCEQFjAAahUKEwjP7Oe50a3HAhUMOD4KHTsSCpo&url=http%3A%2F%2Falexander.shen.free.fr%2Flibrary%2FKolmogorov65_Three-Approaches-to-Information.pdf&ei=bYbQVY-CNYzw-AG7pKjQCQ&usg=AFQjCNHiK9aILugcnDjVe4T5QUpLiY4dsQ&sig2=SWZ8XvVnrWP7tvhFvb6WLw&bvm=bv.99804247,d.cWw)
Comment: "McCain to Georgian President: "Today, We Are All Georgians"  Haha, this  is funny.
Comment: You are clearly a jelly donut.
Comment: Completely over my head... And it's probably funny, given the inane nature of the hyperlinked discussion... So sorry I missed it...
Comment: @Aksakal Absolutely right, Kolmogorov HAD to be a frequentist in Staline Soviet Union! But he finally admitted that: "Generally speaking, there is no ground to believe that a random phenomenon should possess any definite probability"/ (Foundations of probability theory, 1983). Kolmogorov was a Bayesian, after all!
Answer: Andrew Gelman, for example, a professor of statistics and political science at Columbia University, is a prominent Bayesian.
I suspect the most of ISBA fellows would probably consider themselves Bayesians as well.
In general, the following research topics typically reflect a Bayesian approach. If you read papers about them, it is likely the authors would describe themselves as "Bayesian"

Markov-Chain Monte Carlo
Variational Bayesian Methods (the name gives that one away)
Particle Filtering
Probabilistic programming
Comment: Gelman isn't "hard core" though. As far as I can tell, he sees Bayesian statistics as something that has proven its worth practically, and he is definitely interested in frequentist properties of Bayesian procedures.
Comment: It should be noted that Markov-Chain Monte Carlo is not directly related to Bayesian statistics, in the same was as numerical optimization is not directly related to Maximum likelihood estimation...
Comment: I think it is also worth noting that Andrew Gelman has written that he doesn't think it is at all meaningful to label a person as a "Bayesian" or "frequentist". But rather, certain TECHNIQUES may be so labeled. He thinks it is counterproductive to arbitrarily divide statisticians into one camp or the other, because both methodologies have different strengths and weaknesses in different contexts.
Comment: Small note: particle filtering is not just for Bayesians! I worked under a professor at Berkeley, in which we used particle filters for the E step of an MCEM algorithm. But yes, particle filters are typically used by Bayesians.
Comment: I think this guy is a Bayesian.

https://xianblog.wordpress.com/about/
Comment: If you're going to pay the computational price, why not get the philosophical consistency?
Comment: Ray Solomonoff is as bayesian as it gets afaik. In general, people like  Stefen Loritzen, Jurgen Schmidhuber,  Jorma Rissanen, Marcus Hutter, Peter Grünwald... any ISBA fellow...
Comment: I could go on awhile about the project (r-nimble.org if you're interested), but essentially there's no reason that probabilistic programming should be restricted to Bayesian models. That's not to say we were only interested in frequentist methods: our default method of analysis was MCMC.
Comment: e.g. Gelman et al., *Bayesian Data Analysis*: "Rather than engage in philosophical debates about the foundations of statistics, however, we prefer to concentrate on the pragmatic advantages of the Bayesian
framework, whose flexibility and generality allow it to cope with very complex problems." This of course does not prove that he does not believe in the foundations, but rather that he prefers to promote Bayesian methods from a pragmatic perspective.
Comment: Absolutely, my point is merely that  P(Bayesian | writes about MCMC) is high
Comment: Actually, to go into more detail, we were working on probabilistic programming, but which also allowed Bayesian and frequentist inference to be preformed on these model (along other things). So we were blurring the lines on your last two topics.
Comment: "he sees Bayesian statistics as something that has proven its worth practically"

This bugs me. You can't pick an epistemology based on "how well it works" ! "How well things work" is already an epistemological criterion, and trying to make it rigorous is what gets you to bayesianism in the first place.
Comment: @ArthurB., yes, I see that the same way. I'm just saying that there is this view. Without talking about Gelman now, from understanding concrete applications I often have the impression that "Bayesian" practicioners often don't really distinguish any more between a distribution that represents a population (also used in Bayesian statistics within generative models) and a distribution that represents knowledge.
Comment: Yes yes I'm aware of his position, and I understand you were merely relaying it. His tolerance of improper priors is further evidence of his middle of the road position on the matter.
Comment: @ArthurB. "You might be a Bayesian if..." In my best Jeff Foxworthy impression.
Answer: The most "hard core" Bayesian that I know of is Edwin Jaynes, deceased in 1998. I'd expect further "hard core" Bayesians to be found among his pupils, especially the posthumous co-author of his main work Probability Theory: The Logic of Science, Larry Bretthorst. Other notable historic Bayesians include Harold Jeffreys and and Leonard Savage. While I don't have a complete overview of the field, my impression is that the more recent popularity of Bayesian methods (especially in machine learning) is not due to deep philosophical conviction, but the pragmatic position that Bayesian methods have proved useful in many applications. I think typical for this position is Andrew Gelman.
Comment: Jaynes and Jeffreys were who I had in mind too.  A great essay is ["Where Do We Stand On Maximum Entropy?"](http://bayes.wustl.edu/etj/articles/stand.on.entropy.pdf)
Comment: Hmmm, I always read Jaynes as being very pragmatic about Bayes.
Comment: It sounds a bit like a romantic idea. Norman Rockwell of statistics?
Comment: @AntoniParellada, I have no idea what you mean by that...
Answer: I don't know who the Bayesians are (although I suppose I should have a prior distribution for that), but I do know who they are not.
To quote the eminent, now departed Bayesian, D.V. Lindley, "there is no one less Bayesian than an empirical Bayesian". Empirical Bayes section of Bayesian Methods: A Social and Behavioral Sciences Approach, Second Edition by Jeff Gill.  Meaning I suppose that even "Frequentists" think about what model makes sense (choice of a model form in some sense constitutes a prior), as opposed to empirical Bayesians who are totally mechanical about everything.
I think that in practice there is not that much difference in the results of statistical analysis performed by top echelon Bayesians and Frequentists.  What is scary is when you see a low quality statistician who tries to rigidly pattern himself (never observed it with a female) after his ideological role model with absolute ideological purity, and approach analysis exactly as he thinks his role model would, but without the quality of thought and judgment the role model has.  That can result in very bad analysis and recommendations.  I think ultra-hard core, but low quality, ideologs are much more common among Bayesians than Frequentists.  This particularly applies in Decision Analysis.
Comment: It's nice to point to some rigidities with humor. Ty
Answer: I'm probably too late to this discussion for anyone to notice this, but I think it is a shame that no-one has pointed out the fact that the most important difference between Bayesian and Frequentist approaches is that the Bayesians (mostly) use methods that respect the likelihood principle whereas Frequentists almost invariably do not. The likelihood principle says that the evidence relevant to the statistical model parameter of interest in entirely contained in the relevant likelihood function.
Frequentists who care about statistical theory or philosophy should be far more concerned by arguments about the validity of the likelihood principle than about arguments over the distinction between frequency and partial belief interpretations of probability and about the desirability of prior probabilities. While it is possible for different interpretations of probability to coexist without conflict and for some people to choose to supply a prior without requiring others to do so, if the likelihood principle is true in either a positive or normative sense then many Frequentist methods lose their claims to optimality. Frequentist attacks on the likelihood principle are vehement because that principle undermines their statistical world-view, but mostly those attacks miss their mark (http://arxiv.org/abs/1507.08394).
Answer: You may believe you're a Bayesian, but you're probably wrong... http://www.rmm-journal.de/downloads/Article_Senn.pdf
Bayesians derive the probability distribution of outcomes of interest given prior belief / prior information. To a Bayesian this distribution (and its summaries) are what most people will be interested in. Contrast with typical "frequentist" results that tell you what the chance of seeing results as or more extreme than those observed given that the null hypothesis is true (p-value) or interval estimates for the parameter of interest, 95% of which would contain the true value if you could do repeated sampling (confidence interval).
Bayesian prior distributions are contentious because they are YOUR prior. There is no "correct" prior. Most pragmatic Bayesians look for external evidence that can be used for priors and then discount or modify this based on what is expected to be "reasonable" for the particular case. For example, sceptical priors may have a "lump" of probability on a null case - "How good would the data need to be to make me change my mind / change current practice?" Most will also look at robustness of inferences to different priors.
There are a group of Bayesians who look into "reference" priors that allow them to construct inferences that are not "influenced" by prior belief and so they get probabilistic statements and interval estimates that have "frequentist" properties.
There are also a group of "Hardcore Bayesians" who might advocate not choosing a model (all models are wrong), and who might argue that exploratory analysis is bound to influence your priors and so shouldn't be done. There are few that radical though...
In most fields of statistics you'll find Bayesian analyses and practitioners. Just as you'll find some folks who prefer non-parametrics...
Comment: I think I understand Bayesian statistics better after reading your post. I wonder if you can tie it up to the actual question to wrap it up into an outstanding answer... It was along the lines of Bayesians being a specific group of people with names, or mathematical departments known for their bias towards Bayes approach to statistics, etc.
Comment: There are many individuals and academic departments that have favoured Bayesian statistics now and in the past. It's hard to single out any one in particular. If you're interested more then I'd recommend looking at ISBA https://bayesian.org/.
Comment: A few names to look out for: Don Berry, Jim Berger, David Draper, Merlise Clyde, Mike West, David Spiegelhalter, Peter Thall...
Comment: In answer to your last question, it is both. It is definitely a philosophical approach. It complements the scientific method that says that we observe what is (prior information), hypothesise, experiment, synthesise and update our current knowledge, which becomes tomorrow's prior. But it's also a statistical method of analysis that can be applied to an individual case.
Comment: Yes, someone else posted the link, and I actually went through the alphabetic list looking for patterns... I couldn't find any, which is not surprising since I'm not a statistician. I guess the idea boils down to, Is Bayes a lofty, pure idea people like to claim adherence to, or is it (still) a well-defined, day-to-day way of practicing applied statistics in contradistinction to frequentism - the latter one not too "sexy" sounding to attach your name to, but possibly more practical?
Answer: Just to take up your last question (so I'm not after a prize!), about a link between a Bayesian/Frequentist approach and one's epistemological position, the most interesting author I've come upon is Deborah Mayo. A good starting point is this 2010 exchange between Mayo and Andrew Gelman (who emerges here as a somewhat heretical Bayesian). Mayo later published a detailed response to the Gelman & Shalizi paper here.
Answer: I would call Bruno de Finetti and L. J. Savage Bayesians.  They worked on its philosophical foundations.
Comment: Since De Finetti (notice the spelling) died 30 years ago and Savage 44 years ago, they scarcely could be recognized as answering "Who are the Bayesians today?", unless they somehow have risen as zombies and are publishing pseudonymously.
Comment: @whuber... It sounds (from the outside) more like a nice, lofty idea... akin to thinking of oneself as evidence-based, constantly updating our view of the world based on our priors and the evidence collected. Bayes as epistemology... rather than a strict adherence to a "different" set of statistical techniques....
Answer: A subset of all Bayesians, i.e. those Bayesians who bothered to send an email, is listed here.
Comment: @Aksakal I think that's more a reflection of the fact that statisticians come from a variety of backgrounds. If the criterion is "people who have published in major stats journals" then many dozens of those names count, whatever the name of the department they're in. I recognized quite a large number just scanning down the list.
Comment: I found there two stat professors who identify themselves as Bayesians. This must be a good list then.
Comment: @Aksakal I don't understand your point. There are 2 (perhaps 3) statistics professors in the first 5 people on that list.
Comment: @jaradniemi, I recalled two my professors who are openly Bayesians, then found them in the list. This makes me think that the list is probably representative.
Answer: For understanding the foundational debate between frequentists and Bayesians, it would be hard to find a more authoritative voice than Bradley Efron.
This topic has been a theme he has touched on numerous times in his career, but personally I found one of his older papers helpful: Controversies in the Foundations of Statistics (this one won an award for expository excellence).

Who Are The Bayesians?


How do I pass the language through ajax request

Question: I have an ajax function in the javascript file that calls for the data in a custom module. But the problem is it always get the data for the default language. In my case it is 'en'. How do I get the data for another language.
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();

This method always returns the default language for ajax requests. How do I get the data for the language that is mentioned in the url.
ajax:
$.ajax({
    url: "/gallery/view",
    method :'POST',
    data: {
        category : category,
        propertyId : propertyId,
        isCorporate : isCorporate,
        brandId : brandId,
    },
    success: function(result){}
});

routing :
eme_gallery.view:
  path: '/gallery/view'
  defaults:
      _controller: 'Drupal\eme_gallery\Controller\ViewGalleryImage::view'
      _title: 'Image Gallery'
  requirements:
      _permission: 'access content'

Comment: How is the langauge for your site determined? URL? Prefix? Session?
Comment: @Jaypan from the url prefix. eg: www.url.com/ja/html
Answer: You will need to change the URL of your AJAX call to include the language prefix. So this:
url: "/gallery/view",

Will be this:
url: "/ja/gallery/view",

Comment: This doesn't work for the english language. If I write /en/ it doesn't work
Comment: Do not include any prefix (en, ja etc) for the default language. You would only use `/gallery/view`


What is this chord used in C Major?

Question:
What is this chord? The key is C Major and I've put in the root (CEG) and the dominant (GBD) as a contrast. It sounds harmonious to me. It's not a V of V (applied/secondary dominant) as that would have D-F#-A but the bass note is G following in pitch with F, B, G.
Answer: G7:  the dominant seventh chord of C major.
Comment: The fifth can be omitted in a seventh chord.
Comment: G7 is G-B-D-F but there's no D in the chord

What is this chord used in C Major?


É possível utilizar duas id's iguais em uma mesma tabela?

Question: Tenho uma situação que preciso tirar uma dúvida. Eu tenho uma tabela conforme abaixo:
CREATE TABLE confrontos(
    id_confrontos INT AUTO_INCREMENT NOT NULL,
    dt_confronto DATE NOT NULL,
    id_estadios INT NOT NULL,
    ***id_clubes*** INT NOT NULL,
    ***id_clubes*** INT NOT NULL,
    id_treinadores INT NOT NULL,
    escore1 INT NOT NULL,
    escore2 INT NOT NULL,
    CONSTRAINT PK_confrontos PRIMARY KEY(id_confrontos),
    CONSTRAINT FK_confrontos_estadios foreign key (id_estadios)
        REFERENCES estadios (id_estadios),
    CONSTRAINT FK_confrontos_clubes foreign key (id_clubes)
        REFERENCES clubes (id_clubes),
    CONSTRAINT FK_confrontos_treinadores foreign key (id_treinadores)
        REFERENCES treinadores (id_treinadores)
);

Já vi que o MySql não permite criar esta tabela por duplicidade no campo id_clubes. Qual seria a melhor maneira de criar esta tabela?
Comment: Depende o que você precisa fazer. Por que a tabela iria ter duas colunas com `id_clubes`? Por que não renomear as colunas para `clube_a` e `clube_b`, por exemplo?
Comment: no caso o problema é a duplicação do nome... você pode mudar para Ex: id_clube_mandante e id_clube_visitante
Comment: faça como fez com o `escore`.. use `id_clube1` ou `id_clube_mandante` ou algo do tipo..
Comment: Ou... você cria uma tabela de relacionamento `[Id_Confronto | id_Clube]` e assim você poderá ter `N` clubes no mesmo confronto :P
Comment: Obrigado pessoal pelas dicas, vou testar aqui
Answer: voce precisa criar uma table auxiliar entre confrontos e times, exemplo tabela timesquevaojogar nela vai ter a id do confronto e a id do time, como vai funcionar
controntoid 1 time 1
controntoid 1 time 2
e na tabela confroto vc faz a referencia a essa tabela
CREATE TABLE timesquevaojogar(
    id_Timesquevaojogar
    id_confrontos
    id_clubes

caso queira pesquisar mais sobre isso procure por relacao n para n
Comment: Mas se sempre são só dois times que jogam, por que criar uma relação N:N? Não é mais fácil ter duas colunas?
Comment: @AndersonCarlosWoss separando em uma auxiliar tanto melhora na pesquisa, como nas boas praticas do sql, fora que no caso dele ele deveria colocar a pontuacao do jogo na outro tabela tambem, pq ele pode fazer um datamine sobre o team A e ver as estaticas e afins... o assunto e longo mas nao impede de ter duas colunas tambem
Comment: Só estou querendo aprender com base em afirmações que não são "achismos". Você tem algum material de onde concluiu sobre essa diferença de performance ou algum teste que realizou?
Comment: recomendo a leitura tambem(primeiro artigo que eu vi) https://hackernoon.com/mysql-tutorial-example-relation-foreign-key-database-funtion-join-table-query-one-namy-nest-41dd09648fbd
Comment: Não entendo o que seria "boas práticas do SQL". Na minha opinião, permitir uma relação N:N em algo que não é N:N pode trazer mais problemas do que benefícios, tal como ter confrontos com 1 time, ou mais do que dois. Conseguiria adicionar na resposta algumas vantagens que vê fazendo assim?
Comment: se vc quer saber quantas vezes o team A jogou qual query vai executar com melhor perfomace, uma onde exite a id com index ou uma tabela que existe duas row contendo a informacao da id? o select com index é muito mais rapido do que uma busca em duas rows com numeros inteiros
Comment: usar 2 colunas vc deixa a tabela totalmente independente, no back-end vc sempre vai precisar comprar a duas tabelas
Comment: seguindo o exemplo dado, caso ele queira colocar tecnico do team a e b, sao mais duas colunas extras, faltas do team a e b mais duas colunas extras...
Comment: quanto mais colunas na tabela mais lento é a pesquisa e resultado
Comment: se quiser ir para o chat eu posso explicar passo a passo e dar exemplos praticos do meu dia a dia.
Comment: Já está lá, na verdade: https://chat.stackexchange.com/rooms/11910/estouro-de-pilha


Unable to reference d3.js data imported from a csv file with spaces in the header

Question: I am importing data from a csv file that contains headers with spaces in the middle of some of the fields.
For example the following has a column named 'Date Purchased';
Value,Date Purchased,Score
12345,2011-03-23,99
22345,2011-03-24,100
32345,2011-03-25,99
42345,2011-03-26,100

I know that RFC 4180 specifies that this is normal;

Within the header and each record, there may be one or more fields,
separated by commas. Each line should contain the same number of
fields throughout the file. Spaces are considered part of a field and
should not be ignored.

But when I then go to import the data using the d3.csv function, I need to reference the 'Data Purchased' column in a way that makes allowances for the space. The following piece of script would be the most basic solution, but JavaScript is not allowing the use of the space within the variable name (I know it seems obvious, but I'm trying to spell this out logically)
d3.csv("sample-data.csv", function(error, data) {
    data.forEach(function(d) {
        d.date = parseDate(d.Date Purchased);
    });

console.log(data) shows that the file is being imported without problem and that the data in the 'Data Purchased' column is called 'Data Purchased'.
I have found references that suggest the inclusion of a decimal point, an underscore or a hyphen instead of a space (d.Date.Purchased, d.Date_Purchased, d.Date-Purchased), but that doesn't seem to work either.
I could write a simple php parser to remove the spaces, but it feels like there is a simple  solution that that will work in JavaScript / d3 and I'm just missing it.
Answer: Here's how
d.date = parseDate(d['Date Purchased']);

Comment: Ahh... Perfecto! Many thanks! (I initially mistyped your solution, but got there eventually :-))


In a Multiple Linear Regression Model, is $Cov(\pmb{\hat{y}}, \pmb{e}) = 0$?

Question: I'm solving the problem 3.33, from the book "Introduction to Linear Regression Analysis (5th edition)", by Montgomery and I got a doubt.
3.33) Prove that $R^2$ is the square of the correlation between $\pmb{y}$ and $\pmb{\hat{y}}$.
I solved the problem assuming that $Cov(\pmb{\hat{y}}, \pmb{e}) = 0$.
Is this true?
Comment: Yes, that is correct. Linear regression decomposes y (vector containing all y-values in the sample) into two components- $\hat{y}$ that is a linear combination of the columns of X (each row of X is an observation of predictor variables), and, $\epsilon$ that can't be described as such a linear combination (because it is orthogonal to the plane formed by the columns of X).
Comment: Thanks for the comment. Do you have any material or a book showing this?
Answer: I found the solution in "Linear Models in Statistics", from Rencher, Exercise 9.1 d):
$Cov[\pmb{e}, \pmb{\hat{y}}] = Cov[(\pmb{I - H})\pmb{y}, \pmb{Hy}] = (\pmb{I - H})(\pmb{\sigma^2I})\pmb{H} = \pmb{\sigma^2}(\pmb{H-H}) = 0$,
where $\pmb{H}$ is the hat matrix.


Custom Module to remove User Menu Tabs

Question: I'm hoping someone can take pity on me because I just can't seem to figure out how to make a simple module to remove, or hide some tabs in my user pages.
I read the docs on making custom modules, questions about removing tabs, and thought I figured it out. I made a custom module called 'TabEdit' with this structure, just to test it out:
/tabedit
    tabedit.info.yml
    tabedit.module

tabedit.info.yml
name: TabEdit
description: Edit tabs shown in user pages.
type: module
package: custom
core: 8.x
core_version_requirement: ^8 || ^9

tabedit.module
<?php
/**
 * Implements hook_menu_local_tasks_alter()
 */
function tabedit_menu_local_tasks_alter(&$data, $route_name) {
  unset($data['tabs'][0]['simplenews.newsletter_subscriptions_user']);
}

It didn't work, so I obviously still don't get the fundamentals on how to make a module. What I want to do is remove the Shortcuts, Simplenews Subscriptions, Activity, and Submissions from the user menu tabs.
Answer: Hooks need to be written in . module file not in controller. Move your code to .module file and also it should be tabedit_menu_local_tasks_alter
tabedit.module
<?php

/**
 * Implements hook_menu_local_tasks_alter()
 */
function tabedit_menu_local_tasks_alter(&$data, $route_name) {
  unset($data['tabs'][0]['simplenews.newsletter_subscriptions_user']);
}

Clear flush all caches so hook gets pickedup.
Comment: So I would take what was in the php file and move it to a tabedit.module file? If that's the case, do I need anything in the Controller folder?
Comment: @TomP no Controller folder needed.
Comment: I had made those changes. I just edited my original question to match. My user tabs still has NEWSLETTERS (/user/2/simplenews). I've also flushed the cache after reinstalling each time. I'm hoping if this can work I can use it to get rid of a couple other tabs as well.
Comment: @TomP file name should be tabedit.module not RemoveTabEdit.php
Comment: Sorry. I edited the original question to match what I've been trying
Answer: A file like src/Controller/RemoveTabEdit.php is for a class, not a function. In the specific, it's not for hook implementations, which should always go in the module file.
The src/Controller/RemoveTabEdit.php file is automatically loaded when the RemoveTabEdit class is used, but since that doesn't happen, the file is never loaded and that hook implementation is never found.
As side note, it's better to avoid uppercase characters in the module machine name. While PHP is case insensitive, the code looking for hook_update_N() implementations is still case sensitive.
Comment: Ok that starts to make sense. So what would the structure look like. Doesn't a .module file have to go in the root of the module? Also what would the php file need to do then?
Comment: If you don't have any code for that file, that file can simply be removed. Yes, the *tabedit.module* file goes in the directory containing the *tabedit.info.yml* file.
Comment: I've now have a single folder 'tabedit' with two files the 'tabedit.info.yml' and 'tabedit.module'. I completely removed the src folder.

The .module file only has the one function I'm using to test

<?php
'function tabedit_menu_local_tasks_alter(&$data, $route_name) {
 unset($data['tabs'][0]['simplenews.newsletter_subscriptions_user']);
}'
It's still not working. If the module is correct maybe the tab address is wrong.
Comment: If you edit a module code after it has been installed, Drupal doesn't notice the code has been changed, or new files have been added. You need to uninstall the module and re-install it. Any code change must be done when the module isn't installed. As for the SimpleNews module, it has a [*simplenews.newsletter_subscriptions_user*](https://git.drupalcode.org/project/simplenews/-/blob/8.x-2.x/simplenews.links.task.yml#L51) tab; that is correct.
Comment: In particular, Drupal keeps in cache the list of hooks implemented from modules. The only way to refresh that cache is installing or uninstalling a module.
Comment: Yes I did uninstall, edit, then install. I got the address from the same file as you pointed out so I was sure it was right. My user tabs still has NEWSLETTERS (/user/2/simplenews). I've also flushed the cache after reinstalling each time. I just don't know what I could still be missing. This should be simple.
Answer: This did finally works. I renamed it tabedit.module and made the code
<?php
/**
  * Implements hook_menu_local_tasks_alter().
  */
function tabedit_menu_local_tasks_alter(&$data, $route_name) {
/*      If a current user has the 'administrator' role then do not hide the tabs.
    $current_user_roles = \Drupal::currentUser()->getRoles();
    if (in_array('administrator', $current_user_roles)) {
        return;
    }
*/
    unset($data['tabs'][0]['tracker.user_tab']);
    unset($data['tabs'][0]['shortcut.set_switch']);
    unset($data['tabs'][0]['simplenews.newsletter_subscriptions_user']);
    unset($data['tabs'][0]['entity.webform_submission.user']);
}
``

Custom Module to remove User Menu Tabs


PHP com MongoDB - Como criar sessão no MongoDB e executar comando na mesma?

Question: Criei uma conexão com mongodb e criei uma sessão a partir da mesma:
<code>$manager = new MongoDB\Driver\Manager("mongodb://127.0.0.1:27017");
$sessao = $manager->startSession();
$id_sessao = $sessao->getLogicalSessionId();
</code>
No código acima eu sei que a sessão foi criada com sucesso, pois se eu mandar imprimir o objeto $id_sessao, o id é mostrado. Mas agora quero executar um "find()" nessa sessão. Pra isso estou tentando extrair o "server" pra tentar executar nele o comando "find":
<code>$busca_vendas = new MongoDB\Driver\Command(['find'=>'vendas','query'=>[]]);
$cursor = $sessao->getServer()->executeCommand("loja",$busca_vendas);
</code>
Porém, no código acima, a função getServer() retorna NULL. Dai não consigo executar o FIND dentro da sessão. Estou fazendo certo?
Answer: Acabei encontrando outro jeito de fazer. Descobri que dá pra especificar a sessao ao realizar o executeQuery(). Porém ainda acho estranho, na minha tentativa anterior, o getServer() retornar vazio. Mas em todo caso, assim deu certo:
<code>$query = new MongoDB\Driver\Query([],[]);
$cursor = $manager->executeQuery("loja.vendas",$query,['session'=>$sessao]);
</code>


Run a command for each item in jq array

Question: This is how my input file looks like:
[
  {
    "ConfigType": "ABC",
    "Prop1": 3,
    "Prop2": 30
  },
  {
    "ConfigType": "XYZ",
    "Prop3": "Hello",
    "Prop4": "World",
    "Prop5": "Application"
  }
]

I need to prepare insert statement for each item.
This is how my jq command looks like which gives me each item.
cat app-cnfg.json |  jq -r ".[]"

How do I execute aws dynamodb put-item --table-name "xxx" --item <<array's element>>?
Answer: You can pipe to xargs:
jq -c '.[]' app-cnfg.json \
    | xargs -L 1 aws dynamodb put-item --table-name "xxx" --item

The -c option to jq makes sure each element is on a single line, and the -L 1 option to xargs makes sure that the command is called once per item.
If you wanted to avoid potential problems with trailing whitespace (which would make args treat the following line as continuation of the current one), you can get your objects zero byte separated (requires jq 1.7 or newer):
jq -c --raw-output0 '.[]' app-cnfg.json \
    | xargs -0 -n1 aws dynamodb put-item --table-name "xxx" --item

The --raw-output0 option behaves like -r, but with NUL instead of newlines.
xargs -0 -n1 expects zero byte delimited input and runs the command for each argument once.

For jq versions older than 1.7:
jq -j '.[] | tostring + "\u0000"' app-cnfg.json \
    | xargs -0 -n1 aws dynamodb put-item --table-name "xxx" --item

The -j option suppresses newlines from jq, tostring stringifies the objects and + "\u0000" appends a zero byte.
Comment: You can; it's a little tricky. See https://github.com/stedolan/jq/issues/1271 for discussion -- `-j` suppresses the newlines, so you can add NULs via your expressions. `jq -j '.[] | (. + "\u0000")'`, to summarize (perhaps filtering them out from the data, if being suitably cautious).
Comment: You could write a shell function that takes the item as its argument, something like `myfunc () { echo "$1"; aws ... "$1"; }` and then call it like `| xargs -0 -I {} bash -c 'myfunc "$1"' _ {}` (untested), or pipe to `while read -r -d '' item; do echo "$item"; aws ... "$item"; done` (untested)
Comment: `-L` is an interesting choice -- granted, `jq` should never emit a line that ends with whitespace (when not in raw-string mode), but if it *did*, that would be treated as a continuation as I understand it.
Comment: @CharlesDuffy That's right, checking to see if I can get nul byte delimited output from jq...
Comment: @CharlesDuffy Updated.
Comment: @BenjaminW. If I want to execute multiple commands like `echo` and then `aws dynamodb put-item --table-name "xxx" --item` on the same item, how do I do that?
Comment: @BenjaminW. Thanks. I will test it out. Thanks for your help.
Answer: You can apply the filter to extract each element of the JSON array and feed it to an array in bash and iterate over its content later. Assuming you have bash 4.0 or greater, you can use mapfile command as
mapfile -t configArr < <(jq -c '.[]'  < app-cnfg.json)

and now we loop over the array, to run the command for each config item,
for config in "${configArr[@]}"; do
    aws dynamodb put-item --table-name "xxx" --item "$config"
done

(or) use a more efficient way to read from an input data stream using a while loop and the read command (works on bash versions that don't support mapfile or readarray)
while IFS= read -r config; do
    aws dynamodb put-item --table-name "xxx" --item "$config"
done< <(jq -c '.[]' < app-cnfg.json)

Run a command for each item in jq array


Quando usar o MemoryCache?

Question: Gostaria de um exemplo real, não necessariamente de código, sobre quando utilizar o MemoryCache em sistemas Web. Que tipos de situação pedem por seu uso?
Um pouco de contexto: participei de uma entrevista em que me fizeram essa pergunta e eu não soube responder, pois nunca fiz nenhum tipo de caching. Nos sistemas em que já dei manutenção praticamente todas as consultas eram feitas diretamente no banco de dados. Embora o volume de informações fosse grande, nunca tivemos problemas com performance, e o que tínhamos era resolvido com índices ou outras soluções diretamente no banco, mas nunca na aplicação em si.
Comment: bom dia,
geralmente em aplicações onde retornam uma grande massa de dados de informações de conta de acesso do usuário onde não tem a precisão de ir no banco a todo momento estar buscando informação do usuário, podemos estar usando um MemoryCache para estar guardando os dados na aplicação
Answer: A pergunta é um pouco ampla, mas vamos lá.
Imagino que já leu a documentação dele. Pelo menos é isso que o programador faz quando vê algo novo que não conhece e deseja saber mais. Não vou falar o que já está lá, não parece ser o foco.
Cache é uma das estratégias mais importantes e mais usadas para fazer dados serem acessados mais rapidamente. Cache é mais simples do que as pessoas imaginam. Você fazer um cálculo e guardar em uma variável está fazendo cache. Quer mais simples que isso? Claro, aqui estamos falando de um mecanismo um pouco mais sofisticado.
Cache é extremamente complicado conforme vai saindo do trivial, principalmente quando precisa decidir sobre invalidação dele. Mas cache é apenas uma forma de entregar uma informação de um jeito mais rápido que a forma tradicional, não importa muito como. Um exemplo seria a memoização que é o padrão de projeto básico usado em grande parte dos mecanismos de cache.
Você pode ter vários níveis de cache na aplicação e no entorno dela. Pode ter algo que faz parte da sua aplicação ou que é feito por terceiros em infraestrutura que você usa direta ou indiretamente, algo de hardware ou software. Saber escolher quais usar e quais são exagero é uma arte. Alguns você não escolhe, existe e boa. Como é muito complicado fazer certos caches é melhor usar algum mecanismo pronto em boa parte dos casos.
Então a pergunta é mais embaixo, é quando usar o cache. Quando ele for necessário então o MemoryCache deve ser sua escolha (mas pode ter outros níveis de cache fora da sua aplicação). Ele será correto, tem a forma que provavelmente é mais eficiente, controles de concorrência e principalmente já deve ter uma ou mais estratégias de invalidação que funcionam razoavelmente bem na maioria das situações. E uma das coisas mais importantes é ter um monitoramento para invalidar sob demanda, que é uma das invalidações mais consistentes que existe (com vantagens e desvantagens).
O exemplo real depende da situação, por isso é muito difícil colocar um exemplo. De qualquer forma não importa o mecanismo, importa entender todo o processo de desenvolvimento de software para absorver sobre a necessidade de cache. Não tem uma resposta mágica, a não ser que deve usar quando precisar de mais performance e um teste mostrar que o cache resolve parcial ou totalmente. Não existe nenhuma situação que dá para dizer que deve usar sempre ou deve usar nunca, inclusive porque o mesmíssimo problema pode mudar se o volume mudar.
Existem problemas que o cache ajuda pouco ou nada ou atrapalha. Se você tem acesso raro ao mesmo dado o cache é só um estorvo. Somente o padrão de repetição do acesso aos mesmos dados várias vezes é que te dá vantagem clara.
Já respondi sobre para PHP, continua válido aqui.
Coloquei no GitHub para referência futura.

Quando usar o MemoryCache?


Swift - Instance member cannot be used on type custom class

Question: I have no idea why I cannot call token on this argument, I keep getting error on this line
.ExtraHeaders(["Authorization": token])

The error

Instance member 'token' cannot be used on type 'SocketIOManager'

Full code
import SocketIOClientSwift
import KeychainAccess

class SocketIOManager: NSObject {
    static let sharedInstance = SocketIOManager()

    let keychain = Keychain(server: "https://testing.herokuapp.com", protocolType: .HTTPS)

    var token: String {
        get {
            return String(keychain["token"])
        }
    }

    let socket = SocketIOClient(socketURL: NSURL(string:
       "https://testing.herokuapp.com")!,
       options: [.Log(true), .ExtraHeaders(["Authorization": token]) ])

    override init() {
        super.init()
    }

    func establishConnection() {
        socket.connect()
    }

    func closeConnection() {
        socket.disconnect()
    }

}

Comment: I tried your suggestions, It doesn't work
Answer: The problem can be distilled into a tiny bit of code:
class Test {
    let test = "test"
    let test2 = test + "2" // instance member 'test' cannot be used on type 'Test'
}

The problem is that when those fields are initialized, the object doesn't exist yet. There are two ways of dealing with this:
 class Test {
    let test = "test"
    lazy var test2:String = self.test + "2" // since test2 is lazy, it only gets computed at a time when the object already exists
}

and
class Test {
    let test = "test"
    let test2:String

    init() {
        test2 = test + "2" // you can set constants in initializers
    }
}

The downside of the first option is that you have to use var, and you need to explicitly write self, the downside of the second is that your initializing code is not right where the declaration is. (though init() is a very logical place to look next) Both way require you to explicitly state the type. You have to decide what's more important to you, I'd opt for leaving constants constants when possible. But when you're using var already, might as well for the first option.
Note that if you choose the second option and your class inherits from another class, you need to initialize the member before calling super.init():
class Test: SuperTest {
    let test = "test"
    let test2:String

    override init() {
        test2 = test + "2"
        super.init()
    }
}

The compiler will yell at you if you don't do this, so it's hard to get it wrong.
Comment: Im going with the first option but still received an error,  `lazy var socket = SocketIOClient(socketURL: NSURL(string: "https://testing.herokuapp.com")!,
    options: [.Log(true), .ExtraHeaders(["Authorization": token]) ])`
Comment: I added lazy but for some reason, the current error keeps showing.
Comment: @airsoftFreak I've edited my answer, it should work now. Do consider the second option though, making a constant into a variable without good reason is not good practice in Swift.
Comment: I added self.token, but now the error is different, it is `SocketIOManager has no member token`
Comment: `Value of type 'NSObject -> () -> SocketIOManager has no member 'token'` is the full error
Comment: Don't mind this error. Solved it.
Comment: But i have another question, I tried your second option, received an error, because the token is a computed property, so i cant set it to `let`
Comment: second option will work if the token is a constant.


jqGrid zebra/alt rows background not working due to UI Theme class

Question: We cannot get zebra striping to work in jqGrid.
We use altclass and altRows - issue is it appears the ui-widget-content class from the JQuery UI has a background setting which is overriding our altclass's background setting.  Any ideas?

Update: Both answers below work.  Oleg's is the cleanest solution by far.
For Oleg's solution to work, your altRows class has to be defined after including the JQuery UI CSS class as both the JQuery UI and the custom alt rows class define the background property and the last class defined wins.
Comment: Could you post a code example including the jQuery UI theam what you use. How exactly you define `altclass` class which you use. The best is the full code example which reproduces the problem.
Answer: jqGrid use jQuery UI class 'ui-priority-secondary' as the default value of the altclass parameter. The class are described in jQuery UI documentation as

Class to be applied to a priority-2
  button in situations where button
  hierarchy is needed. Applies normal
  weight text and slight transparency to
  element.

It is of cause not exactly the description of the zebra striping, but there are not so many standard classes which can be used. Unfortunately even rows having 'ui-priority-secondary' looks not so different from odd rows in the most themes. So to improve visibility one have to define the class altclass manually.
One of the most native ways to make even rows seen different as the odd rows is the usage of different background color. The problem is that ui-widget-content class use an background image defined with background CSS style, so the most native setting of background-color will not work. To fix the problem one have to do one from the things 1) remove ui-widget-content class 2) use background CSS style instead of background-color 2) use background-image:none together with the background-color style. The simplest way to do this is define your custom AltRowClass as
.myAltRowClass { background: #DDDDDC; }

or
.myAltRowClass { background-color: #DDDDDC; background-image: none; }

and then to use altRows:true and altclass:'myAltRowClass' parameters of jqGrid.
Another way is to do the same without altRows and altclass parameters:
loadComplete: function() {
    $("tr.jqgrow:odd").css("background", "#DDDDDC");
}

In the case you will has some small disadvantages in hovering or selecting the even lines. The following code works better, but it do the same what altRows:true and altclass:'myAltRowClass' do:
loadComplete: function() {
    $("tr.jqgrow:odd").addClass('myAltRowClass');
}

Of cause the background color and other CSS styles attributes which you can set for the even rows are depend from the theme which you use, so if you plan to use ThemeRoller you will have to choose altclass for every theme, which you will allow to choose.
UPDATED: Just seen that I forgot to include the link to the demo file which demonstrate what I wrote live. The demo is here.
Comment: @Marcus: I made small changes of my answer and added the url to the demo.
Comment: Interesting..  I will try using the `background-image:none` setting instead of using the approach I described with `removeClass('ui-widget-content')`
Comment: Worked - one caveat though - see my updated question.  Thanks Oleg!
Comment: @Marcus: I read the "updated" part of your question. It is exactly what I mean and what I used in my demo, but I find good to point the importance of the order for other reader.
Answer: Per Oleg..  in loadComplete:
$.each(grid.getDataIDs(),
    function(index, key){
        if(index % 2 !== 0) {
            var t = $("#" + key, grid);
            t.removeClass('ui-widget-content');
        }
    }
);

And then in the grid definition:
altRows:true,
altclass:'myAltRowClass',

With `myAltRowClass':
.myAltRowClass { background: #F8F8F8 ; border:1px solid #DDDDDD;  }

Comment: Sorry Marcus, is it a solution of your problem or only explanation? If it is not a solution you should also include `myAltRowClass` definition which you use.
Comment: Well this does work, but it's not a great solution.  If you apply a different theme other than `flick` then the grid doesn't look as it should as I am hard coding the border color in `myAltRowClass` (see updated post) and some other themes use different colors.  So if we used a different theme I would have to change the color in `myAltRowClass`.  This isn't ideal - I'd like to be able to pick a different theme and have it work instantly without any other changes.  Note that I have to include the `border` property as the odd rows still use `ui-widget-content` which sets the border.
Comment: I am not designer. If the default `altclass` class 'ui-priority-secondary' are good defined from the designer of the theme, then one will have no problem at all themes. If 'ui-priority-secondary' is not the best choice and you can not find another standard class existing in **all themes**, which you can use as `altclass`, then you will have to customize his own `altclass` for every theme. I see no ways.
Comment: Fair enough Oleg - if you want to add a answer to this question I will accept it as the solution I used came from one of your (other) answers..
Comment: I agree with you. I suppose that the problem is common, so I made some more tests and wrote my answer on your questions using mostly the same information which you already known.
Answer: here is my solution:
altRows     : true,
altclass    : 'oddRow',

gridComplete: function() {
    $(".jqgrow:odd").hover(
        function() { $(this).removeClass("oddRow");},
        function(event) { $(this).addClass("oddRow");}
    );
},

it worked for me and can be used with any ui theme.
Answer: I added the following CSS to a supplementary file to style the alternate row and row hover without using additional Javascript:
table.ui-jqgrid-btable tr:nth-child(odd) td{
    background-color: #E7F0FD;
}
table.ui-jqgrid-btable tr:hover:nth-child(odd) td{
    background: url("images/ui-bg_glass_75_dadada_1x400.png") repeat-x scroll 50% 50% rgb(6, 41, 97);
}


windows 2019 unattended install on kvm via libvirt can't find licence error

Question: I'm trying to install windows server 2019 with autounattend.xml configuration on kvm via libvirt.
Installation fail on dialog with sign: "Can't find microsoft software license terms"
Despite there are a lot of articles with solving this error - it doesn't work for me. The main difference in my case is that I can successfully install windows manually, but I get this error on unattended installation only.
I'm using packer to build VM image, and with qemu builder it works, with libvirt builder doesn't. And this issue isn't related to packer - I've created VM manually and got the same error.
I've played with VM configuration trying to set/remove different parameters but no luck as well.
I've installed windows10 the same way (unattended) without any issue.
So, looks like it isn't an ISO image issue - I can install from the same iso manually or via qemu builder
It doesn't seen to be an error in autounattend.xml - I use the same file for qemu installation and for windows10
Currently I'm stuck. So if anybody has any suggestions, I'll appreciate.
UPDATE: windows 2019 installation doesn't work on qemu and on libvirt.
Answer: The root cause was in autounattended.xml file configuration - Windows 2019 installation fails with specified error if unattended file contains empty parameter "". For Windows2019 that string should be removed:
<code><unattend xmlns="urn:schemas-microsoft-com:unattend">
  <settings pass="windowsPE">
    ...
    <component name="Microsoft-Windows-Setup"...
    ...
      <UserData>
      ...
        <ProductKey>
          <WillShowUI>OnError</WillShowUI>
          <Key></Key>  <------ REMOVE FOR Windows2019 this line
        </ProductKey>
    ...
</code>
From other side, Windows10 requires presence of that string ("")


Bayesian A/B/C testing

Question: I built a Bayesian A/B testing tool - i.e. one which models A and B having posteriors $Beta(\alpha_i, \beta_i)$ where $\alpha_i, \beta_i$ are updated every iteration.
After T iterations, I compare the posterior distributions of A and B and determine which one is larger, lets say, using the mean.
How can I incorporate a third (or fourth...) group?
Originally I wanted to model it as a Dirichlet, giving each group some $\alpha$ that is updated each iteration. And then after T iterations select the group with the largest $\alpha$. But I think that it's more correct to keep each group A, B, C as a separate Beta (since they are theoretically independent) and just compare the posteriors of their respective distributions. It seems naive to me, but also intuitive. Can someone who has done this please opine?
Answer: Addressing your question
As you have stated correctly, the groups are independent, hence Dirichlet does not make any sense. When you have more than one group, you can boil the comparison down to 2 by one of these strategies:

You have a reference / baseline group, which shall be improved. Compare all groups to that one.
Compare the current best to the current second best to decide whether you have a global winner. In the same way, compare the worst to the second-worst to decide whether a group shall dropped from the competition.

General remark
Note: Maybe I have misunderstood what you meant with "comparison by mean", I just add this for sake of completeness for other readers.
Comparing the posteriors is good, but the current mean is rather volatile and hence may be bigger or smaller just by chance. IMHO it is recommended to compare the credible intervals of the means using a two-dimensional monte carlo integration to calculate the subjective probability of the true unknown mean of group B is greater than the true unknown mean of group A, i.e. group B > group A.
Example code for

A: 401 trials, 125 successful trials
B: 441 trials, 141 successful trials

which is
<code>trials <- 10000
resDat<-data.frame("a"=rbeta(trials,125+1,401-125+1),
                   "b"=rbeta(trials,144+1,441-144+1))
length(which(resDat$b>resDat$a))/trials
</code>
But even using this approach one does only control the type II error, i.e. falsely missing a difference. To control the type I error, i.e. falsely stating finding a difference, I recommend a classical frequentist style test (e.g. G-Test) as followup.
Answer: The Beta distribution could be seen as a special case of the Dirichlet distribution and the question is technically not about whether you are using a Dirichlet or not (because a Beta distribution is already a Dirichlet distribution), but the question is about which dimension to use.
These Dirichlet distributions are conjugate priors for the categorical distribution. In the case of the Beta distribution, you have just two categories, and in the case of the Dirichlet distribution, you have more categories.
Which categories and categorical distribution are you modeling with A/B testing?
With A/B testing you are not modeling a probability distribution for probabilities among the two groups/categories A and B, which now become three groups with the addition of C. (this is where your intuition about the need to use a Dirichlet distribution may come from)
Instead, with A/B testing you are more likely* modeling something like success rate and the beta distribution posterior relates to the two classes 'success' and 'failure'.

* I write, more likely. Since you are using a beta distribution as prior/posterior, I assume that you are probably modelling something that is binomial distributed like click-through rate, or number of visitors that continue to make a successful sale. But A/B testing is more general and can also relate to other distributions. E.g. it could be about the total value of sales instead of the number of sales.

Bayesian A/B/C testing


How can I specify background color and image for a block or node?

Question: My web page consists of vertically aligned blocks. Each of these blocks/nodes may have  a custom background color or image. I am entering the background color/image within the specific block. How can i then apply these CSS attributes on that specific block? I would like to simply render the block as

[...]

I played with block template but was not able to persuade the color or image attribute to appear where i needed them, both the values were wrapped in the useless

markup.
Comment: Did you add the bgr_color and the bgr_image as fields?
Comment: Yes, these are only illustrative names, the actual ones would be `field.bgr_color` and `field.bgr_image`. I'll update the question accordingly.
Comment: You can try the answer here: https://drupal.stackexchange.com/questions/187764/getting-a-custom-block-image-field-url-in-the-block-twig-template
Answer: You can do it with this module:
https://www.drupal.org/project/bg_image_formatter
Just upload image as background field and set the class in the field settings for which element you want to display image as bgd.
It works with Views as well. So, for example, you can use Views conditional module and create a block and test if bdg field is empty and then create different styles with bgd color in that case.


Use a Mac (10.8) as a remote log server

Question: I'm trying to use my Mac Mini server as a remote log server for our router. I set the router to forward the logs to the server but I'm not seeing the logs anywhere in the console app.
Am I missing something?
Thanks a lot in advance.
Answer: You have to configure the OS X (or any other OS) to accept remote syslogs using something like syslogd. This article has a very basic tutorial on this.
Simply pointing a device's syslog application to a remote machine isn't enough, if it were malicious users would be able to make a system run full disk with little effort.
Answer: Unfortunately, the article @MDMarra linked is somewhat out of date -- in OS X 10.7, Apple switched the syslogd LaunchDaemon to binary plist format, meaning that it isn't just a matter of editing it with a text editor. Here's how to add the network listener with PlistBuddy:
cd /System/Library/LaunchDaemons
sudo /usr/libexec/PlistBuddy -c "add :Sockets:NetworkListener dict" com.apple.syslogd.plist
sudo /usr/libexec/PlistBuddy -c "add :Sockets:NetworkListener:SockServiceName string syslog" com.apple.syslogd.plist
sudo /usr/libexec/PlistBuddy -c "add :Sockets:NetworkListener:SockType string dgram" com.apple.syslogd.plist
sudo launchctl unload com.apple.syslogd.plist
sudo launchctl load com.apple.syslogd.plist

Note: I haven't fully tested this; it listens for UDP on the right socket, but I haven't verified that it still handles incoming packets properly.

Use a Mac (10.8) as a remote log server


Hide multiple columns VBA Excel

Question: In sheet1 I need to show all columns from (C:N), where is selected month in (B2), other columns must hide. If i chose month 4 in B2, then i need to see only these columns where is date with month 4 in (C:N) and etc.
If i have full calendar of dates, how to find exact month and hide others??

Private Sub Worksheet_Change(ByVal Target As Range)
Dim wb As Workbook
Dim ws As Worksheet
Dim entireRange As Range
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1")
Set entireRange = ws.Columns("C:N")

entireRange.EntireColumn.Hidden = False

Select Case ws.Range("B2")

  Case "1"
      ws.Range("G:N").EntireColumn.Hidden = True

  Case "5"
      ws.Range("C:F,H:N").EntireColumn.Hidden = True

  Case "6"
      ws.Range("C:G,I:N").EntireColumn.Hidden = True

End Select
End Sub

Comment: It looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (console output, tracebacks, etc.). The more detail you provide, the more answers you are likely to receive. Check the [FAQ] and [ask]
Comment: Sorry, i did't new that.
Comment: Can you add what is wrong/ what is missing with your code? Where do you struggle?
Comment: Already done :)
Answer: A simple code to hide the Columns that don t fit your month would look like this:
Sub HidingColumn()

Dim i As Long

For i = 12 To 3 Step -1 '12 being your N Column

    If Month(Cells(4, i)) <> Range("B2").Value Then
        Cells(4, i).Columns.Hidden = True
    End If
Next i

End Sub

Hide multiple columns VBA Excel


Why there is a single-flat key signature for a F major triad?

Question: I am reading a book for beginner about building the chords, basically on triads so far. It is said that the major triads is formed by a root, third and a fifth. From that instruction, it is easily to setup a C major triad by making the root as C; to get the third, I add 4 half steps to C so to get E; to get the fifth, I add 7 half steps to C so to get G. The C major triad is shown on the left of the following stave

Similarly, I am getting the F major triad by using a F note as the root, A as the third and C as the fifth, so F-A-C be the F major triad, correct?
In the book, the author introduces anohter way to construct major triads by taking the first, major third and fifth notes from a major scale. It then gives me F major triad as shown in the right side of above stave. The book does not tell why there is a single-flat key signature added. I am trying to reason it by listing the C major scale, C-D-E-F-G-A-B, from that, the first, major third and fifth notes is just C-E-G but this does not give me F-A-C. However, I find that if I lower the F by half step, I get the E, which may get E-A-C by adding one-flat signature on F. This still does not show me why the RHS staff is connected to the F major triad.
Also, is it any noticeable difference between the F major triads with and without the flat key signature? I tried to repeat the following pattern in a virtual keyboard and listen very carefully, I can't tell the difference honestly

(I am trying to search the related questions on generating F mjaor triad but it comes up with few threads with some terms I don't understand yet).
Comment: Wait, minor triads and major triads sound the same to you? Can you repeat the test pattern with C major and C minor chords, for instance, and do you also find you cannot distinguish between those by ear?
Comment: Did you intend the flats and naturals in your last example to be on A rather than B as in the first example?  In the first example, the flat will have no effect as there is no B in the chord.  In the second, changing the A from flat to natural should have a very noticeable effect.
Comment: Hi Dekadeci and badjohn, to reply both comments here. Yes, my bad to place the flat on the wrong position, it should be placed on the line of "B"  on the sheet and the chord actually doesn't have B, I think that is why I can't tell the difference between them (in actualy play, I do place flat on B line and no effect to the chord).
Answer: The key signature shown there doesn't affect the notes in the triad, as you've correctly worked out. It's just there because it's the signature for the key of F major. The author has just chosen to show the one flat of F major because that's the key they're talking about: it might be confusing to see the F major triad in a C major key signature. It doesn't affect the way you play the triad at all.
It would make more difference for B♭ major. The key signature for that has two flats, on B and E. Obviously the root is on B♭. So if you write a B♭ major triad, you have to either write out the key signature or use an accidental.
About the connection between the triad and the key signature: each major scale has the same sequence of steps and half-steps: TTSTTTS (where T is a whole tone and S is a semi-tone). This is what links the root note of a major scale to its key signature, and it's probably described in more detail later in your book. In C major, this sequence lines up with the pattern of "white notes" and "black notes", so there are no sharps or flats. The F major scale contains a B♭ (as its fourth), so the key signature has a B♭. It just so happens that in this case, the notes of the triad (F, A, and C) don't have any sharps or flats. In some scales (such as B♭ major or D major), the notes of the triad do contain some that are sharp or flat.
Comment: @user1285419 That's pretty much right. A chord is just a stack of notes but you don't just choose random notes, you choose them from a particular scale (the scale of a particular key). That's the starting point, but obviously you aren't limited to the chord of the key the piece is in: if your piece is in C major, you'll tend to use chords whose notes are in C major, such as F and G; but you might also use chords containing accidentals. It's more of a guide than a constraint.
Comment: Thanks Dan. By reading the context of your reply carefully, I think I may find out the reason confusing me: I thought chords is isolated from key and scale since it states in the book that a chord is nothing but a stack or "vertical" combination or 3 or more notes. But as in your explanation, can I say major chord is always related to the key and a major scale? The major scale constrains what notes could be used and arrange in what order and key tell which note should be flatted, sharped or natural, is that right?
Answer: Triads are indeed formed from 1, 3 and 5 of a key, or the scale from that key. So in key C, 1 3 and 5 are C E and G, as you state.
On to the F triad. Exactly the same idea - but now we count from F. 1 3 5 is F A C.
Do the same for G, if you like - G B D. It all works as simply as that.
However (there's often a however!) sharps and flats in certain keys can affect which notes are actually played. Take A major triad. Count up A C E. Wrong! Because there's the key signature of 3♯ to consider, making that C into C♯.
On to your example. In key F, there's the key signature of one flat - B♭. That goes at the start of each line of music. Another however - that B♭ isn't played in an F triad, so is a red herring. I guess it's put in that music to show it's in key F. Confusing! But some would say it's technically correct. I wouldn't as we get an F chord in key C, so don't necessarily need to show that key sig. of one flat.
EDIT: noticing the last para. - don't know why the B♭ has changed to A♭, but now you have F minor and F major triads. They sound very different to most people, and ought to to you. If not, there's a serious problem with your discerning the difference!
Comment: Hi Tim, thanks for the explanation. I sort of understand how to figure out the triad by counting now. But I think I need more time to digest what I learnt so far. Based on your first statement "triads are indeed formed from 1,3 and 5 of a key, or the scale from that key". Can I conclude that the key will be always the lowest tone of a scale? C major scale: CDEFGAB, F major scale: FGAB(flat)CDE, that is why when we say to sing a song in certain "key", we are saying from what starting pitch we sing the "Do" as?
Comment: @user1285419 - got me there! As there are two distinct 'do' meanings. If it's *fixed do*, as used in France for one, then do is *always* C, regardless of any key. If, as I guess you mean, it's *movable do*, then yes, as do is the root of any key we happen to be in at the time. But don't get confused by the fact that we can have an F triad in key C. And that then is produced from 4,6 and 8 of the *C scale*.
Comment: Hi Tim. Yes, my mistake in typing. The flat should be on B line, thanks for pointing that out.


How do I pick a string from a larger string within an array and group them with name?

Question: I have an array in php script.
 $carstable = array(
    "tbl_Volvo_01_05_16",
    "tbl_Volvo_02_05_16",
    "tbl_Volvo_03_05_16",
    "tbl_Volvo_04_05_16",
    "tbl_BMW_01_05_16",
    "tbl_BMW_02_05_16",
    "tbl_BMW_03_05_16",
    "tbl_BMW_04_05_16",
    "tbl_Toyota_01_05_16",
    "tbl_Toyota_02_05_16",
    "tbl_Toyota_03_05_16",
    "tbl_Toyota_04_05_16");

This array is generated by the system.I want another array from it that will contain only the list of cars mentioned in the above array.
I want the array to be like :
$cars =array("Volvo","BMW","Toyota");

Comment: only car name and unique array values...
Answer: Another approach with array_map & array_unique & preg_match to enable support for different string structures:
<?php

$carstable = array(
    "tbl_Volvo_01_05_16",
    "tbl_Volvo_02_05_16",
    "tbl_Volvo_03_05_16",
    "tbl_Volvo_04_05_16",
    "tbl_BMW_01_05_16",
    "tbl_BMW_02_05_16",
    "tbl_BMW_03_05_16",
    "tbl_BMW_04_05_16",
    "tbl_Toyota_01_05_16",
    "tbl_Toyota_02_05_16",
    "tbl_Toyota_03_05_16",
    "tbl_Toyota_04_05_16"
);

$cars = array_map(function($v){
    preg_match("/tbl_([^_]+)/", $v, $t);
    return $t[1];
}, $carstable);

$cars = array_unique($cars);

var_dump($cars);

output:
array(3) {
  [0]=>
  string(5) "Volvo"
  [4]=>
  string(3) "BMW"
  [8]=>
  string(6) "Toyota"
}

Answer: Use foreach and explode the value with _ and store them into final array. now apply array_unique for getting unique array values.
$carstable = array(
    "tbl_Volvo_01_05_16",
    "tbl_Volvo_02_05_16",
    "tbl_Volvo_03_05_16",
    "tbl_Volvo_04_05_16",
    "tbl_BMW_01_05_16",
    "tbl_BMW_02_05_16",
    "tbl_BMW_03_05_16",
    "tbl_BMW_04_05_16",
    "tbl_Toyota_01_05_16",
    "tbl_Toyota_02_05_16",
    "tbl_Toyota_03_05_16",
    "tbl_Toyota_04_05_16"
);

$final = array();
foreach($carstable as $val){
    $tmp = explode("_", $val);
    $final[] = $tmp[1];
}

echo '
';
print_r(array_values(array_unique($final)));

Result
Array
(
    [0] => Volvo
    [1] => BMW
    [2] => Toyota
)

Comment: What will happen with `Alfa_Romeo` btw?
Comment: Sorry,  I did't catch you.
Comment: @u_mulder See my answer for that.
Comment: @u_mulder, Where it is in OP's question?
Answer: You may want to do something like below:
<?php
$carstable = array(
    "tbl_Volvo_01_05_16",
    "tbl_Volvo_02_05_16",
    "tbl_Volvo_03_05_16",
    "tbl_Volvo_04_05_16",
    "tbl_BMW_01_05_16",
    "tbl_BMW_02_05_16",
    "tbl_BMW_03_05_16",
    "tbl_BMW_04_05_16",
    "tbl_Toyota_01_05_16",
    "tbl_Toyota_02_05_16",
    "tbl_Toyota_03_05_16",
    "tbl_Toyota_04_05_16");

//$cars =array("Volvo","BMW","Toyota");

$cars = array();
foreach( $carstable as $carinfo ) {
    $tokens = explode( '_', $carinfo );
    $cars[] = $tokens[1];
}
$cars = array_unique( $cars );

print_r($cars);
?>

Answer: loop through the array and explode it with "_"
<?php
$carstable = array(
    "tbl_Volvo_01_05_16",
    "tbl_Volvo_02_05_16",
    "tbl_Volvo_03_05_16",
    "tbl_Volvo_04_05_16",
    "tbl_BMW_01_05_16",
    "tbl_BMW_02_05_16",
    "tbl_BMW_03_05_16",
    "tbl_BMW_04_05_16",
    "tbl_Toyota_01_05_16",
    "tbl_Toyota_02_05_16",
    "tbl_Toyota_03_05_16",
    "tbl_Toyota_04_05_16");
$newArray = array();
foreach ($carstable as $value) {
  $carArray = explode('_',$value);
  if (isset($carArray[1])) {
    $newArray[] = $carArray[1];
  }
}
print_r(array_unique($newArray));

Answer: A short snippet, works with Alfa Romeo too.
$carstable = array(
    "tbl_Volvo_01_05_16",
    "tbl_Volvo_02_05_16",
    "tbl_Volvo_03_05_16",
    "tbl_Volvo_04_05_16",
    "tbl_BMW_01_05_16",
    "tbl_BMW_02_05_16",
    "tbl_BMW_03_05_16",
    "tbl_BMW_04_05_16",
    "tbl_Toyota_01_05_16",
    "tbl_Toyota_02_05_16",
    "tbl_Toyota_03_05_16",
    "tbl_Toyota_04_05_16",
    "tbl_Alfa_Romeo_04_05_16",
);

$result = array_unique(array_map(function($row) {
    $a = explode('_', $row);
    return array_slice($a, 1, sizeof($a)-4);
}, $carstable));

Will result:
Array
(
    [0] => Volvo
    [1] => BMW
    [2] => Toyota
    [3] => Alfa_Romeo
)

Comment: @FrayneKonok u_muler mentioned in another answer's comment. Naively spitting on every `_` wouldnt work on brands like that.


Streamlit: Use html button as a native one

Question: I have the following html code of a table, embedded within a Streamlit app:
homepage_table = """

\n

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n

Status
Product
Impact

⚠
Product A;
€ 1.520
<button class="css-160hik1 edgvbvh1">Go</button>

"""

That renders as you can see below; I would like to use the button within the html code as a normal Streamlit button (st.button()) so that, whenever it's clicked, I can run some additional code:
e.g.
if st.button("my_html_button"):
   st.write("It works!")

Answer: To the best of my knowledge this is not possible.
The right way to do this would be to create an API with

Flask
Django
FastAPI
etc.

And make the button call the API.
It is also a good practice, because you will be able to take some load off of your Streamlit application.


Selecionar somente tuplas de uma tabela com JOIN

Question: Possuo a seguinte query:
SELECT finpag.cod_forn
      ,sicforn.nome
      ,finpag.data_pagto
      ,finempe.cod_reduzido
      ,finpag.num_empenho
      ,finpag.ano_empenho
      ,num_liquid
      ,ano_liquid
      ,valor_transacao
 FROM finpag
 INNER JOIN sicforn on
       sicforn.cod_forn = finpag.cod_forn
 INNER JOIN finempe on
       (finempe.num_empenho = finpag.num_empenho)
 WHERE  finpag.data_pagto between '1-1-1997' and '31-12-1997' and finpag.cod_forn = 1840 and finpag.ano_empenho = 97
 ORDER BY finpag.num_liquid

Que me retorna a seguinte consulta:
cod_forn/nome/cod_reduzido/num_empenho/ano_empenho/num_liquid/ano_liquid/valor_transacao

1840    LUC'S ELETRODOMESTICOS LTDA 286 1473    97  3554    97  734
1840    LUC'S ELETRODOMESTICOS LTDA 3   1473    97  3554    97  734
1840    LUC'S ELETRODOMESTICOS LTDA 2   1661    97  3671    97  649
1840    LUC'S ELETRODOMESTICOS LTDA 370 1661    97  3671    97  649
1840    LUC'S ELETRODOMESTICOS LTDA 370 1661    97  3903    97  85
1840    LUC'S ELETRODOMESTICOS LTDA 2   1661    97  3903    97  85
1840    LUC'S ELETRODOMESTICOS LTDA 39  1712    97  3942    97  649
1840    LUC'S ELETRODOMESTICOS LTDA 3   1712    97  3942    97  649
1840    LUC'S ELETRODOMESTICOS LTDA 3   1712    97  4143    97  85
1840    LUC'S ELETRODOMESTICOS LTDA 39  1712    97  4143    97  85
1840    LUC'S ELETRODOMESTICOS LTDA 61  1889    97  3894    97  64
1840    LUC'S ELETRODOMESTICOS LTDA 348 1889    97  3894    97  64
1840    LUC'S ELETRODOMESTICOS LTDA 136 2165    97  4571    97  176
1840    LUC'S ELETRODOMESTICOS LTDA 10  2165    97  4571    97  176
1840    LUC'S ELETRODOMESTICOS LTDA 58  2010    97  4331    97  562
1840    LUC'S ELETRODOMESTICOS LTDA 61  2010    97  4331    97  562
1840    LUC'S ELETRODOMESTICOS LTDA 53  2286    97  5111    97  70
1840    LUC'S ELETRODOMESTICOS LTDA 264 2286    97  5111    97  70
1840    LUC'S ELETRODOMESTICOS LTDA 285 1919    97  5714    97  734
1840    LUC'S ELETRODOMESTICOS LTDA 64  1919    97  5714    97  734
1840    LUC'S ELETRODOMESTICOS LTDA 17  2534    97  5277    97  78
1840    LUC'S ELETRODOMESTICOS LTDA 78  2534    97  5277    97  78
1840    LUC'S ELETRODOMESTICOS LTDA 25  2928    97  6612    97  1080
1840    LUC'S ELETRODOMESTICOS LTDA 227 2928    97  6612    97  1080
1840    LUC'S ELETRODOMESTICOS LTDA 17  2773    97  6904    97  130,5
1840    LUC'S ELETRODOMESTICOS LTDA 10  2773    97  6904    97  130,5
1840    LUC'S ELETRODOMESTICOS LTDA 389 2513    97  6621    97  575
1840    LUC'S ELETRODOMESTICOS LTDA 348 2513    97  6621    97  575
1840    LUC'S ELETRODOMESTICOS LTDA 109 2965    97  6762    97  549
1840    LUC'S ELETRODOMESTICOS LTDA 53  2965    97  6762    97  549
1840    LUC'S ELETRODOMESTICOS LTDA 12  2994    97  6763    97  549
1840    LUC'S ELETRODOMESTICOS LTDA 188 2994    97  6763    97  549
1840    LUC'S ELETRODOMESTICOS LTDA 10  2773    97  6960    97  156,6
1840    LUC'S ELETRODOMESTICOS LTDA 17  2773    97  6960    97  156,6
1840    LUC'S ELETRODOMESTICOS LTDA 49  2657    97  6912    97  1500
1840    LUC'S ELETRODOMESTICOS LTDA 31  2657    97  6912    97  1500
1840    LUC'S ELETRODOMESTICOS LTDA 264 3630    97  7698    97  249
1840    LUC'S ELETRODOMESTICOS LTDA 3   3630    97  7698    97  249
1840    LUC'S ELETRODOMESTICOS LTDA 188 2994    97  7198    97  1389
1840    LUC'S ELETRODOMESTICOS LTDA 12  2994    97  7198    97  1389

Preciso remover as duplicatas, como poderia ser feito (sem utilizar função de agregação)?
Comment: se entendi bem você tem o retorno (condições) esperado; então seria o caso só controlar os campos que seleciona, não?! Você está trazendo `finempe.cod_reduzido`, bastaria remover ele (e outros campos da tabela `finempe` que estejam lá)
Comment: os dados estão duplicados justamente por causa do finempe.cod_reduzido (não existe uma coluna cod_reduzido em finpag), pois são diferentes na tabela finempe e finpag, então gostaria de selecionar somente os da tabela finpag
Comment: Está um tanto confuso a sua questão, mas até onde entendi, adicione na condição do JOIN entre as tabelas FINEMPE e FINPAG o campo cod_reduzido. {INNER JOIN FINEMPE ON (FINEMPE.NUM_EMPENHO = FINPAG.NUM_EMPENHO AND FINEMPE.COD_REDUZIDO = FINPAG.COD_REDUZIDO)}
Comment: @Andrey não existe uma coluna cod_reduzido em finpag, se vc observar a query eu busco ela da finempe
Comment: Então coloque os campos num GROUP BY e faça um MAX do COD_REDUZIDO.
Comment: @Andrey vc poderia exemplificar numa resposta? iria facilitar o meu entendimento
Answer: Acredito que o SQL abaixo resolva seu problema:
SELECT finpag.cod_forn
          ,sicforn.nome
          ,finpag.data_pagto
          ,MAX(finempe.cod_reduzido) AS cod_reduzido
          ,finpag.num_empenho
          ,finpag.ano_empenho
          ,num_liquid
          ,ano_liquid
          ,valor_transacao
     FROM finpag
     INNER JOIN sicforn on
           sicforn.cod_forn = finpag.cod_forn
     INNER JOIN finempe on
           (finempe.num_empenho = finpag.num_empenho)
     WHERE  finpag.data_pagto between '1-1-1997' and '31-12-1997' and finpag.cod_forn = 1840 and finpag.ano_empenho = 97
  GROUP BY finpag.cod_forn
          ,sicforn.nome
          ,finpag.data_pagto
          ,finpag.num_empenho
          ,finpag.ano_empenho
          ,num_liquid
          ,ano_liquid
          ,valor_transacao
     ORDER BY finpag.num_liquid

Comment: é isso mesmo... mas ainda deu umas inconsistências aqui... Acho que nem MIN e nem o MAX iriam servir,  o que poderia colocar ao invés deles?
Comment: Podes explicar qual a inconsistência? Pode ser qualquer função de agregação, MIN, MAX, AVG, SUM... depende do seu objetivo final.
Comment: ele realmente retirou as duplicatas, mas a lógica de selecionar o maior ou o menor cod_reduzido não está correta
Comment: Deixa eu entender melhor sua realidade, a tabela finemp é sua tabela de empresas cadastradas? Se sim, quantas empresas tem cadastradas? Talvez falte apenas aplicar um Where no seu SQL original para delimitar a trazer apenas um registro da tabela finemp...
Comment: É mais ou menos por aí, essa consulta retorna os gastos realizados em com outras empresas porém na tabela finempe não possuo o nome da empresa ( pego no inner join com sicforn) e também não possou o cod_reduzido (pego no inner join com finempe)
Comment: Poste por favor a estrutura das tabelas: finpag, finempe e sicforn... ao menos as chaves existentes nessas tabelas
Comment: tá lá as colunas das tabelas
Comment: Vamos [continuar esta discussão no chat](http://chat.stackexchange.com/rooms/72734/discussion-between-andrey-and-v-avancini).
Answer: Solução
No seu caso em questão, provavelmente o RIGHT JOIN que é o que precisa, pois busca somente os valores correlacionados que estão na sua "tabela direita", ou seja, no seu join RIGHT.

Conceito
Basicamente você tem que entender o conceito da esquerda e direita (left e right), por exemplo:
A sua tabela em FROM ela é a sua tabela esquerda, ou seja, LEFT, quando for fazer um JOIN.
FROM tabela1 X
LEFT OUTER JOIN tabela2 Y ON Y.campo1 = X.campo2

Ou seja, você está trazendo tudo da tabela X, mais os registros da Y que tem vínculo com a X.
Agora em:
FROM tabela1 X
RIGHT OUTER JOIN tabela2 Y ON Y.campo1 = X.campo2

Você trás tudo que está na sua tabela da direita "Y" mais os de "X" que tem relação com "Y".
O INNER somente o que for em comum nas 2 tabelas, e o FULL trás TUDO independente das relações.
Existe muito material sobre isso, e principalmente essa imagem super conhecida que ajuda muito no entendimento:

edit

Preciso remover as duplicatas, como poderia ser feito (sem utilizar
  função de agregação)?

Com essa citação após a edição, muda o contexto.
Neste caso deve-se usar o GROUP BY
Comment: nem left nem rigth aplicam quaisquer mudanças no resultado.
Comment: Agora com essa citação que fez: `Preciso remover as duplicatas, como poderia ser feito (sem utilizar função de agregação)?` entendi. Mas nesse caso somente com o `GROUP BY`
Comment: assim como exemplificado na resposta acima?
Comment: Como na resposta do Andrey. Você tem que saber o que você quer unir, e então definir todos os campos. Se nunca fez ou tem ainda certa dúvida, cria um banco para teste, faça por partes. É mais fácil aprender dirigir num carro do que uma carreta ! rsrs Se ainda ficarem dúvidas, posta seu banco no http://sqlfiddle.com/
Comment: eu acho que vc não entendeu meu brm rsrs eu NÃO gostaria de usar função de agregação, o group by vem justamente para utiliza-las, certo?
Comment: Entendi sim ! rs Por isso que disse `Mas nesse caso somente com o GROUP BY` !  Os registros vem no seu filtro, para uni-los somente dessa forma. Eu não vejo outra forma. Você viu algo que faça da forma que você quer ? Se tiver exemplos passa que vemos !