Apache service hung and incoming requests not accepted

Question: My production server is running Apache v2.2.4 with mod_mono v1.2.4 on CentOS release 5.2 (Final).
Suddenly, Apache service hung during normal usage time (approx. 1 pm EDT). Traffic is not too high at this time.  This is the first time we're noticing this kind of behaviour in our server.  I noticed from access log that even subsequent requests are also not received, even though there were incoming requests.  I then manually tried to invoke my application call from web browser, it never returned successfully but it was still loading.
I found no unusual behaviour/activity in:
1) Apache access_log and error_log
2) No kernel level errors found in /var/log/messages
I've no other option but ended up restarting Apache service.
Any idea on what would cause Apache to hang and thereby not allowing subsequent incoming requests?  How do I debug/diagnose when this happens next time?
Experts advice/recommendation on this are highly appreciated.
Answer: I have encountered this when there is a block on IO in the kernel. Is the Apache perhaps serving data from an NFS mount or something similar that can fail hard?
Comment: In my case, I don't think this is a block in IO. Regarding serving of data, my Apache is serving data from within my server drive which is attached permanently, and this is not a NFS mount.


Is it OK to have only a single class labels in test data for prediction with one-class-svm?

Question: I have a data which has only a single class, namely, '0'. There is no 'not 0' class.
The one-class SVM model was trained on a train dataset containing only a single class '0'. I do not unnecessarily want to find a random 'not 0' class to include in test dataset for prediction.
What will be the output of this approach?
How can we interpret the result?
What if the specificity is 0? Is it normal or have sensitivity and specificity to be 0?
In that case how do we plot ROC curve?
After training it only on '0' class, I tested it on only '0' class (unseen and unlabeled data), and the model still gave '-1' for a few samples. Why did not it give all '1'?
I will appreciate an example on an arbitrary data.
Comment: The one-class SVM model was trained on a ```train``` dataset containing only a single class ```'0'.``` Congratulations! You've trained a model that says 0 all the time!
Comment: If you have only a single class, what is your goal in modeling or classifying?
Comment: @StephanKolassa My goal is to identify (classify) '0' class I have.
Answer: If your entire data only has the "0" class, then life is easy: just classify everything as "0". Any tool or method will do so, too. (If a method, upon seeing only "0" instances, classifies something as "rhubarb", I would question its sanity.)
If you classify everything as "0", and everything is in fact "0", then every instance is a true positive. There are no false positives, true or false negatives. Sensitivity is $\frac{n}{n}=1$, specifity is undefined, $\frac{0}{0}$.
As to the ROC curve: there is no threshold to tune, the FPR is constant at zero, the TPR is constant at one, and your ROC curve degenerates to a point in the top left hand corner. AUROC is 1.
And to be honest, everything is maximally useless. If you already know everything is of just one class, why bother modeling?
Comment: So what is the correct way to make sense? I guess, train on '0' class, and test on '0' plus 'not 0' class? Can you present an example?
Comment: Do you know if there exist anomaly/novelty/outlier detection method which works directly on images and not on image descriptors?
Comment: By the way after training it only on '0' class,  I tested it on only '0' class (unseen and unlabeled data), and the model still gave '-1' for a few samples. Why did not it give all '1'?


How to send HTTP request using urllib2 with proxy

Question: I want to send HTTP request using urllib2 with proxy. The proxy will be in the database and each time send HTTP request sent by getting the proxy IP from table.
Thank You.
Answer: I think this is the syntax youre looking for:
proxy = urllib2.ProxyHandler({'http': '18.104.22.168'})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
urllib2.urlopen('http://www.google.com/search')

Alternatively in Python 2.7 requests library you can do:
requests.request(
        method="GET",
        url='https://www.google.com/search',
        params= params,
        headers=headers,
        proxies =  proxy)

Where each input is an object with key value pairs
Comment: But I need to get proxy from a database table.
Comment: So then its as simple as performing a database query for your proxy and  plugging that in to the above code. What exactly are you having trouble with?
Comment: Without taking a look at your database its impossible for someone to provide you with the query syntax..
Comment: You should query the database for the proxy IP, then pass it into ProxyHandler. What do you mean you cant 'append' the IP to the request. What type of error are you getting and when?
Comment: Thank You, I was not passing the right column of the table in proxyhandler.


Erro ''stack smashing detected'', porém não acho onde excedi a matriz

Question: Após pesquisar sobre o erro, achei que tem alguma coisa relacionada a exceder os limites de
uma matriz. porém não encontrei onde ele possa estar em meu código. Bem o código roda como deveria rodar, pode não estar escrito do melhor modo, mas faz o que o enunciado pede. Se poderem me ajudar a descobrir o por quê desse erro, ficarei grato. Obrigado.
/*10) Usando a estrutura "atleta", do exercício anterior, escreva um programa que leia
os dados de 5 atletas e os exiba por ordem de idade, do mais velho para o mais novo.*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct dados{
    char nome[50];
    char esporte[50];
    int idade;
    float altura;
}atleta;

int main(){
    atleta info[6];
    char aux[50];
    int i, j;

    for(i = 0; i < 5; i++){
        printf(".....DADOS DO ATLETA.....\n");
        printf("NOME\t\t");
        fgets(info[i].nome, sizeof(info[i].nome), stdin);
        printf("ESPORTE\t\t");
        fgets(info[i].esporte, sizeof(info[i].esporte), stdin);
        printf("IDADE\t\t");
        fgets(aux, sizeof(aux), stdin);
        info[i].idade = atoi(aux);
        printf("ALTURA\t\t");
        fgets(aux, sizeof(aux), stdin);
        info[i].altura = atoi(aux);
    }
    for(i = 0; i < 4; i++){
        for(j = i+1; j < 5; j++){
            if(info[i].idade < info[j].idade){
                info[6] = info[i];
                info[i] = info[j];
                info[j] = info[6];
            }
        }
    }

    printf("...ORDEM DECRESCENTE POR IDADE...\n");
    for(i = 0; i < 5; i++){
        printf("NOME:\t\t\t%s",info[i].nome);
    }
    return 0;
}

Comment: Não pode acessar `info[6]` se `info` é `atleta[6]`, certo? apenas de 0 a 5 existem. Entenda que seu programa trata uma equipe mas só tem atleta. Seria muito mais simples se tivesse uma `struct` com a equipe
Comment: Eu mudei info[6] para info[5] e mesmo assim aparece o erro. Eu ainda estou aprendendo e estou tendo um pouco de dificuldade.
Comment: Esqueça o que eu disse, fucei aqui e ajeitei. Obrigado pela ajuda, deu certo. funcionou como deveria e sem o erro. Ainda estou aprendendo, por isso não peguei o jeito de como me organizar usando o struct, mas logo eu aprendo.
Answer: Escreva em torno dos dados
Seus dados são 1 time e o time tem atletas. Considere algo assim
typedef struct
{
    char  nome[50];
    char  esporte[50];
    int   idade;
    float altura;
} Atleta;

sua estrutura de Atleta pode ser anônima. Não precisa do nome dados como no programa original. Há uma convenção de reservar alguma propriedade para os nomes que você define, como por exemplo usar a primeira letra em maiúscula apenas nesses casos: Atleta então.
E o time? Podia ser
typedef struct
{
    unsigned limite;
    unsigned tam;
    Atleta   atl[10];
} Time;

Algo assim é mais conveniente: cada time tem um vetor para 10 atletas. o Limite então é 10 e o tamanho vai claro de 0 a 10. Assim é mais fácil controlar um time ou 200 times no programa, porque esses valores estão dentro da estrutura. É o princípio de encapsulamento.
Algo assim
    Time tm = {.limite = 10, .tam = 0};

declara um time vazio com capacidade para 10 caras
Exemplo
int main(void)
{
    char linha[80];
    Time tm = {.limite = 10, .tam = 0};

    for (int i = 0; i < 5; i++)
    {
        printf("\nDados do atleta %d...\n", i);
        printf("Nome:\t\t");
        fgets(
            tm.atl[i].nome, sizeof(tm.atl[i].nome), stdin);
        printf("Esporte:\t");
        fgets(
            tm.atl[i].esporte, sizeof(tm.atl[i].esporte),
            stdin);
        printf("Idade:\t\t");
        fgets(linha, sizeof(linha), stdin);
        tm.atl[i].idade = atoi(linha);
        printf("Altura:\t\t");
        fgets(linha, sizeof(linha), stdin);
        tm.atl[i].altura = (float)atof(linha);
        tm.tam += 1;
    }
    for (unsigned i = 0; i < tm.tam; i++)
    {
        for (unsigned j = i + 1; j < 5; j++)
        {
            Atleta temp;
            if (tm.atl[i].idade < tm.atl[j].idade)
            {
                temp      = tm.atl[i];
                tm.atl[i] = tm.atl[j];
                tm.atl[j] = temp;
            }
        }
    }

    printf(
        "\n\tTime (%d de %d) em ordem decrescente de "
        "idade...\n",
        tm.tam, tm.limite);
    for (int i = 0; i < 5; i++) printf("%s",tm.atl[i].nome);
    return 0;
}

Saída do exemplo

Dados do atleta 1...
Nome:           a1
Esporte:        e1
Idade:          45
Altura:         1

Dados do atleta 2...
Nome:           a2
Esporte:        e2
Idade:          45
Altura:         2

Dados do atleta 3...
Nome:           a3
Esporte:        e3
Idade:          12
Altura:         1

Dados do atleta 4...
Nome:           a4
Esporte:        e4
Idade:          23
Altura:         2

Dados do atleta 5...
Nome:           a5
Esporte:        e5
Idade:          15
Altura:         2

        Time (5 de 10) em ordem decrescente de idade...
a1
a2
a4
a5
a3

fgets()
Cuidado: fgets retorna char* e é esse valor que você deve usar nos programas. Se fgets() não ler nada retorna NULL e a variavel do primeiro argumento permanece inalterada. Isso quer dizer que não vai saber se leu ou não algo e seu programa não vai ter o resultado que você espera... Todo dia milhares de programas de iniciantes entram em loop por causa disso. ;)
Mais: fgets() deixa um '\n' ao final da string, mas apenas se houver espaço. Então você deve testar isso antes de mostrar na tela. A menos que o cara tenha digitado exatos 50 caracteres vai ter um '\n' ao final do nome e do esporte na estrutura
Comment: Obrigado por sua ajuda, foi muito útil, estava com certa dificuldade.
Comment: Bom que ajudou. Marque a resposta como solução assim outros podem ter mais facilidade em encontrar.


Cross Validation - Scaler Method not Being Applied in a Pipeline

Question: I have an issue when doing some cross validation using Scikit Learn.
I have build a pipeline consisting of 2 elements: a scaler and a regression model.
My issue is that I found out that the scaler method that I had configured in the pipeline was not applied (i.e.; taken into account) during the calculations.
Please, check my notebook and tell what is wrong.
Here's the link: https://colab.research.google.com/drive/1KHqHsDHNkGLj4e0u-EWY9oj00NXeO5u3?usp=sharing
And here's also the link to the dataset that I have used:
https://drive.google.com/file/d/1nyx0BitzxBLQjsAAAxfHt-9SzKqk9dWv/view?usp=sharing
Best regards.
Comment: Please paste code (of a minimal reproducible example) into the question body.
Comment: Please provide enough code so others can better understand or reproduce the problem.
Comment: The code is full, well detailed and anyone can reproduce the problem. In addition, my concern is well explained.
Answer: The scaler is being applied.  Scaling has no effect on an unpenalized linear regression, and so it is expected that the cross-validation scores would be the same.  Compare with Lasso, where scaling does matter.
Comment: Ben. To show you the difference, I have scaled my data then configured a new pipeline (that's pipeline2). The score that I have obtained at last is totally different from the initial one (check the notebook again). What was the issue with my first pipeline?
Comment: In the new approach you scale the `y` values as well (which doesn't happen in the pipeline approach). The resulting model still captures the same relationship, but the metric is scaled accordingly.
Comment: I can't understand why "y" doesn't need to to be scaled as opposed to x. Anyway, what's wrong with my coding approach, my pipelines, my metrics. Could you please do some changes to the notebook so that I can see the good approach and best practice.


Two forms using one submit button

Question: I want to merge 2 forms together (user register form and node registration form). Should I use multiform module to achieve this or create new form using form API?
Answer: Option 1:
Think of one form as Node Form with more fields that you can reuse on user entity as well.
Now on node save you have flexible node api to hook in and create user. As an example

hook_node_presave($node)
hook_node_insert($node)
hook_node_update($node)

You can use any of the above, most suitable would be node_insert I think as you would like to create user only when new nodes is created. Inside the hook you will get the user submitted values inside $node object, all you have to do is create user programmatically from it.
Which basically is building a user object and mapping of fields and finally do a user_save() on your user object.
Here is an example of how you can create user programmatically

http://codekarate.com/blog/create-user-account-drupal-7-programmatically

Option 2:
Form does not need to be node form, you can have a custom form as well using form api, in that case you will not need any of the node hooks instead process would be just like user_save() you will do node_save(). So inside your custom form submit handler you will be creating a node(how to create node programmatically) and a user(how to create user programmatically)

Two forms using one submit button


A/B test with two metrics, we test one metrics for improvement on the condition the other one doesn't change

Question: I have the following business request:
"Test this change on the landing page and implement it for all the visitors if the test shows improvement in the conversion rate, but if the page load speed significantly differs between the two variations, discard the experiment results and investigate"
The rationale behind it is we want to test the change, but we also want to make sure the results we are getting can only be attributed to the visual change itself, and not the change in page load speed that may occur due to poor implementation of A/B testing framework etc or some other factors.
As far as I know in our case page load speed is what they call "sanity guardrail metric".
However, I am not sure how to translate it into a proper A/B test.
What I figured out so far:

We choose one-tail test for testing the conversion rate (right tail in our case, since we test for an improvement)
We chose two-tailed test for the page load metric, since we test for a change in any direction.

What I have my doubts about:

Required sample size: since we are going to monitor 2 separate metrics, one of them being a continuous metric and the other one - proportion, I am not sure how to calculate the required sample size. Intuition tells me that I should calculate the required sample size for both metrics with the specified minimum detectable effect, power and error probability and choose the larger sample size.  Of course I expect the sample size for page load metric to be larger.
Should I use some sort of correction here? Since I am going to monitor two metrics, maybe I need to apply some sort of correction (bernoully, dunett etc.), but I have doubts, since we do not seek to improve the page load speed - we only need to make sure it doesn't change, but since the page load speed metric is a subject to false positive as well, I guess something must be done about it as well. Besides, we combine one-tail metrics and two-tailed one into one test, which further complicated things.

Any help will be much appreciated, as well as any links to the relevant resources that cover similar problems.
Comment: Could you not just do a single regression with change + loading speed as independent variables and you are interested in change coefficient
Answer:
Unless it's particularly difficult to test a larger sample, you should generally opt for the sample size required for the less powerful test. That is, do the power calculations for both tests, and go with whichever sample size is biggest. There's no such thing as "too much power".
There's no need for p-value correction here. Correction is necessary where you're looking at multiple outcome measures, and would deem the test to be "successful" if any one of them were to improve, since that would increase the chances of a false positive. I'm defining "false positive" here to be "concluding that the change has increased conversion rates, when it in fact hasn't". The fact that you're also looking at load times doesn't increase the probability of that happening.

Other notes:

It's almost always possible that your test could reduce conversion rates, so I don't think a one-tailed test on conversions is appropriate.
You could use a one-tailed test for load times, if you assume there's no way that people could accidentally improve them.


Mostrar Valores maiores que um valor X em uma lista em C

Question: Supondo que eu declaro uma lista encadeada em C e essa lista contém 7 inteiros, e eu declaro um valor X = 20.
Valores da lista:
3,9,11,18,20,22,25
Sabendo que meu X é igual a 20 qual comando eu usaria para mostrar na tela quantos valores maiores que X existem e quais são eles
Answer: <code>#include <stdio.h>
#include <stdlib.h>

//Estrutura principal da lista.
struct listaE
{
    int vl;
    struct listaE *pl;
};

//funcoes da lista:
void displayLL(struct listaE *p)
{
    printf("Mostrar Lista:\n");
    if(p)
    {
        do
        {
            printf(" %d", p->vl);
            p=p->pl;
        }
        while(p);
    }
    else
        printf("Lista Vazia.");
}
//Q 1
int comprimento (struct listaE *p)
{

printf("\n");

    int i=0;
    if(p)
    {
        do
        {
           p=p->pl;
           i++;

        }

        while(p);
         printf(" %d",i);
    }
    else
        printf("Lista vazia.");
}

//Q 2

int maiores(struct listaE *p)
{
    int x=48;
    int i=5;
    printf("\n");
    printf("Valor(es) maior(es) que o de X:");
    printf("\n");

    if(p)
    {
        do
        {

           p=p->pl;
           i--;

        }
        while(x > p->vl);

         printf(" %d",i);
    }
    else
        printf("Lista vazia.");

}

// Q 3
int ultimo (struct listaE *p)
{
    printf("\n");
 printf("O ultimo valor inteiro e:\n");

    if(p)
    {
        do
        {
         p=p->pl;

        }
        while(p && p->pl != NULL );
             printf(" %d", p->vl);

    }

    else
        printf("Lista vazia.");
}

int main(void)
{
    struct listaE *Lista1 = NULL;
    struct listaE *Lista2 = NULL;
    struct listaE *Lista3 = NULL;
    struct listaE *Lista4 = NULL;
    struct listaE *Lista5 = NULL;

    //Criando os nos e associando os dados.

    Lista1 = (struct listaE*) malloc(sizeof(struct listaE*));
    Lista1->vl = 18;

    Lista2 = (struct listaE*) malloc(sizeof(struct listaE*));
    Lista2->vl = 27;

    Lista3 = (struct listaE*) malloc(sizeof(struct listaE*));
    Lista3->vl = 33;

    Lista4 = (struct listaE*) malloc(sizeof(struct listaE*));
    Lista4->vl = 45;

    Lista5 = (struct listaE*) malloc(sizeof(struct listaE*));
    Lista5->vl = 57;

    //Conectando os nos
    Lista1->pl = Lista2;
    Lista2->pl = Lista3;
    Lista3->pl = Lista4;
    Lista4->pl = Lista5;
    Lista5->pl = NULL;

    //Mostrando a lista.
    if(Lista1)
        displayLL(Lista1);
        comprimento(Lista1);
        maiores(Lista1);
        ultimo(Lista1);
  return 0;
}
</code>


PHP connection to SQL Server 2012

Question: Till now, I was used to connect to local MySQL databases with:
<code>$db=new mysqli('localhost', 'root','','apeirosto');
if ($db->connect_errno)
  ...
</code>
Now, it is the case I want to connect to an existing SQL Server 2012 database (named seminars) over the network. If the IP of the host of the db is 10.1.8.13, what do I have to write as to establish the connection? I tried the following:
<code>$db=mssql_connect('10.1.8.13\sqlmix', 'root','','seminars');
</code>
Unfortunately, it did not work(sqlmix is necessary). Sorry,but this is the first time I am dealing with SQL Server. Have in mind that PHP communicates with SQL Server; this is sure. The problem is the wrong command syntax.
Thank you
Comment: Did you check 10.1.8.13\sqlmix has public database access?
Comment: Yes, my static IP has
Answer: <code>$server="SD-20120627VVKE\\SQLEXPRESS";

$options = array("UID" => "<username>","PWD" =>"<password>","Database"=>"android_api");

$conn = sqlsrv_connect($server, $options);

if ($conn === false) die("<pre>".print_r(sqlsrv_errors(), true));
echo "Successfully connected!";
sqlsrv_close($conn);
</code>
Answer: Try this:
<code>mssql_connect('10.1.8.13\sqlmix', 'root','');
</code>
Comment: You may need to use this function too http://php.net/manual/en/function.mssql-select-db.php
Comment: @ILIAS First you connect with the proper syntax and select db.
http://php.net/manual/en/function.mssql-connect.php

PHP connection to SQL Server 2012


IBM Worklight - Trouble with project build

Question: I have two issues:

I can not export .apk file
I can not understand why there is an error (see below), although the project is being compile and run on the server

full size
Answer: How to export as .apk
Worklight does not export the generated Android project to an .apk. For this you need to use the ADT plug-in provided by Google (which I see you already have installed).
Exporting an .apk comes in two flavors: debug mode and production mode.
To understand this concept, review the following documentation by Google:

http://developer.android.com/tools/publishing/app-signing.html

The general steps are:

Right-click on the generated Android project
Choose Android Tools > Export Signed Application Package or Export Unsigned Application Package.
Follow the wizard

Error in project
This error as well, is not related to the generation of the Android project by Worklight. This error means that you are building the application with a certain API Level (in this case 18), but this API Level is not installed in your Android SDK.
Review the following documentation by Google:

http://developer.android.com/guide/topics/manifest/uses-sdk-element.html

To fix the error:

Open the Android SDK and select the appropriate API Level to install.
Right-click the generated Android project > Properties > Android > Target Platform
Change to API Level 18


How to set a variable with both single and double quotes?

Question: How do I set a string variable in ColdFusion that uses a single quote and two double quotes within the string?
MyVar = "Include multiple addresses on "Recipient's E-Mail" separated by commas.";

I know I could break this up into several variables or escape some characters, but I am wondering if there is a standard "best" way, one that is concise and easy to read.
I could do it this way, but this is cumbersome:
// THIS WORKS
MyVar = "Include multiple addresses on ";
MyVar = MyVar & '"Recipient's E-Mail "';
MyVar = MyVar & "separated by commas.";

I should have noted that I am using CFSCRIPT within a function. This makes using savecontent bulky. And CF didn't like the name of my var (LOCAL.Info[i].EmailProd07) in savecontent, so I had to rename it.
// THIS WORKS
savecontent variable="LOCAL.MyVar" {
writeOutput("Multiple recipients may be included in ""Recipient's E-Mail"" separated by commas.");
};
LOCAL.Info[i].EmailProd07 = LOCAL.MyVar;

// THIS WORKS
LOCAL.Info[i].EmailProd07 = 'Multiple recipients may be included in "Recipient''s E-Mail" separated by commas.';

Comment: (Edit) On second thought, I do not think savecontent is going to help you out here.
Comment: Not the script version anyway..
Comment: Have you tried savecontent?
Comment: I have not tried savecontent.
Answer: CF DOC:

Escaping quotation marks and number signs
To include a single-quotation character in a string that is
  single-quoted, use two single-quotation marks (known as escaping the
  single-quotation mark). The following example uses escaped
  single-quotation marks:
<cfset myString='This is a single-quotation mark: '' This is a double-quotation mark: "'>
<cfoutput>#mystring#</cfoutput>

To include a double-quotation mark in a double-quoted string, use two
  double-quotation marks (known as escaping the double-quotation mark).
  The following example uses escaped double-quotation marks:
<cfset myString="This is a single-quotation mark: ' This is a double-quotation mark: """>
<cfoutput>#mystring#</cfoutput>

Because strings can be in either double-quotation marks or
  single-quotation marks, both of the preceding examples display the
  same text:
This is a single-quotation mark: ' This is a double-quotation mark: "

I would add:
<cfsavecontent variable="MyVar">
  Include multiple addresses on "Recipient's E-Mail" separated by commas.
</cfsavecontent>

And if whitespace matters, either use trim() afterwards, or if the content is short, just keep the tag and content in one line with no whitespace in between.
Comment: I am writing in CFSCRIPT, so things are a little different.  I can get the savecontent to work, but the name is tough. (See above).
Comment: `` only makes sense as a solution for your problem in CFML, not CFScript.
Comment: You can also use #chr(34)# for double quote and #chr(39)# for single quotes.
Comment: Another cfscript-friendly workaround would be saving the string into a file, and then `fileOpen()` & `fileRead()`, but why would anyone do that...
Comment: Or put the `` in a separate .cfm and include that in your script-only file. I love script, but in some situations tags are just better.
Answer: MyVar = 'Include multiple addresses on "Recipient''s E-Mail" separated by commas.';
WriteOutput(MyVar);

The keys were:

Enclose string with single quotes to escape double quotes in the variable
Escape single quotes in variable with another single quote

Edit starts here
Here it is again, but with the single and double quotes switched.
MyVar = "Include multiple addresses on ""Recipient's E-Mail"" separated by commas.";

Works just as well
Comment: I like to be consistent in wrapping strings with double quotes, but your answer works perfectly.
Comment: Yeah, I know how to switch those around. I just want to touch the actual string content as little as possible. Thanks!
Comment: Which brings up the point of, from where does this string come and what do you do with it once you have it?
Answer: Couldn't you use the CHR function? http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_c-d_04.html
This would mean you simply replace one set of "'s with the correct character code instead.
Answer: you need to use the escape characters
usually it is : \
example :
string a = "bla bla bla \' dsfdsf \' bla "
Comment: No, it doesn't work in CFML. CFML doesn't have an escape character like that. As others have suggested, to escape either type of quote (single or double) within a string delimited with the same quote... double it up.  "double quote: """; 'single quote: '''
Comment: What happened when I tried it? *It didn't work*, obviously. Because it doesn't.
Comment: So it works? I haven't tried it but I don't think this is documented.
Comment: I find that attempting to answer questions on forums like this is very educational.


Change values of nested fields with entity_metadata_wrapper

Question: The background of this question is that I'm trying to migrate data from Drupal 6 Imagefield Extended to Drupal 7 File Entity (with File Entity Inline). See also https://www.drupal.org/node/974888
First I tried to understand how entities work and how they can be extracted and manipulated using Entity Metadata Wrappers. That seems to work ok, for example, I can get the values of my imagefield like this:
$nid = 103025;
$node_wrapper = entity_metadata_wrapper('node', $nid);
$images = $node_wrapper->field_image->value();

And it seems that I could change the values of the images with something like this:
// Do something with $images
$node_wrapper->field_image->set($images);
$node_wrapper->revision->set(1);
$node_wrapper->save();

(For some reason it's not saving the values for the node in my case, but that's another question.)
My problem now is that I have nested fields, i.e. the imagefield has "subfields" for the source and license (that I had added in Drupal 6 using Imagefield Extended). I do get the values of those nested fields in $images - but only in the typical array with $images[und][0]['value'] and $images[und][0]['safe_value']. But there seems to be no way to get those values through the wrapper, for example like
$node_wrapper->field_image->field_source->value();
$node_wrapper->field_image->value()->field_source->value();

Now I have been trying for hours to figure out how I can change (or populate) those (sub) fields and then save the entire node, but to no avail.
I'm also wondering if it's necessary to do this on a node level as files are also entities, but it seems that there is nothing like entity_metadata_wrapper('file', $fid);.
I'd appreciate any hint that could point me in the right direction because the search has been kind of exhausting.
Comment: What about `$node_wrapper->field_image[0]->getPropertyInfo()`? And then perhaps `$node_wrapper->field_image[0]->file->getPropertyInfo()`. I don't have file entity installed on anything so I'm guessing a bit
Comment: Have you tried `$node_wrapper->field_image->file->field_source->value()`?
Comment: Hi Clive, that one returns a PHP error: "Call to a member function value() on a non-object".
Comment: Have you managed to confirm that File Entity definitely supports EntityMetadataWrapper? It isn't necessarily something implicit, entity modules can need to explicitly declare their support for it
Comment: Actually ignore that, it does support it. Try inspecting  the results of `$node_wrapper->field_image->getPropertyInfo()` and `$node_wrapper->field_image->file->getPropertyInfo()` to see what fields/properties the system things are available. That might help to shed some light. Feel free to edit them into the question and ping me if you want me to have a look
Comment: Thanks a lot Clive, but I'm still stuck: The first one (´$node_wrapper->field_image->getPropertyInfo()´) leads to the error "Call to undefined method EntityListWrapper::getPropertyInfo()" and the second one (´$node_wrapper->field_image->file->getPropertyInfo()´) to the error "Call to a member function getPropertyInfo() on a non-object".
Comment: That does work! Thanks for the hint. I'll try with that and then get back to you. But I still have the problem that values aren't saved through ->save().
Answer: Using what Clive mentioned and with the hint eikes provided, this seems to be a way to accomplish what I want:
$nid = 108501;
$node_wrapper = entity_metadata_wrapper('node', $nid);

for ($i = 0; $i < count($node_wrapper->field_image->value()); $i++) {
  $node_wrapper->field_image[$i]->file->field_source->set('NEW SOURCE');
  $node_wrapper->field_image[$i]->file->field_license->set('NEW LICENSE');
  $node_wrapper->field_image[$i]->file->save();
}

// Just for dev: Check if the values have been saved
$node_wrapper = entity_metadata_wrapper('node', $nid);
dsm($node_wrapper->field_bild->value());

Erroneously I used the save() call on the whole node wrapper, but as files are their own entities, the call needs to be on the file, as eikes suggested.
Additionally, I noticed that calling $node_wrapper = entity_metadata_wrapper('node', $nid); after the above code doesn't reflect the changes (for checking). It seems I need to reload the entity first.
Thanks a lot to both of you!
Comment: I assume that the file you get is a separate entity and you may need to save it as well:

  $node_wrapper->field_image[$i]->file
Answer: This is my solution to access and update 2 nested levels deep on unlimited values on field collections fields
  function set_descuentos_pagos_action($nid) {
  // $raw_node = node_load($nid);  AVOID THIS
  $node = entity_metadata_wrapper('node', $nid);
  // dpm($node->getPropertyInfo());
  // dpm($node);
  $raw_ana = $node->field_ana->value();
  // dpm($raw_ana);
  $num_cotizaciones = count($raw_ana);

  // $i ES EL ITEM DE  CADA COTIZACION
  for ($i=0 ; $i < $num_cotizaciones  ; $i++ ) {

    $ana[$i] = entity_metadata_wrapper('field_collection_item', $raw_ana[$i]);
    $fp = $ana[$i]->field_m_fc_pago_texto->value();
    if($fp == 'Trimestral'){
      // get values from parent field collection
      $prima_descuento[$i] = $ana[$i]->field_m_fc_prima_neta_descuento->value();
      $prima_original[$i] = $ana[$i]->field_m_fc_prima_neta->value();
      $factor[$i] = $prima_descuento[$i] / $prima_original[$i];

      // get child field collection
      $raw_recibos = $ana[$i]->field_m_fc_recibo->value();
      $num_recibos[$i] = count($raw_recibos);

      // $j SON LOS PAGOS DE LA ITERACION $i
      for ($j=0; $j < $num_recibos[$i]; $j++) {

        // get current child field collection object
        $value[$j] = $ana[$i]->field_m_fc_recibo[$j]->value();

        // $pago[$j] ES EL PAGO OBJETO
        $pago[$j] = entity_metadata_wrapper('field_collection_item', $value[$j]);
         // dpm($pago[$j]->value());
         // get field value, set value on other field
         $prima = $pago[$j]->field_m_fc_prima_total->value();
         $nuevo_valor = $prima * $factor[$i];
         $pago[$j]->field_m_fc_prima_total_descuento->set($nuevo_valor);
         $pago[$j]->save();
      }

    }
  }

} // end  set_descuento_pagos_cotizacion


Correct chord notation for inverted 7ths

Question: I am having trouble composing a piano piece, because i don't know how to correctly notate a specific chord that i have used.
The notes are as such in order: C,F,A,E

The traditional F Major 7th chord uses the notes in the order F,A,C,E, however i do not want to write it like that.
First i thought of using an inverted 7th chord to notate it, but none of them matched.
I also thought of using an Fmaj 2nd inversion add 7th, but that didn't appear to exist either.
Next, i thought to notate it as the diadic F5 chord, then add a c bass notes: F5/C then add a 7th: F5/C+7, but this does not appear to be correct visually, and as far as my research has found isn't an existing notation.
Are any of these, correct? Do they have their own symbols that i have not discovered yet, or have i missed something? If anyone could shed some light on this subject I would be very greatful,
Jacob.
Comment: Chord symbols do not convey any voicing information besides the bass note in "slash chords". Trying to make a chord symbol represent a voicing just leads to a lot of confusion. Just call it an FMaj7/C and call it a day. If the voicing matters, give out the voicings in standard notation.
Answer: It's still Fmaj7.
If you're doing a harmonic analysis you could label it 'Fmaj7, second inversion'.
If you're writing a lead sheet you could give the  musician playing it some more useful information by using the Chord Symbol 'Fmaj7/C'.
But either way, it's still Fmaj7.
You NOTATE it like this, with notes.

You can only convey limited information with chord symbols. 'Fmaj7/C' tells us what notes are in the chord and which note is on the bottom, but nothing about the voicing otherwise.  These would all be correctly labelled as Fmaj7/C.  And there are many more possibilities!

A word of warning.  If there is ONLY a piano in your piece of music, describing the piano voicing as a certain inversion can be useful.  But if there's a bass player too, it's HIS note that determines the inversion.   Don't call it Fmaj7/C if the bass player has F.
And if you want to instruct the musicians in more detail than chord symbols can handle, use notation.  It's what it's for!


API de notificação não retorna dados

Question: Estou tendo um problema com o API de notificação do pagseguro, ele não está retornando o XML de maneira alguma, estou testando em HTTP, pois em HTTPS também não deu certo.
Alguém sabe como resolver isso?
Código:
<?php
require("includes/connection.php"); //meu banco de dados
require("includes/pagSeguro.php");

header("access-control-allow-origin: https://ws.pagseguro.uol.com.br");
$email     = 'email@example.com';
$token     = 'token';
$pagamento = $_GET['transaction_id'];

$url = 'https://ws.pagseguro.uol.com.br/v3/transactions/notifications/' . $pagamento . '?email=' . $email . '&token=' . $token;

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$transaction = curl_exec($curl);
curl_close($curl);

$dominio = $_SERVER['HTTP_HOST'];

if ($transaction == 'Unauthorized') {
    $name = 'unauthorizeds.txt';
    $text = " A transação não foi validada!" . "\r\n";
    $file = fopen($name, 'a+');
    fwrite($file, $text);
    fclose($file);
    exit;
}
$transaction = simplexml_load_string($transaction);
date_default_timezone_set('America/Sao_Paulo');
$date = date('d-m-Y H:i');
$name = 'transaction.txt';
$text = $url = $date . " " . $transaction . "\r\n";
$file = fopen($name, 'a+');
fwrite($file, $text);
fclose($file);

if ($transaction->status >= 1) {
    $transaction_id = $transaction->code;
    $client_id      = $transaction->reference;
    $payment_type   = $transaction->paymentMethod->type;
    if ($payment_type == 1) {
        $payment_method = "Cartão de crédito";
    } elseif ($payment_type == 2) {
        $payment_method = "Boleto";
    } elseif ($payment_type == 3) {
        $payment_method = "Débito online (TEF)";
    } else {
        $payment_method = "Outro";
    }
    $payment_type_method = $transaction->type;
    if ($payment_type_method == 1) {
        $payment_method_transaction = "Pagamento";
    } elseif ($payment_type_method == 11) {
        $payment_method_transaction = "Assinatura";
    } else {
        $payment_method_transaction = "Outro";
    }
    $client_email     = $transaction->sender->email;
    $parceled         = $transaction->installmentCount;
    $parceled_value   = $transaction->installmentFeeAmount;
    $product          = $transaction->items->item->id;
    $product_value    = $transaction->items->item->amount;
    $transaction_date = date('Y-m-d H:i:s', strtotime($transaction->date));

    $transaction_date_last = date('Y-m-d H:i:s', strtotime($transaction->lastEventDate));
    if ($transaction->status == 1) {
        $transaction_status = 'Aguardando pagamento';
    } elseif ($transaction->status == 2) {
        $transaction_status = 'Em análise';
    } elseif ($transaction->status == 3) {
        $transaction_status = 'Paga';
    } elseif ($transaction->status == 4) {
        $transaction_status = 'Disponível';
    } elseif ($transaction->status == 5) {
        $transaction_status = 'Em disputa';
    } elseif ($transaction->status == 6) {
        $transaction_status = 'Devolvida';
    } elseif ($transaction->status == 7) {
        $transaction_status = 'Cancelada';
    }
    $client_name = $transaction->sender->name;
    $select      = $mysqli->query("select * from payments where transaction_id = '$transaction->code' ");
    $row         = $select->num_rows;
    $get         = $select->fetch_array();
    if ($row >= 1) {
        $update = $mysqli->query("UPDATE payments SET transaction_id = '$transaction_id', client_email = '$client_email', payment_method = '$payment_method', payment_method_transaction = '$payment_method_transaction', transaction_status = '$transaction_status', transaction_date_last = '$transaction_date_last', product = '$product', product_value = '$product_value', client_name = '$client_name' WHERE transaction_id = '$transaction->code'");
        if ($update) {
            $select       = $mysqli->query("select * from payments where transaction_id = '$transaction->code' ");
            $row          = $select->num_rows;
            $get          = $select->fetch_array();
            $foiPago      = $get['transaction_status'];
            $status       = $get['status'];
            $product_cash = $get['product'];
            if ($foiPago == 'Paga' or $foiPago == 'Disponivel' and $status == '0') {
                $select = $mysqli->query("select * from data where email = '$client_email' ");
                $row    = $select->num_rows;
                $get    = $select->fetch_array();
                $cash   = $get['cash'];
                if ($product_cash == '50KP') {
                    $cash_update = $cash + 50;
                    $update      = $mysqli->query("UPDATE data SET cash = '$cash_update' WHERE email = '$client_email'");
                    $update      = $mysqli->query("UPDATE payments SET status = '1' WHERE transaction_id = '$transaction->code'");
                }
                if ($product_cash == '200KP') {
                    $cash_update = $cash + 200;
                    $update      = $mysqli->query("UPDATE data SET cash = '$cash_update' WHERE email = '$client_email'");
                    $update      = $mysqli->query("UPDATE payments SET status = '1' WHERE transaction_id = '$transaction->code'");
                }
                if ($product_cash == '1000KP') {
                    $cash_update = $cash + 1000;
                    $update      = $mysqli->query("UPDATE data SET cash = '$cash_update' WHERE email = '$client_email'");
                    $update      = $mysqli->query("UPDATE payments SET status = '1' WHERE transaction_id = '$transaction->code'");
                }
                if ($product_cash == '2000KP') {
                    $cash_update = $cash + 2000;
                    $update      = $mysqli->query("UPDATE data SET cash = '$cash_update' WHERE email = '$client_email'");
                    $update      = $mysqli->query("UPDATE payments SET status = '1' WHERE transaction_id = '$transaction->code'");
                }

            }
        } else {
            printf("Erro do BD de atualização : %s\n", $mysqli->error);
        }
    } else {

        $insert = $mysqli->query("INSERT INTO `payments`(`transaction_id`, `client_email`, `payment_method`, `payment_method_transaction`, `transaction_status`, `transaction_date`, `transaction_date_last`, `product`, `product_value`, `client_name`) VALUES ('$transaction_id', '$client_email', '$payment_method', '$payment_method_transaction', '$transaction_status', '$transaction_date', '$transaction_date_last', '$product', '$product_value', '$client_name')");
        if ($insert) {
            $select       = $mysqli->query("select * from payments where transaction_id = '$transaction->code' ");
            $row          = $select->num_rows;
            $get          = $select->fetch_array();
            $foiPago      = $get['transaction_status'];
            $status       = $get['status'];
            $product_cash = $get['product'];
            if ($foiPago == 'Paga' or $foiPago == 'Disponivel' and $status == '0') {
                $select = $mysqli->query("select * from data where email = '$client_email' ");
                $row    = $select->num_rows;
                $get    = $select->fetch_array();
                $cash   = $get['cash'];
                if ($product_cash == '50KP') {
                    $cash_update = $cash + 50;
                    $update      = $mysqli->query("UPDATE data SET cash = '$cash_update' WHERE email = '$client_email'");
                    $update      = $mysqli->query("UPDATE payments SET status = '1' WHERE transaction_id = '$transaction->code'");
                }
                if ($product_cash == '200KP') {
                    $cash_update = $cash + 200;
                    $update      = $mysqli->query("UPDATE data SET cash = '$cash_update' WHERE email = '$client_email'");
                    $update      = $mysqli->query("UPDATE payments SET status = '1' WHERE transaction_id = '$transaction->code'");
                }
                if ($product_cash == '1000KP') {
                    $cash_update = $cash + 1000;
                    $update      = $mysqli->query("UPDATE data SET cash = '$cash_update' WHERE email = '$client_email'");
                    $update      = $mysqli->query("UPDATE payments SET status = '1' WHERE transaction_id = '$transaction->code'");
                }
                if ($product_cash == '2000KP') {
                    $cash_update = $cash + 2000;
                    $update      = $mysqli->query("UPDATE data SET cash = '$cash_update' WHERE email = '$client_email'");
                    $update      = $mysqli->query("UPDATE payments SET status = '1' WHERE transaction_id = '$transaction->code'");
                }

            }
        } else {
            printf("Erro do BD : %s\n", $mysqli->error);
        }
    }
} else {
    date_default_timezone_set('America/Sao_Paulo');
    $date = date('d-m-Y H:i');
    $name = 'invalids.txt';
    $text = $url = $date . " https://" . $dominio . $_SERVER['REQUEST_URI'] . "\r\n";
    $file = fopen($name, 'a+');
    fwrite($file, $text);
    fclose($file);
    exit;
}
?>

Já tentei contato com o suporte deles mas tive uma péssima experiência, ai gostaria de ver com vocês, meu código está errado ou seria um problema com a plataforma do pagseguro? Percebi que não estou recebendo o XML, no site do pagseguro eles enviam a notificação com status 200, e a comunicação com minha página existe porém é como se não enviassem nada, apenas acessassem ela, pois não vem o código de transição nos logs... quando eu pego o código de notificação no pagseguro e insiro na url manualmente, tudo funciona perfeitamente... então estou achando que eles não estão enviando o código, só não sei de quem é o erro.
Comment: Insere um `var_dump($transaction);exit(2);` após `$transaction= curl_exec($curl);` e posta aí o que ele retorna.
Comment: @JacksonAntunes para salvar um log "customizado" pode fazer assim: `error_log(var_dump($transaction,true))`. A função [error_log()](http://php.net/manual/pt_BR/function.error-log.php) vai salvar o conteudo do `var_dump()`, pode ser print_r, string ou qualquer outra coisa, no mesmo arquivo de log do php, ai facilita nao ter que fazer `file_put_contents()` e similares
Answer: O erro estava na forma que eu tentava obter os dados, pois não tinha entendido bem como funcionava o api de notificação. Ao invés da variável ser $pagamento = $_GET['transaction_id']; era  $pagamento = $_POST['notificationCode'];.
No caso do transaction_id é para quando o PagSeguro redireciona o cliente para uma página prédefinida pelo usuário, então a informação seria pega dessa forma
$pagamento = $_GET['transaction_id'];

No caso do api de notificação eu quero o código da notificação, e não o da transação... para isso eu pego ele usando o parâmetro notificationCode.

API de notificação não retorna dados


Nao estou conseguindo achar alguma maneira de limitar o tamanho geral do meu site

Question: ao voce descer no site ele continua com infinitamente, eu ja tentei com width e height e ambos nao funcionaram do jeito esperado
https://github.com/Luccas-costa/Dusckb/tree/main/teste%20home-login
o html esta no home
o css esta no stylehome
e o js  esta no scriphome
Comment: Boas-vindas. Perguntas não podem depender de links externos e devem seguir o modelo [mcve]. Para aproveitar melhor o site, entender e evitar fechamentos vale a pena ler a [help], após feito isso basta [edit] a pergunta e aguardar a comunidade avaliar se está adequada para o site. *Agradecemos a compreensão*.
Answer: Achei o erro. Lá no seus "script2.js", substitui o seu código pelo que vou mandar abaixo que vai funcionar de boa!
<code>window.addEventListener("scroll", () => {
    let value = window.scrollY

    if (value < 500) {
        leaf.style.top = value * -1.5 + "px"
        leaf.style.left = value * 1.5 + "px"
        hili5.style.left = value * 1.5 + "px"
        text.style.marginTop = value * 2.5 + "px"
        hili4.style.left = value * -1.5 + "px"
        hili1.style.top = value * 1 + "px"
    }

})
</code>
Comment: salvo eu muito obrigado


How do I import configuration without getting these errors?

Question: I am using drush cim and drush cex for importing and exporting the  configuration between environments.
At this moment, local and develop are working OK, but I am getting an error on stage.
This is the error.

The import failed due to the following reasons:
  This config does not have system.site, rejected
  UUID source site does not match current site.
Config core.extension does not exists.

But actually both of them exists. I have already ran drupal config.override and set the UUID on system.site, but I am still getting those errors.
I have also tried drush cr.
The system site has the same UUID as local. It's the same file.
Comment: Does this answer your question? [Site UUID in source storage does not match the target storage](https://drupal.stackexchange.com/questions/204859/site-uuid-in-source-storage-does-not-match-the-target-storage)
Comment: I have done already but still getting that error.
Comment: https://drupal.stackexchange.com/questions/150481/how-can-i-import-the-configuration-on-a-different-site/190282#190282
Comment: also done, the uuid is the same...not sure if its a cache issue, i have ran drush cr as well
Comment: Does this answer your question? [How can I import the configuration on a different site?](https://drupal.stackexchange.com/questions/150481/how-can-i-import-the-configuration-on-a-different-site)
Comment: already done :(
Comment: Is there already content on stage you need to preserve? If no, reinstall, and then set the site UUID.
Comment: not working yet. i cant do it, everything is via git.
Answer: I have fixed the issue using config suite module: install this module and it will assign the uuid for those enviroments so you don't need to worry to set up manually.
Comment: But how exactly?
Comment: Install module and it will assign the uuid for those enviroments so you dont need to worry to set up manually.


Intentionally load imageview with random delay inside UICollectionView cell

Question: I want to create an effect so that my collectionviewcell (which has one imageview as IBOutlet) will load its image with a random delay. So for example, cell #1 will have its image shown in 2 seconds, while #2 will take 1 second, cell #3 will take 4 seconds ... etc.
How would I do this? I heard about using NSOperationQueue at cellForRowAtIndexPath but not sure how to implement.
Answer: If your images are already available, you could try giving a random delay in your cellForItemAtIndexPath method:
UIImage *theImage = ...; //get your image
int maxDelay = 4;
int delayInSeconds = arc4random() % maxDelay;
cell.imageView.image = theImage;
cell.imageView.alpha = 0;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
      cell.imageView.alpha = 1;
});

If your image is not available in memory, and it needs to be loaded, you may want to look at this post on how to load the image asynchronously:
Answer: You could have a method on the cell's subclass for setting the image, then within that method call another method with a random delay to actually set the UIImageView's image. Something like this:
- (void)delayedSetBackgroundImage:(UIImage *)image
{
    [self performSelector:@selector(setBackgroundImage:) withObject:image afterDelay:(arc4random() % 5)];
}

- (void)setBackgroundImage:(UIImage *)image
{
    _myImageView.image = image;
}

So then in cellForRowAtIndexPath you would call delayedSetBackgroundImage: and the cell itself would take care of the rest.


What does "mean age at childbearing" mean?

Question: I'm having trouble putting this into plain English.
According to the UN World Population Prospects glossary it means:

The mean age at childbearing is the mean age of mothers at the birth of their children if women were subject throughout their lives to the age-specific fertility rates observed in a given year.

The "their children" part trips me up.
Can I understand this measure as "average age of entry into child bearing" or "Average age of first child"?
Comment: Sounds very confusing but I think it is off topic for this site.
Comment: Do you not still count as a child even if you were not the first one born to a particular mother?
Comment: I'd say it is statistics and therefore on-topic  for this site. Maybe it is not the mathematical stuff that you more often see here and also it is more about definitions rather than purely statistical issues (although statistics may be considered to start with definitions or at least be intertwined with it).
Comment: Any idea what community this could find a home in? @MichaelChernick
Comment: @Tomulent perhaps post this on English.stackexchange.com? They are wizards at interpreting the gobbledygook that we scientists conjure up.
Answer: It is the mean age at childbearing (any child, not just the first), calculated, for a specific year based on the age specific fertility rates.
I guess that this is done in this way, in order to correct for variations of cohort sizes (population composition).
Changes in certain statistics may occur just because people are getting older or due to other changes in correlations composition and not so much due to certain changes in causal effects.
Consider for instance the following problem with analogous issues of compositions changes: many old people have diabetes, a higher BMI, and lots of problems with cardiovascular diseases. Then we see in populations that are getting older an increase of these health problems, not necessarily (solely) due to causal effects like bad habits, but just because people are getting older.
(although this is a bad example, in the sense that, even if you correct for age and gender those health problems are often still increasing, still in some countries the tide is changing for some problems which means they decrease if you correct for age and certainly in most cases the effects are much smaller than what it might seem or some people try to make you believe)

Say you use these data for Egypt 1997-2000 based on age categories per five years
<code>age    fertility  births
15-19  0.051      764
20-24  0.196      2304
25-29  0.208      1994
30-34  0.147      1295
35-39  0.075      564
40-44  0.024      161
45-49  0.004      19
</code>
Then you get
$$\frac{17 \cdot 51+22 \cdot 196+27 \cdot 208+32 \cdot 147+37 \cdot 75+42 \cdot 24+47 \cdot 4}{51+196+208+147+75+24+4}=27.6$$
which differs from the situation when you compute the mean based on the number of births:
$$\frac{17 \cdot 764+22 \cdot 2304+27 \cdot 1994+32 \cdot 1295+37 \cdot 564+42 \cdot 161+47 \cdot 19}{764+2304+1994+1295+564+161+19}=26.4$$
Note that with this way of calculating a mean age of childbearing, the number is not influenced by differences in the age composition of the population (for instance if there is relatively less teenagers and more women in the forties then the mean age of childbirth might go up) and represents more precisely a difference in habits (for instance an increase because relatively less teenagers and more women in the 40-ies are getting babies)
Comment: Statistics of first born babies vs total born babies are very interesting (e.g. we may see opposite trends in numbers), but it is not the case considered with this statistic here.
Comment: Is another way to say that, "The average childbearing woman in 20xx was X years of age"?
Comment: Indeed, you could say that, just 'another way'. But you have to realize that a mean/average can be computed in many different ways, is ambiguous, and therefore that definition is so verbose (in order to be more precise). Note that my answer is different to the other answer by accumulation.
Answer: My interpretation is that this is calculated by taking each age, finding the number of children borne by women at that age, multiplying that number by the age, summing the results, and then dividing by the total number of births. It should be the same as the average, over all children born that year, of the children's mother's age. That is, if you record for each child born that year the age of their mother, and take the average of those numbers, that should be the same as this statistic.


What is a time-invariant linear filter

Question: I am a new student of time series analysis. Could someone explain to me the meaning of time-invariant linear filter in time series? I do not understand the explanation in wikipedia or the course literature.
Thanks in advance.
Answer: Linearity means superposition and scaling are preserved by the filter. Say we have some signal $s$ and let $f(s)$ be the filter of $s$ as an operator then linearity is just the usual linearity from linear algebra so for some scalar $x$ then  $f(xs)=xf(s)$ and if we have two signals then $f(s_1 + s_2) = f(s_1) + f(s_2)$.
Time invariance means that no matter when we start filtering the signal the filter will be act in the same way on the signal. So if you apply the same shift to the sample before or after the filter you should expect the same result.
These properties are independent of each other and a filter can have all, some or none of these properties. The most important time invariant linear filters are the Fourier Transforms and the $z$-transform. What makes the important is that they can be subjected to frequency-domain analysis.

What is a time-invariant linear filter


Unknown Notation - Brace connect two notes

Question:
I dont know what exactly reffering to. Anyone can explaining to me?
EDIT: this notation appear on "450 Noëls" by Rouher, Edouard Marcel Victor
Comment: Can you say which of the 450 pieces? Which edition of the IMSLP options?
Comment: @AndyBonner is the IMSLP #314558 and #314560
Comment: And I see now, it's throughout. Noel #2 uses it within the piece. I hope an organist can chime in, but it seems to me to have to do with indicating registers/stops.
Answer: The piece is for (pipe) organ. Organs generally have more than one keyboard - one or more for the hands (manuals) and one for the feet. See for example this page at organtutor.byu.edu. These different keyboards are linked to various stops. Different stops control different sounds. The selection of stops (and assignment of particular notes to particular keyboards) is often left to the performer, and is known as registration.
In the scores you are looking at, someone - either composer or editor - has specified particular assignments of notes to keyboards. You can see in the pages before the scores this sort of thing:

Note the G, P, R on the left.
Then, in a score, for example #221:

The R indicates that all the braced voices are to be played on the keyboard that R refers to (Swell, in English)
Sometimes the indicated keyboard changes midpiece:

Here, the instruction is to use Swell for the top two voices of the piano section, but (optionally) switch to Great-Organ or Choir for the forte section.


issue with excel after saveas overwrite data

Question: So I have written the below code that open my excel file and save it as text file
Dim xl As New Excel.Application
Dim xlBook As Excel.Workbook = xl.Workbooks.Open("C:\ExcelData.xlsx")
Dim xlSheet As Excel.Worksheet = xlBook.Sheets("Sheet1")

xlSheet.SaveAs("C:\Data.txt", Excel.XlFileFormat.xlTextWindows)

xlBook.Close

The problem is after it save the file i9t prompt me do you want to save changes and when I click Yes it overwrite the file with the latest opned sheet from the excel.
How can I stop it from overwriting and stop it from prompt me for changes?
Comment: -1 this shows no research effort. This has been asked (and answered) many times already
Comment: If you like my question kindly upvote it
Answer: If you add the following line at the start of your macro:
Application.DisplayAlerts = False

Then no dialog boxes will appear during its running. This will include the popup that shows when closing xlBook.
Comment: This is a vb.net application windows application not a macro.
Comment: When I added it it gave me the below error:

Error 13 'DisplayAlerts' is not a member of 'System.Windows.Forms.Application'.
Comment: That should probably be `xl.DisplayAlerts = False` then.
Comment: If you like my question upvote it
Comment: You don't like my question?
Comment: @MohammadMMohammad - Please stop asking for up-votes on all your questions.
Comment: Why? what's in it with you?
Comment: There is no rule prevent me asking for up-votes.


Given $x^T(A^TMA)x\leq \theta x^TMx$, obtain a tight bound for $y^T([A^TMA]\otimes [A^TMA])y$

Question: Assume that for matrices, $M,A$ where $M$ is positive definite and $0<\theta<1$ the inequality $x^T(A^TMA)x\leq \theta x^TMx$ holds for any vector $x$. I want to obtain a bound for $y^T(A^TMA\otimes A^TMA)y$ where $\otimes$ is the Kronecker product. My hope is that the bound is of the form $y^T(A^TMA\otimes A^TMA)y\leq \theta^2 y^T(M\otimes M)y$.
My attempt was to obtain a direct upper bound using matrix norms (induced by the Euclidean norm as $\|M\|=\max_{\|x\|=1} \|Mx\|$) and the Rayleigh inequality.
Concretelly, we know that $\|M^{1/2}A\|\leq \sqrt{\theta}\|M^{1/2}\|$. Thus
$$
\begin{aligned}
&y^T(A^TMA\otimes A^TMA)y = \| (M^{1/2}A\otimes M^{1/2}A)y \|^2\leq \|M^{1/2}A\|^4\|y\|^2
 \\& \leq\theta^2\|M^{1/2}\|^4\|y\|^2 = \theta^2\|M\|^2\|y\|^2
\end{aligned}
$$
Then, using the Rayleigh inequality I get $\|y\|^2\leq y^T(M\otimes M)y/\lambda_{\min}(M)^2$. Thus, instead of a multiplicative factor of $\theta^2$ I obtain $(\|M\|/\lambda_{\min}(M))^2\theta^2$.
However, $(\|M\|/\lambda_{\min}(M))^2\geq 1$. I wonder if its possible to obtain a tighter bound.
Answer: In general, for any two positive definite matrices $X$ and $Y$, we have $X\preceq Y$ if and only if $\rho(Y^{-1}X)\le1$. Therefore
\begin{align}
X\preceq Y
&\Leftrightarrow \rho(Y^{-1}X)\le1\\
&\Leftrightarrow \rho(Y^{-1}X)^2\le1\\
&\Leftrightarrow \rho\left((Y^{-1}X)\otimes(Y^{-1}X)\right)\le1\\
&\Leftrightarrow \rho\left((Y\otimes Y)^{-1}(X\otimes X)\right)\le1\\
&\Leftrightarrow Y\otimes Y\preceq X\otimes X.\\
\end{align}
Now put $X=A^TMA$ and $Y=\theta M$ and the result follows.
Comment: Is $\rho(\bullet)$ a matrix norm? Thanks!
Comment: It's the standard notation for spectral radius.
Comment: Thanks! I think this is it then. Only one more thing. Do you have a some canonical reference where I should be able to find the first fact you mentioned? ($X\leq Y$ iif $\rho(Y^{-1}X)\leq 1$)
Comment: I think it's covered in Horn and Johnson's *Matrix Analysis* for instance. Anyway this is an easy fact: $X\preceq Y$ iff $Y^{-1/2}XY^{-1/2}\preceq I$ iff $\rho(Y^{-1}X)=\rho(Y^{-1/2}XY^{-1/2})\le1$.
Comment: I was looking in Horn, but I cannot find it. Anyway, I see that showing that is easy. Thanks!!
Comment: If anyone reads this in the future, the result is in Horn in theorem 7.7.3-(a)


Can't load .csv data in a local Spark connection when using sparklyr

Question: Background: I am completely new to the whole Spark platform & concept and I am trying to learn how to operate it with via R with sparklyr. I started following an online course on the topic and I am trying to use it for my own data analysis as a way to learn it.
Problem: I am trying to load a 6.3gb csv dataset (~30 mil rows, ~20 cols) but I get the following error (from what I could tell, the same chunks kept repeating themselves, I give here the first 3 of them, as I will otherwise reach the character limit for the post). The code runs but after 17 minutes it exits with the following error (no data is loaded):
Error: java.lang.IllegalStateException: Cannot call methods on a stopped SparkContext.
This stopped SparkContext was created at:

org.apache.spark.SparkContext.getOrCreate(SparkContext.scala)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
sparklyr.Invoke.invoke(invoke.scala:139)
sparklyr.StreamHandler.handleMethodCall(stream.scala:123)
sparklyr.StreamHandler.read(stream.scala:66)
sparklyr.BackendHandler.channelRead0(handler.scala:51)
sparklyr.BackendHandler.channelRead0(handler.scala:4)
io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:346)
io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:346)
io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)

The currently active SparkContext was created at:

org.apache.spark.SparkContext.getOrCreate(SparkContext.scala)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
sparklyr.Invoke.invoke(invoke.scala:139)
sparklyr.StreamHandler.handleMethodCall(stream.scala:123)
sparklyr.StreamHandler.read(stream.scala:66)
sparklyr.BackendHandler.channelRead0(handler.scala:51)
sparklyr.BackendHandler.channelRead0(handler.scala:4)
io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:346)
io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:346)
io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)

    at org.apache.spark.SparkContext.assertNotStopped(SparkContext.scala:100)
    at org.apache.spark.SparkContext$$anonfun$parallelize$1.apply(SparkContext.scala:716)
    at org.apache.spark.SparkContext$$anonfun$parallelize$1.apply(SparkContext.scala:715)
    at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:151)
    at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:112)
    at org.apache.spark.SparkContext.withScope(SparkContext.scala:701)
    at org.apache.spark.SparkContext.parallelize(SparkContext.scala:715)
    at org.apache.spark.sql.execution.command.ExecutedCommandExec.doExecute(commands.scala:74)
    at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$1.apply(SparkPlan.scala:114)
    at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$1.apply(SparkPlan.scala:114)
    at org.apache.spark.sql.execution.SparkPlan$$anonfun$executeQuery$1.apply(SparkPlan.scala:135)
    at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:151)
    at org.apache.spark.sql.execution.SparkPlan.executeQuery(SparkPlan.scala:132)
    at org.apache.spark.sql.execution.SparkPlan.execute(SparkPlan.scala:113)
    at org.apache.spark.sql.execution.QueryExecution.toRdd$lzycompute(QueryExecution.scala:87)
    at org.apache.spark.sql.execution.QueryExecution.toRdd(QueryExecution.scala:87)
    at org.apache.spark.sql.Dataset.<init>(Dataset.scala:185)
    at org.apache.spark.sql.Dataset$.ofRows(Dataset.scala:64)
    at org.apache.spark.sql.SparkSession.sql(SparkSession.scala:592)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sparklyr.Invoke.invoke(invoke.scala:139)
    at sparklyr.StreamHandler.handleMethodCall(stream.scala:123)
    at sparklyr.StreamHandler.read(stream.scala:66)
    at sparklyr.BackendHandler.channelRead0(handler.scala:51)
    at sparklyr.BackendHandler.channelRead0(handler.scala:4)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:346)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:346)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:346)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:367)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:353)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:652)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:575)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:489)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:451)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
    at java.lang.Thread.run(Unknown Source)
Error: java.lang.IllegalStateException: Cannot call methods on a stopped SparkContext.
This stopped SparkContext was created at:

Here is my R code:
library(sparklyr)
spark_install(version = "2.1.0")
sc <- spark_connect(master = "local")
testdata = spark_read_csv(sc, name = "testdata", path = ...)

Outside of Spark, I am able to load the file e.g. using read_csv. I googled the issue and it has been mentioned that potential cause is an OutOfMemory issue - I am not quite sure if this is the problem and how to fix it.
I'd be grateful if someone could point me out a way how to debug it and fix it!
Cheers
Answer: A few things:

Unless you use tiny data you should forget about local mode. It is primarily designed for testing and small scale experimentation, not for working on even moderate size data.
As it uses only a single JVM for both driver and executor code, the potential for serious fault recovery, and if processing goes AWOL you might loose a whole session (which seems to be the case here).
So if you want to test things locally on a moderate size data consider using standalone mode otherwise just downscale the dataset.
On a side note local mode uses only one processing thread. Even for testing it makes more sense to use local[n] (for n threads) or local[*] (for all available cores).
Be ready to adjust the configuration as default values are extremely conservative - for example spark.driver.memory is by default 1 GB - you might get away with it, in a standalone mode, but not when all components are embedded in a single JVM.
Don't trust sparklyr defaults.
sparklyr developers made a very unfortunate choice of eagerly caching data in memory by default. It not only goes against Spark defaults (which, for a reason, uses MEMORY_AND_DISK for Dataset API) and rarely provides any practical benefits on real size data, but also interferes with Spark optimizer in some ugly ways (most notably preventing projection and selection pushdown).
So get into a habit of using memory = FALSE whenever applicable:
spark_read_csv(sc, name = "testdata", memory = FALSE, path = ...)

Provide schema for the reader instead of using schema inference. See SparklyR: Convert directly to parquet
Comment: My personal path of choice would be to learn core (i.e. Scala API, O'Reilly has a bunch of decent books, by Spark contributors, EPFL has nice MOOC on Coursera)  and then move to sparklyr, but I realize that might not be the most appealing path. Other than that, just don't get deceived by a familiar API - it is your worst enemy here. As of moderate it is subjective and fuzzy, however you can try to compare things to the available memory - if size of the raw data is of the same order of magnitude as the available RAM I'd call it "moderate". For learning I'd use at least order of magnitude less.
Comment: Thank you very much, this is very helpful!  I see that I have to invest a lot more time into understanding this - if you would have a suggestion for an easy to understand guide or other sources, kindly let me know.

Another question: what is actualy considered tiny data when it comes to what you describe about using "local"? Is my 30mil rows/12 columns considered small/moderate or big in this context?
Cheers


Can you jump off the wall in volleyball?

Question: In indoor volleyball, the ball can not be played off of the wall. In a rec league, a ball recently was sent high and off to the side of the court. It was going to make contact with the wall about 7-8 feet up in the air, so I jumped off the wall to knock it back into the court before the ball made contact with the wall. The referee actually allowed the point, but afterwards told me that it was illegal and he should have called it.
I guess I could see this rule going either way, but I'm not convinced that this should be illegal. Does anybody have any insight?
Answer: If the wall was more than 3m from the court, my understanding is that this is a legal play. The important rules here are Rule 1, "Playing Area":

The playing area includes the playing court and the free zone
1.1 DIMENSIONS
The playing court is a rectangle measuring 18 x 9 m, surrounded by a
  free zone which is a minimum of 3 m wide on all sides.
The free playing space is the space above the playing area which is free
  from any obstructions.

Note that this means that there cannot be any walls etc in the free zone, as that as part of the playing area. Next see Rule 9.1.3, "Assisted Hit":

Within the playing area, a player is not permitted to take support from a
  team-mate or any structure/object in order to hit the ball.

(my emphasis). Outside the playing area, it is allowed to take support from structures or objects, and this is allowed by referees in accordance with the principle of "keep the ball flying".
If the wall were within the 3m free zone, then the venue would not be a valid location to play volleyball under FIVB rules. Some leagues I've played in have explicit local rules for this kind of situation (which is good and makes the question answerable: read the local rules), others have relied on the interpretation of the referee (which is slightly less good).
(All rules quotes from the 2017-2020 Rules)


Why does the relation stand?

Question: Why does it stand that if $R$ is a relation, then:
$$R \subset dom(R) \times rng(R) \subset fld(R) \times fld(R)$$
?
Comment: What's $\text{fld}(R)$? The first inclusion (which should be $\subseteq$) is by definition of the entities involved.
Comment: @GitGud LOL we used exactly the same first letters. Note that some authors (and me) use $\subset$ and $\subsetneq$ as inclusion signs for subset and proper subset resp.
Comment: @AlexR I'm aware of that, I just think it's a very bad notation and I occasionally diss it. You don't use $<$ to denote 'less than or equal' so why use $\subset$ to denote less than and possibly equal?
Comment: @GitGud Mostly convenience: Most of the time you don't have to exclude $A=B$ in inclusion. It saves us three letters or a line on the whiteboard ^^... I guess it's a matter of preference. I'm just used to the "very bad notation" and to me it seems unnecessary to do that extra bar. But you can dispute about mathematical style all day long and not come to an agreement :)
Also I often need $A \subset\subset B$, saying that I can find a compact set $K$ such that $A\subset K\subset B$.
Answer: It follows from the definition of the sets.
Each $(x,y)\in R$ is such that $x$ is in the domain and $y$ is in the range. Therefore $(x,y)\in\operatorname{dom}(R)\times\operatorname{rng}(R)$. Since the field of a relation is the union of the domain and range, the right inclusion follows immediately.
Comment: Okay thanks, @GitGud and me were wondering what that might mean^^
Comment: @evinda Not quite.
$$\mathrm{dom}(R) \times \mathrm{rng}(R) \subset (\mathrm{dom}(R) \cup \mathrm{rng}(R)) \times (\mathrm{dom}(R) \cup \mathrm{rng}(R))$$
Comment: @evinda: Yes, the two are often interchangeable (with a clear preference towards $\langle x,y\rangle$ when $(x,y)$ can be mistaken for an interval; and a preference towards $(x,y)$ when $\langle x,y\rangle$ might be mistaken with inner product).
Comment: @evinda: Yes. That is the definition of $\subseteq$.
Comment: So $\mathop{\rm fld}(R) := \mathrm{dom}(R) \cup \mathrm{rng}(R)$?
Comment: Yes, that is the definition I am familiar with.
Comment: @AsafKaragila So, when we say that $(x,y) \in dom(R) \times rng(R)$, does this mean that $x \in dom(R)$ and $y \in rng(R)$ ?
Comment: @AsafKaragila Also, how can we conclude that $dom(R) \times rng(R) \subset dom(R) \cup rng(R)$ ?
Comment: @evinda: What does it mean, at all, when you say that $(x,y)\in X\times Y$?
Comment: Asaf Karagila $X \times Y=\{\langle x,y\rangle: x \in X, y \in Y\}$.. So, we can say that $\langle x,y \rangle \in X\times Y$.. But, can we also say that $(x,y) \in X \times Y$ ?
Comment: @evinda: What is $(x, y)$ to you?
Comment: @AsafKaragila Is it an unordered pair? or am I wrong?
Comment: @evinda: Unordered pair is $\{x,y\}$.
Comment: @AsafKaragila So, with $(x,y)$ is it meant the same as with $$?
Comment: @AsafKaragila A OK... So, because each element of $R$ belongs to $dom R \times rng R$, we have that $R$ is a subset of $dom R \times rng R$, right?
Comment: @AsafKaragila I understand... Thank you very much!!!
Comment: @AsafKaragila Could I also ask you something else about set theory?
$$$$
If $x \neq y $, define the sets $\bigcup \langle x,y \rangle , \bigcup \bigcup \langle x,y \rangle$.

According to my notes, it is like that:

$$\langle x,y \rangle= \{ \{x\}, \{x,y\} \} $$

$$ \bigcup \langle x,y \rangle=\{x,y\} $$

$$ \bigcup \bigcup \langle x,y \rangle=x \cup y$$

Why is it $ \bigcup \bigcup \langle x,y \rangle=x \cup y$ and not $\bigcup \bigcup \langle x,y \rangle=\{x,y\}$ ?

Why does the relation stand?


Problems replacing values in R data frame

Question: Using Friendman1 function, I want to create a data frame replacing the Target column by values TRUE/FALSE if value is bigger than / less than or equal to 14.4.
library(mlbench)
dataset <- mlbench.friedman1(1600)
colnames(dataset$x) <- paste("Attr.", 1:10, sep="")
data <- data.frame(dataset$x, dataset$y)
colnames(data)[11] <- "Target"

data$Target[data$Target > 14.4] <- "TRUE"
data$Target[data$Target <= 14.4] <- "FALSE"

The problem is that it works find except for values < than 10.
So a head result will be:
Attr.1 ... Attr.10 Target
0.8356 ... 0.05367 TRUE
0.9723 ... 0.29951 5.7792
0.5623 ... 0.15223 FALSE

Comment: You haven't showed us your real code, because your last two lines will both not run since `data` has no column called `Target` at that point. But whatever your code _actually_ is, your problem may be that when you assign the TRUE's (and why character not boolean...?) you have coerced ALL the numeric values to character. So the next line is trying to compare things as characters, not numerically. What you want is to probably to use `ifelse`.
Comment: The moment you run this `data$Target[data$Target > 14.4] <- "TRUE"` yout variable is not numeric any more. It's tricky to compare it with another number from now on. Try `ifelse(data$Target > 14.4, "TRUE", "FALSE")`.
Comment: Yep, sorry I've changed the code to show Target attribute
Comment: As a simple example of how tricky it is to continue treating it as a numeric variable run this: `set.seed(1);
x = runif(10,0,20);
x[x>14.4] = "TRUE";
x;
x[x>14.4] = "TRUE";
x` and see what it returns each time.
Answer: Do you mean recoding all variables? May this approach could be usefull:
data %>%
  mutate_all(.,~case_when(. > 14.4 ~ TRUE, TRUE ~ FALSE))

Answer: It was solved by using ifelse function as mention joran.
data$Target <- ifelse(data$Target > 14.4, "TRUE", "FALSE")

Answer: If you want a data.table solution:
setDT(data)
data[, Target := ifelse(Target > 14.4, "TRUE", "FALSE")]

I will suggest you to not overwrite an original variable and create a different one with a a new class (character, logical, etc.)


Is common write $\lim f(2)$ instead of $\underset{x \to 2}{\lim} f(x)$

Question: I didn't saw anyone writing like it, but is it understandable? If yes why anyone write $\lim f(2)$?
Comment: "$\lim f(n)$" would make me guess the [sequential limit](https://en.wikipedia.org/wiki/Limit_of_a_sequence) $\displaystyle{\lim_{n\to\infty}}f(n)$, and not anything like $\displaystyle{\lim_{x\to n}}f(x)$.
Comment: This is not a good way to write limits. For example, the definition of the derivative would become $\displaystyle f'(x) =\lim_{h\to 0}\frac{f(x + h) - f(x)}{h} = \lim \frac{f(x + 0) - f(x)}{0}$, which is very ambiguous.
Comment: It is simply wrong for the meaning that you intend. In context one might be able to guess what was meant, but you should not make readers have to guess.
Comment: It's likely to be understood,  but I wouldn't recommed it. This is mathematics, and logic is crucial, so we should make any assumptions we made very explicit.
Comment: With $\lim f(n)$ I was wanting to say, e.g. $\lim f(2)$
Answer: No. One might say that $f(n)=\lim_{x\to n} f_1(x)$, where $f_1: \mathcal D(f) / \{n\}\mapsto \mathcal R(f)$ s.t. $f_1(x)=f(x)$ in order to extend a function $f_1$ on a domain $\mathcal D(f_1)$ piecewise across a larger domain $\mathcal D(f)$: $$f: \mathcal D(f)\mapsto \mathcal R(f) ,  f(x)=\begin{cases} f_1(x)  & x\in \mathcal D(f_1) & \\  \lim_{t\to x} f_1(t) & x\notin\mathcal D(f_1) \end{cases}$$
However, $\lim f(n)$ has no easily understandable meaning. It could be what you wish to convey, but, as the comments point out, it could also be $\lim_{n\to\infty} f(n)$.
Where notation is ambiguous, it's best to avoid it even at the cost of brevity and stick to more unambiguous notation.


Are there statistical techniques that investigate such relationships ...?

Question: If we have data set, X and Y variable. Say, we do correlation analysis and get some correlation coefficient. Besides, we find an important fact after observing their relationship: That is, the scatter plot of X and Y has a triangular shape. Which means that (for example) when X values are increasing Y values are increasing for all X values, whereas vice versa is not true; when the Y value is increasing X values are anything for all Y values.
What kind of analysis should I do to investigate this?

(Update in response to @Penguin_Knight)
Your graph is exactly what I explained. Just take away the negative values with an imaginary y=0 line. As you can see there are many data points the X of which is either 0 or very small, and Y has pretty high value. However there is no data point that have y=0 and x is quite high value. And as you can see it makes the data scatter shape a right angle triangle. Thus we could say that the high X values necessitates high Y values but high Y values does not always have high X values. I find it very interesting. In practice for example I measure Complexity and Size of given entities. And my analysis show that all complex entities have big size but not all big-size entities are complex. Then I conclude that the certain amount of complexity requires defined amount of size. You cannot put more complexity in a given size. This is a bit abstract but you see my point? It is very interesting and I would like to get some help on how this kind of relationships are discussed or described in statistics formally.
Comment: A scatter might be useful (I've problems seeing the distribution from your description).
Comment: His user icon looks a bit like a scatter-plot triangle, oddly enough.
Answer: Sorry, can't wrap my head around it...
From the plot above (the red line is when x = y)... I can see your first condition where when x increases, y can only increase. But I don't understand given the first condition, how can "X values are anything for all Y values."
Please post your scatter plot, while I'll go prepare some popcorn.
Answer: Typically, to say a scatterplot has triangular shape, it would have to look like this: /\. What you are describing sounds like this: /.
The part about Y~X being positively correlated in the plot, and X~Y not, is IMPOSSIBLE. Please check your code, or the description.
In general you can use a regression model to model a relationship between a ratio scaled X and Y. Look up the assumptions for different regression models in a book or on the Wiki.
Answer: The question is rather vague. From your description, the only case where I can imagine the scatterplot to look like a triangle (and fit the description), is a case where the variance of the Y increases with the X values. The scatter plot would appear something like:
<code>|           .
|         ...
|       .....
|    ........
|  ......
|....
+----------------
</code>
What is the aim of your analysis? If you're trying to predict the Y from the X, you might want to take the increasing variance into account during the analysis using something like generalized least squares or other such methods. If you want to find other such cases from a larger data set that contains several X variables, as crude solution you might consider calculating, e.g., a range or variance of the Y variable along the X variable. Generating all the possible plots, and eyeballing them for interesting patterns might be a viable option, also.
Answer: It sounds like the lower bound on y is a function of x. Something like this?


why the uniform norm in C[a,b] is invariant under linear transformation?

Question: I am trying to prove that the uniform norm in the space $C[a,b]$ is invariant under linear transformation $t=\alpha\tau+\beta$. About the context: The problem arises when I want to prove that this space can't be a Hilbert space.
I have a lot of doubts about how to show this, but I think that if I can prove that $C[a,b]$ and $C[c,d]$ are isometric for all values $a,b,c,d$ with $b>a$ and $d>c$, then the norm would also be invariant, because the norm is the distance between the vector $x$ and the vector $0$.
Without loss of generality, I already have a proof that $C[a,b]$ and $C[0,1]$ are isometric [available in the MHF][1], nevertheless I think that there is a step that is not completely justified. The outline of the proof is as follows:

Looking for an inyective function $F$ from $C[a,b]$ into $C[0,1]$, for example, you choose $F$ such that $F(u)=u((bt+(1-t)*a)$. Here you take a function $u$ which is an element of $C[a,b]$ and, using $F$ this $u$ becomes an element of $C[0,1]$.
Lets take  $u,w$ in $C[a,b]$ and $F$ allows to take  $F(u),F(w)$ in $C[0,1]$, now $d_{C[a,b]}(u,w)=\max_{t\in[a,b]} |u(t)-w(t)|=\max_{t\in[0,1]}|u(bt+(1-t)a)-u(bt+(1-t)a)|=d_{C[0,1]}(F(u),F(w))$

My doubt lies in that I do not know because they say that distances are the same. Is reasoning so obvious, or is there something extra to justify there?. Does the construction of $F$ contain all the justification?
The next step is to use this proof on $\tilde{x}(\tau)=1$ and $\tilde{y}(\tau)=1$, where $\tau\in{}[0,1]$ for to prove that this metric space can not be a Hilbert space, through the use of parallelogram equality.
Thanks very much.
PD: Excuse me, I'm not very good at writing in English.
Comment: Is your question about part 2?
Comment: What does MHF mean?
Answer: You map $C[a,b]$ onto $C[c,d]$ by $Tf(x) = f(\tau(x))$ where $\tau$ is a homeomorphism of $[c,d]$ onto $[a,b]$.  An affine map $\tau$ will do.  Then it's obvious that the same values are taken by $f$ and $Tf$, and thus that the supremum norms are the same.


Use responsive images inline

Question: I can see that using styles on inline images have been left out for some reason. But when I need to make the site behave a little more responsive.
I have been looking after CKeditor plugins that could select a style for the image being include. But I haven't found any.
I have been looking after at comment on the Drupal 7 Picture module that should be what is the base for the implementation of Responsive Images in Drupal 8. But there is nothing about inline images to find - just old Drupal 7 demos on how it should work.
Any idea how to get responsive images or just a basic image style for images include in inline editor on Drupal 8?
Comment: you could use https://www.drupal.org/project/inline_responsive_images
This module does what you want
Comment: https://www.drupal.org/node/2061377 is the issue to fix it in core, there is a patch, might need reroll
Comment: Yes I found that page to but it says "last submitted patch, 124: 2061377-124-wysiwyg-image-styles.patch, failed testing" - and Wim Leers rant pretty much says that it isn't there yet.
Comment: This seems like the most precise answer and my conclusion right now is to wait with the proper resizing of the inline images and wait for the issue to be fixed in core.
Answer: The module Entity Embed will be able to do that. There is now a dev version available, but you better wait for the first alpha/beta-release.
Even longer it will take, until this is in core:
Allow image style/responsive image mapping to be selected in Text Editor's image dialog
This is postponed to drupal 8.1
Until then you can use jquery to move the image from an image field to an empty container in the body. To avoid flicker effects, add a style display:none in the twig template of that specific image field and show it after moving it into the body in jquery.
Comment: Do you have a example on how the solution with jquery is done? It does sound a little hard to get the order of the images in place, when you have a list of fields images and a number of placeholder in the content.

On the other hand I am trying to achieve a progressive loading of the images too. And what you suggest sounds like it could be a part of a solution.
Comment: First seperate each node with `$('article').each`, then transfer inside each article the image fields to the body with `.find` and `append`. If you have a lot of images, you better use custom tokens in the body, that you replace in a hook_entity_view with the empty container, that you can identify later in your jquery. So that the author only has to put the token in the body and the rest is done by your code.
Comment: It seems that the solution with Entity Embed is embedding a whole node - which from a performance standpoint is a step in the wrong direction. I will go with a fixed image size for now. And then make a poor mans responsive behavior with styling. And then wait for Drupal 8.1 to get it right.
Comment: I've tested the dev version of Entity Embed some month ago. This will be a great module, when it is ready. It is not restricted to nodes. You can place all entities inline in CKeditior, including images and you can apply all kind of rendering that is availiable for the entitity, including image styles.
Comment: I'll have to try it one more time. Just embedding images sounds great. When I tested Yesterday the first step asked me for the name of the node I wanted to include.
Comment: You first have to configure a button for each entity, before you can use it in the ckeditor, as far as I can remember. Later this will be integrated with Entity Browser, then this will be a whole package for uploading and embedding images in ckeditor.
Answer: Add the css code into "/themes/bootstrap/css/3.3.x/overrides.min.css"
<code> img {
    display: Block;
    max-width: 100%;
    height: auto;
 }
</code>
Answer: You can add the class="img-responsive" in  the image tag it will responsive automatically. Hope its will work for you.

Use responsive images inline


How to detect and restart program that uses 100% CPU?

Question: The program autokey have a very annoying bug which makes it take up 100% of a CPU core after a few days of running.
If I use top and kill the process with k then it restarts and is fine for another few days.
$ ps ax|grep autokey
 1074 ?        S      0:00 python /etc/rc2.d/S20autokey start
17606 pts/1    S+     0:00 grep autokey

Question
How do I detect when it is maxing out a CPU core, and then restart from a cron script?
Answer: You usually would use a system like monit or something similar to handle this.
In a case like autokey (do you mean this?) I would just use a cronjob that restarts the process every night no matter what if it really always hanging after a few days of run time. This is OK as the program clearly is nonessential. Also, file a meaningful bug report.


Riemannian measure and Hausdorff measure in a general Riemannian Manifold

Question: Let $ M $ be a Riemannian manifold and let $ \mu $ be its Riemannian measure. This is the measure obtained by Riesz reprersentation theorem such that for every continuous function with compact support $ f $
$ \int_M f d\mu = \sum_i^n \int_{U_{i}}(\rho_i\sqrt{G_i}f)\circ \phi_i^{-1}dx $
where $ (U_i,\phi_i ) $ is a finite covering of $ supp f $, $ \rho_i $ is a partition of unity subordinated to $ U_i $ and $ G_i $ is the determinant of the metric of $ M $ in the $ \phi_i $ -coordinates.
If $ M=R^n $ is the standard euclidean space then $ \mu = L^n $, where $ L^n $ is the Lebesgue measure.
On the other hand on $ M $ (not necessarily equal to $ R^n $) we can define the $ n-$dimensional Hausdorff measure $ H^n $. It is a standard result that if $ M= R^n $ then $ \mu=L^n=H^n $.
Now the question: is it true that $ \mu=H^n $ for every Riemannian manifold $ M $?
Thanks
Comment: I would guess they are equal. You only need to show that they coincide on chart domains (being $\sigma$-finite measures, and using the "monotone class" theorem).
Comment: Just take a chart domain $U$, and use the fact that the distance function induced by the riemannian metric (on any compact subset $K$) will be bounded above and below by the standard euclidean distance:
$$c d_{std}\leq d_g\leq Cd_{std}$$ where $0<c<C$ depend on the compact subet $K\subset U$. Using the definition of the Hausdorff measure we have that the Hausdorff measure of $K$ with the metric induced by $g$ on $U$ is at most $C$ times the standard Lebesgue measure of $K$. Since $M$ is covered by a sequence of compact subsets, the Hausdorff measure will be $\sigma$-finite.
Comment: We know that $ H^n $ is Borel regular (actually it holds in every metric space). If we prove that $ H^n $ is also finite on compact sets we conclude that $ H^n $ is $ \sigma$-finite. But i'm not sure that it is easy....
Comment: Actually I'm not sure they are equal, but to tackle the problem the above approach should work.
Answer: Yes, you can reduce the problem to the Euclidean case using normal coordinates, working along the lines of the comments by Olivier Bégassat, but with $c\approx C\approx 1$. Precisely, given $\epsilon>0$, you can use the normal coordinates to cover the manifold by patches $(U_i,\phi_i)$ such that

the metric tensor in these coordinates is $\delta_{ij}+O(\epsilon)$
the pushforward of the Lebesgue measure under $\phi_i^{-1}$ is comparable to $\mu$ to within the factor $1+O(\epsilon)$. (This is  a consequence of 1.)

Property 1 allows you to compare the Hausdorff measures on $M$ and on $\mathbb R^n$, while property 2 compares Riemannian and Lebesgue measures. It follows that within each patch on $M$ the Hausdorff and Riemannian measures agree up to a factor of $1+O(\epsilon)$. Since $\epsilon$ was arbitrary, the measures are equal.