Dynamic Landing Page

Question: I have a site with posts going back 5 years and I want to create a couple landing pages to highlight groups of posts. For example, I want to create a page about "blue widgets". The page should include some new content that I will write about "blue widgets" and I want to dynamically include posts that match "blue widgets". Any ideas on how to best accomplish this?
Answer: The best solution here IMHO is to create a custom taxonomy named "highlights" or something similar. You can then create new terms for each landing page that you wish to create. The of of which would probably be "Blue Widgets". You can then associate as many posts to the "Blue Widget" term as you wish. For the "Blue Widgets" term, you can add a custom description via the WordPress administration panels and allow it to appear in your theme by using the term_description() template tag. I would suggest adding this to a custom template file that you create to display term archives of the "highlights" taxonomy. taxonomy-highlights.php should work. Please read this thread for ideas on creating the custom template file.
I use a very similar approach on my own site fir WordPress functions. Here's a link to a landing page that has a description of the setup_postdata() function as well as all posts that use this function.
Best wishes,
-Mike
Answer: Like an archive?
yoursite.com/archive/blue-widgets
Answer: Since your posts about blue widgets contain the blue widgets keywords you might as well go with a related posts plugin.
Other than that, the only clean solution I could think of right now is creating a custom shortcode to squeeze in lists of posts that match a certain criteria which you'll pass on to a new WP_Query. Criterias could be post IDs, a search query, a taxonomy query or even a meta query.
Let me know if you need further explanation on this.
Cheers!
Answer: Create a page template and do a custom query over there, like posts from a certain tag, post title containing words on even in post_content or even a combined version of all of them. And I would strongly suggest you to cache the query results in a transient so as not to do those heavy queries everytime a page is generated.
Comment: Seriously who down voted me without an explanation?

Dynamic Landing Page


Derailleur adjustment: front or rear first?

Question: When adjusting both front and rear derailleurs, which should be done first?
Comment: Do them in stages, going back and forth.
Answer: If the derailers just need minor tweaking (they are basically in adjustment but are "not quite right") then you adjust the one that is obviously wrong, check the overall adjustment again, then again adjust what needs adjusting.  Often only one derailer needs adjusting and often the adjustment is just a half-turn of the barrel adjuster.
If they are completely mucked up (but nothing visibly bent/broken), I usually first check the front for parallel and sprocket clearance (they often get knocked out of alignment), get it on the center sprocket, then address the rear.  Once the rear is basically correct, get the front to where it will shift to all rings with modest accuracy, then, trying all combos, adjust the rear some more.  Finally, fine-tune the front, then fine-tune the rear.
But it varies with the bike, how recalcitrant the derailers are, and specifically what is out of adjustment most.
Answer: There are three main steps to adjust both derailleurs.  The first is usually not necessary unless the rear is very far out of adjustment.

Adjust the rear derailleur enough that it will stay in the lowest and highest gears, even if you have to help it a little with finger pressure on the derailleur arm.  This may require adjusting the high and low limit screws.
Adjust the front derailleur:  Start by putting the rear in one of your middle gears.  Then run the front through each chain-ring and make sure that it will smoothly move from ring to ring.  Adjust as necessary.  Set the rear to the highest (smallest) gear.  Adjust the front so that it does not rub in any of your 2 or 3 chain-rings.  Set the rear to the largest (biggest) gear and repeat the tuning process.  In a 2 chain-ring setup, you have to make sure that the cross chain combinations (small-small and large-large) don't rub either.  In a 3 ring setup, it's not always possible or necessary.  If you have 1/2 clicks on the front shifter (most often in 2 ring setups), make sure to include them in the process.  If  you can't seem to get the front to adjust without rubbing, it's possible the height and/or twist of the derailleur clamp has changed.  Check manufacturer's recommendations for position, if so.
Adjust the rear derailleur:  Put the front in smallest ring in front and tune the rear derailleur until you are satisfied with the speed and quietness of the shifting.  If it's noisy or grinds, it's not right yet.  Don't forget about the B-screw when tuning.  If it's out of whack, then your shifting will be difficult or inconsistent, depending on which way it's out of adjustment.  Next, move to your next biggest chain-ring and repeat the adjustment process of the rear derailleur.  If you have 1/2 click front derailleur adjustments, you will need to include them in your tuning process.

In a nutshell, adjust the front derailleur first, then the rear.
Answer: Answer:  "Yes"
Every part of the system affects every other part of the system.    So you could spend ages making the rear perfect, then go and tweak the front which puts the rear out again.
Like truing wheels, back and forth is your best answer to focus down on the best position for both.
Don't forget to clean everything before you do adjustments.  Makes life easier.
Comment: Our experiences are wildly different, and I can not find a rational explanation to your experience.
Comment: Can you explain how the front and rear affect each other? They are not connected to each other, unlike spokes that are pulling against other spokes.
Comment: @ojs you're right  they're not connected by anything directly.  However they both work to manage the one chain.  My bike lacks any form of trim on the front mech (which is also a triple) so I get rub on the front cage.  With minimum rub, I now can't backpedal in low gears without derailing the front chainring.  So you can't flatly say "do front then rear" or "rear then front"  it has to be an iterative process.
Comment: The derailleurs are located on opposite sides of the cogs, so the the relative location of derailleur and chain depends only on shifter position, derailleur adjustment and which cogs the chain is on. The derailleur on opposite side can not change chain position, except by moving the chain to different cog.
Comment: @ojs I can only speak from experience, having to adjust one then the other and then go back and tweak the first one again.  Repeat until correct.
Answer: It does not matter. The derailleurs are located on opposite sides of the cogs, so the the relative location of derailleur and chain depends only on shifter position, derailleur adjustment and which cogs the chain is on. The derailleur on opposite side can not change chain position, except by moving the chain to different cog.
It is far easier to adjust the derailleurs by sight, so that rear one lines up with cogs and front one has correct limits, than try iteratively adjusting until the shifting is smooth. If you want to do the latter, you may need to switch between front and rear.
Comment: Your answer is not exactly correct.  For example, if the rear is so far out of adjustment that it can not get to the highest or lowest gear on the cassette, then you will not be able to adjust the front properly.  So while the adjustment of the derailleur only depends it's location, chain rub is affected by both front and rear positions and is a critical component of derailleur adjustment.
Answer: I learned that the rear should be adjusted completely first. The front is notoriously difficult to get just right.
Comment: But if the front isn't roughly correct then you'll never get the rear right.
Comment: Welcome to Bicycles! We're looking for answers with [more detail](//bicycles.stackexchange.com/help/how-to-answer). Please consider expanding your answer to further elaborate how you dial in the adjustment. A short answer like this is likely to get downvoted, flagged for moderator intervention, and possibly deleted.


Group of word representations

Question: For word representation baseline people use bag-of-words or word embedding. Here, I want to understand all approaches that can be used for word representations. For example:
-Bag-of-words (tfidf, n-gram,etc.)
-word embedding (GloVe, word2Vec, skip gram, etc.)
etc.
Is there any source/article that explains all of the word representation group? Does anyone have a good understanding and explain it here? thanks.
Answer: 'All' is a very strong quantifier :) very tough requirement to find 'one article to rule them all (word representations)'.
And representation of word can vary depending on the task to be solved.
E.g. a word can be represented also as its morhological tags - part of speech, atributes like (grammatical) number etc. - for the task of parsing.
You may sometimes skip meaning of word and jump directly to meaning of whole text (like in doc2vec).

Group of word representations


What happens if my auction listing ends with no bids placed?

Question: Specifically, do I have to pay some sort of fee if that happens?
Answer: There is no single answer.
It mainly depends on the product you auction, the type of auction and your account type.
Basically, your final fees come in the form of Insertion fees and Percentage fees

When you list and sell items on eBay, we charge selling fees. There
are two main types of selling fees: an insertion fee when you create
a listing, and a final value fee when your item sells.
The amount we charge depends on the item's price, the format and
category you choose for your listing, any optional listing upgrades
you add, and your seller conduct and performance.

You should carefully read the pages about Selling through auctions, Selling fees, Ending a listing and Store selling fees
Comment: Have you followed the given solution? Did it work for you? If not please add what is missing. If yes, as per [site guidelines](https://webapps.stackexchange.com/help/someone-answers) when an answer addresses your question, you should [accept](https://webapps.stackexchange.com/help/accepted-answer) it so others can benefit as well.


Can the ratio of the two smallest element of an iid sample converge to 1 if the support of $X$ is positive?

Question: We have: $\mathbb P(X \leq 0)=0$ and $\mathbb P (X \leq a)>0$ for any $a>0$.
Comment: Doesn't something like the exponential of a standard Gaussian already provide a counter example? Then getting closer to zero gets exponentially less likely, so $X^{(2)}-X^{(1)}$ wil converge to zero but I don't think $X^{(2)}/X^{(1)}$ converges to $1$.
Comment: Sorry, I meant if there exists a random variable with the given support such that the ratio still converges to 1 - I did not properly write that down; 1000x sorry
Answer: The answer is no. Here is a counterexample. Lets $X_1, X_2, \dots, X_n$ random samples from an exponential distribution with parameter $\lambda$.the order statistics $X_{(1)}, X_{(2)}$ each have distribution
\begin{align*}
X_{(1)} &= \frac{Z_1}{\lambda n} \\
X_{(2)} &= \frac{1}{\lambda}\left(\frac{Z_1}{n}+\frac{Z_2}{n-1}\right)
\end{align*}
where the $Z_1, Z_2$ are iid standard exponential random variables (see Wikipedia).
Therefore
$$
\frac{X_{(2)}}{X_{(1)}} = \frac{Z_1}{Z_1+Z_2n/(n-1)} \rightarrow \frac{Z_1}{Z_1+Z_2} \neq0
$$
Comment: I actually meant if it is possible to construct a random variable $X$ with the given support as indicated, such that the ratio will converge to 1; Sorry, I corrected it
Answer: You're right for most cases, however this depends on the distribution as well.
If $X_1, \dots, X_n \sim \Bbb{P}_\theta$ where $Var_\theta(X_i) = 0$, this doesn't hold true, because
$$\forall i,j \in \{1,\dots,n\}\quad\Bbb{P}(X_i = X_j) = 1 \rightarrow \Bbb{P}\left(\lim_{n \to \infty}\frac{X_i}{X_j}=1\right)=1$$
But for most cases, where $Var_\theta(X_i) \ne 0$, you can prove this indirectly:
Let's assume that
$$\exists \lim_{n \to \infty}\frac{X^{(2)}}{X^{(1)}} := A \in \Bbb{R}^+_0 \cup \{+\infty\}$$
We can assume that $A \ge 0$, because $X^{(2)} \ge X^{(1)}$.
If
$$\lim_{n \to \infty}\frac{X^{(2)}}{X^{(1)}} = A \stackrel{\text{then }}{\longrightarrow}\lim_{n \to \infty}\Bbb{E}\left(\frac{X^{(3)}}{X^{(2)}}\right) = A$$
Since $\forall \varepsilon, N_1 \in \Bbb{R}^+ \exists, N_2 \in \Bbb{N}^+$ such that from a sample of $X_1,\dots,X_{N_1}$
$$A - \varepsilon < \frac{X^{(2)}}{X^{(1)}} < A + \varepsilon,$$
We can assure that from a sample of $X_1,\dots,X_{N_2}$, where $N_2$ is sufficiently large:
$$A - \varepsilon < \frac{X^{(3)}}{X^{(2)}} < A + \varepsilon$$
Since as $n \to \infty$,
$$\lim_{n \to \infty}\left(\frac{X^{(3)}}{X^{(2)}} - \frac{X^{(2)}}{X^{(1)}}\right) = 0$$
Now we'll have to prove $2$ cases separately:
Case $1$: $A = 1$
From our previous argument it follows that
$$\lim_{n \to \infty}\frac{X^{(2)}}{X^{(1)}} = \lim_{n \to \infty}\frac{X^{(3)}}{X^{(2)}} = \dots = \lim_{n \to \infty}\frac{X^{(n)}}{X^{(n-1)}} = 1$$
$$\Rightarrow \lim_{n \to \infty}\frac{X^{(n)}}{X^{(1)}} = 1$$
$$\Rightarrow \forall i \in \{1,\dots, n\} \quad \sup {Ran}_{\theta} X_i = \inf {Ran}_{\theta} X_i$$
$$\Rightarrow \forall i \in \{1,\dots, n\}\quad Var(X_i) = 0$$
Which is a contradiction, becuase in this case we assumed that $Var(X_i) \ne 0$.
Case $2$: $A \in \Bbb{R}^+_0 \backslash \{1\}$
Again, we get
$$\lim_{n \to \infty}\frac{X^{(2)}}{X^{(1)}} = \lim_{n \to \infty}\frac{X^{(3)}}{X^{(2)}} = \dots = \lim_{n \to \infty}\frac{X^{(n)}}{X^{(n-1)}} = A$$
Which is this case means:
$$\lim_{n \to \infty}\frac{X^{(2)}}{X^{(1)}} = \lim_{n \to \infty}\frac{1}{A}\frac{X^{(3)}}{X^{(1)}} = \dots =\lim_{n \to \infty}\frac{1}{A^n}\frac{X^{(n)}}{X^{(1)}}$$
$$\Rightarrow \lim_{n \to \infty}\frac{X^{(n)}}{X^{(1)}} = \lim_{n \to \infty}A^n\frac{X^{(2)}}{X^{(1)}} = \\ = 0, +\infty \text{ or does not exist (depending on the value of } A)$$
It can't be $0$, since then $$\Bbb{P}(X_n = 0) = 1 \rightarrow \forall i \in \{1\dots n\}\quad \Bbb{P}(X_i = 0) = 1 \rightarrow Var(X_i) = 0$$
Which is a contradiction again.
It can' be $+ \infty$ either, because that can only occur if
$X_n \ne 0$ and $X_{n-1} = 0$, but as we've already discussed,
$$\lim_{n \to \infty}\frac{X^{(n)}}{X^{(n-1)}} = \lim_{n \to \infty}\frac{X^{(n-1)}}{X^{(n-2)}} (= + \infty)$$
Which also means that $X_{n-1} \ne 0$ and $X_{n-2} = 0$, and we get a contradiction from $X_{n-1} = 0$ and $X_{n-1} \ne 0$.
The only option in this case is for the limit not to exist, which isn't technically a contradiction, but it further proves our point.
Result:
Both cases lead to contradiction, which means that the given limit does not exist.
Comment: I still need a couple of minutes to work through your proof; Thank you so much for your answer already - I highly appreciate it
Comment: Just a little remark; If $\mathbb P (X \in (0,a])>0$ for any fixed $a$, then e.g. variance 0 is simply not possible and also there is no "smallest" value that $X$ can take but the minimum will just converge to zero, getting smaller and smaller
Comment: @Johannes That's true, I glossed over the fact that $\mathbb P (X \in (0,a])>0$, but the proof is still valid, since we're trying to contradict the fact that the variance is $0$.
Comment: I either did not properly understand your proof or it is wrong; Imagine I have a random variable $X$ with supp$(X)=(1,\infty)$  and $\mathbb P(X \in (1,a])>0$ for any fixed $a>1$ (so everything shifted up by one) Then obviously both, the smallest and the second smallest realization will converge to one and hence the ratio will also converge to 1; However, if I understood your proof correctly, I could also show with the same arguments that this does not hold;
Comment: The basic idea for it to work must be that the minimum converges to zero; If it converges to some fixed number $a$ with $a \neq 0$, then the ratio will indeed converge to 1...
Comment: I don't think your Case 1 argument works as it stands. You can conclude that $lim_{n \rightarrow \infty} \frac{X^{(k)}}{X^{(1)}}=1$ for any fixed $k$. But that is not the same as $lim_{n \rightarrow \infty} \frac{X^{(n)}}{X^{(1)}}=1$ and I don't see how that follows.
Comment: Exactly...That is the flaw in it


The request failed with HTTP status 401: Unauthorized

Question: I have the following error:
The request failed with HTTP status 401: Unauthorized. URL:http://serverName/ReportServer/ReportService2005.asmx
I have a web application in one server and reporting service en other.both server have installed Windows 2003. The user in the crediatials is the same the I use to install reporting service and the same the Reportins service service used. Also, this user has the RSS role and is owner in the database and this user is in teh application Pool. is somethig wrong in my code? what is the way to access the reporting service web service using imporsonation?
<code> {

             ReportingService2005 rs = new ReportingService2005();

            try
            {

                rs.Url = ConfigurationSettings.AppSettings["WSRS"].ToString();
                //rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

                rs.PreAuthenticate = true;

                rs.Credentials = new NetworkCredential(RS.User_Name,RS.Pass_Word,RS.Domain)
                    );

                //string report = "/SampleReports/Employee Sales Summary";
                string desc = "Added by workflow automatically";
                string eventType = "TimedSubscription";
                string scheduleXml = string.Empty;

                /*ExtentionSettings Values*/
                List<ParameterValue> ExtensionSettingsparmList = new List<ParameterValue>();
                foreach (String name in colExtensionSettings.AllKeys)
                {
                    ExtensionSettingsparmList.Add(new ParameterValue() { Name = name, Value = colExtensionSettings[name].ToString() });
                }

                ExtensionSettings extSettings = new ExtensionSettings();
                extSettings.ParameterValues = ExtensionSettingsparmList.ToArray(); // extensionParams;
                extSettings.Extension = "Report Server Email";

                /*Parameters Values*/

                List<ParameterValue> parameterList = new List<ParameterValue>();

                foreach (String name in colParameters.AllKeys)
                {
                    parameterList.Add(new ParameterValue() { Name = name, Value = colParameters[name].ToString() });
                }

                scheduleXml = @"<ScheduleDefinition><StartDateTime>" + DateTime.Now.AddMinutes(1).ToString("s") + "</StartDateTime></ScheduleDefinition>";
                string matchData = scheduleXml;

                return rs.CreateSubscription(report, extSettings, desc, eventType, matchData, parameterList.ToArray());
            }
</code>
Answer: This looks like a configuration issue with IIS and NTLM authentication in combination with an AppPool.
This knowledge base article might be a solution:

You receive an "HTTP Error 401.1 - Unauthorized: Access is denied due to invalid credentials" error message when you try to access a Web site that is part of an IIS 6.0 application pool
Answer: Application pool needs to be running under credentials that have access to website. To ensure security run app pool as a domain user you have created that has access to your database/application with proper security access.


any ways to check if current profile is allowed to access a particular page?

Question: I have a couple of static pages( just text no custom object involoved ) need to show to users and links to the pages need to be hidden if the user doesn't have privilege to do so. Is there any way to check that or I have to do with profile name match?
Answer: You can't directly check the permissions for the page-- you'd have to either go the long way around with a Metadata API query, which should be painful at best, or you can attempt to open each page on behalf of the user (e.g. via PageReference) and see if you get an error page or not. In the end, it's probably best to check profile names explicitly, although that runs the problem of another administrator later changing the page permissions or adding permission sets. Personally, I would recommend that you simply display the links, and allow the user to see the error message for themselves. This way, if they were told they should have access, they will have an idea why they do not have access instead of just reporting "I can't find the link you were talking about."
Comment: I don't think it's good idea to have them display if they are not entitled to do so. That might confuse users. I might give a try with metadata api or just name match to make it quick fix.
Comment: I'm usually inclined to agree-- why give them a choice if they can't actually do it... but in this case, the effort may far exceed the benefits. Checking by profile name is a poor means of accomplishing the task, because you can't predict when an administrator will make a breaking change (either adding a page they can't access, or removing a page they could access). Maybe you should look at Custom Settings, instead; at least then you'd have the flexibility of configuring per-profile settings without code changes.
Comment: For the custom settings, you meant I can set so that some of CS can be only seen by specific profile or I need to have a key/value pair for each pages to do show/hide.
Comment: I would use CS type hierarchy, set org defaults to minimum default pages for all users then set override values per profile/per user as necessary to indicate page access. This should scale well for an average sized organization.


How can I temporarily disable a foreign key constraint in MySQL?

Question: Is it possible to temporarily disable constraints in MySQL?
I have two Django models, each with a foreign key to the other one. Deleting instances of a model returns an error because of the foreign key constraint:
cursor.execute("DELETE FROM myapp_item WHERE n = %s", n)
transaction.commit_unless_managed()  #a foreign key constraint fails here

cursor.execute("DELETE FROM myapp_style WHERE n = %s", n)
transaction.commit_unless_managed()

Is it possible to temporarily disable constraints and delete anyway?
Comment: Either I don't get what you want to do, or what you are trying to do is **very, very, very ugly**. Even if you can do it, you probably shouldn't.
Comment: what if, instead of disabling your constraint, you permanently modified it to `ON DELETE SET NULL`? That would accomplish a similar thing and you wouldn't have to turn key checking on and off.
Comment: Dropping and reapplying an FK _is_ changing your db. You're trying to defy the very constraints that allow the system to see some sense, it has no regard that an FK could be a temporary thing, and if it did know, it would panic.
Comment: Its strange what you trying to do. But which database are you using?
Comment: @dnagirl: that would be better, indeed. How can I do that?
Comment: @andrefsp: I'm using MySQL. I'll edit my question to add that.
Comment: You should do what @dnagirl its telling you to do. Its way more reasonable and its the way to ensure you don't mess in a really nasty way with your data. Playing with it like what you want to do might lead you to serious integrity and consistency problems.
Comment: @Dariusz I do it all the time resetting certain tables in my test data db, without regenerating the whole thing. Not sure why it's do bad
Answer: Try DISABLE KEYS or
SET FOREIGN_KEY_CHECKS=0;

Make sure to
SET FOREIGN_KEY_CHECKS=1;

after.
Comment: I believe it is per session.
Comment: is this something that is set for mysql as a whole or just that session?
Comment: http://serverfault.com/questions/291100/with-mysql-how-long-does-an-alter-table-disable-keys-statement-last#comment820481_291100 , Also note that you [**cannot** `disable keys`](http://serverfault.com/questions/234893/how-to-disable-keys-in-mysql-innodb/234901#comment820478_234901) for Innodb
Comment: To clarify @Pacerier's comment: For Innodb, you cannot `DISABLE KEYS`. But you *can* accomplish what is requested in this question, using the other command shown: `SET FOREIGN_KEY_CHECKS=0;` (I thought at first he was saying there was no way to accomplish this.)
Comment: Can I just disable FOREIGN_KEY_CHECKS for a single table?
Comment: @Pacerier From reading that, it appears you can, but only for a single session.
Comment: `SET FOREIGN_KEY_CHECKS=0;` is not working for me. Is this working from newer version of mysql.
Comment: @MusaddiqKhan - Yes: [MySQL 8 foreign_key_checks](https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_foreign_key_checks). As mentioned in comments above, this is only for the current session/connection. If you still can't get it to work, *post a new question*, with good detail about what you tried, and what happened - error message?
Comment: A word of caution: MySQL doesn't revalidate the foreign keys when you reactivate the checks. This can cause serious referential errors.
Comment: Wish I could upvote this answer, everytime I came back here.
Answer: To turn off foreign key constraint globally, do the following:
SET GLOBAL FOREIGN_KEY_CHECKS=0;

and remember to set it back when you are done
SET GLOBAL FOREIGN_KEY_CHECKS=1;

WARNING: You should only do this when you are doing single user mode maintenance.  As it might resulted in data inconsistency.  For example, it will be very helpful when you are uploading large amount of data  using a mysqldump output.
Comment: @hexnet The difference is that just `SET FOREIGN_KEY_CHECKS` just changes the value for the _current connection_, while `SET GLOBAL ..` changes the value for _all connections_, including future connections. If you just do `SET FOREIGN..` in one window, then try to apply the statement in a different window (over a different connection), the value has not changed there. With `GLOBAL`, the same variable has the same value for both connections.
Comment: this is what I needed to know, so its not great practice, but this guys answer should be scoring higher...
Comment: This worked for me after trying the 'best answer' didn't work for me. Perhaps an explanation of the difference could be added.
Comment: The only thing that could help me when playing back a larger dump (6+ GB)
<3
Comment: This doesn't work for me.  When I try, I see:`ERROR 1228 (HY000): Variable 'foreign_key_checks' is a SESSION variable and can't be used with SET GLOBAL`
Comment: Try UPPERCASE @MikeB
Comment: @berniey no luck.  It's alright though. I used `alter` statements to temporarily disable the foreign key constraints.
Comment: @MikeB, I think it has to do with the tool that you use to issue the command (it works with `myqsl` command line tool). I've been using the command on v5.5 and 5.6 and it works fine. Document suggested ut even works on v5.7. http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html. Also, case doesn't matter (pardon on my earlier suggestion)
Comment: Would like to note that if you connect to MySQL that has foreign key checks enabled prior to issuing the global query, that the current session state for foreign key checks is preserved. i.e. `SET GLOBAL FOREIGN_KEY_CHECKS=0; SELECT @@FOREIGN_KEY_CHECKS;` will return `1` until you reconnect to start a new session
Comment: this doesn't work for me (mysql 5.7).  However the accepted answer "SET FOREIGN_KEY_CHECKS=0;" does work.
Answer: I normally only disable foreign key constraints when I want to truncate a table, and since I keep coming back to this answer this is for future me:
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE table;
SET FOREIGN_KEY_CHECKS=1;

Answer: Instead of disabling your constraint, permanently modify it to ON DELETE SET NULL. That will accomplish a similar thing and you wouldn't have to turn key checking on and off. Like so:
ALTER TABLE tablename1 DROP FOREIGN KEY fk_name1; //get rid of current constraints
ALTER TABLE tablename2 DROP FOREIGN KEY fk_name2;

ALTER TABLE tablename1
  ADD FOREIGN KEY (table2_id)
        REFERENCES table2(id)
        ON DELETE SET NULL  //add back constraint

ALTER TABLE tablename2
  ADD FOREIGN KEY (table1_id)
        REFERENCES table1(id)
        ON DELETE SET NULL //add back other constraint

Have a read of this (http://dev.mysql.com/doc/refman/5.5/en/alter-table.html) and this (http://dev.mysql.com/doc/refman/5.5/en/create-table-foreign-keys.html).
Comment: Beware alterting table can take a long time, better to set the server global for `FOREIGN_KEY_CHECKS` to 0 and put it back once the dirty work is done. Besides it might lock for writing your tables.
Comment: Won't that break the reference when altering the remote column type? (It seems my client renames a modified temp table to the original table name.)
Answer: To turn off the foreign key constraint globally:
SET GLOBAL FOREIGN_KEY_CHECKS = 0;

And for the active foreign key constraint:
SET GLOBAL FOREIGN_KEY_CHECKS = 1;

Comment: This appears to be an exact duplicate of an [existing, older answer from @berniey](https://stackoverflow.com/a/24602164)
Answer: A very simple solution with phpMyAdmin:

In your table, go to the SQL tab
After you edit the SQL command that you want to run, there is a check box next to GO, named 'Enable foreign key checks' .
Uncheck this check box and run your SQL. It will be automatically rechecked after executing.
Comment: Thanks! Indeed solution `SET FOREIGN_KEY_CHECKS=0; ..... SET FOREIGN_KEY_CHECKS=1;` didn't work for me in PHPMyAdmin because I forgot to uncheck the 'Enable foreign key checks' checkbox. In PHPMyAdmin you can skip these SET commands and just uncheck the checkbox.
Answer: For me just SET FOREIGN_KEY_CHECKS=0; wasn't enough.
I was still having a com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException.
I had to add ALTER TABLE myTable DISABLE KEYS;.
So:
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE myTable DISABLE KEYS;
DELETE FROM myTable;
ALTER TABLE myTable ENABLE KEYS;
SET FOREIGN_KEY_CHECKS=1;

Comment: FYI, mySQL 5.7 throws warning, InnoDB engine doesn't have this option when running DISABLE KEYS command.
Comment: this did work, without the alter table it also didn't work for me
Comment: This solved my issue! thank you very much for this answer!
Answer: In phpMyAdmin you can select multiple rows and can then click the delete action. You'll enter a screen which lists the delete queries. It looks like this:

Please uncheck the "Enable foreign key checks" checkbox, and click on Yes to execute them.
This will enable you to delete rows even if there is an ON DELETE restriction constraint.
Answer: If the key field is nullable, then you can also set the value to null before attempting to delete it:
cursor.execute("UPDATE myapp_item SET myapp_style_id = NULL WHERE n = %s", n)
transaction.commit_unless_managed()

cursor.execute("UPDATE myapp_style SET myapp_item_id = NULL WHERE n = %s", n)
transaction.commit_unless_managed()

cursor.execute("DELETE FROM myapp_item WHERE n = %s", n)
transaction.commit_unless_managed()

cursor.execute("DELETE FROM myapp_style WHERE n = %s", n)
transaction.commit_unless_managed()

Answer: It's not a good idea to set a foreign key constraint to 0, because if you do, your database would not ensure it is not violating referential integrity.  This could lead to inaccurate, misleading, or incomplete data.
You make a foreign key for a reason:  because all the values in the child column shall be the same as a value in the parent column.  If there are no foreign key constraints, a child row can have a value that is not in the parent row, which would lead to inaccurate data.
For instance, let's say you have a website for students to login and every student must register for an account as a user.  You have one table for user ids, with user id as a primary key; and another table for student accounts, with student id as a column.  Since every student must have a user id, it would make sense to make the student id from the student accounts table a foreign key that references the primary key user id in the user ids table.  If there are no foreign key checks, a student could end up having a student id and no user id, which means a student can get an account without being a user, which is wrong.
Imagine if it happens to a large amount of data.  That's why you need the foreign key check.
It's best to figure out what is causing the error.  Most likely, you are trying to delete from a parent row without deleting from a child row. Try deleting from the child row before deleting from the parent row.
Comment: No one is saying to run it like this forever. You turn off constraints, bulk load some data, and flip it back on. No big deal, people do it all the time.
Comment: This is not an answer to the question.
Comment: True, there's always a trade-off.
Comment: it is necessary for bulk imports, for performance at least, it is very common. also sometimes you just need the data to be restored, then you can make your checks.
Comment: Note, his question is how to do this temporarily.  This is required when doing certain maintenance and data imports. The caveat of course is that your import scripts become responsible for data integrity.  Then, later when the indexes and constraints are turned back on, the db will tell you if something is broken.
Comment: have you ever used phpMyAdmin?
Comment: There are situations where this is useful.
Comment: Example:

I have a table with a self-referential foreign key. The two fields are main_character_id and character_id. Each character_id must have at least one matching main_character_id. I generally want the foreign key constraint here, but it prevents me from deleting any main character (which would have the same value in both fields).

I could solve this by adding a main_character_id of 0 or -1 in the table that's used to allow update and deletion of other main characters, but is having false data better? Probably not.
Comment: I can not agree with you as it's not a permanent solution. I know this solution helped me on several occasions. Importing tables one by one in the order of constraints does not seem to be practical.


How does an intelligent race which can only perceives microwave develops written language?

Question: Imagine a race of humanoid alien living somewhere in the universe evolves weird sensory organ which can only picks up frequency of light ranging from 800MHz up to 2.5GHz which is in the microwave spectrum. They can hear and talk but how would they read and write? The more primitive the tech the better.
Comment: @user535733: no, see blackbody radiation and radar.
Answer: Using metal
Metals, such as aluminum, reflects microwaves. Therefore, they'd just use metals to write. It might start with something as crude as banging a metal rocks against cave walls to leave a pattern, but eventually they'd develop metal-based inks to write with against none microwave reflective items.
Comment: You could just make a paste of fine metal powder and glue.
Comment: @KlausÆ.Mogensen That's pretty much just what ink is. A vehicle (glue) and a pigment (metal dust). (And a catalyst to help it dry faster.)
Answer: When you mentioned reading it brought me to think about how (regular) humans can read nature and know when it's going to snow, or if there is danger nearby.
They must be sensing a pattern which is communicating information. A natural material that can "record" electromagnetic pulses and then emit these pulses would suffice for transmitting information. You would basically "read" the material by being in the vicinity that it is pulsing. You can write to the material by modulating the pulses the material emits.


How do I create my own mulch?

Question: I have a pile of small wood chips from felled trees.
I want to create black mulch.
Can I do it and how?
Comment: Please note that the "no answers I'm comments" rule is still valid. If you are unsure of what you are suggesting, I recommend you re-read [answer] and then decide whether it's an answer or not.
Answer: You can buy mulch dyes in a variety of colors. A simple google search will reveal many sources. I have no idea what's in them, but one said "environmentally safe", whatever that may mean.
Comment: sprayed my mulch with a product like you suggested and it looks great.  If it's mulch it's perfect; doesn't work so well on twigs or areas with sparse mulch.  Think it is a great idea to refresh every other year to save money.
Comment: If you think about it, stop by again next year and update us on how it holds up over time.
Comment: I will.  You can see the difference.  My thinking is to re-mulch every OTHER year and color the next.  It doesn't color the dirt so well and the mulch gets kicked around.  But if it saves me $8K/yr it's worth it.

How do I create my own mulch?


What are the pro and cons of two stage vs single stage triggers for hunting?

Question: In addition to getting a trigger with a lighter pull weight, I also have the option of switching from a single stage to a two stage trigger. What would the pros and cons of doing so be?
Answer: What the 2-stage gains you is having a perceived lighter trigger weight even though it is the same overall. I forget the technical term for it, but the first stage takes up the "slack" or travel in the trigger up to where you reach the second stage. From there it acts just like a single stage. So the potential benefit is if you can set the first stage high enough, you need just a little bit more squeeze to fire the trigger.
For example, in your other question we assumed you had a 7-8 pound pull. With a single stage you keep squeezing until you reach that 8 pounds and BANG. With a 2-stage, you could set the first stage to say 6 or 7 pounds (depends on the springs how much adjustment you have). So now you pull back 7 pounds and you reach a stop. At that point you know it's just another pound until BANG.
There isn't really much against having one other than cost and being slightly more complex. For hunting I wouldn't bother, but it would give you something to play with. :)
Comment: I would add my own $0.02, but I can't beat that.  'Xactly.
Answer: I can't say for sure on rifles how well a 2-stage trigger works, but I like it for my revolver.
Personal preference for me would be to go to a lighter trigger on a rifle though.  This is primarily to reduce the finger squeeze pressure you're exerting to complete the first stage.  I feel like that could potentially throw off your shot.
However, for me and my revolver, it is pretty nice.  It doesn't have safeties and no external hammer.  So, I can pull partway, better line up my shot, then complete it for a more accurate shot.
When it comes to long guns, I would prefer a lighter trigger since I would have those external safeties.  As in, when I put my finger on the trigger, I mean to shoot very soon.  I would rather not have an intermediate step in between that process.
It really comes down to personal preference and which option you work better with.  Try and compare both options and find what works best for you personally.


Sun God vs. Temple of the Sun God?

Question: Which is better: 5 sun gods or 1 temple of the sun god? I don't want to sacrifice all my sun gods if the temple doesn't do better!
Comment: Simply keep the 5 sun gods. It should be enough to complete any challenge on any difficulty. If you are free-playing you may consider saving up allot of money and then building a temple and some additional sun gods afterwards.
Answer: I believe (from personal experience) that the 5 sun gods are a lot stronger than a Temple of the sun god. Just keep it as is, it is plenty strong enough to handle many situations, if you have them strategically placed. Just keep buying sun gods.
Comment: I've never made it past level 90, so yer. My experience isn't that great.
Comment: IMO, the Sun God Temple is better if you can get all of the Sacrifices into it when you upgrade it.
Comment: not from my experience.  The biggest draw of the temple of the sun god is that the shots will penetrate everything.  I believe that eventually there'll be enough bloons to soak the damage from regular sun gods, at least from me playing into higher levels.
Comment: A max temple is definitely better, but much more expensive. Also, the Super Monkey itself and all its upgrades are overpriced for its ability
Answer: Sun gods are more powerful not temple-ized. However, when you make a Temple of the Monkey God, all the other towers in its range are taken in and combined into the temple to make it have more power, plus now you have more space to build other towers, or more Temples if you like.
It is your choice, though, depending on your playing style.
Answer: The temple will do more damage to MOAB class bloons, so its better late game, where you can get it (unless youre like me and use tons of special agents and banana farms. The earliest ive gotten a perfect temple is round 60)
Answer: If you fully upgrade the monkey temple, then it is leagues above the sungods. However, if you don't sacrifice to the temple, the sun god is better in every respect.  To get a fully upgraded temple, if I remember right, you need 30k in each category: bombs(bomb and mortar), magic, ice, glue, and misc.  Also, you can sacrifice a monkey village to the monkey temple to give it the buffs internally. This doesn't stack with any other village you might or might not have on the temple itself after you upgrade it.

Sun God vs. Temple of the Sun God?


Is weakly compact subset weakly separable?

Question: Let $X$ be a Banach space and $K$ be a weakly compact subset of $X$, i.e. compact set with respect to the $\sigma(X, X^{*})$-topology. Is it true that $K$ is weakly separable?
Since weak topology is never metrizable for infinite dimensional space, it is impossible to construct a countable dense subset using a metric. Also, I tried to use Eberlein-Smulian theorem, which states that weakly compactness is equivalent to weakly sequentially compactness. But this isn't helpful to me.
Comment: If this is not true in general, it will be helpful to show for $l_\infty$.
Answer: Let $H$ be a non-separable Hilbert space, say one with an orthonormal basis $\{e_t\}$. Let $K$ be the closed unit ball of $H$. By Reflexivity and Banach Alaoglu Theorem $K$ is weakly compact. Suppose there is a countable dense set $\{f_n\}$ in $K$. Since the weak closure of $M \equiv span \{f_n:n \geq 1\}$ is equal to the norm closure we see that each $e_t$ is in the separable Hilbert space spanned by the $f_n$'s. This is a contradiction.


Intuition for Gram-Schmidt process

Question: Let V be a finite dinner-product space, given a$ v_1,...v_n$ orthogonal bases, and $w_1,...w_n \in W $be subspace of V. Then $v_1=w_1$, $v_2= w_2-proj_w v_2$, $v_3= w_3-proj_w v_2- proj_w v_3$... I know that $proj_w v_i$ is the vector $v_i$ projected onto W subspace. How to intuitively understand Gram-Schmidt process, why as i gets bigger, we keep on subtracting more? I looked up the diagram on Gram-Schmidt, but still fails to get the sense.
Wiki for Gram-schmidt
Answer: When you project a vector onto a subspace (any dimension), and subtract the result, you get a vector orthogonal to the subspace.  Projection onto an $n$-dimensional subspace, on the other hand, can be accomplished by adding the projections onto the
$n$ individual members of an orthogonal basis.
Perhaps try an example.  Project $(x,y,z)$ onto the $2$-dimensional subspace spanned by the unit vectors in the directions of the $x$ and $y$ axes.  These two are often denoted $\bf{\vec i}$ and $\bf{\vec j}$.  The projection in this case is of course $(x,y,0)$.  And that's indeed $(x,y,z)-(x,0,0)-(0,y,0)=(x,y,z)-\operatorname{proj}_{\bf{\vec i}}(x,y,z)-\operatorname{proj}_{\bf{\vec j}}(x,y,z)$.  After subtracting, and normalizing, you of course get $\bf{\vec k}=(0,0,1)$, to complete the standard basis.
Answer: What helped me was to just follow the algebra.
We claim that $\mathbf{v} - \frac {\mathbf{u}\cdot \mathbf{v}}{\mathbf{u}\cdot \mathbf{u}} \mathbf u$ is orthogonal to $\mathbf u$.
In which case $\mathbf {u}\cdot(\mathbf{v} - \frac {\mathbf{u}\cdot \mathbf{v}}{\mathbf{u}\cdot \mathbf{u}} \mathbf u) = 0$
Try it out.
$\mathbf{u}\cdot \mathbf{v} - \frac {\mathbf{u}\cdot \mathbf{v}}{\mathbf{u}\cdot \mathbf{u}} \mathbf{u}\cdot \mathbf{u} = \mathbf{u}\cdot \mathbf{v} - \mathbf{u}\cdot \mathbf{v} = 0$
Comment: Next we need to figure out what to do to $\mathbf w$ so we subtract the projection of $\bf u$ onto $\bf w$ and we get a vector that is orthogonal to $\bf u$.  Then we subtract the projection of the transformed vector $\mathbf{v} - \frac {\mathbf{u}\cdot \mathbf{v}}{\mathbf{u}\cdot \mathbf{u}} \mathbf u$ onto $\bf w$.  We know that this vector is orthogonal to $\mathbf u$ so subtracting a multiple of it doesn't add anything in the $\bf u$ direction.  And we know that it will be perpendicular to our transformed vector.
Comment: then why it keeps adding on more projections?
Answer: The article you linked is quite good and has a very nice animation
Say have two linearly independent vectors $\mathbf{u_1},\mathbf{u_2}$
You first calculate $proj_{\mathbf{u_1}}(\mathbf{u_2})$, the projection of $\mathbf{u_2}$ to the line generated by $\mathbf{u_1}$ which is calculated by $\frac{\mathbf{u_1}\cdot\mathbf{u_2}}{||\mathbf{u_1}||}\mathbf{u_1}$
Now if we subtract it from $\mathbf{u_2}$ we'll get rid of the "common" part of the two vectors (that's where the Venn's diagram comes into play).

You can now easily prove that $\mathbf{v_1} = \mathbf{u_1},\space \mathbf{v_2} = \mathbf{u_2} -\frac{\mathbf{u_1}\cdot\mathbf{u_2}}{||\mathbf{u_1}||}\mathbf{u_1}$ are orthogonal
How would you construct an inductive proof for $n$ vectors?

Intuition for Gram-Schmidt process


Birthday Paradox 2 pairs

Question: I have followed the various birthday paradox posts. Can someone please assist with the logic for finding the probability of two pairs of people with the same birthday in a group of $23$. If $n=23$ gives us more than $0.5$ probability of one pair, what is the outcome for two pairs in the same population (assuming the second pair do not share the same birth date as the first pair)?
Answer: For the standard birthday problem, the number of possible sequences of $n$ birthdays that don't have two the same is $365\times364\times...\times(365-n+1)$ and so the probability that we don't have two the same after $n$ attempts is
$\frac{365\times364\times...\times(365-n+1)}{365^n}=p_n$, which goes below $1/2$ at $n=23$.
The probability of either having all birthdays different or exactly one pair the same, all others different, or exactly three people the same, all others different is $$\frac{365\times...\times(365-n+1)+\binom n2365\times...\times(365-n+2)+\binom n3365\times...\times(365-n+3)}{365^n}\\=p_n\bigg(1+\binom n2\frac1{365-n+1}+\binom n3\frac1{(365-n+1)(365-n+2)}\bigg).$$
Thus we need to check when this is less than $1/2$. This first happens at $n=36$.
This assumes that you count any two pairs, including where both pairs have the same birthday. It would be more complicated to exclude this, and it shouldn't make very much difference, but as it happens the probability is actually very close to $1/2$ at $n=36$.
(edit: Actually, doing some more careful bounds, the probability of not having exactly one set of $2$, $3$ or $4$ the same, all others different at $n=36$ is $0.49944$. A simple bound on the probability of any configuration with $5$ or more people having the same birthday is the expected number of sets of $5$ people with the same birthday, and this is only $0.0000212$, not enough to tip the probability over $1/2$. So it is $n=36$ with either interpretation.)

Birthday Paradox 2 pairs


Programmatically fill PDF forms from Excel data

Question: I am seeking to implement PDF form filling in Windows. The data is in Excel 2010. I prefer to do this programmatically from Excel VBA. The target PDFs are IRS tax forms, which are PDF versions 1.6 and 1.7. What is an automated form filling method?
Answer: There is a company out there called Foxit Software that seems to have some pretty good PDF tools.  I currently use their Reader instead of Adobe's and have found it be faster, less resource intensive and crash less.  The do have some SDK options:
http://www.foxitsoftware.com/pdf/sdk/
It seems like there should be a way to use ActiveX with Excel.  The big unknown is that they do not list any SDK pricing on their website, but it might be worth the time to contact them and find out what they have to offer?
Comment: Thanks for the answer, but this is not open source. Form fill requres the pro version and is not free.
Comment: Very true.  One thing that came to mind is if you were willing and able to write a stand-alone app in say Java or .NET, there are many tools available to process these types of documents.  For example, in .NET you could read an Excel document using OLEDB and modify a PDF file using iTextSharp.  In any case, good luck with whatever route you end up taking.
Answer: Maybe my open source tool BulkPDF could do what you want.
What is BulkPDF?

BulkPDF is a free and easy to use freeware software (Open Source), which allows to automatically fill an existing PDF form with different values. Only a spreadsheet (Microsoft Excel 2007/2010/2013, LibreOffice or OpenOffice Calc) with the desired values is required.

How does it work?

BulkPDF automatically recognizes the values in the selected table. Then the column names must be manually assigned to the form fields. After the fill progress have started, BulkPDF will go through line by line and write the cell value into the form.

Functions

Supports text fields, checkboxes, radio buttons, combo boxes, and list boxes
Individual configuration for each form field
Filename freely configurable with automatic value
Setable write protection for individual form fields as well as for the entire document
Save and load the configuration
Configuration manually adjustable (XML)
Relative paths in the configuration file possible
Command line tool available
Compatible with Acroform and XFA


With sheet music, how do you determine whether the song is in the major key or the minor key?

Question: For example, if the key signature on the left doesn't have any sharps or flats then it could theoretically be in either the C Major scale or the A Minor scale. How do you determine which one?
Answer: If it starts on C and ends on C, it's probably in C.  And vice versa.
If it has lots of A minor and E minor chords, it's probably in Am (E is the dominant).  Likewise, lots of Cs and Gs implies C Major.
There are a few other indicators — for example, the harmonic minor scale raises the 7th one semitone (as Jenny mentions) and the melodic minor raises both the 6th and 7th while ascending — but largely speaking it doesn't matter.  Frequently, they are two names for the same thing.  Often people say that minor keys sound sad and major keys sound happy or triumphant, but this is nothing more that psychological tricks (see Why do minor keys sound "sad"?).
You can use C Major to write a sad song, and you can use A minor to write a happy song.  In the end, the only way to know what key is being used is to ask the composer.  The intent is the only thing that unequivocally distinguishes a major key from the minor with the same key signature.
Comment: Actually most pieces in A minor are more likely to have more chords in E *major*, while pieces in C major will tend to have E minor chords.  Another common sign of the minor key is the raised leading tone.
Comment: @phoog: To further complicate things, it's not uncommon for songs to use chords that would be common in both relative major and minor.  Hotel California, for example, is in two sharps, and features the Bm, Em, and F# chords expected of B minor, but also includes the A, D, G, and E chords expected of D major.
Comment: @supercat sure, spending time in the relative major or minor is pretty normal.  But are there many F# *minor* chords in the song?  Those would be more likely in a piece in D than in one in Bb minor.  Of course, a song in a major key can also have a secondary dominant on the relative minor, a minor chord on the third scale degree of a major key is far more common than a minor chord on the fifth scale degree of a minor key.  (Also, are those E chords really E major? The normal ii chord in D would be E minor.)
Comment: @phoog: The verses are Bm F# A E G D Em F#.  The first E is major; the second one is minor.
Comment: @supercat ah, chromaticism.
Comment: @phoog: I think it's better described as out-of-order circle-of-fifths progression, so the E major serves as a secondary-dominant V/VII, while the Em serves as the iv.
Answer: Minor keys will usually have the 7th note raised.  E.g. in A minor the 7th note is G, so you will see Gsharps throughout the music
Answer: If i want to determine the key of a song or part of a song. I'm looking for dominant chords and where those resolve to. If i see a G7 (and especially when it resolves to C chord) - then i suspect C major. For a minor often this will be E7 (in place o Em7) resolving to Am chord.
This E7 is dominant chord from harmonic minor scale and is in common use.
This is not a 100% sure method, but i would say 90% :) Whether You need to determine key for jazz changes or for the pop tune.
P.S. Looking at the last note in melody can be another tip
Answer: In C-Major, the "main" chord of a song is usually the C-E-G chord, and that's usually the beginning and ending chord of a song. The other two most common chords in simple tunes are C-F-A and B-D-F-G. If the song uses those chords, then it's probably in C major.
If it uses a minor third instead of a major third in the first two notes of the primary chord (3 half-steps vs. 4 half steps), then it's minor. Play these on the piano and you'll hear the difference:  C-Eb-G is minor, and C-E-G is the major chord. You can transpose up to A to make the comparisons there, too.
Answer: You look at the score. Between the Clef and the Time Signature there will usually be some sort of indication of the key. If there is no sharps or flats in between the clef and the time signature then you are either in C Major or a minor. (The Major key with no sharps or flats)
Then you need to look at whether there are any notes raised in the piece. The leading tone of minor keys is always raised by a semitone. So if you see a G# you need to think a minor.

Think about the sharps they give.
Determine the Major key that consist of those sharps.
Determine the relative minor of that Major key.
Look for the leading tone of the minor key.
See if it is raised or not.

And remember the note that could be raised could be a flat that is raised to the natural note. It could be a c that is raised with the use of a sharp or it could also be a note with a sharp raised to a double sharp. So do not just assume if you do not see a sharp that there is no notes raised.
Comment: Unless I am listening to Bach or a music genre besides classical music, what I usually hear and what I prefer for flat keys is natural minor. A minor and sharp keys are the keys in which I commonly hear harmonic minor. But rarely will I hear a B in a C minor piece unless the piece is modulating to a key with a B instead of a Bb in its scale(so like C minor modulating to C major for example). Similar story for A in C minor
Answer: You're kind of over complicating this. The best [and easiest] way to find out whether it is C major or A minor is by looking at which note starts and ends the song. Sometimes, this doesn't work and you might feel a little lost. You need to look at which note is within the song more frequently than the other. That should help


Google Reporting API with oauth 2.0

Question: I want to use Google Reporting API to get the users' activity report (last login, etc).
My application is using oauth 2.0 to access other Google APIs. But it seems like  Google Reporting API is not supporting oauth 2.0. Any suggestions how should I do it ? Implement oauth 1 or use different Google API (if it exists) to get users' activity report?
Answer: I think you are looking at the old documentation for the reporting API.
For the brand new reports API (https://developers.google.com/admin-sdk/reports/v1/guides/authorizing), it is encouraged to use OAuth 2.0.
Notice that the older API is called reporting API, but the new API that was just released at the IO is called reports API.

Google Reporting API with oauth 2.0


PDF tool similar to ImageMagick

Question: I was introduced to ImageMagick a few months back for manipulating images for print but now I'm curious to know if anyone has seen one for .pdf?  I would like to create scripts that will check or modify crop, bleed, font embedding, and the like.
Comment: Why not.... ImageMagick ? it can work on PDF as it works with images. Of course, you won't manipulate fonts but you will be able to crop, extend, repage...
Answer: I don't think there's any tool for PDF files that has a large set of commands like ImageMagick. Here are a few with their main capabilities.

pdfjam, a shell wrapper around the pdfLaTeX pdfpages package. Pdfjam includes some specialized commands (pdfnup to make 2-up arrangements and so on, pdfbook to make booklets, pdfjoin to concatenate several files, pdf90 and so on to rotate pages) and can set metadata (author, title, keywords, …), scale and rotate pages, and so on. The pdfpages package lets you arrange pages or parts of pages of one or more files in any way you want and write arbitrary LaTeX code around them.
pdftk is primarily useful to reassemble known amounts of pages but has other capabilities.
The pyPdf Python library can easily reassemble pages in complex ways, and can crop and merge pages. Example: un2up, unbook.
Perl's PDF::API2 is more complex and can embed fonts.
Ghostscript works with PostScript and PDF files. It can embed fonts in a PDF file.

If you want to work on a PDF file as a bitmap image, ImageMagick does that. It doesn't support multiple-page PDF files well, so extract and recompose your files with other tools.
Answer: I will prefer Inkscape  similar to ImageMagick
Comment: Why? How does Inkscape handle pdfs in a way that imagemagick does images? ImageMagick is a command-line tool, while Inkscape is GUI-based. Also, I have been Inkscape a lot, but never for pdf-files. Maybe you can refer to some relevant sections on their website to improve your answer?

PDF tool similar to ImageMagick


Where do Great Musicians go?

Question: I've gotten my great musicians to go to certain wonders, but not sure where else to put them. My theater districts accept artists, writers, and artifacts (depending on art gallery vs arch museum). Where do I put them? And how do I do a tour? Do I just put them to another civ's building that I would drop them on usually? I do have open borders with a few folks right now.
Answer: The way to place Great Musicians easily is way later in the game apparently with http://civilization.wikia.com/wiki/Broadcast_Center_(Civ6)

Where do Great Musicians go?


With $A,B,C \subseteq X$ prove that $(A \cap B) \subseteq C$ if and only if $A \subseteq ((X \setminus B) \cup C$)

Question: I drew a Venn diagram and it is clear to me why it is true. However I just have difficulty formalizing the proof. So far I first tried proving from left to right, assuming that $(A \cap B) \subseteq C$ and working from there to try and show that $A \subseteq ((X \setminus B) \cup C)$, but I'm completely stuck. Any help would be appreciated.
Comment: Perhaps trying to come up with how you would *say* $A \subseteq ((X - B) \cup C)$ would help: For each $a \in A$, I would say $a \in X - B$ means that "$a$ is not in $B$", while $a \in C$ of course means "$a$ is in $C$". We're linking them with a union, so we want to say that the first is true, *or*, the second is true...
Answer: I would have a look at the definitions of subset, complement, intersection and union.
Let $x \in A$. Then if $x \in B$, we have by $A \cap B \subseteq C$ that $x \in C$ and thus $x \in (X \setminus B) \cup C$. If $x \notin B$, we have that $x \in X \setminus B$ and thus again $x \in (X \setminus B) \cup C$. Conversly, if $x \in A \cap B$, then $x \in A$ and thus $x \in (X\setminus B) \cup C$. But $x \in X\setminus B$ cannot be true since if $x \in A \cap B$ so is $x \in B$ hence $x \in C$.
Answer: With the use of De Morgan's Law, Associativity for $\cap$, and the fact that two sets are disjoint iff one set is contained in the complement of the other, we get
$$
\begin{align}
(A\cap B)\subseteq C &\iff (A\cap B)\cap C^c=\emptyset\\
&\iff A\cap (B\cap C^c)=\emptyset\\
&\iff A\cap (B^c\cup C)^c=\emptyset\\
&\iff A\subseteq (B^c\cup C)\\
&\iff A\subseteq[(X\smallsetminus B)\cup C].
\end{align}
$$
Answer: Here is an element-level or 'element chasing' proof.  But let's first write down the statement a bit more formally: given $\;A,B,C \subseteq X\;$, prove
$$
\tag{0}
A \cap B \subseteq C \;\equiv\; A \subseteq (X \setminus B) \cup C
$$
For statements like this, it is often helpful to start at the most complex side, and use simplification to work towards the other side.  And for set theory proofs, it often helps me to be able to reason at the level of logic.$
\newcommand{\calc}{\begin{align} \quad &}
\newcommand{\op}[1]{\\ #1 \quad & \quad \quad \unicode{x201c}}
\newcommand{\hints}[1]{\mbox{#1} \\ \quad & \quad \quad \phantom{\unicode{x201c}} }
\newcommand{\hint}[1]{\mbox{#1} \unicode{x201d} \\ \quad & }
\newcommand{\endcalc}{\end{align}}
\newcommand{\Ref}[1]{\text{(#1)}}
\newcommand{\then}{\Rightarrow}
$
Here, the right hand side of $\Ref{0}$ is the more complex one.  So, let's calculate:
$$\calc
    A \;\subseteq\; (X \setminus B) \cup C
\op\equiv\hint{definition of $\;\subseteq\;$}
    \langle \forall x :: x \in A \;\then\; x \in (X \setminus B) \cup C \rangle
\op\equiv\hint{definitions of $\;\cup,\setminus\;$}
    \langle \forall x :: x \in A \;\then\; (x \in X \land x \not\in B) \;\lor\; x \in C \rangle
\op\equiv\hint{using $\;A \subseteq X\;$, so $\;x \in A \then x \in X\;$; simplify}
    \langle \forall x :: x \in A \;\then\; x \not\in B \;\lor\; x \in C \rangle
\op\equiv\hints{write $\;P \then Q\;$ as $\;\lnot P \lor Q\;$}\hint{-- to bring $\;A\;$ and $\;B\;$ together, as in the LHS of $\Ref{0}$}
    \langle \forall x :: x \not\in A \;\lor\; x \not\in B \;\lor\; x \in C \rangle  \tag{*}
\op\equiv\hints{write $\;\lnot P \lor Q\;$ as $\;P \then Q\;$; DeMorgan}\hint{-- to better match the LHS of $\Ref{0}$}
    \langle \forall x :: x \in A \;\land\; x \in B \;\then\; x \in C \rangle
\op\equiv\hint{definition of $\;\cap\;$}
    \langle \forall x :: x \in A \cap B \;\then\; x \in C \rangle
\op\equiv\hint{definition of $\;\subseteq\;$}
    A \cap B \;\subseteq\; C
\endcalc$$
This completes the proof.
Note the nice symmetry in this proof, centered around $\Ref{*}$: everything up until that point has been expanding definitions and simplifying.  Also note that we didn't need the assumption that $\;B,C \subseteq X\;$.  Finally, if you're curious, the above proof notation was designed by Edsger W. Dijkstra et al.; see for example EWD1300.


Is it safe to refreeze a tuna sandwich?

Question: I made a sandwich two days ago that consists of white bread and canned tuna. I put it in my freezer immediately after making it and it stayed there until today. This morning I took it to work, planning to eat it for lunch, but am now going out for lunch instead. I'd rather not waste the sandwich, so is it safe to refreeze it until tomorrow? It has been out of the freezer for 5 hours and sitting in my desk drawer.
Comment: It doesn't matter if it is a tuna sandwich or a piece of raw meat, food safety rules are consistent enough to apply to both. Closing as a duplicate of our standard refreezing question. There are others on refreezing, you can see them in the sidebar.
Answer: The larger issue is the storage time that the sandwich has already been subjected to. 5 hours at room temperature is enough time for at least some of the tuna to spend significant time in the "danger zone" (the temperature range from 40 to 140 degrees F where bacteria grow most quickly).
At this point I would not consider the sandwich safe, regardless whether you refreeze it. Refreezing will not render it safe again and I would recommend tossing it.
Comment: I do that everyday, haha. I leave for work quite early in the morning and don't take lunch until around 1PM. Never caused me a problem (that I'm aware of), but I don't doubt what you say is true!
Comment: @lilligantex Frankly then, you've gotten lucky. At minimum it's a good idea to get a reusable cold storage bag that will keep your food colder for longer so that it doesn't reach risky temperatures.
Comment: Lucky for over a year! Haha. But noted. Thanks! :)
Answer: When you freeze anything that contains moisture, freezing produces ice crystals that rupture cell walls; this damage speeds up any spoilage that might begin. The more often you freeze a food, the more damage is done. I would advise against re-freezing anything you plan to eat without cooking, simply out of concern over not knowing how quickly any spoilage will progress as it thaws.
Comment: Placing it in the fridge would be better, simply because the fridge wouldn't freeze the sandwich, but I would still have misgivings about the sandwich. It did, after all, spend significant time in a warm environment after being frozen. While I am a big fan of being frugal and not being unnecessarily wasteful, I am not a big fan of food poisoning. I would go with being necessarily wasteful and getting rid of the sandwich.
Comment: Thank you. Would placing it in the refrigerator rather than the freezer be any better?

Is it safe to refreeze a tuna sandwich?


Is there any device/technology based on QFT in curved space?

Question: General relativity has given us the GPS, and  QFT has provided a big amount of useful technology, from medical treatments to advances in condensed matter. Can QFT in curved space lead to similar advances in technology/engineering/condensed matter? Is there any pratical device or technology at least inspired in QFT in curved space?
Comment: I highly doubt any medical treatment depends on QFT. Also, that GR is needed for GPS [is a myth](http://physics.stackexchange.com/a/128951/).
Comment: http://www.nejm.org/doi/full/10.1056/NEJMra050276
Comment: PET scans were invented in the 50s, before almost all of QFT. And positrons themselves were discovered in the late 20s. One doesn't need QFT to use radioisotope tracers; one hardly even needs quantum mechanics.
Answer: It seems rather implausible that results from quantum field theory in curved spacetimes will lead to any technological innovations in the foreseeable future. This is mainly due to the fact that the length scales at which QFT in curved spacetimes starts to significantly differ from ''regular old'' QFT is much, much larger than our Earth.
Hence, it seems unreasonable to try to build any devices which relies on predictions that can only be made using QFT in curved spacetimes. That being said, never say never...
Comment: Would it be possible to relate quantum field theory in curved space-time with quantum fields living on a sphere, for instance?


How to use bevel node without joining objects?

Question: I have an object with modifiers, it is a bit complex, it is intersected by another object that is CAD modeled (it does not have a good topology), My idea was to use the bevel node to smooth the intersection however I think this only works if one of the two objects which I cannot do for the modifiers and boolean either (it generates errors due to the bad topology of the CAD object), is there any way to use the bevel node in two different objects?
Answer: As long as these objects are not connected in the Edit Mode, Blender cannot understand the correct way to bevel the intersection.
Below I shared a .blend file where I connected a cylinder and a cube in the edit mode. For more understanding on how to do that, I recommend this tutorial: https://www.youtube.com/watch?v=M4F6Q6h2-ao


Internship for PhD students

Question: I am a PhD student and I would like to do an internship at an American university or institute. How should I proceed?
Comment: Contact the university or institute at which you want to intern, and find out what their requirements are for international students.
Answer: If your advisor has contacts at any of the universities you'd like to work at, I would ask him or her to reach out for you. If you are looking to work with a specific faculty member, that is probably the trickiest route, as faculty members often use the summer to travel themselves, and it is rarely worth the hassle to hire an unknown student for the summer, anyway.
If you don't have a networking contact through your advisor or other faculty members at your school, my next suggestion would be to start networking at a conference, or through a professional organization that you are affiliated with (e.g., IEEE, AMS, etc.). Start getting the word out that you are looking to spend a summer at a U.S. school, and see if anyone has suggestions.
If you are looking for a paid internship, you may be at a disadvantage as an international student, and you are probably more likely to find something if you can fund yourself. If that isn't an option, you might also consider looking at internships in industry, as they tend to have more money for summer interns.
Answer: If you are in a STEM field, there are lots of options available to you. There are about 20 national laboratories that take students from every level of education as summer students, including international students. Personally, I've interned at Los Alamos National Lab and at Pacific Northwest National Lab. It's generally very applied work, but it's a great atmosphere for students and is also extremely helpful for making connections with potential future employers. I would look up national lab websites and look at their respective research areas, and contact individuals you would be interested in working with.
The internet is your friend -- many companies and government agencies have programs listed on their website, and many of them don't require US citizenship.
Comment: Be careful, though—many of the programs at national laboratories do __not__ take international students, which the OP appears to be.
Comment: I was at Pacific Northwest last summer, and many of the other interns were international students. International students (as well as international staff) were issued badges that had some access restrictions. The OP may be ineligible for some opportunities, but there are many internationals that do get internships at labs.
Comment: It definitely differs between labs. The Office of Science labs (Argonne, PNNL, Oak Ridge, etc.) definitely have a lower threshold than the National Nuclear Security Administration labs (Sandia, Los Alamos, Livermore).

Internship for PhD students


Distribution of 1-norm for Gaussian Unitary Ensemble

Question: Suppose I uniformly sample matrices X from the Gaussian Unitary Ensemble (GUE) with variance \sigma^2.  Consider the Ky-Fan d norm, i.e. the sum of the singular values, of X.  Let's call this Z=||X||_1.  What is the distribution of Z as a function of the dimension d and the variance \sigma^2? Really, all I want are estimates of the mean and a good tail bound, so maybe also the second moment.
Answer: Let's normalise the variance of the entries to be $1$.  Then GUE asymptotically obeys the semicircular law, i.e., the eigenvalues (which equal the singular values, as GUE is Hermitian), after dividing by $\sqrt{n}$, are distributed according to the law $\frac{1}{2 \pi} (4 - x^2)^{1/2}_+ dx$.  So the Schatten $1$-norm (Ky Fan norm) should asymptotically equal $\sqrt{n}$ times n times the integral
\begin{equation*}
\int \frac{|x|}{2 \pi}  (4 - x^2)^{1/2}_+ dx,
\end{equation*}
which Wolfram alpha tells me is $8/3 \pi$.  So the answer is $n^{3/2} ( 8 / 3 \pi + o(1) )$ with probability $1-o(1)$.  Using an explicit convergence rate for GUE, one can probably replace the $o(1)$ with $O(n^{-c})$ for some explicit constant $c>0$.
Getting the variance may be within current technology - it's some integral of two-point correlations of GUE, which are known - but somewhat tedious.  Higher moments should also (in principle) be computable.  My guess is that the limiting distribution will be asymptotically gaussian, but I might be wrong about this (the central limit theorem doesn't apply directly because the eigenvalues are correlated with each other).
Comment: Indeed, my only worry with using the semicircular law as heuristic was the non-uniform spacing of the eigenvalues - I gather this is all well understood by those who've thought about this more and better than I have, but thought it worth giving some cheap bounds that can be got by easy global arguments
Answer: I'm not at all expert on random matrix stuff, but until someone more qualified pops up, would you be interested in some crude estimates on Z in the $n \to \infty$ asymptotic? Or do you really want something sharper in each dimension?
EDIT/UPDATE: OK, here's my hand-wavy argument,
it's been a while since I did any probability theory, so caveat lector and all that.
I'm going to use the GOE just because that's the one I know better and to save me worrying about stray scaling factors.
The idea is that for any $n \times n$ matrices $S$ and $T$ we always have
$\Vert S\Vert_1 \Vert T \Vert_{\rm op} \geq |{\rm tr}(ST)|$
where the subscript 1 denotes Ky-Fan/Schatten 1-norm and the subscript "op" denotes usual operator norm. In particular, if $S=T$ is self-adjoint then
$\Vert S\Vert_1 \geq || S ||\_2^2\\, /\\, || S ||_{\rm op}$
Now when S is GOE(n,$\sigma^2$) then $n^{-2} \Vert S\Vert_2^2$ is strongly concentrated round its mean (which is $\sigma^2$) -- it's the average of a bunch of independent random variables so we could use variance estimates and Chebyshev, or probably some stronger exponential tail estimates.
Also, when S is GOE(n,$\sigma^2$) then $n^{-1/2} \Vert S\Vert_{\rm op}$ is strongly concentrated round $2\sigma$ - one can get exponential tail estimates, at least for an upper bound of $(2+\epsilon)\sigma$ for any positive $\epsilon$. I think this is folklore or a special case of Big Machinery, but as I said I have a more elementary proof, albeit one which is probably not original.
So, there is going to be a high probability (for $n$ large) that || S ||22 is bigger than $(1-\epsilon)\sigma^2n^2$, and there is going to be a high probability (for $n$ large) that $\Vert S\Vert_{\rm op}$ is less than $(2+\epsilon)\sigma n^{1/2}$. On the intersection of these two events you're going to find that
$\Vert S\Vert_1 \geq (1-\epsilon)n^2\sigma^2 / (2+\epsilon)\sigma n^{1/2}$
which gives the lower bound I was claiming.
Comment: As long as the estimate isn't too crude, then it should be fine.  There is one obvious way to get an estimate, which is to use a bound on the 1-norm in terms of the 2-norm, picking up a dimensional factor along the way.  I'd like to avoid that, if possible.
Comment: OK, I can almost (modulo some CLT handwaving) show that, for any c\in (0,1/2),

\sigma c \leq \liminf_n Z n^{-3/2} \leq \limsup_n Z n^{-3/2} \leq \sigma

The upper bound is, as you allude to, just the 2-norm and Cauchy-Schwarz. The lower one would follow from some known upper bounds on the spectral radius in the GUE (and I have a reasonably elementary proof of the analogous sp. rad. bound for the GOE, I don't think the complex case is significantly different).

Does this sound helpful? If so, I'll try to tighten up the argument - might post it on my blog if it checks out but looks a bit long.
Comment: Yes, that's helpful, thank you.  Do I understand that correctly, that this implies the optimal scaling I can hope for with Z is n^{3/2}?  I did a bit of numerics, and (at least for small n) it seemed like Z = O(n) up to maybe some log factors.  (I'm ignoring a constant that depends on \sigma...)  So this is a bit surprising.
Comment: Oh, and I should add: I'm mostly interested in an upper bound.  So don't worry too much about the lower bound.
Comment: Wow, that's great!  I can get the upper bound from here; I already estimated that one using 2-norm and Cauchy-Schwarz.  I didn't realize that it was tight because my numerics was off, so I was dreaming about an impossible bound.  Thanks for your help.
Answer: More precise results along the lines of Yemon Choi's answers are in two papers by Szarek: "Spaces with large distance to $l^\infty$ and random matrices", and "Condition number of random matrices".
Answer: Some vaguer thoughts: one way to try and get an intuitive handle on these kinds of global question, is to think of the not-quite-correctly named Wigner theorem on convergence to the semicircle distribution. That is, we know that if we scale the variance by 1/n then one gets convergence of the empirical spectral measure (in various senses) to a continuous density supported on [-2,2]. So there are going to be enough 'big' eigenvalues to drive up the values of the Schatten norms, in particular the sum of their absolute values should naively be O(n). This was when we scaled the entries by 1/\sqrt{n}, so to get a limit of the 1-norm it looks like we need a n^{-3/2} scaling.


Scroll bar arrows missing after a recent update of 15.10

Question: The scroll bar arrows seem to have disappeared from everything except Firefox after a recent update of Ubuntu 15.10. I have poor hand-eye coordination, and am having a very hard time adjusting to OSX-style arrow-less scroll bars. Is there a way of getting scroll bar arrows back, short of switching to a different window manager? I'm so frustrated that I'm actually starting to miss CDE on Solaris.
Answer: You need a theme for GTK that doesn't have those overlay scroll bars. Most pre-15.10 themes should work, for example Irradiance.
You need to use Unity Tweak Tool, Unsettings or a similar tool to select the theme as the official Unity settings only deal with themes for the current version of Unity.


Is there a tutorial how to compile my own monero cli wallet software from source?

Question: Is there an easy to follow guide on how to compile my own monero cli wallet from source code? I want to modify some very minor settings that has to do with initial wallet creation settings specifically the ask-password variable. Currently the ask-password variable on wallet creation is set to 1 as default. I want it to be 0 when creating a wallet as it doesn't seem like this can be set globally from a .conf file.
Answer: Compiling from source instructions are in the project README.
Though changing the Monero source code just to deviate from a sensible default value, which can be easily changed as soon as the wallet has been created in any case, seems a pointless exercise to me.
Comment: Point is, as soon as you've created them, you just run set ask-password 0 straight after, once. It's one extra step at creation.
Comment: the end result what I really want to do is be able to do a "refresh" of multiple monero private keys at once. if i can't edit the source code to do this that would be great, but currently I need to do all these weird work around's just to make this a reality by creating a wallet and then doing a periodic refresh for each address with its own instance.


Convert a discrete stochastic process with non-normal noise to continuous stochastic process

Question: Suppose I have a discrete stochastic process, in the form of
$$x_{t+1} = x_t + \varepsilon_t$$
where $\varepsilon_t$ is the random noise. The caveat is by examining the existing data, $\varepsilon_t$ does not follow a normal distribution. Suppose it follows a Cauchy distribution or more well-behavior distributions such as hyperbolic distribution. Is there any general procedure to convert this discrete stochastic process into a continuous stochastic process described by
$$dx = \mu(x, t) \, dt + \sigma(x, t) \, dW$$
where $\mu$ is the drift, $\sigma$ is the square root of variance of the noise, and $dW$ is Wiener process?
Answer: You would first need to check whether Donsker's applies to your process https://math.stackexchange.com/questions/274685/joint-convergence-and-donskers-theorem. If not, it could be that the process has some different limiting process $L$ eg. some Levy process https://en.wikipedia.org/wiki/Cauchy_process and so you will need to study the stochastic integral wrt to that process.


Vector or raster graphic for UI elements?

Question: Which type of graphic should I use for UI elements in web and mobile?
If I need to create @5x image size and then just reduce it or I need to create 1 vector image (like a button or icon) and just use this for all screen resolutions?
Comment: It would help to know a bit more about the context you're making this decision in. Perhaps you'll receive more specific suggestions :)
Comment: This isn't really a User Experience question. The end user doesn't care if you'e used a Vector or Raster image. So the issue you're having is with implementation, not with user experience.
Answer: If you are designing UI elements use vector graphics.
Use raster only for photos.
If you use vectors the elements you design will maintain their sharpness at any resolution.
EDIT: (I thought it would be better to add the answer to your comments in here)

I just want to understand which way create graphics.

It depends.
Vector and raster are different ways images are rendered on the screen.
With raster the image format stores the information of every pixel composing the image.
With vector the image format stores the position of each of the points of a path (and some other information; vector files can also include raster images). Then during render, the image shown on the screen is composed for each resolution.
There is no a "better" format, it depends on what is your goal.
Nowadays designers use software like Sketch, Figma, Adobe XD to design user interfaces because they render the images in a very similar way the browsers do. And they all work in vector.
In conclusion:
My advice would be to use the software you find yourself most comfortable with, and see how you go. The important thing is to start designing!
I am sure you will get familiar enough with UI Design that you will find the answer to this very question by yourself in no time :)
Comment: So it means that I don't need to create one button in size like 120x120px and then reduce it to 80x80 and 40x40 px? Just create 1 vector image and save it?
For example: iOS requires for me as designer create email@example.com, email@example.com etc
Comment: Alright, so do you have a list of specifications you need to follow?
Comment: You mean "alright" for this 'Just create 1 vector image and save it'?
For now I don't have any specifications to follow. I just learn and want to understand which way create graphics


For which $n$ are there primitive Pythagorean triples with legs of lengths $a$ and $a+n$?

Question: For which n can $a^{2}+(a+n)^{2}=c^{2}$ be solved, where $a,b,c,n$ are positive integers?
I have found solutions for $n=1,7,17,23,31,41,47,79,89$ and for multiples of $7,17,23$...
Are there infinitely many prime $n$ for which it is solvable?
Comment: @Angela: Very interesting question!
Comment: The title says "primitive", so $GCD(a,n,c)=1$ is assumed?
Comment: A paper with some useful info about this question is Delano Wegener. Primitive Pythagorean triples with sum or difference of legs equal to a prime. Wegener proves that your equation is solvable for prime $p$ iff $p=\pm1\mod 8$.
Answer: The general primitive solution to $x^2+y^2 = z^2$ is given by: $x=u^2-v^2$, $y=2uv$, $z=u^2+v^2$, with $u,v$ relatively prime and not both odd.
For $(a,a+n,z)$ to be a primitive triple, we'd have to have a $(u,v)$ such that: $|u^2 - v^2 - 2uv| = n$.  We can rewrite that as: $(u-v)^2 - 2v^2 = \pm n$
So, setting $w = u-v$, we want to find $(w,v)$ which are relatively prime and $w$ is odd, with:
$$w^2-2v^2 = \pm n$$
This means that $n$ must be odd.
In fact, we can use unique factorization in $\mathbb{Z}[\sqrt{2}]$ to show that $n$ can be any product of primes of the form $8k\pm 1$.  Since there are infinitely many primes of the form $8k\pm 1$, the answer to your question is, "yes."
(Oh, and once you find one solution $(w,v)$ for a particular $n$, you can find infinitely many solutions for that $n$.)
Comment: For example, $-71 = w^2 - 2v^2$ has solution $(w,v)=(1,6)$.  So $u=7$, $x=u^2-v^2 = 13$, $y=2uv=84$, and $z=u^2+v^2=85$, so $n=71$ has a solution with $a=13$.
Comment: Explicitly, if $p^2 + (p+n)^2 = r^2$, then subsequent ones can be found as $q^2 + (q+n)^2 = (p+q+r+n)^2$, where $q = 3p+2r+n$.
Answer: $2a^{2}+2na+n^{2}=c^{2}$ --> $a=-\frac{-n+\sqrt{2c^{2}-n^{2}}}{2}$ --> there are solutions iff $x^{2}+n^{2}=2c^{2}$ has solutions --> find the set of the squares of all integers 0 in the set such that $y=2x-n$ then there is a primitive pythagorean triple with a difference of n between legs, and also for any multiple An if n>1 since if $k^{2}\equiv x(\mod{n})$ then $(Ak)^{2} \equiv Ax(\mod{An})$ -->  $Ay=2Ax-An$.
Answer: There are infinitely many Pythagorean triples where the difference between two legs is either $1$ or any of the infinite prime numbers $P\equiv\pm 1 \mod 8\quad$ taken to any non-zero power.
Under $100\quad
P\in \{1,7, 17, 23, 31, 41, 47, 49, 71, 73, 79, 89, 97\}.\quad $
To find these, we begin with Euclid's formula
$ \quad A=m^2-k^2,\quad B=2mk,\quad C=m^2+k^2\quad$ solve the $\quad (B-A)$ difference equation for $m$ and generate the $(m,k)$ values needed to feed Euclid's formula. Each iteration uses a seed $k$ which is either given or is the $m$-value of the previous iteration. Here is the formula for $P=1$ with a seed $k=1$. Note that $(m,k)$ are Pell numbers.
\begin{equation}
\quad m=k+\sqrt{2k^2+(-1)^k}
\end{equation}
\begin{align*}
k=1\space &\implies m=(1+\sqrt{2(1)^2+(-1)^1}\space)\big)=2\quad & F(2,1)=(3,4,5)\\
k=2\space  &\implies m=(2+\sqrt{2(2)^2+(-1)^2}\space)\big)=5\quad & F(5,2)=(21,20,29)\\
k=5\space  &\implies m=(5+\sqrt{2(5)^2+(-1)^5}\space)\big)=12\quad & F(12,5)=(119,120,169)\\
k=12\space  &\implies m=(12+\sqrt{2(12)^2 (-1)^{12}}\space)\big)=29\quad  & F(29,12)=(697,696,985)
 \end{align*}
For $P>1$, the formula is
\begin{equation}
 m=k+\sqrt{2k^2\pm P}
 \end{equation}
and there is more than one seed $(s)$ in a set $(k_1)$ each of which generates a subset of the entire set of triples for that difference. There is one more seed than the power $n$ of the prime number that is P. For example, $1$ is a zero power so there is $1$ seed.
$$P=1\implies k_1=\{s1\}=\{1\}\quad
P=7^1\implies k_1=\{s1,s2\}=\{2,1\}\\
P=343=7^3\implies k_1=\{s1,s2,s3, s4\}=\{14,16,3,7\}$$
The elements of $k_1$ are generated as follows.
\begin{equation}
\end{equation}
\begin{align*}
\text{where}\quad s_i=\sqrt{\frac{j_i^2 + P}{2}}
\\  &\text{for}\space\space\space 1 \le i \le \bigg\lceil\frac{(n+1)}{2}\bigg\rceil \space
  \land \space \space                                      1 \le j_i                \le  \lfloor\sqrt{X}\rfloor\\
\text{where}\space s_i=\sqrt{\frac{j_i^2-P}{2}}
\\ &\text{for}\space    \bigg\lceil\frac{(n+1)}{2}\bigg\rceil + 1 \le i \le (n+1)\space
  \land \space    \lfloor\sqrt{P} +1 \rfloor \le j_i \le  \lfloor\sqrt{2P}\rfloor
\end{align*}
For example, we have $n=3, P=7^3=343\\$
\begin{align*}
 1 \le   & i \le   2
 \space             1 \le     & j \le \lfloor\sqrt{343}\rfloor=18
 \space  \\
s_1=\sqrt{\frac{7^2+343}{2}}=14\space\quad  &  s_2=\sqrt{\frac{13^2+343}{2}}=16  \\
3 \le  & i \le  4
\space  19 \le    &  j  \le \lfloor\sqrt{2(343)}\rfloor=26
 \space   \\
s_3= \sqrt{\frac{19^2-343}{2}}=3 \quad
&  s_4=\sqrt{\frac{21^2-343}{2}}=7  \
 \end{align*}
\begin{align*}
s_1= 14\quad
     &14+\sqrt{2(14)^2-343}=21\quad   &F(21,14)=(245,588,637)\\
     &21+\sqrt{2(21)^2+343}=56\quad   &F(56,21)=(2695,2352,3577)\\
s_2=16 \quad
      &16 +\sqrt{2(16)^2-343}=29\quad  &F(29,16)=(585,928,1097)\\
      &29 +\sqrt{2(29)^2-343}=74\quad  &F(74,29)=(4635,4292,6317)\\
s_3=3 \quad
      &3+\sqrt{2(3)^2+343}=22\quad  &F(22,3)=(475,132,493)\\
      &22+\sqrt{2(22)^2+343}=47\quad  &F(47,22)=(1725,2068,2693)\\
s_4=7 \quad
      &7 +\sqrt{2(7)^2+343}=28\quad  &F(28,7)=(735,392,833)\\
      &28+\sqrt{2(28)^2+343}=63\quad  &F(63,28)=(3185,3528,4753)\\
 \end{align*}
For $P=1$
These $(m,k)$-values
may be generated directly using a Pell-related equation as follows.
\begin{equation}
 m_n= \frac{(1 + \sqrt{2})^{n+1} - (1 - \sqrt{2})^{n+1}}{2\sqrt{2}}\qquad \qquad\qquad
 k_n= \frac{(1 + \sqrt{2})^n - (1 - \sqrt{2})^n}{2\sqrt{2}}
 \end{equation}
For example
{\small
\begin{align*}
\frac{(1 + \sqrt{2})^{2} - (1 - \sqrt{2})^{2}}{2\sqrt{2}}=2 \quad
     \frac{(1 + \sqrt{2})^1 - (1 - \sqrt{2})^1}{2\sqrt{2}}=1 \quad&  F(2,1)=(3,4,5)\\
 \frac{(1 + \sqrt{2})^{3} - (1 - \sqrt{2})^{3}}{2\sqrt{2}}=5 \quad
     \frac{(1 + \sqrt{2})^2 - (1 - \sqrt{2})^2}{2\sqrt{2}}=2 \quad&  F(5,2)=(21,20,29)\\
\frac{(1 + \sqrt{2})^{4} - (1 - \sqrt{2})^{4}}{2\sqrt{2}}=12 \quad
      \frac{(1 + \sqrt{2})^3 - (1 - \sqrt{2})^3}{2\sqrt{2}}=5 \quad& F(12,5)=(119,120,169)\\
\frac{(1 + \sqrt{2})^{5} - (1 - \sqrt{2})^{5}}{2\sqrt{2}}=29 \quad
     \frac{(1 + \sqrt{2})^4 - (1 - \sqrt{2})^4}{2\sqrt{2}}=12 \quad& F(29,12)=(697,696,985)
 \end{align*}
}
Comment: https://math.stackexchange.com/questions/5540/k2k12-being-a-perfect-square-for-infinitely-many-k/700126#700126   there's a connection to Pell's equation.
Comment: @ individ 59  I know about the Pell connection with $P=1$ and I have added  such to my answer. Unfortunately, I have inconsistent luck with the ability to change font size in MathJax: Do you know how to make it \small or \footnotesize?
Answer: If you solve expression for $n$ you get
$n=\sqrt{c^2-a^2}-a$, let's denote $b=\sqrt{c^2-a^2}$,so we have that $n=b-a$
Now,take look at picture bellow.Note that $AD=a$,and $BD=b-a=n$
If you change value of $b$ and keep $a$ to be constant you will get a infinite number of right triangles,and therefore infinite number of values of $n=b-a$,so answer is yes, there are infinitely many primes $n$ for which equation is solvable.

Comment: Except that you don't know for which integer values of $b$ yield integer values of $c$.
Comment: So, what does your argument say when $n=3$?
Comment: @Thomas,That's true,I have answered only on second part of the question...however, one can find one (a,b,n) triple and then for each different triple choose another b such that n becomes prime number
Comment: @Thomas,I didn't say that this reasoning is correct for each prime number.I just pointed that there is infinitely many distinct (a,b,n) triples such that n is prime...
Comment: This probably unnecessary at this point but, among primitive Pythagorean triples, the difference between the two legs  is always a prime $P\equiv \pm 1 \mod 8\quad$ and I have shown how to find such triples in my recent answer.
Comment: @poetasis Not quite. Each prime factor of this difference $n$ is $p=\pm1\mod 8$, but $n$ might not be prime. For example, there's $a=24, n=119=7\cdot 17, c=145$ which is primitive.


Can someone show me how u can derive the infinite product representation of digamma(z) /gamma(z)

Question: Here is the picture from Wikipedia which shows the infinite product. I am confused about how to derive this infinite product below. Infinite product picture
Comment: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
Answer: According to the problem book "Problems in the Theory of Functions of a Complex Variable", L. Volkovysky, G. Lunts and L. Aramanovich, Problem 951, such a function, with simple zeros $x_1, x_2, x_0, x_3, x_4, x_5...$ has a Weierstrass product expansion,
$$f(z)=f(0)e^{\frac{f'(0)}{f(0)}z}\prod_{k=0}^{\infty}(1-\frac{z}{x_k})e^{\frac{z}{x_k}}.$$
Honsetly, I do not know the proof. They skipped in the solution set very much. The rest of the problem is easier.
Here, $f(z)=\frac{\psi(z)}{\Gamma(z)}=\frac{\Gamma'(z)}{\Gamma^2(z)}$.
We know the Laurent expansion: How to obtain the Laurent expansion of gamma function around $z=0$?
Then, by limit, we can show that $f(0)=-1$ and $f'(0)=-2\gamma$.


Downloading... don't turn off target (S7 Edge)

Question: I accidentally went to download mode and this "downloading don't turn off target message" appeared. It took me at least 20 seconds before I finally pressed volume down + home button + power button. My phone seemed to have rebooted after I did this. Was any harm done? Did my phone download something? Kinda worried because I'm not sure if it damaged my phone or something. Thanks!
Answer: That's Odin mode, designed for flashing firmwares from PC via Odin or Heimdall. As long as you didn't flash anything during the period, you're fine.


Central Bank Meeting Date Curve in QuantLib

Question: Is it possible to construct a central bank meeting date curve, using futures prices & OIS rates, in QuantLib?
Specifically, I mean a yield curve with flat (constant) forward rates in between meeting dates, and discontinuous moves on meeting dates (or 1 day after I guess, given that typically the rate change applies the next day).
If so, how?
Comment: Do you need to distinguish the [effective fed funds rate](https://fred.stlouisfed.org/series/FEDFUNDS), which the futures reference, from the [target rate](https://fred.stlouisfed.org/series/DFEDTARU), which usually stays constant between [FOMC meetings](https://www.federalreserve.gov/monetarypolicy/fomccalendars.htm) (but on rare occasions can change between meetings)?
Comment: Very good question. I want to model the target rate, rather than the effective fed funds rate.
Comment: I made a typo in my original question so just corrected "spot rates" -> "forward rates". i.e. the YC is composed of many forward rates with 1 day expiry representing the overnight cash target rate.
Answer: From my first line of thought:

Obtain OIS 1D,1M,2M,...12M
Use the Fed Funds Target - EFFR spread and apply that spread to each OIS curve.
Convert the simple 1,2, 3M OIS swaps to 1M, 1M1M, 2M2M forward rate curves. This is a simple process is easily bootstrapped.
Interpolate (Linear, spline etc.) between each data point.

In your example- you request the jumps to be after specific "meeting dates". You could iterate through each data point, and if OIS_next - OIS_t > 25bps. You could simply apply a function that increases it after the meeting date (Which is between dates next and t) based on this condition (Assuming no "micro" hikes or ECB style hikes)


How to use chrome web inspector to view hover code

Question: Using chromes web inspector to view code is very useful. But how do you view for example the hover code for a button? You will have to hover the mouse over the button and thus cannot use it (mouse) in the inspector. Are there any shortcuts or other ways to accomplish this in the inspector?
Comment: Isnt this a duplicate of this? http://stackoverflow.com/questions/4515124/see-hover-state-in-chrome-developer-tools
Comment: Does this answer your question? [See :hover state in Chrome Developer Tools](https://stackoverflow.com/questions/4515124/see-hover-state-in-chrome-developer-tools)
Answer: Now you can see both the pseudo-class style rules and force them on elements.
To see the rules like :hover in the Styles pane click the small dotted box button in the top right.

To force an element into :hover state, right click it.

Alternatively, you can use Event Listener Breakpoints sidebar pane in the Scripts panel and select to pause in mouseover handlers.
Comment: In Chrome 48 (and perh earlier), that dotted box has been replaced with a pushpin icon that says Toggle Element State when you hover on it. Then you select "hover" from the drop down list.
Answer: Alternatively, you can use Event Listener Breakpoints sidebar pane in the Scripts panel and select to pause in mouseover handlers.
Answer: It's a little annoying, but you need to right click on the element, and then, keeping your mouse over the link, use your keyboard select the 'Inspect Element' link and press enter. This should show you the css for the hover pseudo class for the selected element.
Here's hoping they make this a little easier in future builds.
Comment: Good to know, but yes it is very frustrating that the mouse needs to stay hovering over the link... even while you poke around in the Inspect Element window using only the keyboard. What a nuisance!
Comment: The **actual** whole process of forcing the element to `:hover` state,(`as in the accepted answer`),is also achieved Via right-clicking over the element, > Inspect , and keep the pointer there, and then use keyboard keys to check pseudo code.. Thanks for this _working_ alternative.... So _not_ actually a _nuisance_ ! : ) +1
Answer: In Chrome:
You can also mouseover on an element, and then click CTRL+SHIFT+C to inspect that element.
In Firefox:

in firebug:

source: https://stackoverflow.com/a/11272205/2165415
Answer: I know it is old question
What i do is run this in console and quicly hover the element i need to inspect
setTimeout(function() {
  debugger; // this will stop all script on the page
}, 1000);

to release this breakpoint click "resume script..." in Sources tab of dev tools
Comment: This is brilliant! When you're dealing with a library that uses mouse events rather than the hover state, this is the only thing I've found that actually works!
Answer: I'm not sure that I right understand your question but if you want to see the event handler code you can just inspect the element and look at Event Listeners sidebar pane of Elements Panel.
Another way is just press pause button in Scripts Panel and just hover the element.
The debugger will stop at the first instruction of the first event handler.
Comment: Could you be just a little more specific about how you do this?. A typical case would be a button I like, and want to see se how the hovering effect is accomplished in the same easy manner as ordinary inspect.
Answer: Please have a look on below link for answer
See :hover state in Chrome Developer Tools
Comment: The link might expire and render your answer useless. Please provide some information in your answer to prevent that.