Issues with AWS Aurora MySQL engine version "5.7.mysql_aurora.2.10.3"

Question: Is anyone else experiencing problems after recent automated AWS Aurora MySQL database engine updates?   (specifically "5.7.mysql_aurora.2.10.3")

Over the weekend our web servers started reporting issues and were becoming non-responsive at times.
Troubleshooting today showed that since Thu morning we have been hitting max_connections=80 regularly on an AWS Aurora database that had been running very-lightly-loaded beforehand.

Further digging showed two step-changes in the DatabaseConnections metric (see plot 1)

The most recent step change on May 25 corresponds to an automated DB engine upgrade (5.7.mysql_aurora.2.10.3 --> 5.7.mysql_aurora.2.11.2) during the DB instance maintenance window...
...and an earlier step-change on May 7 corresponds to an unknown change during an earlier DB cluster maintenance window.

Other factors:

CPU usage has been impacted only slightly (see plot 2)
DB queries and usage patterns are unchanged.
There's nothing particularly interesting in the release-notes for this DB engine update.

We have put a few workarounds in place, but it looks like something in the recent Aurora MySQL DB engine update is adversely impacting performance, and I'm keen to hear from others who may be experiencing similar issues... and any solutions you may have found.
EDIT 6/6/2023
This Aurora DB seems to have now magically healed itself (ironically during another cluster maintenance window) - see plot below:

Note: based on analysis of our web servers, we had migrated a legacy web server from BlueHost (USA) to AWS (Sydney) to try to cope with the underperforming Aurora instance.  This migration was implemented on June 2 and resulted in a step change improvement in performance... but then during the cluster maintenance window on June 4, the DB magically returned to pre-disruption performance once again!
Here's the final before/after profile:

I wish I could find a way to audit what is being done during each Aurora maintenance window!
Comment: Additional DB information request from AWS AURORA, please.
OS, Version?
RAM size, # cores, any SSD or NVME devices on MySQL Host server?
Post TEXT data on justpaste.it and share the links.
From your SSH login root, Text results of:
A) SELECT COUNT(*), sum(data_length), sum(index_length), sum(data_free) FROM information_schema.tables;
B) SHOW GLOBAL STATUS;    after minimum 24 hours UPTIME
C) SHOW GLOBAL VARIABLES;
D) SHOW FULL PROCESSLIST;
E) STATUS;  not SHOW STATUS, just STATUS;
G) SHOW ENGINE INNODB STATUS;
for server workload tuning analysis to provide suggestions.
Comment: WilsonHauck - as mentioned earlier a LOT of different codebases are accessing this instance, so posting specific code is not practical...
...but I've just checked CloudWatch logs and it seems to have mysteriously healed itself during a cluster maintenance window - see edit above.
Here's some answers to your questions:
It's a single-instance Aurora MySQL db.t3.medium instance (2VCPU, 4GB RAM, etc) hosted in ap-southeast-2b zone.
The results of the requested stats are here:  https://justpaste.it/84njg
Comment: Is there any kind of "connection pooling"?  Do clients explicitly close there connection?
Comment: Please post your code responsible for Connect, Process, Close activities for your clients success.
Comment: @Michael-Engelbrecht  What is result of SELECT @@innodb_buffer_pool_load_at_startup in your aurora2.11.2 version that uses more CPU?
Comment: @RickJames one of our legacy servers has a process that sometimes terminates without explicitly closing connections.  No connection pooling.
Comment: Despite leaky processes the Aurora instance was coping perfectly well for 6+ years until the recent DB engine updates.  In case anyone is interested, a temporary workaround has been to adjust parameter groups to set 'wait_timeout'=600 (vs 28800), 'interactive_timeout' = 600 (vs 28800), and 'max_connections' = 160 (vs 80 based on formula).  This has helped somewhat, but the DatabaseConnections metric graph is still sitting around 20-25 where it had been around 5 before May 2023.
Comment: @WilsonHauck @@innodb_buffer_pool_load_at_startup = 0.  This Aurora instance is shared between 10+ web servers (Wordpress + Laravel + Legacy PHP) - so lots of different codebases.
Comment: Please post your (PHP) code responsible for Connect, Process, Close activities that manages your clients connection.
Answer: rest assured that you are not alone in this situation. Recently, I received an email from AWS urging me to upgrade my Aurora MySQL to engine 2.11.2 before the 30th of June.
However, after the upgrade, I have noticed a significant decline in the performance of various aspects, such as disk I/O and commit latency.
In an attempt to address this issue, I reached out to AWS support via email. Their response merely suggested to "ANALYZE TABLE." Regrettably, despite following their advice, the situation did not improve, and instead, it continues to cause numerous problems.
Comment: This does not provide an answer to the question. Once you have sufficient [reputation](https://serverfault.com/help/whats-reputation) you will be able to [comment on any post](https://serverfault.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/555622)
Answer: We are facing a similar issue as well, we upgraded our Aurora cluster from 2.11.1 to 2.11.2. We usually had around 30 - 50 sessions at a given time before the upgrade, but after the upgrade it's facing havoc. Session count has reached 300 +.
If you are using 'INSERT IGNORE' and 'INSERT ON DUPLICATE KEY' statements, AWS has an internal fix that they will apply.
There are performance issues definitely with the 2.11.2 version. We are still facing the issue, even upscaling the instance didn't resolve the issue.
Comment: This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://serverfault.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://serverfault.com/help/whats-reputation), you can also [add a bounty](https://serverfault.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/556094)


Trying to JOIN 5 tables, having issues

Question: I'm fairly new to both mysql and php so I am still getting my head around it all, so please bear with me.
I basically have a site where users can make topics, and tag tagwords to their topics, I am trying to join the tables so when I query for the POSTS, it can also show the tag information in there.
"SELECT u.user_id, u.username, u.profile, topic_tags.tag_id, tags.tag_id, tags.tags,
       p.post_id, p.post_content, p.post_date, p.post_topic, p.post_by, p.invisipost
FROM `posts` p
JOIN `users` u on p.post_by = u.user_id
JOIN `topics` t on p.post_topic = t.topic_id
WHERE p.post_topic='$id'
INNER JOIN `tags` ON topic_tags.tag_id = tags.tag_id
INNER JOIN `topic_tags` ON topics.topic_id = topic_tag.tag_id
WHERE topic_tags.tag_id = topics.topic_id";

Like I said I am still very new to this so if you could offer any advice I would be much appreciative.
EDIT: here is the code that calls the tags
<?php
        $topic_id = $rows['topic_id'];
        $sql=mysql_query("SELECT * FROM topic_tags WHERE `topic_id`='{$topic_id}'");
        while($rowd=mysql_fetch_array($sql))
        {
            $tag_id = $rowd['tag_id'];
            $fetch_name = mysql_fetch_object(mysql_query("SELECT * FROM `tags` WHERE `tag_id`='{$tag_id}'"));
        ?>

<?php echo ucwords($fetch_name->tags);?>

        <?php
        }
        ?>

Answer: All the wheres should be at the end:
SELECT u.user_id, u.username, u.profile,
topic_tags.tag_id, tags.tag_id, tags.tags,
   p.post_id, p.post_content, p.post_date,
 p.post_topic, p.post_by, p.invisipost
FROM `posts` p
JOIN `users` u on p.post_by = u.user_id
JOIN `topics` t on p.post_topic = t.topic_id
INNER JOIN `tags` ON topic_tags.tag_id = tags.tag_id
INNER JOIN `topic_tags` ON topics.topic_id = topic_tag.tag_id
WHERE p.post_topic='$id' and topic_tags.tag_id = topics.topic_id

This is the corrected query statement based on your original question. I am still not sure if the last part is correct though. You might want to run this in your database directly and see if you get the results you need.
Comment: Thanks for the reply, I'm getting "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in  on line 76" which is "$result2 = mysql_query($sql2);
while($rows = mysql_fetch_array($result2)){"
Comment: Can you try running this statement directly against MySQL  (and not through PHP) ? You can use PHPMyAdmin or MySQL Workbench etc.
Comment: "Unknown column 'topics.topic_id' in 'where clause'" is what I got.
Comment: does your topics table have a topic_id column ?
Comment: yes, topic_id is in topics and TOPIC_TAGS, the tags are associated with the topics via topic_tags table.
Comment: will it be possible for you to post the structure of all of your tables? try "show create table tablename" in MySQL.
Comment: POSTS
post_id
post_content

TOPICS
topic_id
topic_content

TOPIC_TAGS
tag_id
topic_id

TAGS
tag_id
tags

USERS
user_id
username
profile
Comment: I think you need another table that stores tags for a post or you need a table that associates POSTS with TOPICS. In either case, you probably don't need the user table for your original query.
Comment: well the tags aren't for posts, they are so I can display the TOPIC TAGS in each post result, kinda like on a forum how the topic is "fred" then replies are "re: fred" the users table is in there to show the username and poster avatar.
Comment: in that case you need some sort of association between posts and topics.
Comment: they are currently associated, just i can't get the tag info to display within the posts, everything else displays fine, originally topics had a category field and that displayed for posts, but adding the tag tables has thrown everything off it seems.
Comment: I added to my original post the code used to fetch the tags, maybe I am doing something wrong there?
Comment: do you think you can create your schema on sqlfiddle: http://sqlfiddle.com/ and populate it with some sample data. That would be helpful in debugging the query.
Answer: There are a few rules when writing SQL.  The where clause comes after the from clause.  In addition, tables can only be references in an on clause after they have been placed in the from clause.  And, a query only has one from statement and one where statement.  All joins are placed in the from statement.
Two good practices are to use table aliases that are abbreviations for the table (which you do sometimes).  And, don't mix join and inner join.  They are synonyms, but only one should be used in a query.
SELECT u.user_id, u.username, u.profile, tt.tag_id, ta.tag_id, ta.tags,
       p.post_id, p.post_content, p.post_date, p.post_topic, p.post_by, p.invisipost
FROM `posts` p join
     `users` u
      on p.post_by = u.user_id join
     `topic_tags` tt
      ON p.post_topic = tt.topic_id join
     `tags` ta
     ON tt.tag_id = ta.tag_id
WHERE p.post_topic='$id';

Finally, I'm pretty sure that you do not want and tt.tag_id = topics.topic_id.  This is comparing a tag_id to a topic_id.  They are not referring to the same thing.  I think the joins as shown above are sufficient for your query.
Comment: Thanks for your reply, I was joining tag_id to topic_id because topic_id is in TOPICS, tags are in TAGS, and then TOPIC_TAGS is where the tag_id and topic_id join them up.

I tried what you suggested and I am still getting "Warning: mysql_fetch_array() expects parameter 1 to be resource"
Comment: I don't think you need the topic table in the query.  You can join directly from `posts` to `topic_tags`.  (The `on` condition was wrong there.)

Trying to JOIN 5 tables, having issues


Localized Taxonomy terms in a View

Question: Localized taxonomy terms are not displayed in a View. Only the default language term is shown. I solved this issue writing a small module according to this article.
Perfect. But in one View i have two fields: term ID and Global PHP code. My question is: what needs to be changed in the Global PHP code below to have the localized terms displayed?
$term = taxonomy_term_load($data->tid);
//print l($term->name,"voices", array('query' => array('type' => $term->tid)));
print l($term->name,"voices", array('query' => array('f[0]' => 'field_production_type_:'.$term->tid), 'attributes' => array('class' => array($term->name))));

/*
  $url = drupal_get_path_alias('taxonomy/term/'. $term->tid);
  $url_part = explode('/', $url);
  print l($term->name ,"voices/voiceovers/".$url_part[1], array('attributes' => array('class' => array($term->name))));
*/

Answer: From the question details provided, I'm not sure if the i18nviews module is enabled (make sure it is).
Probably the best option might be to use i18n_taxonomy_term_get_translation as explained also in the questions:

How to get the translated term name by tid?.
how to get the translated taxonomy term programmatically?

Something else you may want to try to get the terms translated, is to use the setting (for Translation mode) Translate. Different terms will be allowed for each language and they can be translated (instead of 'Localize'). This setting can be found within admin/structure/taxonomy/<YourTaxonomy>/edit.
Comment: I do have i18nviews enabled. Without the custom module it only shows the term in the default language. I can imagine i need to change the code above with lines like: localized_term or localized_name but i don't know exactly which lines. Some suggestions for that would be very helpful.
Answer: $term = taxonomy_term_load($tid);
$translated_term = i18n_taxonomy_term_get_translation($term, $langcode);
Comment: Thanks a lot Namari, I replaced the first line of my code with yours: first line: $term = taxonomy_term_load($data->tid); into Your lines: $term = taxonomy_term_load($tid); $translated_term = i18n_taxonomy_term_get_translation($term, $langcode); But this didn't work out. I tried changing ($tid) into ($data->tid) then only the default language terms where displayed like before. Maybe i did something wrong. Would you mind to have another quick look at it and paste the complete piece of code?
Comment: try this:
global $language;
$lang_name = $language->language; //or use the one you want 'en', 'fr'...
$term = taxonomy_term_load($data->tid);
$translated_term = i18n_taxonomy_term_get_translation($term, $lang_name);
Comment: if it doesn't have a look here http://drupal.stackexchange.com/questions/79037/get-translated-term-name

Localized Taxonomy terms in a View


Does a maiden over require all 6 balls to be bowled?

Question: If a team is defending a total, and say in the first ball the bowler takes a wicket and the team is all-out. Will that over be considered a maiden over since no runs came from the batsman's bat and there were no bowler extras either?
Answer: To be considered a maiden convention is that it must be a completed over.


Granger Test interpretation

Question: I am complete novice so bear with me. As per the documentation on statsmodels, the NULL hypothesis is that the second time series X2 does NOT granger cause X1.
<code>Granger Causality
number of lags (no zero) 1
ssr based F test:         F=3.0976  , p=0.0792  , df_denom=369, df_num=1
ssr based chi2 test:   chi2=3.1227  , p=0.0772  , df=1
likelihood ratio test: chi2=3.1097  , p=0.0778  , df=1
parameter F test:         F=3.0976  , p=0.0792  , df_denom=369, df_num=1

Granger Causality
number of lags (no zero) 2
ssr based F test:         F=2.3378  , p=0.0980  , df_denom=366, df_num=2
ssr based chi2 test:   chi2=4.7394  , p=0.0935  , df=2
likelihood ratio test: chi2=4.7094  , p=0.0949  , df=2
parameter F test:         F=2.3378  , p=0.0980  , df_denom=366, df_num=2
</code>
After reading through all different articles, I am still confused to understand what to make out of the P-value and the level of significance.
Answer: The null hypothesis in the granger causality test is that the second time series does not Granger cause the first time series (column two and column one respectively for the module that you are using). In your case your p-values are larger than 0.05, which is the traditional cutoff for statistical significance. That is to say you fail to reject the null hypothesis. If you were to pick a different cutoff for statistical significance then that might alter your conclusion, but you would probably be met with a lot of skepticism for picking a different value (especially if it is less stringent; i.e., higher than 0.05).
Further reading: https://blog.minitab.com/blog/adventures-in-statistics-2/understanding-hypothesis-tests-significance-levels-alpha-and-p-values-in-statistics
TL/DR: The level of significance refers to what p-value you use as your cutoff between failing to reject and rejecting the null hypothesis. The by far most commonly accepted choice is 0.05
Comment: so, just so that I understand, in my case I am saying that the second time series in fact does cause the first one, is that correct?
Comment: It is saying that you do not have sufficient evidence to say that the second time series causes the first. So the answer to your question at the risk of using sloppy language is no. The null hypothesis is that the second series does NOT cause the first and you have failed to reject that hypothesis. So you have insufficient evidence to say that the second causes the first.
Comment: thank you for the answer, but if I increase the lags to 4, then the last two lags will give me a p value which is much smaller than 0.05, so then should reject the null based on the first two lags or fail to reject the null?
Comment: You would then reject the null hypothesis because you have found lags that are statistically significant. The thing that is unclear to me about the package that you chose is if it offers any adjustment/correction for multiple comparisons: https://en.wikipedia.org/wiki/Multiple_comparisons_problem

So I would be sure that indeed you have p-values that are much smaller than 0.05/(#of lags) to avoid this problem. That is to say make sure your p-values are below 0.05/4.

Granger Test interpretation


Liferay, ServiceBuilder, what's the scope for attributes userId, companyId, userId

Question: Although I've developed some services with Liferay ServiceBuilder, I'm not quite sure I understand the point of using the attributes:

userId
companyId
groupId
Note that these attributes are available through the PortalRequest.

Following the basic tutorials, you are instructed to create these attributes for every entity, and take care to set them on 'add' functions. But thinking of it, I've not ever seen any tutorial or referenced code where these attributes are used on data retrieval (Finder methods, dynamic queries, or custom queries either)
So what's the point on keeping this information ?

Are these attributes used automatically somehow under some convention or scope ? Something like, the Liferay's default Finders using them when they are available through the PortalRequest ?
Or is it up to the developer to use them on every Select, E.g. are all the single-parameter Finders practically useless on multi-instance Portals (since the companyId attribute should be used on every Finder method) ?
Or is it just a good practice to keep this structure for database extendability, auditing, indexing or something else I'm totally missing ?
Answer: These attributes are necessary when you use your entities for example on staging environment. The groupId specifies to which environment the entity belongs to. Meaning of userId is obvious and as for companyId it is the site identifier. So IMHO these attributes are quite important when you have multiple sites on one portal, when you have staging env. enabled etc..
Comment: I agree, userId is usually nice to be there for any type of application, while companyId and groupId are useful only when using multiple Sites Organizations etc
Answer: Suppose you have a new table and you want to set UserId in your table then it is necessary but otherwise I don't think these attributes are neccessary.
I have created service builder
<code><entity name="FaoEsalesCustomer" local-service="true" remote-service="false" table="fao_esalecustomer">
    <!-- PK fields -->
    <column name="esaleCustomerId" type="long" primary="true" />
    <!-- Audit fields -->
    <column name="createdBy" type="long" />
    <column name="createdOn" type="Date" />
    <column name="modifiedBy" type="long" />
    <column name="modifiedOn" type="Date" />
    <!-- Other fields -->
    <column name="customerName" type="String" />
    <column name="address" type="String" />
    <column name="ph" type="Integer" />
    <column name="categoryId" type="long" />
    <column name="categoryName" type="String" />
    <column name="quantity" type="Double" />
    <column name="price" type="Double" />
</entity>
</code>
Comment: I know, I have built Entities with and without these attributes. As a good Practice, i'm considering them as 'reserved' attribute names, add the proper values on 'add' functions,  and in case I want to relate the entity with a user, I'll use another attribute (instead of using 'userId'). I have no problem building Services, it's just that I wonder why I (and the tutorials) include these attributes without using actually them.


How to see that "two manifolds are diffeomorphic when you can give them each a coordinate atlas with the same transition maps"

Question: This question is about the diffeomorphism of $\mathbb{C}P^1$ and $S^2$. At the end of youler's answer, we read

"the general fact that two manifolds are diffeomorphic when you can give them each a coordinate atlas with the same transition maps."

I am not sure why this is true. I have not even a geometric intuition.
In my lecture notes, we were given the same example, up to showing that the two manifolds have the same transition maps. I think we are expected to understand that the transition maps imply that the two manifolds must be diffeomorphic to each other, but I don't see why.
If possible, I would like an intuitive reasoning, followed by a rigorous answer.
Answer: Suppose that $X, Y$ are manifolds with atlases $\{\phi_\alpha: \alpha\in A\}$ and $\{\psi_\alpha: \alpha\in A\}$ such that for any two pairs of indices $\alpha, \beta\in A$,
$$
\phi_\beta\circ \phi_\alpha^{-1}= \psi_\beta\circ \psi_\alpha^{-1}.
$$
Define the map $f: X\to Y$ by the formula
$$
f(x)=y
$$
whenever $\phi_\alpha(x)= \psi_\alpha(y)$ for any pair of charts with common index whose domains contains $x$ and $y$ respectively. The fact that the transition maps of the two atlases are the same implies that this map is well-defined (i.e. are  independent of the choice of the above charts). To see that this map is a diffeomorphism, one needs to check smoothness of this map (and of its inverse) in local coordinates, i.e. smoothness of compositions
$$
\psi_\alpha \circ f \circ \phi_\alpha^{-1}
$$
and
$$
\phi_\alpha \circ f^{-1} \circ \psi_\alpha^{-1}.
$$
But these compositions are equal the identity maps for every $\alpha\in A$. Hence, $f$ and its inverse  are diffeomorphisms. Thus, $f: X\to Y$ is a diffeomorphism.
The converse statement holds as well: Suppose that there is a diffeomorphism $f: X\to Y$. Then $X, Y$ can be equipped with atlases that have the same transition maps. Indeed, given an atlas $\{\psi_\alpha: \alpha\in A\}$ on $Y$, define charts on $X$ by the formula
$$
\phi_\alpha= \psi_\alpha\circ f.
$$
Direct computations shows that transition maps for the two atlases are the same.
Answer: Consider two manifolds $M$ and $N$, with atlases $\{(U_{\alpha}, \phi_{\alpha})\}$ and $\{(V_{\alpha}, \psi_{\alpha})\}$ respectively.  Let $\tau = \phi_{\beta} \circ\phi_{\alpha}^{-1}:\phi_{\alpha}(U_{\alpha}\cap U_{\beta})\rightarrow\phi_{\beta}(U_{\alpha}\cap U_{\beta})$ and $\xi=\psi_{\beta} \circ\psi_{\alpha}^{-1}:\psi_{\alpha}(V_1\cap V_{\beta})\rightarrow\psi_{\beta}(V_{\alpha}\cap V_{\beta})$ be the transition maps associated with each atlas.
If $\tau = \phi_{\beta} \circ\phi_{\alpha}^{-1} = \psi_{\beta} \circ\psi_{\alpha}^{-1} = \xi$, we then have $$\phi_{\beta}(U_{\alpha}\cap U_{\beta})=\psi_{\beta}(V_{\alpha}\cap V_{\beta}) \implies M \supset U_{\alpha}\cap U_{\beta}=V_{\alpha}\cap V_{\beta} \subset N,$$ since both $\phi_{\beta}$ and $\psi_{\beta}$ are homeomorphisms.
Let's denote this open set with $S=U_{\alpha}\cap U_{\beta}=V_{\alpha}\cap V_{\beta}$.
As stated in youler's answer, consider the map $\Phi:M \rightarrow N$, defined by $\Phi(\phi_{\alpha}^{-1}(S))=\psi_{\alpha}^{-1}(S)$. Its inverse $\Phi^{-1}:N \rightarrow M$, also exists and is defined by $\Phi(\psi_{\alpha}^{-1}(S))=\phi_{\alpha}^{-1}(S)$.  If we can somehow show that $\Phi$ and $\Phi^{-1}$ are both smooth... then indeed the two manifolds are diffeomorphic.


If two different statistics converge to a same function, does it mean both of them converge to a same distribution?

Question: Let $A(x)$ be a (deterministic) function, and let $A_n(x)$ and $A_n^*(x)$ be two different estimators of $A(x)$. Define $B_n=\sup|A_n-A|$ and $B_n^*=\sup|A_n^*-A|$. If for a sequence $(c_n)$ and a distribution function $F$

$B_n=o_p\left(\frac{1}{c_n}\right)$
$\lim\Pr(c_n B_n\leq x)=F(x)$
$\sup|A_n-A_n^*|=o_p\left(\frac{1}{c_n}\right)$

does it mean $\lim\Pr(c_n B_n^*\leq x)=F(x)$?
My answer is "yes", but my proof is kind of strange. Since we have
\begin{eqnarray*}
B_n^*\leq\sup|A_n^*-A_n|+\sup|A_n-A|=o_p\left(\frac{1}{c_n}\right),
\end{eqnarray*}
then it is abvious that $|B_n-B_n^*|=o_p\left(\frac{1}{c_n}\right)$. From this, if $n$ is large enough, then
\begin{eqnarray*}
\Pr(c_n B_n^*\leq x)=\Pr(c_n B_n\leq x)\rightarrow F(x).
\end{eqnarray*}
I think, my intuition is right, but the proof is too heuristic and not firm. Do you guys have any idea what is my mistake and how to fix it? Thank you so much
Answer: If $|B_n-B_n^{*}| = O_p \left( \frac{1}{c_n} \right)$ then $|c_nB_n-c_nB_n^{*}| = O_p \left( 1 \right)$. Since $|c_nB_n-c_nB_n^{*}|$ does not converge in probability to zero for large $n$, you cannot conclude that $Pr(c_nB_n^{*}\leq x)$ converges towards $Pr(c_nB_n\leq x)$.
Wikipedia defines the notation $o_p$ as follows:
$X_n=o_p(a_n) \ \text{ if } \ \lim_{n\rightarrow \infty}\mathrm{Pr}\left(\left|\frac{X_n}{a_n}\right|\geq \epsilon\right)=0$.
With this notation it can be deduced that $F(x)=0$ when $x<0$, that $F(x)=1$ when $x>0$ and that $\mathrm{Pr}(c_nB_n*\leq x)=F(x)$ when $x \ne 0$. However there exists a counterexample in the case when $x=0$.
Let $A(x)=0$, $A_n(x)=1$, $A_n^* (x)=0$ and $c_n=\frac{1}{n}$. It can be verified that all three conditions hold. Note that $c_nB_n=\frac{1}{n}$ and hence that $F(0)=\lim_{n\rightarrow\infty}\mathrm{Pr}(\frac{1}{n}\leq 0)=0$. On the other hand, $\mathrm{Pr}(c_nB_n^* \leq 0)=1$ since $B_n^*=0$. It follows that $\lim_{n\rightarrow\infty}\mathrm{Pr}(c_nB_n^*\leq 0)=1 \neq F(0)$.
Comment: Thank you so much for answering, but, it is not big-O, it's $|B_n-B_n^*|=o_p(c_n^{-1})$, little-o, so $|c_n B_n-c_n B_n^*|=o_p(1)$, and it will converge to $0$ in probability, so is my argument valid?


Using ColorBox to popup "iFrame" shows original page content after the "iFrame" data?

Question: I have a basic module that parses a JSON feed, stores it in cache, then shows a "gallery" of the objects - I know I should have maybe stored these as Nodes but it was supposed to be a quick simple module...
Anyway, it works well except, when I click on one of the objects in the gallery, I have it linked to an "iFrame" (which I cached too, but it's not really a real page) found at:
the_page?iFrame-id="theDataID" - these all popup in ColorBox and the HTML from the cache for the "iFrame" is displayed.
This worked well on the dev site, however for the production site - it uses different modules and templates (which I didn't have access to for setting up the dev site).
Now when you click on an object, the ColorBox popup shows the data, except it then shows the original pages' content and I haven't been able to figure out why it does that. I assume the prod site must try to always load the "original content" based on the URL and therefore "ignores" the ?iFrame-id part?
So basically, in my code for the iFrame, I do:
echo $data;
return;

Which causes the data to be printed above the normal pages' content in the popup. So I changed it to:
return $data;

But that caused the data to show up as the pages' content, and I still had the header/footer for Drupal.
Anyone have any ideas?
Another way I could do this is by using ColorBox's inline option instead of the iframe option, however I assume that would require all the data for the objects to be on the page? As right now, the content is loaded dynamically on popup (it doesn't exist anywhere in the DOM before hand).
Answer: OK, so originally I had tried echo $data; then return;
I then tried: return $data; but that kept showing the header/footer.
I've found that this works well:
echo $data;
die;

Though it's probably not the best way to do it, but it works for the way the module was wrote... should really use the Node/Entity API next time :)


How can I create an object and add attributes to it?

Question: I want to create a dynamic object in Python and then add attributes to it. This didn't work:
obj = object()
obj.somefield = "somevalue"

AttributeError: 'object' object has no attribute 'somefield'

For details on why it doesn't work, see Can't set attributes on instance of "object" class.
Comment: Why are you doing this?  A generic "object" has no actual *meaning*.  What is the *meaning* of the thing you are creating?  Why is it not a proper class or namedtuple?
Comment: The example is not minimal and confusing for me or I just don't see why you don't work with some `a = object()` and you need `obj.a = object()`. Again I am talking about the example, in your actual code an object inside an object might be useful.
Answer: The built-in object can be instantiated but can't have any attributes set on it.  (I wish it could, for this exact purpose.)  This is because it doesn't have a __dict__ to hold the attributes.

I generally just do this:
class Object(object):
    pass

obj = Object()
obj.somefield = "somevalue"

But consider giving the Object class a more meaningful name, depending on what data it holds.

Another possibility is to use a sub-class of dict that allows attribute access to get at the keys:
class AttrDict(dict):
    def __getattr__(self, key):
        return self[key]

    def __setattr__(self, key, value):
        self[key] = value

obj = AttrDict()
obj.somefield = "somevalue"

To instantiate the object attributes using a dictionary:
d = {"a": 1, "b": 2, "c": 3}

for k, v in d.items():
    setattr(obj, k, v)

Comment: it *can* be instantiated, just not used for anything useful once it has been done.  `foo = object()` works, but you just can't do much of anything with it
Comment: great answer, the only thing I changed was to use `Struct` as the name of the class to make it more obvious. Saved me a ton of typing `["` and `"]`, Cheers!
Answer: You could use my ancient Bunch recipe, but if you don't want to make a "bunch class", a very simple one already exists in Python -- all functions can have arbitrary attributes (including lambda functions).  So, the following works:
obj = lambda: None
obj.somefield = 'somevalue'

Whether the loss of clarity compared to the venerable Bunch recipe is OK, is a style decision I will of course leave up to you.
Comment: @naught101, avoiding the creation of a new type (reusing an existing one) does not complicate, it simplifies.  Nowadays on might actually prefer `from argparse import Namespace` though I wish it lived elsewhere *e.g, `collection`) -- again reusing a now-existing type, just a better one, and still avoiding new-type creation.  But, it wasn't there then:-).
Comment: @naught101, a function **is** an object, in Python, so your objection is unfathomable.
Comment: I was looking for exactly this functionality, but `from argparse import Namespace` is so counter intuitive. Has it ever been suggested to move it, indeed, to `collections`?
Comment: See answer below from "J F Sebastian" regarding SimpleNamespace from the types module. If your version of python supports it, this is the best solution (and exactly what SimpleNamespace is designed for)
Comment: @AlexMartelli Except that dynamically slapping more attributes onto some object that happens to be a callable has nothing to do with lambda calculus and is by all means "hacky" - abusing some random object that had no intention of being a dictionary for you, but just so happens to work. Not that I don't like lambda calculus. I really do.
Comment: Dude, the OP's question clearly implies that `someobject` has been previously set -- indeed it STARTS by assigning it.
Comment: And in some cases, considering whether or not the `lambda` pattern fits for your use case may lead you to realize that something you'd originally thought of as data is actually more like a function anyway--or, in any case, a functor.
Comment: but... then obj.a is a *function*, not an object. This makes no sense, compared to FogleBird's answer.
Comment: @AlexMartelli: yes, obviously just about everything in python is an object. So why complicate things? it just adds a whole lot of unnecessary attributes and methods, and makes it uselessly callable...
Comment: @schatten, I don't know -- I haven't followed the python-ideas mailing list in a while -- I'm still mostly using Python 2.7 and my own ancient `Bunch` recipe anyway, and any changes in 3.5 or later would not benefit me for quite a while:-).  BTW, I believe the Python standard library has other (essentially) implementations of Bunch, too -- `argparse.Namespace` is just one of them.
Comment: @AlexMartelli could have even gone deeper there, 23 itself can be expressed as a bunch of functions. see "church encoding" :)
Comment: It became a pip package at some point :) https://pypi.python.org/pypi/bunch
Comment: @AlexMartelli The way Python's lambda is being used here has nothing to do with the way functions work in the lambda calculus.
Comment: This answrer from @AlexMartelli should not be marked as correct: `NameError: name 'someobject' is not defined`
Answer: There is types.SimpleNamespace class in Python 3.3+:
obj = someobject
obj.a = SimpleNamespace()
for p in params:
    setattr(obj.a, p, value)
# obj.a.attr1

collections.namedtuple, typing.NamedTuple could be used for immutable objects. PEP 557 -- Data Classes  suggests a mutable alternative.
For a richer functionality, you could try attrs package. See an example usage. pydantic may be worth a look too.
Comment: If you need something that works with Python 2.7, you can also try the `argparse.Namespace` class
Comment: @Roel `attrs` package supports Python 2.7
Comment: This seems a better solution to me than unittest.mock; the latter is a bit too heavy-weight and a bit more malleable. With a mock object, simply assigning to an attribute will cause it to spring into existence; SimpleNamespace will resist that.
Answer: You can also use a class object directly; it creates a namespace:
class a: pass
a.somefield1 = 'somevalue1'
setattr(a, 'somefield2', 'somevalue2')

Comment: I don't understand why this is not the top answer?
Comment: @KarlKnechtel This answer uses a custom class directly, while the top answer instantiates a custom class.
Comment: @confiq it doesn't say anything that the top answer is missing.
Comment: Easy to make mistakes with this (e.g. reusing the class). Instantiating an object is much more robust.
Answer: The mock module is basically made for that.
import mock
obj = mock.Mock()
obj.a = 5

Comment: `unittest.Mock` is a part of the standard library since Python 3.3 (https://docs.python.org/3/library/unittest.mock.html)
Comment: Disadvantge is that's an external dependency
Comment: Depends on the usage of your code I think. If it is production code, I would not want some `mock` in it. Just feels weird to me.
Answer: There are a few ways to reach this goal.
Basically you need an object which is extendable.
obj = type('Test', (object,), {})
obj.b = 'fun'

obj = lambda:None
obj.b = 'fun'

class Test:
  pass

obj = Test()
obj.b = 'fun'

Comment: `obj.a = type('', (), {})`
Answer: Now you can do (not sure if it's the same answer as evilpie):
MyObject = type('MyObject', (object,), {})
obj = MyObject()
obj.value = 42

Comment: @evilpie's answer sets attributes directly on MyObject (the class), not its instance like yours.
Answer: Try the code below:
$ python
>>> class Container(object):
...     pass
...
>>> x = Container()
>>> x.a = 10
>>> x.b = 20
>>> x.banana = 100
>>> x.a, x.b, x.banana
(10, 20, 100)
>>> dir(x)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__',     '__sizeof__',
'__str__', '__subclasshook__', '__weakref__', 'a', 'b', 'banana']

Comment: @DeadChex Clearly it creates a new Class(object) which is a empty class with object properties, and stores the attributes inside the class. This is even better than install more modules, or rely in lambdas.
Comment: Not sure why this does not have more upvotes. Is there a reason not to use this for a basic container class? Seems to work fine in Python 2.7, 2.6, and 3.4
Comment: Can you explain more of what this does? while the code may be useful for solving this problem, having it explained can go a lot further than just one problem.
Comment: So how does this set the value of an attribute whose name is contained in a separate variable?
Answer: as docs say:

Note: object does not have a __dict__, so you can't assign arbitrary attributes to an instance of the object class.

You could just use dummy-class instance.
Answer: These solutions are very helpful during testing. Building on everyone else's answers I do this in Python 2.7.9 (without staticmethod I get a TypeError (unbound method...):
In [11]: auth = type('', (), {})
In [12]: auth.func = staticmethod(lambda i: i * 2)
In [13]: auth.func(2)
Out[13]: 4

Answer: If we can determine and aggregate all the attributes and values together before creating the nested object, then we could create a new class that takes a dictionary argument on creation.
# python 2.7

class NestedObject():
    def __init__(self, initial_attrs):
        for key in initial_attrs:
            setattr(self, key, initial_attrs[key])

obj = someobject
attributes = { 'attr1': 'val1', 'attr2': 'val2', 'attr3': 'val3' }
obj.a = NestedObject(attributes)
>>> obj.a.attr1
'val1'
>>> obj.a.attr2
'val2'
>>> obj.a.attr3
'val3'

We can also allow keyword arguments. See this post.
class NestedObject(object):
    def __init__(self, *initial_attrs, **kwargs):
        for dictionary in initial_attrs:
            for key in dictionary:
                setattr(self, key, dictionary[key])
        for key in kwargs:
            setattr(self, key, kwargs[key])

obj.a = NestedObject(attr1='val1', attr2='val2', attr3= 'val3')

Answer: To create an object from a dictionary:
class Struct(object):
    def __init__(self, d):
        for key in d.keys():
            self.__setattr__(key, d[key])

Usage:
>>> obj = Struct({'a': 1, 'b': 2})
>>> obj.a
1

Comment: Another way is `types.SimpleNamespace(**d)`.
Comment: Thanks for sharing! This is why I always scroll down.
Answer: Which objects are you using? Just tried that with a sample class and it worked fine:
class MyClass:
  i = 123456
  def f(self):
    return "hello world"

b = MyClass()
b.c = MyClass()
setattr(b.c, 'test', 123)
b.c.test

And I got 123 as the answer.
The only situation where I see this failing is if you're trying a setattr on a builtin object.
Update: From the comment this is a repetition of: Why can't you add attributes to object in python?
Comment: b.c is set to object() not a defined class
Answer: I think the easiest way is through the collections module.
import collections
FinanceCtaCteM = collections.namedtuple('FinanceCtaCte', 'forma_pago doc_pago get_total')
def get_total(): return 98989898
financtacteobj = FinanceCtaCteM(forma_pago='CONTADO', doc_pago='EFECTIVO',
                                get_total=get_total)

print financtacteobj.get_total()
print financtacteobj.forma_pago
print financtacteobj.doc_pago

Answer: if you are looking for chain assignment, to do things such as django model template abstract attribute assigning:
from types import SimpleNamespace

def assign(target, *args, suffix):
    ls = target
    for i in range(len(args) - 1):
        a = args[i]
        ns = SimpleNamespace()
        setattr(ls, a, ns)
        ls = ns
    setattr(ls, args[-1], suffix)
    return ls

a = SimpleNamespace()
assign(a, 'a', 'b', 'c', suffix={'name': 'james'})
print(a.a.b.c)
# {'name': 'james'}

which allows you to pass model as a target, and assign end attribute to it.
Answer: Coming to this late in the day but here is my pennyworth with an object that just happens to hold some useful paths in an app but you can adapt it for anything where you want a sorta dict of information that you can access with getattr and dot notation (which is what I think this question is really about):
import os

def x_path(path_name):
    return getattr(x_path, path_name)

x_path.root = '/home/x'
for name in ['repository', 'caches', 'projects']:
    setattr(x_path, name, os.path.join(x_path.root, name))

This is cool because now:
In [1]: x_path.projects
Out[1]: '/home/x/projects'

In [2]: x_path('caches')
Out[2]: '/home/x/caches'

So this uses the function object like the above answers but uses the function to get the values (you can still use (getattr, x_path, 'repository') rather than x_path('repository') if you prefer).
Answer: di = {}
for x in range(20):
    name = '_id%s' % x
    di[name] = type(name, (object), {})
    setattr(di[name], "attr", "value")

Answer: Other way i see, this way:
import maya.cmds

def getData(objets=None, attrs=None):
    di = {}
    for obj in objets:
        name = str(obj)
        di[name]=[]
        for at in attrs:
            di[name].append(cmds.getAttr(name+'.'+at)[0])
    return di

acns=cmds.ls('L_vest_*_',type='aimConstraint')
attrs=['offset','aimVector','upVector','worldUpVector']

getData(acns,attrs)

Comment: This is adding a very big non-standard dependency while a simple `class a: pass` gives all the power required.
Comment: you can add in append the name attr this di[name].append([at,cmds.getAttr(name+'.'+at)[0]])


Do bass notes basically just accent and/or add notes to the above harmony?

Question: I'm trying to understand how the bass timbre folds into the harmony.
I understand doubling more dissonant intervals is generally bad unless creating a cool melody.  Is this basically because it's "accenting" a dissonance in the harmony??
Is adding a note that isn't in an above harmony basically just adding a note to a chord??  Say:  If there's a C5 playing... and the bass plays a D in a lower octave... does the overall harmony function as a Csus2??
Does the timbre and the distance of the bass make this not work??
Comment: Depends on what you want to do with it, so you might want to give us a bit of context. If, for instance, you were in G and holding the D as a dominant pedal point, this would just be "business as usual" - all kinds of things find themselves over pedal points, often more dissonant than this would be. In classical music, this would be a ninth in the bass, and that was considered a real no-no (except that Schoenberg used one in Verklärte Nacht and it worked beautifully). It's a truism, but it really does depend on how you use it.
Answer: I would be careful of how you use the word timbre, which refers to the quality of the sound.
There are several embedded questions here, and I will try to address them.

Most doubling rules apply to voice-leading, and the treatment of the bass is integral into creating a satisfactory and refined sound.  Instead of "accent" I would use the word "emphasize" which is a subtle difference.
Bass register very typically serves as the aural foundation.  So, whatever note is put in the bass,  the other notes will be heard in reference to the lowest pitch, regardless of whether or not they are functional, and regardless of whether or not you want them to be; it's just the way things work.
It is impossible to discuss harmonic function without understanding contextual harmonic motion. I want to clarify for other readers that "C5" refers to a specific guitar chord-shape.  With a "D" in the bass, it wouldn't be heard as a suspension unless there was an anticipation in the bass, followed by the actual suspension, and then resolved by downward motion to a resolution.  Downward basslines are very popular, though not usually achieved through suspension and resolution.
Bass is your stability, and to suspend it would be to suspend your foundation, which creates a certain effect.
Your question of whether or not it works is subjective - it depends on what you're trying to do.  If you're trying to destabilize your bass and blur harmonic function, then yes, it would work.  Otherwise, it just sounds like a Dm11 with some omitted notes.
Answer: Listen to, oh, I dunno...Paul McCartney.  He's ALL OVER THE PLACE in terms of busy lines.  And his stuff works great.
One of the issues with catching tension notes in the bass is the concept of "low interval limits."  What happens when you violate low interval limits, is that the interval that you're playing ceases to sound like that interval, instead sounding like an awful wolf-tone-ish thing.  So there's only so low you can go with, say, a 9th tension, before it starts to sound like mush and nonsense.


Why does American traditional music (e.g. old-time fiddle, folk, bluegrass, etc.) exclude drumming?

Question: I'm a trained percussionist who for years has appreciated traditional American folk music. I've also been frustrated for years by the complete lack of any drums in this music. I've searched the web and found no good answers.
I recognize any answer would be necessarily complex and have to take into account the evolution of music in Western culture. But that's no excuse for there being no answer...
There are many responses to my question that I consider unsatisfactory. These answers include things like...
• The melody and harmony itself is rhythmic! There's no need for drums! (Sorry, weak answer--there is plenty of rhythmic melody and harmony in music from cultures where drums also play a big role. The presence or absence of rhythm in melody and harmony is irrelevant to the presence or absence of drums.)
• There are "drums" in American folk music---just look at the spoons, the washboard, clogging and flatfoot dancing, etc. (Sorry, another weak answer, because while they're all forms of percussion, none of these are drums.)
• Nobody could build or play drums in the hollows of Appalachia, so they didn't have them! (Sorry, another weak answer--if people could make and learn to play a fiddle, they could easily make and learn to play a drum!)
• Drums just aren't needed in American folk music--it sounds good without them! (Again, another weak, subjective answer--fiddles and gutbuckets are no more or less "needed" than drums in this music.)
As I mentioned above, there are plenty of cultures around the world whose music has everything American folk music has (melody, modality, simplicity, etc.) yet in many of these cultures drums also play a key role. So why not in American folk music?
Did early Americans (or the Scots/Irish/English/Dutch/Germans who emigrated to America) have something against drums? Were they considered "primitive" or "evil?"
The same question can be asked of folk music of the British Isles, which is also devoid of any drumming. The one notable exception to all of this, of course, is the bodhran in Irish music. And the popularity of the bodhran suggests that there is no inherent bias against drums in this music. The bodhran fits in beautifully and plays an integral role in Irish music. So how or why did the "drumming influence" of the bodhran not spread to other forms of folk music?
Were early Anglo-Saxons so daft that it never occurred to a single one of them to beat on something with their hands or sticks to create rhythm? (Conversely, how exactly did drums evolve to be such a central instrument in African, Indian, Chinese and Japanese music? Were these people smarter than early Anglo-Saxons and just figured out how to make and play drums where the Anglos didn't?)
Discussion and speculation (and facts too, of course) are appreciated! :-) (And please try to avoid posts like "American folk music doesn't have drums because it doesn't have drums. It's different." This much is clear--but I'd like to dig a bit deeper!)
Comment: Fascinating question - especially the aspect as to why much folk music of the British Isles doesn't make much use of drums! Unfortunately the most obvious - and sinister - part of the reason why American folk music as a *whole* doesn't feature a lot of drums is that many plantation owners saw fit to ban African slave workers from playing them. TED talk: https://www.youtube.com/watch?v=YLG871tKZUM
Comment: @AlexBasson I think that phrase is a little tongue-in-cheek; if it seems offensive when taken literally, it's better take it as a joke (and an invitation to give an answer containing the 'real' reason!)
Comment: Frankly, I find this question offensive. Were the early Anglo-Saxons daft or Eastern people smarter? No, of course not. Were Bach, Mozart, and Beethoven idiots because their music doesn't feature a lot of drums? C'mon. American folk music doesn't have drums because they didn't want drums. It doesn't feature a lot of flutes, either, even though flutes are pretty cheap and easy to make. If they had wanted drums, they would have included them.
Comment: Apologies to anyone who found my original post offensive. When I wondered if Europeans were "daft" it was tongue-in-cheek (I know they certainly weren't daft!). Alex's excellent answer below notwithstanding, I do believe the general question of why drumming traditions have thrived in many cultures around the world and not in others is a valid one that has not been sufficiently explored. Even the American drumset tradition (which evolved from early jazz) pales compared to the percussive traditions of India, Indonesia, African countries, etc.
Comment: Of note: those large drums I see and hear every Chinese New Year's celebration look and sound a *lot* like taiko drums, which are Japanese. I therefore believe that Chinese and Japanese music traditions influenced each other.
Comment: @AlexBasson Raises a good point. American folk music is noticeably bereft of mouth blown instruments as well. One thing to think about related to this is the American culture that has being created by European settlers/invaders is only about 400 years old at most, which makes it a relatively young culture in the world. Note that "discussion and speculation" are not what Stack Exchange is for.
Comment: I'm downvoting because of your apparent arrogant attitude as to instrumentation.  If you rewrite I'll vote back up.   You gonna dump on Haydn's chamber music because it doesn't have drums too?
Comment: @CarlWitthoft I somewhat agree, and that's why I changed "lame" to "weak", among other slight restatements. I dislike noncommital, trivial-to-the-point-of-not-answering-the-question, and sometimes completely factually incorrect answers; however, there is a hint of superiority from the question that I tried to eliminate. OP has good points, and I love the question, but I agree with you in that it was asked in a somewhat patronising manner.
Comment: Please listen to Reich's 'Drumming'. Yes, it belongs to one of the most American genres, minimalism.
Comment: Would a drum survive the dryness? Isn't a drum basically wood, metal and skin? (Also feels like getting skin is kind of hard, you basically have to be a hunter or cattlefarmer?)
Answer: I'm sorry you don't find "spoons, washboards, and flatfoot dancing" an acceptable answer. I would invite you to consider that spoons, washboards, and feet all feature some things in common that drums do not—they're inexpensive, they don't take up much space, they're very portable, and they're ubiquitous—every household, even in impoverished Appalachia, had spoons, washboards, and feet. When I see a folk music tradition create percussion using common household implements and their own body parts, the conclusion seems obvious: they were making do with what they had.
Update: Longer, more involved answer
To begin with, let's acknowledge that there is no one such thing as American traditional music. At a minimum, American traditional music includes:

Cajun Zydeco (which features drums)
Mississippi Delta Blues (mostly solo acoustic guitar)
Chicago Electric Blues (again, features drums)
Appalachian String Band (umbrella term for old time & bluegrass)
New Orleans Jazz (drums optional)
Kansas City (and then Harlem Renaissance, etc.) Jazz (drums prominently featured)

You're asking primarily about Appalachian String Band music and why that music doesn't feature drums.
Ok. Consider who created that music and their circumstances. The Appalachian settlers were primarily Scots-Irish fleeing extreme poverty and persecution by the British.
If you were one of those immigrants, imagine the circumstances of your journey—you're extremely poor and you'll arrive having traveled across an ocean owning only what you were able to carry. Fiddles are small. You could maybe carry a fiddle. Drums, though? Probably not.
And so now you've settled in Appalachia. You're still extremely poor, as is everyone around you, but some people have fiddles, and everyone has spoons, washboards, and feet. So on Saturday nights everyone gathers around and makes the most of what they've got, and a folk music tradition is born.
In the comments, I see a question about guitars, banjos, and bass fiddles. Those came later. Banjos and steel-string guitars are both American innovations—banjos, in particular, come from the African-American slave tradition and were originally made from gourds. And bass fiddles are rare in old-time folk music until much later. Even today, it's quite common to show up to an old-time jam and find numerous fiddles and guitars, but no basses (that's why, despite the fact that I play guitar and banjo pretty well, I always go to a jam with a bass, because I'm almost always the only bass there).
In short: folk music (almost by its very definition) is the outcome of a people making the music they liked with the tools available to them. Poverty-stricken Scots-Irish Appalachian farmers had fiddles, spoons, washboards, and feet, and they built a folk music tradition from those tools on hand.
Comment: @ScottWilkinson Honestly, the more I think about it the more I'm even more intrigued by the lack of flutes in Appalachian folk music. Flutes were prominent back home in Ireland, and moreover they were small and easy to make from readily-available materials. So why didn't a flute tradition survive immigration?
Comment: @marcellothearcane Yes, it's an American folk term for double bass.
Comment: Why did they have fiddles, guitars, bass fiddles, and banjos? Certainly a bass fiddles are larger and less portable than many types of drum.
Comment: Further,  "spoons, washboard," etc. qualify as percussion instruments, of which the vague term "drums" is a subset in any case.
Comment: May be they were afraid that the indian tribesmen could misunderstand the message :)
Comment: Thanks Alex for your excellent answer! I appreciate it. I think you're spot-on with regard to the impoverished circumstances of early Appalachians and their need to travel through difficult terrain making drums impractical. As a drummer who has spent thousands of hours hauling them around, it's not easy. Two points though: frame drums (like the bodhran) can be smaller and lighter than a banjo or fiddle—and easier to carry. These appear in musical cultures around the world—why not Appalachian? Also (mentioned above) why no drum tradition in the British Isles?
Comment: @Alex Basson I agree, the flute question is intriguing too! And I really think that, to a certain extent, there may be no "good" reason for these evolutionary developments (or lack thereof) that the tendency among humans to "go with the herd." If nobody saw any other musical ensembles using a flute or a drum, they were far more likely to do without themselves rather than "buck the system" by introducing a new instrument. (Yes, just speculation.)
Comment: When you say bass fiddle, is this an American folk term for a cello or double bass?
Comment: Interesting! I haven't come across that before.
Comment: A lot of Scots/Irish also brought their drum - a bodhrán - which is not very big. Although not used much in Old Time music these same people had Irish/Scottish sessions (esp in the Northeast, like Boston) with their drum an integral part.
Answer: Drums are too loud to compete in small groups of acoustic players and non-operatic voices. Especially inexpensive instruments.
This is from my personal experience playing with and without a drummer.
Answer: The music that you are referring to is mostly that derived from country dance music of Britain and Ireland.
In the history of that tradition, drums have not played any significant role. This was a pattern set down before English, Scottish or Irish settlers came to America.
In the dance traditions of Britain and Ireland, the tune is the thing. A single fiddle can give all the rhythm, lift and phrasing needed for a dance. It is complete, nothing needs to be added ... though of course we do.
As for the bodhran, it is an instrument that was introduced into Irish traditional music in the 1950s, primarily by Seán Ó Riada. So dump all that nonsense about "Anglo-Saxons" and "Celts", it's got nothing to do with them in terms of either drums, music or dance.
There were traditions of playing drums in Britain and Ireland. Drums were used in military music, and in theatre and concert music. Also think of a tradition like that of the Lambeg drums. There was also the widely played small tabor drum and three-holed (tabor pipe) pipe that was often used for Morris Dance.
So, the answer is that drums were not really used in the country dance music of the 17th, 18th, and 19th centuries. The settlers who brought this music to America in those centuries did not have a tradition of playing drums. It may confuse or perplex you, but that's just the way is was (and often still is).
Answer: I think fife and drum music would be the genre with exactly what you are looking for.
I don't know if you would exclude that genre for some reason (martial music, the tunes aren't specifically American origin, etc?) but it seems that a lot of the repertoire in that genre includes popular folk tunes, and of course, there are bona fide drums.
Answer: Many times bass sound was add by a bucket bass with a wire and a broom handle for pitch changing. Making an adequate drum head though involved time and effort to scrape hides stretch and cure and secure to a hollow wood chamber. Calfskin is dramatically affected by humidity so small hand drums were more common in the Scottish traditions. Western Cowboy and Appalachian traditional music didn't embrace drums until the 20th century. It's not weird it's just the way things were settled and it hung on. TRADITION! (sucks)


Grunt Serve Dist is not minifying scripts imported through lazy loading

Question: I'm using Yeoman, Grunt and bower for my AngularJS application. It's working fine. I'm using bootstrap, Angular bootstrap, Angular Toaster and few other bower components. But when I do grunt serve:dist, it is not adding all files and also not minifying the scripts which are imported in views (HTML files other   than index.html) through lazy loading.
Here is my index.html

<link rel="stylesheet"
    href="bower_components/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet"
    href="bower_components/bootstrap/dist/css/bootstrap-theme.css" />
<link rel="stylesheet"
    href="bower_components/angular-ui-select/dist/select.css" />
<link rel="stylesheet"
    href="bower_components/angular-toastr/dist/angular-toastr.css" />

<link rel="stylesheet" href="styles/select2.css" />
<link rel="stylesheet" href="styles/select2-bootstrap.css" />
<link rel="stylesheet" href="styles/selectize.bootstrap3.css" />

<link rel="stylesheet" href="styles/app-style.css">
<link rel="stylesheet" href="styles/app-theme.css">
<link rel="stylesheet" href="styles/animate.css">

When I do grunt serve:dist index.html gets updated. It removes CSS imports
inside bower:css and endbower. it removes the bootstrap CSS and only have the following.
<link rel="stylesheet"
    href="bower_components/angular-ui-select/dist/select.css" />
<link rel="stylesheet"
    href="bower_components/angular-toastr/dist/angular-toastr.css" />

I'm lading my controllers through lazy loading. My login.html is like following.

In grunt serve:dist, it minifies the HTML. but it is not updating the import file name or the file is not copying to scripts folder.

Why it's not minifying all? or changing bower components in index? How to solve it?
Here is the Gruntfile.js
// Generated on 2015-07-06 using generator-angular 0.11.1
'use strict';

// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'

module.exports = function (grunt) {

  // Load grunt tasks automatically
  require('load-grunt-tasks')(grunt);

  // Time how long tasks take. Can help when optimizing build times
  require('time-grunt')(grunt);

  // Configurable paths for the application
  var appConfig = {
    app: require('./bower.json').appPath || 'app',
    dist: 'dist'
  };

  // Define the configuration for all the tasks
  grunt.initConfig({

    // Project settings
    yeoman: appConfig,

    // Watches files for changes and runs tasks based on the changed files
    watch: {
      bower: {
        files: ['bower.json'],
        tasks: ['wiredep']
      },
      js: {
        files: ['<%= yeoman.app %>/scripts/**/*.js'],
        tasks: ['newer:jshint:all'],
        options: {
          livereload: '<%= connect.options.livereload %>'
        }
      },
      jsTest: {
        files: ['test/spec/**/*.js'],
        tasks: ['newer:jshint:test', 'karma']
      },
      styles: {
        files: ['<%= yeoman.app %>/styles/**/*.css'],
        tasks: ['newer:copy:styles', 'autoprefixer']
      },
      gruntfile: {
        files: ['Gruntfile.js']
      },
      livereload: {
        options: {
          livereload: '<%= connect.options.livereload %>'
        },
        files: [
          '<%= yeoman.app %>/**/*.html',
          '.tmp/styles/**/*.css',
          '<%= yeoman.app %>/images/**/*.{png,jpg,jpeg,gif,webp,svg}'
        ]
      }
    },

    // The actual grunt server settings
    connect: {
      options: {
        port: 9000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname: 'localhost',
        livereload: 35729
      },
      livereload: {
        options: {
          open: true,
          middleware: function (connect) {
            return [
              connect.static('.tmp'),
              connect().use(
                '/bower_components',
                connect.static('./bower_components')
              ),
              connect().use(
                '/app/styles',
                connect.static('./app/styles')
              ),
              connect.static(appConfig.app)
            ];
          }
        }
      },
      test: {
        options: {
          port: 9001,
          middleware: function (connect) {
            return [
              connect.static('.tmp'),
              connect.static('test'),
              connect().use(
                '/bower_components',
                connect.static('./bower_components')
              ),
              connect.static(appConfig.app)
            ];
          }
        }
      },
      dist: {
        options: {
          open: true,
          base: '<%= yeoman.dist %>'
        }
      }
    },

    // Make sure code styles are up to par and there are no obvious mistakes
    jshint: {
      options: {
        jshintrc: '.jshintrc',
        reporter: require('jshint-stylish')
      },
      all: {
        src: [
          'Gruntfile.js',
          '<%= yeoman.app %>/scripts/**/*.js'
        ]
      },
      test: {
        options: {
          jshintrc: 'test/.jshintrc'
        },
        src: ['test/spec/**/*.js']
      }
    },

    // Empties folders to start fresh
    clean: {
      dist: {
        files: [{
          dot: true,
          src: [
            '.tmp',
            '<%= yeoman.dist %>/**/*',
            '!<%= yeoman.dist %>/.git**/*'
          ]
        }]
      },
      server: '.tmp'
    },

    // Add vendor prefixed styles
    autoprefixer: {
      options: {
        browsers: ['last 1 version']
      },
      server: {
        options: {
          map: true,
        },
        files: [{
          expand: true,
          cwd: '.tmp/styles/',
          src: '**/*.css',
          dest: '.tmp/styles/'
        }]
      },
      dist: {
        files: [{
          expand: true,
          cwd: '.tmp/styles/',
          src: '**/*.css',
          dest: '.tmp/styles/'
        }]
      }
    },

    // Automatically inject Bower components into the app
    wiredep: {
      app: {
        src: ['<%= yeoman.app %>/index.html'],
        ignorePath:  /\.\.\//
      },
      test: {
        devDependencies: true,
        src: '<%= karma.unit.configFile %>',
        ignorePath:  /\.\.\//,
        fileTypes:{
          js: {
            block: /(([\s\t]*)\/{2}\s*?bower:\s*?(\S*))(\n|\r|.)*?(\/{2}\s*endbower)/gi,
              detect: {
                js: /'(.*\.js)'/gi
              },
              replace: {
                js: '\'{{filePath}}\','
              }
            }
          }
      }
    },

    // Renames files for browser caching purposes
    filerev: {
      dist: {
        src: [
          '<%= yeoman.dist %>/scripts/**/*.js',
          '<%= yeoman.dist %>/styles/**/*.css',
          '<%= yeoman.dist %>/images/**/*.{png,jpg,jpeg,gif,webp,svg}',
          '<%= yeoman.dist %>/styles/fonts/*'
        ]
      }
    },

    // Reads HTML for usemin blocks to enable smart builds that automatically
    // concat, minify and revision files. Creates configurations in memory so
    // additional tasks can operate on them
    useminPrepare: {
      html: '<%= yeoman.app %>/index.html',
      options: {
        dest: '<%= yeoman.dist %>',
        flow: {
          html: {
            steps: {
              js: ['concat', 'uglifyjs'],
              css: ['cssmin']
            },
            post: {}
          }
        }
      }
    },

    // Performs rewrites based on filerev and the useminPrepare configuration
    usemin: {
      html: ['<%= yeoman.dist %>/**/*.html'],
      css: ['<%= yeoman.dist %>/styles/**/*.css'],
      options: {
        assetsDirs: [
          '<%= yeoman.dist %>',
          '<%= yeoman.dist %>/images',
          '<%= yeoman.dist %>/styles'
        ]
      }
    },

    // The following *-min tasks will produce minified files in the dist folder
    // By default, your `index.html`'s  will take care of
    // minification. These next options are pre-configured if you do not wish
    // to use the Usemin blocks.
    // cssmin: {
    //   dist: {
    //     files: {
    //       '<%= yeoman.dist %>/styles/main.css': [
    //         '.tmp/styles/{,*/}*.css'
    //       ]
    //     }
    //   }
    // },
    // uglify: {
    //   dist: {
    //     files: {
    //       '<%= yeoman.dist %>/scripts/scripts.js': [
    //         '<%= yeoman.dist %>/scripts/scripts.js'
    //       ]
    //     }
    //   }
    // },
    // concat: {
    //   dist: {}
    // },

    imagemin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>/images',
          src: '**/*.{png,jpg,jpeg,gif}',
          dest: '<%= yeoman.dist %>/images'
        }]
      }
    },

    svgmin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>/images',
          src: '**/*.svg',
          dest: '<%= yeoman.dist %>/images'
        }]
      }
    },

    htmlmin: {
      dist: {
        options: {
          collapseWhitespace: true,
          conservativeCollapse: true,
          collapseBooleanAttributes: true,
          removeCommentsFromCDATA: true,
          removeOptionalTags: true
        },
        files: [{
          expand: true,
          cwd: '<%= yeoman.dist %>',
          src: ['*.html', 'views/**/*.html'],
          dest: '<%= yeoman.dist %>'
        }]
      }
    },

    // ng-annotate tries to make the code safe for minification automatically
    // by using the Angular long form for dependency injection.
    ngAnnotate: {
      dist: {
        files: [{
          expand: true,
          cwd: '.tmp/concat/scripts',
          src: '*.js',
          dest: '.tmp/concat/scripts'
        }]
      }
    },

    // Replace Google CDN references
    cdnify: {
      dist: {
        html: ['<%= yeoman.dist %>/*.html']
      }
    },

    // Copies remaining files to places other tasks can use
    copy: {
      dist: {
        files: [{
          expand: true,
          dot: true,
          cwd: '<%= yeoman.app %>',
          dest: '<%= yeoman.dist %>',
          src: [
            '*.{ico,png,txt}',
            '.htaccess',
            '*.html',
            'views/**/*.html',
            'images/**/*.{webp}',
            'styles/fonts/**/*.*'
          ]
        }, {
          expand: true,
          cwd: '.tmp/images',
          dest: '<%= yeoman.dist %>/images',
          src: ['generated/*']
        }, {
          expand: true,
          cwd: 'bower_components/bootstrap/dist',
          src: 'fonts/*',
          dest: '<%= yeoman.dist %>'
        }]
      },
      styles: {
        expand: true,
        cwd: '<%= yeoman.app %>/styles',
        dest: '.tmp/styles/',
        src: '**/*.css'
      }
    },

    // Run some tasks in parallel to speed up the build process
    concurrent: {
      server: [
        'copy:styles'
      ],
      test: [
        'copy:styles'
      ],
      dist: [
        'copy:styles',
        'imagemin',
        'svgmin'
      ]
    },

    // Test settings
    karma: {
      unit: {
        configFile: 'test/karma.conf.js',
        singleRun: true
      }
    }
  });

  grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
    if (target === 'dist') {
      return grunt.task.run(['build', 'connect:dist:keepalive']);
    }

    grunt.task.run([
      'clean:server',
      'wiredep',
      'concurrent:server',
      'autoprefixer:server',
      'connect:livereload',
      'watch'
    ]);
  });

  grunt.registerTask('server', 'DEPRECATED TASK. Use the "serve" task instead', function (target) {
    grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
    grunt.task.run(['serve:' + target]);
  });

  grunt.registerTask('test', [
    'clean:server',
    'wiredep',
    'concurrent:test',
    'autoprefixer',
    'connect:test',
    'karma'
  ]);

  grunt.registerTask('build', [
    'clean:dist',
    'wiredep',
    'useminPrepare',
    'concurrent:dist',
    'autoprefixer',
    'concat',
    'ngAnnotate',
    'copy:dist',
    'cdnify',
    'cssmin',
    'uglify',
    'filerev',
    'usemin',
    'htmlmin'
  ]);

  grunt.registerTask('default', [
    'newer:jshint',
    'test',
    'build'
  ]);
};

UPDATE 1
I added following in the end of Gruntfile.js
grunt.registerTask('default', [
    'newer:jshint',
    'test',
    'build'
  ]);

  grunt.loadNpmTasks('grunt-ngmin');

  ngmin: {
      controllers: {
        src: ['script/controllers/auth/login.js'],
        dest: ['script/controllers/auth/login.js']
      },
      directives: {
        expand: true,
        cwd: 'script',
        src: ['directive/**/*.js'],
        dest: 'script/directive'
      }
    }

When I do grunt serve, I get error
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: /home/myuser/workspace/workspace1/myapp/Gruntfile.js:450
>>      dest: ['script/controllers/auth/login.js']
>>          ^
>> Unexpected token :
Warning: Task "serve" not found. Use --force to continue.

Aborted due to warnings.

Comment: I know this is quite old, but I am having this exact same problem. were you able to solve this ?
Answer: You have not passed optimize option in your grunt setup . this is for minification.
   requirejs: {
          build: {
            options: {
                 optimize: 'uglify2',
               }
          }
    }

If you have loaded ngmin and not using requireJS.
grunt.loadNpmTasks('grunt-ngmin');

ngmin: {
  controllers: {
    src: ['test/src/controllers/one.js'],
    dest: 'test/generated/controllers/one.js'
  },
  directives: {
    expand: true,
    cwd: 'test/src',
    src: ['directives/**/*.js'],
    dest: 'test/generated'
  }
},

Comment: I'm sorry where I need to add in Gruntfile.js? Also do I need requirejs? I'm not using requirejs for lazy loading
Comment: you have no requireJS module
Comment: I'm sorry I'm not that great in this. I tried adding the code, but it gives error. please check **UPDATE 1**
Comment: please read the docs its very simple ... dest is the folder where you'll keep the minified file ,so for every thing in angular whether it is controller ,filter , factory etc. you can define it in the grunt file .. https://www.npmjs.com/package/grunt-ngmin
Comment: Earlier I didnt install grunt-ngmin, now I installed it. But I'm still getting the same error
Comment: Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83189/discussion-between-nglover-and-icode).


Summation of independent Gamma distributions?

Question: Let $X_k$ be independent gamma distribution:
$$X_k =\frac{X}{k}$$
where $X$ is a gamma distributions on $(0, \infty)$.
How to find the distribution of the summation of $X_k$:
$$\sum_{k=0}^{+\infty} X_k $$
Can anyone provide some detailed calculation steps ?
Answer: Let $Y:=\sum_{k\geqslant 1}X_k$, then its easy to check that $\operatorname{Var}[Y]=\sum_{k\geqslant 1}\operatorname{Var}[X_k]=\sum_{k\geqslant 1}\frac{4}{\pi^4k^4}<\infty $ so there is a theorem that ensures that $Y$ is well-defined and almost sure finite. Indeed we can see that $\operatorname{E}[Y]=\frac2{3}$.
Also observe that $\varphi _k(t):=\operatorname{E}[e^{-tX_k}]=(1+2t/(\pi^2k^2))^{-2}$, so it follows that
$$
\varphi (t):=\operatorname{E}[e^{-tY}]=\prod_{k\geqslant 1}\varphi _k(t)=\left[\prod_{k\geqslant 1}\left(1+\frac{2t}{\pi^2k^2}\right)\right]^{-2}=\frac{2t}{(\sinh(\sqrt{2t}))^2}
$$
Now, the inverse Laplace transform of $\varphi$ will be the density of $Y$. I dont see a way to compute this inverse Laplace transform by hand so I tried to compute it using Wolfram Mathematica, and it gives as a result that
$$
f_Y(s)=\pi^2\sum_{n\geqslant 1}((n\pi)^2 s-3)n^2 e^{-(n\pi)^2 s/2}\tag1
$$
A little easier is to find the CDF of $Y$, as it is the inverse Laplace transform of $\frac1{t}\varphi (t)$, then we get (with the help of Wolfram Mathematica) that
$$
F_Y(s)=1-2\sum_{n\geqslant 1}e^{-(n\pi)^2 s/2}((n\pi)^2s-1)\tag2
$$
After some work I can confirm that both expressions in (1) and (2) given by Wolfram Mathematica are correct for all $s>0$. Its annoying but they doesn't hold for $s=0$. You can justify them rigorously with a bit of Fourier, real and complex analysis.
Using a numerical computation of the inverse Laplace transform I get

This is the code that I used in Julia to do the figure
<code>using InverseLaplace, GLMakie

# Laplace transform of density of Y
f(t) = 2t/(sinh(sqrt(2t)))^2

# Inverse Laplace transform of Y
pdf1 = ILT(t -> f(t), 64)
CDF1 = ILT(t -> f(t)/t)

# Drawing
fig = Figure()
ax = Axis(fig[1, 1],
    xlabel = "Support",
    ylabel = "Probability"
)
x = range(0, 3, length=100)
y1 = pdf1.(x)
y2 = CDF1.(x)
lines!(ax,x,y1, color = :blue, label = "pdf of Y")
lines!(ax,x,y2, color = :red, label ="CDF of Y")
axislegend()
fig
save("./Julia/figure.png", fig)
````
</code>


Why can't i declare a field using var

Question:
Possible Duplicate:
Why class fields cannot be var?

I'd like to avoid typing out complex/long type definitions for fields like you can with local variables.
I'd like to know why this couldn't be done?
public class Foo
{
    public var barField = new Dictionary<string, int>(); // Does not work

    public void Method()
    {
        var barLocal = new Dictionary<string, int>(); // Works
    }
}

Answer: Straight from the source:
Why no var on fields?
Comment: +1 (and accept when i can), answers the 'why', which was my question.
Answer: You can't have global vars.  Please check the remarks section of http://msdn.microsoft.com/en-us/library/bb384061.aspx
Comment: The question is asking *why* this can't be done - not just the fact that it can't.

Why can't i declare a field using var


Prove that the class of dense linear orders cannot be axiomatized by purely universal sentenes

Question: That is, prove that there is no set $T$ of purely universal sentences such that for every structure $A$ over the signature $\{\leq\}$, $A$ is a dense linear order iff $A\models T$.
Comment: Given a model of such a theory, consider whether a substructure must be a model as well.
Answer: Suppose there was such a set $T$. Clearly $(\mathbb{Q}, \le) \models T$, as it is a dense linear order.
$(\mathbb{Z}, \le)$ is a substructure of $(\mathbb{Q}, \le)$ so $T$ also holds in this, because purely universal sentences stay true on subsets: $(\mathbb{Z}, \le) \models T$.
But $(\mathbb{Z}, \le)$ is not a dense linear order, which contradicts the assumption on $T$.
Comment: Why the purely universal sentences are true on subsets?
Comment: @Gonzalo $\forall x \phi(x)$ holds for the larger set, so also for the smaller. Induct on the structure of the formula.
Comment: Thank you for the clarification


Java scanner input into array

Question: I'm wanting to put the input of a scanner into my array but I am getting the error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

my code:
    public static void main(String[] args)
    {
        Scanner scanInput   =   new Scanner(System.in);
        Random randomGen    =   new Random();

        String captureString[]  = new String[] {};

        System.out.println("Please enter some words..");
        captureString[0]  =   scanInput.next();
        captureString[1]  =   scanInput.next();
        captureString[2]  =   scanInput.next();

        System.out.println("You entered: " + captureString[0] + " " + captureString[1] + " " + captureString[2]);

    }

}

I cannot use loops or conditionals (task) so is an array viable for this? or should I just use variables, only reason I want to use an array is because I want to do some string manipulation afterwards which can be a little awkward with variables
Comment: As I write this, you have three good explanations of why this happens.  May I suggest you use an `ArrayList` instead, as this will grow on demand.
Answer: Since you are getting three inputs, i'd suggest. Change it to String captureString[]  = new String[3];. This is because, Arrays need to be initialized before they are used. Since you have initialiazed with no values. There will not be any index in it. So, when you access the index 0, you are getting ArrayIndexOutOfBoundsException. Hope it clarifies!
Answer: Your array captureString has zero capacity. You can't add elements there. Java arrays can't grow, Use ArrayList, if the content intend to be grow

Java scanner input into array


Vue.js how to load dependent components

Question: Vue.js : how to load dependent components?
From router currently using component as follows:
import A from './A';

export default {
    components : {
        'new-comp-A' : NewCompA
    }
}
...

But this renders the template before import causing errors. Is there a better way for loading dependencies?
The template uses the  - did you register the component correctly.
Comment: I'm not sure I follow. What error does it give you? Based upon your code, everything seems normal to me.
Comment: But this renders the template before import causing errors. Is there a better way for loading dependencies?

The template uses the  - did you register the component correctly.
Comment: "Did you register the component correctly"?
Comment: It looks like we are going to need to see all of the code you are using to try and import your component. One thing I can think of is the path may be wrong? Also, try to use it like: `` versus ``, that may also be your issue.
Answer: Your casing is incorrect. Use either 'NewCompA' or 'new-comp-a' for the name.
In fact, it would be even easier to use
import NewCompA from 'wherever/the/component/is/defined'

export default {
  components: {
    NewCompA
  }
}

Your template can then use either
<NewCompA></NewCompA>

<new-comp-a></new-comp-a>

See https://v2.vuejs.org/v2/guide/components-registration.html#Name-Casing
Comment: yes,, that got fixed.. but i got another error..  while registering a component in beforeMount() method  i am using it in template ... but it throws up the error ..    the reason for doing this is because it needs the imports libs on the top..
Answer: After looking at your code again, it does not seem normal. You are assigning the variable A to your component, but trying to import it with the variable NewCompA..
You need to change the following:
From this:
import A from './A';

export default {
    components : {
        'new-comp-A' : NewCompA
    }
}
...

To this:
import A from './A';

export default {
    components : {
        'NewCompA' : A
    }
}
...

and use it like this:
<new-comp-a>

Vue.js how to load dependent components


bind9: example.com works, www.example.com doesnt, and how to block urls

Question: 1)
I was following a guide to setup bind again after I formatted to Ubuntu 10.04.2 LTS.
http://doc.ubuntu.com/ubuntu/serverguide/C/dns-configuration.html#dns-primarymaster-configuration
I can get my domain example.com to resolve but I want "www.example.com" to resolve to the actual domain on the web.
I don't have a webserver setup on my domain at the moment so I would rather it resolve properly.
So "ping example.com" works and resolves to my local address but "ping www.example.com" gives "ping: unknown host www.example.com".
Here is the file db.example.com,
;
; BIND data file for example.com
;
$TTL    604800
@       IN      SOA     ns.example.com. root.example.com. (
                              9         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns.example.com.
@       IN      A       10.11.12.1
;www    IN      A       10.11.12.1
ns      IN      A       10.11.12.1

I tried adding in a www entry but it only resolves to the same local ip as example.com so I commented it out.
2)
I am planning on adding all of the urls from the ad block site http://winhelp2002.mvps.org/hosts.txt to bind so as to block them on my network.
So how would I add this list to bind?
Answer:
I tried adding in a www entry but it only resolves to the same local ip as example.com so I commented it out.

Well, that's why it doesn't work. Create a proper A resource record for www, increase the serial number of your zone file and reload the zone.
You should also read up on the basics of DNS e. g. in DNS for Rocket Scientists.

I am planning on adding all of the urls from the ad block site
  http://winhelp2002.mvps.org/hosts.txt to bind so as to block them on
  my network.

BIND is not really meant for this kind of manipulation. This said you can create a static-stub zone in newer versions of BIND to manipulate DNS entries. See http://ftp.isc.org/isc/bind9/cur/9.8/doc/arm/Bv9ARM.ch06.html#id2591396 for details.
Comment: "Create a proper A resource record for www", not sure what you mean, could you explain further or give an example
Comment: Uncomment the line `www IN A 10.11.12.1` and read up on it in DNS for Rocket Scientists.
Comment: Ok I can hardcode it to the IP of www.example.com while remaining the master for example.com.  Secondly, what do you mean bind wasn't meant for blocking urls.  Its a domain name server, what else am I supposed to use?  I browse with chrome and its adblock isn't as good as ff.  Using hosts file slows down windows.
Comment: BIND was built to be an auhtoritative name server and caching resolver. Manipulating DNS entries, e. g. overwriting zone-data of the forwarders (the name servers the caching resolver will get its data from) was not a primary concern. That's why getting that list to use with BIND is rather tedious.


Is `auto x = f()` better than `T x = f()`?

Question: In another topic someone suggested using
auto x = f();

instead of
T x = f();

(if the signature of f is T f()). They pointed out this prevents silent object slicing if someone happens to change f to U f(), where U descends from T.
It makes sense to me, but there might be other things in play that I am missing. So, which is better and why?
Comment: You may want to read [Herb Sutter's GotW #94 (Almost Always Auto)](http://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-almost-always-auto/).
Answer: One of the best advantaes of using auto in that context is, as Herb Sutter noticed at Almost Always Auto, that auto makes the usage of an API more mantenible. That is, the API can be modified/refactored without any necesary change in client code.
For example:
API v1.0
template<typename T>
T* abstract_factory::create();

API v2.0
template<typename T>
std::shared_ptr<T> abstract_factory::create();

Usage (Without auto)
 Foo* instance = abstract_factory::create<Foo>();

Client updates API library to v2.0
 Foo* instance = abstract_factory::create<Foo>(); //TYPE ERROR!!!

Update using auto
 auto instance = abstract_factory::create<Foo>(); //OK! type infered to std::shared_ptr<Foo>

Comment: Am I the only one that thinks "the API can be modified/refactored without any necesary change in client code." is a bad thing?
Comment: If things go ahead with a need to recompile, it's because the new thing you got from the new API has the same _duck type_ anyway, and therefore you shouldn't need to change the original code, unless your original code depended on a particular implementation or type (which should be avoided in most cases). In the latter case, you should specify the required type (e.g. `auto x = TypeINeed(f());`). Herb Sutter's article that was posted argues that well
Comment: Sorry, I meant "If things go ahead withOUT a need to recompile [...]"


Compare records of 2 tables with SQL

Question: I have 2 tables with the following structure:
1-Items Table
create table if not exists items
(
    id bigserial not null primary key,
    group_id integer not null,
    description text not null,
    quantity double precision not null,
    measurement_id integer not null,
    model varchar(255),
    unitary double precision not null,
    price double precision not null,
    currency_id integer not null
);

1-Hireds Table
create table if not exists hireds
(
    id bigserial not null primary key,
    item_id integer not null constraint hireds_item_id_foreign references items on delete cascade,
    quantity double precision not null,
    price double precision not null
);

I would like to get all the items in the second table that their quantity exceeds what is already defined in the first .. for example ..
Table 1
id | name   | quantity
---------------------
1  | Item 1 | 10
2  | Item 2 | 20
3  | Item 3 | 30
4  | Item 4 | 15
5  | Item 5 | 30

Table 2
id | item_id| quantity
---------------------
1  | 1      | 15
2  | 2      | 25
3  | 3      | 35
4  | 4      | 10
5  | 5      | 29

I need a query that returns a table similar to this:
id | item_id| quantity
---------------------
1  | 1      | 5
2  | 2      | 5
3  | 3      | 5

Comment: Items #4 and #5 on the second table ... they do not comply with the condition that their quantity in the second table exceeds that which is defined in the first
Answer: A simple JOIN will do:
select
  i.id,
  h.item_id,
  h.quantity - u.quantity as quantity
from items i
join hireds h on h.item_id = i.id
where i.quantity < h.quantity
order by i.id

Comment: Work like a charm! Thanks so much!.. save my day!

Compare records of 2 tables with SQL


Statistical measure for if an image consists of spatially connected separate regions

Question: Consider these two grayscale images:

The first image shows a meandering river pattern.
The second image shows random noise.
I am looking for a statistical measure that I can use to determine if it is likely that an image shows a river pattern.
The river image has two areas: river = high value and everywhere else = low value.
The result is that the histogram is bimodal:

Therefore an image with a river pattern should have a high variance.
However so does the random image above:
River_var = 0.0269, Random_var = 0.0310

On the other hand the random image has low spatial continuity, whereas the river image has high spatial continuity, which is clearly shown in the experimental variogram:

In the same way that the variance "summarizes" the histogram in one number,
I am looking for a measure of spatial contiuity that "summarizes" the experimental variogram.
I want this measure to "punish" high semivariance at small lags harder than at large lags, so I have come up with:
$\ svar = \sum_{h=1}^n \gamma(h)/h^2 $
If I only add up from lag = 1 to 15 I get:
River_svar = 0.0228, Random_svar = 0.0488

I think that a river image should have high variance, but low spatial variance so I introduce a variance ratio:
$\ ratio = var/svar $
The result is:
River_ratio = 1.1816, Random_ratio = 0.6337

My idea is to use this ratio as a decision criteria for if an image is a river image or not; high ratio (e.g. > 1) = river.
Any ideas on how I can improve things?
Thanks in advance for any answers!
EDIT: Following the advice of whuber and Gschneider here are the Morans I of the two images calculated with a 15x15 inverse distance weight matrix using Felix Hebeler's Matlab function:

I need to summarize the results into one number for each image.
According to wikipedia: "Values range from −1 (indicating perfect dispersion) to +1 (perfect correlation). A zero value indicates a random spatial pattern."
If I sum up the square of the Morans I for all pixels I get:
River_sumSqM = 654.9283, Random_sumSqM = 50.0785

There is a huge difference here so Morans I seem to be a very good measure of spatial continuity :-).
And here is a histogram of this value for 20 000 permutations of the river image:

Clearly the River_sumSqM value (654.9283) is unlikely and the River image is therefore not spatially random.
Comment: Interesting question. One bit of advice that comes to mind immediately is to focus on the short-range part of the variogram: that is the crucial part and will do the best job distinguishing pairs of images like these.  (Closely related statistics are [Moran's I](http://en.wikipedia.org/wiki/Moran%27s_I) and [Geary's C](http://en.wikipedia.org/wiki/Geary%27s_C).)  It's hard to give specific advice, though, unless you can more clearly characterize the kinds of images you anticipate processing.
Comment: +1 whuber, Moran's I seems like a good start in this case. Then maybe consider a permutation test to see how "extreme" your image is.
Comment: @Gschneider The permutation test is a nice idea, especially because no permutations need to be conducted! It's straightforward to calculate the distribution of the variogram (or Moran's I or Geary's C or whatever) under permutations of the values in the image: there are so many values that the CLT applies. (E.g., the variogram will look like the green points; twice their constant height is the variance of the image values.) The problem becomes more challenging when a "river" pattern needs to be distinguished from other patterns such as a "lake" or "rivers" can have widely varying widths.
Comment: Sorry but I am not sure I follow: are you telling me to permute the image being tested pixel per pixel in some random fashion and then compare the Moran's I value of the permuted image with that of the image being tested?
Comment: What I had in mind was first define some sort of (probably simple) neighborhood structure and compute Moran's I. Then you can compute K, say 200,000, possible permutations of the pixels, computing Moran's I for each permutation. Once you've got these 200,000 Moran's I, see where your observed statistic lies. But, whuber's method sounds easier :).
Comment: You should ask over at the signal processing stack exchange. This is totally their bag. http://dsp.stackexchange.com/
Answer: I was thinking that a Gaussian blur acts as a low-pass filter leaving the large-scale structure behind and removing the high wave-number components.
You could also look at the scale of wavelets required to generate the image.  If all the information is living in the small scale wavelets then it is likely not the river.
You might consider some sort of auto-correlation of one line of the river with itself.  So if you took a row of pixels of the river, even with noise, and found the cross-correlation function with the next row, then you could both find the location and value of the peak.  This value is going to be much higher than what you are going to get with the random noise.  A column of pixels is not going to produce much of a signal unless you pick something from the region where the river is.
http://en.wikipedia.org/wiki/Gaussian_blur
http://en.wikipedia.org/wiki/Cross-correlation
Comment: Some interesting ideas here! Could I persuade you to flesh out this answer by applying one or more of your approaches to the sample images to (1) show how your methods work and (2) evaluate how well they perform?
Comment: It is from my Thesis.  (Mechanical Engineering)  I put a Gaussian blur on the position of a nonlinear pendulum, and then used the convolution method to back out the position from an image and compare it to the analytic.  I tried it with several levels of noise.  As long as the noise was below a threshold related to the size of the gaussian, there was very good reconstruction.

[link](http://repository.asu.edu/items/15110)

Figure 11 was the relevant graph for the reconstruction.  Figure 6 and equation 2 indicate response to noise.
Comment: Thanks! So it looks like you are in a great position to flesh out this answer and demonstrate how effective it really is. :-)
Comment: Sorry for the double comment.  I think it is "clever" to use part of an object as a pseudo "mother-wavelet" for itself.  It seems self referential, but also poetic.  Self Adjoint.
Answer: This is a bit late, but I cannot resist one suggestion and one observation.
First, I believe a more "image processing" approach may be better suited than histogram/variogram analysis. I would say that the "smoothing" suggestion of EngrStudent is on the right track, but the "blur" part is counter-productive. What is called for is an edge-preserving smoother, such as a Bilateral filter, or a median filter. These are more sophisticated than moving average filters, as they are by necessity nonlinear.
Here is a demonstration of what I mean. Below are two images approximating your two scenarios, along with their histograms. (The images are each 100 by 100, with normalized intensities).

Raw Images

For each of these images I then apply a 5 by 5 median filter 15 times*, which smooths the patterns while preserving the edges. The results are shown below.

Smoothed Images

(*Using a larger filter would still maintain the sharp contrast across the edges, but would smooth their position.)
Note how the "river" image still has a bimodal histogram, but it is now nicely separated into 2 components*. Meanwhile, the "white noise" image still has a single-component unimodal histogram. (*Easily thresholded via, e.g. Otsu's method, to make a mask and finalize the segmentation.)

Second, your image is certainly not a "river"! Aside from the fact that it is too anisotropic (stretched in the "x" direction), to the extent that meandering rivers can be described by a simple equation, their geometry is actually much closer to a sine-generated curve than to a sine curve (e.g. see here or here). For low amplitudes this is approximately a sine curve, but for higher amplitudes the loops become "overturned" ($x\neq f[y]$), which in nature eventually leads to cutoff.
(Sorry for the rant ... my training was as a geomorphologist, originally)
Comment: On a side note, it is generally a good idea to be very cautious in applying "variogram methods" to natural images, which are typically *not* stationary. This is touched on in my answer [here](http://stats.stackexchange.com/questions/233960/how-in-practice-are-spatial-covariances-determined).
Answer: A suggestion which may be a quick win (or may not work at all, but can easily be eliminated) - have you tried looking at the ratio of mean to variance of the image intensity histograms?
Take the random noise image. Assuming it's generated by randomly emitted photons (or similar) hitting a camera, and each pixel is equally likely to be hit, and that you have the raw readings (i.e. values are not rescaled, or are rescaled in a known way you can undo), then the number of readings in each pixel ought to be poisson distributed; you're counting the number of events (photons hitting a pixel) that occur in a fixed time period (exposure time) multiple times (over all pixels).
In the case where there's a river of two different intensity values, you have a mixture of two poisson distributions.
A really quick way to test an image then might be to look at the ratio of mean to variance of the intensities. For a poisson distribution the mean will approximately equal the variance. For a mixture of two poisson distributions, the variance will be bigger than the mean. You'll end up needing to test the ratio of the two against some pre-set threshold.
It's very crude. But if it works, you'll be able to calculate the necessary sufficient statistics with just one pass over each pixel in your image :)


Prove using properties of divisors and or induction

Question: How would I go about proving the statement that for all positive integers $n$, $$(n+1)\Big|\binom{2n}{n}$$
Induction in this case is possible but I wanted to use a different method. If I compute $$\frac{2n+1}{n+1}\binom{2n}{n}$$ I would be able to get $$\frac{(2n+1)!}{(n+1)!(n)!},$$ where $n$ is non negative. Would I be able to use a theorem with the greatest common divisor? If I were to use induction, how should I do it?
Comment: When you wrote $\binom2n$, did you mean $\binom{2n}n$?
Comment: $1|1, \; 2|2 \; 3|2 FAIL$
Answer: As you observed
$$\frac{2n+1}{n+1}\binom{2n}{n}=\binom{2n+1}{n}$$
Therefore
$$n+1 | (2n+1) \binom{2n}{n}$$
Now, show that $n+1$ is relatively prime to $2n+1$.