Euler vs. Heun Numerical Methods

Question: I have a question about Heun's numerical method. I have the understanding that Heun's method is basically an improved Euler method which uses Euler as a predictor step and find the values of $y$ at the next steps and take average of the two.
However, I was thinking, what if I create two predictor steps?
For instance:
a) One called $y_n^*$ that predicts $y$ at $\frac{h}{10}$
$y_n^*=y_n+\frac{h}{10}f(y_n)$
b) Another called $y_{n+1}^{**}$ that predicts the value at $\frac{2h}{10}$
$y_{n+1}^{**}=y_n+\frac{2h}{10}f(y_n)$
Finally: the actual would be calculated by $y_{n+1}=y_{n}+h[\omega(y_n^*)+(1-\omega)f(y_{n+1}^{**})]$ , $\omega\in\mathbb{R}$

For instance, we can make $\omega = \text{"anything to make truncation error at least one and particular omega"}$ ($\omega=\frac{1}{2}$) will give us truncation error two. But I am not exactly sure I understand this completely.
How is it (if it is) better than having one predictor step?

In case anything isn't clear:

$h$ is the step size
and the interval is [$x_n$, $x_{n+1}$]

Thank you.
Comment: I apologise. I have updated it. Thank you.
Comment: It's Heun with E before U. It rhymes with "coin." And this is indeed an interesting topic; there are chapters of book written about how to use multiple estimators (possibly even whole books).
Answer: $\newcommand{\D}{\mathit{\Delta}}$
You are actually following along the lines that Karl Heun in 1900 was exploring. In the second order case, he considered to construct the next value $y+\D y$ as
$$
\D y=\sum \alpha_mf(x+ϵ_m\D x,\,y+ϵ_m\D'_m y)\D x
\\
\text{ where }\D'_m y=f(x,y)\D x
$$
By comparing Taylor expansions he found the order conditions
$$
\sum α_m=1,~~\sum α_mϵ_m=\frac12
$$
and that it is not possible to reach all third order terms in the Taylor expansion of $y(x+\D x)-y(x)$.
So it is perfectly valid to take 3 terms and $ϵ_m=0,\frac1{10},\frac2{10}$. The second order condition $α_2+2α_3=5$ and $α_1=1-α_2-α_3$ can then be satisfied in multiple ways.

For third order methods Heun expanded this scheme to
$$
\D y=\sum \alpha_mf(x+ϵ_m\D x,\,y+ϵ_m\D'_m y)\D x
\\
\text{ where }\D'_m y=f(x+ϵ'_m,y+ϵ'_m\D''_m y)\D x,\\
\D''_m y=f(x,y)\D x.
$$
Now the Taylor expansions match up to third order if
$$
\sum α_m=1,~~\sum α_mϵ_m=\frac12,~~\sum α_mϵ_m^2=\frac13,~~\sum α_mϵ_mϵ'_m=\frac16
$$
The first method for this order uses two terms and $ϵ_1=0$ and results in Heuns 3rd order method
$$
\D y=\frac14\Bigl(f(x,y)+3f(x+\tfrac23\D x, y+\tfrac23\D'y)\Bigr)\D x\\
\text{ where }\D'y=f(x+\tfrac13\D x, y+\tfrac13f(x,y)\D x)\D x
$$

With 3 terms one gets the original 3rd order method of Carl Runge (1895) as one among a large variety of configurations
$$
\D y=\frac16\Bigl(f(x,y)+4f(x+\tfrac12\D x, y+\tfrac12f(x,y)\D x)+f(x+\D x, y+\D 'y)\Bigr)\D x\\
\text{ where }\D 'y=f(x+\D x, y+f(x,y)\D x)\D x
$$

This rather expansive and repetitive notation was brought into a more compact framework by M. Wilhelm Kutta in 1901
Comment: I could have tried to improve my answer, but this one would still be better. One might also consult the works of John Butcher (e.g. https://www.math.auckland.ac.nz/~butcher/ODE-book-2008/Tutorials/RK-methods.pdf).

Euler vs. Heun Numerical Methods


Given $A = \begin{pmatrix} 0 & I\\ -I & 0 \end{pmatrix} \\$ Evaluate (in terms of theta): $e^{I\theta A}$

Question: I am having trouble figuring out how to interpret and approach this particular matrix exponential.

Given $$A = \begin{pmatrix} 0 & I\\ -I & 0 \end{pmatrix} \\$$
Evaluate (in terms of theta): $e^{I\theta A}$

Thank you in advance!
Comment: Is the exponent matrix $I$ (in which case omit it) or is it meant to be $i$?
Comment: Why write it there if it's the identity matrix? After all, $IB=B$ (when this makes sense).
Comment: The I is meant to denote the identity matrix in this case.
Comment: The question is part of a set of review questions for linear algebra that I need to work through as preparation for a course. I can only assume it is there to test if one knows what you just stated. @TedShifrin
Answer: Hint : notice that $$A^2 = -I$$


Count similar words

Question: I am having an issue with this program, I want it to only displays words in the input once and count each time they appear, however it is displaying every word entered.
for example if i enter

"this should only only appear appear once"

then i want the program to output
this 1
should 1
only 2
appear 2
once 1

Any help would be appreciated.
#include <stdio.h>
#include <string.h>

#define ROW 1000
#define COL 50

int read_input(char *str, int n);

int main(void)
{
    char str[ROW];
    char stringSeperate[ROW][COL] = { };
    const char *s= " ,.!";

    char *p;
    int freq[ROW];
    int i = 0;
    int wordCount = 0;
    int pos = 0;

    read_input(str, ROW);

    p = strtok(str,s);
    i = 1;

    while(p !=NULL) {
        wordCount = i;
        for(i = 0; i < wordCount; i++) {
             if (strcmp(p, stringSeperate[i]) != 0)
                pos = 1;
            else
                pos = i;
        }
        if (pos == 1) {
            strcpy(stringSeperate[i], p);
            freq[i++]++;

        }
        else
            freq[pos]++;
        p = strtok(NULL,s);
    }

    for ( i = 1; i <= wordCount; i++ ) {
        printf("Word: %s\t Number: %d\n",stringSeperate[i], freq[i]);
    }

    return 0;
}

int read_input(char *str, int n)
{
    int ch, i = 0;

    while((ch = getchar()) != '\n') {
        if ( i < n ) {
            *str++ = ch;
            i++;
        }
    }
    *str = '\0';
    return i;
}

Comment: Note: you should start using array from index 0 if it is not too confusing for you.
Answer: You invoked undefined behavior by using value of uninitialized variable freq having automatic storage duration, which is indeterminate.
Initialize it like int freq[ROW] = {0};
Also you should
1. Change initialization of stringSeperate to standard: empty initlalizer is not allowed, so it should be like
char stringSeperate[ROW][COL] = {{0}};

2. Remove extra printing to match the desired output: change
printf("Word: %s\t Number: %d\n",stringSeperate[i], freq[i]);

to
printf("%s %d\n",stringSeperate[i], freq[i]);

3. Check the length of input in order not to cause buffer overrun. Change
if ( i < n ) {

in read_input to
if ( i < n - 1 ) {

in order to make room for terminating null-characteer.

Count similar words


Evaluating $\sum_{i=3}^5 f_{2i}$

Question: I was studying for some quizzes when a wild question appears. It goes like this:

If the ith Fibonacci number is denoted by $f_i$, calculate $\sum_{i=3}^5 f_{2i}$

My work
The Fibonacci sequence looks like this: $0,1,1,2,3,5,8,13,21,34,55......$
The formula to get the ith term of a Fibonacci sequence is $ith \space term = \frac{a^i + b^i}{a+b}$, where $a = \frac{1+\sqrt{5}}{2}$ and $b = \frac{1-\sqrt{5}}{2}$.
Looking at the given formula above....it becomes...
$$ \sum_{i=3}^5 f_{2i} = f_{2(3)} +f_{2(4)} + f_{2(5)}$$
$$ \sum_{i=3}^5 f_{2i} = f_6 +f_8 + f_{10} $$
Getting now the 6th, 8th and 10th term of the Fibonacci sequence:
$$6th \space term = \frac{a^6 + b^6}{a+b} = 18$$
$$8th \space term = \frac{a^8 + b^8}{a+b} = 47$$
$$10th \space term = \frac{a^{10} + b^{10}}{a+b} = 123$$
Then....
$$ \sum_{i=3}^5 f_{2i} = f_{2(3)} +f_{2(4)} + f_{2(5)}$$
$$ \sum_{i=3}^5 f_{2i} = f_6 +f_8 + f_{10} $$
$$ \sum_{i=3}^5 f_{2i} = 18 + 47 + 123 = 188$$
The problem is that my answer wasn't in the choices, then I don't know where I screwed up.
How to properly get $\sum_{i=3}^5 f_{2i}$
The choices were $$55, \space 178, \space 89, \space 84$$
Comment: Are you sure about the problem statement ? This is just $F_6+F_8+F_{10}$, which can even be computed mentally. Better to tell us what the choices were.
Comment: @YvesDaoust It was my first time encountering that problem...so it thought it might be difficult......The notation was intimidating......plus...I often get thrown out if I ever encounter more genuinely-difficult versions of the above problem.....I just want to make  sure that my train of logic is correct..........hehehehe.....
Comment: You don't answer my questions.
Comment: @YvesDaoust Yes...that's how it was written....I discovered that question while helping a friend on his review classes......The choices were $55, 178, 89, 84$
Answer: The Fibonacci's first term is variously set to be either $0$ or $1$. Clearly, this question is adopting the latter convention (whereas you assumed the former), giving:
$f_6 = 8, f_8 = 21, f_{10} = 55$ and the required sum is $84$.
As another answer-giver stated, don't overcomplicate things.
Answer: $$\sum_{i=3}^5 f_{2i} = f_6 + f_8 + f_{10} = 8+21+55 = 84$$
It's the last option. You're complicating everything.
Answer: Hint: Just plug in the numbers you know: $8 + 21 +55 =?$
Answer: As mentioned by other answers, those numbers are small enough that you can evaluate them directly. After all, you have listed them earlier.
As for the mistake.
$$f_i = \frac{a^i\color{red}{-}b^i}{a\color{red}{-}b}=\frac{a^i-b^i}{\sqrt{5}}$$

Evaluating $\sum_{i=3}^5 f_{2i}$


How to use Hash values in ruby

Question: I wrote a small Ruby program, but  can't access the hash value stored in the parent class.
Here is the code:
class College
  @@dep = ["cs" => 60000, "mat" => 20000, "che" => 30000]
end

class Student < College
  def get_det
    puts "Enter name... \n"
    @name = gets
    puts "Enter department...\n"
    @dpt = gets
  end

  def set_fee
    case @dpt
    when "cs"
      @fee = (@@dep["cs"]).to_i
    when "mat"
      @fee = @@dep["mat"].to_i
    when "che"
      @fee = @@dep["che"].to_i
    else
      puts "Eror!!!"
    end
  end

  def print_det
    puts "Name : #{@name}"
    puts "Department : #{@dpt}"
    puts "Course fee : #{@fee}"
  end
end

det = Student.new

det.get_det
det.set_fee
det.print_det

I got the output as:
Output:
Comment: You want `@name = gets.chomp` and `@dpt = gets.chomp`. If the user enters `"Bubba"`, followed by return, `gets` returns `"Bubba\n"`. `chomp` lops off the `"\n"`. If you don't `chomp`, `@dpt` will never be matched in the case statement.
Comment: `gets` will also preserve the new line, so use `String#chomp` as @Cary suggested. Also the `Sudent#set_fee` can be simplified to `@@dep[@dpt].to_i`. Your hierarchy is weird.
Comment: Don't use a link to store a page showing your output. Links rot then break. Instead put the output into the text of your question. Read "[ask]" and "[mcve]".
Answer: You've defined your @@dep variable as an array, not as a hash. You need to replace [ ] with { }, like so:
@@dep = {"cs" => 60000, "mat" => 20000, "che" => 30000}

Then you'll be able to access your hash values via the string keys:
@@dep['cs']  # Will return 6000

And just an FYI, your set_fee method could be refactored to just be this:
def set_fee
  @fee = @@dep[@dpt] || 'Error!'
  puts @fee
end

Since you're simply passing in the value you're checking against for each of your when statements, you can just pass the value directly to your @@dep object. And you don't need to_i, because the values in your hash are already integers.

How to use Hash values in ruby


Como chamar uma View passando parâmetros através de json

Question: Tenho este código que passa parâmetros para meu controller:
<code>var id = $(Musico).val();
var url = '@Url.Action("Votar","Chamada")';
var tipo = 1;
$.ajax({
    url: url,
    data: {
         id:id, tipo:tipo
    }
});
</code>
meu controller:
<code>    public ActionResult Votar(int id, int tipo)
    {
        if (tipo == 1)//Tipo Musico
        {
            var chamadaMusicas = db.ChamadaMusicas.Include(c => c.Chamada).Include(c => c.Musica).Where(c => c.Chamada.PessoaID.Equals(id)).Where(i => i.Chamada.Ativa.Equals(true)).ToList();
            return View(chamadaMusicas);//Fábio Souza);
        }
        else//Local
        {
            var chamadaMusicas = db.ChamadaMusicas.Include(c => c.Chamada).Include(c => c.Musica).Where(c => c.Chamada.LocalID.Equals(id));
            return View(chamadaMusicas.ToList().Where(i => i.Chamada.Ativa.Equals(true)));//Fábio Souza);
        }
    }
</code>
até o controller, está recebendo as informações tudo certo, porém a view não abre. o que teria que fazer para a view Votar seja aberta?
Answer: Você não está tratando o retorno da chamada Ajax.
Tem que tratar no Success, pegar o resultado e inserir em algum lugar.
<code>        $.ajax({
        url: url,
        type: "GET",
        success: function (result) {
            $('#resultado').html(result);
        },
        error: function (x, m, s) {
            if (x.status == 403) {
                alert(m, x.statusText);
            } else {
                alert(x.responseText);
            }
        }
    });
</code>


difference between msgget() and mq_open

Question: I Read about message queue operations such as msgget(), msgsnd() and msgrcv(). But when I was searching for message queue related questions on stack overflow, I came to know there is another set of message queue operations such as mq_open(), mq_send(), mq_receive(). Can any one please let me know what are the differences between these 2 types of message queues and which type of message queues are extensively being used?
Answer: The msgXXX family is inherited from SysV.  The mq_XXX family was created by POSIX.  Both families are however part of POSIX.
The two families have somewhat different feature sets the most important being that the SysV variant allows for the specification of different message types.  This provides for flexibility in the way messages are processed and in assigning priorities.  The POSIX family in contrast always returns the oldest message with the highest priority.
As a rule the POSIX family is the better choice unless there is something about SysV that you really need to use.  The POSIX interface is also less cumbersome.  An added bonus (on Linux) is that the POSIX mqd_t type representing a queue identifier is actually a file descriptor.  This allows for the extremely convenient use of POSIX queues with select, poll and similar facilities.
Answer: Basicly, msgget, msgsnd, msgrcv are System V IPC, while mq_open, mq_send, mq_receive are POSIX IPC.
A good explaination: System V IPC vs POSIX IPC
Oracle Document for System V IPC
Oracle Document for POSIX IPC
In summary, POSIX IPC is designed after System V IPC. So a lot of old systems support only System V IPC while new systems begin to support POSIX IPC as well. And, because POSIX IPC can learn the advantages and disadvantages from System V IPC, POSIX IPC may be designed and implemented better. A notable difference is that all the POSIX IPC interfaces are thread safe.
Comment: SysV interfaces are also thread safe.  There would be no point to them otherwise.
Comment: Well, I didn't confirm it but just read it from docs.oracle.com/cd/E19455-01/806-4750/6jdqdfltf/index.html that SysV IPC may not thread safe: *Unlike the System V IPC interfaces, the POSIX IPC interfaces are all multithread safe.* @Duck

difference between msgget() and mq_open


Somar valores de linhas dinâmicas automaticamente

Question: Conforme o exemplo abaixo, estou tentando somar os valor das linhas Qtde Transferir, que são geradas dinamicamente conforme o resultado do banco, subtrair do valor digitado no campo Quantidade a Transferir e exibir a diferença no campo Falta:

Montei o código abaixo, usando alguns exemplos que encontrei, ele somou as linhas dinâmicas, mas preciso primeiro digitar os valores nas linhas e por ultimo a Quantidade a Transferir para calcular a Falta:
$(document).ready(function() {
    $("#qtde_entrada").on('change', function() {
    if($(this).val().length > 0) {
     var total = 0;
     $('.input').each(function(){
       var valor = Number($(this).val());
       if (!isNaN(valor)) total += valor;
     });
     var final = $("#qtde_entrada").val() - total;
     $("#qtde_falta").val(final);
    }
    });
});

Os inputs estão setados desta forma:
Qtde a Transferir e Falta:

          Quantidade a Transferir:
          <input type = "number" id="qtde_entrada" name = "qtde_entrada"  min="1" max="99999" style="width: 10em;"> -
          Falta: <input type = "number" id="qtde_falta" name = "qtde_falta" class="resultado" style="width: 10em;" readonly>

Qtde Transferir (dinâmico):
HTML += "<input type = 'text' size = '5' name = 'qtde_trans[]' id = 'qtde_trans[]' class='input' >
";

Alguma sugestão de como poderia fazer para primeiro digitar o valor total a transferir e conforme for digitado nas linhas ele ir exibindo na falta?
Answer: Você pode separar o cálculo em uma função:
function calc() {
    if($(this).val().length > 0) {
      var total = 0;
      $('.input').each(function(){
        var valor = Number($(this).val());
        if (!isNaN(valor)) total += valor;
      });
      var final = $("#qtde_entrada").val() - total;
      $("#qtde_falta").val(final);
    }
}

E utilizá-la no evento change tanto do #qtde_entrada quanto dos campos dinâmicos:
$('#qtde_entrada').on('change', calc);
$('table').on('change', '.input', calc);

Repare na segunda linha do código acima, a construção do on está diferente. Como os campos são dinâmicos, você precisa usar algo chamado de delegation. Isso é necessário porque quando você escuta um evento no Javascript, ele associa a função de resposta aos elementos presentes no DOM; então se temos o seguinte código:
`$('.input').on('change', calc);

A função calc vai ser associado ao evento change dos elementos .input presentes no momento da chamada. O que não resolveria seu problema, umas vez que esses campos são dinâmicos e podem ser inseridos na página após a execução do código acima.
Ao utilizarmos a construção:
$('table').on('change', '.input', calc);

A biblioteca jQuery vai associar o evento change ao elemento table, mas vai executar a função calc apenas quando o change ocorrer nos elementos .input. Isso ocorre devido ao event bubbling, que faz com que ao ocorrer um evento em um elemento, ele (o evento) é propagado até o pai mais alto a partir do elemento onde o evento foi iniciado, ou até que a propagação seja cancelada (retornando false ou chamando o método stopPropagation do evento).
Como mostra na imagem abaixo, o evento iniciou no elemento de número 3 e propagou para cima até o elemento de número 1:

Dessa forma o evento não está mais associado apenas aos elementos que existiam na hora da associação. Os novos elementos também vão propagar o evento e a função calc será chamada corretamente.
Veja funcionando: https://jsfiddle.net/bdsb70rh/
Comment: Deu certo, faltou uma # na parte que mudei no var table. Obrigado pela excelente explicação e resposta. Muito obrigado.
Comment: Obrigado pela resposta. Estou olhando no JSfiddle e realmente funcionou. No meu caso ainda não, mas estou revisando novamente.
Comment: @Diego Como aplicou as modificações?
Answer: O código quase faz o que deseja, porém não recalcula enquanto está digitando nas linhas. Para isso basta adicioná-las ao evento de alteração.

$(document).ready(function()
{
    $("#qtde_falta").val("? - 0.0"); // Definimos um texto inicial
});
function alteracaoValores() // Quando houver alterações, não importando qual dos campos for (das linhas ou da qtd transferir)
{
    var total = 0.0;
    $('.somatorio').each(function() // Tanto para alteração na linha superior como nas editadas...
    {
        var valor = Number($(this).val());
            if (!isNaN(valor)) total += valor;
    }
    var quant_entr = parseFloat($("#qtde_entrada").val());
    if(!isNaN(quant_entr))
    {
        var final = quant_entr - total;
            $("#qtde_falta").val(final);
    }
    else
    $("#qtde_falta").val("? - " + total); // Colocar texto quando não tiver campo quantidade a transferir preenchido.
}

HTML:

      Quantidade a Transferir:
      <input type = "number" id="qtde_entrada" name = "qtde_entrada"  min="1" max="99999" style="width: 10em;" onchange='alteracaoValores();'> -
      Falta: <input type = "number" id="qtde_falta" name = "qtde_falta" class="resultado" style="width: 10em;" readonly>

HTML gerado dinâmicamente:
HTML += "<input type = 'text' size = '5' name = 'qtde_trans[]' id = 'qtde_trans[]' class='input somatorio' onchange='alteracaoValores();' >
";

Comment: Obrigado pela resposta, mas está dando um erro que não identifiquei porque: SyntaxError: missing ) after argument list

var quant_entr = parseFloat($("#qtde_entrada").val());


Hybris Server showing Garbage collection issue?

Question: I had recently installed java adopt JDK 1.8.0_202 version.
It worked fine for the first time and later when i start hybris server getting the below issue again & again on console :
JVMJ9GC063E Unable to open file '/opt/hybris/log/tomcat/java_gc_ger-d-maa-apsp-001.log' for writing

<allocation-stats totalBytes="223210880" >
  <allocated-bytes non-tlh="13688" tlh="223197192" />
  <largest-consumer threadName="localhost-startStop-1" threadId="0000000002F7B000" bytes="217285784" />
</allocation-stats>
<gc-op id="2563" type="scavenge" timems="53.990" contextid="2560" timestamp="2019-03-14T15:18:57.791">
  <scavenger-info tenureage="14" tenuremask="4000" tiltratio="88" />
  <memory-copied type="nursery" objects="394430" bytes="16048744" bytesdiscarded="115760" />
  <finalization candidates="204" enqueued="174" />
  <ownableSynchronizers candidates="3195" cleared="7" />
  <references type="soft" candidates="9645" cleared="0" enqueued="0" dynamicThreshold="32" maxThreshold="32" />
  <references type="weak" candidates="6673" cleared="84" enqueued="67" />
</gc-op>
<gc-end id="2564" type="scavenge" contextid="2560" durationms="54.398" usertimems="46.801" systemtimems="0.000" timestamp="2019-03-14T15:18:57.791" activeThreads="2">
  <mem-info id="2565" free="564246568" total="1073741824" percent="52">
    <mem type="nursery" free="224266520" total="268435456" percent="83">
      <mem type="allocate" free="224266520" total="240451584" percent="93" />
      <mem type="survivor" free="0" total="27983872" percent="0" />
    </mem>
    <mem type="tenure" free="339980048" total="805306368" percent="42" macro-fragmented="3110739">
      <mem type="soa" free="299715344" total="765041664" percent="39" />
      <mem type="loa" free="40264704" total="40264704" percent="100" />
    </mem>
    <pending-finalizers system="174" default="0" reference="67" classloader="0" />
    <remembered-set count="33247" />
  </mem-info>
</gc-end>
<cycle-end id="2566" type="scavenge" contextid="2560" timestamp="2019-03-14T15:18:57.792" />
<allocation-satisfied id="2567" threadId="0000000002F7B000" bytesRequested="48" />
<af-end id="2568" timestamp="2019-03-14T15:18:57.792" threadId="0000000002F7B988" success="true" from="nursery"/>
<exclusive-end id="2569" timestamp="2019-03-14T15:18:57.792" durationms="55.438" />

<exclusive-start id="2570" timestamp="2019-03-14T15:19:06.478" intervalms="8740.918">
  <response-info timems="0.039" idlems="0.039" threads="0" lastid="0000000002F7B000" lastname="localhost-startStop-1" />
</exclusive-start>
<af-start id="2571" threadId="0000000002F7B988" totalBytesRequested="24" timestamp="2019-03-14T15:19:06.478" intervalms="8740.939" type="nursery" />
<cycle-start id="2572" type="scavenge" contextid="0" timestamp="2019-03-14T15:19:06.478" intervalms="8740.941" />
<gc-start id="2573" type="scavenge" contextid="2572" timestamp="2019-03-14T15:19:06.479">
  <mem-info id="2574" free="339975744" total="1073741824" percent="31">
    <mem type="nursery" free="0" total="268435456" percent="0">
      <mem type="allocate" free="0" total="240451584" percent="0" />
      <mem type="survivor" free="0" total="27983872" percent="0" />
    </mem>
    <mem type="tenure" free="339975744" total="805306368" percent="42">
      <mem type="soa" free="299711040" total="765041664" percent="39" />
      <mem type="loa" free="40264704" total="40264704" percent="100" />
    </mem>
    <remembered-set count="34712" />
  </mem-info>
</gc-start>

Any help would be appreciated?
Thanks,
Mohammed
Comment: What is the issue? You don't want this logs in console?
Comment: @talex  Yes i dont want to see this again & again in console...Is it possible to stop that?
Answer: This logs produced by -verbose:gc (or similar) JVM option.
You should remove that option if you don't need this logs.
Comment: Can i pls know what is the location of this from where i need to remove?
Comment: How you start your app?
Comment: i can see -verbose:gc this in wrapper.conf file....can i comment it for changes to get refelcted?  i startmy server from console hybrisserver.bat command
Comment: Yes. Remove it and restart your app.
Comment: Even after removing.. i can still see them on console
Comment: Check your local.properties file for tomcat.generaloptions and tomcat.debugjavaoptions configuration params. wrapper.conf file overwriting with clean build.
Comment: @mkysoft You want me to remove that from generaloptions?
Comment: In Hybris `verbose:gc` option is usually added in the environment variable `CATALINA_OPTS` and sometimes in `JAVA_OPTS`, albeit you can add it to the configuration of any *environment variable*.


Como criar um algoritmo que rastreie automaticamente certas paginas de um site?

Question: Eu tenho uma plataforma onde as pessoas podem colocar comentários escrever opiniões e eu neste momento preciso de criar um algoritmo em que me rastreie essas mesma zonas do site caso alguém escreva um comentários menos impróprio o mesmo o apague do sistema automaticamente sem que eu esteja sem a deitar um olho no que as pessoas escrevem.
Gostaria de saber a melhor forma de fazer e sugestões de como o fazer.
Answer: Não creio que rastrear a página em busca de comentários impróprios seja a melhor opção.
O que você pode implementar é um algorítimo que crie uma fila de aprovação dos comentários, obrigando que todos os comentários sejam aprovados pro algum moderador, assim como ocorre do Wordpress.
Outra sugestão pode ser não permitir que alguns comentários sejam postados a partir de uma lista de palavras proibidas, barrando assim na hora que o usuário tentar incluir o comentário.
Você pode também combinar essa lista de palavras proibidas com a fila de aprovação para pré-aprovar os comentários que não possua essas palavras.
Answer: Esta acção deverá ser feita antes da inserção da mensagem na base de dados, dessa maneira você não irá gastar recursos a percorrer uma página de X em X tempo.
pseudo-code:
<code>if (coisa_inserida.contains('asneira'))
    nao_inserir_em_base_de_dados;
    mostrar_erro('asneiras nao sao permitidas');
}
else {
    inserir_em_base_de_dados(coisa_inserida);
    mostrar_sucesso('yay! comentario inserido!');
}
</code>

Pode, no entanto, fazer um sistema de approval - como o @gmsantos referio.


statement is true for L^2 not for L^1

Question: A problem about L^p space in Bass's real analysis book.
Define $g_n(x) = n\chi_{[0,n^{-3}]}(x)$:
(1) Show that if $f \in L^2([0, 1])$, then $\int_{0}^{1}f(x)g_n(x)dx\rightarrow 0$
(2)Show that there exist $f \in L^1([0, 1])$ such that $\int_{0}^{1}f(x)g_n(x)dx \nrightarrow 0$;
I've no idea how to prove that, please give any hint or idea. thanks
Answer: For the first one, you can use Cauchy-Schwarz.
For the second one, how about $f(x) = x^{-\frac{2}{3}}$
Comment: thanks, here is what I am thinking (1) $f, g_n \in L^2$ and $\int {g_n}^{2} dx \rightarrow 0$, then by Cauchy Schwarz ineq, we get it;
(2) it approaches to 1.
Comment: Actually, for the 2), it's equal to 3 : $$\int n x^{-\frac{2}{3}} dx = 3nx^{\frac{1}{3}}$$ so between $0$ and $n^{-3}$ you get $3$ and not $1$

statement is true for L^2 not for L^1


How to create a configuration export such that it installs two modules, one of which has a dependency on the other?

Question: I've written a custom module that uses jwt.transcoder service  from the jwt module. In turn, it provides another service:
$ cat mymodule.services.yml
services:
  mymodule.jwt:
    class: Drupal\mymodule\Services\Jwt
    arguments: [ '@jwt.transcoder', '@event_dispatcher' ]

Everything went smoothly during development. However, neither the jwt module, nor my new custom module, were installed on our site before I started developing this feature.
I added both modules with composer, and did a config export to enable them (and set up the cryptographic keys, etc). However, when I go to do a deployment, I get an error on the config import, which apparently is coming from a dependency on the jwt.transcoder service, which is not yet installed at this point.
In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86:

  The service "mymodule.jwt" has a dependency on a non-existent service "jwt.transcoder".

With our deploy process, we can only deploy one codebase at a time-- meaning that, if I wanted to do a config import to get jwt installed first, and another config import with the enabling of my custom module, I would have to do a second deploy to do get that second config codebase up on the server.
Is there any way to get the config import to install jwt first, and then my custom module, in a single codebase, so this dependency is resolved?
Comment: Is "jwt" marked as a dependency of "mymodule" in mymodule.info.yml?
Comment: @sonfd that was it! Thank you. Please put that in an answer and I will accept it : )
Answer: You need to mark the jwt module as a dependency of mymodule in mymodule.info.yml, via the dependencies key.

dependencies: a list of other modules your module depends on. Dependencies on Drupal core or contrib modules should be namespaced in the format {project}:{module}, where {project} is the project name as it appears in the Drupal.org URL (e.g. drupal.org/project/views) and {module} is the module's machine name. Dependencies can also include version restrictions, for examplewebform:webform (>=8.x-5.x). Note that if your module has dependencies on other contributed modules or libraries, these should be declared in the module's composer.json file. If you have local custom modules that are dependent on each other you can use {module}:{module} (or {module}:{submodule} for sub-modules.)
Source: Let Drupal know about your module with an .info.yml file

For example, inside your mymodule.info.yml:
name: My Module
type: module
...
dependencies:
  - jwt:jwt


fpdf com cakephp

Question: Estou usando a biblioteca no cakephp de fpdp, criei um método privado no meu controller montando um pdf básico e depois chamei esse método em uma action mas ele não gera o pdf..
método privado:
private function montaPDF(){
    require('fdpf/fpdf.php');
    $pdf = new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->Cell(40,10,'Hello World!');
    $pdf->Output();
}

e retorna esse erro na minha page:

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x�3R��2�35W(�r Q�w3T04�30PISp  �Z*�[����(hx����+���(j*�d��7W endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 5 0 R >> /XObject << >> >> endobj 6 0 obj << /Producer (FPDF 1.7) /CreationDate (D:20150824102520) >> endobj 7 0 obj << /Type /Catalog /Pages 1 0 R >> endobj xref 0 8 0000000000 65535 f 0000000228 00000 n 0000000416 00000 n 0000000009 00000 n 0000000087 00000 n 0000000315 00000 n 0000000520 00000 n 0000000595 00000 n trailer << /Size 8 /Root 7 0 R /Info 6 0 R >> startxref 644 %%EOF
Comment: Você já verificou se ele não esta renderizando a view? tenta `$this->autoRender = false`
Comment: sim, está com autoRender = false;
Answer: 1 - Crie um layout por exemplo "pdf.ctp" em /views/layoyts
<?php
header("Content-type: application/pdf");
echo $content_for_layout;
?>

2 - No controlador, use o layout citado acima.
3 - Na visão, certifique-se de usar o TCPDF com a codificação correta.
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);

Link: http://www.tcpdf.org/doc/code/classTCPDF.html#a134232ae3ad1ec186ed45046f94b7755

fpdf com cakephp


How to evaluate classification results (Precision, Recall, F1)?

Question: For a classification problem (based on news summery, put news articles into 4 classes), we built a linear SVC model, trained with 120,000 data and tested with 7,600 data. The result is:
Accuracy = 0.9134210526315789
Weighted Precision = 0.9134148091865167
Weighted Recall = 0.9134210526315789
F1 = 0.9132905479246967
The question is how to evaluate such result? Is the result good, normal or bad?
Is there any rule of thumb value or anything we can compare, like famous classification problem result or kaggle competition result?
Thanks
Comment: Those numbers are rather high, but as you mentioned, it's all relative. Try and look for different work on a different dataset (perhaps in google scholar), and run your classifier on that dataset. Compare the results to the previous results.
Answer: If you don't have much experience with either the data or this type of task, I think @Eran's suggestion is correct.
Here are a few classic natural language processing text classification benchmarks:

Reuters-21578
RCV1
the 20 newsgroups dataset

Let's look at some old results:

In (Lewis et al., 2004) was getting a micro-averaged F1.0 score of 0.816 with SVMs on RCV1 on 101 topics.
In the scikit-learn documentation they get a macro-averaged F1 score of 0.769 with Naive Bayes based on 20 topics.
In (Li and Yang, 2004) get they get a  macro-average F1 0.8857 with a SVM across 90 categories.

I don't know what the state of the art is for these datasets, but I am sure you could track it down. You can see also that there's quite a bit variation in terms of how hard these datasets are.
Depending on which dataset yours is more like, I'd interpret your results somewhere in the range of middle of the road to quite good. Now you could run your model on these datasets and directly compare how effective your models is on these known datasets. This is the common task framework methodology in action!
Lewis, David D., et al. "Rcv1: A new benchmark collection for text categorization research." Journal of machine learning research 5.Apr (2004): 361-397.
Li, Fan, and Yiming Yang. "A loss function analysis for classification methods in text categorization." Proceedings of the 20th International Conference on Machine Learning (ICML-03). 2003.


Propriedade com GET (GetterOnly) com IQueryable linq C#

Question: Não sei exatamente como se chama quando mapeia o retorno no método assim, mas vou tentar explicar, Eu tenho a seguinte classe por exemplo:
public class Venda(){
   public decimal Valor {get;set;}
   public decimal Desconto {get;set;}
   public decimal ValorLiquido => Valor - Descontos;
}

Eu uso EntityFramework e essa classe seria uma model do Banco de Dados, preciso fazer um relatorio de vendas e nesse relatorio eu uso a Propriedade ValorLiquido e o problema esta ai faço a seguinte consulta:
var vendas = ctx.Vendas;

Isso me retorna uma Iqueryable ate ai tudo bem, porem se eu tento usar a propriedade ValorLiquido me retorna a seguinte mensagem:

The specified type member 'ValorLiquido' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

Se eu der ToList() passa a funcionar e consigo acessar a propriedade, só que é um relatorio com mais de 50mil itens, e na classe real, existe umas 10 Propriedade GetterOnly pra mais, então é inviável usar ToList(),
A questão é:
Teria alguma forma de acessar essa propriedade sem dar ToList() no caso numa lista IQueryAble?
Comment: @EdenilsonBila de uma lida nisso: https://pt.stackoverflow.com/questions/17284/qual-a-diferen%C3%A7a-entre-ienumerable-iqueryable-e-list   O IQueryable é uma arvore de consulta, os dados não foram "materializados" ainda. por isso não é possível acessar o propriedade ValorLiquido
Comment: Porque não utilizas uma View que carrega os teus dados já calculados, logo o output muito menor, (calculas no servidor), ao invés de carregares 50K de registos...e quando chegar aos 10 milhões? O que fazes?
Comment: Teria como parametrizar essa view pela aplicação? No caso deste relatorio o Usuario pode escolher os filtros, como data, forma de pagamento e etc
Comment: As Views são como uma query normal a uma tabela, mas permite mapear o teu output (só retornas o que queres que vejam/acedam), fazer joins com outras tabelas, cálculos, agregar dados etc, doc microsoft https://docs.microsoft.com/en-us/sql/t-sql/statements/create-view-transact-sql?view=sql-server-2017. A sua utilização em SQL é como efetuares um select a uma tabela to tipo SELECT * FROM [View_Name] WHERE User LIKE '%An%', a sua utilização em EF, tens num post aqui https://stackoverflow.com/questions/7461265/how-to-use-views-in-code-first-entity-framework.
Comment: uma view carrega todos os dados antes de fazer os filtros, vai te dar dor de cabeça, se quiser diminuir o result set use um where no seu linq ex : .where(x=>x. valorliquido=10).ToList()
Answer: Já tentou ignorar o mapeamento desse campo no Entityframework adicionando o atributo 'NotMapped' ?
Exemplo:
public class Venda(){
   public decimal Valor {get;set;}
   public decimal Desconto {get;set;}
   [NotMapped]
   public decimal ValorLiquido => Valor - Descontos;
}


Prove that $f'''(x) = 0$ for some $x \in (0,1)$.

Question: I've been working on this problem for a bit and was hoping to get a hint.
Problem:
Suppose that $f$ is nonnegative and $f'''$ exists on $(0,1)$. Suppose also that there exist points $c \neq d$ in $(0,1)$ such that $f(c) = 0 = f(d)$. Prove that $f'''(x) = 0$ for some $x \in (0,1)$.
Attempt:
Since $f'''$ exists on $(0,1)$, $f''$ and $f'$ exist and are continuous on $(0,1)$. By MVT and $f(c)=f(d)=0$, $\exists ~x \in (c,d)$ such that $f'(x) = 0$. Maybe this $x$ is my candidate for $f'''(x)=0$, but I'm not sure how to move forward.
Thoughts?
Answer: $f$ non negative implies that $c$ and $d$ are minimums and $f'(c)=f'(d)=0$. Let $e$ be the maximum of $f$ in $[c,d]$, $f'(e)=0$ (we suppose $f(e)\neq 0$ otherwise the restriction of $f$ to $[c,d]$ is zero and the result is true). There exists $a\in (c,e)$ with $f"(a)=0$ (since $f'(c)=f'(e)=0$) and $b\in (e,d)$ with $f"(b)=0$ so there exists $u\in (a,b)$ with $f'''(u)=0$.
Comment: $f$ need not have a maximum, I suppose.
Comment: $f$ is continuous and not identically zero on the interval $[c,d]$, so it must have a maximum.
Answer: One can easily note that $c, d$ are local minima of $f$ and hence $f'(c) =f'(d) =0$. And since $f(c) =f(d) =0$, by Rolle's theorem we have a point $p\in(c, d) $ such that $f'(p) =0$. Now $f'(c) =f'(p)=f'(d) =0$ and hence Rolle's theorem gives us $a\in(c, p), b\in(p, d) $ such that $f''(a) =f''(b) =0$ and again applying Rolle's theorem we get $f'''(q) =0$ for some $q\in(a, b) \subseteq (0,1)$.
Comment: This is definitely the best answer here. Very elegant, too.
Comment: @Fimpellizieri: thanks for the appreciation. The key fact here is observation that $c, d$ are local extrema. Apart from that I think rest follows quite easily.
Answer: We have $f'(c)=0$. If $f''(c)\ne 0$, then $f'''(c)=0$. Similarly for $d$.
So let's assume $f''(c) > 0$, $f''(d) > 0$. Then $c,d$ are local minima.
So there must be a local maximum in $(c, d)$, at which, again, either the third derivative is zero, or the second derivative is negative.
Because $f''(c)>0$ or $f''(d)>0$, and $f''(a)<0$, then by mean value theorem, there exists a point at which the third derivative is zero.


Is this a bad use of GC.ReRegisterForFinalize()

Question: So I've heard that GC.ReRegisterForFinalize() should generally be avoided, but I see no reason to not use it for my specific problem. So first this is a very performance sensitive area of code so speed counts.
I have a stack of unmanaged resources and small (8 byte) managed objects each of which wrap one of these unmanaged resources. When a wrapper is created it pushes an unmanaged resource on the stack and wraps it. When its destructed instead of removing its resource from the middle of the stack (which would cause the whole stack to shift) it can do one of two things: either it can push an int representing its stack position into a queue, so the next object created can wrap that stack position instead of pushing a new one, or it can push itself into a queue and reregister for finalize and be reused.
The difference may be small, I realize I may be splitting hairs, but atleast with the second method I'm saving an allocation and deallocation each time it happens. So whats the downside?
Comment: Are you sure that the logic you're using actually increases performance?
Comment: @thecoop Not entirely sure. It seems like it would. I'm still hammering out some bugs. Might be a while before I can do real performance testing. Just wondering if there's a reason I should avoid this route.
Comment: If you're planning to reuse the objects, why are you finalizing them in the first place? Figure out a strategy (ideally using real performance data) and stick with it. If you're re-registering for finalization as part of your normal processes, you're probably doing something wrong. In any case - profile.
Comment: @Luaan becuase I want the wrappers to be valid for as long as they're being used without having to explicitly call some Dispose function. Letting the garbage handler determine when they're ready to recycle seems like the smartest route.
Comment: *Premature optimization is the root of all evil*. See what the performance is like with normal code, then, and only then, test if there is a significant difference with this logic. If there is, then put this in with LOTS of comments explaining what's going on and why you're doing it.
Answer: Ok, let me just write this down as an answer.
GC.ReRegisterForFinalize has a two uses - to revert the GC.SuppressFinalize() method, and to "resurrect" an object that's already in it's finalizer (the ~SomeType method).
You just need to understand how finalization works. The basic idea is, that a managed object that holds some unmanaged resource will get an opportunity to release the unmanaged resource when it's collected by the garbage collector. Since in most cases, you wan to release the resources much earlier (e.g. releasing a SqlConnection to make sure we're not keeping unnecessary sockets open), an optimization has been introduced, which is part of the "disposable pattern".
So, the finalizer will contain the code to get rid of the unmanaged resource, and nothing else. To handle the early disposal, we're going to implement a Dispose method, which does some cleaning-up, including releasing the unmanaged resource. Now, the type does have a finalizer, so it is registered for finalization by default - however, we've already released those unmanaged resources before, so there's no point in getting finalized on collection. So you call GC.SuppressFinalize(this), which basically removes this instance from the list of items to finalize on collection.
However, what if your class is not just a simple wrapper around the unmanaged resource, but for example allows you to release and reacquire it again? GC.ReRegisterForFinalize comes to the rescue - whenever you reacquire the unmanaged resource, you'll register yourself for finalization again, to ensure proper cleanup.
This somewhat violates a simple principle in dealing with unamanged resources in .NET, which is basically that the managed wrapper should be as small and simple as possible. So your real class that does some real work would use this tiny wrapper instead of directly using the unmanaged resource. This is one reason why you really don't need GC.ReRegisterForFinalize, and why seeing it in code might look fishy.
The second use for GC.ReRegisterForFinalize however, gets even more objectionable. It allows you to stop the finalization of the instance, and bring it back to life. Doesn't sound too bad? Well, for one, it shows that your design is likely flawed. More importantly, though, all the other instances that were only referenced by this instance (e.g. a field pointing to another .NET object) might have already been collected. This is a great way to introduce bugs that are very hard to reproduce. Programmers don't like those much, so you're mostly trying to avoid those as much as possible.
So, TL;DR version: You probably don't need GC.ReRegisterForFinalize. If you keep the managed wrapper in a list of "unused" objects, it will not be collected, and thus it will not be finalized either. It would only make a difference if you released the unmanaged resource first (in Dispose including a call to GC.SuppressFinalize), and then wanted to create a new unmanaged resource for the same managed instance. Which probably isn't what you want (there really isn't much of a point).


How can I find the percentage of men and women in a certain building?

Question: Tables:
- Activities: id, userId, description, buildingId
- Buildings: id, name
- User: id, name, gender

Users can create activities for example: "checking mail" would be an activity, the buildingid links to a building where a certant activity is going on.
What I need is a query that will get the % male/female per building, based of the amount of activities going on at such building.
For example:
User: 1, mike
Building: 1, main hall

Activities:

id: 1
userId: 1 (mike)
description: "checking mail"
buildingId: 1 (main hall)

id: 2
userId: 1 (mike)
description: "getting coffee"
buildingId: 1 (main hall)

So I want to get the % female / male of the building 1 (main hall) how can I do this the best way?
Comment: Seems like schoolwork, what did you try yourself..?
Comment: Im very bad in Mysql, seriously, im sorry.
Comment: Did you try to find some pen-and-paper solution? That would be a good start to "translate" it into some SQL.
Answer: SELECT buildingId,
  (SUM(CASE WHEN `User`.gender='male' THEN 1 ELSE 0 END)/
  COUNT(*))*100 as male_percent
FROM Activities JOIN `User` ON Activities.userID=`User`.id
GROUP BY `Activities`.buildingId

Or if you prefer ratio:
SELECT buildingId,
  SUM(CASE WHEN `User`.gender='male' THEN 1 ELSE 0 END)/
  SUM(CASE WHEN `User`.gender='female' THEN 1 ELSE 0 END) as ratio
FROM Activities JOIN `User` ON Activities.userID=`User`.id
GROUP BY `Activities`.buildingId


PHP & MySQL Tickers..Is this standard practice?

Question: I currently have about 4 different database tables which output to html tables. Each of these tables uses a count query to calculate data from a 5th table.
That's no problem, but what about when I want to sort and order the data, and paginate etc (like with zend). If it were a one page table, I could probably sort an array.
My thought was, to use a ticker. But that would require a new column in all 4 tables and seems like overkill or like there could be a better way.
Sadly, I can't find much info on it (likely because I don't know what to search for).
Advice?
..and please take it easy, I'm new and learning.
Answer: Assuming youre using Zend_Db_Table_Row and that you dont need to persist any modifications you might make to these rowsets then you can just append the virtual columns to the row object and have them be accessible via array notation. So if youre doing it all in one query now just use that same query, and the column should be there.
OTOH, if youre using a Data Mapper pattern then simply adjust your hydration to look for this "virtual column" and hydrate it if it exists in the result data. Then in your getter for this property have it see if the property is null or some other negative specification, and if it is, to execute a calculation query on that single object or return the already calculated result.
Comment: Thanks! That sounds perfect. Do you have a link where I can find more information about implementing virtual columns and such. I use Mappers which extend an abstract mapper. I have a getter for the property within the relevant mappers, but can't figure out how I would sort that property when I have an array of Mappers to loop through. i.e. having the data sorted prior to the loop.
Comment: Why would you have an array of mappers? shouldnt you have an array of objects? ie. Mappers issue queries and handle hydration and persisting the data objects, but in your view or with a paginator iw ould thing youd have a data object or a collection object... I Dont have any specfici links to a turotial but if you want o post sample schema and your query(ies) i might be inclined to give you a skeleton example...


What does a line through a tie indicate?

Question:
I was wondering how to play the notes that have a small dash going through the tie, for example, the first two beats of the second bar.
For the left hand, do you play it slightly staccato? That is what I have heard Barenboim do.
For the right hand, how is it played? Why are there two ties covering the first two notes of the notes written above the treble clef line but not one the last to notes?
Comment: The inset explains how the grace note is integral with the first proper note (grace note F, to E). The whole phrase of 4 notes has a slur mark, so it's a slur within a phrase, if you like.If that's how the composer wanted it played, can't understand why it wasn't written like that. Dash is interesting.
Comment: I think it's already answered here: https://music.stackexchange.com/questions/40417/slur-options-in-sheet-music "may use a dashed/dotted/broken slur or phrase mark when it's optional" or "may use a dashed/dotted/broken slur to indicate editorial material"
Answer: I think @atanii is right about the dashes, but I can tell you more about what the editorial note in the right hand's first measure means:
When composers of Mozart's time wanted to write out a group of four running notes that starts on a strong beat, they sometimes needed to prepare (or write) the notes differently than we would today. They would double the length of the second note, and prepare the first note as a grace note tied into the group.
I believe this is due to species counterpoint rules. It used to be considered undesirable to put a dissonant harmonic interval such as the perfect fourth between C and F on a "strong" beat. To circumvent this rule, Classical Era composers would place the second note, in this case a consonant major third, on the strong beat.
But you don't need to know that to perform this accurately. Play it just as the editorial inlay says: four slurred sixteenth notes, in time.
Answer: The line indicates that the slur is editorial, not in the original manuscript.  Unless you disagree with the editor, play it as normal.


Dúvida com height em um DIV

Question: Estou com um, problema que me parece muito simples e já fiz antes, porém simplesmente não me recordo como!
Supondo uma página com 3 divs (cabeçalho, conteúdo e rodapé) como faço para a div de conteúdo ocupar todo o espaço livre da página?
Ex:

    barra de cabeçalhos - está OK!

    área de conteúdo. Deverá preencher 100% da área disponivel entre o header e o footer

    barra de rodapé, fixo no bottom da página, está OK

Aqui o CSS atual:
#header {
     width: 100%;
     height: 65px;
     line-height: 65px;
     vertical-align: middle;
     overflow: hidden;
}
#footer {
    position:fixed;
    left: 0px;
    bottom: 0px;
    height: 15px;
    width: 100%;
    background: #434;
    padding: 6px;
}

Qual o css adequado para o #content?
Já tentei algumas soluções diversas, mas sem sucesso...
Lembrando que body e html já estão em 100% em outro trecho do CSS
Answer: Bom, se não precisar dar suporte para navegadores muito antigos tu pode usar o flexbox do CSS3, se encaixa como uma luva no seu caso.
Veja o exemplo

body {
  color: #fff;
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

#header,
#content,
#footer {
  padding: 1em;
}

#header,
#footer{
  background-color: #3498db;
}

#content {
  background-color: #2980b9;
  flex: 1;
}

barra de cabeçalhos - está OK!

área de conteúdo. Deverá preencher 100% da área disponivel entre o header e o footer

barra de rodapé, fixo no bottom da página, está OK

Aqui você encontra ótimos exemplos do que consegue fazer com flex
www.philipwalton.github.io/solved-by-flexbox
E aqui a tabela de compatibilidade
www.caniuse.com/#feat=flexbox
Answer: Você pode usar o método CALC
Da seguinte forma:
#content {
    height: calc(100% - 80x); /* 80 porque é 65+15 */
    /* height: 100% também pode funcionar! */
    background-color: gold;
}

/* Veja se isto está igual: */

html, body {
  height: 100%;
  margin:0px;
  padding:0px;
}

Teste isto clicando aqui. :)
Comment: Já tinha tentado com o height 100% mas tive problemas com a barra de rolagem! o Método CALC() funcionou perfeitamente, apenas ajustei os valores para compensar as margens e paddings! Obrigado! Funfou!
Answer: Outra maneira, é um height: auto, porém com um min-height: 100%.
JsFiddle

html, body{
 height: 100%;
}
#header {
  width: 100%;
  height: 65px;
  line-height: 65px;
  vertical-align: middle;
  overflow: hidden;
  background: #333;
}

#content {
  height: auto;
  min-height: 100%;
  background: #ccc;
}

#footer {
  position: fixed;
  left: 0px;
  bottom: 0px;
  height: 15px;
  width: 100%;
  background: #434;
  padding: 6px;
}

  barra de cabeçalhos - está OK!

 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus faucibus risus, sed fermentum risus condimentum eu. Suspendisse potenti. Pellentesque vel commodo nisi. Aliquam at arcu nec enim auctor ultricies. Quisque ac leo auctor, semper nisl nec, porta dolor. Duis eget ligula non leo lacinia rhoncus eget id nisi. Sed sit amet elit mi. Aliquam at mollis neque. Vestibulum ornare imperdiet turpis, sed tincidunt mi pulvinar in. Maecenas volutpat viverra augue a tempus. Donec eu aliquet dolor.

Mauris vitae urna sodales, dignissim felis ac, porttitor mauris. Nam tortor nisi, suscipit vitae diam nec, vehicula pulvinar neque. Sed sed luctus neque, quis fermentum odio. Pellentesque eu porttitor orci, sit amet iaculis leo. Mauris in ornare massa. Phasellus dolor leo, egestas vitae orci venenatis, suscipit condimentum lacus. Sed quis nisl placerat, tristique lacus ut, bibendum diam. Cras massa lacus, consequat at scelerisque a, euismod vel neque.

Cras finibus orci non scelerisque ornare. Morbi eu dapibus arcu. Maecenas tempor leo eu ligula fringilla, in egestas arcu pulvinar. Nunc eu purus non felis congue facilisis vitae porttitor turpis. Sed ullamcorper massa quis tortor convallis, id eleifend nisi sagittis. Ut posuere lacinia libero ac cursus. Sed luctus eget magna quis sollicitudin.

  barra de rodapé, fixo no bottom da página, está OK

Sem o height: auto, quando o conteúdo da div#content for maior que a altura da viewport, o conteudo irá ultrapassar a div. Veja nesse exemplo.
Porém com o height: auto e o min-height: 100% isso não acontecerá, como você pode ver aqui. Para que o footer não sobreponha o conteúdo dei ao body um padding-bottom: 5px.
Comment: Esse foi um dos métodos que tentei anteriormente sem sucesso. O problema com isso é que, como pode observar no link do exmplo que mandou, o header também se desloca com a barra de rolagem.
Comment: @RhubenniTelesco Vi no seu exemplo: "barra de cabeçalhos - está OK!", por isso não mexi nela. Mas ok. Apenas lhe atento novamente para o uso do `height:auto` para o ajuste de conteúdo.
Answer: vou utilizar position: absolute para tal;

html, body, main, header, footer, section, div {
  box-sizing: border-box;
}
html, body, main {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0px;
  margin: 0px;
  background-color: whitesmoke;
}

header, footer {
  position: absolute;
  width: 100%;
  height: 40px;
  box-shadow: 0px 0px 10px black;
  background-color: white;
  z-index: 2;
}

header {
  top: 0px;
}

footer {
  bottom: 0px;
}

section {
  position: absolute;
  width: 100%;
  top: 40px; /* height to header */
  bottom: 40px; /* height to footer */
  overflow-y: auto;
  z-index: 1;
}

    barra de cabeçalhos - está OK!

    área de conteúdo. Deverá preencher 100% da área disponivel entre o header e o footer

        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sit amet lorem imperdiet, aliquam justo condimentum, euismod sapien. Aliquam vulputate sodales ligula eu convallis. Mauris vulputate enim et velit sagittis, porta efficitur lectus ultricies. Sed tincidunt libero eu aliquet pharetra. Nam quis vestibulum augue. Vestibulum facilisis ipsum urna, in tempus nunc condimentum at. In nisl erat, tempor eu nisi a, hendrerit ullamcorper nisl. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec quis leo at justo fringilla placerat at sit amet lorem. Maecenas placerat scelerisque magna nec varius. Nulla facilisi. Morbi ipsum velit, euismod vitae dolor ut, blandit laoreet magna.

        Sed eu mi sem. Suspendisse consequat leo eu maximus fringilla. Suspendisse ornare pellentesque semper. Pellentesque ac ipsum ac diam tempor mollis. Suspendisse sit amet commodo nisi. Donec mattis ipsum quis dolor finibus venenatis. Nam at tincidunt tortor. Sed pretium tellus quis justo suscipit, quis elementum ex blandit. Donec sit amet rhoncus diam. Fusce sagittis laoreet interdum.

        Maecenas ac tortor sed elit interdum placerat nec ac justo. Quisque a nibh semper, feugiat augue id, iaculis orci. Vivamus sollicitudin ante nec aliquam vehicula. Fusce viverra venenatis diam eu tincidunt. Fusce ornare eros vitae metus faucibus tincidunt quis sit amet tellus. Nam dignissim scelerisque quam ac ullamcorper. Suspendisse nibh enim, ultricies non pretium et, tempus id ligula. Quisque interdum erat odio, sit amet dictum lectus vehicula consequat. Aliquam ac rutrum dui, vitae sollicitudin libero.

        Sed fermentum nisi pharetra, varius urna ullamcorper, molestie dui. Quisque orci elit, commodo sit amet velit a, mollis facilisis lacus. Phasellus et lacus quis nisi dignissim ultrices ac vel libero. Quisque accumsan, nisi sed molestie tristique, elit dui sagittis lacus, sit amet tristique turpis erat eu lorem. Proin a gravida mauris. Pellentesque quis egestas leo. In eget enim dui. Fusce consequat sit amet orci ac gravida.

        Donec est nunc, venenatis eu justo quis, lobortis finibus lectus. Pellentesque convallis ultricies sodales. Pellentesque elementum sodales lacus, quis vehicula purus luctus ac. Nam vel elit eleifend, lobortis neque sit amet, hendrerit nulla. Nunc tincidunt, tortor at condimentum consequat, enim tellus elementum risus, vulputate tincidunt sapien elit nec est. Donec congue ex nec rutrum aliquam. Etiam nec aliquet erat.

        Morbi sed aliquet enim. Curabitur egestas et lorem vel ultrices. Aenean pharetra dui ac laoreet tempor. Praesent nec varius velit, nec varius ipsum. Aenean feugiat dui ipsum, non placerat augue congue non. Maecenas tincidunt arcu nec ex efficitur, sed pretium arcu aliquam. Aliquam tincidunt pretium mauris eget tincidunt.

        Sed vel justo condimentum, egestas purus et, commodo nibh. In fermentum placerat neque eu mollis. Fusce condimentum, augue ut porta congue, arcu leo sagittis nulla, vel convallis ante lorem a felis. Morbi sit amet augue sagittis velit condimentum pulvinar pellentesque et dolor. Pellentesque fermentum egestas ante, ut mattis enim blandit eget. Maecenas iaculis auctor tortor id bibendum. Fusce euismod augue nibh, ac feugiat odio convallis sed. Aliquam a augue ac sapien aliquet tincidunt. Duis viverra id arcu ac rhoncus. Sed volutpat, arcu in vulputate fermentum, erat arcu sagittis metus, id suscipit nulla erat eu nibh. Sed accumsan faucibus faucibus.

        Vestibulum dictum maximus est, eu suscipit neque sollicitudin eget. Aenean justo nibh, elementum vitae nisl ut, tincidunt porta elit. In tincidunt condimentum ornare. Pellentesque aliquam semper nisi non lacinia. Quisque porttitor rhoncus lorem, eu sollicitudin urna ornare non. Mauris ac mattis orci. Mauris facilisis iaculis pretium. Phasellus eget accumsan justo. Curabitur lacinia ullamcorper erat id pharetra.

        Morbi aliquet nulla ultrices urna interdum, id feugiat dui gravida. Nullam ullamcorper quam turpis, ut condimentum ipsum sodales a. Suspendisse libero arcu, varius nec consequat eget, placerat sed velit. Curabitur gravida consectetur nunc, sagittis venenatis massa rutrum non. Etiam consequat porttitor pulvinar. Pellentesque at congue massa. Integer non sapien ut eros tempor scelerisque.

        Nunc bibendum tellus nec neque pellentesque auctor. Morbi non luctus turpis, vitae pellentesque nunc. Etiam quis maximus enim. Suspendisse convallis, ex sed congue egestas, mi purus fermentum augue, in pharetra sem orci auctor velit. Fusce imperdiet orci sit amet nisl tempus, eu tincidunt odio lacinia. In sollicitudin sem sit amet tellus rhoncus, sagittis pulvinar nibh laoreet. Aenean scelerisque aliquet libero vitae ullamcorper. Praesent pellentesque efficitur massa, ac feugiat sem. Nunc quis tortor diam. Sed facilisis lectus ex, quis dictum sapien pellentesque ut. Nullam suscipit ullamcorper ante, at tempor justo commodo sed. Maecenas eros ipsum, sodales vitae dui sit amet, porta pretium nulla.

        Integer porttitor turpis in sem volutpat laoreet. Ut leo nisl, dapibus a nunc sed, tempus rhoncus arcu. Vivamus laoreet, velit hendrerit iaculis condimentum, ligula turpis semper leo, vel dignissim nunc urna quis justo. Fusce dapibus quis elit et facilisis. Nam congue congue iaculis. Vivamus sed vehicula leo, quis placerat nunc. Proin sit amet nunc pellentesque, porttitor ante at, consequat ante. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus consectetur venenatis sapien at gravida. Sed molestie eu urna vel luctus. Etiam fermentum diam dictum faucibus rhoncus. Integer pharetra, orci et tristique convallis, orci leo pretium lacus, vel porta est nisl iaculis est. Nullam nisi augue, imperdiet nec egestas sed, placerat eu arcu. Phasellus non rutrum risus, a tempor mi. Integer eget est eget dolor semper fringilla nec in sem.

        Sed accumsan convallis nulla, dignissim blandit tellus ultrices at. Sed volutpat commodo libero, ut tincidunt libero. Phasellus eu libero magna. Donec facilisis pulvinar sapien non luctus. Morbi luctus fermentum quam, eget euismod neque sodales vel. Sed consectetur pulvinar tortor, quis maximus metus blandit eget. Nulla vulputate ex diam, tincidunt convallis nibh condimentum sed. Etiam lacinia urna maximus, molestie purus dictum, consectetur ipsum. Proin tempus interdum elementum.

        Phasellus varius velit in porta molestie. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse vehicula quam ligula, non mollis mi dignissim efficitur. Vivamus nec metus molestie, porta purus in, ullamcorper quam. Ut eget dignissim urna. Etiam lacinia et nulla nec ullamcorper. Cras in erat eget elit sollicitudin eleifend eget vitae eros. Nam scelerisque lacus vitae felis efficitur, blandit consectetur purus sodales. Praesent at sapien quis quam efficitur pharetra. Fusce fringilla ante ut nunc vulputate, ut scelerisque ligula bibendum. Etiam vel convallis lacus, ut finibus augue. Nulla facilisi. Integer mattis tellus vel augue malesuada tempor. Phasellus cursus enim ac massa semper varius. Nunc dapibus pellentesque nibh, sit amet sodales ligula tristique ac. Nullam bibendum sollicitudin purus quis hendrerit.

        Integer facilisis lorem consectetur, auctor turpis quis, eleifend felis. Ut mollis, mauris id convallis porta, urna metus blandit magna, non auctor tellus leo sit amet arcu. Proin tellus ligula, ullamcorper ut nisi quis, rhoncus varius dolor. Integer ultrices venenatis nibh, eget placerat ligula imperdiet non. Vestibulum tincidunt imperdiet dolor vitae ornare. Aenean in dignissim sapien. Quisque accumsan, dui eu sodales fermentum, justo mauris efficitur lectus, non porttitor ante nisi eu risus. In a metus pretium enim varius scelerisque eget quis nisl. Fusce ante sapien, aliquam sed dignissim sed, volutpat quis nisl. Aliquam massa ipsum, tincidunt in lacus vitae, fringilla sollicitudin tellus. Curabitur feugiat sem eget nisl convallis porttitor. Curabitur ac leo non ante porttitor pellentesque. Mauris et elit vel dui rhoncus congue.

        Sed rutrum augue quis ex condimentum scelerisque. Donec ut dolor dapibus, auctor quam vel, sollicitudin urna. Aenean eget justo feugiat, aliquam nisi ac, laoreet justo. Cras non nibh pharetra, rhoncus lacus eu, scelerisque nisl. Nulla vel nisl vel quam imperdiet scelerisque a vel enim. Aliquam imperdiet gravida lorem. Pellentesque molestie sed dui eu dignissim. Vivamus a eros at ante suscipit ornare. In commodo et erat eget bibendum. Quisque sodales rutrum urna. Phasellus eu tristique neque. Nulla molestie purus ut purus consectetur, vel fermentum justo pharetra.

    barra de rodapé, fixo no bottom da página, está OK

Dúvida com height em um DIV


Related Rates Ladder Problem

Question: The question is a ladder is 10 ft long and leans against a wall. The top of the ladder slides down at 3 m/s and the bottom slides away from the wall at 4 m/s. Find how high the top of the ladder is up the wall.
I know the general solution to these problems starts with using Pythagorean's theorem but I'm confused how I start this question when I'm not given x (distance from the wall). I've tried to re-arrange Pythagorean's theorem as follows:
<code>l^2 - x^2 = y^2
Plug into Pythagorean's theorem:
l^2 = x^2 + l^2 - x^2
</code>
But that doesn't get me anywhere. I know how to do implicit differientation, so could someone explain or give a hint as to how I find x?
Answer: Hint: from $x^2+y^2=10$ take implicit derivative and divide by 2, get
$$x\cdot x'+y \cdot y'=0.$$
You know $x'=4,\ y'=-3$ so you have $4x-3y=0$. Now solve this along with $x^2+y^2=10.$
Comment: Thank you, your explanation also makes a lot of sense. I guess I was sort of circling around it but didn't quite get it, although I now understand it!
Answer: Start with $l^2-x^2=y^2$ and do implicit differentiation. Note that $l$ isn't changing, so that gives you $$-2x\frac{dx}{dt}=2y\frac{dy}{dt}.\tag{1}$$ You also know from Pythagorean Theorem that $$x=\sqrt{l^2-y^2},$$ since $x$ is simply the horizontal distance from the wall to the bottom of the ladder, so we can rewrite $(1)$ in terms of $y$ and known quantities. After plugging in our values for $l$, $\frac{dx}{dt}$ and $\frac{dy}{dt}$, we then solve for $y.$ Don't forget that $\frac{dy}{dt}$ will be negative. (Why?)
Comment: Thank you so much, your explanation makes a lot of sense. dy/dt would be negative because the ladder is sliding down the wall at the calculated rate.
Answer: In addition to the two hints already given, check your units. I hope your calculus teacher doesn't assign problems with ladders in feet and speed in meters/second.
Comment: Oops, that was my fault when copying down the question, thank you for catching that!

Related Rates Ladder Problem


Melodic minor and the ii chord

Question: I am curious about the following.  If you look at the Melodic Minor scale (ascending) it is really just Dorian with a major 7th.
In Jazz we do not alter this mode when descending.  In classical music this mode is used in minor keys, e.g. A melodic minor in the key of A minor (to create leading tones when needed and the sharp 6th to turn the jump of a -3rd to a step).  In rhythm changes the vi chord is often changed to a dominant 7th, acting as a secondary dominant to the ii, e.g. I --> VI7 --> ii-7 --> V7, etc.  The major third of the VI7 created the "melodic minor" out of the Dorian on the ii chord.  So in soloing if one wanted to create a resolution from VI7 to ii-7 it would seem natural to augment the 7th degree of Dorian.  I do this to all the modes when I see a need or opportunity to do so but never really thought of a connection to other modes.
Over Rhythm changes I would improvise ii-Melodic minor over (VI7, ii-7) and I-Ionian over (V7, I).
My question is whether or not there is any historical connection between the "Jazz Melodic Minor" and this device.  Has anyone ever written about the Dorian sharp 7th?
Keep in mind that the corresponding altered Dorian mode based on the relative melodic minor in any key would NOT be this mode.  For example in the key of C, A melodic minor does not correspond to Dorian sharp 7th.
Comment: _Has anyone ever written about the Dorian sharp 7th_ - not really the correct term. The Melodic Minor is Aeolian with raised a 6th and 7th - that is its derivation. No reason to refer to it anything  as _Dorian sharp 7th_ .
Comment: Just a comment to help my understanding. First of all, for me it's much more natural to use harmonic minor (of II) over the VI7 chord because it has the b9 of the VI7 chord, which for my ears is a much  more common and pleasing tension in that context than the (unaltered) 9. Second, over the ii-7 chord, with melodic minor you would miss out on the b7 of the chord, but you replace it with the natural 7 (which is not a chord tone and which kinda clashes with the b7 in the chord). So is it just that I hear things differently, or did I misunderstand your question?
Comment: Could also regard the melodic minor (jazz) as simple major but with a m3 instead of the M3.
Comment: Related:  https://music.stackexchange.com/questions/16248/understanding-minor-key-harmony
Comment: @Dom, thanks but I just read that post and it doesn't really address the specific device I am mentioning.
Comment: @ggcc which is why it is related and not a dupe. Minor key harmony weaves in and out of a lot of different scales that post is for others who want to understand the basic of minor key harmony first.
Comment: I usually don't stick to just one mode to play over a change but I also don't change for each and every chord, trying to find Motifs that cover a pair, triplet or string of chords depending on the situation.  But that said I Melodic minor works over V7-->X-(7) progressions if used wisely.  So you miss the b7, you create a passing tone and can toggle back and forth in an idea.  I am curious about whether or not there is anything in music history about adding the leading tone to all minor modes other than natural minor, Dorian being the case here.
Comment: @MattL., here's a thought.  You don't have to stay on one mode for the entire duration of a chord.  Think of the ii as split in half.  Relative to the VI7 it is a one chord in ii minor, and rel to the V7 it is a ii rel to the key.  ii melodic minor accentuates the first device and offers a leading tone down to the b7, sound s bit like a be bop scale, then transition to straight Dorian after.  If you play the maj 7 over the -7 chord it still sounds good, creates a great dissonance that will eventually resolve.  keep in mind the ii is not the final end on the phrase.
Comment: Sure there is, in relation to creating a leading tone on the ii
Comment: Try Phrygian sharp 7.  It works.
Answer: A few historical tidbits on European music, since that seems to be partly what the question is after.
First, there's a lot of misunderstanding about modes and how they were used in medieval music.  Prior to the 16th century, the modes we call Dorian, Hypodorian, Phrygian, etc. were almost exclusively used to classify chant melodies which were monophonic, not polyphonic pieces of music that involved harmony.
It's a separate question to ask about the use of leading tones in polyphonic works.  And leading tones started to be used as accidentals (then called musica ficta) somewhere around the 12th century.  That is, when cadencing to D, one would often modify the voice that went C-D to instead be C♯-D.  When cadencing to G, one would use F♯-G.  When cadencing to A, one would use G♯-A.  These early experiments in two-voice counterpoint thus expanded the minor sixth to a major sixth near a cadence, thereby creating a stronger resolution outward to an octave.  (Cadences to C and F already had the built-in semitone motion.)
Phrygian was not modified in this way, as it would create an augmented sixth.  Instead, F was viewed as an upper leading tone of sorts, so Phrygian already had a built-in leading tone that resolved down F-E.
So, when the question asks whether Dorian mode historically exists with a sharp seventh -- well, yes, I suppose one could say it was used frequently in polyphonic music.  Any pieces that were based around a D center and did not make frequent use of the B♭ option (the only legitimate accidental in the scale at that time) could be seen as a sort of "Dorian #7," employing a C♯ at appropriate cadence points.
Note that these polyphonic works were not necessarily thought of as "in Dorian mode."  Until the mid-1500s the only reference to mode in polyphonic works was generally in classifying the mode of a chant melody that may have been used as the basis for the piece (often appearing in the tenor voice).
Some of that changed with the revival of interest in Greek theory and terminology in the 1500s.  Some composers began to try to write cycles of polyphonic works that were actually in various modes, including "Dorian."  And that's probably the place where one can find the closest approximation to the use of the "Dorian #7" scale, at least in its structure around cadences where the leading tone was necessary.  However, it's important to note that polyphonic works of the time assumed accidentals would be added as needed, including appropriate leading tones at cadences, so it was rare that one would encounter a piece only using the notes of the "Dorian #7" scale, even though that might have been the central note collection.
Furthermore, while the B♭ option since the earliest chant notations allowed the ♭6 we now associate with minor keys (and much later named "Aeolian mode"), the usage of the sixth scale degree was rather inconsistent well into the 18th century when our modern key system was finally standardized.  One can find plenty of examples of "Dorian" pieces with "Dorian" key signatures that employed the leading tone where appropriate.  In fact, it might be more accurate to think of the ♭6 until the early 18th century as an optional chromatic tone, added when appropriate to create a strong resolution down to scale degree 5, just as the leading tone was added as an accidental and raised to create a strong resolution upward.  The concept of the "minor mode" being centered around an Aeolian-type scale with the matching key signature was a rather late development.  So something like "Dorian #7" was a common historical option (if not almost a default) until key signature standardization settled the question another way.
As to whether there's any connection to the modern "jazz melodic minor" scale, I'd say only in the basic sense that the instability of the sixth scale degree stuck around even as minor mode practice developed in the classical and romantic periods.  Certainly plenty of classical pieces will also employ sequences such as those mentioned in the question (i.e., V7/ii-ii-V7-I).  Both the melodic and harmonic vocabulary were well-integrated into common practice style, so it's unsurprising that jazz developed its own variants of it.
Comment: There's a lot of incomplete and misleading information in introductory textbooks regarding historical modes and their use, so it's not surprising that people haven't happened upon this kind of thing.  It's only if you spend a lot of time with renaissance and medieval music (and its theory) that you tend to get a sense of how it all really worked.
Comment: @ggcg: I agree with you.  This sort of stuff used to be taught more in counterpoint classes, but that's fallen away in favor of the chordal approach.  A lot of mysteries of classical harmony can also be better understood just with a little thought about leading tones. For example, what's the strongest note in the scale after the tonic? Dominant (5). What's the most common secondary dominant? V/V, because it adds #4, the leading tone to 5. What's the most common modal mixture? Chords with b6, leading to 5. What's an augmented sixth chord? A chord with both upper and lower leading tones to 5.
Comment: thanks for the very thorough answer and connecting the idea to something historic in Western music.  I  wasn't after a concrete connection with the Jazz melodic minor, but that scale was the inspiration for the question.  I frequently use "leading tone" principles in improv, almost to the exclusion of all other ideas.  Despite having some classical education I admit I am not aware of the historical points you make.  Sometimes we rediscover old ideas from a different point of view.
Comment: For me, I started building melodies with leading tones both ascending and descending into scale tones, you sort of rediscover the bebop scale, blues, etc.  But I was not aware if such things were standard in the past.  This really is useful info.  I had only delved into Indian scales as an alternate approach.  I think it would help jazz students learn better than matching a diatonic mode to each chord.  Just my opinion.
Answer: As Stinkfoot mentioned, I've never seen in a music theory textbook or heard in my own listening a reference to the Dorian mode with a raised 7th.  Seems like it would self-evidently (since the major third is already in the chord) be useful in a solo as a leading tone, but in the Mark Levine books and in my general listening the altered chord with a #9 is more prominent.
Seems like it could be a cool groove though, messing with the listener by mixing in the raised 7th for a leading tone or the b7 for an altered funk sound.
Comment: I know it has not appeared in theory books, I am curious if it anything like it has an historical context.
Answer: Here is my 2 cents on this topic after some research (serendipitous research in a sense).  Perhaps nowhere in Western music is there such a thing as Dorian #7.  However, in Carnatic music there are modes that are equivalent to the Western modes with raised 7ths (more correctly, major 7ths).  To understand this better would require a deep excursion into Carnatic music which I will not go into except to state that Carnatic scales are built from a 12 tone chromatic scale by choosing 7 intervals between an octave with a few simple rules.  The unaltered scales must have a P5 in them but the choice of 2, 3, 4, 6, and 7 are open (as long as there are no repeats, e.g. #2 and b3).  That is to say you can have a scale with (1, b2, b3, #4, 5, b6, 7, 8) etc.  This leads to something like 72 distinct scales.  Modified scales have the P5 altered.
So, the scale I'm referring to does exist in some historical context other than melodic minor in the Western tradition.  However, it does not seem that the corresponding relation among modes the exists in the Western tradition is preserved in the Carnatic tradition.  There may be some relation as the scales are grouped together but for example Ionian and Dorian are both Carnatic scales but one would not refer to C Ionian and D Dorian as being related in the same key.
Leading tones do have meaning in Indian music but perhaps for different reasons.  Indian music is highly improvisational with melodic phrases from scales being used as motifs.  It is quite common for musicians to move up or down into a desired focus note by half steps.  That doesn't mean that large jumps are avoided at times but there seems to be a feeling of completeness that a leading tone provides that is not present using other intervals.  I state this from years of listening to Ragas and Carnatic music but could not cite a text as teaching this.  This style of music is not learnt the same way as Western music theory.  One thing that is NOT present in Indian music, at least not to the extent as Western music, is multi voice harmony.  Ragas are usually played against the background of a drone note or two (1 and 5).  There are no "changes".  There is no 7-->8 and 4-->3 like there is in Western music.  In some sense modern Carnatic music can seem a little more Western as guitar accompaniment is popular and there may be some progression or movement between a few chords, but there doesn't seem to be a strong tendency to focus on cadences as a main feature of the accompaniment.
So leading tones are used in melodic phrases to accentuate focus notes, but not in multi-voice harmony.  In the former sense a Dorian #7 or and Phygian #7 (also a Carnatic scale) has definite meaning.
Afterward:  Some of what I surmised here was derived from a few texts on Indian music I recently picked up in India.
Classical Music of India, a Practical Guide by Subramaniam and Subramanium
The Raga-ness of Ragas by Raja
It is by no means a substitute for a proper music education and I'm inferring a lot based on my Western education.  My view of what a leading tone means to Indian music is definitely ethnocentric but an honest attempt to explain the Dorian #7 and other such scales.

Melodic minor and the ii chord


Statistical test for comparing two frequencies with R

Question: i have this situation. A set of 5000 objects, 4950 blue and 50 green. From this set two people (person A and person B) fish separately 100 objects each and i would like to know if one of the two people has tricked me (not fishing blinded).

person A fished one set of 100 objects, 90 blue and 10 green.
person B fished one set of 100 objects, 99 blue and 1 green (that would be expected by chance)

Which test should i use? Could someone point me to a R example/solution about it?
Thanks in advance
Comment: Questions about choosing statistical tests are off topic for Stack Overflow. If you need statistical advice, you should ask your question at [stats.se] instead. Once you know the right test to use, you can probably easily google how to do that in R, but if you are still stuck, then you can ask a question like that here.
Comment: I agree that CV is the place to ask, but you should fix your typo about person B.
Answer: Edit: Fisher's exact is the wrong test, but a hypergeometric test is appropriate.
Following the answer to a similar question, you can test how "unlikely" either proportion is using Fisher's exact test or a hypergeometric test. From your question, you're interested in whether the proportion of blue:green for either person (90:10 person A, 99:1 person B) significantly differs from the true proportion (4950:50). In that case you have two contingency tables:
$$
\array{& \text{Blue} & \text{Green} \\\text{Person A} & 90 & 10 & 100\\\text{Truth} & 4950 & 50 & 5000 \\ & 5040 & 60}
$$
$$
\array{& \text{Blue} & \text{Green} \\\text{Person B} & 99 & 1 & 100\\\text{Truth} & 4950 & 50 & 5000 \\ & 5049 & 51}
$$
and you'd want to test both tables. Since the hypergeometric distribution models the probability of getting a certain number of draws without replacement, i.e. your situation, you can use phyper in R to run a hypergeometric test:
pA = phyper(10-1,50,4950,100, lower.tail=F)
pB = phyper(1-1,50,4950,100, lower.tail=F)

Which gives pA=3.4e-08 and pB=0.64. (The -1 in phyper(10-1,...) because we want the probability of getting greater than or equal to that number of green draws.)
So, by the logic of the hypergeometric test, Person A's basket of fish is highly unlikely to have occurred by chance, while person B's basket is totally reasonable.
Comment: For this question, the entire set is the population--it's not a sample and is not subject to any uncertainty.  It is of some interest to compare the Fisher test result to the hypergeometric probability of observing 10 or more green balls in the sample of 100.  `R`'s function `phyper(9, 50, 4950, 100, lower.tail=FALSE)` reports that as 3.4e-8, which is just one-fifth the Fisher Test p-value, showing that they do give different results. In this situation the answers will never be too far apart because the population is large; with smaller populations the answers can differ more.
Comment: @whuber Thank you for explaining. My (new) understanding is that Fisher's exact is not appropriate for comparing one sample to the population, but a hypergeometric test is. I'll edit my answer to use the hypergeometric test.
Comment: This is a good solution for the question you state--but I don't think it's the question that was asked.  We already know the contents of the set, so the issue isn't one of comparing the two samples, but only of comparing the 90-10 sample to the known contents of the set.
Comment: @whuber Isn't the question asking how to test whether 90:10 is likely to have been drawn from 4950:50, and similarly for 99:1? Doesn't Fisher's exact test that?
Comment: I don't see how Fisher's test applies to a *single* sample.  As @Vincent pointed out in his answer, the sample count of $10$ has approximately a Binomial distribution (it's really hypergeometric, but close enough) and that suffices for a full analysis of the result.  Where it gets interesting is in a different formulation, which (generalizing a bit) supposes there are $m$ independent samples from this set and asks which (if any) are inconsistent with the hypothesis that it is a simple random sample.  I don't see a direct application of Fisher's test to that interpretation, either.
Comment: @whuber I think I'm doing a two sample, but the set itself is the second sample. Is my error in using Fisher's exact to compare person A's sample (90:10) to the entire set (4950:50)?
Comment: @whuber Sorry to belabor the point, but I'm curious because using Fisher's exact here seems similar to gene set enrichment analyses, where a proportion in a subset of genes is compared to a proportion in the entire set of genes. e.g. https://www.biostars.org/p/110781/ I'd love to clear up my confusion. Happy to discuss this outside of comments.
Answer: The first idea that comes to mind would be to compute the likelihood of fishing each set of 100 objects, and using a threshold on this likelihood to detect cheaters.
If you know what cheaters would be inclined to do (for example, green objects are more desirable and they would boost their number of green objects fished), then you can look for that directly.
In the example you gave, it seems like you have a 0.01 probability of fishing a green object. This is a Bernoulli trial, and the distribution for the number of green objects in 100 trials follows a binomial distribution $X \sim B(100, 0.01)$. You can use the cumulative distribution function for the binomial distribution to determine at how many green objects you should start worrying (essentially, find the $x$ for which $P(X \geq x) < p$ where $p$ is how unlikely a result must be for it to be worrisome)
Answer: This answer was corrected according to the comment of phuber.
You need to use the hypergeometric distribution. In contrary to the binary distribution, the hypergeometric distribution is for drawing without replacement.
https://en.wikipedia.org/wiki/Hypergeometric_distribution
In R, the hypergeometric test of the hypergeometric distribution is implemented using phyper.
phyper(x, m, n, k)

x are the drawn green objects,
m are the total green objects in the set,
n are the total blue objects in the set,
k are the total number of objects drawn
With your numbers, this results in
pA = phyper(10-1,50,4950,100, lower.tail=F)
pB = phyper(1-1,50,4950,100, lower.tail=F)
The -1 in phyper(10-1,...) is there because we want the probability of getting greater than or equal to that number of green draws.
Comment: The hypergeometric distribution is the right idea, but its probability mass function is not a correct way to solve this problem.  See the other answers in this thread for correct approaches.
Comment: Thank you. I corrected the answer including the off by one error and named your contribution.


Rules: Load List of Entities by Object or Entity ID (Performance)

Question: I'm looking to load a list of Users by an Entity Reference Property within Rules. There may be times when I need to load hundreds or thousands of Users that have a matching Property to update a secondary Property. I'm having a difficult time determining the best performance option.
Here's my use case:
Users within our website may be linked to a Company (stored as a Node with Content-Type: company). When any user of this Company purchases membership, the company Node is updated with a Taxonomy Term Reference "Member." Then, every employee (read: User with entity reference to the same company node) of that organization needs to have a Taxonomy Reference field within their account updated to reflect they are a "Member (Corp)."
My Rules Based Solutions (that is executed when the order is first Paid In Full that sets the Data Value for that Property of the Company node, then...):
Solution A (Rules without VBO View):

Fetch all User Entities By Property: company, where company = Company node.
Loop through User list.
Check that Entity has Field: "Membership Status."
Set Data Value: "Membership Status" = "Member (Corp)."

Solution B (Rules with: Load a List of Entities from a VBO View):

Pass nid as parameter to view.
Loop through returned List.
Check that Entity has Field: "Membership Status."
Set Data Value: "Membership Status" = "Member (Corp)."

Solution C (Rules with: Load a List of Entity IDs from a VBO View):

Pass nid as parameter to view.
Loop through returned List.
Fetch User Entity by ID.
Check that Entity has Field: "Membership Status."
Set Data Value: "Membership Status" = "Member (Corp)."

I'm hesitant to load up every Entity that matches due to Performance implications; however, being fairly new to Drupal, I'm not sure the most efficient method to bulk update all of the affected Users.
Can you help me better understand the performance implications of these solutions? Perhaps, I'm missing a better option that I haven't considered? Thanks in advance for your help!
*This question is in reference to Drupal 7.
Answer: Using Solution A will pretty sure have performance implications, so I wouldn't recommend that approach "to load hundreds or thousands of Users". Below is a blueprint of yet another approach (another option that you could considered, up to you to decide if it is "better"), which will allow you to reduce the performance risk significantly ...
Step 1 - Refine your view
Adapt the VBO view you already have, by limiting the results of that view to the first X users only. Pick a value for X that fits your needs, to start make it small enough and increase later on as much as you feel comfortable with.
Also adapt the views filter, to no longer include the users that have been processed already (by the Rules Component described in the next steps).
Step 2 - Create a Rules Component
Create a custom Rules Component which performs the Rules Actions as in your Solution "B" or "C". If the value of X is small enough, you can do some experiments with either of these solutions (B or C), i.e. to find out what happens if you increase the value of X (and based on that decide for yourself which one works best). Note that the list to be processed is limited to "X users" only (i.e. those that are contained in your views results from the previous step).
Add an additional Rules Action in your Rules Component, to actually reschedule the execution of this Rules Component itself after a few seconds or minutes (whatever fits). And trigger the very first execution of this Rules Component via a custom rule that is triggered "When any user of a Company purchases membership" (as in your question, I bet you have some appropriate Rules Event for that).
Step 3 - Stop rescheduling the Rules Component when the time is right
Also add a Rules Condition in the Rules Component of the previous step, to "Check the number of results returned by a VBO view" (using the same VBO view). The actual number of results should be at least 1. If there are zero results, then the Rules Actions of this Rules Component will not be performed, which is what we want. Since it will also prevent the the rules component reschedules itself when all users have been processed.
Step 4 - Review the frequency of your cron jobs
Make sure your cron job runs frequent enough, because each execution of your scheduled Rules Component will actually only happen when cron runs.
Conclusion: because this approach is based on the Rules Scheduler, the elapsed time will be longer, for sure. But the advantage of it is that, as compared to any of your 3 solutions as in your question, the poor user "of the Company who purchased the membership", will not have to wait for the rule to complete execution, before being able to do anything else on the site.
PS: I'm assuming this is about D7 ...
Comment: Thanks @pierre.vriens.  I ended up marking your solution as correct since it actually addressed the question. Although, I ended up (explained in my answer) solving the issue by invoking a hook in a custom module on node_presave.
Comment: @ShaunO merci for the feedback!
Answer: I opted to use a custom module invoking node_hook_presave(), rather than Rules as I assumed it would be more efficient. This process checks if the "Membership Status" on the Company node has been changed prior to saving the Company.
/**
 * Implements hook_node_presave().
 */
function lia_company_node_presave($node){
    if($node->type=='company'){
        /**
         * If field_membership_status is set and the value has changed, then execute
         * the function  lia_company_update_membership_for_users($node->nid, $membership_status);
         */
        if(isset($node->original->field_membership_status[LANGUAGE_NONE][0]['tid'])
            && isset($node->field_membership_status[LANGUAGE_NONE][0]['tid'])
            && $node->original->field_membership_status[LANGUAGE_NONE][0]['tid'] <> $node->field_membership_status[LANGUAGE_NONE][0]['tid']) {

            $membership_status = $node->field_membership_status[LANGUAGE_NONE][0]['tid'];
            lia_company_update_membership_for_users($node->nid, $membership_status);
        }
    }
}

If the original value is set and the new value was not equal to the original value, I call a local method lia_company_update_membership_for_users($node->nid, $membership_status).
That method looks as follows. I'm thinking I probably should refactor this to run as a batch process. But any optimizations/feedback others find would be greatly appreciated.
/**
 * Implemented by hook_field_presave on Company node when field_membership_status is updated
 * on a Company node so that all of the Users referencing this Company are
 * updated to Member (Corp) or Non-Member, as appropriate.
 *
 * @param $company_nid
 * @param $membership_status_tid
 */
function lia_company_update_membership_for_users($company_nid, $membership_status_tid){
    $query = new EntityFieldQuery();
    $query
        ->entityCondition('entity_type', 'user')
        ->fieldCondition('field_company','target_id',$company_nid,'=');
    $results = $query->execute();

    $member_tid =  1744; // Taxonomy tid for Member
    $non_member_tid = 1749; // Taxonomy tid for Non-Member
    $member_corp_tid = 1745; // Taxonomy tid for Member (Corp)
    $member_status_excluded = array(
        1744, // Active
        1745, // Active (Corp)
        1748, // Deceased
        1746, // Deleted
    );

    foreach($results['user'] as $user){
        $user_wrapper = entity_metadata_wrapper('user',user_load($user->uid));

        /**
         * If the user is not already in an excluded membership_status, then we should update their status.
         * If the Company is being updated to a Member [TID: 1744] then, let's set all eligible Users to a
         * membership_status of Member (Corp) [TID: 1745]. Otherwise, we need to set them to Non-Member [TID: 1749].
         */
        if(isset($user_wrapper->field_membership_status) && !in_array($user_wrapper->field_membership_status->value()->tid, $member_status_excluded)){
            $user_wrapper->field_membership_status = ($membership_status_tid== $member_tid) ? $member_corp_tid : $non_member_tid;
            $user_wrapper->save();
        }
    }

}

Thank you @pierre.vriens for your answer. I'll probably end up refactoring when I have more time.


Removing an object from a list and the game?

Question: The problem I am having is that I have created a list with an object inside but when the player collides with the Object in question I can't remove it from the list.
//This is where the issue is
foreach (Objective seagull in seagulls)
{
    if (Objective.visable == false)
    {
        seagulls.Remove(seagull);
    }
}

EDIT: My problem now after changing to a for loop is that the remove does not work, I have no Idea what the remove function is asking me for ?
Comment: Please show your code and exception message as a text in question itself. People don't need to follow 3rd party sites to see your code.
Comment: you cannot modify a collection while looping through it with a `foreach`
Comment: Possible duplicate of [How to remove elements from a generic list while iterating over it?](http://stackoverflow.com/questions/1582285/how-to-remove-elements-from-a-generic-list-while-iterating-over-it)
Comment: Don't use `foreach`, use `for` with an inverse indexer and removed the last.
Comment: I can't there will be too much code?
Comment: And try to simplify the code as much as possible to fastly get where you are stuck. With the current source-code it may take much time to understand what you´re doing and where the actual problem is. Furthermore when you click on details within the debugger when showing the sexception, what do you get there? Is there a stacktrace?
Comment: See : http://stackoverflow.com/questions/604831/collection-was-modified-enumeration-operation-may-not-execute
Comment: Could you explain inverse indexer please?
Comment: We don't need your entire application, just the relevant code. Pastebin is blocked at my work (and the job I had before this) so I can't look at your code. No reason to post the exception as a screenshot either. Loop through it backwards; `for (int i = myList.Count - 1; i >= 0; i--) myList[i].Remove` or whatever it would be
Comment: Sorry, First time using Stack. Didn't know what was needed. And Thanks for the help everyone
Comment: @Adam take a look at the help section, in particular this: http://stackoverflow.com/help/how-to-ask
Comment: In the new `for` loop, you should [`RemoveAt`](https://msdn.microsoft.com/en-us/library/5cw9x18z(v=vs.110).aspx)
Comment: I have used RemoveAt(i), But the object is still there.
Answer: When using a for, you should use RemoveAt since it will reference your index.  Remove will expect a value to match, this is may be partially why your new for implementation doesn't work.

The reason you're receiving that error, is because you're enumerating through a collection that was modified.  If you utilize a for loop, instead of foreach you'll be able to iterate through while removing particular indexes.  Otherwise, you'll need to create a separate List, which is a copy of your List.  Remove it, then equal it to the other.
int total = example.Count;
List<Example> example;
for(int i = 0; i < total; i++)
     if(...)
     {
           example.RemoveAt(i);
     }

The conditional will be your check, before removing.  I'm not sure what that would be, but it would be similar to that.  I simplified code a bit for brevity sake.
Comment: Your example works, but just to clarify. If the object is removed from the list does that mean it stops excising therefor all the logic for that object stops working. Because allthough I am not getting any errors anymore the score continues to rise as if the object was there.
Comment: Here is the new code,  if (Player.playerBound.Intersects(Objective.objectiveBound))
            {
                Objective.visable = false;
                Player.score = Player.score + 10;
                for (int i = seagulls.Count - 1; i >= 0; i--)
                {
                    if (Objective.visable == false)
                    {
                        seagulls.RemoveAt(i);
                    }
                }

            }
Answer: Yo can put some flag like 'active' in your 'seagull' and then remove all
seagulls.removeall(c => c.active == false)