ON taylor coefficients for a function with singularities

Question: we know Taylor series coefficients are given by
$$ a(n)= \frac{1}{n!}\frac{d^{n}}{dx^{n}}f(0) $$
then my question is if we want the taylor series involving the term $ 1/x$
could i use the limit $$ a(-1)= \frac{1}{\Gamma(-1)}\frac{d^{-1}}{dx^{-1}}f(0)$$
taking the limit of this expression as $ x--> 0 $
Answer: If you have some function with a simple pole at $0$, it is sufficient to find the limit $a(-1)=\lim_{x\to 0}xf(x)$. If there are poles of higher order, you need to start with the highest order pole. If you have a highest-order pole $x^{-n}$, we get that $a(-n)=
lim_{n\to 0}x^nf(x)$. Then, remove the pole by subtracting $\frac{a(-n)}{x^n}$ from $f$ and repeat the process.


Como funciona a função "next" no Angular?

Question: Segue o exemplo:
@Output() exemplo = new Subject<{ valor1: number, valor2: number }>();

this.exemplo.next({ valor1: _valor1, valor2: this.valor });

O que está acontecendo aqui?
É passado um objeto como parâmetro?
Comment: Na verdade acredito que isto tenha mais a ver com [Generators](https://pt.stackoverflow.com/questions/91400/com-fazer-um-iterator-generator-no-javascript) do que com Angular propriamente dito
Comment: Apenas com este código não tem como afirmar nada, o método **next()** no **`Angular`** pode ser aplicado em diversos contextos, ele pode ser executado a partir de um Observable, ou em um Subject por exemplo, isso já explica alguma coisa, pois ambos ficam "observando" alterações em algum valor declarado.
Comment: Acrescentei uma linha de código ao exemplo. Parece que tem o Subject.
Answer: Ao instanciar um Subject é necessário informar qual o tipo de dado que irá trabalhar, por exemplo: new Subject<number>();. No seu exemplo o tipo de objeto que o Subject irá trabalhar é um objeto com a seguinte estrutura: { valor1: number, valor2: number }, ou seja, o objeto deverá ter dois campos do tipo number com os nomes "valor1" e "valor2".
Ao utilizar a função next você emite um valor para os subscribers, em outros termos mais simples, você publica um valor para quem estiver ouvindo.
Veja este pequeno exemplo retirado da documentação:
import { Subject } from 'rxjs';

const subject = new Subject<number>();

subject.subscribe({
  next: (v) => console.log(`observerA: ${v}`)
});
subject.subscribe({
  next: (v) => console.log(`observerB: ${v}`)
});

subject.next(1);
subject.next(2);

// Logs:
// observerA: 1
// observerB: 1
// observerA: 2
// observerB: 2

Se quiser se aprofundar no assunto:

https://firstname.lastname@example.com/angular-rxjs-cold-e-hot-observable-557f04cb2e3d
https://rxjs-dev.firebaseapp.com/guide/subject


Question about direct sum of function space

Question: I am reading Applied linear algebra: the decoupling principle by Lorenzo Adlai Sadun (btw very recommendable!)
On page 30 about direct sums on vector spaces it says:

Let $V$ be the space of continuous functions on a domain $U \subset \mathbb R^3$. Then $V \oplus V \oplus V$ is the space of continuous $\mathbb R^3$-valued functions on $U$.

What I don't understand is how this threefold direct sum of $V$ can lead to a statement about the codomain ("-valued" functions). But I just guess that I don't get it altogether - please enlighten me. Thank you!
EDIT
I think what confuses me most is that we start with $\mathbb R^3$ and end up with it. It would come more natural if we started with $\mathbb R$ and after taking the direct sum three times would end in $\mathbb R^3$.
Comment: The first instance of $R^3$ is the domain and $R$ is the co-domain, in the second instance, both are $R^3$.
Comment: A function to $\mathbb R^3$ is continuous iff its component scalar valued functions are continuous
Comment: @Dactyl: Could you please elaborate? So I don't get it...
Answer: In fact, the domain $U$ does not play an actual role here, specifying that it is a subset of $\mathbb R^3$ is just adding to the confusion, in my opinion.
First let us establish that $V$ is indeed a vector space. $f\in V$ if and only if $f\colon U\to\mathbb R$ and $f$ is continuous.
If $f\in V$ and $\alpha\in\mathbb R$ then $g(x) = \alpha\cdot f(x)$ is indeed a continuous function whose domain is $U$ and codomain $\mathbb R$, and if $f,g\in V$ then the function $h(x) = f(x) + g(x)$ is also a continuous function whose domain is $U$ and codomain is $\mathbb R$.
Now, the definition of $V\oplus V\oplus V$ is simply $\{(f,g,h)\mid f,g,h\in V\}$.
Suppose $(f,g,h)\in V\oplus V\oplus V$, then it defines a function: $h(x) = ( f(x), g(x), h(x))$. The function $h$ is continuous if and only if it is continuous in every coordination, and since $f,g,h$ are all continuous then so is $h$.
Since the domain of $f,g,h$ is $U$, then $h\colon U\to\mathbb R^3$, as it takes a point in $U$ and returns a vector in $\mathbb R^3$.
On the other hand, if $h$ is a continuous function from $U$ to $\mathbb R^3$, then $h(x) = (h_1(x), h_2(x), h_3(x))$, and $h_i$ are continuous functions from $U$ to $\mathbb R$, so $h_1,h_2,h_3\in V$ as needed.
Answer: The space $V\oplus V \oplus V$ is nothing else than the set of triples
$$ (v_1,v_2,v_3) $$
where
$$v_1,v_2,v_3\in V.$$
So the set $U$ is being mapped to 3-component objects which I will call "vectors". Each element $P$ of $U$ is assigned a 3-component vector $(v_1(P), v_2(P), v_3(P))$. The continuity of a vector-valued function, as Dactyl pointed out, means that each of the components of the vector is a continuous function. Indeed, it means that each $v_i$ among the three components is an element of $V$.
One may either say that it is a definition of the continuity of vector-valued functions.
Equivalently, one may define the continuity in this case by looking at balls in the space ${\mathbb R}^3$ into which we're mapping things. But in the manipulation with $\epsilon$ and $\delta$, balls are equivalent to little cubes - one may squeeze a ball inside a cube or vice versa (at least for finite dimensions such as 3), so we may equivalently replace the balls by the cubes, and then the definition of continuity using balls gets reduced to that of the cubes, i.e. to the component-wise continuity.
At any rate, the continuity of 3-component functions is either defined as - or may be proved to be - the continuity of each component.
Comment: I think what confuses me is that we start with $\mathbb R^3$ and end up with it. It would come more natural if we started with $\mathbb R$ and after taking the direct sum three times would end in $\mathbb R^3$.
Comment: Dear @vonjd, your problem already starts with ${\mathbb R}^3$: the first sentence says that $V$ itself are functions from $U$ which is a subset of ${\mathbb R}^3$. $V$ itself are functions that take value in ${\mathbb R}$ and $V\oplus V\oplus V$ are functions from ${\mathbb R}^3$ to another ${\mathbb R}^3$. But functions from ${\mathbb R}$ never appear in your problem at all so I don't understand in what sense it would be "natural". Real numbers and their 3rd power are equally natural but only the latter appear in your problem. The tripling only affects the value of the function not the domain
Answer: What is unclear in the exposition is just exactly what the author means by "the space of continuous functions on a domain $U\subseteq \mathbb{R}^3$."
What he means is that $U$ is the vector space of real-valued continuous functions with domain $U\subseteq\mathbb{R}^3$; that is, the elements of $U$ are function $f\colon U\to\mathbb{R}$ that are continuous, with $U\subseteq \mathbb{R}^3$. (He omits "real valued" when he says "functions").
That means that an element of $V\oplus V\oplus V$ consists of a $3$-tuple of real valued functions, $(f_1,f_2,f_3)$, with $f_i\colon U\to\mathbb{R}$. Thus, the tuple is naturally interpreted as a function from $U$ to $\mathbb{R}^3$ in which each component is continuous.
Answer: I guess you can identify the space of continuous functions on $U$ that take values in $\mathbb{R}$ with subspaces of the space of continuous functions on $U$ that take values in $\mathbb{R}^3$ by isomorphisms of type $x\mapsto (x,0,0)$, $x\mapsto (0,x,0)$, $x\mapsto (0,0,x)$. In this view the book's assertion may look more natural, because now you're indeed having the direct sum of subspaces of a given space.
Comment: I think what confuses me is that we start with $\mathbb R^3$ and end up with it. It would come more natural if we started with $\mathbb R$ and after taking the direct sum three times would end in $\mathbb R^3$.
Comment: @vonjd: it all depends on how the author talks about direct sum. When I took LA, direct sums where defined for subspaces of a given linear space. But generally in algebra you can talk about direct sums as structures defined on $V_1\times ... \times V_n$, where the operation(s) is defined as is most natural (e.g., $(v_1,...,v_n)+(w_1,...,w_n)=(v_1+w_1,...,v_n+w_n)$). But in the end, these approaches are pretty much the same.
Answer: I know that this question is 9 years old, but the other answers didn't help my tiny brain. If someone comes across like I did, I hope this helps!
Let $C(\mathbb{R}^3)$ denote the space of continuous functions with domain $\mathbb{R}^3$.  Let $V \subset C(\mathbb{R}^3)$ be defined by $V := \{f \in C(\mathbb{R}^3) : f:U\subset \mathbb{R}^3 \rightarrow \mathbb{R}\}$. Then $V$ is simply the subspace of  $C(\mathbb{R}^3)$ where each function is restricted to $U$.
The direct sum $$V\oplus V \oplus V := \{ (f_1,0,0)+ (0,f_2,0) + (0,0,f_3) : f_i \in V\} = \{(f_1,f_2,f_3) : f_i \in V\}$$
is simply the tuple of continuous functions on the domain $V$. In otherwords, you give me an $(x_1,x_2,x_3) \in U \subset \mathbb{R}^3$ and I give you back $(f_1(x_1,x_2,x_3),f_2(x_1,x_2,x_3),f_3(x_1,x_2,x_3))$. Hence, elements of the direct sum are the maps
$$[ (x_1,x_2,x_3) \mapsto(f_1(x_1,x_2,x_3),f_2(x_1,x_2,x_3),f_3(x_1,x_2,x_3))] \in V \oplus V \oplus V$$
This is what is meant by $(f_1,f_2,f_3)$.


How to Capture Request and Response in testSuite TearDown using groovy

Question: I have a testSuite with lets say 5 cases, i run the cases from my testSuite.
In my tear down script I want to capture all request and response of all testcases all test testSteps.
Below is the code I have written in tearDown TestSuite, problem in context.expand is returning empty. I assume testCase context is require, or not sure where i am going wrong.
tc_list = testSuite.getTestCaseList()
tc_count = tc_list.size()
for(i=0;i<tc_list.size();i++){
    if(!tc_list[i].isDisabled()){

        ts_list =  tc_list[i].getTestStepList()

        for(j=0;j<ts_list.size();j++){
            req = testSuite.getPropertyValue("reportpath")+'/'+testSuite.getName()+'/'+tc_list[i].getName()+'/'+ts_list[j].getName()+'_RequestData.txt'
            res = testSuite.getPropertyValue("reportpath")+'/'+testSuite.getName()+'/'+tc_list[i].getName()+'/'+ts_list[j].getName()+'_ResponseData.txt'

            def request_expand = context.expand('${'+ts_list[j].getName()+'#Request}')
            log.info '${'+ts_list[j].getName()+'#Response}'+tc_list[i].getName()
               def response_expand = context.expand('${'+ts_list[j].getName()+'#Response}')
              log.info response_expand

             /* def req_file = new File(req)
               req_file.write(request_expand,"UTF-8")
               def res_file = new File(res)
               res_file.write(response_expand,"UTF-8") */

            }
        }

    }

Comment: Are you using open source edition? or Pro? Usually it captures request and response for the failed steps. Do you those irrespective of the result status?
Answer: @Ragesh kr
Whenever any time in Soap ui or Ready API you need RawRequest or RawResponse
you can just replace Request with  RawRequest
                 and Response with RawResponse
i just did in your code and it worked
        def request_expand = testSuite.getTestCaseByName(tc_list[i].getName()).getTestStepByName(ts_list[j].getName()).getPropertyValue("RawRequest")
        def response_expand = testSuite.getTestCaseByName(tc_list[i].getName()).getTestStepByName(ts_list[j].getName()).getPropertyValue("RawResponse")

Some other examples to help everyone
When we just need request and response in soapui we can use below

When we just need RawRequest and RawResponse in soapui/ReadyaPI via groovy we can use below
 req=context.expand('${RequestStepName#RawRequest}')
 log.info req
 res=context.expand('${RequestStepName#RawResponse}')
 log.info res

Answer: The Below code worked for me. But I am still trying to capture rawRequest and rawResponse, which is still not achieved
tc_list = testSuite.getTestCaseList()
tc_count = tc_list.size()
for(i=0;i<tc_list.size();i++){
    if(!tc_list[i].isDisabled()){

        ts_list =  tc_list[i].getTestStepList()

        for(j=0;j<ts_list.size();j++){

            req = testSuite.getPropertyValue("reportpath")+'/'+testSuite.getName()+'/'+tc_list[i].getName()+'/'+ts_list[j].getName()+'_RequestData.txt'
            res = testSuite.getPropertyValue("reportpath")+'/'+testSuite.getName()+'/'+tc_list[i].getName()+'/'+ts_list[j].getName()+'_ResponseData.txt'

            def request_expand = testSuite.getTestCaseByName(tc_list[i].getName()).getTestStepByName(ts_list[j].getName()).getPropertyValue("Request")
            def response_expand = testSuite.getTestCaseByName(tc_list[i].getName()).getTestStepByName(ts_list[j].getName()).getPropertyValue("Response")
            def req_file = new File(req)
            def res_file = new File(res)
            log.info testSuite.getTestCaseByName(tc_list[i].getName()).getName()+' '+testSuite.getTestCaseByName(tc_list[i].getName()).getTestStepByName(ts_list[j].getName()).getName()+' '+response_expand
            if(request_expand!=null && response_expand!=null){

                 log.info testSuite.getTestCaseByName(tc_list[i].getName()).getName()+' '+testSuite.getTestCaseByName(tc_list[i].getName()).getTestStepByName(ts_list[j].getName()).getName()+' '+response_expand

               req_file.write(request_expand,"UTF-8")

               res_file.write(response_expand,"UTF-8")
                }

            }
        }

    }


SIGSEGV error when attempting to acsses 2d array

Question: I am tring to make a simple transpose func on an r*r matrix. In my code below, when i get to the line temp = mat[i][j] I get SIGSEGV.
but I dont really get why. Any tips would be appreciated.
void transpose(int** mat, size_t col)
{
 int i = 0;
 int j = 0 ;

 for(i= 0; i< col; ++i)
 {
    for(j = i ; j< col; ++j)
    {
        int temp = mat[i][j];
        mat[i][j] = mat[j][i];
        mat[j][i] = temp;
    }
 }
}
void printMat(int* arr, int size)
{
 int i = 0;
 for(i = 0 ; i< size*size ;++i)
 {
    printf("%d| ", arr[i]);
    if((1+i)%size == 0)
    {
        printf("\n");
    }
 }
}
int main()
{
 int arr[][3] = {{1,2,3},{4,5,6},{7,8,9}};
 printMat((int*)arr, 3);
 transpose((int**)arr, 3);
 printMat((int*)arr, 3);

return 0;
}

Comment: Why are you slamming hard casts on that variable to make it fit into functions otherwise-not-designed for arrays of arrays ?... *repeatedly* ? fyi `int ar[x][y]` is **not** synonymous with `int **`, and all the casting in the world isn't going to change that. The error you were getting (and covered up with the hard casts) was there for a reason. Casting like this is C is almost never required, and if you're just starting out in the language it is a near-guarantee you're doing something wrong.
Comment: Where is `arr` defined?
Comment: sorry, it accidentally didn't make my original post - in main. @AndrewHenle
Comment: Did you try using GDB or [Valgrind](http://valgrind.org) ?
Comment: i used gdb and got :Program received signal SIGSEGV, Segmentation fault.
0x00005555555548a6 in transpose (mat=0x7fffffffe030, col=3) @Jean-MarcZimmer
Comment: i dont want to define N in transpose(arr[]N] mat, int col) what do you suggest? @WhozCraig
Comment: C toolchains nearly all support VLAs (ex of one that doesn't: MSVC), so if you flip the order of your arguments you can do what you seek without forcing N externally. [Like this](https://ideone.com/BCqmpa).
Comment: `col=3` : Well it's trying to access the fourth row in the table/the fourth cell in the row. Now the question is : how the hell did `i` or `j` increment up to 3 ?
Comment: @WhozCraig I don't really understand what you mean - Not like this right:   void transpose(size_t col, int** mat)
Comment: This is a common FAQ. See for example https://stackoverflow.com/questions/42094465/correctly-allocating-multi-dimensional-arrays
Comment: performance tip: if `i==j` there is no benefit to swapping `mat[i][j]` with `mat[j][i]`
Answer: void transpose(int** mat, size_t col) is saying you have a pointer to an array of pointers.
But the array is a single piece of memory
change void transpose(int** mat, size_t col) to
void transpose(int mat[][3], size_t col)

will work
Comment: Thank you- but i'm trying to avoid having to define that 3 in the function, i would rather not use a Define N 3 in my file or a literal 3 in func declaratin. is there another way?
Comment: what with `int mat[][]` ?
Answer: If you're using a native array of arrays of int, you can't force-feed it to a function expecting a pointer to a sequence of pointers. All of those hard casts are a clear-and-present indicator you're doing something wrong. Whoever told you int[N][M] is synonymous with int** was lying; they're not.
Most toolchain vendors support VLAs (variable length arrays) in C in automatic variable locations, including function arguments. The only requirement is the size must precede the array in the argument list:
#include <stdio.h>

void transpose(size_t siz, int mat[][siz])
{
    for(size_t i= 0; i< siz; ++i)
    {
        for(size_t j = i ; j< siz; ++j)
        {
            int temp = mat[i][j];
            mat[i][j] = mat[j][i];
            mat[j][i] = temp;
        }
    }
}

void printMat(size_t siz, int const arr[][siz])
{
    for(size_t i=0; i<siz; ++i)
    {
        for (size_t j=0; j<siz; ++j)
            printf("%d| ", arr[i][j]);
        fputc('\n',stdout);
    }
}

int main()
{
    int arr[][3] = {{1,2,3},{4,5,6},{7,8,9}};
    printMat(3, arr);
    transpose(3, arr);
    printMat(3,arr);

    return 0;
}

Output
1| 2| 3|
4| 5| 6|
7| 8| 9|
1| 4| 7|
2| 5| 8|
3| 6| 9|

See it live.
Comment: @H.cohen Don't try this with any MS compiler. To this day they don't support VLAs in any flavor of their C toolchain. clang, gcc, icc, all *do* support them.
Comment: @H.cohen Bummer =(. Well, hopefully it will help in the future.
Comment: Thank You SO MUCH!
Comment: I am using gcc but also compiling with ansi so i can't apply this to my program BUT- i if decide not to this is very helpful
Answer: So, I was thinking about how the 2D array is set in the memory, the col are needed to let the compiler know how many ints (in this case) to skip over between the rows, but in fact A 2D array is simply set as a regular array in the memory, a continuous block of memory.
So- if I want to "move" between the rows I can simply calculate the offset myself. For example- the element mat[1,0] is set in the mat[col_num*1 +0] if I ask the compiler to look at mat as an ordinary int array.
The reason I wanted to set my function this way is that I wanted this function to work without having to #define col 3, or set it as a literal int the function definition (int mat[][3]). keeping in mind the int mat[][3] I declared in main will have to be casted into (int*)mat when calling the function, this works:
void TransposeOfD2Array(int* mat, size_t col)
{
    int i = 0;
    int j = 0;

   for(i= 0; i< col; ++i)
   {
     for(j = i ; j< col; ++j)
     {
     int temp = mat[(col*i)+j];
       mat[(col*i)+j] = mat[(col*j)+i];
       mat[(col*j)+i] = temp;
     }
   }
}
void printMat(int* arr, int size)
{
  int i = 0;
  for(i = 0 ; i< size*size ;++i)
  {
     printf("%d| ", arr[i]);
     if((1+i)%size == 0)
     {
         printf("\n");
     }
  }
}
int main()
{
   int mat[][3] = {{0,1,2},{3,4,5},{6,7,8}};
   TransposeOfD2Array((int*)mat, 3);
   printMat((int*)mat, 3);
   return 0;
}


Message order with Kafka Connect Elasticsearch Connector

Question: We are having problems enforcing the order in which messages from a Kafka topic are sent to Elasticsearch using the Kafka Connect Elasticsearch Connector. In the topic the messages are in the right order with the correct offsets, but if there are two messages with the same ID created in quick succession, they are intermittently sent to Elasticsearch in the wrong order. This causes Elasticsearch to have the data from the second last message, not from the last message. If we add some artificial delay of a second or two between the two messages in the topic, the problem disappears.
The documentation here states:

Document-level update ordering is ensured by using the partition-level
  Kafka offset as the document version, and using version_mode=external.

However I can't find any documentation anywhere about this version_mode setting, and whether it's something we need to set ourselves somewhere.
In the log files from the Kafka Connect system we can see the two messages (for the same ID) being processed in the wrong order, a few milliseconds apart. It might be significant that it looks like these are processed in different threads.  Also note that there is only one partition for this topic, so all messages are in the same partition.
Below is the log snippet, slightly edited for clarity. The messages in the Kafka topic are populated by Debezium, which I don't think is relevant to the problem, but handily happens to include a timestamp value. This shows that the messages are processed in the wrong order (though they're in the correct order in the Kafka topic, populated by Debezium):
[2019-01-17 09:10:05,671] DEBUG http-outgoing-1 >> "
{
  "op": "u",
  "before": {
    "id": "ac025cb2-1a37-11e9-9c89-7945a1bd7dd1",
    ... << DATA FROM BEFORE SECOND UPDATE >> ...
  },
  "after": {
    "id": "ac025cb2-1a37-11e9-9c89-7945a1bd7dd1",
    ... << DATA FROM AFTER SECOND UPDATE >> ...
  },
  "source": { ... },
  "ts_ms": 1547716205205
}
" (org.apache.http.wire)

...

[2019-01-17 09:10:05,696] DEBUG http-outgoing-2 >> "
{
  "op": "u",
  "before": {
    "id": "ac025cb2-1a37-11e9-9c89-7945a1bd7dd1",
    ... << DATA FROM BEFORE FIRST UPDATE >> ...
  },
  "after": {
    "id": "ac025cb2-1a37-11e9-9c89-7945a1bd7dd1",
    ... << DATA FROM AFTER FIRST UPDATE >> ...
  },
  "source": { ... },
  "ts_ms": 1547716204190
}
" (org.apache.http.wire)

Does anyone know how to force this connector to maintain message order for a given document ID when sending the messages to Elasticsearch?
Comment: How many partitions are there in your topic? What is your partition key?
Comment: There is one partition and the key is a JSON representation (generated by Debezium) of a single UUID value which is the primary key of a row in a Postgres database, e.g. `{ "id": "ac025cbe-1a37-11e9-9c89-7945a1bd7dd1" }`
Comment: How many `tasks.max` do you have configured for the connector?
Comment: `tasks.max` is `1` for both the Elasticsearch connector and the Debezium connector. (The Debezium connector reads data from Postgres and puts it into the Kafka topic; this is then sent to Elasticsearch by the Elasticsearch connector.)
Answer: The problem was that our Elasticsearch connector had the key.ignore configuration set to true.
We spotted this line in the Github source for the connector (in DataConverter.java):
final Long version = ignoreKey ? null : record.kafkaOffset();

This meant that, with key.ignore=true, the indexing operations that were being generated and sent to Elasticsearch were effectively "versionless" ... basically, the last set of data that Elasticsearch received for a document would replace any previous data, even if it was "old data".
From looking at the log files, the connector seems to have several consumer threads reading the source topic, then passing the transformed messages to Elasticsearch, but the order that they are passed to Elasticsearch is not necessarily the same as the topic order.
Using key.ignore=false, each Elasticsearch message now contains a version value equal to the Kafka record offset, and Elasticsearch refuses to update the index data for a document if it has already received data for a later "version".
That wasn't the only thing that fixed this. We still had to apply a transform to the Debezium message from the Kafka topic to get the key into a plain text format that Elasticsearch was happy with:
"transforms": "ExtractKey",
"transforms.ExtractKey.type": "org.apache.kafka.connect.transforms.ExtractField$Key",
"transforms.ExtractKey.field": "id"


Is there a general method for simulating data from a formula or analysis available?

Question: De novo simulation of data from an experimental design data frame.
With a focus on R (though other language solution would be great).
In designing an experiment or a survey, simulating data and conducting an analysis on this simulated data can provide terrific insight into advantages and weaknesses of the design.
Such an approach can also be essential to the understanding and proper use of statistical tests.
However, this process tends to be somewhat tedious and many are led to skip past this important step in an experiment or survey.
Statistical models and test contain most of the information required to simulate the data (including an assumption or an explicit statement of the distribution).
Given an an analysis model (and its associated assumptions eg. normality and balance), the levels of a factor and a measure of significance (such as p-value), I would like to obtain simulated data (ideally with a generalized function akin to print(), predict(), simulate()).
Is such a generalized simulation framework possible?
If so, is such a framework currently available?
Example, I would like a function, such as:
 sim(aov(response~factor1+factor2*factor3),
          p.values=list(factor1=0.05,
                        factor2=0.05,
                        factor3=0.50,
                        factor2:factor3=0.05),
          levels=list(factor1=1:10,
                      factor2=c("A", "B", "C"),
                      factor3=c("A", "B", "C")))

ie, a generalized version of:
sim.lm<-function(){
library(DoE.base)
design<-fac.design(nlevels=c(10,3,3),
                   factor.names=c("factor1", "factor2", "factor3"),
                   replications=3,
                   randomize=F)

response<-with(design, as.numeric(factor1)+
                      as.numeric(factor2)+
                      as.numeric(factor3)+
                      as.numeric(factor2)*as.numeric(factor3)+
                      rnorm(length(factor1)))

simulation<-data.frame(design, response)}

OR
sim(glm(response~factor1+factor2*factor3, family=poisson),
         p.values=list(factor1=0.05,
                       factor2=0.05,
                       factor3=0.50,
                       factor2:factor3=0.05),
         levels=list(factor1=1:10,
                     factor2=c("A", "B", "C"),
                     factor3=c("A", "B", "C")))

OR
  library(lme4)
  sim(lmer(response~factor1+factor2 + (factor2|factor3)),
           F_value=list(factor1=50,
                        factor2=50),
           levels=list(factor1=1:10,
                       factor2=c("A", "B", "C"),
                       factor3=c("A", "B", "C")))

that would create a complete corresponding data.frame
potential examples of specific functions (please edit at will)
 - arima.sim
function exist to create a data.frame of the factor levels, without the modelled response:
eg. conf.design
http://cran.r-project.org/web/views/ExperimentalDesign.html
Comment: http://stats.stackexchange.com/questions/11233/simulating-data-sets-for-a-linear-mixed-model-in-r
Comment: While not providing a general method for simulating data, the `psych` package has several functions called `sim.()` to simulate with certain characteristics. An example would be `sim.anova()` for data from a multi-factorial ANOVA model.
Comment: One thing to bear in mind is that you need to specify an error distribution. In addition, I don't completely follow your "p.values" or "F_value" lists; is the idea that the sampling distributions of F & p be centered on the listed numbers?
Comment: @gung, the distribution is assumed in the test (both here assume normality or I would have had to use something like glm).
Comment: The *test* certainly does assume a specific distribution, but that doesn't mean that the data were actually generated in that way. You could generate data from any number of distributions for various purposes (e.g., simulation studies, robustness, etc.).
Comment: @gung, I have tried to edit my question to make clear that I want to create a data set that corresponds to the expectations of the test/model.  I am not looking for something for a simulation study or for a robustness study, but to provide a dry-run of an experimental design.
Answer: There actually is an S3 generic simulate that even returns the data frame (or other list) you want. Type
?simulate

It has methods for classes lm (works also for glm or for your aov example) and glm.nb (in MASS) already. You can now write S3 simulate methods for other classes of objects, e.g. for objects from lme4. You can check for which classes there are methods by typing
getAnywhere("simulate.class"), getAnywhere("simulate")

or
getS3method("simulate","class"), methods(simulate)

Comment: One could always construct an initial fitted object with all response values being 0, say, and replace the coefficients in the fit with desired parameter values. Then simulated responses can be obtained using 'simulate'.
Comment: Some simulate functions do not create the data only the fit: http://stats.stackexchange.com/questions/11233/simulating-data-sets-for-a-linear-mixed-model-in-r/28627#28627
Comment: simulate would be great if it did not require "an object representing a fitted model" which itself already requires data or simulated data.
Comment: `>getAnywhere("simulate.class")
no object named 'simulate.class' was found`
`>getS3method("simulate","class")
Error in getS3method("simulate", "class") :
  S3 method 'simulate.class' not found`
Comment: That is true.  The packages in the [experimental design task] (http://cran.r-project.org/web/views/ExperimentalDesign.html) view has many packages to create the dummy variable setup.  Integrating the simulate and experimental design functions would be great!
Answer: There is a new function called simfun in the TeachingDemos package for R (it is currently only in the development version on R-forge, it will be a while before it is on CRAN).  It is intended to help with creating functions to do simulations.
One of the intended uses is that a teacher would use the simfun function to create a function and distribute it to students (possibly have a web interface at some point as an alternative).  The students would then create a data frame of the factors representing an experimental design, pass this data frame to the created function and get returned the data frame with an additional column of the response simulated according to the parameters and error distribution set up by the teacher, the student can then analyze the data.  This allows the teacher to set up a "True" relationship, but allow students to try many different experimental designs to explore ways to get at the "Truth" in much less time than doing an actual experiment and requiring less work for the teacher than to create or find a bunch of different sample datasets representing the different possible designs.
The simfun function is designed to be flexible so the teacher/creator can base the simulations on a fitted regression model, parameters supplied by the teacher/creator, or parameters suplied by the student/user.
The created function can also be easily used in simulations (with the replicate command) to explore power, sample size, effect size, etc.  Though the resulting simulation may be slower than hand crafting the simulation process.
This looks like what you describe with the exception that it does not take p-values to create the data, but use of power. functions or pwr. from the pwr package could be incorporated to create simulations based on specifying power and alpha rather than means and differences.
Here is an example from the help page (there are several more examples) that assumes that you are measuring heights of subjects (male and female) that are nested in cities which are nested in states, there is a random effect for state with a SD of 1 and a random effect for city (within state) with a SD of 0.5 then the "error" SD is 3, females have a simulation mean of 64 inches and males have a mean of 69 inches (the error SD and means are realistic, the random effects are a bit contrived).  The simfun function is used to create a new function called simheight, then a data frame is created with state ID's, city ID's and a column for sex of the subject (the experimental design or sampling design), this is passed to simheight and the result in a new data frame with the simulated heights (in addition to the other variables) that could then be analyzed using appropriate tools.
# simulate a nested mixed effects model
simheight <- simfun({
  n.city <- length(unique(city))
  n.state <- length(unique(state))
  n <- length(city)
  height <- h[sex] + rnorm(n.state,0,sig.state)[state] +
    rnorm(n.city,0,sig.city)[city] + rnorm(n,0,sig.e)
}, sig.state=1, sig.city=0.5, sig.e=3, h=c(64,69),
  drop=c('sig.state','sig.city','sig.e','h','n.city','n.state','n'))

tmpdat <- data.frame(state=gl(5,20), city=gl(10,10),
  sex=gl(2,5,length=100, labels=c('F','M')))
heightdat <- simheight(tmpdat)

Comment: install.packages("TeachingDemos", repos="http://R-Forge.R-project.org")
Comment: I can't seem to find the new TeachingDemos on R-Forge?
Comment: Try `install.packages("TeachingDemos", repos="http://R-Forge.R-project.org")`.  You need "http://" at the beginning and no ";".
Answer: Typing methods(simulate) or getAnywhere("simulate") should work. The former gives you a few methods, if package lme4 is loaded:
[1] simulate.lm*     simulate.merMod* simulate.negbin* simulate.polr*
Lm-objects are used for both lm and glm models.
Comment: Thanks, but this seems like @Momo's answer.


How to shift color of part of an image with ImageSharp?

Question: I need to make a highlighter effect as if drawing with a transparent ink.
How do I do this in ImageSharp (or any other C# image processing library)?
Example Image:
Answer: Looks like I can just set alpha on the pen's color to something other than 255 in ImageSharp.


Multicast port 40000 and safetynetp

Question: I have a vendor that is sending multicast messages using port 40000. When I watch the traffic using tcpdump the port is reporting as safetynetp as can be seen below. The application that is listening for the traffic on 40000 never receives the messages.
Is this a port conflict that would cause the messages to not be delivered to the application listening for the messages or should everything still work with safetynetp using that port?
The tcp dump traffic looks like
09:16:16.565887 IP x.x.x.x.33957 > x.x.x.x.safetynetp: UDP, length 263
09:16:16.569960 IP x.x.x.x.57385 > x.x.x.x.safetynetp: UDP, length 263
09:16:17.225545 IP x.x.x.x.39261 > x.x.x.x.safetynetp: UDP, length 50

This is on a server running RHEL 7. Is there a way to allow the application to receive these messages?
Answer: It seems unlikely that this will be a port conflict. The tcpdump utility is simply reading the port name from the /etc/services file, see services(5) for more info. The /etc/service file maps a name to a port/protocol e.g.

safetynetp      40000/tcp               # SafetyNET p
  safetynetp      40000/udp               # SafetyNET p

Unless you have taken actions to allow a connection on port 40000/udp then the default CentOS 7 firewall configuration will be blocking the connection. You should open the port in your filewall.
Comment: So you would expect no interference with an application listening for those messages on 40000?
Comment: Also the firewall explicitly allows the traffic. We're seeing the packets on the server but they don't arrive at the application.

Multicast port 40000 and safetynetp


Camel route multiple if condition

Question: I have to write to multiple if condition in camel and I need help to go around.
if(token is NULL)
if(condition is NULL)
if(Dates does not match)
Then execute this...

What I am trying is
.choice
.when(token is NULL)
.when(condition is NULL)
.when(Dates does not match)
.log(update DB)
.endchoice()

which dont work..
Please help
Answer: Two conditions:
Predicate p1 = header("token").isEqualTo("001"):
Predicate p2 = header("condition").isEqualTo("002");

Combine these conditions:
Predicate cond = PredicateBuilder.and(p1, p2);

Then In Camel:
.choice
.when(cond)
.log(update DB)
.endchoice()

Answer: The best way to do this is to use Predicates.
You can define Predicates as private field if you are using Java DSL, by using expression builder, to build multiple conditions, then use the predicate in your when(), your route would looks much cleaner and easier to read.
private static final Predicate invalidHeaders = or(header(XXX).isNull(), header(YYY).isNull());

...

.when(invalidHeaders)

Answer: You need to do this in a single when and use and &&
.when(token is NULL && condition is NULL && XXX)

There are various ways to do this.
If you use Java code then you can append multiple predicates together: http://www.davsclaus.com/2009/02/apache-camel-and-using-compound.html

Camel route multiple if condition


rand() array doesn't change each time I run the code

Question: For a small program I am running I am using the rand() function to provide numbers for an array of 23 integers. I found that every time I run the code, it reuses the same numbers that were used before in the array, so i'm never getting different results each iteration. How can I fix this problem?
Edit: The code is and experiment of the birthday paradox. This paradox states that the chance that you would share a birthday with anyone in a room filled with 23 people is 50%, but naturally most people would think its quite smaller than that.
#include "stdio.h"
#include "stdlib.h"

#define interations 10 //number of repitition in the code for a more accurate percentage
#define numppl 23 //number of people

int main()
{
    int inv;
    float percent = 0, sum = 0;
    int i, j, k;
    int seq[numppl];

    for (inv = 0; inv < interations; inv++)
    {
        for (i = 0; i < numppl; i++) {
            seq[i] = rand() % 365;  //creates a random array of 'numppl' integers every iteration
        }

        for (j = 0; j < numppl; j++)
        {
            for (k = j + 1; k < numppl; k++)
            {
                if (seq[j] == seq[k]) //if any two number in the array match each other, increment sum by 1
                    sum++;
            }
        }
    }

    percent = (sum / interations) * 100; //divide the amount of arrays with numbers that match with the number of total arrays generated for a percentage

    printf("Chance of two people sharing the same birthday is %f percent", percent);
}

Each iteration is a different array of random numbers, but when I run the code again, the arrays are the same as before, so I get the same percentage
Comment: You need to show us the code you have written to do this. We can't help you unless we know what you've done.
Answer: That is the expected behavoiur of rand(). You need to seed the random number generator with srand().


Search through a specific field - Drupal 7

Question: Is it possible with Drupal to create a seperate search field to search in a custom field for a specific content type?
For example I have a text field in a content type with the name keywords. I gave some important keywords for that specific node.
What I want is that a user can search through these words with a custom search field, that is displayed on a specific page.
I know I could use something like exposed filters in views, but it is not working in my case. The reason is the nodes are having a relationship with a taxonomy list. The nodes are showing based on the taxonomy term ID in the URL.
For example, my taxonomy list called 'Jobs'. The terms in the list are
'sanitary', 'interior' and 'garden'.
When I'm on the page with the sanitair, there is a search field. If I search in this field it should take a look for all the nodes not only the nodes that are related with the 'sanitair' term. If I used exposed filters the filter is only searching on the current term, so only the kind of jobs for 'sanitair' are showing up.
Is there a way to do this with or without views and is it also possible to create this search field in a block, so I can use it on different places?
Thanks!
Answer: You could:

create a new separate view for searching across all nodes and display it in a block on the taxonomy term page, or
use solr search and set up facets (requires a lot of setup)


Why I see two API requests with different times in NextJS 13?

Question: I have BuildingInfo component where it contains API request function getData():
import { getData } from "./api"
import { Form } from "./components/Form"
import styles from "./style.module.css"
import { Suspense } from "react"

export const BuildingInfoForm = async () => {
  const data = await getData()

  return (

      <Suspense fallback={
Loading feed...
}>
        <Form data={data} />
      </Suspense>

  )
}

When NextJS render the component, I see two API calls at different times! What does it mean each one of them?
Answer:
The first call shown in the pic (*/building-info) is the request made to the api
The second call shown (notice that its a child of the first call) is the request made from the api (meaning */building-info made a request to second api credium-api.*)

To clarify further,

components/form/building-info is the route where your form resides.
On visiting that page, the component made a request to credium-api.* through getData() function (which will be a child request of components/form/building-info).
Comment: But I have only one call API which the second one.
Comment: @MenaiAlaEddine-Aladdin Have updated my answer. Does that clarify?
Comment: So the first one is related to the UI routing while the second is related to the API request right? But why it's `893ms`?
Comment: Thats probably because that includes all the server rendering, and the api call inside it as well.


Segmentation Fault While Reading File in C

Question: I am still very new to the c language and I am playing with reading files for the first time.  I had similar code to this code which used to run perfectly fine but now I am running into issues.  I  keep getting the error Segmentation fault (core dumped) every time I try to run this program.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct student {
    char first[30];
    char last[30];
    char ssn[9];
};

void make_arrays() {
    FILE *fp = fopen("students.db", "r");
    fseek(fp, 0, SEEK_END);
    long size = ftell(fp);
    fseek(fp, 0, SEEK_SET);

    long num_students = size / sizeof(struct student);
    printf("There are %ld students in the file", num_students);
    fclose(fp);
}

int main(int argc, char **argv[]) {
    make_arrays();
    return 0;
}

Comment: Check the return values of `fopen`, `fseek`
Comment: @Edenia What about it? But the file should be opened in binary mode.
Comment: That's a *bad* solution. Read e.g. [this `fopen` reference](https://en.cppreference.com/w/c/io/fopen), especially about the difference between the `"r"` and `"a"` options, and what happens if the file doesn't exist. That should help you understand why using the *append* option make it seem to work.
Comment: Seems like a good time to [learn how to debug your programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/). Especially how to use a debugger to catch crashes "in action" to see where in *your* code they happen, and then examine relevant variables and their values.
Comment: It has already been said. Many times: Check return values of all functions, especially `fopen`. Here every function can return error.
Comment: Are there platforms that don't support `stat()` but do support `SEEK_END` in binary mode (which C doesn't require)?
Comment: @Someprogrammerdude or, the simpler way, printf counter (possibly with some delay) before and after every line that could cause a crash and see the last value printed.
Comment: OP: `long num_students = size / sizeof(struct student);` what the hell?
Comment: @Edenia In the shown code, the only reasonable possibility of a crash is `fopen` failing and then passing a null pointer to `fseek`. We can't tell for *certain* (which is why debugging is needed) but since there's no actual reading of the file that can't be a cause.
Comment: @Edenia How is that simpler when you can literally just look at the stack trace of a crash and see exactly what happened?
Comment: @melpomene Not everyone likes to use debugger and read stack traces. Use whatever suits you.
Comment: Setting the file position indicator to end-of-file, as with `fseek(file, 0, SEEK_END)`, has undefined behavior for a binary stream (because of possible trailing null characters) or for any stream with state-dependent encoding that does not assuredly end in the initial shift state.
Comment: -quoted from C11 standard n1517
Comment: It also depends on the contents of the file, which are not presented here. I'd also check value of `size`
Comment: I changed the "r" to a "a" and it works fine now. Guess I'll just go with that.
Comment: Gotcha, I'll be sure to check that out. Thanks for the info.
Comment: @Edenia printf debugging is fine if that's your preference, but be sure you always put an explicit fflush call after each line, or the program might crash while the last successful line of output is still in the buffer, thus making it seem as though it crashed earlier than it did.
Comment: @Istanford53: you can accept one of the answers by clicking on the grey checkmark below its score
Answer: The segmentation fault might be caused by fopen failing to open the file.
You should always test for such failures and exit with an informative message.
Also note that, if the file is indeed binary, it should be open in binary mode to avoid end of line translation:
FILE *fp = fopen("students.db", "rb");

Also change the prototype for main to int main(int argc, char *argv[]) or simply int main(). There are too many stars in char **argv[].
Answer: You don't have to mark my answer as accepted, just want to inspire people to write code so that it is readable and safe. Don't be lazy to write code like this where quality is a factor.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <sys/stat.h>

struct student /* Magic numbers everywhere */
{
    char first[30];
    char last[30];
    char ssn[9];

};

void* handle_nullptr_error (void* ptr, char *action, int code)
{
    if(ptr == NULL)
    {
        fprintf(stderr, "Failed to %s\n", action);

        exit(code);
    }

    printf("Succeeded to %s\n", action);

    return ptr;
}

int handle_nonzero_error (int val, char *action, int code)
{
    if(val != 0)
    {
        fprintf(stderr, "Failed to %s\n", action);

        exit(code);
    }

    printf("Succeeded to %s\n", action);

    return val;
}

int handle_negval_error (int val, char *action, int code)
{
    if(val < 0)
    {
        fprintf(stderr, "Failed to %s\n", action);

        exit(code);
    }

    printf("Succeeded to %s\n", action);

    return val;
}

/** This function is not guaranteed to be portable and work (but it will at least fail properly),
 * because not all systems and/or library implementations support `SEEK_END` in files
 * opened in text mode, as specified by @mode
 * Moreover, in binary mode it will behave in an undefined manner, because different systems
 * may store files data completely differently. In most cases it will succeed, just don't
 * write code that crashes if not.
 */
long int get_file_charcount (const char *filename, char* mode)
{
    FILE*       fp      = NULL;
    long int    fpSize  = 0L;

    /* Alignment for complicated function calls (for e.g where functions are passed as arguments) */
    fp = handle_nullptr_error       (fopen(filename, mode),     "open file.",           1);

    (void)handle_nonzero_error      (fseek(fp, 0, SEEK_END),    "seek end position.",   2);

    fpSize = handle_negval_error    (ftell(fp),                 "tell position.",       3);

    fclose(fp); /* - May fail, as well */

    return fpSize;
}

/** This function depends on POSIX headers and it is unix-conformant, although there are still
 * some exceptions.
 *
 * Note that the value returned is the length of the contents of the symbolic link,
 * and does not count any trailing null pads. The value is ought to be system-specific.
 */
_off64_t get_file_size (const char *filename)
{
    struct stat st = {0};

    (void)handle_negval_error(stat(filename, &st), "get file size.", (-1));

    return st.st_size;
}

/** A validation function should first determine whether file's size is
 * actually dividable by `sizeof(struct STUDENT_DESCRIPTION);`.
 *
 * Further more you can use `get_file_size()` as an alternative to
 * `get_file_charcount()`. In the latter case, make sure you to specify the
 * appropriate mode, "r" for text files and "rb" for binary files.
 */
void make_arrays ()
{
    long int    size            = get_file_charcount("myfile.txt", "r");
    long int    num_students    = size / sizeof(struct STUDENT_DESCRIPTION);

    printf("size of file: %ld\n", size);

    printf("There are %ld students in the file", num_students);
}

int main (void)
{
    make_arrays();

    return EXIT_SUCCESS;
}


Alfred's Adult Piano Level 2 Augmented Chords page 130

Question: On page 130 Alfred's Level 2 book is a sample of Augmented Chords, but for any chord which should have the middle note sharped, the middle sharp is dropped when converted to Augmented. I've looked on the internet, and everywhere else this does not happen.
Alfreds gives A Aug as this: A, C, E#.  The sharp for C is omitted.  He does the same thing with B Aug, D Aug, E Aug.  They all have sharps on the middle note of the chord and these sharps are dropped in the Augmented version.
Can anyone explain why he does this when I don't see it anywhere else?
Comment: One would hope that somewhere, earlier in the book, it would be stated that accidentals last through the whole bar.
Comment: on the grade when augmented chords are introduced I think the beginner should be on a level where he knows that rule of accidentals ...
Comment: Does this book show B augmented as B–D–Fx? D+ as D–F–A#? E+ as E–G–B#? If so, that's a definite error! All of these chordal thirds should have sharps on them.
Comment: Introducing the constituent notes of a newly defined type of chord in the middle of what is meant to be read as a bar of actual music is not a particularly great pedagogical decision
Answer: The book shows the major chord followed by the corresponding augmented chord, both in the same measure. Because they're in the same measure, the accidental associated with the major chord carries over to the augmented chord as well. So, for example:
<code>X: 1
T: Augmented chord
K: none
M: none
"A"[A^ce]4 "A aug"[Ac^e]4|
</code>
Here is an image (in the bass clef) from the 1984 edition of the book (page 76):
Comment: Ahh, interesting. I can see how this would be confusing; a parenthesized courtesy accidental probably would have been pedagogically wise.
Comment: +1 - well spotted. Just when we thought we didn't need courtesy accidentals! In a beginner book, it would be more clear to use semibreves, one bar each. That would cut out any ambiguity. I often wonder what 'educators' are thinking...
Comment: Haha this is a terrrrrible typographical decision!
Comment: In the first image, it's not clear that it _is_ a bar/measure; it could easily be isolated chords illustrating only the pitches, in which case it's not obvious that accidentals would carry through in the normal way.
Comment: @PhilMJones Good call. Thanks. I've added some text to clarify.
Comment: @Richard Perhaps, although given the number of courtesy accidental questions we see here ...
Comment: For anyone, like me, who initially thought "huh?" at the second image above: it's the bass clef. My bad for too many years in brass bands ;)
Comment: In my own cheat sheets I put barlines or staff breaks between items like that. Surely they are isolated chords, not a progression. Make that visual, super obvious IMO.
Answer: thankyou everyone.  This has cleared it up.  Of course, the accidentals carrying through in the same bar. I should be more awake.


Paginação com NodeJS e MongoDB

Question: Olá colegas programadores!
Estou enfrentando um problema a dias e gostaria da ajuda de vocês para solucionar.
Estou criando um projeto em NodeJS e MongoDB. Ele consulta o banco de dados de acordo com o que o usuário digita e trás os resultados em uma lista. Por enquanto uso o NodeJS puro e bootstrap.
O meu próximo passo é criar uma paginação simples, pois a lista de itens que sai nos resultados é enorme.
Mas como sou muito noob ainda no assunto, estou em busca da ajuda de vocês.
Segue abaixo o meu index.js
<code>const express = require('express');
const router = express.Router();
const morgan = require("morgan");
const bodyParser = require('body-parser');
const path = require("path");
const mongoose = require('mongoose');

function simplify(text) {
    const separators = /[\s,\.;:\(\)\-'\+]/g;
    const diacritics = /[\u0300-\u036f]/g;

    //capitalização e normalização
    text = text.toUpperCase().normalize("NFD").replace(diacritics, "");

    //separando e removendo repetidos
    const arr = text.split(separators)
        .filter((item, pos, self) => self.indexOf(item) == pos);
    console.log(arr);

    //removendo nulls, undefineds e strings vazias
    return arr.filter(item => (item));
}

router.get('/search', function (req, res) {
    res.render('search', {
        title: 'Pesquisa'
    });
});

router.get('/about', function (req, res) {
    res.render('about', {
        title: 'Sobre'
    });
});

router.get('/', function (req, res, next) {
    if (!req.query.q)
        return res.render('index',
            {
                title: 'Site',
                rb: [], query: ''
            });
    else {
        const query = simplify(req.query.q);
        const mongoClient = require("mongodb").MongoClient;
        mongoClient.connect("mongodb://localhost:27017", {
            useNewUrlParser: true,
            useUnifiedTopology: true
        })
            .then(conn => conn.db("search-db"))
            .then(
                db => db.collection("tags")
                    .find({ tags: { $all: query } }, { title: { $all: query } })
                    .skip(10)
                    .limit(10)
            )
            .then(cursor => cursor.toArray())
            .then(rb => {
                return res.render('search',
                    {
                        title: 'Pesquisa',
                        rb, query: req.query.q
                    });
            })
    }
});

module.exports = router;

</code>
Answer: A solução para esse problema é passar mais um query param para a sua rota, indicando a quantidade de itens que deverão ser "pulados". O que está acontecendo hoje é que você sempre está "pulando" 10 documentos e retornando os próximos 10.

Paginação com NodeJS e MongoDB


High D on Tenor Recorder

Question: I just received my tenor recorder (courtesy of Music.SE :D) and I was playing around in the upper range. I noticed that once I get up to the high C and beyond (no pun intended), the notes come out an octave low. I can get the high C out by really blowing hard, but I can't get the high D out for the life of me.
I've noticed this same thing in my alto, but it is not nearly so hard to play the upper range. It only needs a little extra effort. However, the tenor is just impossible.
Is this a glitch in the recorder, or do I need to do something differently? I've tried blowing harder and pinching the thumb differently, but I can't get it out.
Comment: Sorry if this sounds like "is it plugged in?" tech support, but just to check: you are fully covering the hole on the back for the lower octave and are uncovering it for the upper octave, right?
Comment: You mean the thumb hole? I'm pinching it when I play the upper octave. I've tried pinching it in various amounts, but to no avail. I've never seen it marked as "uncovered" above F# (usually D).
Comment: Yes, that's the hole I was talking about.  I'm not a recorder player myself (I play with some), so I thought they were leaving that hole uncovered for the high notes, but maybe they're pinching it.  For debugging you might see what happens if you completely uncover it and then start adjusting the pinching from there.  Good luck!
Comment: I play some tenor recorder myself and am interested in your question but am confused by which C your are talking about.
Comment: I am talking about the C two ledger lines above the top of the G clef. Does that clarify?
Answer: The high D is actually pretty easy on my tenor (Rottenburgh). You have to pinch the thumb hole (covering somewhere around half of it) and then four of the first six top holes, leaving both middle fingers off (also both pinkies, though you never use the left pinky anyway—I just wanted to be clear).
Imagine that an X indicates a closed hole and an O indicates an open one, where the recorder is oriented head-joint to the left, it would look like this:
X 0 X X 0 X 0
(again, with the thumb hole half covered starting at the lower edge).
Also remember you have to blow hard, and keep your throat open!
For me the high C is the iffy note on many recorders. The D, when fingered as I showed you, is clear as a bell and easy as pie.
addendum
Take care with the thumb hole that you are covering it evenly—that is, not on a slant. It's easy to slide your thumb down so that it is attacking the hole from an angle. What you want is a half-covering that is exactly perpendicular to the column of air.
Comment: Let me add to this good answer that "open throat" is another way of saying to keep your jaw and neck muscles relaxed. It can help to imagine that your head is a balloon lifting off your shoulders.  Usually, a very small opening is all that is needed for the thumb, very small. You'll get it eventually.
Comment: I am using that fingering and can get it on my higher recorders. I'll try pinching the thumb-hole differently a little more. Could you expound on keeping your throat open? I've never heard that term used about playing the recorder.
Comment: A lot of players will tighten up their throats as they go for the higher notes. It's kind of instinctive. The problem is, that chokes off the volume of air flow just when you need it the most. As a side note, an open throat acts as an additional resonance chamber: subtle but present nonetheless. It's more important for playing the concert flute, but it works for recorder as well.
Comment: I thought the difference might be due to the fact that my Rottenburgh tenor is just a great instrument, but I just tried what I told you on a cheap plastic Aulos model and it works just as well. It's all about airflow and correct thumb placement. I do notice hints of the lower octave if I don't keep up the flow. Remember, the tenor requires much more air than the treble recorder does.
Comment: I tried this again with your advice, and I was able to hit the high D (haven't tried higher). I think my problem was partly that my throat was a little tight. However breath control was the larger problem. My recorder seems to get finicky in the upper range. If I over or underblow at  all up there, it goes way off. How I got around that was by holding a B and slurring to C without changing how I was blowing at all. It took a few tries, but I eventually got it and was able to get C, C#, and D spot on. I'm now working on hitting them consistently starting an octave lower. Thanks for your help.
Answer: You might find this app helpful for further queries. http://www.dolmetsch.com/cfingerchart.htm
I used his when I was just starting to play
Comment: My question was more about the technique than the fingering. BTW, though, that link is already in my bookmarks. :P

High D on Tenor Recorder


Probability of picking 3 playing cards that belong to different suits

Question: If you have 52 playing cards with 4 different suits (13 spades, 13 clubs, 13 hearts, and 13 diamonds), what is the probability of picking 3 random cards that are all from a different suit?
I tried going about this by writing down all 52 cards and I found out that, if you were to pick a second card, the probability of the second card being from a different suit is 39/51, since there are 51 cards left, with 12 of them being from the same suit as the first card you picked (51-12=39).
However, when I tried to do the same thing with a third card, I got 26/50, since there are 50 cards left, and, assuming the first 2 cards you picked are from a different suit, the probability of the third card being from a different suit would be 50 cards - 12 cards of the same suit * 2 different suits =26 out of 50.
Unfortunately, I realized that it's also possible for the second card you pick to belong to the same suit as the first one, so, in that case, there would also be 50 cards left, and the probability is not the same since there would also be 50 cards left, but 39 cards would belong to a different suit, so I got 39/50.
After that, I realized that I had just managed to confuse myself more than I should have and couldn't really figure out where to go from there. Where did I go wrong and what is the proper way to solve this problem?
Comment: "I realized that it's also possible for the second card you pick to belong to the same suit as the first one" -- With respect this to this comment, it brings up a question. The question you seem to be asking in the opening parts of the question seems to imply that you want all three to be from different suits (i.e. Spade/Spade/Heart is not valid). Yet the quote seems to imply this is okay. This is an important nuance to settle for probably everyone's sake.
Comment: Sorry about that. You're right. Spade/Spade/Heart would not be a valid combination in this scenario. I nonetheless mentioned it, thinking that it could somehow affect the probability of the third card belonging to a different suit. I didn't mean to imply that it actually was a valid combination. Which is why I also said that I just confused myself even more, since this would contradict the initial statement.
Answer: You are correct that your chance to get an acceptable second card is $\frac {39}{51}$ and that assuming the second is acceptable the chance for the third to be acceptable is $\frac {26}{50}$.  You don't need to worry about the chance the third is acceptable if the second is not because you have already failed.  Now you can use the multiplication principle to get the probability of success
$$\frac {39}{51} \cdot \frac {26}{50}=\frac {169}{425}$$
Answer: There are 4 suits from which you choose 3, C(4,3)=4. There are 4 ways of choosing which suits to represent. For each of the 3 chosen suits, there are 13 options from which to choose one representative, C(13,1)=13. So there are $4*13^3$ ways of selecting these cards.
Overall, the number of ways of choosing 3 cards from a group of 52 is :
$C(52,3)=\frac{52!}{3!49!}=\frac{52*51*50}{6}=26*17*50$
So the probability of choosing 3 cards each of different suits is : number of ways of selecting 3 cards of different suits/ total number of ways of picking 3 cards out of 52.
ans = $\frac{4*13^3}{26*17*50}=\frac{4*13^2}{2*17*50}=\frac{169}{425}$


Does a bounded norm of a function in L2 mean the function is bounded?

Question: In $L^2$ space, if the norm of a function $||f||$ is bounded on $[0,1]$ does that mean the function is bounded?
If so, why? Is there a theorem? Or a counter example?
Comment: In general, an integral bound on a function cannot give a pointwise bound. It is enough to remark that there are unbounded functions with bounded integral.
Answer: This is not true. Consider the function
$$
 f(x) := \begin{cases}
\frac{1}{x^{1/4}} & \text{if } x \in (0,1],\\
0 & \text{if } x = 0.
\end{cases}
$$
Clearly, $f$ is unbounded on $[0,1]$. However,
\begin{align*}
\left\Vert f \right\Vert_{L^2}^2 = \int_0^1 |f|^2\,\mathrm{d}m = \int_0^1 \frac{1}{\sqrt{x}}\,\mathrm{d}x = 2.
\end{align*}
Moreover, as pointed out in the comments, the $L^2$-norm does not give you much information on the pointwise values of a function. Indeed, by the very nature of the Lebesgue integral, changing the values of $f$ on a null set would not affect the value of the integral.
Comment: For $1 \leq p < \infty$, the norm on $L^p(X)$ is simply the map $$ f \mapsto \left( \int_X |f|^p\,\mathrm{d}m\right)^{1/p}.$$ See https://en.wikipedia.org/wiki/Lp_space#Lp_spaces
Comment: Isn't the norm in $L^2=\sqrt{x^2}$? If I am wrong... please tell me why, it would really help me.
Comment: The $L^2([0,1])$-norm of a function $f$ is $\left( \int_0^1 |f|^2 \right)^{1/2}$.
Comment: Can you tell me why? Where can I read that this is the case? When I look up Lp space it tells me the norm $||X||_p$ is $\sqrt{x^p}$
Comment: A norm has to return a real number not a function. In fact, since elements of $L^2$ aren't well defined pointwise, your "norm" would not be well defined. Which source are you referring to?
Comment: Okay, thank you so much. I see it.
If you have a second, could you also please tell me then, what about C[0,1] ? I am supposed to prove a function is bounded on C[0,1] with "sup norm"
What is the norm on this C space?  (This stuff is not a pre-req to the course I'm taking -_-)
Comment: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/91278/discussion-between-rolandcyp-and-frank).


django.db.utils.IntegrityError: column "venue_city" contains null values

Question: I have read a lot of other posts here on stackoverflow and google but I could not find a solution.
It all started when I changed the model from a CharField to a ForeignKey.
The error I recieve is:
Operations to perform:
  Synchronize unmigrated apps: gis, staticfiles, crispy_forms, geoposition, messages
  Apply all migrations: venues, images, amenities, cities_light, registration, auth, admin, sites, sessions, contenttypes, easy_thumbnails, newsletter
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  Rendering model states... DONE
  Applying venues.0016_auto_20160514_2141...Traceback (most recent call last):
  File "/Users/iam-tony/.envs/venuepark/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
psycopg2.IntegrityError: column "venue_city" contains null values

My model is as follows:
class Venue(models.Model):
    venue_city = models.ForeignKey(City, null=True,)
    venue_country=models.ForeignKey(Country, null=True)

venue_country did not exist before so that migration happened successfully. But venue_city was a CharField.
I made some changes to my migration file so that it would execute the sql as follows:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models

class Migration(migrations.Migration):

    dependencies = [
        ('venues', '0011_venue_map_activation'),
    ]

    migrations.RunSQL(''' ALTER TABLE venues_venue ALTER venue_city TYPE integer USING  venue_city::integer '''),

    migrations.RunSQL(''' ALTER TABLE venues_venue ALTER venue_city RENAME COLUMN venue_city TO venue_city_id '''),

    migrations.RunSQL(''' ALTER TABLE venues_venue ADD CONSTRAINT venues_venus_somefk FOREIGN KEY (venue_city_id) REFERENCES  cities_light (id) DEFERRABLE INITIALLY DEFERRED'''),

Thanks in advance!
UPDATE: my new migration file:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models

class Migration(migrations.Migration):

    dependencies = [
        ('cities_light', '0006_compensate_for_0003_bytestring_bug'),
        ('venues', '0024_remove_venue_venue_city'),
    ]

    operations = [
        migrations.AddField(
            model_name='venue',
            name='venue_city',
            field=models.ForeignKey(null=True, to='cities_light.City'),
        ),
    ]

Comment: I think, you added `null=True` after created migration file. Because `venue_city ` is not a nullable field in your migration file
Comment: @Anoop how can i fix this? and yes I did.
Comment: which django version you are using?
Comment: If it is latest version then, execute again  `python manage.py makemigration
Comment: 1.8.7, I tried doing the makemigration and migration again but still the same
Comment: could you please share your migration file `alter query`?
Comment: I updated my question with the new migration file
Comment: Looks like you created another migration file for remove `venue_city`. If this is new table in prod then delete tall these migration files and generate new one
Comment: If this is an existing table in prod then, remove all the migration files from your local since you started this `CharField to a ForeignKey` changes and create new migration file.
Comment: I get django.db.migrations.graph.NodeNotFoundError: Migration venues.0018_auto_20160514_2146 dependencies reference nonexistent parent node ('venues', '0017_remove_venue_venue_city') - when i do makemigration
Comment: Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/111999/discussion-between-tony-kyriakidis-and-anoop).
Answer: Looks like you added null=True after created migration file. Because venue_city is not a nullable field in your migration file
Follow these steps.
1) Drop venue_city & venue_country from your local table
3) Delete all the migration files you created for these `CharField to a ForeignKey` change
4) execute `python manage.py makemigrations`
5) execute 'python manage.py migrate'

It should work
Comment: How do you do 1)?
Comment: Thank you Anoop for all your help in the chatrooms!
Comment: Just as a quick comment, if you are using something like AWS Elastic Beanstalk it could be easier to simply correct the models, delete the erroneous migrations and makemigrations again.
Answer: Had a similar problem i resolved it by removing the previous migration files.No technical explanation
Comment: Definitely don't do this blindly. Could result in some crazy prod db issues.
Comment: just leave the first one[0001].just save the in another folder incase it dosent work.
Comment: did that, It requests dependencies from other nodes when i run makemigrations
Comment: :-( my help ends there.But because migration files are Dependant with previous files.Try inspecting them because the error is a result of conflicting commits to the database
Answer: I solved it by just adding null = True to both the (automatically generated) migration file that was causing the issue and in the Model. Then migrate again and your failed migration will now succeed. As you changed it also in your model, makemigration will detect no changes after that.
Answer: follow the below steps:-

add null=True, blank=True in Venue model class
eg: venue_city = models.ForeignKey(City, null=True, blank=True)
delete venues.0016_auto_20160514_2141 migration file from migrations folder in your app
then run python manage.py makemigrations
then run python manage.py migrate

no need to drop table or remove migrations from migration tables
Answer: I solved it by below:

First delete last migration that face problem
Then add like venue_city = models.CharField(blank=True, null=True)
Finally use makemigrations and migrate command
Answer: As the error says, you have a null value in the "venue_city" column.
It seems at the time of defining your model you had not included "null=True".
So it returns null because there is nothing in your 'venue_city" variable. Consider deleting the last migration file and perform another migration using
python manage.py makemigrations and python manage.py migrate commands.
Comment: Encountered the issue on 6th of November, 2022. It still does exist
Comment: That's correct, 7+ years ago this was the issue!
Answer: Migration was created but it fails during running. Remove the last migration.
Fix the model definition by adding null=True, default=None if you want it to allow null in database. You need to supply any default value when you are adding column in existing table.
Regenerate the migration (manage.py makemigrations venues) again and migrate (manage.py migrate venues).
Answer: You may need to open the migration 0016_auto_20160514_2141 and assign some default value there.


Haar state on nonseparable, noncocommutative compact quantum group

Question: I am trying to understand what seems to be a common knowledge, that every compact quantum group has a Haar state. However, each approach that I found on the internet is a bit hard for me to grasp.
I began with Van Daele's paper:
http://www.ams.org/journals/proc/1995-123-10/S0002-9939-1995-1277138-0/S0002-9939-1995-1277138-0.pdf
However, I do not understand, why the weak$^*$ limit in Lemma 2.1 exists. In other words, given a state $\omega$, why does a sequence of Cesaro sums
$$\omega_n = \frac{1}{n} \bigg(\omega + \omega^{\star 2} +\ldots + \omega^{\star n}\bigg)$$
converge in the weak sense? $\omega^{\star n}$ denotes the $n$-convolution, i.e.
$$\phi\star\psi = (\phi\otimes\psi) \circ \Delta, \hspace{0.4cm} \Delta - \text{comultiplication}.$$
In Woronowicz's paper:
https://www.impan.pl/~pmh/teach/intro3/CQG3.pdf
the issue is omitted but the price we have to pay is that we assume the compact quantum group to be separable. I would like not to do that, although I heard that non-separable $C^*$-algebras are considered as 'pathological'. Is there any evidence to support that claim?
Furthermore, I also stumbled upon a paper 'Haar Measures on Hopf $C^*$-Algebras' by Quan (I don't know if enclosing the link would be legal). The idea of using Markov-Kakutani fixed point theorem is really breathtaking (in my opinion), but still, the author needs to assume that the compact quantum group is cocommutative. I would also like to avoid this restriction.
Last but not least, there is another Woronowicz's paper: https://projecteuclid.org/download/pdf_1/euclid.cmp/1104159726
which concerns compact matrix pseudogroups (I don't know how these relate to compact quantum groups yet). The exposition is hard for me to follow, but I suspect the answer to my question may be somewhere between the lines of Lemma 2.6 and Proposition 2.7.
To sum up, I would like to find out a 'relatively modern approach' (not in the language of matrix pseudogroups) to the construction of Haar state on a compact quantum group, which is neither separable nor cocommutative.
Answer: Every bounded ball in the dual space is $w^{*}$ compact by the Banach-Alaoglu theorem, in particular, every bounded net has a $w^{*}$-convergent subnet. The state $\omega_n$ is bounded as an average of states, and so it has a convergent subnet in the $w^{*}$ topology, which implies that the sequence has a limit point in the $w^{*}$ topology. I don't think you can assert that the sequence converges itself, though.
Comment: The thing that is not clear to me is the following: Banach-Alaoglu theorem asserts that bounded ball in the dual space is weak$^*$ compact, where compactness is taken in the topological sense. It does not say that the ball is weak$^*$ sequentially compact, which would indeed imply the existence of weak$^*$ convergent subsequence. Wiki provides a sequential version of Banach Alaoglu theorem: https://en.wikipedia.org/wiki/Banach%E2%80%93Alaoglu_theorem#Sequential_Banach.E2.80.93Alaoglu_theorem,

but it requires separability, something I want to avoid. I hope I understood your answer properly.
Comment: @uniquesolution: as mateusz says, unless you require separability you need to replace "subsequence" with "subnet" everywhere in your answer.


A sum on co-prime positive integers with different parity

Question: I was trying to see that if the sums like the following is calculable
$$\sum_{(x, y)=1} f(x,y)$$
where $x>y$ are positive integers with different parity. How can we prove that the sum is divergent or convergent? Like the following
$$\sum_{(x, y)=1} \frac{x^2-y^2}{x^2+y^2} $$
Actually, what I'm looking for is to see that if the sum is convergent, how can we calculate it? Like
$$\sum \frac{x^2}{x^4+y^4}$$
Comment: What do you mean by different parity?
Comment: One of $x$ and $y$ is odd and other is even.
Answer: Hint:
Since $\gcd(n,1)=1$ for any positive integer $n$, the sum contains $\sum\limits_{k=1}^\infty\dfrac{k^2-1}{k^2+1}$
Also, we have $\lim\limits_{k\to\infty}\dfrac{k^2-1}{k^2+1}=\lim\limits_{k\to\infty}\dfrac{1-1/k^2}{1+1/k^2}=1\neq 0$

One could also argue that since we're summing over all coprime tuples of $\Bbb Z^2$, for $\gcd(x,y)=1$, the term $\dfrac{x^2-y^2}{x^2+y^2}$ is cancelled out by the term $\dfrac{y^2-x^2}{x^2+y^2}$ which is from the tuple $(y,x)$ since $\gcd(x,y)=\gcd(y,x)$, so the overall sum is $0$.
Hence, my original answer assumes (wlog?) that $x\gt y$ (i.e., the tuple $(x,y)$ is assumed to be the same as $(y,x)$, so we only take the tuple $(x,y)$ in the sum) to show divergence.
Comment: @Ghartal, If $x\gt y$, then my answer shows that the sum is divergent. Read the answer again more carefully.
Comment: I'm sorry. I should have mentioned $x>y$. Actually I wanted to see if the sum is convergent, then can we find a way to calculate it?
Comment: Yeah, I know:) Your answer is correct. But look at my edit. If the summand was an expression that made sum convergent, how could we calculate it? Like $$\frac{x^2}{x^4+y^4}$$Or any other expression that is easy to handle.
Comment: @Prasun Your first argument is totally fine but in the second argument where you said they get cancelled out so the sum is zero. My point here is you can not rearrange them. Rearranging them will give any number you want because this is not absolutely convergent


Counterexample to an Equivalence

Question: I need to prove or refute the equivalence:
$\forall{x}.(\exists{y}Q(x,y))\rightarrow R(x) \equiv \forall{x}\exists{y}(Q(x,y)\rightarrow R(x))  $
where $x\in\mathbb{N}$ and $Q,R$ are two-place and one-place predicates.
I assume that it is false but I can't find any productive counterexample.
Comment: This question is missing context or other details: Please improve the question by providing additional context, which ideally includes your thoughts on the problem and any attempts you have made to solve it. This information helps others identify where you have difficulties and helps them write answers appropriate to your experience level.
Comment: A correct relation is $$\forall x ~ (\exists y ~ Qxy \Rightarrow Rx) \equiv \forall x ~ \forall y ~ (Qxy \Rightarrow Rx)$$ so a counter example requires $\exists y~ Qxy$ and $\forall y ~Qxy$ to be different.
Comment: As others have said, the usual left side would be $\forall{x}.(\exists{y}Q(x,y)\rightarrow R(x)) $, which is a different statement.  On the other hand, your version is a well formed formula, so it is a question that can be answered.  I answered the question as written.  Please check if this is what you intended.
Answer: For an $x$ where $R(x)$ is true, both sides are true, so our only problem is if $R(x)$ is false.  The right side is true if there is any $y$ such that $Q(x,y)$ is false.  The left side is only true if there is no $y$ such that $Q(x,y)$ is true.  You therefore need there to be some $x$ where $R(x)$ is false and $Q(x,y)$ can be true or false depending on $y$.
Answer: First, you have a parenthesis in the wrong place for the first expression; it should be: $\forall x \: (\exists y \: Q(x,y) \rightarrow R(x))$
Second, I think you have a hard time finding a counterexample, since the second expression is a rather unusual expression: it contains an existentially quantified conditional, and that almost never represents a statement we would make under normal circumstances. In other words, there is no 'nice' interpretation for that kind of sentence.
Still, as others have pointed out, this second statement can be made true simply by picking something for which $Q(x,y)$ is false, as that will make the conditional true. So, here is a simple way to make this all work: for $Q(x,y)$ pick $x <y$: since for any $x$ there is some $y$ such that $x$ is not smaller than $y$ (in fact, we can always pick $y=0$ (or $y=1$, if you do not consider $0$ part of $N$)), that means that for any $x$ there is some $y$ such that $Q(x,y) \rightarrow R(x)$ is true. Hence, the second expression is true, regardless of what we pick for $R(x)$.
For the first expression, however, note that for any $x$, there is some $y$ such that $x<y$ ($y=x+1$ will do nicely). So this means that for the first expression to be false, all we need to do is pick some $R(x)$ that is not always true, e.g. $R(x)$: $x$ is even. Because with that, we see that the universal statement of the first expression is not true for any odd number. That is, the first expression is false.
Ok, so there is a simple counterexample to the supposed equivalence. But again, you probably couldn't find a counterexample, because you tried to have some kind of interesting and meaningful interaction between $Q(x,y)$ and $R(x)$, but the 'weirdness' of the second expression rules out anything 'interesting and meaningful' in the first place.

Counterexample to an Equivalence


iOS App running on iOS 13 is resetting each time the user goes into background for at least 30sec

Question: It is not really a question but I wanted to write it down here so other people facing the problem could find the solution.
Since the release of iOS 13, some of our users were contacting us telling that our app was resetting each time they go into background for a medium amount of time (approximatively 30sec).
Of course, absolutely no clue of the behavior, nothing on Crashlytics etc. We were able to reproduce on a QA device but unable to reproduce on a debugger attached device.
So obviously we used the Console to monitor what's going on and we noticed that a weird message was being sent after approx. 25sec after our app was put into background:
default 10:14:01.658579+0100    XXX RunningBoardServices    Received process assertions expiration warning!
default 10:14:01.659214+0100    XXX RunningBoardServices    Notifying client of imminent expiration of assertion
default 10:14:01.659568+0100    XXX RunningBoardServices    Expiration notification complete

If you were fast enough to relaunch the app, everything just worked fine, but if you left the app inactive for another 5sec (approx.) and then relaunched it, then the app was resetting (appDidFinishLaunching...).
...
Comment: I also face the same issue, I try to fig out the issue.
Answer: ...
We dug deeper and deeper without finding anything... until we decided to update some of our external libraries through Cocoapods, and guess what? we found our guilty guy: GoogleDataTransport from the Firebase suite!
We were using the 1.1.3 version and updating to the 3.0.1 fixed the issue. I guess they were doing some "bad" stuff in the background...
That's it guys. I hope it will help some others!
Cheers.
EDIT:
From this page (Firebase release notes) https://firebase.google.com/support/release-notes/ios#6.11.0, you can read:

Fixed race condition that prevented upload from completing while app was in the background.
  Version 6.10.0 - October 8, 2019

From what I understand, maybe Firebase was not notifying iOS that the upload they were doing in the background was completed. It could explain why iOS 13 kills an app in this case.
♂
EDIT 2:
Apple apparently released an iOS update (13.2.2) which is supposed to solve these background issues: https://twitter.com/engadget/status/1192512171252551682?s=12.

Fixes an issue that could cause apps to quit unexpectedly when running in the background

We tested it using an old app which does not include our previous fix and unfortunately the problem is still present...
Answer: The crash was due to a background task leak. In my application, some SDKs don't use the background task correctly. Because it was killed by the watchdog, debugging will not appear, you can print beginBackgroundTask and endBackgroundTask during debugging. If there is a mismatch, a leak occurs.
I wrote a category to hook background task related methods to avoid leaking being killed by watchdog:https://github.com/ruanjx/MPIBackgroundTaskProtection
More information about background task:https://medium.com/swlh/handling-background-tasks-in-ios-13-67f717d94b3d


Can SoapUI's property expansion be used to access a TestCase label?

Question: I'm trying to write a SoapUI TestCase at the moment. I'd like to access the label of the test case in one of my test steps. Is there any way to do this using the property expansion syntax?
Something in the region of
${#TestCase#label}
Thanks
Answer: It's possible using the follow syntax:
${=context.testCase.name}

Explanation
${= } this allows to execute some Groovy code inside the request.
Like in the Groovy testSteps you've context available so you can access the testCase and then access the name property which contains the label.


How to add new columns to a dataframe if common variables are found in multiple other dataframes

Question: I have a data frame similar to the one below.
df1 <-
Class    Race    Level

Paladin  Human   4
Fighter  Elf     5
Wizard   Gnome   3
Rouge    Elf     4

I would like to add columns to this data frame based on the information found in the following three data frames.
Mission1 <-

Class    Exp

Paladin  80
Fighter  70
Cleric   100
Wizard   80

Mission2 <-

Class    Exp

Cleric   200
Fighter  220
Wizard   190

Boss1 <-

Class    Exp

Wizard   500
Paladin  520
Cleric   490
Druid    500

I would like to add a 1 or 0 to df1 if the df1$Class column matches the $Class column of the other three. I would like to add a 1 or 0 for each of the three other data frames and sum up the mission, and mission+boss scores. So the output would look like this.
df2$Missions  = Mission1 + Mission2

df2$Final = Mission1 + Mission2 + Boss1

df2 <-

Class    Race    Level   Mission1   Mission2  Missions   Boss1   Final

Paladin  Human   4       1          0         1          1       2
Fighter  Elf     5       1          1         2          0       2
Wizard   Gnome   3       1          1         2          1       3
Rouge    Elf     4       0          0         0          0       0

Any help would be appreciated.
Answer: you can use dplyr:
df2 %>% mutate(Mission1 = as.integer(Class %in% Mission1$Class))
    %>% mutate(Mission2 = as.integer(Class %in% Mission2$Class))

df2 %>% mutate(Missions = Mission1 + Mission2)
df2 %>% mutate(Boss1 = as.integer(Class %in% Boss1$Class))
df2 %>% mutate(Final = Missions+Boss1)

Comment: Thanks, this kind of works. Had to edit it slightly:

df1 %>%  mutate(Mission1 = as.integer(Class %in% Mission1$Class)) -> df2
df2 %>%  mutate(Mission2 = as.integer(Class %in% Mission2$Class)) -> df3
Answer: A simple solution would be to use dplyr left_join and then change to 0s and 1s based on values being present or not:
df1 <- left_join(df1, Mission1)
names(df1)[4] <- "Mission1"
df1 <- left_join(df1, Mission2)
names(df1)[5] <- "Mission2"

df1$Mission1 <- ifelse(is.na(df1$Mission1), 0, 1)
df1$Mission2 <- ifelse(is.na(df1$Mission2), 0, 1)


String enums as object indexing types in TypeScript

Question: Consider following Enum:
export const SOME_STRING_ENUM {
  ONE = 'one',
  TWO = 'two'
}

Now let's assume, I need some value mapper to this enum, I figured out such a monstrosity:
export type eKey = keyof typeof SOME_STRING_ENUM;
export const mapper: {[k in eKey]?: string} = {
  [SOME_STRING_ENUM[SOME_STRING_ENUM.ONE]]: 'This is label for one'
  [SOME_STRING_ENUM[SOME_STRING_ENUM.TWO]]: 'This is label for two'
}
// please note referring to labels via [E[E.K]] not via just plain E.K

End then obtaining those mapper keys is even more ridiculous to be hones:
  public mapEnum(reason: SOME_STRING_ENUM) {
    return mapper[SOME_STRING_ENUM[reason]];
  }

Well... above works well. But it's ugly as hell and I'm not fully convinced where I went so wrong that I need to use double referring to actually make myself happy with referring object by label... My expected solution would be as simple as:
export type eKey = keyof typeof SOME_STRING_ENUM;
export const mapper: {[k in eKey]?: string} = {
  [SOME_STRING_ENUM.ONE]: 'This is label for one'
  [SOME_STRING_ENUM.TWO]: 'This is label for two'
}

  public mapEnum(reason: SOME_STRING_ENUM) {
    return mapper[reason];
  }

Would this be possible with string enumerators? Or, as always, I get confused somewhere at the beginning?
Thanks for any help!
Answer: You can instead use the values of the enum, rather than the keys as you have here.
To do this, you extract object values via T[keyof T] - where T is your enum type (typeof SOME_STRING_ENUM).
This gives you pretty much as you had written the second example:
export enum SOME_STRING_ENUM {
    ONE = 'one',
    TWO = 'two'
}

export type eKey = typeof SOME_STRING_ENUM[keyof typeof SOME_STRING_ENUM];

export const mapper: { [k in eKey]: string } = {
    [SOME_STRING_ENUM.ONE]: 'This is label for one',
    [SOME_STRING_ENUM.TWO]: 'This is label for two',
}

function mapEnum(reason: SOME_STRING_ENUM) {
    return mapper[reason];
}

Playground link here


How does Minecraft use their lang files?

Question: I have always been fascinated with how they have done it, so I will know ask how.
An example lang file that minecraft uses looks like this:
options.stream.chat.enabled.streaming=Whilst Streaming
options.stream.chat.enabled.always=Always
options.stream.chat.enabled.never=Never
options.stream.chat.userFilter=User Filter
options.stream.chat.userFilter.all=All Viewers
options.stream.chat.userFilter.subs=Subscribers
options.stream.chat.userFilter.mods=Moderators
title.oldgl1=Old graphics card detected; this may prevent you from
title.oldgl2=playing in the future as OpenGL 2.0 will be required.
controls.title=Controls
controls.reset=Reset
controls.resetAll=Reset Keys
key.sprint=Sprint
key.forward=Walk Forwards
key.left=Strafe Left
key.back=Walk Backwards
key.right=Strafe Right
key.jump=Jump
key.inventory=Inventory

What I am asking is, how would I go about doing this code wise? Say, how would I get what is on the right hand side of the equals sign if I 'searched' key.right? How would I even search the file for that string in the first place?
Any help is appreciated, as this seems like a very useful thing to use for making config type files.
Thanks
Answer: This is the default way to store some settings in Java, using Properties. This is just a HashTable, which can be used for getting some properties and it can be initialized from file this way:
Properties settings = new Properties();
settings.load(inputStream);

inputStream can be loaded by something like:
InputStream inputStream = new FileInputStream(fileName);

Comment: Thanks, this is exactly what I was looking for! Thanks to this, I have built the preferences section of an app really easily... :D Once again, thanks!
Answer: Properties are indeed one part of the whole; the actual whole is a bit of a forgotten term "i18n", which is a shorthand term for internationalization.
http://docs.oracle.com/javase/tutorial/i18n/
Unsurprisingly Java contains mechanisms to handle that and Minecraft likely makes use of it. Of course I'm not a Minecraft dev so I can only guess.


How to add another overlay item to a android mapview

Question: I need to add another overlay item to a mapview. I have used the standard android developers guide to google maps. I currently have the mapview within a tab. I would really appreciate any ideas. Thanks.
Below are my java classes:
public class Mapview extends MapActivity {

    protected boolean isRouteDisplayed(){
        return false;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapview);

        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);

        // JD sports marker begin
        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources()
                .getDrawable(R.drawable.jd_sports_logo);
        //Passes drawable(jd sports logo) into HelloItemizedOverlay class
        HelloItemizedOverlay itemizedoverlay =
                new HelloItemizedOverlay(drawable);

        double latitude = 51.545538;
        double longitude = -0.477247;
        GeoPoint point = new GeoPoint((int)(latitude * 1e6),
                (int)(longitude * 1e6));

        OverlayItem overlayitem = new OverlayItem(point, "JD Sports",
                "This is a sports shop");

        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);
        // JD sports marker ends

        // Fitness first marker begin
        List<Overlay> mapOverlays1 = mapView.getOverlays();
        Drawable drawable1 = this.getResources()
                .getDrawable(R.drawable.fitness_first_logo);
        HelloItemizedOverlay itemizedoverlay1 =
                new HelloItemizedOverlay(drawable);

        double latitude1 = 51.545157;
        double longitude1 = -0.477247;
        GeoPoint point1 = new GeoPoint((int)(latitude * 1e6),
                (int)(longitude * 1e6));

        OverlayItem overlayitem1 = new OverlayItem(point, "JD Sports",
                "This is a sports shop");

        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);
        // Fitness first marker ends
    }

}

My HelloItemizedOverlay class:
public class HelloItemizedOverlay extends ItemizedOverlay {

    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    private ArrayList<OverlayItem> mOverlays1 = new ArrayList<OverlayItem>();

    public HelloItemizedOverlay(Drawable defaultMarker) {
        super(boundCenterBottom(defaultMarker));

    }

    public void addOverlay(OverlayItem overlay) {

        mOverlays.add(overlay);
        populate();
    }

    public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
        super(defaultMarker);
        Context mContext = context;
    }

    @Override
    protected OverlayItem createItem(int i) {
        // TODO Auto-generated method stub
        return mOverlays.get(i);
    }

    @Override
    public int size() {
        // TODO Auto-generated method stub
        return mOverlays.size();
    }

    @Override
    protected boolean onTap(int index) {
        OverlayItem item = mOverlays.get(index);
        Context mContext = null;
        AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
        dialog.setTitle(item.getTitle());
        dialog.setMessage(item.getSnippet());
        dialog.show();
        return true;
    }

}

Comment: what's the problem on adding another layer just as you did with the first one itemizedoverlay.addOverlay(overlayitem), and it would be nicer if you could format all that is code as code...
Answer: OverlayItem overlayitem1 = new OverlayItem(point, "JD Sports, ...

Should read
OverlayItem overlayitem1 = new OverlayItem(point1, "JD Sports", ...

Shouldn't it?
Answer: Try this:
...
Drawable drawable1 = this.getResources()
            .getDrawable(R.drawable.fitness_first_logo);
boundCenterBottom(drawable1);
...


C corruption or double free, why?

Question: I have a C code (first C code I have ever written), and there is an error in it, but I dont know, where. When I try to free a variable (dinamically allocated, its name is out_html) I get double free or corruption. I have no idea why my program does this, I checked all my calls for free etc.
The code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>

#include "fcntl.h"
#include "errno.h"

#include "sys/types.h"
#include "sys/stat.h"

#include "unistd.h"

#define MAX_SIZE 512

typedef struct node
{
    char* data;
    struct node * nextnode;
} node;

int max(int a, int b)
{
    if(a>b) return a;
    else return b;
}

node* push(node * stackTop, char* data)
{
    //static
    node* newItem;

    newItem = calloc(sizeof(node),1);
    newItem->data = data;
    newItem->nextnode = stackTop;

    return newItem;
}

node* pop(node* stackTop)
{
    if(stackTop != NULL)
    {
        free(stackTop->data);
        node* P = stackTop;
        return stackTop->nextnode;
        free(P);
    }else return NULL;
}

int isMajorTag(char* tag)
{
    if(strcmp(tag, "") == 0 || strcmp(tag, "") == 0 ||
       strcmp(tag, "") == 0 || strcmp(tag, "") == 0 ||
       strcmp(tag, "") == 0 || strcmp(tag, "") == 0 ) { return 1; }
    else                         { return 0; };
}

int isHTMLtag(char* tag, char* tags)
{
    char* tag2;
    if(strstr(tag," ") != NULL)
    {
        char* strptr = strstr(tag, " ");
        int End = strptr - tag;
        char* tag_ = strndup(tag, End);
        tag2 = calloc((strlen(tag_) + strlen("*") + 2), sizeof(char));
        strcpy(tag2, tag_);
        strcat(tag2,"*");
        free(tag_);
    }
    else tag2 = tag;
    int ret;
    if(strstr(tags, tag2) != NULL){ ret =  1; }
    else                         { ret = 0; };
    if(tag2 != tag ) free(tag2);
    return ret;
}

int isCloserTagOf(char* cltag, char* tag)
{
    int ret = 1;
    if( cltag[1] != '/' ) ret = 0;
    if( tag[1] == '/' ) ret = 0;
    char* ntag;
    char* ncltag;
    if(strstr(tag," ") != NULL)
    {
        char* strptr = strstr(tag, " ");
        int End = strptr - tag;
        ntag = strndup(tag, End) + 1;
        // ntag = calloc(strlen(ntag0) + 1 + 1, sizeof(char)); strcpy(ntag, ntag0); strcat(ntag, ">");
        ncltag = strndup(cltag+2,strlen(cltag) - 3);
    } else
    {
        ntag = tag + 1;
        ncltag = cltag + 2;
    }
//  printf("|%s|%s|  %i", ntag, ncltag, strcmp(ncltag, ntag));

    if(strcmp(ncltag, ntag) != 0) ret = 0;
    return ret;
}

int isIndividualTag(char* tag)
{
    if(strcmp(tag,"
") == 0) return 1;
    else if(strncmp(tag,"

C corruption or double free, why?