Prove that $d(A,B)=d(x,y).$

Question: Problem: Define the distance between two subsets $A$ and $B$ of a metric space $X$ by
\begin{equation*}
d(A,B)=\inf\{d(a,b):a\in A,b\in B\}.
\end{equation*}
Prove that if $A$ and $B$ are compact, then there exist $x\in A$ and $y\in B$ such that
\begin{equation*}
d(x,y)=d(A,B).
\end{equation*}
** I know there's something missing in this proof because I can't guarentee that my $x\in A, y\in B$ will cover all the possible point in the set. We're currently using Baby Rudin as our textbook and haven't finished the chapter on series and sequences yet. I would appreciate any feedback.
My work:
Given $A$ and $B$ are compact, choose a sequence $\{a_n\}_n \in A, \{b_n\}_n\in B.$ Then by thrm 3.6(a), there exists a subsequence $a_{n_\ell}\to x\in A, b_{n_\ell}\to y\in B.$ This means for all $\varepsilon >0,$ there exists a $N\in \mathbb{N}$ s.t. $d(a_{n_\ell}, x) <\varepsilon$ for $\ell\geq N$. Similarly for all $\varepsilon >0,$ there exists $M\in \mathbb{N}$ s.t.  $d(b_{n_\ell}, y)<y$ for $\ell \geq M.$ Then choosing $\ell\geq \max\{N,M\},$ $$d(a_{n_\ell}, b_{n_\ell})\leq d(a_{n_\ell}, x)+d(b_{n_\ell},y)+d(x,y)$$
$$d(x,y)\leq d(a_{n_\ell}, x)+d(b_{n_\ell},y)+d(a_{n_\ell}, b_{n_\ell})$$
So together we have $|d(a_{n_\ell}, b_{n_\ell})-d(x,y)|\leq d(a_{n_\ell}, x)+d(b_{n_\ell},y)<2\varepsilon$ thus $\lim_{\ell\to \infty} d(a_{n_\ell}, b_{n_\ell})=d(x,y).$
Let $D:=\{d(a, b) \mid a\in A, b\in B\}$; need to show $\inf\{D\}=d(x,y).$ We have $d(x,y)\in D.$
By thrm 3.7 we have that all the limits of subsequences in a metric space form a closed set. i.e.  \begin{align*}
    \lim_{\ell \to \infty}d(a_{n_\ell},b_{n_\ell})&=d(x_1,y_1)\\
    \lim_{k \to \infty}d(a_{n_k},b_{n_k})&=d(x_2,y_2)\\
    &\vdots
\end{align*}
Then all the $d(x_i, y_i)$ form a closed set where $x_i\in A, y_i\in B$. All of theses $\{d(x_i,y_i)\mid i\in\mathbb{N} \} \subset \mathbb{R}$ and in particular, they form a closed subset of $\mathbb{R}$ so there is a minimum  element we call $d(x,y)$.
\begin{align*}
    d(A,B)&=\inf\{d(a, b) \mid a\in A, b\in B\}\\
    &=\inf\left\{\lim_{\ell \to \infty} d(a_{n_\ell},b_{n_\ell})=d(x,y) \mid  a_{n_\ell} \in A, y, b_{n_\ell} \in B\right\}.
\end{align*}
The infimum of a closes sets is an element that is in the set because every set contains all its limit points so $\inf\{D\}\in D.$
Reference:
Thrm 3.6(a) If $\{p_n\}$ is a sequence in a compact metric space $X$, then some subsequence of $\{p_n\}$ converges to a point of $X$.
Thrm 3.7 The subsequential limits of a sequence $\{p_n\}$ in a metric space $X$ from a closed subset of $X$.
Comment: basically, $A$ and $B$ are compact, so they are closed
Answer: I'll be honest, I didn't read all of what you wrote, but you're overcomplicating it for yourself.
For every $n > 0$, there are $x_n \in A, y_n \in B$ such that $d(x_n, y_n) < d(A, B) + 1/n$.
Let $\{x_n\}$ and $\{y_n\}$ be the associated sequences in $A, B$. So by compactness both have convergent subsequences, and suppose that those convergent subsequences converge to some $x, y$ respectively. For convenience let $\{x_n\}$ and $\{y_n\}$ now refer to the subsequences that converge to $x,y$
.
Note that for any $\epsilon > 0$, there is some $N$ such that for $n \geq N$ for $d(x, x_n), d(y,y_n) < \epsilon /2$, which means thanks to the triangle inequality that $d(x, y) \leq d(x, x_n) + d(x_n, y_n) + d(y, y_n) \leq \epsilon + d(x_n, y_n)$.
Therefore for every $\epsilon > 0$ there is $N$ such that for all $n \geq N$, $d(x,y) \leq d(x_n, y_n) + \epsilon/2$. We also know by construction of the sequences that there is some $M$ such that for all $n \geq M$, $d(x_n, y_n) < d(A, B) + \epsilon/2$. So for $n \geq max (M, N)$, $d(x, y) \leq d(x_n, y_n) + \epsilon/2 \leq d(A, B) + \epsilon$.
So then $d(x, y) \leq d(A, B) + \epsilon$, and $\epsilon > 0$ was arbitrary. So $d(x, y) \leq d(A, B) \implies d(x,y) = d(A, B)$.
Comment: Hi @Vercingetorix, do you mind explaining first line? Namely, where di $x_n, y_n$ live (I assume in $A,B$ respectively)?
Comment: Yes they live in $A, B$ respectively. Sorry for being sloppy. The reason such $x_n, y_n$ exist is essentially thanks to the definition of infimum. In particular, if no such points existed, then $d(A,B)$ would be at least $1/n$ bigger.
Comment: PS: If this is a satisfactory answer I would appreciate it if you accepted it.
Comment: Haha!! I do accept it. I'm just trying to process it line by line. I'm wondering why you have $d(x,y) \leq d(x_n,y_n) +\epsilon/2$ instead of $+\epsilon$?
Comment: Lol accept as in the green tick thingy that you can do to close a question.

About the $\epsilon/2$, no reason. Just so that we end up with $d(x,y) \leq d(A,B) + \epsilon$ in the end, not $d(x,y) \leq d(A,B) + 2\epsilon$. The former is more aesthetically pleasing I guess.
Comment: You're hilarious! I see--it was for the sake of beauty. :)
Comment: My next questions: how can I relate $1/n$ to $\epsilon$? And I'm confused on what sequences you're constructing to get to $d(x_n,y_n)\leq d(A,B)+\epsilon/2$?
Comment: It's probably best to move this to the chat.
Comment: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/116217/discussion-between-vercingetorix-and-cheeseboardqueen).

Prove that $d(A,B)=d(x,y).$


Can music theory help hobbyist instrumentalist get better at playing?

Question: For hobbyists who don't plan to write songs, is it worth to invest their time to study music theory rather than get better at playing?
I sometimes wonder how given piece is it structured, especially when chords are complex, dissonant but somehow sound right. I feel it would help me to learn the piece faster if I could mind-map or name things I play (how is A#5 or Bb7(13) related to key of C?) - it doesn't even have to be correct name of a chord relationship.
Or should I jump in and learn harmony just for that? I am worried that this will might be an endless (and possibly pointless) journey for my needs. I sometimes think that harmonies I see just give color over a melody which keeps the piece together.
I wish I could just tell shades of 'pink' from shades of 'blue'.
Comment: The answer is yes.
Answer: Definitely.
For one thing it's much easier to memorise a piece if you understand the theory behind it.
Imagine memorising a seemingly random sequence of letters. Now imagine how much easier it is to memorise a poem, because you know how the letters fit together to make words, the words go together to make lines, the lines have a rhythm, some of the words rhyme, and the sentences have meaning.
It's just the same with music. It helps to know when a chord change is conventional, and when it's more unusual. It helps to know when a chord change or a melodic element is going to come in, if you understand the rhythmic structure of the piece.
How, and in what form, you learn the theory, is another matter. If you have a certain kind of mind, it's possible to self-learn a lot of musical theory, without knowing the academic names for the things you are learning, simply by working your way through a canon of music (for me it was the Complete Beatles songbook) and observing things. Later you'll discover academic terms that apply to the nameless things you've learned.
However, working through a good book on theory is probably a faster way to get the same knowledge into your brain, and you can communicate with other people who know the terminology right from the start.
Just as you can enjoy a poem, and write poems to some standard, without academic study of literature; you can enjoy music and create music knowing only what you've learned from singing nursery rhymes. But the more you know, the more tools you have to either make music-making easier, or to allow you to do more sophisticated things.
Comment: I think that's a poor analogy. A person can memorize a poem without knowing the 'theory' of literature. You needn't know about metaphors, assonance, symbolism, alliteration etc to understand, appreciate or write poetry. These are language tools that we hear from the time we are born starting with nursery rhymes, they are ingrained in our culture and familiar well before we ever learn their names. This is analogous to music theory, we hear musical conventions everyday, one does not need to understand the theory of what a V I cadence is recognize its sense of finality and use it effectively.
Comment: You know some of the "theory" of literature even if you've not been taught it. You do need to know about metaphors to understand, appreciate or write poetry. You might not need to know it's called a "metaphor"! You find it easy to remember it's "I think that there will never be / a poem as lovely as a tree", not "I think that there will never be / a poem as nice as a bush" - because you know the former rhymes and scans. Will add something about this.
Answer: I would say it depends on what you like to do.  If you're playing sheet music as written, you may not need much theory.  However, if you want to improvise at all, it's pretty necessary.  I've been playing sax and flute off and on for many years, and now jam with some friends on weekends.  We play miscellaneous rock/folk/blues/jazz with opportunities for solos often.  I've just started learning some theory (which is why I found this forum), and the chords we play are just now starting to make sense.  My playing has been improving significantly since I started learning the theory behind it and what scales go with what chords.  I found a great book--Edly's Music Theory for Practical People.  It's short, to the point, and fun to read.  It's also cheap.
Comment: I'm playing with a guy at the moment who has very little theory. He struggles to name chords. However, he's one of the most tasteful players I've had the pleasure to play with - hears something a couple of times, and plays some great stuff of his own over it. He wants me to teach theory, but I'm reticent. It won't necessarily make him play better, it may hinder as he will be considering what's going on behind it all. He obviously knows his instrument, and that works well for him.Django Rheinhard had the same syndrome - it didn't stop him.
Answer: I've been playing guitar for about 7 years and when I started I made a point of learning the theory from various websites.
I learned every mode of every scale and how to construct any chord, but haven't gone much further than that because my studies and work take up a lot of my time, but now I have the theory so ingrained in my brain that I can just listen to any song and pick up what key it's in right away, and play any note I think of right away. Then I play around with the pentatonic scale and various modes and play with different patterns of playing each scale or mode.
So to sum up learn the theory really well, so well that you don't even have to conciously think about the theory when you're playing but just know that you are applying it automatically.


Circular Logic in proof writing

Question: I recently had a lecture in a proof class where we were proving a Theorem of the form

Theorem 6.18 Let condition be true. Then the following are equivalent.
a) Statement 1
b) Statement 2
c) Statement 3
d) Statement 4
e) Statement 5

When we began to prove the theorem in the following manner of showing $a\implies b$ and then $b \implies c$ and so forth until $e\implies a$
Is this valid? It seems circular in essence since we assumed $a$ to prove everything.
Comment: It doesn't prove that they are all true., but it does prove that any one of the conditions implies any of the others and vice versa.  That is to say, they are either all true simultaneously or they are all false simultaneously.
Comment: It'd be circular if you were trying to prove they were all true.  But you are try to prove that *if* one is true then they are all true.  To prove the statement $a \implies K$ its perfectly okay to assume $a$ and then conclude $K$.  Because that proves $a \implies K$.  It *doesnt* prove $K$ but you weren't trying to prove $K$.
Comment: As an aside, proving the conditions are equivalent like this is quite time efficient in comparison to other strategies, the worst being proving $(a)\implies (b)$, proving that $(a)\implies (c)$, proving that $(a)\implies (d)$ etc... on up until proving $(e)\implies (c)$ and $(e)\implies (d)$, having to go through $20$ separate steps rather than just the five steps needed using the strategy employed above.
Answer: "The following are equivalent" means that the following statements share the same truth value. That is, if any one of the statements is true then all are true, and if any one is false then all are false. So you can prove $a\implies b$ and $b\implies c$ etc. to obtain a loop of implications, which allows you to go from any one statement to any of the others. For instance, if $b$ is true, then in the proof we showed $b\implies c\implies d\implies e\implies a$ so that the other four statements are true.
The statement of the theorem is not saying "the following are all true", and so the proof is not showing this. There is a difference between a statement being true and it being equivalent to another statement. For example, consider the well-known result:

The following are equivalent:
  $$(1)\qquad\text{$f$ is continuous at $x$}\\(2)\qquad\text{for any sequence $(x_n)$ converging to $x$, $\lim_{n\to\infty}f(x_n)=f(x)$} $$

This statement gives a logical equivalence between $(1)$ and $(2)$, however it is not claiming that $(1)$ and $(2)$ always hold; indeed not every function is continuous, but every continuous function satisfies $(2)$ and vice-versa.
Answer: Generally, these statements tend be predicates. That is, they are statements that can be true or false, given some input. For instance, given a square nxn  matrix A, the following are equivalent:
S1. A is invertible
S2. det(a) is not 0
S3. dim(nullspace(A)) = 0
S4. dim(columnspace(A)) = n
S5. In row-reduced form, A has n pivot columns
You can think of S1 ... S5 as being functions that return some truth value. Put in different matrices A, and you'll get different output. S1(I) = true; the identity is indeed invertible. Saying they're equivalent means that while the output might vary for different A, it doesn't vary for different functions; S1(A) = S2(A) = S3(A) = S4(A) = S5(A).
So when proving a theorem of this sort, S1 ... S5 are not being proved to be true; they clearly are not always true (there are matrices that are not invertible). What is being proven is that S1 .. S5 are equal to each other. Proving that two predicates are equal can be done by proving that the first implies the second, and the second implies the first. For five different statements, that's a total of 20 different implications. However, we can take a shortcut of only showing five implications; if we have a cycle of each statement implying the next, then a chain of implications exist from any one to another.
Another way of thinking about it is that if one statement implies another, then it is at least as strong as the statement it implies. Just as showing
$a \geq b \geq c \geq d \geq e \geq a$ shows that a = b = c = d = e
showing that S1 is at least as strong as S2, which is at least as strong as S3, which is at least as strong as S4, which is at least as strong as S5, which is at least as strong as S1, shows that S1 = S2 = S3 = S4 = S5.
Answer: " It seems circular in essence since we assumed $a$ to prove everything."
Except you didn't actually prove anything is actually true (all those statements could be utterly false for all we know).  You proved $a \implies$ everything else is true.
If you want to prove a statement:  $a \implies K$.  It is perfectly fine to "assume" $a$ is true.  Because you aren't actually assuming $a$ will always be true.  You are simply proving that in the cases when $a$ happens to be true that $K$ will follow.  That is not assuming that $a$ is true.  $a$ doesn't need to be true for $a \implies K$ to be true.
A statement: The following are equivalent; $a,b,c,d,e$ is a statement that means (among other things):
if $a$ happens to be true then so will $b,c,d,e$.  (It also means if any of the other four happen to be true than all five will be.)

Circular Logic in proof writing


How to show other columns in Windows DHCP server?

Question: In the Windows Server DHCP server, the only column that shows for "Reservations" is the "Reservations" column.  That's not very helpful.  It would be so much more helpful if I could see the description and the mac address.
When I go to "Customize Columns" there is no option to add anything to the view.
Is there any way to get the other columns to become available to the column editor, or is this one of those typical Microsoft feature-failures?
Answer: In the GUI at least you don't get any additional options, you basically have to open the properties of the reservation.
Since it's 2012, you could use:
Get-DhcpServerv4Reservation
or
Get-DhcpServerv6Reservation
in Powershell with whatever parameters are available with the command or just the | fl.
http://technet.microsoft.com/en-us/library/jj590708.aspx
Comment: What good is a GUI????  That really gets my ire up.  A GUI to display the appropriate columns is wonderful - why, oh why, Microsoft do you do things like that?
Comment: Yes, I have read about the powershell command, and I've read where other people said the GUI doesn't show it, but I was hoping someone would have a hack or fix for that dumb issue.
Comment: Yeah, I'm not aware of (never really looked) any workaround or 3rd party GUI that can handle it.
Comment: One more pipe and you can get a "GUI" from Powershell: `Get-DhcpServerv4Reservation -ScopeId 192.168.0.0 | Out-GridView`
Comment: This is the only real answer, I think.  I ended up, however, installing a dhcp helper to point to a linux dhcp server on my other subnet...  Otherwise I would have to memorize all those powershell commands!
Comment: :) sorry mate...MS doesn't assume you'll be getting back into that section of the GUI often I suppose.


linux multipath - change device alias safely

Question: I'm running RHEL 5.2 connected to a NetApp over FC. The server is running a database on mpathNN devices that can not be stopped. I need to add a new LUN and give it a specific alias (rather than mpathNN). I know how to set this up in multipath.conf, but I don't know the wwid of the LUN yet. I also know this can be achieved by restarting multipathd, but don't know if this is safe.
Is it safe to restart multipathd without i/o interruption?
or, is there another way I can enable the alias specified in multipath.conf once I've presented it to the host?
thanks!
Comment: add alias in multipath.conf and use "multipathd -k "reconfigure" " that works
Answer: Yes, you can safely restart multipathd. It is only responsible for checking for failed paths and listening for new paths. It is not directly involved in i/o. To understand the different parts of the multipath system, read The Linux multipath implementation.
Answer: Add your new alias to your multipath.conf and if you have multipathd daemon running then you can use the command multipathd -k"reconfigure"


How can there be a standard deviation of true scores?

Question: Dudek (1979) describes the following formula as "the standard deviation of true scores when
the observed score is held constant" (p. 337):
$SE_{est} = SD \sqrt{(reliability × (1 - reliability))}$
As I understand it, my true score is a hypothesized 'real' score for me on some test, for example an IQ test. Due to measurement error it won't necessarily be my actual score on any given test, but if I could repeat the IQ test infinitely many times with no practice effects then my true score would be the mode mean.
If I just have a single underlying true score, how can we talk about there being a standard deviation of true scores?
Dudek FJ. 1979. The continuing misinterpretation of the standard error of measurement. Psychol Bull 86:335–337.
Comment: Why the mode? With so little context it's hard to tell, but the standard deviation referred to sounds like perhaps it's across individuals at a given observed score.
Comment: Since error is randomly distributed around 0, I think that my true score is the most likely value for me to obtain on any given repetition of the test. Hence I believe it's correct for me to equate the mode with the true score under the condition of infinite repetition that I described. I think it's plausible that the standard error of estimation relates to the spread of true scores across individuals who happen to have the same observed score. However, I couldn't find anything in the original Dudek paper or anywhere else to indicate that this was definitely true.
Comment: Using the mode *might* work but is not guaranteed to do so. For instance, the nature of the variation in your test scores might be such that sometimes you do slightly better than your true score but occasionally you do much worse. The mode will be an asymptotically biased estimator of your true score. In fact, because test results are necessarily discrete, then unless your true score coincides with one of the possible test values, the mode--whatever it might turn out to be in the long run--is *guaranteed* to be incorrect.
Comment: It seems that at minimum it would have been less confusing for me to instead equate the true score with the mean of the repeated scores. So I've edited the original post.
Answer: From a frequentist perspective, the parameter is fixed. Thus, from a frequentist perspective a person's true score is fixed (excluding of course for the moment that true scores can change over time). A standard error is the standard deviation of an estimator. Thus, the score you obtain for a person is an estimator of the true score. Typically in actual data analytic contexts, we don't have the standard error; instead, we have an estimate of the standard error. Thus, the estimated standard error of the true score is the estimated standard deviation of the estimator of the true score.
Comment: fwiw this doesn't substantially differ from a Bayesian perspective: the person's true score is still fixed and a random (posterior) distribution describes your uncertainty about that fixed value, which has a mean and some std dev. On the other hand in actual data analysis contexts the posterior and thus its mean and std dev. are exact not estimated (modulo mcmc issues etc.) Upshot is that the Dudek quote just seems a bit misleading, though I suppose it might make more sense in context.
Answer: I've found an answer, although not one that I find particularly satisfying.
Here on p9 of the book "Handbook of Psychological and Educational Assessment of Children it is written:
"The standard error of estimation is used to establish a 'confidence interval', which indicates the probability that an individual's true score lies within a specified range over repeated 'theoretical' test occasions."
I still find this confusing. I'm used to building confidence intervals around unknown population means and stating that the confidence interval should be interpreted as a long-run frequency. My understanding is that it's incorrect to say "there's a 95% chance the mean is between X and Y" because the population mean is either the bounds of the confidence interval or it isn't. Aren't we just making the same mistake here?
Answer: From what I can see, the equation $SE_{est} = SD\sqrt{reliability(1-reliability)}$ is an attempt to construct a measure more akin to a credibility interval used in Bayesian statistics, i.e. the probability of the parameter given the data. A confidence interval is, as you say, the long-run frequency - if you repeated the test a large number of times, the confidence interval would include the true score in 95% of those tests.
From the abstract of the Dudek article, it seems that people had used the formula $SE_{est} = SD\sqrt{1-reliability}$ to assess the variability in scores. Dudek argues that this gives the variability of the observed scores when the true score is held constant (which would be what we traditionally use for a confidence interval), but that what is actually desired is a measure of the variability of the true score when the observed score is held constant (at the measured value). Dudek states that "the [resulting] interval is around the estimated true score rather than around the observed score".
Reference: http://psycnet.apa.org/journals/bul/86/2/335/
Answer: Good question. There is only true score for you, but there are many true scores for different test-takers. Dudek was probably referring to the distribution of true scores for all test-takers with the same observed score. See Richard A. Charter & Leonard S. Feldt, 2001, Confidence Intervals for True Scores: Is There a Correct Approach?, J. Psychoeducational Assessment 19:350–61.
Answer: The standard error Dudek talks about is not for true scores but for estimated true scores. Estimated true scores are obtained by shrinking observed test scores towards the sample mean by an amount indicated by the error variance of the observed scores. The error variance of the estimated true scores is smaller than that of the observed scores (it's a case of bias-variance tradeoff). Lord & Novick's Statistical Theories of Mental Test Scores (1967) contains a good treatment of this topic.


JAXB - Tag repetindo, ao invés de aninhar

Question: Estou com um problema que não consigo armazenar mais de um elemento na mesma TAG, olhem o XML:
<ItemCardapio>
    <nCdItemCardapio>10</nCdItemCardapio>
    <nQtdeItemCardapio>2</nQtdeItemCardapio>
    <ObsProducao>
        <sDsObservacaoProducao>Com Gelo</sDsObservacaoProducao>
    </ObsProducao>
    <ObsProducao>
        <sDsObservacaoProducao>Sem Açucar</sDsObservacaoProducao>
    </ObsProducao>
</ItemCardapio>

Como vocês podem ver, a TAG "ObsProducao" repete, ao invés de ficar assim:
<ItemCardapio>
    <nCdItemCardapio>10</nCdItemCardapio>
    <nQtdeItemCardapio>2</nQtdeItemCardapio>
    <ObsProducao>
        <sDsObservacaoProducao>Com Gelo</sDsObservacaoProducao>
        <sDsObservacaoProducao>Sem Açucar</sDsObservacaoProducao>
    </ObsProducao>
</itemcardapio>

Segue a classe com as anotações JAXB:
@XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "nCdItemCardapio",
        "nQtdeItemCardapio",
        "obsProducao"
    })
    public static class ItemCardapio {

        protected int nCdItemCardapio;
        protected int nQtdeItemCardapio;
        @XmlElement(name = "ObsProducao")
        protected List<WsTSPaymentParamPedido.ItemCardapio.ObsProducao> obsProducao;
            ..........

Agora a classe que repete:
 @XmlAccessorType(XmlAccessType.FIELD)
        @XmlType(name = "", propOrder = {
            "sDsObservacaoProducao"
        })
        public static class ObsProducao {

            protected String sDsObservacaoProducao;
......

Answer: Como sua classe ObsProducao é apenas um wrapper para uma String, você pode eliminá-la completamente:
@XmlElementWrapper(name = "ObsProducao")
@XmlElement(name = "sDsObservacaoProducao")
protected List<String> obsProducao;

O @XmlElementWrapper gerará um wrapper chamado ObsProducao, o @XmlElement fará com que cada item dentro da lista gere um elemento chamado sDsObservacaoProducao, logo, o resultado será aquilo que você espera:
<ObsProducao>
    <sDsObservacaoProducao>Com Gelo</sDsObservacaoProducao>
    <sDsObservacaoProducao>Sem Açucar</sDsObservacaoProducao>
</ObsProducao>

Comment: Anthony funcionou perfeitamente :) ... mas como ficaria o XSD desse arquivo XML, pois do jeito que eu criei o XSD, quando gero as classes a partir dele o resultado do XML é aquele com a tag repetindo, dê uma olhada no meu xsd, por favor:
Comment:
Comment: Você pode usar o [schemagen](http://docs.oracle.com/javaee/5/tutorial/doc/bnbcv.html) para gerar um xsd da sua classe e ver como o Java faz essa construção. De qualquer forma, se eu fosse gerar um XSD na mão (no geral eu evito isso) usaria um `xsd:complexType` para a lista (contendo uma sequência de strings `unbouded` cujo nome é `sDsObservacaoProducao`). O `ItemCardapio` teria um `xsd:element` chamado `ObsProducao` referenciando esse tipo complexo.
Comment: Deu certo diego? Se sim por favor aceite a resposta.
Comment: Deu sim, obrigado amigo :)


IE wants to download returned JSON from Django

Question: I have a Django site where one page is doing an AJAX-based file upload (using Valum's file uploader) that returns some info back via JSON.  The way the JSON is returned by Django is...
return HttpResponse( json.dumps( info ), mimetype="application/json" )

When trying the page in Firefox, Chrome, and Safari I get the appropriate behavior of the file uploader marking the upload as complete and the data being inserted into a table on the page.
When testing in IE8 I get incorrect behavior after Django sends the JSON back: a download dialog comes up--which is the JSON text if you save it--and the file uploader continues to think the file is uploading since it has received no response from the server.  IE must be seeing the response and interpreting it as a download rather than passing it to the page's javscript.  Note that I've tried changing the mime to application/javascript and this appeared to make no difference.  Anyone got a fix?
Comment: IE doesn't handle iframes the same way as Firefox, Chrome, Safari, and Opera. You'll have to make a work around for the 'importNode' method which isn't supported in IE. That's about as far as I was willing to fix/investigate until I just decided to use SWFUpload.
Comment: Oh that's right, the iframe fallback.  I may end up using some other method for <IE9 then as that's going to be a major hassle.  If I do come up with a solution I'll post something here.  Hopefully someone else has already solved this though!
Answer: IE has issues with the "application/json" response from the iframe.
While I don't know the particulars of Django, I can say from experience in other frameworks that one of the easiest ways to get around this is to return the response as "text/html" and then parsing that string as JSON. In this situation I would guess it is as simple as changing the response to:
return HttpResponse( json.dumps( info ), mimetype="text/html" )

and then parsing this response whatever framework you prefer (whether it is native JSON.parse, or jQuery.parse, etc).
Should be localized only to those situations where you are ajax uploading files (as you are here).
Answer: Try setting a mime-type of "text/plain", that should work. See this question for more details:
json xhr response opens a download file popup window
There you can also find in the last comment why setting mime-type to text/html is a bad idea (opens your site to XSS attacks)


oracle sql stored procedure that creates temporary local cache of number(10)

Question: I need to do several select statements in a stored procedure and then update tables based of the key retrieved in the select statements at the end of the procedure. What is the best way to do this in a stored procedure, I looked into global temporary tables and it doesn't seem to be the best way.
Just an fyi, for the select statements I am using a cursor in a loop, that is how I hope to update the local temp cache/table.
Thanks for any help in advance.
create or replace procedure...
begin

select primary_keys from table..
-- save these keys to a temp cache or table

select primary_keys from table
-- save these additional keys to a temp cache or table

update table set field = 1 where primary_key in (select keys in temp cache or table)

commit;
delete temp cache or table

Comment: Which version of Oracle are you using?
Answer: A global temporary table (GTT) is a perfectly fine way to do it if you do not know how many keys you might have because a GTT will spool to temporary storage rather than blow up your session memory.
But if you are absolutely sure that the size is small, then a nested table can do it, eg
SQL> set serverout on
SQL> declare
  2    emplist sys.odcinumberlist;
  3    l_count int;
  4  begin
  5    select empno
  6    bulk collect into emplist
  7    from scott.emp;
  8
  9    for i in 1 .. emplist.count
 10    loop
 11      dbms_output.put_line(emplist(i));
 12    end loop;
 13
 14    select count(*)
 15    into   l_count
 16    from   scott.emp
 17    where  sal > 2000
 18    and  empno in ( select column_value from table(emplist));
 19
 20    dbms_output.put_line('l_count='||l_count);
 21
 22  end;
 23  /
7369
7499
7521
7566
7654
7698
7782
7788
7839
7844
7876
7900
7902
7934
l_count=6

PL/SQL procedure successfully completed.

Comment: how do you add a number to emplist and select a value from emplist? Can you use an insert into or select statements with emplist as if it was a table,etc?
Comment: There's a complete treatment of object types within PLSQL in the docs https://docs.oracle.com/en/database/oracle/oracle-database/19/adobj/using-pl-sql-with--object-types.html#GUID-C70ACBDE-FFCC-495C-931D-07E0D59C92E5, but as others have said, make sure you actually need to head down this path
Answer: You do not need a GTT nor a collection to spool the keys. Further even plsql is not necessary; you can do it in a single statement. Since you didn't post where clauses I'll keep the same basic select structure:
update table
   set field = 1
 where primary_key in
       ( select primary_keys from table    -- first select
         union
         select primary_keys from table    -- second select
       );

This likely can be further reduced to a single sub select in the where clause connected with an OR.
update table
   set field = 1
 where primary_key in
       ( select primary_keys from table
          where (clause form first select)
             or (clause form second select)
       );

Depending on those clauses perhaps reduced to:
update table
   set field = 1
 where (clause form first select)
    or (clause form second select);

But I would need those clauses to make that determination.
Comment: I want to do more than just update a field with these stored numbers, I would also like to do some inserts,etc. so I would prefer to iterate over the stored cache to do appropriate inserts,updates,etc
Comment: Then, in the future, put that type information in your description of what you are attempting. It is difficult to give a good answer when we only have part of the requirements. Glad you got an answer anyhow.


Sharepoint Document Library - Change .Zip to .Junk

Question: Anytime I post a zip file with a renamed extension to .anything, it will always download as a .zip file.  I have organizations that need to download these files, but cannot download .zip files.  Is there anyway to have SharePoint not convert the file to .Zip when downloading?  I do this all the time on ftp sites to bypass the security issue, but it just doesn't work here.
Thanks!
Answer: I don't think SharePoint cares about what's in the file, just the extension of it. I'd bet this is IIS and the client browser since there's not a mime type for '.anything'. It's similar to what happens when you download a docx when there's no associated mime type: the browser asks to save the docx as a zip file. Try adding a MIME type of (I think) 'application/octet-stream' for extension '.anything'.
Comment: Well the .anything was more figurative.  I changed the .zip to a .jpg and it still downloaded as a .zip instead.
Comment: I figured, ya. Just meant that I think you need a dedicated mime type for the extension you've chosen. Do you get the same result with other browsers (chrome, firefox, etc.)?
Answer: This is called "magic numbers": first few (usually 3) bytes in a file that identify its format. For instance, ".jar" Java files have 0xCAFEBABE leading bytes. Look through SharePoint configuration, and disable "magic numbers" if there's any option for that.
Also, try other archiving algorithms: i believe it won't recognize *.7z (7zip).
Comment: .jar files are just .zip files, so it will have the magic number for zip archives. Java .class files, however, do use the magic number you mentioned.

Nevertheless, I agree. tar+gzip/bzip2, 7zip, or rar are suitable alternative archiving formats that usually get through security checks.
Comment: Ehm, sure it's *.class! I saw "CAFEBABE" only once in something connected with Java. Brain's not perfect :)
Answer: Try creating a new content type, starting from Document. Then remove(hide?) the file-type attribute.


permutations of bst , given preorder array

Question: Given a Preorder array of a Binary Search Tree how many other permutations of the given binary search tree will form the same BST as the given preorder.
Comment: Any attempt? Any research done? What if there are duplicate values?
Comment: Yes . No duplicates allowed
Comment: Please show your attempt and research efforts, and focus your question on where you got stuck.
Comment: BTW, I understand permutations of a (preorder) array, but can you explain what "permutations of the given binary search tree" means?
Comment: Permutations here means different possible structures of bst
Comment: Then what do you mean with the *same* BST? Surely if a BST has a different structure, it is not the same BST, right?
Comment: I suppose the question should read *"how many other BSTs have the same preorder sequence"*.
Answer: First of a all: a value in a preorder sequence can never become an ancestor node of a node that has a value that occurred earlier in that sequence (this would be a contradiction with "preorder"). Any next value in the sequence (except the first) represents a child node of an earlier value's node. So values that are added to a tree are always leaves at the moment they are added -- never internal nodes.
The preorder sequence starts with the root, so any BST that it represents, must have it as root.
Any next value must be added as a leaf. So for the second value in the sequence there are 2 potential positions for it. For the 3rd, 3, for the 4th 4, ...etc. However, since the partial tree formed by the first k values must be a BST, there is only one of these positions for the unique (k+1)th value that is in line with the BST requirement, so there is never a choice between multiple alternatives.
By induction that means that only one BST can be formed from a preorder sequence of unique values.


SBS 2008 Script to connect - disconnect backup disk?

Question: I want to be able to leave multiple external drives connected to an SBS 2008 server and select which drive is used as a target for the backup without physically connecting/disconnecting the drive.
Windows doesn't support this and my testing confirms that if 2 drives are connected there is little to no rotation between the target drives, the backup will run to the last drive it used if it is connected.  Anyone have a script that will disconnect and reconnect a physical drive?
Thanks!
Answer: I don't know Windows sym links at all really, but that might be what you're after.
With say three drives attached;

create a symbolic link to one using mklink
run the backup so the link is the destination
have a daily script that deletes and remakes the link pointing to the next drive in rotation


Is there a way to tell an html element to ignore any stylesheets?

Question: I'm attempting to add a drop down to a page that already has a global "select" style.  Is there a way to tell the new select list to ignore the global style?  There's about 1 to 2 zillion existing drop downs that use the global style, so I don't want refactor the existing html.
Answer: Assuming you could set a unique class or id on that element you could use the (limited browser support) property all and set it to unset or initial
Something like

and
.ignore-css{all:unset;}

Comment: In 2021, the browser support looks much better already
Answer: there is no easy way to do what you are asking, one approach is to create a CSS class that resets all appropriate attributes for a specific element and its children to make it more complete, here is a good starting point Element specific CSS reset
Comment: This is the best answer.  It was the only answer that addressed the actual question.
Answer: You can override another style using "!important", like this:
a {color: red !important}

Or using a more specific selector:
*               // a=0 b=0 c=0 -> specificity =   0
LI              // a=0 b=0 c=1 -> specificity =   1
UL LI           // a=0 b=0 c=2 -> specificity =   2
UL OL+LI        // a=0 b=0 c=3 -> specificity =   3
H1 + *[REL=up]  // a=0 b=1 c=1 -> specificity =  11
UL OL LI.red    // a=0 b=1 c=3 -> specificity =  13
LI.red.level    // a=0 b=2 c=1 -> specificity =  21
#x34y           // a=1 b=0 c=0 -> specificity = 100
#s12:not(FOO)   // a=1 b=0 c=1 -> specificity = 101

See specificity documentation here.

UPDATE:
For example:
You have a global rule:
a {color: blue}

But you want your links red.
So, you must create the rule below:
a {color: red !important}

If the global rule also has "!important", you must use a more specific selector:
So, you may use:
body a {color: red !important}

Comment: I think the select tags have been totally hijacked by a jquery plugin (jqTransform), this surely would have worked otherwise.
Answer: you can eaither add cascading styles like:
#id1 .class1 select
or
.class:width:200px !important
The !important will make it use the style you want rather than the global one, but if you have to overwrite it it can get a little tricky. You have to use a combination of both.
Answer: I'd be most inclined to narrow down your selectors. By that I mean..

     I want this to be different.

CSS:
div.newbox a
{
     color: #888;
     text-decoration: none;
}

Answer: Or you could just...

......

where
.global-css{
    vertical-align: middle;
}
.ignore-css
{
    all:unset;
}
.important-css{
    vertical-align:left !important;
}

Comment: And once again, someone has marked it down without adding a comment explaining. Please don't do that.
Answer: What I usually do in this situation is add a unique class to the new element; in this case something like this will work:
<select class=i-am-unique>

</select>

and then in the stylesheet, find the global rule and add a :not() pseudoclass to differentiate:
select:not(.i-am-unique) {
    /* global rules */
}

select.i-am-unique {
    /* unique rules */
}

This requires minimal code updates, with only 1 class added in your HTML markup, one CSS selector tweaked, and 1 new declaration block for the unique element. Here is an example.
In addition, :not() is supported by a wide swath of browsers, even IE9+ and Safari 3.2+.
Answer: actually there is an easy way, what worked perfectly for me was simple CSS rule

display: contents;

what this value does is simple causes an element's children to appear as if they were direct children of the element's parent.


Upload multiple media entities at once

Question: Is there any solution yet which allows me to upload multiple media entities at once? At the moment I've to

Select a file
Upload it
Select the next file
Upload this

Especially for a gallery, where I've to upload a lot of images, this can be very annoying.
I really like to use the media entity module for this job because this way I can reuse all the images I've already uploaded in my gallery for other content.
Answer: Have you already checked the PlUPload module ?
It's still -dev, but should work ..
Another approach could be:
Using IMCE browser, that already allows multi-file uploads
in combination with filefield_sources, you should then be able to select the uploaded images for your gallery field and others.

More sophisticated is the media(-entity)-suite, there's
  dropzoneJS in place.
Comment: Thanks for your answer! I went with the PlUpload solution. Works like a charm :-). Although it's not really obvious that the integration of a JS library will add the functionallity for creating media entities in bulk ;-).
Comment: just added another option - ;)
Comment: In Drupal 8.5.6-dev / lightning-8.x-3.x-dev PlUpload doesn't seem necessary now for multiple file uploads: It is possible to pick more than one file at the same time, from the pop-up chooser shown. I have found this to be the case when clicking "Choose Files" when creating or editing content with a File field that has the "unlimited" upload setting. I'm not sure if my finding also applies to earlier pure Drupal 8 version (i.e not lightning.) I would bear in mind licensing of plupload - have a look at the library's website. The GPL variant may be unsuitable for some,
Comment: All that said. I'd still be interested (and grateful) in how @TiMESPLiNTER setup PlUpload.
Comment: With the possible licensing restrictions with PlUpload, I think that dropzoneJS would be worth considering.
Comment: I used the dropzonejs solution and this works very well. I will try to write instructions when I get a chance. +1 to @rémy's answer for the suggestion
Comment: So many years later, Plupload module is STILL not working and the file widget is still not covered by Drupal's security advisory policy.
Comment: @MrUpsidown - with Drupal 8 its really no longer any need for PlUpload. dropzoneJS (although still in alpha) is the successor imo.

Upload multiple media entities at once


How does the internet really work?

Question: Sounds like a dumb question but I bet a lot of people don't know either. I understand servers, clients, modems, routers, ISP's, ect; but what I don't understand is what makes up the backbone structure of the internet. I have never seen any clear UML diagram or description of the backbone of the internet. I have heard things about 7 main servers (don't quote me on that), but who owns each server, when were they built, how old are they, how do they interact? It seems surprisingly hard to find information on this.
All my google searching provides seemingly vague and outdated information.
Edit: Sorry if you found this question vague, not only did I write it late last night, but I have a vague understanding of how the backbone of the net works thus making my question vague.
Comment: Let's play nice, and the question will either get answered or get downvoted to close.  Opinions will always vary.  :)
Comment: Gee, thank goodness this isn't an excessively huge and vague question...
Comment: Seriously, while it's understandable for people to ask questions like this, this really isn't the venue.
Comment: I cant ask a question about the internet on SERVER Fault?
Comment: No, it's not suitable for Server Fault. How does a question such as this relate to system administration? The connection is as tenuous as asking about basic electrical theory.
Comment: @John Gardeniers I would think someone who is a system admin would have to have a detailed understanding of the internet to do their job.
Comment: @teh_noob: I agree. However, this isn't a venue for anyone to ask questions of systems administrators. It's a venue for those of us who *are* systems administrators to ask other systems administrators questions about systems administration. This is not that
Comment: I am a system administrator, sort of lol, I run a server out of my room.
Comment: @Kara Couldn't agree more. I suspect some of the people downvoting here never bothered to read the post and just decided the title alone wasn't sophisticated enough for them. I wonder if the question would be downvoted if the title had been "wan topology 101"
Answer: I'll take a stab at this:
First thing first, no one owns or controls the internet.  Right now there is defacto control provided through the DNS servers, which are what change "www.google.com" into "IP address 123.456.789.000".  These DNS "root" servers control the domain name infrastructure that provides the web as many people know it.
However the internet is actually a network of networks controlled by people (hence inter - network).  If you imagine that you have a network of computers controlled by a cable provider, by a telephone provider, network them to a government network, network them to a link to europe, another to hawaii, another to asia, another to Australia, you can see how the internet starts to take shape.  Essentially companies and in some cases countries will pay to have their internet connected to a link in a network to america.  Once these links were established the internet really started to take shape.
From a hardware point of view, the internet is built upon IP (not TCP/IP).  IP was a system that provides for networking using a shared address space (the familiar www.xxx.yyy.zzz) addressing system with a notion of a "gateway" which is if I don't know the person who owns this packet I'll forward it to someone who does.  Essentially there was a routing network created which defines which routers control certain IP ranges.  That way if I can digress, for your computer to send a packet in america to a computer in australia, the following would happen.

You send the packet via your modem to your ISP.
Your ISP uses it's rules to determine it doesn't own the IP of the packet and forwards it to it's backbone or a Tier 1 provider.
The backbone will determine that this packet is for australia and sends it to a machine connected to a fibre link or possibly over a satellite etc.
This process happens in reverse from the backbone, to the ISP, to the local ISP connection, to the modem in the house, to the computer in the house.

Now when you realise that the routing rules have redundancy (ie. you have more than one route to send a packet to australia for instance, picking a different cable, or using a sattelite) you can start to understand how the internet can survive when computers or routers shut down or fail, which is a key part of the infrastructure.
So if you have a network that can get packets to anyone who is connected, and anyone can connect by agreement to tier 1 connections, you can combine the capability to talk to any computer on the network with a protocol to send information, such as HTTP, FTP, SSL etc.  you end up with the internet as it exists.
A final word: If you managed to soak all of that in, you can see now that the argument between "well everyone should be able to watch youtube and make VOIP calls without it EVER being throttled" doesn't mesh so well with the fact that the people who are providing the internet have to share it with networks which they don't control. I'm speaking about net neutrality of course.
Comment: =D ..............
Comment: Good Shot Spence! I think I may cut and paste for the next person what asks me that question :)
Answer: It's really a series of tubes.
Comment: Not a truck...?
Comment: I'm gonna get laughed at for this, but the "series of tubes" analogy isn't really all that bad. The book "The Victorian Internet" (http://tomstandage.wordpress.com/books/the-victorian-internet/) describes the communication networks, composed of pneumatic tubes, telegraphs, bicycle messengers, and postal mail, of the 19th century. (You could send a message "by tube" to a telegraph office, which would send the message on to another city where it could be picked-up by a bicycle messenger and delivered to the recipient in a few minutes.) It's a rocking book, and I highly recommend it.
Comment: @RainyRat: that's the high bandwidth version :-p
Comment: @Evan: "A series of tubes" is not, in fact, a bad analogy to settle the questions of the un-geeky. But it is a horrible analogy to rely on when trying to make policy about how to run or regulate the internet. Really, mind-bogglingly bad. Which is why the Senator is rightly laughed at and derided.
Comment: @dmckee: I laughed at Sen. Stephens because I think he literally believed it was a series of tubes.
Comment: Hmmm... a bit more explanation would have deserved my vote up for this answer, even though I know what you mean and agree.
Answer: I guess you're talking about root servers. These one are used for DNS, without them you would not be able to connect to computers using a name.
Your question is a bit complex to answer because the term Internet is a large things. If we only consider IP level, Internet is just a lot of routers interconnected together.
Answer: The backbone of the internet is composed of loooong strands of optical fiber, which interconnect different datacenters (IXP - Internet eXchange Points), where different ISPs keep their routers, make peerings (interconnections).
So, "who owns the internet?" - well - ISPs, who buy the routers, switches (usually from Cisco), ask other firms to make new connections (via optical fiber) to other PoPs (Points of Presence) or other ISPs (peerings) and implement new protocols (IPv6, multicast transmissions).
Some interesting links:
http://en.wikipedia.org/wiki/Internet_exchange_point
http://en.wikipedia.org/wiki/List_of_Internet_exchange_points_by_size
Later edit:  You may also want to read about the BGP - the main routing protocol for the "core" of the internet - http://en.wikipedia.org/wiki/BGP
Answer: in a word cisco - lol.
in reality it works simply on lot of pipes connection oodles of computers all mostly passing on anonymous bits of data till it get's (usually) to the right place. Some are big computers some are small some pipes are wide and fast others are slow. But in essence its all just one logical forwarding system. A bit like a really fast postal system.
Answer: Pigeons. We'd be lost without the little guys running the packets around. See RFC 1149 and RFC 2549 for more information.

How does the internet really work?


If then switch in coffeescript

Question: I want to achieve this
if a?
  switch a
    'hello'
  else 'hi'

How to chain an if statement with switch statement if the condition isn't null or undefined?
Answer: As far as I can tell, your switch syntax is wrong. Something like that might be what you are looking for:
f = (a) ->
    if a?
        switch a
            when 'bonjour'
                'hello'
            else
                'yo'
    else
        'hi'

console.log f null
console.log f 'bonjour'
console.log f 'guten tag'

Producing:
sh$ coffee t.coffee
hi
hello
yo

Please note you can have an else close both for the switch statement (where it denotes the default case) and for the if statement.
Depending your needs, you might want to write the other way around:
f = (a) ->
    switch a
        when 'bonjour'
            'hello'
        else
            if a? then 'yo' else 'hi'

Or even get completely rid of the if:
f = (a) ->
    switch a
        when 'bonjour'
            'hello'
        when null, undefined
            'hi'
        else
            'yo'

Answer: That works. I found out that I have an spacing error.
Comment: your answer should contain the solution: corrected indenting of the else clause.

If then switch in coffeescript


Continue to other generators once a generator has been exhausted in a list of generators?

Question: I have a list of generators in a function alternate_all(*args) that alternates between each generator in the list to print their first item, second item, ..., etc. until all generators are exhausted.
My code works until a generator is exhausted and once the StopIteration occurs, it stops printing, when I want it to continue with the rest of the generators and ignore the exhausted one:
def alternate_all(*args):
    iter_list = []
    for iterable in args:
        iter_list.append(iter(iterable))
    try:
        while True:
            for iterable in iter_list:
                val = next(iter_list[0])
                iter_list.append(iter_list.pop(0))
                yield val
    except StopIteration:
        pass

if __name__ == '__main__':
    for i in alternate_all('abcde','fg','hijk'):
        print(i,end='')

My output is:
afhbgic

When it should be:
afhbgicjdke

How can I get this to ignore the exhausted generator? I would prefer not to use itertools and keep this same structure.
Comment: is there any reason you would prefer not to use `itertools.zip_longest`?
Comment: I'm learning generators and trying to understand them without simplifying the solution by just using itertools. This is an assignment requirement
Comment: Sorry, I should have been more specific. You should handle it inside the `while` loop so that it keeps `yield`ing. You should then implement the logic to quit when all iterators are exhausted.
Comment: @tdelaney it's certainly more conventional to use a comprehension, although I personally prefer using `map` with named functions. I honestly don't understand Guido's hate for `map()`.
Comment: You are getting a `StopIteration` exception in `next(iter_list[0])` if the iterator has been exhausted. You should catch and handle it.
Comment: I've tried to catch and handle the StopIteration exception, such as popping the generator out of the list, but it doesn't return to the code within the try block
Comment: As an aside, you can create the iterator list with `iter_list = [iter(arg) for arg in args]`. And don't use `map` which is just an odd thing to have in a language that highlights list comprehensions like python does.
Comment: @newbiecoder11 thanks for the fun problem. I never saw anything anywhere near this level in school in lecture, let alone homework. Are you in an undergrad program? US? Abroad?
Comment: @ddejohn Haha, I am glad you enjoyed it. I am in an undergrad program in the US. Here, atleast in this program, the homework is usually the hardest part of the course.
Comment: What should the result be for `alternate_all("aaa", "bbbb", "cccc")`? `'abcabcabccb'` or `'abcabcabcbc'`?
Answer: This works. I tried to stay close to how your original code works (though I did replace your first loop with a list comprehension for simplicity).
def alternate_all(*args):
    iter_list = [iter(arg) for arg in args]
    while iter_list:
        i = iter_list.pop(0)
        try:
            val = next(i)
        except StopIteration:
            pass
        else:
            yield val
            iter_list.append(i)

The main problem with your code was that your try/except was outside of the loop, meaning the first exhausted iterator would exit from the loop. Instead, you want to catch StopIteration inside the loop so you can keep going, and the loop should keep going while iter_list still has any iterators in it.
Comment: @newbiecoder11 please accept this answer instead of mine.
Answer: How about the itertools-recipe roundrobin, straight from the itertools documentation? You'd still end up using itertools.cycle and itertools.islice, though, not sure if that's a deal-breaker.
def roundrobin(*iterables):
    "roundrobin('ABC', 'D', 'EF') --> A D E B F C"
    # Recipe credited to George Sakkis
    num_active = len(iterables)
    nexts = cycle(iter(it).__next__ for it in iterables)
    while num_active:
        try:
            for next in nexts:
                yield next()
        except StopIteration:
            # Remove the iterator we just exhausted from the cycle.
            num_active -= 1
            nexts = cycle(islice(nexts, num_active))

Comment: OP explicitly states that they want to avoid `itertools`.


How does the songwriting "jam session" work?

Question: When trying to understand this stage of creation, I read "members play instruments freely to experiment with melodies, chord progressions, and rhythms". But how playing two, or even multiple melodies in parallel, leave alone "freely" could result in anything else than total chaos where nothing could be heard? If I would say mix multiple finished songs to be played in parallel tracks, the output likely will not sound like any music. Do they have any rules for that?
Comment: It seems like this question is about it can ever be possible for multiple musicians to jam together and make something nice. If that's the case, you might take the word "songwriting" out of the question. Often people jam in situations where the goal isn't to capture what they do and save it to be "a song" that can be played again. Improvised guitar solos, free jazz, etc. all make jamming work but don't "write a song" as a result.
Comment: It's actually harder to do it alone. Jam sessions start with simple ideas, probably soloing/vamping over a basic agreed pattern. Then musicians feed off each other's ideas and notice potential new building blocks that could turn into melodies, progressions and form. They also somewhat "criticize" each other in good spirit and thereby establish common aesthetic.  As they repeat this, they can bounce off from higher and higher levels, and sometimes start with complicated stuff that gets distilled down.
Comment: "If I would say mix multiple finished songs to be played in parallel tracks, the output likely will not sound like any music." - for what it's worth, renowned composers have done almost exactly that. See for example Charles Ives, who was inspired by childhood experiences of hearing multiple marching bands play at the same time: https://www.youtube.com/watch?v=niUXRKdpeZ0&t=520s
Answer: Maybe that's why a 'Songwriting jam session' is not encountered very often!  'Jam session' more typically means a group of players extemporizing on an agreed song or chord sequence.  There HAVE been experiments with completely 'free-form' improvisation where everyone just plays whatever comes into their heads, but yes, it generally results in chaos!
But yes, it could work like this.  Bass player comes up with a lick, drummer joins in, guitar suggests taking it round a certain chord sequence, vocalist improvises a melody...   But it really has to start with SOMETHING, not just everyone playing their own idea regardless!
Comment: Seems to be the norm in some French circles. But it certainly isn't about song writing, more about a jam session, that sometimes (if lucky) develops into something palatable.
Comment: @Tim I confirm. That might explain why I have troubles finding these king of jam abroad...
Comment: @Tom - for king of jam do we translate as kind of jams? Or is confiture more in keeping?
Comment: @Tim, yes... My autocorrect sometimes gets creative ;)


Chords available in a certain Key?

Question: I am a total beginner here so please bear with me.
When you have a certain key, let's take C, we have
C D E F G A B C
Looking at the wheel of fifths, my available chords are
F C G major
D A E Minor
B     Dim
So if I tried to create a triad with say G using 1,3,5 from G if I had to stay in the octave the only notes available to me make this G chord triad are G A B C is that correct?
Or can I move outside of the octave with the G as root?
My head is hurting thinking about it, please try and help me in a simplistic manner.
Comment: This question is an example of the kind of incredible, inexplicable problems that are caused by trying to learn music theory first before learning practice. Based on this site, music theory is causing more harm than good. OP's head hurts. Mine too. Stay away from any kind of music theory completely for one week. No circle of fifths. It is nonsense until you can play something. Play an instrument. Take a piano keyboard and play it. Play chords on the piano. Play a song in C major on the piano. BANG. My head just exploded.
Comment: @piiperiReinstateMonica the bigger problem is trying to learn music alone. The OP is making assumptions that a teacher would  clear up instantly.
Comment: It is not very often that the Octave is considered when building a chord, which causes me to wonder if you are confusing the term Octave with the term Scale. If that is the case, then your understanding may become much easier, as chords are built from a scale which often extends both above and below the Tonic and its Octave.
Comment: I play classical guitar, tuned EADGBE. The simplest 6-string G chord plays G on first, third and sixth strings, D on fourth, B on fifth, and either B or D on second. It would be a poor instrument if you could only play 3 or 4 notes within an octave at a time. The subtlety is choosing from which octaves you pick up those extra notes for 7ths and other embellishments (that and the 4 fingers, 6 strings conundrum).
Comment: @Dom That too. I was imagining any sort of realistic theory lesson "this is a C major, this is a G major". I hope nobody would introduce chords as a purely theoretical concept without showing any examples? Though I must say I first learned chords as a kid by seeing/spying someone play and repeating it afterwards without talking with anyone. The chords were C - Am - F - G. I knew I had found the building blocks for all songs, so I started to replicate and modify the patterns and learned to play songs by ear. No teacher, no talking, just playing like with toys. Theory seems to make it difficult!
Answer: You do not need to stay in the octave of the key you are in, or any other octave for that matter.  The formula of every other note, or (1, 3 ,5) for Maj, (1, b3, 5) for min etc help you pick the correct notes but those notes can (1) be  played in any order creating inversions of the chords or triads, (2) include repeated notes to make the chord more full sounding, and (3) be anywhere in the range of the instrument in theory.
Take for example the Key of C.  Think of your available notes as being the repeating sequence,
C D E F G A B C D E F G A B C D E F G A B C D E F G A B C ...
We sometimes label the letters with a number to remind us of what octave we are in, for example,
C1 D1 E1 F1 G1 A1 B1 C2 D2 E2 F2 G2 A2 B2 C3 D3 E3 F3 G3 A3 B3 C4 D4 E4 F4 G4 A4 B4 C5 ...
Then you can grab any of the triads you listed in their "root" position, (1, 3, 5).  For example your G starting on G1 is (G1, B1, D2) etc.
You can get all your chords to stay within an octave by rearranging the notes to make an inversion.  These are much more interesting in terms of chord movement and harmony.
Root position (I had learned or remember inversion) has the root note, the 1 in the bass. The first inversion has the second note, the 3rd in the bass, and the second inversion has the 5th in the bass.
In the Key of C all your triads can fit into one octave and will have the following format.
I = C Maj  (C, E, G)   root position
ii = D min   (D, F, A)   root position
iii = E min   (E, G, B)   root position
IV = F Maj   (F, A, C)   root position
V = G Maj   (D, G, B)   first inversion
vi = A min   (E, A, C)   first inversion
vii = B dim   (F, D, B)   second inversion
Things get more interesting with 7th chords but the same logic applies.
Comment: @BrianM playing the nearest adjacent notes (e.g. C4 E4 G4, G4 C5 E5) is usually the simplest since even though C3 E5 G7 is also a C chord, it might be difficult for new learners to hear it as a chord. That said, chords don't have an octave indicator because it can be played anywhere, both on low notes (C3 E3 G3) and high notes (C6 E6 G6).
Comment: Thats,great thanks. So when you look at a piece of music are the chords numbered using the octave reference like
Cmajor 2      then E major 5 an G major 7 or whatever is it marked on the score with these numbers? what does it look like written down?
Comment: @BrianM, Not that I'm used to.  I read in standard notation and the placement of the note on the staff should correspond to a particular octave, depending on the instrument.  Some instruments read in a different octave than played.  But the order of the notes indicates what inversion you have.
Comment: So how do you know what octave the note is in ? if the note is a G then how will i know if its not is the same octave as the C or the E? what visual indicator will give me that information?
Comment: If you are referring to a chord chart then no.  There are standard fingerings and voicing for guitar, piano, etc.  We learn them and just know after a while what works.  There is a notation for indicating inversion.  The classical is to write a subscript by the chord  6 = 1st inversion and 6/4 is 2nd.  Not to be confused with a Maj 6 chord.  The other is slash notation.  G/D would be a G chord with D in the Bass, hence 2nd inversion.  In SMN the placement of the dot on the staff tells you exactly what to play.
Comment: Not being picky (just pedantic!), but the order of the notes isn't exactly telling which inversion you have. It's which note is lowest that tells.
Answer: To make any of those chords, you can use them in a triad. That is, all three notes but (as Eric Morecombe said) not necessarily in the right order! That's because there is not really a right order.
There are different ways of voicing chords. The way you are considering is close voicing, where all three notes are as close to each other as possible. Taking a C major close triad, it could be voiced in 3 ways - root position, C E G; 1st inversion - E G C; or 2nd inversion - G C E.
However, putting those three notes in any order still results in a C major chord. You could have  double bass play a low C, a trumpet play a middle(ish) G, and a piccolo play a high E. That's still a C chord.
So, yes, you can move out of the octave (or as many octaves as you like...) and while it will still be and sound like a C chord, the subtle difference will be in the voicing - the way it sounds.
And while we're on the subject, the root position chord sounds the most stable (and it could be played C G E in open voicing. Putting the G underneath (G C E, or G E C) will sound the next strongest, leaving 1st inversion (E G C or E C G) as the weakest sounding. Although it does get used in certain circumstances.
Hope this clarifies things. Try not to think it's complicated - it's really quite straightforward. And, as with any musical query, just try out what you think may or may not work. General feeling is - if it sounds good, it probably is. And no-one gets punished for 'breaking the rules' - they're not rules!

Chords available in a certain Key?


If a matrix is symmetric, tridiagonal, and diagonally dominant, is it positive definite?

Question: If a matrix $A \in \mathbb{R}^{N\times N}$ is symmetric, tridiagonal, diagonally dominant, and all the diagonal elements of $A$ are positive, then is $A$ also positive-definite? If it is, how to prove it?
The proposition looks to be true according to a statement in this question,
Is a symmetric positive definite matrix always diagonally dominant?
and a comment to it. However, I can't come up to a proof by myself. I would appreciate your help.
Comment: The matrix $-I$ is symmetric, diagonal (not just tridiagonal), and diagonally dominant. But it is not positive definite. Do you have any conditions on the individual entries?
Comment: Right. It looks I need to add a condition that the diagonal elements of A are all positive, according to the statement in the cited question. I am going to edit my question.
Answer: You don't need tridiagonal.  Gerschgorin's theorem (plus the fact the eigenvalues of a symmetric matrix are real) implies that all eigenvalues of a strictly diagonally dominant symmetric matrix with positive diagonal elements are positive, and all eigenvalues of a diagonally dominant symmetric matrix with positive diagonal elements are nonnegative.
You do need that "strictly", e.g. $\pmatrix{1 & 1\cr 1 & 1\cr}$ is diagonally dominant but not strictly diagonally dominant, and has an eigenvalue $0$.
Comment: Thank you. It was good that today I learned Gerschgorin's theorem.


After forced login, return to first entered login

Question: I have situation where i redirect user programatically on condition. After condition is met:
drupal_goto('http://www.mydomain.com/user/login');

But what it does, it forgets path that was initially entered by user.
Is there a way to redirect user to login (programatically), but to remember url ?
(as it works when you try to login to admin area).
BTW, i have Login Tobbogan also installed. (Drupal 7)
Thanks!
Answer: I believe the correct way to do this is:
drupal_goto('user/login', array('query' => drupal_get_destination()));

The documentation for drupal_get_destination() states:

Prepares a 'destination' URL query parameter for use with drupal_goto().
Used to direct the user back to the referring page after completing a form. By default the current URL is returned. If a destination exists in the previous request, that destination is returned. As such, a destination can persist across multiple pages.

Update: You could try putting the URL in directly:
$path = 'path-to-redirect-to'; // or $GET['q']
drupal_goto('user/login', 'query' => array('destination' => $path)));

Comment: tried, but not redirected after login where initial link was leading... are you sure this is the way ? :) Because if it is, i have another thingy which lands me on user profile page... thanks!
Comment: There is no redirect going on in your form? Do you see the ?destination=* part of the URL at the login form? I've updated the answer.
Comment: interesting approach for further reference! But this solves problem for me: drupal_goto('user/login', array('query' => drupal_get_destination()));
Answer: I take you want to redirect the user from the login page to the page where you are checking the condition. If this is the case, the code you should use is the following one.
drupal_goto('user/login', array('query' => array('destination' => $GET['q'])));

Otherwise, if you want to redirect the users to the destination set from other modules, when there is one, or the current page, then the code should be similar to the following one.
drupal_goto('user/login', array('query' => drupal_get_destination()));

Remember that the first two parameters accepted from drupal_goto() are the same parameters accepted from url().
Comment: Second approach solves what i needed: q parameter is appended on login, and after login, im redirected to url. Only, the ugly query is visible on login page. Could it be masked, withouth query, or with clean urls ? (not?)
Comment: This answer is actually the same as mine, but I missed out the query parameter. A green tick swiped from under my feet.
Comment: With clean URLs, the `?q=[…]` part would not be visible, but the `redirect=[…]` part would still be visible, also because Drupal looks for `$_GET['redirect']`.


How to add only unrefered node of a content type in an entity reference field of another content type

Question: There are 2(two) Node types

A
B

A has a node reference field to node type B.
If a node x of A type used a node y of B type as a node-reference then next time node z of A type will not use the node y of B type as a node-reference because x is already used as node-reference.
Comment: Did you already try the [Entityreference unique](https://www.drupal.org/project/entityreference_unique) or [Field validation](https://www.drupal.org/project/field_validation) module?
Comment: No, but I think [Entityreference unique](https://www.drupal.org/project/entityreference_unique) will be perfect though I've not found the recommended version.
Comment: @johirpro what do you mean by recommended version? It does not have a *stable* release yet, but rc means release candidate - maintainer thinks it's ready and all he needs is some brave people who will start using it and confirm it's ready :) By using it and reporting everything you didn't found to work as expected, you help maintainers to help you.
Comment: Thanks! @Mołot to explain about the meaning of **rc**. I'll use the _stable_ release.
Comment: The Git repository is indeed a bit messy, there is also an issue (more than a year old) of applying Drupal's coding standards.. I would use the rc version.
Answer: The Entityreference unique sounds what you're looking:

This modules adds a checkbox to an entity reference instance to enable a check for unique multiple entity reference fields. With this option enabled it is not possible to add one and the same entity to a multiple entity reference field.


Derived subgroup where not every element is a commutator

Question: Let $G$ be a group and let $G'$ be the derived subgroup, defined as the subgroup generated by the commutators of $G$.
Is there an example of a finite group $G$ where not every element of $G'$ is a commutator? $G'$ is only generated by commutators, but with all of the properties of commutators (ie: what happens under conjugation, exponentation, etc) I can't think of an example.
Answer: For any prime $p$ and $n>1$, there are nilpotent groups $G$ of class 2 and order $p^{n(n+1)/2}$ with generators $a_i$ $(1 \le i \le n)$, $b_{ij}$ $(1 \le i < j \le n)$, such that $[a_i,a_j] = b_{ij}$, the $b_{ij}$ are all central in the group, and all generators have order $p$.
Then $G'$ is the group of order $p^{n(n-1)/2}$ generated by the $b_{ij}$.
In any group, we have $[ax,by] = [a,b]$ when $x,y$ are central in the group, so $G$ has at most $p^{2n}$ distinct elements that are commutators.
Hence, for any fixed $k>0$, by choosing $n$ sufficiently large we can find $G$ such that not all element of $G'$ are products of at most $k$ commutators.
Comment: Nice! (I was waiting for you to show up :) )
Answer: For a nice source of examples, see

I. M. Isaacs: Commutators and the Commutator Subgroup. The American Mathematical Monthly. Vol. 84, No. 9 (Nov., 1977), pp. 720-722

which you can get from JSTOR.
Using GAP I find that the two examples of order 96, which is the minimal possible order, are the groups generated by the following two lists of permutations on $32$ elements.

[ (3,8,6)(4,7,5)(9,27,17)(10,28,18)(11,30,22)(12,29,21)(13,26,23)(14,25,24)(15,31,20)(16,32,19),
(1,17,7,23)(2,18,8,24)(3,19,5,21)(4,20,6,22)(9,26,15,32)(10,25,16,31)(11,28,13,30)(12,27,14,29),
(1,9,5,13)(2,10,6,14)(3,11,7,15)(4,12,8,16)(17,25,21,29)(18,26,22,30)(19,27,23,31)(20,28,24,32),
(1,5)(2,6)(3,7)(4,8)(9,13)(10,14)(11,15)(12,16)(17,21)(18,22)(19,23)(20,24)(25,29)(26,30)(27,31)(28,32),
(1,3)(2,4)(5,7)(6,8)(9,11)(10,12)(13,15)(14,16)(17,19)(18,20)(21,23)(22,24)(25,27)(26,28)(29,31)(30,32),
(1,2)(3,4)(5,6)(7,8)(9,10)(11,12)(13,14)(15,16)(17,18)(19,20)(21,22)(23,24)(25,26)(27,28)(29,30)(31,32) ]

and

[ (3,7,5)(4,8,6)(9,25,17)(10,26,18)(11,31,21)(12,32,22)(13,27,23)(14,28,24)(15,29,19)(16,30,20),
(1,17)(2,18)(3,19)(4,20)(5,21)(6,22)(7,23)(8,24)(9,25)(10,26)(11,27)(12,28)(13,29)(14,30)(15,31)(16,32),
(1,9)(2,10)(3,11)(4,12)(5,13)(6,14)(7,15)(8,16)(17,25)(18,26)(19,27)(20,28)(21,29)(22,30)(23,31)(24,32),
(1,5,2,6)(3,8,4,7)(9,13,10,14)(11,16,12,15)(17,21,18,22)(19,24,20,23)(25,29,26,30)(27,32,28,31),
(1,3,2,4)(5,7,6,8)(9,11,10,12)(13,15,14,16)(17,19,18,20)(21,23,22,24)(25,27,26,28)(29,31,30,32),
(1,2)(3,4)(5,6)(7,8)(9,10)(11,12)(13,14)(15,16)(17,18)(19,20)(21,22)(23,24)(25,26)(27,28)(29,30)(31,32) ]

(They have GAP ids $(96, 3)$ and $(96, 203)$ respectively.)
Later: I used the following very simple-minded code to find the groups
chk := function (g)
  local comms, sub;
  comms := Set(List(Cartesian(g, g), p -> p[1]*p[2]*p[1]^-1*p[2]^-1));
  sub := Set(DerivedSubgroup(g));
  return Size(comms) = Size(sub);
end;;
examples := AllSmallGroups(96, chk, false);

This works because I remembered there were examples of order 96. To get the permutation representations I did, for example,
GeneratorsOfGroup(Image(SmallerDegreePermutationRepresentation(Image(IsomorphismPermGroup(examples[1])))));

Comment: Thanks! Would you mind outlining your method for finding these in GAP? I am somewhat familiar with the program.
Answer: The "simplest" example is the free group on two generators, but is perhaps not the easiest to play with unless you are comfortable with free groups.
A nice survey of the problem of commutators vs. commutators subgroups in finite groups is:

Kappe, Luise-Charlotte, and Morse, Robert Fitzgerald. On commutators in groups. Groups St. Andrews 2005, Vol. 2, pp. 531-558. London Math. Soc. Lecture Notes Ser., 340, Cambridge University Press, 2007. MR 2331612 (2008g:20068)

The smallest groups in which the commutator subgroup does not equal the set of commutators have order 96; in fact, there are two non-isomorphic groups of order 96 in which the set of commutators does not equal the commutator subgroup. (This result also appeared in Robert Guralnick's 1977 thesis, "Expressing group elements as products of commutators", UCLA).
Kappe also has an upcoming joint paper in which she discusses the same question, restricted to $p$-groups.
Another interesting item is the Ore Conjecture, which stated that if $G$ is a finite nonabelian simple group, then the set of commutators equals the commutator subgroup. Its proof was recently completed, and it appears in:

Liebeck, Martin W.; O'Brien, E. A.; Shalev, Aner; Tiep, Pham Huu. The Ore conjecture. J. Eur. Math. Soc. (JEMS) 12 (2010), no. 4, 939–1008. MR MR2654085. A PDF preprint can be found at O'Brien's website.
Comment: Is the proof of the Ore conjecture a verification based on classification? (One can state the conjecture without the "nonabelian" :) )
Comment: @Mariano: I'll add  a link to the preprint from O'Brien's site. From the introduction, it seems to me that it *does* rely on the classification at least to some extent.
Answer: Keith Dennis has also done some work on this problem.  In the paper:
Dennis, R. K.(1-CRNL); Vaserstein, L. N.(1-PAS)
Commutators in linear groups.
K-Theory 2 (1989), no. 6, 761–767.
they consider conditions under which all elements of the commutator subgroup are products of at most 2 commutators.  I seem to recall that Dennis did computer calculations to find the smallest group for which the commutator subgroup contains elements that are not commutators (and my recollection is that the size of the group was around 100 elements) but I can't see anything on-line about that.
Comment: Cool!  I'm surprised I remembered this to within 4%.  My entire knowledge of this is based on a two-minute conversation in the tea room back in 2000...
Comment: 96 is the minimal size :)
Answer: An explicit example is $G = (V \times Q) \rtimes C$ where $V=\langle \varepsilon \rangle \times \langle \varepsilon \rangle \cong C_2 \times C_2$, $Q$ is the quaternion group $Q_8=\{\pm 1, \pm i, \pm j, \pm k\}$ and $C_3 \cong C =\langle t \rangle$ acts "diagonally" on both $V$ and $Q$. It acts on $V$ so that $VC \cong A_4$ and it acts on $Q$ by cyclically permuting $i,j,k$: $i \to j \to k \to i$, so that $QC \cong SL(\mathbb{F}_3^2)$.
We have $|G|=96$. It is a nice exercise to compute the character table of $G$, which is of size $12 \times 12$. If you do so, you will realize that the element $x=((1,\varepsilon),-1) \in V \times Q = G'$ satsifies $\sum_{i=1}^{12} \chi_i(x)/\chi_i(1)=0$ so it is not a commutator.
(This group has GAP id $(96, 203)$.)


How to deal with information that arrives null? - NoSuchMethodError

Question: I'm getting null information from a web api. If a single information is null, the error will occur:

Error: Exception: NoSuchMethodError: '[]'
Dynamic call of null.
Receiver: null
Arguments: ["address"]

I declared this information in the model like this:
final String? address;

..
address: json['data1']['data2'][0]['data3']['address'][0]

I tried to do something like:

address: json['data1']['data2'][0]['data3']['address'][0].isEmpty
? ''
: json['data1']['data2'][0]['data3']['address'][0],

But it does not work.
I appreciate if anyone can help me analyze it!
Answer: The only thing you can do is to anticipate the null values and handle each case as needed.
For instance, if a null value is not accepted at all, you could wrap the code in throw ... catch statement then throw an error -- e.g.Missing Data and handle that error.
If having a null value is fine, you can use the null aware operator ? (or a nested if-statements if you prefer that). For example, assuming the value is a String, you could do something like this:
final String? myValue = json['data1']?['data2']?[0]?['data3']?['address']?[0];

Though, keep in mind if you're accessing a list by index, you still can get a RangeError if the index is out of range or if the list is empty. In such case you may need to split the process in a separate method and inspect each part separately such as:
String? extractValue(Map<String, dynamic> json) {
  final firstList = json['data1']?['data2'];
  if (firstList is List && firstList.isNotEmpty) {
    final innerList = firstList[0]['data3']?['address'];
    if (innerList is List && innerList.isNotEmpty) {
      return innerList[0];
    }
  }
  return null; // or return a default value or throw an error
}

Answer: You can handle such arguments ( arguments that give you null value) like this.
Let's say there's a variable a and there's a possibility that it'll give a null value, you can give it a default value.
For example:
There is a  variable 'a', which is your data source.
String name = a ?? "This is not a null value";

The ?? would check if the value is null or not. If it's null, it would assign the value that you provided, otherwise it would keep the existing one.


web application audit task require my remote IP to be allowed on application network firewall

Question: I want to audit a web application which is hosted on a web server sitting behind a cyberoam firewall. My task is to run a scan from my remote machine which has ISP MTNL broadband. My machine gets a private IP address through DHCP and currently it has following configuration:

Wireless adaptor: 192.168.1.7 (private)
Gateway of my MTNL modem: 192.168.1.1

But when I do whatismyip, the result comes out to be the address of the default gateway router, which is set up at MTNL and looks like 59.178.x.x.
Now in order to audit web application, I want to allow my remote machine IP address on the cyberoam firewall . Please tell me which IP should be given to administrator to allow it at application network?
Comment: Give them your external IP.
Comment: Please elaborate what do you mean by external IP?
Comment: Is the default gateway router IP like 59.178.X.X?
Comment: Questions must demonstrate a **minimal understanding of the problem being solved**. Try including attempted solutions, why they didn't work, and the *expected* results. See [How can I ask better questions on Server Fault?](http://meta.serverfault.com/q/3608/118258) for further guidance.
Answer: To answer your question, use the second IP Address (59.178.x.x) which is your Public address and is the source address of all the traffic leaving your local network.
Side note: you shouldn't need a hole in the firewall to perform penetration tests (if that is what you mean by "audit web app" -- the firewall forms part of your defences. You wouldn't disable it for a real attacker.
Comment: If I run nmap scan from my machine towards application then result shows a filtered ports which means that nmap request are getting dropped somewhere in between (probably at application firewall) so may be I need to allow my public IP at firewall?
Comment: For most I need to do vulnerability assessment of application sitting behind the firewall. Yes, I do agree with your suggestion that firewall forms part of defences but the major concern is to check the open ports on web server hosting web application.


Please help me name this chord

Question: I'm harmonising a tune I've written, in C major, and one chord which resolves to C major consists of B, Db(or C#), F and A. It seems to be a sort of tritone substitution, but I am struggling to come up with an appropriate name for it. There are several options, but their names all sound quite ugly. What would be the best name for the chord? What would be the reasoning behind your answer?
How embarrassing ! Don't know why A got morphed into another note. SORRY !!
Comment: Can you maybe give the preceding and the following chord? That might help determine the name/role of the chord
Comment: The following chord, as stated, is Cmaj.
Comment: This underscores the conventionally ignored shortcomings of how chords are usually named in most Western music.  We end up doing nutty contortions to name a chord which could just be named by its chromatic intervals as Db 4 9 10.  I'd go with Db Aug 7 if pinned down.
Answer: It's not really in the key but you could call it a Db7#5 since the notes you have can be arranged as Db, F, A, and Cb. It is the simplest name and you could look at it as an altered chord borrowed from the Phrygian mode thus fitting in with resolving to C.
Comment: This chord is not borrowed from the Phrygian mode, as the note A natural is not part of C Phrygian (should be Ab).
Comment: @SeuMenezes It can be borrowed and altered (i.e. the 5th is raised the 7th is lowered)
Comment: @Dom I see, but in this case it could be easier to think of the chord as a substitute dominant. The altered chord loses a lot of its aural association with Phrygian overall sonority. Furthermore, Greek modes do not have intrinsic harmonic functions or chord formations (at least not naturally); OTOH a substitute dominant is sufficiently abstract and bound to the tonal system (the OP states that the chord "resolves into C", hence my reasoning).
Comment: Modes have very distinct motions and functions. Ever here of a [Phrygian cadence](http://dictionary.onmusic.org/terms/2586-phrygian_cadence)? There's a reason why it's called that.  Tritone substitutions _are_ modal in nature and can be traced back from the traditional modes and typical progressions for them. They are not exactly them and are typically altered, but it's much more succinct information to say what mode exactly it's from the  just saying it's a tritone substitution.
Comment: If the B is the lowest note, then one could write `D♭7#5/B`.
Comment: Or – but that chord probably does not exist – it can be considered a `Bøsus2`. ;-)
Answer: It is indeed a tritone sub of V. I hear it as a G9(b5) with the root (G) replaced by the b5 (Db). So as a chord with root Db it is a Db7/#5, as already pointed out in the other answers. Since it is a tritone sub I wouldn't look at it as "borrowed" from some other mode. Possible scales to play over it are the whole tone scale (of course the one including a G and a Db), and the Db altered scale. Note that the latter scale is (enharmonically) equivalent to a C major scale with the root shifted up by a half tone to Db.
Comment: Can one call a chord by its root name, but not include that note in the chord?
Comment: @Tim: I'd say yes, and it's done a lot on the guitar where - depending on context - the root can be left out in order to be able to play extra tension. But in this case there's not need for that, and it's more natural to call it Db7/#5, as suggested. This does not change the fact that I hear it as a V chord, which it is in any case.
Comment: L - I'm happy leaving out a root, provided there's a bass or suchlike to put it in instead. Still deciding whether the 'A' is a #5 or a b13, though... We all seem to agree that it is a tts., I'm just looking for the best name.
Comment: @Tim: b13 if you prefer to hear the Db altered scale as the chord scale, #5 if you hear the whole tone scale as the chord scale.
Comment: L - Tricky - there's only 3 or 4 notes in that bar, and, obviously, they could belong to either...
Answer: This chord could be named Db7(5+)/B (Db7(5+) with B in the bass). It is a substitute dominant chord (a tritone away from G7, and sharing a tritone with G7 -- that is, F <-> B), altered in its fifth degree, and played in the third inversion (the 7th degree is used in the bass). Its best enharmonic spelling is B-Db-F-A, as Db and A are made to explicitly be a minor second and a major second away from C and G, respectively (C# would be an augmented unison away, which could be at least misleading).
Answer: As others have suggested, a tritone substitution is probably the best way to look at it. As an additional point of interest, it could also be seen as a form of Augmented Sixth chord on the b2 scale degree. The Db and B form the interval of an augmented sixth, and adding the F makes it an Italian augmented sixth. The French and German aug6th chords would include a G or an Ab respectively. AFAICT, there's no special name for your version of the aug6th chord (where an A is added).
Answer: It could be construed as Db7b13 (or C#7b13). The 5 is missing, but it often is in more complex chords, and would clash with the b13 if left in. That chord would be Db, F, (Ab), Cb, no 9th or 11th, but they don't HAVE to appear in 13 chords,and it's not strictly a 13 chord anyway - just a dom 7 with a b13; and Bbb.I'm going for Db rather than C# as the key is C.
Answer: TL;DR
The root of the chord, as given, is B -- thus, a vii chord -- because the resolution of the outer voices dominates the sound.

How do we get to a Db (i.e., bII) chord?
Voice-leading "rules"
In the canonical teaching of functional harmony, there are rules about how certain intervals are required to resolve. In particular:

diminished intervals resolve "inward";
augmented intervals resolve "outward";
The resolution of outer voices generally takes precedence over inner voices.

Voice-leading applied to the OP chord as Db7
In the case of the OP chord, B-F, being a diminished fifth, resolves "inward" to C-E. F-B, as in a root position Db7 chord, resolves "outward" to E-C. (Note that this would also hold in a C minor context.)
X:1
M:C
K:none
L:1/2
"_d5"[Bf]"_M3"[ce] | "_A4"[FB]"_m6"[Ec] || [K:Cminor] "_d5"[=Bf]"_m3"[ce] | "_A4"[F=B]"_M6"[Ec] ||

Similarly, the B-Db, being a diminished third, resolves inward to C; Db-B would resolve outward to C. (Since the OP is in C major, the minor case is excluded.)
X:1
M:C
K:none
L:1/2
%%score (V1 V2)
V:V1 clef=treble stem=up
V:V2 clef=treble stem=down
[V:V1]_d c | B c ||
[V:V2]"_d3"B "_P1"c | "_A6"_D "_P8"C ||

Thus, so far, we have the following, given the OP voicing and the "rules".
X:1
M:C
K:none
L:1/2
%%score (V1 V2)
V:V1 stem=up
V:V2 stem=down
[V:V1] "as given"[_DF][CE] || "spaced out"[B,F_d][CEc] || "root position"[_DFB][CEc] ||
[V:V2] B,C ||

The A, being an inner voice, we can be a bit loose with and just let it resolve down to G. (We could also argue whether it's actually an A [#5, which should resolve upward] or a Bbb [b6/13, which should resolve downward], but let's not.)
X:1
M:C
K:none
L:1/2
%%score (V1 V2)
V:V1 stem=up
V:V2 stem=down
[V:V1] [_DFA][CEG] ||
[V:V2] B,C ||

BUT ...
The naming of this chord depends a great deal on its voicing. When voiced as a root position Db chord, the sound of the resolving Db, F, and B dominates -- particularly the outer voices.
X:1
T:Ⓐ sounds like Ⓑ
M:C
K:none
L:1/2
[V:V1] "Ⓐ"[_DFAB][CEGc] || "Ⓑ"[_DFB][CEc] ||

However...
...it is exactly because the outer voices dominate that, as given, the B, F, and A resolution dominates.
X:1
T:Ⓒ sounds like Ⓓ
M:C
K:none
L:1/2
[V:V1] "Ⓒ"[B,_DFA][CEG] || "Ⓓ"[B,FA][CEG] ||

Further ...
... the sound doesn't change much if you displace the Db by an octave.
X:1
T:Ⓒ2 also sounds like Ⓓ
M:C
K:none
L:1/2
[V:V1] "Ⓒ2"[B,FA_d][CEGc] || "Ⓓ"[B,FA][CEG] ||

Thus ...
... the given chord is either B7b5b9 or B∅7b9, which one being determined by the melody or other context -- or left ambiguous.
Conclusion
The given chord is a vii chord, rather than a bII chord.
Comment: Thanks - it'll take a while to plough through all this, but first observation - me writing a B as the first note doesn't mean that's the root, does it? It may (or may not) be the *lowest note*.
Comment: @Tim You're right. I took your writing B first to mean your were voicing the chord with B as the lowest note. That doesn't make it the root, but it is important in interpreting the chord, because the interpretation depends a great deal on the voicing/inversion. Read on... (and please let me know if the answer can be improved in content or style.)
Comment: It always depends. I quite often voice differently, depending on mood, where I am in the piece, who else is playing what, etc. I should have made it clearer - but 6 yrs ago I was even more ignorant than I am now! CEG will always be C major, but these weird conglomerations of notes can and will have several different incarnations, hence the question. All we have to go on is the key - C - well, C at that point... - but that's hardly a help.
Comment: @Tim Yes, your chord is like Amin7 vs. C6; which it is depends on a combination of voicing and context. Where CEG is always C major, regardless of inversion or voicing, that's not the case with the four notes you came up with. It would not be hard to revise my answer to make that point more the focus. I await your conclusions....
Comment: Yes, it's a bit like is a chord Co, D#o, Ebo, F#o, Gbo, Ao,or Bbbo - and there, it isn't always the lowest note that determines its name (at least according to Mark Levine - but I don't trust him). Although I would use any when playing, and be a little more specific when writing.

Please help me name this chord