Copy string value into address

Question: I have the following class
class MyClass{
    char myValue[14] //has a 13 character string in it already
public
    void toStr(char* str) const;
}

The instruction is: The member function toStr is query that receives the address of a C-style, null-terminated string and fills that address with the object's value
This function assumes that the caller has allocated enough space to hold a thirteen (13) character string.
So I coded:
void myClass::toStr(char* str) const
{
std::strcpy(str, myValue);

}

However str is receiving the address of myValue and not the string itself. I did quite a bit of searching here and couldn't find anything similiar. I CANNOT use dynamic memory in this exercise.
Comment: Please post a full program that shows the error.  We don't know what's behind those variables such as str, or even myValue.
Comment: Don't describe -- actually show a small, but full example of this behavior.
Comment: Is anything set to myValue? If it's not null terminated strcpy will copy whatever garbage is in memory at myValues location until it hits a null terminator '\0'.
Comment: yes, I removed part of the code but myValue has a 13 character string in it
Comment: str is a pointer to an empty str
myValue has a 13 character string in it
Comment: oh, well that's a problem. str needs to be pre-allocated, at least as long as myValue.
Comment: I can't post the full program here of I get a ZERO for plagiarism
Comment: This function assumes that the caller has allocated enough space to hold a thirteen (13) character string. (for str)
Comment: What exactly do you mean by "str is receiving the address of myValue and not the string itself"?
Comment: So you can't just post a 5 or 6 line main() program that shows the error????
Comment: myValue has 1234567890123 but str is not receiving 1234567890123, it's receiving a 0x value, like the place in memory where 1234567890123 is
Comment: How exactly are you seeing that "it's receiving a 0x value"? Give us something we can see ourselves.
Comment: when I debug it I put a break after that function and check the value of str. it's not receiving the 1234567890123
Answer: Here is your class used in a simple example (this is all I wanted you to post, but for some reason you couldn't do it).
#include <cstring>
#include <iostream>

class MyClass
{
    char myValue[14];
    public:
        void toStr(char* str) const;
        MyClass() { std::strcpy(myValue, "0123456789012"); }
};

void MyClass::toStr(char* str) const
{ std::strcpy(str, myValue); }

int main()
{
    MyClass m;
    char testString[100];
    m.toStr(testString);
    std::cout << testString;
}

This function works as expected.  I see testString being assigned the myValue text.  I added a constructor to MyClass to ensure it is the same as you described, namely that myValue has a 13 character string before the call to toStr.
Now take that example I posted, and either
1) Change whatever you need to change to duplicate your error -- comments can come later as to why what you did doesn't work, or
2) point out what you missed in your code that you see in the example above, thus fixing your error.
There is no plagiarism here, since I have no idea what your assignment is really supposed to be -- this is purely written given your description.  See how easy it is just to provide a simple example?
Answer: In your assignment there is written that str can hold only 13 characters while myValue is defined as an array of 14 characters. So you should use std::strncpy instead of std::strcpyFor example
void myClass::toStr(char* str) const
{
    std::strncpy(str, myValue, 13);
    str[12] = '\0';
}

I think you get the weird result because myValue is not zero-terminated. If you are considering the both strings as some buffers of bytes then you should use function std::memcpy  In this case the function will look as
void myClass::toStr(char* str) const
{
    std::memcpy(str, myValue, 13);
}

I
Answer: We obviously need more information on this. But what I understood, your calling code should be as below:
MyClass a;
char *astr = new char[15]; //Allocate enough space for astr to hold myValue
a.toStr(astr);
cout << astr;
delete astr;

Also, value should be assigned in constructor or any other setter as below:
strcpy(myValue,"Test String");

Edit: As explained in another answer by Vlad, strncpy should be better.

This function assumes that the caller has allocated enough space to
  hold a thirteen (13) character string.

This means before calling your function, your string already allocated space (as I have done with new).
Looks like you mis-understood question.
Comment: Like I said, I cannot allocate dynamic memory for this exercise. But thanks anyway.
Comment: Then you need to allocate memory in function and copy to your passed pointer.
Comment: and how could I do that?
Comment: @PhillToronto, Actually your exercise assumes that str have memory allocated. See my original answer..
Answer: Try this! You dont need to bother about myValue array size.
void myClass::toStr(char* pstr) const
{
    std::string str(myValue);
    pstr = new char[str.size()+1];
    strcpy(pstr, str.c_str());
}

Comment: I cannot allocate dynamic memory in this exercise :(

Copy string value into address


R: Can I use percentages instead of counts in a chi-squared & pairwise test?

Question: I have count data with a corresponding time and place of each count, but my research question is about proportions. Is it valid to run a chi-squared test on percentages rather than count data? I'm also asking because I don't understand some of the results. For example, "Whipray" in 2016 (value of 43.75000) is "higher than expected value" (Residuals: 4.23 and statistically significant: 0.00027), but the next value (58.33) in 2017 is not higher than expected...just confused why a lower observed value would be significant and a higher observed value than the previous wouldn't be.
Contingency table of my data:
library(chisq.posthoc.test)
> table
                   Year
        Zone        2016 2017 2018
          Crocodile    0    8    2
          Rankin       3   17    8
          West         7   31   17
          Whipray      4    4    0

    Same data (as average % of total count):

> table2
                  Year
        Zone            2016     2017     2018
          Crocodile  0.00000 41.66700 28.57143
          Rankin    27.27273 33.92857 13.23656
          West      23.91304 42.64676 36.01179
          Whipray   43.75000 58.33333  0.00000

    > chisq.test(table2)

        Pearson's Chi-squared test

    data:  table
    X-squared = 76.958, df = 6, p-value = 1.516e-14

    > chisq.posthoc.test(table2, method = "bonferroni")

          Dimension     Value      2016       2017      2018
        1 Crocodile Residuals -5.727856  1.6457246  4.146400
        2 Crocodile  p values  0.000000  1.0000000  0.000405
        3    Rankin Residuals  2.068596 -0.9662472 -1.050602
        4    Rankin  p values  0.463008  1.0000000  1.000000
        5      West Residuals -1.046354 -2.1617513  3.716144
        6      West  p values  1.000000  0.3676480  0.002427
        7   Whipray Residuals  4.233146  1.5844252 -6.429553
        8   Whipray  p values  0.000277  1.0000000  0.000000

Comment: In many threads here on CV it has been pointed out that the answer is "no," because the variability in the numbers depends on the counts and that information is lost when working with proportions.  The meaning of the numbers in Table 2 is unclear, because they have little evident relationship with the counts.  Could you at least explain how `table2` is derived from `table`?
Comment: Ok, well, that's unfortunate. Thanks for the quick answer. 'Table' has the sum of all counts of fish with empty stomachs while 'Table2' are average %'s of fish with empty stomachs per batch out of all fish caught (per batch/catch/haul)
Comment: I re-did the analysis with the sum of counts of fish with empty stomachs (table) and the results still seem odd. Whipray in 2016 and 2017 have the same counts (count of 4), but only Whipray @ 2016 has a higher than expected value (and significant), while the other (2017) is not.
Comment: Whipray 2016 Residuals =  3.0827154, p-value = 0.0246150,
Whipray 2017 Residuals = -0.5645732, p-value = 1.0000000
Comment: Essentially a duplicate (answers to it are covered by many questions on site) e.g. 1 https://stats.stackexchange.com/questions/453095/r-same-dataset-different-units-and-then-chi-square-test-no-longer-works e.g. 2 https://stats.stackexchange.com/questions/398036/is-the-chi-square-test-of-independence-the-best-option-for-3x2-contingency-table/398043#398043 3. https://stats.stackexchange.com/questions/350717/do-i-use-chi-square-test-correctly-for-such-dataset
Comment: Thank you @Glen_b, I have some good answers below.
Comment: @Nate, in general, you can do a chi-squared test with percentages. It's called a goodness-of-fit test. With the R chisq.test function, you just specify p instead of y.
Comment: @Nate they were to establish that the question *should have been closed* not answered; If people have good answers they ought to post them on the most canonical thread rather than in yet another version  of essentially the same question. Pointing out duplicates is step 1 in closing and/or merging. Closure as duplicate (the correct action for this question) has been attained and the top of the post now links to other threads which will help later readers find more good answers (the purpose of the site). At this stage I'll leave it for the mods to consider whether they want to merge it as well.
Comment: Oh ok, no problem. "Closed" seemed like a very ambiguous word choice; I wasn't sure what it meant so to be on the safe side, I clicked no. As long as I can still view these answers again, I don't mind what happens beyond that.
Answer: Think about the percentages in each Zone within each year. Few or no cases are in Whipray for 2017 or 2018 relative to the total number of cases for those years. In contrast, more than 25% (4/14) are in that Zone for 2016. With a contingency table you need to think about proportions in both directions.
Comment: Aha! Got it, thank you!
Answer: Suppose you have the table of counts
shown below:
Cr  = c(0, 8, 2)
Ra  = c(3,17, 8)
We  = c(7,31,17)
Wh  = c(4, 4, 0)
TAB = cbind(Cr,Ra,We,Wh); TAB
     Cr Ra We Wh
[1,]  0  3  7  4
[2,]  8 17 31  4
[3,]  2  8 17  0

The low counts (in the first row and first column)
lead to some low expected counts in the chi-squared test, invalidating a chi-squared test of
homogeneity of counts across years.
See the warning message below:
chisq.test(TAB)

        Pearson's Chi-squared test

data:  TAB
X-squared = 12.804, df = 6, p-value = 0.04626

Warning message:
In chisq.test(TAB) :
 Chi-squared approximation may be incorrect

Specifically, the warning message appears because
some expected counts are smaller than $5.$
Some statisticians are willing to ignore the
warning if only a few expected counts are below $5$ and none are below $3,$ but you clearly
have a problem with low expected counts.
chisq.test(TAB)$exp
           Cr        Ra        We       Wh
[1,] 1.386139  3.881188  7.623762 1.108911
[2,] 5.940594 16.633663 32.673267 4.752475
[3,] 2.673267  7.485149 14.702970 2.138614
Warning message:
In chisq.test(TAB) :
 Chi-squared approximation may be incorrect

As implemented in R, one can simulate a more
accurate P-value for this test as shown below:
chisq.test(TAB, sim=T)

        Pearson's Chi-squared test
        with simulated p-value
        (based on 2000 replicates)

data:  TAB
X-squared = 12.804, df = NA, p-value = 0.03998

So, at the 5% significance level you can reject
the null hypothesis that proportions are
homogeneous across years.
You might investigate various scenarios ad hoc,
trying to isolate or explain the
the lack of homogeneity, and @EdM (+1) has
mentioned some things to look at. However,
after adjusting significance levels to avoid 'false discovery'
from repeated analyses of the same data,
you may not have enough power for a
successful detailed investigation.
Comment: Another great answer, thank you!


Mobile browsers window height & page scaling

Question: For wide pages with scaling where is starge behavior for mobile browsers:
$(window).height() (and document.documentElement.clientHeight) returns wrong heignt. Result is less when actually. The difference is about 10%
Simple test page:
<!DOCTYPE html>

  <meta charset="UTF-8">

      test block

page bottom

As result, the red box have height less then window height
All works well after removing of width: 1200px => Problem in page scaling (auto fit by page width).
How to get correct window height for page with scaling?
window.innerHeight return very funny result after zooming.
Tested on iphone (safari & chrome), ipad, android 4 (chrome). For Opera mobile the difference is bigger
Answer: To stop the page from scaling try adding the following tag to your head section.
<meta name="viewport" content="width=device-width, initial-scale=1.0">

You could get the width and scale it afterwards via JavaScript if you really have to (which you shouldn't - make it responsive instead).
Comment: no, for my site scaling is required. Its a big site and I can't make it responsive fast. The problem only in one feature and I want ot fix it


Problema na edição dos dados - AngularJS

Question: Tenho uma grid com os dados e também possui um botão de editar.
Problema:
Quando clico em alterar e começo a modificar os dados, lá na grid os dados estão sendo mudados também, mesmo sem ter salvado.
Minha função que carrega os dados é essa:
<code> /* Função que carrega na grid, TODOS os pacientes cadastrados */
 $scope.loadPacientes = function(){
    OdontoService.load('rest/paciente/loadPacientes').then(function (data) {
        $scope.pacientes = data.data;

        /* For para formatar a data no formato certo */
        for(var x = 0; x < $scope.pacientes.length; x++){
            $scope.pacientes[x].dataNascimento = new Date($scope.pacientes[x].dataNascimento);
        }

    },function (error){
        console.log(error);
    });
}
</code>
Queria que os dados só fossem alterados na grid, quando eu salvasse e não quando eu estou editando ainda.
Comment: Provavelmente isso acontece porque os dados na grid estão associados ao mesmo "model" tanto na edição quanto no grid, o que pode fazer é usar um modelo auxiliar somente para edição e atribuir o valor somente ao confirmar a edição.
Comment: @LucasCosta e é uma boa prática fazer isso?
Comment: sim @GuilhermeNass, se você quer esse comportamento não vejo outra alternativa, porque se uma variavel de escopo estiver sendo usada em *n* lugares, quando ela for alterada todos os lugares que estão exibindo ela serão alterados também, culpa do data binding :p
Comment: @LucasCosta Entendi cara, hehe. Muito obrigado pela ajuda!

Coloca teu comentário como resposta, para eu selecionar como resolvida.
Answer: Se a variável de escopo estiver sendo usada em mais de um lugar, caso modificada, mostrará a alteração onde ela estiver sendo aplicada na view, isso devido ao data binding que automaticamente sincroniza os dados entre o modelo e a view.
Para previnir essa situação no seu cenário, você pode criar um variável de escopo auxiliar e associar a edição.


Need a help in understanding theorem 6.1 in chapter 2 in Israel Gohberg.

Question: The theorem and its proof is given in the following pictures:

But I could not understand:
$Q_{1}$ the line after equation(1), why $f_{i}(x)$ is given by the indicated form for all i?, and why it is a bounded linear functional?
$Q_{2}$ why the representation of $K$ is not unique?
Could anyone explain this for me please?
Answer: $f_{i}(x)=\left<Kx,\varphi_{i}\right>$ is simply by definition. To see that it is bounded, we have $|f_{i}(x)|\leq\|Kx\|\|\varphi_{i}\|=\|Kx\|\leq\|K\|\|x\|$. Note that $K$ is bounded by assumption.
Comment: That is a shortcut, because he didn't want to write $\left$ everytime, and $\left$ as linear map of $x$, is bounded, hence Riesz applies.
Comment: For different set of orthonormal basis $\{\psi_{1},...,\psi_{n}\}$, the corresponding Riesz vectors $w_{i}$ are not equal to $v_{i}$, still, we have $Kx=\displaystyle\sum_{i=1}^{n}\leftw_{i}$.
Comment: Yes, sorry for that typo.
Comment: I think $i,j$ are mixed up?  They should all be $i$.
Comment: which definition ? the book did not mention any definition except what is given by Riesz representation theorem.
Comment: The author defined $f_{i}$ to be $f_{i}(x)=\left$.
Comment: why he defined it in this shape ?
Comment: I have added a question, could you please answer it ?
Comment: I think $\psi _{i}$ should be interchanged with $w_i$ in your last comment ....am I right?
Comment: Thank you for your so clear explanation :)


JFreeChart Null Pointer issue

Question: I'm just trying to run a demo of a 'simple' pie chart I found online. I'm running this in Eclipse Kepler and I keep getting,
Exception in thread "main" java.lang.NullPointerException
    at org.apache.fontbox.afm.AFMParser.main(AFMParser.java:304)

when I try to run the program. I would think, considering where I got the code (linked off of a JChart site), that it would run without issue. Just trying to see if anyone can see something I can't.
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

public class BarChartDemo {
    public static void main(String[] args){
        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("Category 1", 50.0);
        dataset.setValue("Category 2", 50.0);
        JFreeChart chart = ChartFactory.createPieChart(
            "Sample Pie Chart",
            dataset,
            true,
            true,
            false
            );

        ChartFrame frame = new ChartFrame("First",chart);
        frame.pack();
        frame.setVisible(true);
    }
}

Comment: Did you write the class AFMParser? I assume not, but that exception tells you the NullPointer is in line 304 in AFMParser, which would be pretty silly if it's published, finalized code.
Comment: No, I didn't think I had to do anything other than just test it out.
Comment: The best advice I can give right now is just to redownload the APIs. I know it seems ridiculous but if there's something wrong with THEIR code the only way I would fix it is that it might be corrupted. Otherwise, good luck I guess... sorry
Answer: I was able to get the chart to appear without changing your code. Did you include both jars (jfreechart, jcommons) in your build path?
Comment: Yeah, those are both in my path. I also tried to run another class (JFreeChart example) that was working on another computer, and it also fails to run giving me the same exception.
Comment: Weird. I found this about AFMParser: "This class is used to parse AFM(Adobe Font Metrics) documents". I'm not sure what this has to do with JFreeChart or anything in your example.
Answer: After some battling and researching (guessing), I came across this class via some Adobe Font Metrics googling. Incidentally I can't remember exactly where I found it, but it solved my issue. I'll spare the SO servers and not post the 1000(+)-line code, but here it is as a gist if anyone has the same problem. I just included it in my project source file as a separate class, and voila...
I'm still not sure why my project wouldn't run without this. It worked on other systems, but not my Eclipse Kepler (Mac OS 10.9). If anyone can tell me exactly why it kept failing, I'd be very thankful.

JFreeChart Null Pointer issue


In the quiz app, I want to add a Picture under each question

Question: I want to add a picture under each question. I am using Android studio.
String questions[] = {
    "Which method can be defined only once in a program?",
    "Which of these is not a bitwise operator?",
    "Which keyword is used by method to refer to the object that invoked it?"};
String answers[] = {"main method","<=","this"};
String opt[] = {
    "finalize method","main method","static method","private method",
    "&","&=","|=","<=",
    "import","this","catch","abstract"};

Can anyone please help?
Comment: Where can the user read/see those questions?
Answer: you can use Picasso to achieve that. Follow the setup instructions, then just add and edit this line:
Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(imageView);

imageView is your ImageView in your xml layout file.
Answer: I assume that your questions are output in TextView. in this case, you can get the text from TextView (tv1.getText().toString), and then compare the resulting value with each array element in the loop (tv1.getText.toString.equals(questions[n])), so you can set your own image for each text.


Como criar uma lista de Roles no Claim usando ASP.NET Core

Question: Fiz uma autenticação usando Claims com cookies no ASP.NET Core.
No Método abaixo, o objeto por parâmetro traz as informações de login e dentro dele tem uma lista chamada PerfisDeAcesso. Como faço para atribuir essa lista ao ClaimTypes.Role? Pergunto isso porque ele só aceita um único elemento do tipo string e minha lista tem mais de um elemento (do tipo string).
Não foi aceito um foreach dentro.
 private async Task<IActionResult> SignInAsync(Usuario usuario)
    {
        var claims = new List<Claim>
        {
            new Claim(ClaimTypes.NameIdentifier, usuario.CodUsuario),
            new Claim(ClaimTypes.Name, usuario.Login),
            new Claim(ClaimTypes.Role, /* lista com os perfis de acesso */)

        };

        var identity = new ClaimsIdentity(claims, "login");
        var principal = new ClaimsPrincipal(identity);

        await HttpContext.SignInAsync(principal);

        return RedirectToAction("Index", "Home");

    }

Answer: Você precisa adicionar individualmente, como uso o Authorize do próprio asp.net core faço assim, ele fica responsável em serializar isso internamente:
claims.AddRange(roles.Select(role => new Claim(ClaimTypes.Role, role)));


Como retirar a barra de título do app android VisualStudio C# Xamarin

Question:
Estou com dificuldade para retirar a barra de titulo do app que estou desenvolvendo, ja tentei pelo android studio e falhei miseravelmente assim como no visual studio, como não sou bom em java optei pelo visual que tenho mais afinidade. Como posso resolver esse problema ??
Comment: Testou a sugestão apresentada em minha resposta?
Answer: Segundo a resposta dada à mesma pergunta no SO EN
<code>NavigationPage.SetHasNavigationBar(this, false);
</code>
Fonte:
https://stackoverflow.com/questions/20480724/xamarin-remove-app-title


Criar um Elemento Div dinamicamente em JS puro e atribuir um Bg color aleatorio a ele

Question: Estou resolvendo um exercício que consiste em Gerar um divcom 100px X 100px e quando o usuário clicar em uma desses quadrados a cor do BG deve mudar para uma cor gerada aleatoriamente, consegui gerar a div quadrada, mais quando criou a function que muda o BG dela, mais ela não funcina
não sei se por conta do escopo ou algo assim.
segue o código:

/// FUNÇÃO QUE GERA UMA COR ALEATÓRIA
function getRandomColor() {
    let letters = "0123456789ABCDEF";
    let color = "#";
    for (var i = 0; i < 6; i++) {
        color += letters[Math.floor(Math.random() * 16)];
    }
    return color;
}

// VARIÁVEL QUE GUARDA A COR ALEATÓRIA
var newColor = getRandomColor();

// FNÇÃO QUE CRIA QUADROS NOVOS AO CLICAR NO BOTÃO

function addNewSquare(){
    let divElement = document.createElement('div')//
    divElement.setAttribute("onclick", "changeBg()")
    divElement.setAttribute("class","box")
    document.body.appendChild(divElement)

}
//FUNÇÃO PARA MUDAR A COR DE FUNCO DA DIV PARA UMA COR ALEATÓRIA
function changeBg() {
    divElement.style.background(color)
}
div{
    width: 100px;
    height: 100px;
    margin:20px ;
    border: 3px solid slateblue;
}
    <button onclick="addNewSquare()">Clique aqui</button>
Answer: Faltou pouco, exemplo:

/// FUNÇÃO QUE GERA UMA COR ALEATÓRIA
function getRandomColor() {
    let letters = "0123456789ABCDEF";
    let color = "#";
    for (var i = 0; i < 6; i++) {
        color += letters[Math.floor(Math.random() * 16)];
    }
    return color;
}

function addNewSquare(){
    let divElement = document.createElement('div')//
    divElement.setAttribute("onclick", "changeBg(this)")
    divElement.setAttribute("class","box")
    document.body.appendChild(divElement)

}
//FUNÇÃO PARA MUDAR A COR DE FUNCO DA DIV PARA UMA COR ALEATÓRIA
function changeBg(obj) {
    obj.style.background = getRandomColor();
}
div{
    width: 100px;
    height: 100px;
    margin:20px ;
    border: 3px solid slateblue;
}
 <button onclick="addNewSquare()">Clique aqui</button>

Foi adicionado o this na função do changeBg(this) pra saber qual elemento vai sofrer a alteração e na função foi chamado a outra função getRandomColor() para gerar sempre a nova cor.
Comment: Muito Obrigado!


Are the highest pitches always the easiest to hear in a musical texture?

Question: Are the highest pitches always the easiest to hear in a musical texture (all other factors, such as dynamic, timbre, articulation, etc. being equal)? Is this why melodic parts tend to be the highest part within a musical texture (or certainly higher)?
Presumably inner parts of a texture are always harder to hear; despite its obvious importance (in terms of perceiving harmony), is the bass part always as easy to hear as a melody part?
How is this affected by overall register? (For instance, if all parts are higher or lower.) Or by spacing? (If there is a greater distance between parts of a musical texture.)
If higher tones are easier to hear (within a musical texture or not) why is this?
Answer: Yes, some frequencies are easier to hear. We tend to be specially sensitive to frequencies around 2000 and 5000 hertz. The resonance of the ear canal and the transfer function of the ossicles of the middle ear cause of this phenomenon.
We see this measured in equal-loudness contour charts, a study first performed by Harvey Fletcher and Wilden A. Munson, which will be later known as the Fletcher–Munson curves. Other measurements have been performed since then, and some flaws were found in the Fletcher-Munson measurements. Current equal-loudness contour charts, when compared to the Fletcher-Munson curves, are very different in some ranges, specially in the lower half of the spectrum.

We can see that our sensitivity peaks at around 4kHz, so it'll be easier to hear frequencies from around that range. We also see that it's not the case of "the higher the easier", as the sensitivity will decrease as we go past 5kHz.
Another thing to notice is that as the sound intensity becomes higher, the differences become smaller. At low amplitudes the differences are much bigger than at higher amplitudes.
Comment: @BobBroadley If they all are so close together (that's around a one octave range) I feel like the note with less masked harmonics will be easier to hear, which would still be the highest one. I wanted to include that dynamic in my answer, but I can't find an article/study/paper about it, so I'm not sure if that idea is correct. I still feel like both are important in why the exposed high note is so important (and this last piece could also explain why the low exposed note is so important too).
Answer: In short: no.  Obviously, you don't hear bats.  But actually the main problem with your question is that you write "all other factors, such as dynamic, timbre, articulation, etc. being equal".  "dynamic" is a diffuse term usually implicating loudness, and similar loudness will be similarly noticeable.  "timbre" contains the composition from harmonics and that implies a set of frequencies.  It's not independent from pitch.
The usual fundamental frequency typically has several diminishing harmonics.  The bulk of the harmonics, even for the highest instruments being played, are within reasonably well-audible frequencies.  So the harmonics of high notes are nicely spread out and have the higher frequency ranges mostly to themselves.
That gives them an advantage.  There are lots of ways in which tones can be made to "cut through".  Accordions use "tremolo", several reeds slightly out of tune with each other.  The resulting beating is very regular and this very discernible even compared with similar (unsynchronized) notes.  Things like high-hats plaster over a large part of the high frequency spectrum with a common dynamic, again standing out as a unit.  Percussive instruments (this includes non-bowed string instruments) have common envelopes for their frequency imprint.  Singers and wind instruments have a characteristic spread of "formants" which are frequency envelopes not moving with the fundamental pitch itself.
So like in a pencil drawing which just consists of lines and actually pencil marks, there are lots of cues which help with piecing things together and offsetting them from other elements.  High pitches tend to be "well-lit" in the sound texture.  But for example the whine of a CRT tube or (these days more likely) a switching power supply, in spite of being high, is hard to discern because it has few audible harmonics and no detectable changes of volume.
Comment: Laptop switching power supplies tend to be much more audible than I'm happy with... not _acoustically_, but electrically, interfering with instruments plugged into an audio interface without galvanically separated ground.
Answer:
Are the highest pitches always the easiest to hear in a musical texture (all other factors, such as dynamic, timbre, articulation, etc. being equal)?

I guess when you put it that way, "all other factors", I would say the upper and lower voices are easiest to hear.
That said, there are a number of factors that I find to be very important whether a line in a texture is perceived as "salient" and that is rhythm and pitch content.
If the upper and lower voices are more slowly paced, and have the same rhythm then a faster paced inner voice will stand out, in particular when it has varied pitch content (as opposed to a repeated figure). Also, if the inner voice has a lot of dissonance and the outer voices use mostly consonants then the inner voice will also be distinguished by the use of dissonance.
However in many cases the upper line will also be more interesting in both rhythm and pitch content.

is the bass part always as easy to hear as a melody part?

If you put it this way, "always", then I would say no. It is very often the case that the lowest voice tends to move by leaps or at least larger leaps than the inner voices. That contributes a lot to how clearly you can hear it. If you would set up a texture where the lowest voice uses about the same contours as the inner voices, then it becomes less distinctive.
Another thing that often happens with the lowest voice is that there tends to be more space between the lowest voice and the lowest of the inner voices than between the inner voices themselves. This spacing also helps you to distinguish the lowest voice more clearly within the texture. So if the lowest voice is narrowly spaced then that will take away some of its prominence, possibly enough to allow an inner voice to be heard more clearly.
Comment: +1 Thanks for this RB, I anticipated mostly getting answers related to acoustics, which I think I will, so it is good to get a "compositional"(?) perspective, too.
Answer: I'm too lazy to look up references, but my understanding is that there appears to be a psychological phenomenon that amplitude and pitch are both factors of a sense of intensity. With two pitches at the same amplitude: the higher one will appear to cut through the lower. Pragmatically, a Bass will need a lot more air to compete for volume with a Soprano.
But it is my understanding that this is a psychological effect, not directly reducible to a physical explanation.
Comment: Fletcher-Munson effect: we're more sensitive mid-high (1k-10k Hz) frequencies of sound http://en.wikipedia.org/wiki/Equal-loudness_contour
Comment: Thanks, Dave! I was wondering when you'd chip in with an answer to this! Any chance you could put this in a full answer?
Comment: `But it is my understanding that this is a psychological effect, not directly reducible to a physical explanation.` It *is* physical effect, since it's caused by the resonance of the ear canal and the transfer function of the ossicles of the middle ear.
Comment: It is a physical stimulus of course, but a psychological response. The Fletcher-Munson measurements, and the subsequent refinements AFAICT are based on reports from human subjects. It can be correlated to physically measurable features of the stimulus, but the effect itself transpires *in the hearing* and not in the physics.
Answer: I don't know about 'easier to hear', within a well produced piece of audio, you should be able to hear everything.
Within a chord though, for example, I associate the highest note of a chord as the 'one that stands out'.
I have made two short quick examples of "Twinkle, Twinkle, Little Star" to demonstrate what I mean.  (I used the first online sequencer I could find, I'm really unfamiliar with it, I hope it works - I have a very basic setup so I hope they do.  If not, I'm sorry - perhaps a project for meta might be to get something we can embed more easily into questions and answers, like how chess.stackexchange.com have an embeddable game playback viewer).
The first example, the tune is played with chords where the highest note of each chord also belongs to the melody: http://onlinesequencer.net/20687 (midi version) - and this sounds about right.
The second example, the tune is played with chords where the lowest note of each chord plays the main melody: http://onlinesequencer.net/20693 (midi version) - which, to me, is barely recognisable, and more suitable as a harmony/accompaniment for the melody, for the left hand.
(Un)scientifically, I think two frequencies of the same sound (so, same instrument) with the same amplitude will vibrate the same amount of air, for a single sound wave length (possibly not the same because the thing that produces the lower frequency is vibrating more slowly).  A higher frequency sound has a shorter wavelength, so you would expect it to vibrate more air because it is moving at a faster rate.  Whether this is compatible with the mechanics of hearing, I don't know, but within the pitch-range of a musical instrument, the higher notes of chords appear to be heard more prominently.


EC2 Windows server recovery options if disconnected from domain

Question: So, I have these Windows 2016 servers. Everything is domain joined.
They are running in Amazon EC2.
I'm doing some system hardening, using recommendations from CIS. (For reference, the PDF is titled "CIS Microsoft Windows Server 2016 RTM (Release 1607) Benchmark" and can be downloaded here: https://www.cisecurity.org/benchmark/microsoft_windows_server/ )
There is one recommendation for hardening that seem to be a Bad Idea(TM) in EC2. That one is CIS section 22.214.171.124, Ensure 'Accounts: Administrator account status' is set to 'Disabled'
The concern I have with this is this paragraph from the same section in the CIS document:

Maintenance issues can arise under certain circumstances if you disable the Administrator account. For example, if the secure channel between a member computer and the domain controller fails in a domain environment for any reason and there is no other local Administrator account, you must restart in safe mode to fix the problem that broke the secure channel.

In EC2, you can't boot to safe mode. There's no physical console. The only recovery option available is "Directory Services Restore Mode" which isn't the same as Safe Mode.
I've taken other hardening steps to ensure the local Administrator is hardened.
What is a recommended the best practice here?
Answer: This is referring to the default admin account called Administrator. You will want to create a new local admin account that does not have the username "Administrator" and then you can safely disable the account named "Administrator." The spirit of CIS 184.108.40.206 is to remove this default account and create something unique to your company and not use the default username provided by the EC2 instance.
Comment: ok, this makes sense and is straightforward. thanks
Comment: yes. I created a new user in the admins group named "myadmin" and renamed the built-in admin to "builtin-admin" and disabled him.
Comment: you bet, and to further clarify your warning you referenced is that is you don't have any local admin you're out of luck if the instance can no longer talk to a DC, so just make sure you know that local admin login you created.
Comment: @JDS Did everything end up working out for you?


Are there general rules for playing a three-voice organ piece without pedals?

Question: I've been fixing up an old reed organ, and would love to play some of Bach's organ works on it; for example, I've had my eye on the chorale prelude Wachet auf, ruft uns die Stimme (BWV 645).
The problem is, these pieces were generally written for two hands plus a pedalboard, and this organ doesn't have a pedalboard (you need your feet to pump the bellows).
I know this means I won't be able to play the piece quite as Bach intended it. But there are plenty of keyboard instruments out there that don't have pedalboards. Are there good general rules for adapting a piece from three voices to two like this? Or will it take a good arranger to figure it out on a piece-by-piece or section-by-section basis?
P.S. Here's an excerpt from this particular piece, if it helps. It's marked canto firmo in Tenore, so presumably I shouldn't sacrifice the left hand part.
Comment: Hm; for this excerpt, at least, it seems possible to play treble and tenor both in the right hand; allowing small fudgings like the length of the Bb in the last bar
Answer: Definitely no general rules. Adapting three-part organ music for keyboard only is quite radical, as adaptations go, so you'll almost always have to compromise and opportunistically distribute voices just to get by.
That said, there are adaptations of most of Bach's organ music for pianists, see here: https://imslp.org/wiki/Special:ImagefromIndex/745234/qruu. (Of course, that particular adaptation assumes a grand piano and isn't quite suitable for a reed organ, but you can see how it's done.)
Answer: In this style of music you shouldn't plan to discard ANYTHING. It's a 3-part texture, we need to hear the three parts.  An occasional octave transposition would be acceptable.


Invalid Operation Exception - "Cross-thread operation not valid: Control 'TextBox1' accessed from a thread other than the thread it was created on."

Question:
"If necessity is the mother of
  invention, I'd like to kill the guy
  who invented this."
-Jimmy Buffet

I don't care if 100 people with a million reputation jump down my throat for saying this, but who ever thought of throwing this exception deserves a fate worse than death.
I have QUITE LITERALLY copied and pasted code from one project to another to populate standard data into a small set of text boxes.  In one application, the data is displayed perfectly.  The new one I'm working on now, throws this exception of course.
So here is my question - why would one throw it and the other not if the code is the same?  Is there a setting in the project settings?  Is there a property in the text box that prevents this?
I don't recall setting anything in the project to ignore this exception, but the code is EXACTLY THE SAME.
Comment: You pasted it into a non-UI thread.
Comment: You're going to need to show some code.
Comment: Probably should learn about threads and asynchronous programming before getting on your high horse and declaring something stupid.
Comment: Why don't you learn something about who you're talking to before blurting out insults?  I just don't feel that creating a delegate, checking for invoke required, invoking a multi-argument delegate, and then seeing the results is an efficient replacement for something that effectively is lock(mylock){string1=string2;}.
Answer: STAThread attribute set on the thread creating the controls?
Is the populating code called in the UI thread or not? Noone cares whether you did copy the code properly - if the call is on the wrong thread to start with.
Comment: Well, it does not have to be set. It should be on the Main method, and other wise set the any other thread's appartement to STA: thread.SetApartmentState(ApartmentState.STA);
Answer: I don't want to repeat the error message, but you are trying to modify a control from a thread different than th thread that control was created on.
Take a look at InvokeRequired and Invoke.


Hibernate não reconhece anotação das classes

Question: Tenho um projeto Maven, com Glassfish 4.0, Hibernate, estou utilizando anotações e meu projeto foi facetado com JPA o arquivo persistence.xml foi gerado e a connection pool do Glassfish está funcionado. no entando a seguinte mensagem é gerada pelo inspetor do Eclipse:
Class "com.financeiro.Pessoa" is managed, but is not listed in the persistence.xml file
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="Finaceiro" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>jdbc/MavenDB</jta-data-source>
        <properties>
            <property name="hibernate.transaction.jta.platform"
                value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform" />
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
        </properties>
    </persistence-unit>
</persistence>

pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.financeiro</groupId>
    <artifactId>Finaceiro</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.8.Final</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.8.Final</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.34</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

</project>

Como estou utilizando anotações é necessário mapear as classe no persistence.xml ou o erro gerado é por outro motivo ? Gostaria de saber se alguém tem a solução.
Answer: Você deve adicionar a classe com.financeiro.Pessoa no seu persistence.xml.
Coloque a seguinte linha antes da linha que contém <properties>:
<class>com.financeiro.Pessoa</class>

Uma alternativa, que não é suportada oficialmente pela especificação JPA, mas funciona no Hibernate, é adicionar a seguinte propriedade:
<property name="hibernate.archive.autodetection" value="class, hbm"/>

Comment: Perfeito o erro parou de ocorrer no entanto mesmo assim as tabelas do Banco de dados não estão sendo geradas
Comment: A propriedade *exclude-unlisted-classes* é da especificação JPA e faz o serviço.


Import date to Drupal

Question: I am receiving data from a third party company through XML.
I want to add this to my website as drupal nodes, having some information like title, body, summary, image,...
I am able to make a cron job that reads all the data from the XML & write it to a database.
Now I was wondering:

Can I write this to the database directly without creating any inconsistenties?
What tables do I have to write this to? only the node table and the field_data tables? Or do I also have to add it to field_revision tables etc? Am I forgetting any others?
Is there a module that's doing this? I tried the Feeds & the Migrate modules, but I can't seem to find anything to set up XML or SQL Data import on those. Either of the 2 is fine, whether it goes directly from the XML, or if I have to import it from SQL, cause then I can just add them to a temp table first.

Thank you very much
Comment: Please, be more concrete. For XML import via Feeds you can use [Feeds extensible parsers](https://www.drupal.org/project/feeds_ex) What does "inconsistenties" mean?
Comment: Well, I mean, if I would add new content to the database through a query, would drupal understand it? wouldn't there be other problems? like 2 nodes messing up eachother?

For example, lets say I have a node 1000 in drupal, I make one through an SQL import, with id 1001, would drupal make the next as 1002, or would it use 1001 again (max(id)+1 or is there a table that keeps the highest number)?

Or other possible problems like this
Comment: You can always look at drupal tables structure and see how it works.
Comment: where do I see that?
Or do you mean in the database? Cause that I checked, but that's my big question, if I forgot any.
Answer:
Can I write [the external data] to the database directly without creating any inconsistenties?

Hypothetically, yes. On a practical level, I'd avoid this approach like the plague. For example, in your next question, you ask…

What tables do I have to write this to? only the node table and the field_data tables? Or do I also have to add it to field_revision tables etc? Am I forgetting any others?

Thanks for the segue. Why not use Drupal's Feeds module to consume your data and let Drupal and Feeds manage the consumption process? This will ensure all the data modeling, processing, security and coding best practices inherited by the larger community. Why would you bypass all the work that's gone into this development?

Is there a module that's doing this? I tried the Feeds & the Migrate modules, but I can't seem to find anything to set up XML or SQL Data import on those. Either of the 2 is fine, whether it goes directly from the XML, or if I have to import it from SQL, cause then I can just add them to a temp table first.

As ar7Max indicates, you can use the Feeds and Feeds XPath Parser. It's stable, mature and has a large user base. We rely on this combination heavily (50+ sites, 100's of specific feeds imports) mostly without a hitch. The hitch tends to be poorly formed XML output which can break an import — again, this is rare and addressable at the source OR using Feeds Tamper. where you can rewrite the XML data as needed. If you wish, ask your XPath Parser specific questions here — once you understand it, it's trivial to manage.
Comment: Thank you very much.

however, I don't seem to understand the Feeds Module, I followed a tutorial to use this, and all I received were errors.
Comment: We can start a stackexchange chat and I'd be happy to troubleshoot this with you — if you'd like.

Import date to Drupal


Instantiate particular class based on object value

Question: I have classes for each payment mode for e.g. Cash, Cheque, Card. I have to pass object as a   parameter based on object value I have to instantiate a relevant class.
How can I achieve this? Suggest me a better design
public interface CollectionInfo {
    //Code Goes here
}

public class Cash implements CollectionInfo {
    //Code goes here
}

public class CollectionFactory {
    public void newInstance(Enum<CollectionMode> collectionMode) {
    }
}

public interface Receipts {
    public Receipt createReceipt(String Amount, /*(Here i need to pass parameter of object either cash ,Cheque or card),*/Date date);
}

Comment: Perhaps it is just me, but I am utterly confused by what you are asking. Maybe you should include code and/or pseudo-code of what is being attempted.
Comment: *"Regards
Vijay"*  Don't include sigs. in questions, they are noise.  Also, there is no need to add the major tag in the title.
Answer: You could pass an enumeration (Cash/Cheque/Card) into a factory ?
e.g.
Payment p = PaymentFactory.newInstance(PaymentMode.Cash);

and within that method you would do:
switch(mode) {
   case PaymentMode.Cash:
      return new CashPayment();

   // ...
}

where CashPayment, ChequePayment etc. are subclasses of Payment.
Comment: Or if you want to be hyper-dynamic, some naming convention and `Class.forName`. But the factory is probably the better way...
Comment: Yes. I didn't want to complicate matters too much
Comment: @BrianAgnew public interface CollectionInfo{

 //Code Goes here
}

public class Cash implements CollectionInfo
{
 //Code goes here
}

public class CollectionFactory {

 public void newInstance(Enum collectionMode) {

 }

}

public interface Receipts{

 public Receipt createReceipt(String Amount, /*(Here i need to pass parameter of object either cash ,Cheque or card),*/Date date);
}
Comment: @VijayM: To improve your question by adding details, use the "edit" link under the question (and the code formatting tools in the resulting editor).
Answer: You can look at the factory pattern:
http://en.wikipedia.org/wiki/Factory_method_pattern


For all n there exists n distinct integers whose sum is a perfect square and whose product is a perfect cube

Question: Show that for all $n$ we can find $n$ distinct natural numbers whose sum is a perfect square and whose product is a perfect cube?
$$a_1 + ... + a_n = m^2 \quad\text{ and }\quad a_1a_2...a_n=k^3$$
Answer: For any $n\in\mathbb{N}$
$\sum _{k=1}^n k^3=\left(\frac{1}{2} n (n+1)\right)^2$
For instance
$1+ 8+ 27+ 64+ 125+ 216+ 343+ 512=1296=34^2$
and $1\times  8\times  27\times  64\times  125\times  216\times  343\times  512=65\,548\,320\,768\,000=40320^3$


How does someone that uses fixed do solfeggio practice dictation?

Question: I have some experience with moveable do solfeggio and I've been experimenting with fixed do solfeggio recently as it seems to simplify the sight singing process since you don't have to account for modulations.  However, I feel completely lost when trying to dictate melodies using fixed do as there's essentially 12 ways to write down a melody by hearing it alone.
My questions is:  for anyone skilled in using fixed do and not moveable do.  How do you go about notating a melody when you don't have access to the note names?
Edit:
My process using moveable do:  I'll hear a melody either in my head or on a video and I attempt to notate it without seeing the score.  Since moveable do generally revolves around finding scale degree 1 and having everything relative to that, it's usually pretty straightforward to put the melody into context.  All I need to do is then find the first note and then it's simple to write down.
I can't really practice fixed do dictation because I automatically hear everything in moveable do.  My question is how does a person who hasn't practiced moveable do think about dictating a melody?  Do they just hear the intervals and memorize the relationships between each consecutive pair of intervals in sequence or do they recognize similar patterns like scale degrees 3-2-1 or 5-3-1 and choose some key and put everything into that context?  As an example if C-D-Eb is played would think "sounds like 1-2-flat 3, I'll call it Fi-Si-La or Te-Do-Ra"?
Comment: I'm a little confused; can you edit the question to clarify: How *have* you been doing dictation? Have you been writing down solfege syllables, or staff notation? And wait, when you say dictation, do you mean "Someone plays a melody, and as an ear-training exercise I try to write it down," or do you mean "I get someone else to write down my melody for me as I tell them the pitches"? Solfege and letter names could be helpful stepping stones in both processes, but they have the shortcoming of making it hard to specify which octave.
Comment: Modulations will need to be sorted, whichever system is used.
Comment: @AndyBonner I've updated the question.
Comment: You may find a few insights here: [Melodic Dictation Practice](https://music.stackexchange.com/q/108171/70803).
Answer: Wouldn't one establish a key initially, which would then give the appropriate sharps/flats? So in key D for example, C♯ would be 'do diese', and F♯ 'fa diese'. Or key F would automatically have 'si bemol' as the 'non-white' note.
Not knowing the note names won't be easy for anyone without AP., regardless of fixed or moveable do.
EDIT: just spoken at length to a friend who uses fixed do exclusively (finds it hard to cope with moveable do!) who agrees that the key is of paramount importance, and generally will dictate what each note will be named, according to that key. Even modulations will follow that pattern in a theoretical way (as in key C, F♯ will more likely be called fa diese rather than sol bemol).
Answer: Questions about "how do people think"/"how do people's brains work" are a bit tricky. But I'd suggest that most people do dictation in a few of the same ways, regardless of the terminology and tools they use.
One approach is to listen to relationships between notes. You might listen to hear intervallic contours (up a fourth, down a major second, up a minor third, etc.), or to hear the tonal functions of notes—this is what you've been doing with moveable-do solfege; hearing the "dominant" feeling of sol, the leading tone of ti, etc.
Another approach, for those with some degree of "absolute" or "perfect pitch" is simply to recognize the pitches themselves—to hear "That's an A, that's a C, that's a B flat," whether they refer to them by letter names or by fixed-do syllables. Letter names and fixed do are just two interchangeable systems for serving the same function. Arguments for using fixed do in ear training systems often revolve around a desire to build absolute pitch recognition.
In practice, even those who have enough pitch recognition to let them take advantage of the second approach will still use some of the first one. That is, even if you can recognize an A and a C, you'll probably "double check" your identification against an awareness of tonal function, even if that double-checking is subconscious. If you're in the key of G and you come to a cadence, you're pretty well defended against mistaking the final note for an F#.
One note: writing down a melody as a series of moveable-do syllables can be a very useful step in dictation, and it's often helpful to take dictation in multiple steps (I write down the pitches first without regard for note durations, then go back through and notate the rhythms). But ultimately, you'll want to also build your skills in translating this into standard staff notation, since that's a more efficient way of showing register (if do is C, is it middle C or an octave above? two below? etc.) and rhythm, not to mention chords or multiple voices.
Comment: Certainly agree that dictation using moveable do is far easier - but that's what I'm used to. My French friend disagrees whole-heartedly! But which octave? Isn't that a problem for each? Probably better to use those funny little dots on lines and spaces.
Comment: @Tim Yeah, that's the point I was trying to make. I edited a word to hopefully make that clearer. And I am *studiously* avoiding making any claims about the relative merits or usefulness of fixed vs moveable—though if you wanna step outside and get me off the record, I'LL BRING MY OWN SOAPBOX.


why different results with summary()and anova() function in linear mixed effect model

Question: I know that the question has been submitted several times but given my level of knowledge, I'm afraid I haven't been able to find a satisfactory answer.
I have two fixed effects :  frequency (high vs low) and predictability (high vs low).
my model is as follows :
m1=lmer(log(FF) ~ frequence * Predic + (1 | Sujet) + (1 | item), data= FreqPredicExpert72)

The anova function returns :

Type III Analysis of Variance Table with Satterthwaite's method
                  Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)
Predic           1.78800 1.78800     1 68.035 23.1208 8.774e-06 ***
frequence        0.78005 0.78005     1 68.155 10.0869  0.002243 **
Predic:frequence 0.16368 0.16368     1 67.894  2.1166  0.150321

The summary function returns :

Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: log(FF) ~ Predic * frequence + (1 | Sujet) + (1 | item)
   Data: FreqPredicExpert72
REML criterion at convergence: 558.9
Scaled residuals:
    Min      1Q  Median      3Q     Max
-3.6928 -0.5517 -0.0021  0.5770  4.3347
Random effects:
 Groups   Name        Variance Std.Dev.
 item     (Intercept) 0.002058 0.04536
 Sujet    (Intercept) 0.014550 0.12062
 Residual             0.077333 0.27809
Number of obs: 1580, groups:  item, 72; Sujet, 28
Fixed effects:
                     Estimate Std. Error       df t value Pr(>|t|)
(Intercept)           5.33733    0.02883 49.82410 185.118   <2e-16 ***
PredicHP             -0.05921    0.02490 67.27315  -2.378   0.0202 *
frequenceHF          -0.03042    0.02489 67.28622  -1.222   0.2260
PredicHP:frequenceHF -0.05133    0.03528 67.89410  -1.455   0.1503

Correlation of Fixed Effects:
            (Intr) PrdcHP frqnHF
PredicHP    -0.428
frequenceHF -0.429  0.497
PrdcHP:frHF  0.302 -0.705 -0.705

There is no difference concerning p value fonte interaction, but as on can see, anova returns a significant effect of frequency (p = 0.002243 ** ) while this effect is not significant in results with summary (p = 0.2260). For me it's a big problem.
My question is threefold
1) Why both p value of the interaction and  p value of the Predic effect are identical in summary() and in anova() function? And why it is not the case for the frequency effect?
2) In what outcome can we trust? (Anova or summary?). Pratically, effect of frequency amounted to 6 ms in the group of 21 adults. It seems unlikely that this effect is significant. So I will tend to rely on results from the summary() rather than anova()
3) What I have just described is part of my data. IN fact, I have three groups of participants (grade 3, grade 5 and Adults).
To analyse my data, I conducted a 3 way-anova : Group x frequency x Predic
The model used is as follows :
m1=lmer(log(FF) ~ Group * frequence * Predic + (1 | Sujet) + (1 | item), data= FreqPredicExpert72)

For this model, anova() and summary() returns very different results. If I understand correctly, it's because summary() function tests contrasts?
Is it possible to specify something so that summary function gives global effect for the Group x frequency x Predic interaction as in anova() function. Does this have anything to do with contrast specification?
Comment: i apologize for the the table which are not formatted correctly
Comment: Is there some reason you are using Type III Anova? And just how was Type III defined in this implementation? See [this question](https://stats.stackexchange.com/q/20452/28500) about these difficulties. Also, the order of entry of predictors into the model can matter in some Types of `anova()`. In the first model with "Type II!" Anova you entered `frequence * Predic ` but in the model reported by Summary it was in the order `Predic * frequency`. Check if that makes a difference for the `anova()` result. (Order shouldn't affect the Summary result.)
Comment: Thank you for the answer. I have no reason to use Type III Anova. Changing the order ( frequency * Predict or Predic* frequency) have no effect on p value in anova or in summary function. Using car::Anova(time.lm, type = 3) gives the Sams p values as the summary() function. Do you think that the use of summary is better than the use of anova given that car::Anova(time.lm, type = 3) and the Anova(m1, type=c("III"))  give same results as summary() function? Thank you.
Comment: Just to be clear: the first `anova()` function presented in your question was from the `lmerTest` package. Working on a single object produced by `lmer()`, does that function (with its default `type="III"` setting) give different results from `Anova()` (with a `type=3` setting) in the `car` package? Also, are your objects `time.lm` and `m1` the same? It would be best to clarify those issues by editing the question itself, to make it easier for others to find the information. Also, comments can sometimes be lost.
Comment: I'll try to be clear, the problem concerns the p value for the factor "frequence"  :
1) P value is significant (p<.001)when i use  anova(m1), anova(m1, type = 2) or car::Anova(m1)
2) P value becomes NOT significant ( p = 0.22) when i use Anova(m1, type=c("III")) or summary() function
So, what is the most likely outcome, given that inspection of the data shows a very limited effect of frequence.
Answer: This apparent discrepancy comes from the difficulty in interpreting "main effects" (e.g., the coefficient for frequence reported by summary(), or a Type III Anova test) when there is an interaction.
With the standard treatment coding default in R, the significance test for frequence reported by summary() in your interaction model will examine whether the coefficient is different from 0 when predictability is at its reference level. It looks like the reference levels for frequence and predictability are both set at "low" in your model. As a concrete example say that there is a significant interaction between the two predictors, with 0 influence of frequence on outcome when predictability is "low" but a large influence when predictability is "high".
Then the coefficient reported by summary() for frequence should be insignificant, with a coefficient of 0! That's because at the reference level of predictability there is no influence of frequence on outcome. That doesn't mean that frequence is unimportant. You would still have a large interaction coefficient involving it. And if you simply set the reference level for predictability to "high" then the coefficient reported by summary() for frequence would now be significantly different from 0.
So you have to be very circumspect when interpreting apparent "main effects" when predictors are included in interactions. As another example, just centering a continuous predictor can change the apparent "significance" of individual coefficients for all predictors interacting with it.
In your case there is an interaction coefficient (-0.05133) of magnitude similar to that of the "main effect" of predictability (-0.05921, for the case of "low" frequence), even though it didn't reach the magical threshold of 5% significance. The combination of the interaction term and the "main effect" of frequence (-0.03042) would estimate an effect of frequence at "high" predictability of -0.08175, which might well pass that threshold. Try switching the reference level of predictability and see for yourself.
This difficulty with interpreting the results of summary() will only be compounded in your final 3-way interaction model. The "main effects" for each predictor would be when both of the others are at their reference levels, however those were chosen.
Type III Anova can lead to similar difficulties in interpretation, as the significance of frequence will be assessed after the contributions of both predictability and the interaction between frequence and predictability are evaluated. So an "insignificant" effect of frequence doesn't mean it isn't important, just that its "main effect" is dwarfed in part by its interaction with predictability. As @gung puts it in this answer, there is an inherent problem with Type III Anova that can lead to false negative results:

If you sum the type III [sum of squares] SS in an ANOVA table, you will notice that they do not equal the total SS. In other words, this analysis must be wrong, but errs in a kind of epistemically conservative way.

Or, as the Warning in the manual page for the car Anova() function puts it:

Be careful of type-III tests.

In your particular case, one might argue that the lack of a statistically significant interaction term (at least in the 2-predictor model) could allow you to revert to a simple additive model. Then this problem would go away, although you should report that you first tested the interaction model.
What you presumably care most about is whether frequence is associated with outcome whether or not that association is primarily due to an interaction with predictability. With fixed-effect models the rms package in R handles this nicely by doing a Wald-type test of whether all of the coefficients (up to 2-way interactions) involving a predictor are 0, taking into account the covariances among the coefficient estimates. I don't work much with mixed models but there should be ways to do the same analysis for those. That might be how Anova() in car performs its Wald tests (as opposed to its default likelihood-ratio tests), but I'm not sure. You might also consider the emmeans package as a tool for evaluating effects of interest in mixed models with interaction terms.
What I'm still confused about is why the "Type III" test reported by anova() from the lmerTest package gave a significant coefficient for frequence while the other Type III tests didn't. But that's seems to be more a question of software implementation than a statistical issue.
Comment: Thank you very much for this detailed explanation. I think that I better understand my problem. As proposed, I will try to use emmeans package to evaluate in particular effect of frequency.  Many thanks again for your response.
Comment: @rach just remember that with interaction terms there is no single "effect of frequency." Its "effect" depends on the levels of all the other predictors interacting with it.
Comment: So as I understand it, if I'm interesting in the single "effect of frequency", I should test it in a model as m1=lmer(log(FF) ~ frequence + Predic + (1 | Sujet) + (1 | item), data= FreqPredicExpert72), where the interaction terms does not appears?
Comment: @rach yes, but if there is truly an interaction there is no "single effect of frequency." For example, in an observational study with a true interaction, the apparent "single effect of frequency" would depend on the relative number of cases having `Predic="low"` and `Predic="high"`. Those are the types of problems that `emmeans` can help with. In your particular case with an insignificant interaction term you could justify proceeding that way, but you might miss finding something important that further study could elucidate.
Comment: Ok @EDM, All this information is very formative and useful. In fact, I have several groups, some in which frequency x Predic interaction is significant, other not (I do this because I have initially a significant interaction between Groups, frequency and Predic). So, according to the p value of the interaction, I can or not focus on single/main effects. I will try to use emmeans function and post the outcome. Very pleased with your advice!
Comment: @rach in that case there certainly will be no "single effect of frequency." You need to display results for different combinations of Group, frequency, and predictability and gauge significance of differences between specific combinations of interest, as you should be able to with `emmeans`.
Comment: Dear @EDM, I apply emmeans, and effectively, each combinaison of the factors are compared, for example frequency (High F vs Low F) and Predic (High P vs Low P) lead to four comparisons. Than you again, you helped me clear up the problem, it allows me to better understand the different analyses to be considered according to hypotheses and results. Very happy!
Comment: @rach if your question has been answered then please mark this answer as accepted.
Comment: I'm just adding that when interaction is not significant and is remove from the model frequence + Predic  rather than frequence * Predic, anova() and summary return same p value for each factor.


How i can find point that Touching edges of tow circle?

Question: i have to circle with Different whidth and radius
so how i can make contact with this tow circle
and i know the center of each circle.
i have an image to explain what i need:

so i have the shape1 on the image
and i want to make it like shape 2
what is Formula i should use ?
thanks
Comment: It's hard to see what you mean with a lot of information missing. Could you elaborate?
Comment: what informaion u need?
Comment: It seems that one of the circles is fixed and the other one is to be moved along a fixed line to touch the first one. Do you mean this?
Answer: Based on what I understood, you want the two circles to be always tangent to each other.

I assumed the centers of the circles lie on some sort of a line, so I'll define them as:
$$f(x):=m x\\
g(x):=n x$$
But the centers can be arbitrarily anywhere. Now the centers must lie on either $\bigl(p,f(p)\bigr)$ or $\bigl(k,g(k)\bigr)$, with $r$ and $t$ as radii respectively. For two circles to meet at exactly one point, draw a line passing through the centers, then we just have to make sure the distance between the centers is equal to the sum of the radii, i.e.:
$$\sqrt{(f(k)-g(p))^2+(p-k)^2}=t+r$$
Solving, for example, for $p$, we find that:
$$\left\{p\to \frac{\sqrt{\left(n^2+1\right) (r+t)^2-k^2 (m-n)^2}+k m n+k}{n^2+1}\right\}\tag{1}$$
This means that given two circles lying on $f(x)$ and $g(x)$, with $t,r \in \Bbb R^+$, using $p$ in $(1)$ will always give us two circles tangent to each other for any $k$.
You can check this Desmos implementation to see what I mean.


How is set of points distanced $\leq r$ from set $S$ is called

Question: What is name of the notion described below.
Let S be any body (set of points) in Euclidian n-dimensional space.
Let H(S,r) be set of all points x that distance between x and y is <= r for some $y \in S$.
In other words, it is union all of spheres of radius r and centered in S.
What is name of this H(S,r) set.  Is it r-Neighborhood of S ?
Thanks
Answer: $r$-neighborhood is fine. See http://en.wikipedia.org/wiki/Neighbourhood_(mathematics)#In_a_metric_space.
Comment: Isn't that normally for the set of points strictly less than $r$? The OP is using $\leq r$.
Comment: @Jim, ok, *closed* $r$-neighborhood then :-) Thanks for pointing that out anyway.


Is it necessary for hamiltonian cycle to cover all the vertices of the graph??

Question: I have read the definition on wikipedia and it says:
In the mathematical field of graph theory, a Hamiltonian path (or traceable path) is a path in an   undirected or directed graph that visits each vertex exactly once. A Hamiltonian cycle (or Hamiltonian circuit) is a Hamiltonian path that is a cycle.
This definition does not say that this cycle should cover every vertex of the graph.
Till today I assumed that hamiltonian cycle should cover all the vertices But,today my teacher was reducing the hamiltonian cycle to Travelling salesman problem and he told that this condition is not necessary
Can Anyone please let me know the correct definition as well as any source of it's definition.
Comment: "visits each vertex exactly once" does mean it covers all vertices, and additionally that it visits each only once
Comment: It's right there in your quote: a Hamiltonian cycle is a Hamiltonian path, and a Hamiltonian path "visits each vertex exactly once." Perhaps you misunderstood your teacher.
Answer: Yes, of course. Otherwise it's just a cycle (or circuit, as some would prefer to say.) The definition you quote does include this.
Answer: Note that a Hamiltonian cycle is not a graph, it is a cycle (set of edges). Thus, a Hamiltonian cycle doesn't have any vertices, it may only visit them but not contain. Thus, "each vertex" here means each vertex of the graph which contains a Hamiltonian cycle.
So, yes, a Hamiltonian cycle of the graph G visits all of the vertices of G by definition.


Linear Algebra Solution set equal to Span

Question: I am confused on how to approach a certain question. It asks to find a collection of vectors $x_1,\ldots,x_p$ so that the solution set of equation $ax=0$ is equal to $\operatorname{span} \{x_1,\ldots x_p\}$
They give a matrix of what $A$ is. What I am doing at the moment is creating a augmented matrix with $A$ and zeros in the last column. After I row reduce the matrix, I get $x_2=-x_4$ and $x_3=0$. How can I get the solution set from my answer?
Answer: You're seeking a basis for the null space of $A$.  If I understand correctly, you've reached the reduced row echelon form augmented matrix:
$$
\left[\begin{array}{cccc|c}
0 & 1 & 0 & 1 & 0 \\
0 & 0 & 1 & 0 & 0 \\
\end{array}\right]
$$
(possibly with some extra rows of zeroes).  The solutions to this system of linear equations (i.e., the null space) has the form $$\mathrm{null}(A)=\{(\alpha,\beta,0,-\beta):\alpha,\beta \in K\}$$ (where $K$ is the underlying field).
We could alternatively write this $$\mathrm{null}(A)=\{\alpha(1,0,0,0)+\beta(0,1,0,-1):\alpha,\beta \in K\}$$ which should give you an idea of what's a good choice of basis for the null space.
Comment: could you please explain the null (a) I reached the echelon form you posted. I have x2=-x4 and x3=0. How did you get (1,0,0,0)+B(0,1,0,-1)?
Comment: There are two free variables: $x_1$ has no restrictions placed on it (so it is free), and $x_2$ can be considered free.  We know $x_3=0$, so it's not free, and $x_4$ is determined by $x_2$.  So, I set $x_1=\alpha$ and $x_2=\beta$.
Comment: Oh ok, so if there are no other extra rows with zeros. I can still   assume there are extra rows that have x1 and x2 free?
Comment: With or without additional rows of zeroes, the null space is the same.  It equivalent to adding the restriction $0=0$ (which makes no difference).  We must have $x_1$ free, since it's value does not affect whether or not $A \mathbf{x}=\mathbf{0}$.  We either have $x_2$ free (and $x_4$ is determined from it), or we can have $x_4$ free (and $x_2$ is determined from $x_4$).
Comment: ok so far I have x1=x1, x2=-x4, x3=0, x4=free. Shouldn't your vector with scalar B be (0,-1,0,1)?
Comment: That's essentially the same thing: we now have the arbitrary scalar replaced by its negative.
Answer: Could you specify, what $A$ is or write the row-reduced form of $A$? Then your question will be clearer. Given that you have got the row-reduced form, you are just a step away from getting the vectors $x_1,\ldots, x_p$ such that they span the solution space of $AX = 0$
Comment: my row reduced form is what Rebecca posted above


Repositório genérico com SQL

Question: Vendo essa pergunta: Aqui
Fiquei imaginando se é possível/certo usar um esquema igual esse em um projeto no qual não utilizo algum framework para conexão com banco.
Gostaria de um exemplo de qual a forma correta de ter uma camada DAL, no qual se comunique com SQL SERVER.
Preciso realmente ter um método para todas minhas interações com o banco?
Answer: Não é obrigatório utilizar uma camada somente para a interação com o banco de dados. Vai muito do projeto que você está desenvolvendo.
Por exemplo, se você está construindo uma aplicação simples, um To-Do List ou um projeto com pouquíssimas tabelas ou entidades, e você ou alguém com certeza não vá precisar incluir novas funcionalidades no futuro, não vejo que é necessário perder tempo com a camada de dados.
Por outro lado, se seu projeto tem potencial para crescer (incluir novas funcionalidades, alterações frequentes, entre outros) recomendo olhar com carinho, logo de início do projeto, em uma camada de repositórios para sua aplicação, justamente para isolar a lógica do negócio a implementação do banco. Isso trará muito mais facilidades para evoluir sua aplicação.
Answer: Sim, é possível.
Dei um exemplo de DAL genérica aqui. Na verdade a ideia é uma DAL que se parece muito com um repositório, visto que as operações básicas são geradas a partir da classe passada para a classe comum. Outras operações podem ser escritas em classes derivadas de Comum.
Entretanto, é importante dizer que este método é um tanto prolixo e te tomará algum tempo para escrever as operações que não são triviais (por exemplo, um select com join, e a montagem dos objetos para a camada que solicitou os dados). Ou ainda, no pior dos mundos, você pode trabalhar com o DataTable direto, o que é a pior abordagem possível.
Comment: @Felipe O exemplo que coloquei já define pra você 4 métodos por entidade, economizando você de ter que implementar seleção, inclusão, atualização e exclusão para cada entidade do seu projeto.
Comment: Para um projeto curto, o melhor é eu criar um método para cada operação, para cada table?

Repositório genérico com SQL


Question on compact sets in metric spaces

Question: Let $(X,d)$ be a metric space and consider on $X$ the topology induced by the metric $d$.
Let $\{x_n\}_{n\in \mathbb{N}}$ be e sequence of points in $X$. Is it true that if there exists $x\in X$ such that $d(x,x_n)\rightarrow \infty$ then $\{x_n\}_{n\in \mathbb{N}}$ can not be contained in any compact subset of $X$ (for the topology induced by $d$)?
The answer is yes if compact sets in $(X,d)$ must be bounded, but I don't know if it's true.
Answer: If $d(x,x_n)$ is unbounded, then $\{B(x, n): n \in \mathbb{N}\}$ is an open cover of $(X,d)$ without a finite subcover (A finite subcover would reduce to the largest radius ball and this misses many $x_n \in X$)
Answer: Yes, compact subsets of a metric space must be bounded. In fact, a metric space is compact if and only if it is complete and totally bounded, which is stronger than being bounded.
To see that boundedness is necessary, note that compactness and sequential compactness are the same for metric spaces. In an unbounded space you can construct a sequence $(x_n)$ such that $d(x_i, x_j) > 1$ for all $i \ne j$. Such a sequence cannot have a convergent subsequence.
Comment: An unbounded sequence can have a convergent subsequence. Take the sequence $(1, 1, 1, 2, 1, 3, 1, 4, 1, 5, \ldots)$, then take the subsequence of odd indexed terms. It's constantly one. But the even indexed terms clearly are unbounded.
Comment: You're right, I misspoke. Now fixed.


ZFS: How do you restore the correct number of copies after losing a drive?

Question: With zfs, if you have copies=2 and then you lose a drive containing some of those copies, how do you tell the system that it should make a new copy of the data blocks for the affected files?  Or does zfs just start adding data blocks for the extra copies as soon as it finds out about bad data blocks?
Will scrub do this?
(v0.6.0.56-rc8, ZFS pool version 28, ZFS filesystem version 5, Ubuntu 11.10)
Answer: I found this question really intriguing, and after spending an hour pouring over documentation, I dived into the code.  Here's what I found.
First, some terminology.  Ditto blocks (which are what these copies are, as opposed to mirrors) are automatically created on a write but may or may not be in the same virtual device (vdev) as the original copy.  On the other hand, mirrored blocks are always reflected onto another virtual device.
However, the code refers to both types of blocks as children.  You'll see here that ditto blocks are just children with io_vd == NULL (this is in the write function).  For a mirrored block, io_vd would be set to the corresponding virtual device (your second disk, for example).
With that in mind, when it gets to the read portion, it treats all children (be they mirror or ditto blocks) as potentially unsafe if it doesn't contain the expected good_copies, and rewrites them as needed.  So it sounds like the answer to your question is--yes, it will rewrite them when you have at least one good copy, and either of the following:

Unexpected errors when you tried to read the data,
You are resilvering, or
You are scrubbing.

Phew!  Maybe someone can point out flaws, but I enjoyed learning about ZFS through this little exercise, and I hope this helps!
Comment: @JamesMoore you can force the array online in a degraded state if you have the first 1MB of the device that failed. Presumably you just need the metadata from the failed device. I've tested this with a jbod-style zpool and it works : [recovering raidz broken labels](http://mail.opensolaris.org/pipermail/zfs-discuss/2012-June/051731.html). I did an md5sum before and after I broke the zpool, and only the copies=1 filesystem was broken after the import. The copies=2 and copies=3 filesystems matched up perfectly.
Comment: The problem is in @jlliagre's answer - the pool is dead if it loses any device.  The fact that the pool still has enough ditto blocks doesn't seem to matter.  Any way around that?
Answer: "copies=2" (or 3) is more designed to be used with pools with no redundancy (single disk or stripes). The goal is to be able to recover minor disk corruption, not a whole device failure. In the latter case, the pool is unmountable so no ditto blocks restoration can occur.
If you have redundancy (mirroring/raidz/raidz2/raidz3), the ditto blocks are not different than other ones and scrubbing/resilvering will recreate them.
Comment: @James Moore After a whole device failure, no ditto blocks will be written on that disk. There is no redundancy at the pool level so there is no way to replace the faulty disk by a new one. The only method to properly recover that situation would be to do a full backup of the pool, recreate it with healthy devices, and restore from backup while making sure no unintentional reboot occur before the first backup is done. Otherwise the pool might not be importable and its data lost. This is quite a burden compared to redundant pools where recovering a bad disk is done on-line and survives reboots.
Comment: Here is a reference: http://docs.oracle.com/cd/E19082-01/817-2271/gbbvf/index.html#6mhupg6rl `For a device to be replaced, the pool must be in the ONLINE state. The device must be part of a redundant configuration, or it must be healthy (in the ONLINE state).` I assume copies=2 or 3 is not considered to be a redundant configuration.
Comment: the "copies=N where N>1" feature is not intended to add redundancy. it is intended to resolve data corruption. everything written to zfs is checksummed or hashed. when it's read back, the checksum/hash is verified. if N=1, then a checksum/hash verification failure results in an error back to the app. if N>1, then one of the other copies can be consulted and used to repair all other copies.
Comment: @James Moore: I understand your point and you are correct stating that in there is enough data redundancy for a disk failure not to affect stored data. However, my understanding is you still have to care about redundancy at the pool level because the pool itself doesn't care about redundancy at the dataset level. With a striped pool, you can only replace healthy devices, i.e. reported as ONLINE. A faulty device, i.e. in UNAVAIL state, is not replaceable.
Comment: One thing to keep in mind, though, is that if you originally had `copies=1` and you've upped it to `copies=2`, then you'll probably want to resilver/rescrub afterwards--which will create these instances.  But @jilliagre is correct: ditto blocks do not constitute a redundant configuration.  There is NO guarantee that the blocks are set on another device, even if you have multiple devices in a pool.
Comment: "There is no redundancy at the pool level so there is no way to replace the faulty disk by a new one."  This doesn't seem relevant.  Why do I care about redundancy at the pool level?  copies=3 gives me redundancy at the file level.  It sure seems like replacing the failing disk + scrub gets back to a good state.
Comment: "With a striped pool, you can only replace healthy devices" - reference, please?  Nothing I see in the doc says that this is true.  What exactly am I missing?  And even if I am missing something that says I can't replace that drive - so what?  I care about data.  As long as there are multiple copies of the data, the right functionality is there.
Comment: OK, that's interesting.  I assumed the opposite: obivously copies=N is a redundant configuration, but now I suspect that you're right and I'm wrong.  Unfortunate that they don't also document that here: http://docs.oracle.com/cd/E19082-01/817-2271/gazgd/index.html
Comment: copies=N is definitely not a redundant configuration as far as the pool is concerned. This is what the zpool command checks. Even at the dataset level, there is no guarantee for ditto blocks to exist at all. For example, copies=N might have been set after some blocks have been written. These blocks have no copies.
Comment: Sure, but that's OK - I'd expect that status would just say that some files are lost.  (OK clearly meaning "we've got _something_ useful here", not "everything's fine").  Now I'm wondering why they even added the copies=N feature.
Comment: This directly conflicts with what @Redmumba says - and Redmumba provides links to code.  Can you cite some sources for what you're saying?  In particular, I'd love to see good citations for why you think copies=N isn't going to cope with whole device failure - that doesn't match with anything I've read.
Answer: @jlliagre and others who seem to think that the entire zpool dies if it one of the disks (vdevs) dies but the pool is not redundant (mirror/raidz). This is not true; a multi-disk pool will always survive a single complete disk failure even if it is not a mirror or raidz.
ZFS Metadata is always copied at least 2 times so total failure of a complete disk (or any portion of it) will not take down the file system. Furthermore, many files, especially smaller ones, will not be spread across all disks and will therefore not necessarily be faulted by the disk failure. The OP is asking about the case of a multi-disk pool using ditto blocks (user data copies > 1). Here, a single complete disk failure should never result in any data loss. ZFS will always try to put ditto blocks far away from the original block, and for pools with multiple vdevs, this always means on another vdev (an exception might be where one vdev is >50% of the pool, which would be very unusual). File system meta data is also always copied +1 or +2 times more than the ditto level, so it will always survive disk failure. Furthermore, if you have a pool more than three disks, you should be able to lose up to half of them without any data loss; ZFS stores the ditto blocks on the next disk over so as long as you never lose two adjacent disks, you never have data loss. (three adjecent disk failure for ditto=2).
When there are sufficient copies of data to access a file (whether those copies are from ditto blocks, mirror, or raidz), then all missing copies of data are repaired when the file is accessed. This is the purpose of the scrub; read all data and fix any that is bad by making use of redundant copies. So to answer the OP question directly, you just need to do a scrub after replacing the failed drive, and all copies will be restored.
As always, you can easily experiment with the concepts by creating pools whose vdevs for backing store are just ordinary sparse files. By deleting or corrupting the vdev files you can simulate any type of failure, and can verify integrity of the pool, file systems, and data along the way.
EDIT: after experimenting, it looks like zfs will fail the pool if a disk fails in a multi-disk non-redundant pool with copies>=2. Parital data corruption on one or more disks should remain survivable and should be fixed by a scrub.
Comment: The scary thing about those sorts of experiments is that they're great for telling me a setup will fail immediately or at least quickly.  They're not so great for telling me that a setup will fail occasionally.  In any case, it's not clear how you bring back a pool that has a failure; I tried setting up a pool like this with three sparse files and removing one of the sparse files seems to be fatal to the entire pool.  zpool replace won't replace the failed file, zpool scrub stalls at 5% (and these are very small pools), and the error page at http://illumos.org/msg/ZFS-8000-5E isn't optimistic.
Comment: I had a similar result to my experiements, done only after my answer. I normally only use raidz, and was answering based on information from what I believed to be credible sources (oracle blogs). I no longer believe that a multi-disk JBOD type pool, with copies >1 can survive a disk failure.


What is admin_devel module in drupal?

Question: THis module is separate from the devel module that gives ability to dpm() variables etc. What is it?
Answer: The admin_devel module actually comes with the admin_menu module.
It adds a debug function for javascript debugging (along the lines of dpm for php), which you can include and use.
It also adds a button you can press to rebuild system links, which is on the admin menu settings page.
This rebuilds menu item links that are handled by the drupal core system module.
Answer: admin_devel is part of Administration Menu and provides administration and debugging functionality for site builders. It's quite a small module; in Drupal 7 it only has a function to rebuild all system menu links. It isn't tied to Devel in any particular way.
Comment: Just to say, rooby's answer is more comprehensive - there is also a javascript debugging function :)
Comment: Mine was also first, but you can't win 'em all :)

What is admin_devel module in drupal?


Feature with Content Types is not reverted

Question: I am stuck watching the Feature state as Overriden. I tried different solutions as:

Disable and re-enable the feature
Restart apache to ensure the APC cache is cleared
Clear All caches from Drupal administration

But I get stcuk with the overriden state.
Doing a Diff within the Diff module, I see the following differences:

But if I check the current feature code the Line 732 doesn't seems to be the same as the Diff module is detecting.

So I don't understand where is the difference.
I do the revert of the feature, clear cache, ... several times, and the Feature is always on Overriden state.
Please, any idea to discover the reason why I can't do the revert and a solution to perform the revert?
Answer: Please check whether there are two copies mistakenly placed inside drupal modules. Just recreate the feature with a new name and a version number. Download new feature then disable current feature and remove module completely from source. Then make sure the feature is completely removed and not appearing in the module list. Then add new feature and see.
Comment: Hi, I appreciate your suggestion, but I would like to find the way to do it without recreating, what I had already into account but I wanted to skip it. Mainly to have a better understanding of the reason. This is a kind of "format windows" solution ... lol. Anyway, since I have had to do other stuffs and I have had to recreate the whole DB, now the state is correct.


how to determine the available physical memory in linux

Question: I'm trying to figure if my software running on linux suffers from memory leak. I've tried to measure the available physical memory as found in /proc/meminfo (see below) but could understand which field(s) represents the available memory and what is the relation between MemFree, Cached, Buffers, Active, Inactive.
cat /proc/meminfo
MemTotal:       124128 kB
MemFree:         62872 kB
Buffers:             0 kB
Cached:          15624 kB
SwapCached:          0 kB
Active:          38724 kB
Inactive:        11148 kB
SwapTotal:           0 kB
SwapFree:            0 kB
Dirty:               0 kB
Writeback:           0 kB
AnonPages:       34272 kB
Mapped:          14640 kB
Slab:             5564 kB
SReclaimable:      424 kB
SUnreclaim:       5140 kB
PageTables:        504 kB
NFS_Unstable:        0 kB
Bounce:              0 kB
WritebackTmp:        0 kB
CommitLimit:     62064 kB
Committed_AS:    57936 kB
VmallocTotal:   655360 kB
VmallocUsed:      1016 kB
VmallocChunk:   654328 kB

Answer: This is simpler command to check memory usage:
free

Comment: `free -m` to display in MB
Answer: /proc/meminfo is for overall system memory information.  /proc/[pid]/status has the memory usage info for an individual process.  (it's also in /proc/[pid]/stat in a more machine parseable format).
In particular, VmData (size of data segment) and VmStk (size of stack segments) are most likely of use to you.  Or just use ps or top instead of trying to read the data directly yourself.
The other numbers are likely to just be confusing, because the overall system memory usage is complicated by shared memory, various kinds of buffers, etc.
Answer: If you're looking for memory leaks, use Valgrind.
For a quick check of your application's memory use, use getrusage() (requires a recent linux kernel) and look at the ru_maxrss value. /proc/meminfo gives information about the system as a whole.
Answer: If you're looking to see if your software has a memory leak, look at either 'ps' or 'top' to look at your program.  See if the virtual size (VSS) increases over time.
To debug such memory issues, use Valgrind or (my personal favorite) dmalloc.
Answer: Your question is asking something different, but since this is the #2 Google
hit for "linux physical memory"—
Newer kernel versions running on x86 have DirectMap4k, DirectMap2M, and
potentially DirectMap4M and DirectMap1G fields at the end of
/proc/meminfo. Adding them up and multiplying by 1024 seems to give the
number of bytes of physical RAM.


Deleted a Block type LUN on Synology - is this recoverable?

Question: Following some poor doco - a block type LUN on our company Synology was accidentally deleted with some business critical data on it. This LUN wasnt replicated anywhere or backed up. Is it possible to recover the data that was lost? Can this be done by SSHing into the NAS and working with the CLI?
I've submited a ticket to Synology and highlighted the issue, however being Australian we have to wait for their working hours to get any info back. Over the phone to them - I did hear that within the Storage Manager, under Volume, I can perform some action under the "Manage" option, however the Manage field is greyed out for me.
Part 2 of my question is: Is there a way I can find ou why this button is greyed out, so that i can investigate any options within that area for recovering my deleted LUN.
Any help would be severely appreciated.
Cheers,
Leon
Comment: +1 for eeaa ....... we know it's not help itself it's just path to follow, and since it was block type lun then no free/trial software available on market will be able to help you out. Just from curiosity what model of synology is it? cause i'm pretty sure that high-ends one are making mirroring without raid.
Comment: Thanks for the reply,
Synology model was: RS3614xs+
We'ev got the machine off and have since found some of our data that's 6+ months old. Would still be nice to chase up this current data if possible.
Comment: did you had encryption on?
Answer: No backups? Your option now is to shut the NAS down now, remove all of the disks, perform a block copy of all of them to another set of disks, and then send them to a place like Kroll Ontrack for recovery.
Warning, though: it will be expensive, and the data they recover may not be all-inclusive of what was on the deleted LUN.