SPF and DKIM configuration Ubuntu 18.04 fails

Question: I have been following this tutorial from DigitalOcean. I have followed every detail but nothing seems to work as expected.
Assuming that my FQDN is the following: mydomain.com. Here are my details:
SPF (DNS):
~$ dig mydomain.com txt

OUTPUT:
;; ANSWER SECTION:
mydomain.com.       600 IN  TXT "v=spf1 -all"

TESTING:
~$ sudo echo "test email" | sendmail email@example.com

EMAIL RECEIVED OUTPUT:
==========================================================
Summary of Results
==========================================================
SPF check:          fail
"iprev" check:      pass
DKIM check:         permerror
SpamAssassin check: ham

==========================================================
Details:
==========================================================

HELO hostname:  mail.mydomain.com
Source IP:      xxx.xxx.xxx.xxx
mail-from:      email@example.com

----------------------------------------------------------
SPF check details:
----------------------------------------------------------
Result:         fail
ID(s) verified: firstname.lastname@example.com

DNS record(s):
   mydomain.com. 60 IN TXT "v=spf1 -all"

Notice: Using Postfix as MTA for my mail server
Answer: Your SPF record of v=spf1 -all says "literally no server on the internet can send mail on this domain's behalf". All mail will fail. Your tutorial links to a separate tutorial on setting up an SPF record.
Comment: If you're sending from Gmail for this domain (which you presumably are, given you're using their MX records), you [must include Gmail's SPF in your SPF record](https://support.google.com/a/answer/33786?hl=en). Having the MX does not remove this requirement. **You really do need to understand what you're doing here or your emails will go missing.**
Comment: Based on your experience what do you think is the best SPF value?
Comment: It should be a comprehensive list of the servers you intend to send email with. If you send emails for that domain from Gmail, you'll need to include Gmail's recommended SPF records. If you send from your VPS, you'll want it's IP in there.
Comment: I already have the Gmail MX in place. I only send from my server so I will set the IP address alone. Thanks
Comment: Seems like I still have more readings to do. Thanks buddy! I will Google this.
Answer: There's two things wrong that I see.
First, as has already been pointed out, your SPF record is wrong.  SPF records tell the world what IP address/es your outbound mail server sits on.
Lets consider a really simple case where outbound and inbound mail are dealt with by the same server.
v=spf1 mx -all

Looking at each part
v=spf1 - The version number of the SPF record - currently only spf1 is defined.
mx - use the IP addresses of servers found in my domains MX records
-all All in this context means every address and the - before it means hard fail.
If setting an SPF record up is daunting - you could try one of the many SPF generators such as:
https://mxtoolbox.com/SPFRecordGenerator.aspx
However you also have another problem:
DKIM check:         permerror

This suggests that your mail is being signed by the mail server but there's a problem with the DKIM record this could be anything such as
No record in DNS
Improper DKIM record in DNS
This may seem a little vague, but the first thing I'd do is to look at the DKIM signature on one of your outbound mails.  Two things to note will be the d= and s= values
d= is the domain responsible for signing the mail.
s= is called the DKIM selector.
If you look for a txt record under the following record:
._domainkey.
For example if I take a DKIM signature from Twitter
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=twitter.com;
    s=dkim-201406; t=1554045794;
    bh=JrX7TaDioaOnxGz+nN85Zv7ueFvbyTa36Avx+BeDPEI=;
    h=Date:From:To:Subject:MIME-Version:Content-Type:List-Unsubscribe:
     Message-ID;
    b=CD/rqEhFqCH0gkh9zOoWsCynbem2PChQMiR0apSSXQg4IPigtJXfDNsZQg0/Q1V6K
     NimuwFUiIMRwyV7Q2Ck2HuWABt13yVTX2LZhHqCWPEzYYWXAii0fyPeNT6U/PbZfSQ
     0/ZL1zE11E/iVKgqCQalVR+om6au/dE4V2fqnw3DMTXrU+Up5dS7N+Xkrm0/FQQ6N4
     LIr06Nq9Neft8ScJvcxsf/9KL+NJY8uhpXZJ6grdE/as+73Qw9fv0MZZ7M33zhcIMs
     WgIy0HtvxPJ0Bha+z2aLTZDGxudmxfhMFjuQtnXhs9xCePX4izVYKx909+oilJ6Dgt
     ppww0Don384fQ==

We see that
d=twitter.com
s=dkim-201406
So if we do a DIG
C:\Users\timdu>dig txt dkim-201406._domainkey.twitter.com

; <<>> DiG 9.10.6-P1 <<>> txt dkim-201406._domainkey.twitter.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32288
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;dkim-201406._domainkey.twitter.com. IN TXT

;; ANSWER SECTION:
dkim-201406._domainkey.twitter.com. 300 IN TXT  "v=DKIM1; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwe34ubzrMzM9sT0XVkcc3UXd7W+EHCyHoqn70l2AxXox52lAZzH/UnKwAoO+5qsuP7T9QOifIJ9ddNH9lEQ95Y/GdHBsPLGdgSJIs95mXNxscD6MSyejpenMGL9TPQAcxfqY5xPViZ+1wA1qcr" "yjdZKRqf1f4fpMY+x3b8k7H5Qyf/Smz0sv4xFsx1r+THNIz0rzk2LO3GvE0f1ybp6P+5eAelYU4mGeZQqsKw/eB20I3jHWEyGrXuvzB67nt6ddI+N2eD5K38wg/aSytOsb5O+bUSEe7P0zx9ebRRVknCD6uuqG3gSmQmttlD5OrMWSXzrPIXe8eTBaaPd+e/jfxwIDAQAB"

We find the DKIM record which has the public key used to verify the signature and body hashes of the email.
So you need to make sure that you've got an equivalent record set up correctly.


Is it possible to create that query using Spring Data with mongoDB?

Question: like in question is it possible to create that query?
db.persons.find({ 'oi': '5f2417e3c655cb13e85186df', 'ch': { $elemMatch: { 'type': { $in: ['MAN']  }}}}, {'ch.$': 1})

The last part of this query is problematic. How to retrive fields that pass the $elemMatch predicate only.
Spring data @Query annotation have field property but if specify it by {'children: 1'} I retrive all children instead of this which pass the query.
{ 'children.$': 1} doesn't work of course.
Answer: You can use @Query annotation. Pass the query in value and projection in fields inside @Query annotation like this
@Query(value = "{ 'oi': ?0, 'ch': { $elemMatch: { 'type': { $in: ?1 }}}}", fields = "{'ch.$' : 1}")
Person findPersonCustom(String id, List<String> types);

Here ?0 & ?1 will be passed as method arguments 0 & 1 respectively. You can also put that values inside @Query directly if they are static.
The resulted Person object will contain only matched elements from ch array.
Comment: That is not true. It will contains all array.
Comment: It actually works, I am using spring boot 2.1.5 with mongodb 4.0 and it works. There may be something wrong with code or field names. Can you post the code with which you have tried?
Comment: also turn on logging to see query using `logging.level.org.springframework.data.mongodb.core.MongoTemplate=DEBUG`
Comment: Are you sure that it is possible to pass positional operator to fields value ?
Comment: Yes I am sure as I have used these type of queries in my project and it works


Should we use AUC as an indicator of overfitting when dataset is highly imbalanced?

Question: In my problem, there are 2 class labels, but one label only counts for 1% of the total data. I first divided my data set by train_test_split such that only 10% are test set, then I performed 10-Fold cross validation and below is the AUC on the validation set for 10 folds:
<code>0.8339720951796847
0.8339720951796847
0.8340767220106542
0.8331529270822466
0.8293208019913448
0.8474731942921908
0.8545871857725601
0.8235138776279672
</code>
which seems to have very low variances between each fold.
However on the test set: AUC=0.543546.
The situation is even worse if I use StratifiedShuffleSplit: while the average AUC for cross validation is still around 0.85, the AUC on the test set is 0.2.
My question is: Can we use AUC as an indicator for overfitting when dataset is highly imbalanced? Since the test set now is very small and the auc should not be expected to be as accuracy as when cross validation.
Answer: AUC seems to be OK to use with imbalanced classes, although the precision-recall curve is better, as explained for example here AUC and class imbalance in training/test dataset
However, you MUST use StratifiedShuffleSplit (or any other stratified sampling which ensure the splits preserve class distributions) with imbalanced classes, otherwise you risk getting really bad test sets (missing the minority class, and overestimating your model's performance). This is reflected in your results: without Stratified sampling, the test AUC is better, 0.54 vs 0.2 with StratifiedShuffleSplit. I am quite sure the true performance metric of that model is 0.2, not 0.54.
Answer: One way to check if you're overfitting using AUC is also to apply it directly on your train data, and compare it to your validation. If you have a huge difference (with a train AUC way better, meaning you know the train data "too much"), that means you're overfitting.


Return ViewModel instead of Model

Question: The following method returns a IEnumerable MODEL called PROF.
Instead of using the model, I want to use a viewModel which contains the same fields as the Model PROF. How can i make changes to the following function to return my VIEWMODEL(which is called MyProfViewModel ) instead of the model (which is called PROF ).
public async Task<ActionResult> Index()
{
    var cp= db.PROF.Include(c => c.ACCOUNTS);

    return View(await cp.ToListAsync());
}

ViewModel
public class MyProfViewModel
    {

        public int myprofID { get; set; }

        public string myprofDes{ get; set; }
    }

Model
public class PROF
    {

        public int ID{ get; set; }

        public string DESCRIPTION { get; set; }
    }

Comment: Maybe you just need to "map" the model to viewmodel and return that...?
Comment: @Illep if you want to know more about AutoMapper, then go to the [website](http://automapper.org/) or use google to find plenty of blogs, tutorials, questions on here etc. Also note *kayess* advice above. AutoMapper can be a great time saver if you find you're writing a lot of  brain-dead mapping code, but probably shouldn't be introduced for one simple use case.
Comment: Can you tell me how it's done. I am a newbie.
Comment: If the properties were actually named *the same* (and not just similar), then you could use a AutoMapper and the [`ProjectToListAsync()` extension method](https://lostechies.com/jimmybogard/2015/07/08/entity-framework-extensions-for-automapper/).
Comment: @CharlesMager Can you give me more details on `AutoMapper`. You mean if I have named my attributes with the same name in both the model and viewmodel ?
Comment: @CharlesMager that's an advice which can be considered good, however I would just like to add that to OP and future visitors that you need to weigh pros/cons of introducing another layer of abstraction/tool just for mapping easy tasks like this. JoelHarkes answer greatly shows an easier and probably faster way than say Auto-/or any other mapper tools.
Answer: Joel's answer is pretty much it. But since you mentioned you are starting I will provide a more deltailed answer to make more clear how to use.
First you define a conversion, in this case I put it in the ViewModel, but you can put it somewhere else that would make more sense in your project:
public class MyProfViewModel
{
    public int myprofID { get; set; }

    public string myprofDes { get; set; }

    public static MyProfViewModel FromModel(PROF model)
    {
        var viewModel = new MyProfViewModel()
        {
            myprofID = model.ID,
            myprofDes = model.DESCRIPTION
        };
        return viewModel;
    }
}

Then you just apply the conversion before returning:
    public async Task<ActionResult> Index()
    {
        var cp = PROF.Include(c => c.ACCOUNTS);
        var models = await cp.ToListAsync();

        var viewModels = models.Select(MyProfViewModel.FromModel);

        return View(viewModels);
    }

By the way, you can make the tranformation to models as well by adding this to your ViewModel class:
    public PROF ToModel()
    {
        return new PROF()
        {
            ID = this.myprofID,
            DESCRIPTION = this.myprofDes
        };
    }

Hope this helps!
Comment: Yup. Thank you. Helps a lot.
Answer: Add a select statement which maps one type to another:
db.PROF.Include(c => c.ACCOUNTS)
       .Select(x=> new MyProfViewModel(){myprofID = x.ID, ...});

Depending on if this select statement is supported by your ORM layer (Entity Framework?), I would do it before, or after .ListAsync();
Pros of before: could lead to better optimized SQL queries.

Return ViewModel instead of Model


Can decision stumps have more than 2 leaves?

Question: I understand decision stump: a shallow 1-level decision tree is often used as base-leaner in ensemble methods such as AdaBoost. What is not immediately clear to me is using such ensemble methods in multi-class classification task.
Can a decision stump have more than 2 leaves? Or each decision stump picks only 2-classes of the multi-class and fits model on?
I want to understand how decision stump works in a multiclass classification task. Which of this illustrations (my drawing) describe how it works (3-class problem for instance)?
Comment: None of these diagrams shows a decision stump because they all imply that the split is on the response, not on a predictor of the response. Fig 1a for example seems to show a perfect classifier that separates three classes with just one decision.
Comment: What do the arrows represent in the diagrams? Suppose you want to classify a new instance & you don't know its true class. How will the RF decide whether the instance belongs to the left, middle or right child of the root? The diagrams seem to focus (know?) on the response but at prediction time we only know the features.
Comment: "...they all imply that the split is on the response" can you please elaborate on your comment? How does decision stump works in multi-class?
Answer: You used the tag cart; CART trees always use binary splits.  However, the Quinlan family of decision tree algorithms support multiple-arity splits for categorical features, and such a stump could be used as the base learner for AdaBoost.
However, that doesn't say anything about multiclass targets.  All trees support multiclass problems, by using a version of impurity measures that take into consideration multiple classes.  Each node contains a subset of your training set, and we record the number in each class.  The final class prediction is still just the majority class in a leaf, so a CART stump will predict at most 2 classes (but across the AdaBoost ensemble, probably all of the classes will eventually show up).  For example, a stump for the iris dataset (using just two features to keep it from being too good a split to be instructive):

The left leaf contains a large majority from the first class, so a row with first feature <=5.45 would be classified as the first class.  The right leaf contains nearly an even split between the second and third classes, but with the third class slightly more prevalent, and so predictions there will be the third class.  This leaves the second class un-predicted, so all of its examples are misclassified, and AdaBoost will increase its focus on them in future trees.
The trees can also produce "soft" predictions, the proportion of samples in a leaf for each class; this is done for random forests, but not in AdaBoost to my knowledge, since the reweighting uses information about the misclassified examples.  (In the example above, the right leaf would predict probabilities of 5/98, 44/98, and 49/98.)
All that said, you could produce multiple binary models in either a one-vs-one or one-vs-rest fashion if desired instead of relying on the trees' internal multiclass approach.
Comment: @arilwan I'm not entirely sure what you meant, but I added a simple example to the answer.
Comment: This explanation solves my doubt. Now I can see the logic. Tnx!
Comment: Ah, ok. I am curious about the multiclass approach. imagine a `3-class` problem, a `decision stump` that takes 10 training examples could provide one of the 3 possibilities? E.g. `class1=7, class2=2, class1=1`? Is that what you mean?
Answer: @Ben Reiniger has a more complete answer with lots of useful details about random forests; definitely read that first.
I, on the other hand, want to elaborate on one single point: each decision in a tree-based model splits examples according to a single feature.
Consider the following example: we have n continuous features Xi and a categorical response with three levels y1, y2, y3. At each split the model chooses feature Xi and comes up with a decision rule such as:

If Xi < some number x, then the example belongs to the left child of the root. If Xi $\geq$ x, then it belongs to the right child.

What would a three-way split look like?

If Xi < some number x1, go left; if Xi is between x1 and x2, go in the middle; if Xi $\geq$ x2 then go right.

You suggest that since the target has three levels, three-way splits might be more appropriate. However:

Three-way splits are more complex to estimate: we need to find two cutoff values x1 and x2 instead of just one x by optimizing a metric such as impurity.
One three-way split is equivalent to two consecutive two-way splits so a tree-based model with binary decisions is just as flexible.
There is no guarantee that any given feature Xi separates all three classes from each other. (Maybe both y1 and y2 instances tend to have low Xi and only y3 instances tend to have high Xi).


Como adaptar um app em Android a diversos tamanhos de tela?

Question: Por exemplo...
Quero o app em Android seja apresentado igualmente tanto em telas de 5" à 3"...
E como faço para aplicar um layout de "rolagem", como adiiconar um scroll ao layout em Android?
Comment: E tipo assim... Estou rodando o app em um aparelho com uma tela de 5", e na minha activity tenho certos elementos com um valor de marginTop... E quando vou rodar essa mesma activity em um aparelho de 3" ele acaba ultrapassando os limites da tela... Tem como definir uma activity específica para aparelhos com esse determinado tamanho de  tela?
Answer: Use wrap_content e match_parent:
Para garantir que o seu layout seja flexível e se adapte a diferentes tamanhos de tela, você deve usar "wrap_content" e "match_parent" para a largura e altura de alguns componentes de visualização. Se você usar "wrap_content" , a largura ou a altura da view ficará definida para o tamanho mínimo necessário para se auto ajustar ao conteúdo que está dentro, enquanto "match_parent" (também conhecido como "fill_parent" anterior à API 8) faz com que o componente se expanda para corresponder ao tamanho da view(parent ou pai).
Exemplo do uso de "wrap_content" e "match_parent":
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout android:layout_width="match_parent"
                  android:id="@+id/linearLayout1"
                  android:gravity="center"
                  android:layout_height="50dp">
        <ImageView android:id="@+id/imageView1"
                   android:layout_height="wrap_content"
                   android:layout_width="wrap_content"
                   android:src="@drawable/logo"
                   android:paddingRight="30dp"
                   android:layout_gravity="left"
                   android:layout_weight="0" />
        <View android:layout_height="wrap_content"
              android:id="@+id/view1"
              android:layout_width="wrap_content"
              android:layout_weight="1" />
        <Button android:id="@+id/categorybutton"
                android:background="@drawable/button_bg"
                android:layout_height="match_parent"
                android:layout_weight="0"
                android:layout_width="120dp"
                style="@style/CategoryButtonStyle"/>
    </LinearLayout>

    <fragment android:id="@+id/headlines"
              android:layout_height="fill_parent"
              android:name="com.example.android.newsreader.HeadlinesFragment"
              android:layout_width="match_parent" />
</LinearLayout>

Resultado:

Leia mais...
Comment: Ótima resposta, mas não seria legal falar do  "match_constraint" também?
Answer: Acredito que na maioria dos casos declarar os elementos do XML utilizando wrap_content e match_parent funciona bem.
Porém, para comportar diferentes situações com maior liberdade, o Android permite a declaração de elementos com base no tamanho da tela, densidade e orientação. Isso com certeza pode fazer toda a diferença.
Para utilizar vários arquivos diferentes, basta declará-los com um identificador.
Por exemplo:
se você declarar res/layout/main_activity.xml esse recurso será o padrão, porém ao incluir o arquivo res/layout-sw600dp/main_activity.xml, o sistema carregará este layout caso a menor largura (smallest width) seja de 600dp.
Esse princípio se mantem para qualquer outro qualificador, como por exemplo res/layout-land/main_activity.xml que será carregado caso o aparelho esteja em modo paisagem.
Uma lista com os qualificadores pode ser encontrada aqui.


Alternative to data binding

Question: As an alternative to binding an array collection to a data grid's data provider, could I assign the array collection as the data provider to the data grid on it's creation and everytime the array collection is updated execute invalidateProperties(); invalidateList(); to re-render the data grid?
Does my described approach make sense?
Comment: @Wade: Could you elaborate on why you're leaning toward "no"? Thanks.
Answer:
Does my described approach make sense?

Sort of.   If you have an arrayCollection ( ac) defined using a get/set method, there is no reason you can't set the dataPRovider on your DataGrid in the set method, every time the data is changed.
If you do that, then you most likely will not have to update the properties or displayList of the DatGrid, because the mere fact of replacing the dataProvider will do it for you.
Something like this:
private var _ac : ArrayCollection;
public function get ac():ArrayCollection){
 return this._ac;
}

public function set ac(value:ArrayCollection){
 this._ac = value;
 this.dataGrid.dataProvider = this.ac;
}

Bingo, every time that the ac value is updated, so will the dataProvider on the DataGrid.
Comment: @Flextras: The caveat is the collection is being modified item-by-item rather than as a whole collection, i.e. `_ac.addItem(obj);` Ideally, I'd like all the objects to be added/removed from the collection before (re)assigning it as the data grid's data provider. Is that possible via the getters/setters approach?
Comment: @dank106 I think understand better now. You're not changing the dataPRovider reference, but rather changing the collection that that reference points to.  Is taht correct? The DataGrid should update automatically when items are added removed in a Collection.  This has nothing to do with binding.  It is because the DataGrid implements a collectionChange event handler.  However, the DataGrid will not update if you modify properties in the objects in the collection.  For that you'll have to do the relevant invalidation on the DataGrid.
Comment: @Flextras: Yes, you're correct. I am looking for a more efficient way to handle the changes to the collection; I want to wait for all the changes in the collection to occur before forcing the grid to re-render. Also, thanks for pointing out the Data Grid implements the collection change handler; I was under the impression that binding was required.
Comment: You can check the code, but most likely the default collectionChange handler makes use of the component lifecycle; in which case a bunch of changes in succession will not update "all at once".  However, you could always extend and override to change the default approach.

Alternative to data binding


can somebody explain the outcome of macro (preprocessor) in c (SQUARE(X) X*X why it yields to 49 where x =5 by sending ++x

Question: see code below . The output is 49 ( 7*7 = 49) . How this could happen? can somebody explain in details.
#include <stdio.h>
#define SQUARE(X) X * X
#define PR(X) printf("The result is %d.\n", X)

int main(void) {
  int x = 5;
  printf("x = %d\n", x);
  PR(SQUARE(++x)); // print out 49 but x is 5

  return 0;
}

Comment: just.... use a function, please
Comment: This is the very classic example of a macro pitfall. https://gcc.gnu.org/onlinedocs/cpp/Macro-Pitfalls.html
Comment: The macro also needs parentheses: `#define SQUARE(X) ((X) * (X))`. Consider that will happen with `SQUARE(2+1)` which yours expands to `2 + 1 * 2 + 1` which is `5` not `9`.
Comment: @WeatherVane trying it with  your suggestion does not make any difference in relation to the question .
Comment: @AlamM that is because in this case `7 * 7` evaluates the same as `((7) * (7))`. The comment wasn't a suggestion, but is pointing out a **fault** in the macro.
Answer: It will expand this way:
PR(SQUARE(++x));
==>
PR(++x * ++x)
==>
printf("The result is %d.\n", ++x * ++x);

And, modifying variable x twice without a "sequence-point" (mainly, a semi-colon ;, but there are other sequence-points) creates Undefined Behavior
Comment: Thanks . Undefined Behavior should yield different result once executed many times; However, seems it is up to GCC interpretation to  increment x twice and multiply it with each other like 7*7. My compiler . GCC (MinGW.org GCC-6.3.0-1) 6.3.0. Thanks for your support
Comment: No, Undefined Behavior does ***not*** mean *"random, unpredictable, unstable behavior"*.  It may very well be consistent within one compiler.  But another compiler or platform or build may produce a wildly different, behavior while still being a completely Standard Compiler because the code you gave does not have a Defined Behavior.
Comment: Many thanks for clarification. I have noted this


Application of Slutsky's Theorem

Question: Let $X_i$ be a random variable.
Let $\{X_i\}_{i=1}^{n}$ be a sample of observations i.i.d. over $i$ with $ \mathbb{E}(X_i)=\mu$ and $Var(X_i)=\sigma^2>0$.
Let $\bar{X}_n:=\frac{1}{n}\sum_{i=1}^{n}X_i$.
Let $\hat{\sigma}_n^2\geq 0$ be a consistent estimator of $\sigma^2$ as $n \rightarrow \infty$.
By CLT, $\frac{\bar{X}_n-\mathbb{E}(\bar{X}_n)}{\sqrt{Var(\bar{X}_n)}} =\sqrt{n}\frac{\bar{X}_n-\mu}{\sigma} \rightarrow_d N(0,1)$ as $n \rightarrow \infty$.
Using $\hat{\sigma}_n^2 \rightarrow_p \sigma^2$ as $n\rightarrow \infty$ and applying the Slutsky's Theorem,  we can conclude that
\begin{equation}
\sqrt{n}\frac{\bar{X}_n-\mu}{\hat{\sigma}_n} \rightarrow_d N(0,1)
\end{equation}
as $n \rightarrow \infty$.
Let $\{\epsilon_n\}_{n=1}^{\infty}$ be a sequence of positive constants approaching zero as $n \rightarrow \infty$. Hence $\tilde{\sigma}_n^2:=\hat{\sigma}^2_n+\epsilon_n$ is a consistent estimator of $\sigma^2$ as $n \rightarrow \infty$.
Therefore,
\begin{equation}
\sqrt{n}\frac{\bar{X}_n-\mu}{\tilde{\sigma}_n} \rightarrow_d N(0,1)
\end{equation}
as $n \rightarrow \infty$.
Questions:
1) Are all steps above right (in particular the final convergence in distribution result)?
2) How fast the sequence $\{\epsilon_n\}_{n=1}^{\infty}$ approaches zero is relevant somewhere? If it is relevant, how can I set that rate of convergence?
Answer: For 1) Yes, they are both correct.
2) no, the rate is irrelevant since its a sequence of constants that disappear in the limit.
Is there a counterexample that gave you concern?
Comment: In my application (which is more complex than the example I have posted here) $\hat{\sigma}^2$ can be zero and hence I need to correct it with some sequence of positive constants converging to zero. However I don't know how to set that sequence: $\frac{1}{n}$ or $\frac{1}{n^2}$ or $\frac{1}{\sqrt{n}}$ or...?
Comment: Do you think that the answer does not change if I define $\tilde{\sigma}^2_n:=\max\{\hat{\sigma}_n^2, \epsilon_n\}$?
Comment: @Cris That's a cool trick (I might actually use it in some of my work :-). As long as $\hat \sigma^2_n \xrightarrow{p} \sigma^2$ then your constants will cease to be important for some $n$, although if your $\epsilon$ converge slowly, then you'll be pushing this back.

Application of Slutsky's Theorem


Programmatically adding components with React

Question: I'm fairly new to React and I'm trying to add new components to already exsisting, but I am not sure how to do that.
So here I have the list of my Seances and the button to add more:
SeanceManager.js
return (
  <MDBRow>
    <MDBCol md="6">
      <MDBCard>
        <MDBCardBody>
          <form>

Sign up

              <MDBInput
                label="Type your email"
                icon="envelope"
                group
                type="email"
                validate
                error="wrong"
                success="right"
              />
              <MDBInput
                label="Type your password"
                icon="lock"
                group
                type="password"
                validate
              />

              <MDBBtn color="cyan" type="submit" onClick={props.submitLogin}>
                Log in
              </MDBBtn>

          </form>
        </MDBCardBody>
      </MDBCard>
    </MDBCol>
  </MDBRow>
);

By pressing the button to add more, a modal view pops up and at the end it has a submit button that should add the Seance.
AddSeanceModal.js
return (
  <Modal
    {...this.props}
    size="lg"
    aria-labelledby="contained-modal-title-vcenter"
    centered
  >
    <Modal.Header closeButton>
      <Modal.Title id="contained-modal-title-vcenter">Add Seance</Modal.Title>
    </Modal.Header>
    <Modal.Body>

        <form>
          {/*First row*/}
          <MDBRow>
            <MDBCol md="4">

                <input
                  type="file"
                  className="custom-file-input"
                  id="inputGroupFile01"
                  aria-describedby="inputGroupFileAddon01"
                />

                  Choose file

            </MDBCol>
          </MDBRow>

          {/*Second row*/}
          <MDBRow>
            <MDBCol md="4">
              <MDBInput
                onChange={this.changeHandler}
                type="text"
                id="materialFormRegisterPasswordEx4"
                name="algus_aeg"
                label="Algus Aeg"
                required
              />
            </MDBCol>
            <MDBCol md="4">
              <MDBInput
                onChange={this.changeHandler}
                type="text"
                id="materialFormRegisterPasswordEx4"
                name="lopp_aeg"
                label="Lõpp Aeg"
                required
              />
            </MDBCol>
          </MDBRow>

          {/*Third row*/}
          <MDBRow>
            <MDBCol md="4">
              <MDBInput
                onChange={this.changeHandler}
                type="text"
                id="materialFormRegisterPasswordEx4"
                name="aja_samm"
                label="Aja Samm"
                required
              />
            </MDBCol>
          </MDBRow>

          <Button variant="secondary" onClick={this.props.onHide}>
            Close
          </Button>
          <MDBBtn color="success" type="submit" className="float-right">
            Add Seance
          </MDBBtn>
        </form>

    </Modal.Body>
  </Modal>
);

And finally the Seance itself:
Seance.js
return (

 this.setState({ modalShow: true })}
  >

Seance nr: {this.props.id}

Start aeg: {this.props.startDate}

End aeg: {this.props.endDate}

      <button type="button" className="close float-right" aria-label="Close">
        ×
      </button>
      <ResultModal id={1} show={this.state.modalShow} onHide={modalClose} />

);

I also made a fiddle on sandbox:
https://codesandbox.io/s/qloo1vqr7j?fontsize=14
At the moment I have 4 static Seances, but it should start with 0 and add more once you add them.
Also the Xon the Seance should remove it.
I have tried creating a list on state in SeanceManager.js, but I have not understoond how to add components to the list from another component AddSeanceModal.
Comment: You can use a `for` loop to programmatically add components, see this answer: https://stackoverflow.com/questions/22876978/loop-inside-react-jsx
Comment: Where dou you save the information stored in your `Seance`s? Where is the code that `renders` each `Seance`?
Comment: Well they should be stored locally, but at the moment they aren't stored anywhere.
Answer: There are quite a few code choices that are holding your application back from being dynamic.
First, you'll need to utilize a container component that handles all things related to Seance state. This includes, adding, removing and viewing. All of this needs to be handled by a parent that updates its children according to what current in its state. Please follow this guide to understand containers vs components.
Second, you need to refactor how you're utilizing Seances. They need to be stored as an array within the parent's state. As you have it now, it's hard-coded with 4 <Seances /> that can't be removed/updated.
Instead, you should create an array of objects like so within state:
seances: [
  { id: "1", startDate: "2019-04-10 10:28:05.926-07", endDate: "2019-05-10 10:28:05.924-07" },
  { id: "2", startDate: "2019-04-11 11:28:05.926-07", endDate: "2019-05-11 11:28:05.924-07" },
  { id: "3", startDate: "2019-04-12 12:28:05.926-07", endDate: "2019-05-12 12:28:05.924-07" },
  ...etc
];

You'll utilize Array.map to map over this seances array and implicitly return these seances dynamically (to make easier to read, I'm writing your <Seance id={id} /> component inline):

  {seances.map(({ id, startDate, endDate }) => (

Seance nr: {id}

Start date: {startDate}

End date: {endDate}

     <button type="button" onClick={() => handleDeleteSeance(id)}>X</button>

  ))}

Now you'll remove these items from the seances array by utilizing Array.filter by a seance's id property. When a user clicks the "X" button it calls this.handleDeleteSeance with the specific seance id:
handleDeleteSeance = id => {
  this.setState(prevState => ({
    ...prevState, // spread out any previous state not related to "seances"
    seances: prevState.seances.filter(seance => seance.id !== id) // this translates to: compare each "seance" within "seances" and implicitly return any that do NOT match the "id" that was clicked
  })
};

To add an item to the seances array, you'll utilize the spread operator, and add an object with properties that were collected from a form:
handleSubmit = e => {
  e.preventDefault();
  const { id, startDate, endDate } = this.state;

  if (!id || !startDate || !endDate } return null; // if any properties are missing, don't add an item yet

  this.setState(prevState => ({
    ...prevState, // spread out any previous state not related to "seances"
    seances: [...prevState.seances, { id, startDate, endDate } ] // this translates to: spread out any previous seances and add a new object with "id", "startDate" and "endDate"
  });
}

Working with arrays example (since this a client-only implementation, I decided to filter by array position so I don't have to have to deal with generating unique ids; however, you can utilize uuid to generate these dynamic ids if you wish):

Other notes:

One of your components contains a let modalClose = () =>
this.setState({ modalShow: false }); within the render method.
This is invalid and should be defined as a class method.
Structure your components to be reusable. You have some components that are, but then you have some that reside within another component (like FileInput). As your application grows, you may need to use FileInput elsewhere for another form.
Utilize ES6 syntax throughout your project to simplify your code. For example you can deconstruct props for your Login component like so: const Login = ({ submitLogin }) => ( <MDBRow>...etc</MDBRow>);.
Comment: You bet. If you find that you're passing down props too many times and/or have way too many mounted children that are mounted but invisible, then you should look into redux: https://redux.js.org/introduction/getting-started. It acts like a container for your entire application, but it doesn't need to traverse the children to reach a component that requires some `state`. Instead, you just directly `connect` to the child that needs the `state`. However, your project, as of now, doesn't need this yet.
Comment: Awesome. That was my intention. I didn't want to fix your code, otherwise, if I did then you wouldn't learn nearly as much by doing it on your own.
Comment: Thank you for this answer, there is a lot to look into. I am pretty sure this is what I am looking for and will help me. I will accept this answer as soon as I get it working. Thank you a lot for your answer.
Comment: Can you answer this one question please. In my example I have `AddSeanceModal.js` and it was a component and I tried to switch it to a container as per your example. But the `` in that class requires `{...this.props}` and so does the `` in the end of that class. I tried passing `show` and `onHide` as proptypes like in yout codesandbox example you are doing with `age` and `name`, but that does not seem to cut it. What am I supposed to do with that?
Comment: In that case, you wouldn't deconstruct `props` if both `Modal` and `Button` need the `onHide` function. It'd be: `const AddSeanceModal = props => ( ...Close...`. HOWEVER, if the `Modal` doesn't need `onHide`, then you can do something like `const AddSeanceModal = ({onHide, ...rest}) => (  ...Close .. )`. You partially deconstruct `props` via `...rest`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#Rest_syntax_(parameters)
Comment: Ideally, you'd only have one container that updates all its children (not multiple). However, you can have a stateful `form` component that, once submitted, passes back its `state` to the `parent` it resides in. For example: `` resides in `App`. Now `AddSeance` has a `handleSubmit` prop via `this.props.handleSubmit`. This is especially useful if you want to make this `AddSeance` component self-contained (it handles its own `state` separately from `App`), but it still utilizes a class method from `App`.
Comment: Alright, I got it working. There are still some errors but I'm pretty sure I'll be able to figure them out. Thank you a lot, I will give you the bounty as soon as it lets me.
Comment: Did most of it from your example and finally got it all working. Thank you a lot.


Posterior predictive distribution and posterior predictive checks

Question: The posterior predictive density for replicated data $y_{rep}$ given observed data $y$ is
$$
p(y_{rep} \mid y)
=
\int p(y_{rep} \mid \theta) \cdot p(\theta \mid y)
\, \textrm{d}\theta,
$$
where the parameter vector $\theta$ is marginalised out from the joint distribution $p(y_{rep}, \theta \mid y)$ (ref).
In graphical posterior predictive checks, $B$ draws are sampled from the posterior distribution of $\theta$ and $B$ outcome vectors ($y_{rep}^{(1)}, \ldots, y_{rep}^{(B)}$) of the same size of the analytic dataset are simulated from the model (one vector for each posterior draw).
Kernel density estimate (for example) of the observed outcome is then overlaid to $B$ KDEs, one for each of the $B$ simulated outcome vectors (see, for example, Figure 6 in Gabry et al. on arXiv).
My question is: why did they write that each of the $B$ outcome vectors ($y_{rep}^{(b)}$) is simulated from the posterior predictive distribution? It seems to me that $y_{rep}^{(b)}$ is simulated conditional on a specific value of $\theta$ from the posterior distribution. There's no marginalisation there (afaict), and therefore how can each given outcome vector $y_{rep}^{(b)}$ come from the posterior predictive distribution?
To obtain a random draw from the posterior predictive distribution I would concatenate the $(y_{rep}^{(1)}, \ldots, y_{rep}^{(B)})$ vectors, marginalising out the posterior distribution (see for example this question here on Cross Validated). At that point, I would overlay the KDE of the observed outcome with the KDE of (what I believe is) the posterior predictive distribution.
Answer: To get the posterior predictive distribution, you would need to calculate the integral
$$
\int p(y_{rep} \mid \theta) \cdot p(\theta \mid y)
\, \textrm{d}\theta
$$
Notice that the code snipped from your first link does, it draws samples for the particular values of $\theta = (\alpha, \beta, \sigma)$. The example uses MCMC for Monte Carlo integration, i.e. instead of calculating the integral directly, you sample from the distribution and average over the samples.
<code>generated quantities {
  array[N] real y_rep = normal_rng(alpha + beta * x, sigma);
}
</code>
You need many samples because you approximate the distribution with the empirical distribution of the Monte Carlo samples.
Comment: Thank you, Tim! From that code, one gets a $S \times N$ matrix, where $S$ is the number of posterior draws and $N$ the number of observations. In Figure 6, they take 100 out of the $S$ rows and plot the corresponding 100 densities (the coloured lines). Each density is therefore based on $N$ observations simulated from the model using the same parameter vector drawn from the posterior. You wrote "You need many samples..." and I agree, but I would plot only one density from combining *all* the $S \times N$ sampled values, not by row as in Figure 6. What am I missing?
Comment: @boscovich usually you are interested also in the variability of the predictions.
Comment: Thanks again. I don't want to take up any more of your time, but how **each** of the $S$ vectors of length $N$ is drawn from the PPD is still beyond me. If one wanted to assess variability, I would generate multiple $S \times N$ matrices (say, $M$ of such matrices) and plot the associated $M$ densities. But then again, it's clear I am missing something.
Comment: @boscovich each of them is drawn from $p(y_{rep}|\theta)$, we use Monte Carlo integration to get the posterior predictive distribution. But the $p(y_{rep}|\theta)$ draws are interesting by themselves, so we often look at them as well.
Comment: Thanks! "Each of them is drawn..." now this makes _a lot_ of sense to me! But calling the $p(y_{rep} | \theta)$ "simulations from the PPD ($p(y_{rep} \mid y)$)" is  common. Other examples are: Stata's Bayesian analysis reference manual (page 444, https://www.stata.com/manuals/bayes.pdf) or Bayesian Data Analysis by Gelman et al. (Figure 6.2, http://www.stat.columbia.edu/~gelman/bayescomputation/bdachapter6.pdf). Personally, I find that quite confusing.
Comment: As a note to myself: no need of generating multiple $S \times N$ matrices. There's no uncertainty around the PPD. It's just a matter of increasing the number of posterior draws so that numerical integration is (for practical purposes) exact.


Finding zeroeth coefficient of a Chebyshev polynomial expansion

Question: Let $v_\theta = (\cos\theta,\sin\theta)$ be a unit vector in the plane. I have a kernel $p(\theta,\theta') = p(v_\theta\cdot v_{\theta'})$ that satisfies
$$\int_0^{2\pi} p(v_\theta\cdot v_{\theta'})\,d\theta' = 1\;\;\;(*)$$
for all $\theta\in [0,2\pi]$. I also have Chebyshev polynomials $T_0,T_1,\dots$ such that $T_k(cos\theta) = \cos(k\theta)$, normalized such that
$$\{T_0/\sqrt{\pi}\}\cup\{\sqrt{2/\pi}T_k\}_{k=1}^\infty$$
form an orthonormal basis of $L^2(-1,1)$ with weight $1/\sqrt{1-t^2}$.
Now I write the Chebyshev expansion of my kernel:
$$p(t) = \sum_{k=0}^\infty p_kT_k(t), \;\;\;\;\; t\in(-1,1)$$
and I want to show that $p_0 = \frac{1}{2\pi}$.
My progress so far: by orthonormality, we have
\begin{align*}
\int_0^{2\pi} &\frac{1}{\sqrt{\pi}}T_0(v_\theta\cdot v_{\theta'})\frac{\sqrt{2}}{\sqrt{\pi}}p(v_\theta\cdot v_{\theta'})\frac{1}{\sqrt{1 - (v_\theta\cdot v_{\theta'})^2)}}\,d\theta'\\
 &= \sum_{k=0}^\infty\int_0^{2\pi} T_0(v_\theta\cdot v_{\theta'})\frac{\sqrt{2}}{\sqrt{\pi}}p_kT_k(v_\theta\cdot v_{\theta'})\frac{1}{\sqrt{1-(v_\theta\cdot v_{\theta'})^2}}\,d\theta'\\
&= \sqrt{2}p_0.
\end{align*}
Also, noting that $T_0\equiv 1$, I know
\begin{align*}
\int_0^{2\pi} &\frac{1}{\sqrt{\pi}}T_0(v_\theta\cdot v_{\theta'})\frac{\sqrt{2}}{\sqrt{\pi}}p(v_\theta\cdot v_{\theta'})\frac{1}{\sqrt{1 - (v_\theta\cdot v_{\theta'})^2)}}\,d\theta'\\
&=\int_0^{2\pi} \frac{\sqrt{2}}{\pi} p(v_\theta\cdot v_{\theta'})\frac{1}{\sqrt{1 - (v_\theta\cdot v_{\theta'})^2}}\,d\theta'.
\end{align*}
Then it would suffice to show
$$\int_0^{2\pi}  p(v_\theta\cdot v_{\theta'})\frac{1}{\sqrt{1 - (v_\theta\cdot v_{\theta'})^2}}\,d\theta' = \frac{1}{2}.$$
This is where I'm stuck: I'm not sure how to use (*) in the expression above. Indeed since the expression above is constant in $v_\theta$ as we showed earlier, we are free to pick a particular value, say, $v_\theta = (0,1)$, to make this
$$\int_0^{2\pi} \frac{p(\cos\theta')}{\sin\theta'}\,d\theta',$$
but still I am not sure what to do with this.
Answer: As it turns out, using orthonormality was a a red herring, and the solution is actually quite simple. Choosing $v_\theta = (1,0)$, we compute
\begin{align*}
1 &= \int_0^{2\pi} p(v_\theta\cdot v_{\theta'})\,d\theta'\\
&= \sum_{k=0}^\infty \int_0^{2\pi} p_kT_k(v_\theta\cdot v_{\theta'})\,d\theta'\\
&= \sum_{k=0}^\infty \int_0^{2\pi} p_kT_k(\cos\theta')\,d\theta'\\
&= \sum_{k=0}^\infty \int_0^{2\pi} p_k\cos(k\theta')\,d\theta'\\
&= 2\pi p_0 + \sum_{k=1}^\infty \underbrace{\int_0^{2\pi} p_k\cos(k\theta')\,d\theta}_{= 0},
\end{align*}
and so $p_0 = 1/2\pi$.
Comment: Nice solution !


Problema com algoritmo de remoção de números repetidos em lista duplamente encadeada

Question: Alguém poderia me ajudar com o seguinte código?
void removeRepetidos(Lista *l)
{

    Elemento *aux = (*l);
    Elemento *aux2;
    Elemento *aux3;

    while(aux!=NULL)
    {
        aux2 = aux->prox;

        while(aux2 != NULL)
        {
            if(aux->num == aux2->num)
            {

                aux2->ant->prox = aux2->prox;

                if(aux2->prox!=NULL)
                {
                    aux2->prox->ant = aux2->ant;
                }

                aux3 = aux2;

            }

            aux2 = aux2->prox;
            free(aux3);
        }

        aux = aux->prox;
    }
}

Ele está crashando ao executar, ao retirar a função de desalocação free() o programa funciona perfeitamente. Nâo encontrei nenhum erro na lógica do meu código, fiz vários testes de mesa.
Answer: O ponteiro aux3 está sendo deletado duplamente,
void removeRepetidos(Lista *l)
{
  Elemento *aux = (*l);
  Elemento *aux2;
  Elemento *aux3;

  while (aux!=NULL)
  {
    aux2 = aux->prox;
    while (aux2 != NULL)
    {
      if (aux->num == aux2->num)
      {
        aux2->ant->prox = aux2->prox;
        if (aux2->prox != NULL)
        {
          aux2->prox->ant = aux2->ant;
        }

        aux3 = aux2;
        aux2 = aux2->prox; // <---
        free(aux3);        // <--- incluir aqui
        continue;          // <---
      }

      aux2 = aux2->prox;
      // free(aux3); // <--- tirar daqui
    }

    aux = aux->prox;
  }

}
Comment: Mas se eu liberar o aux3 antes do incremento `aux2 = aux2 -> prox` não terá problema? mesmo que o ponteiro aux3 receba o de aux2?
Comment: veja a nova edição


Updating release def results in error VS402903: The specified value is not convertible to type ReleaseDefinition

Question: I am updating release definitions using the onpremise Azure DevOps API using the following powershell script:
$listurl="https://onpremdomain/{ogr}/{proj}/_apis/release/definitions?api-version=6.0"

$PAT="Personal access token"

$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))

#get the releases' ids.
$result = Invoke-RestMethod -Uri $listurl -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get

#loop the ids to get each release's definition
foreach($release in $result.value){

#get each release's definition
 $definitionurl="https://onpremdomain/{ogr}/{proj}/_apis/release/definitions/$($release.id)?&api-version=6.0"

  $releaseDefinition = Invoke-RestMethod -Uri $definitionurl-Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get

  #loop through each stage
  foreach( $environment in $releaseDefinition.environments){

     #loop through each tasks to find the task group
     foreach($task in $environment.deployPhases.workflowTasks){

       # change the 'taskId'  to the taskId of your task group
        if($task.taskId -eq "{taskId}"){

            $task.version = "2.*"  # update the taskgroup version to the newest version
       }
     }
  }

    $updateurl="https://onpremdomain/{ogr}/{proj}/_apis/release/definitions?api-version=6.0"

    # update the release definition
    Invoke-RestMethod -Uri $updateurl -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -ContentType "application/json" -Method PUT -Body (convertto-json $releaseDefinition -Depth 100)
}

When Invoke-RestMethod in the last line is called I get the following error:
 Invoke-RestMethod : {"$id":"1","innerException":null,"message":"VS402903: The specified value is not convertible to type ReleaseDefinition. Make sure it is convertible to type ReleaseDefinition and
try again.","typeName":"Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, Microsoft.VisualStudio.Services.ReleaseManagement2.Data","typeKey":"InvalidRequestE
xception","errorCode":0,"eventId":3000}

Any idea why this error occurs?
Answer: REST API doc:
Get a list of release definitions.
Get a release definition.
Update a release definition.
Power shell script
$listurl="https://vsrm.dev.azure.com/{Org name}/{Project name}/_apis/release/definitions?api-version=6.0"
$PAT="{PAT}"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))

#get the releases' ids.
$result = Invoke-RestMethod -Uri $listurl -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get

write-host $result.value.id

#loop the ids to get each release's definition
foreach($release in $result.value){

#get each release's definition
$definitionurl="https://vsrm.dev.azure.com/{Org name}/{Project name}/_apis/release/definitions/$($release.id)?api-version=6.0"
#write-host $definitionurl
$releaseDefinition = Invoke-RestMethod -Uri $definitionurl -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get

  #loop through each stage
  foreach( $environment in $releaseDefinition.environments){

     #loop through each tasks to find the task group
     foreach($task in $environment.deployPhases.workflowTasks){
     write-host $task.taskId
       # change the 'taskId'  to the taskId of your task group
        if($task.taskId -eq "e213ff0f-5d5c-4791-802d-52ea3e7be1f1"){
            write-host $task.version
            $task.version = "1.*"  # update the taskgroup version to the newest version
            write-host $task.version
       }
     }
  }
    $updateurl="https://vsrm.dev.azure.com/{Org name}/{project name}/_apis/release/definitions?api-version=6.0"

    # update the release definition
    Invoke-RestMethod -Uri $updateurl -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -ContentType "application/json" -Method PUT -Body (convertto-json $releaseDefinition -Depth 100)
}

Update
I found the issue, the second Invoke-RestMethod method is missing the space before the -Headers parameter, and the issue should be Invoke-RestMethod : A positional parameter cannot be found that accepts argument 'System.Collections.Hashtable'.

After adding a space before the parameter, it works, you could check the pic below.
Comment: Hi @doorman, I have updated my answer, please check it and then kindly share the result here. If the issue still occurs, do you mind share a screenshot here? Such as above. Thanks
Comment: Hi @doorman, I found this issue and I have updated the answer, you could check the update, it should work, please check it and then kindly share the result here.
Comment: thanks! But I am still getting the same error even for release definitions that have not been updated
Comment: Hi @doorman, Just checking in to see whether this issue is still blocking you now? Any update for this issue?
Comment: Hi @VitoLiu-MSFT thanks for your help, I was still getting the same error so I decided to update it manually for now. It feels a bit of a hack to use the API and I feel it might make unexpected changes to the releases. So I updated all my releases to version 2 task group in each environment. I like the easy way of editing task groups using the draft->preview->publish method but it lacks support for publishing latest version to multiple releases. We will probably just update the same version instead until multi update feature is supported in the DevOps UI.
Comment: Hi @doorman, Are you using Azure DevOps Server or Azure DevOps Service? In addition, if you just change the 'taskId'  to the taskId of your task group and do not update the release definition, it will works, right?
Comment: By the way, could you please update the rest API version to 5.0 and then try it again?
Comment: Hi, thanks for your help. I am using Azure DevOps Server on premise (v18.170.30525.1) how can I update only the API? I didn´t change any property in the release definition just ran update on it so it didn´t work either.
Comment: Hi @doorman, How about the issue? Does the answer resolved your question? If not, would you please let me know the latest information about this issue?
Comment: Hi thanks for your help but I am still getting the same error. I am sorry but I won´t spend more time on this since I already updated the release definitions manually.


Can I use Price Resolvers for dynamic product pricing?

Question: All cart items are adding programmatically. I am trying to set a product cost based on various factors that change for each instance of an item added to the cart.
I discovered Price Resolvers and it seemed like it was working until I ended up adding 2 of the same "dynamically priced" items to my cart. Each was passed different prices and in my resolver I can see that the price is set correctly for each item. However, in the cart, they both have the same cost (the cost of the last item added to the cart).
My guess is that I can only set the price of an item per php session and not per cart item add. Is this correct? Is there some other way to dynamically set price of a product as it is added to a cart?
Answer: Eventually sorted this out on my own. Simple answer is NO, this is not the purpose of Price Resolvers. Price Resolvers can be used to "statically" set a price based on something which does not change during the php session - such as location, year, etc. But if you need to modify the price due to user input at the time; the correct solution is to set the Unit Price.
Before looking at Resolvers I already had this code:
<code>  $order_item = OrderItem::create([
    'type' => $item_type,
    'purchased_entity' => $variation->id(),
    'quantity' => isset($options['qty']) ? $options['qty'] : 1,
    'unit_price' => $my_dynamic_price,
  ]);
</code>
and I have seen posts and had been given suggestions that this works. It does not. Setting the unit_price at the time of OrderItem::create has no impact on the item's price. The correct way to do this is with the setUnitPrice() method like this:
<code>  $order_item = OrderItem::create([
    'type' => $item_type,
    'purchased_entity' => $variation->id(),
    'quantity' => isset($options['qty']) ? $options['qty'] : 1,
    'unit_price' => $variation->getPrice(),  // may be overwritten by $options['cost']
  ]);

  // If we are setting a custom cost, override unit_price now.
  if (isset($options['cost']) && $options['cost']) {
    $order_item->setUnitPrice($options['cost'], TRUE);;
  }
  $order_item->save();
</code>


Google Drive Integration with Single Account for Entire System

Question: Hi, everyone.
I have a use case for my system where I want to save my user's photos/files.
I want to upload these photos/files into Google Drive storage and save the link in my database.
It actually works :).
But the problem is when I upload a photo/file, its uploaded to specific user's account (the user that currently logged-in in browser).
How could I use a single account for my entire system, so every user can upload their files/photos to my system in same Google Drive storage (which is my account)?
Thank you
Answer: You need to provide an OAuth authentication on your webpage from where users will be able to login with Google account. When this is done, your account will act as a one stop service account for all the users to sign in and upload the files.
Follow the official Google documentation on Authorizing your app with Google drive to know more about the process. You need to get client ID and secret ID in order to validate other users so that they can make request through your developer account.
Follow the documentation on Upload Files to upload the files to Drive API.


Change placement of 'Read more' link in a teaser

Question: I have a view where the content is displayed as teasers on the page. There is a 'Read more' link that is displayed above the body text for each teaser (refer to the screenshot below, circled in red), but I would like it to sit underneath the body text instead. Any suggestions on how this can be done?
Answer: I figured out how to move the 'Read more' link to display below the body text for each teaser.
In my Drupal site, I went into 'Structure' in the main administration menu > 'Content types' > Selected the content type I created (in this case, it was: 'Blog post') > Manage display > and then went into the 'Teaser' tab. I was then able to move around the fields so that the 'Read more' link displayed below the body text.


Arquivo Corrompido em PHPExcel

Question: Ao gerar o arquivo PhpExcel de dados do banco de dados, o arquivo .xls está vindo corrompido, segue imagem
Qual seria o erro, já tentei achar mas não vejo nada de errado. Segue códigos.

O código PHP a seguir recebe os dados de outra pagina de um formulario preenchido. Onde o usuario seleciona a tabela do banco de dados e quais colunas queres gerar as informações.

// Incluimos a classe PHPExcel
include '../componentes/plugins/PHPExcel/Classes/PHPExcel.php';
$tabela = $_POST['txttabela'];# recebe o nome da tabela
$p_colunas = $_POST['chkcolunas'];  #recebe as colunas das respctivas tabelas
$qtdColunas = count($p_colunas); #conta quantas colunas o usuario selecionou
// Instanciamos a classe
$objPHPExcel = new PHPExcel();
if($tabela==""){
  echo "Selecione a tabela.";
}else{
$sel_sintaxe = "SELECT "; # adiciona o SELECT, deixando o parateses aberto para concatenar no proximo $sel_sintaxe
$row = 1;
$col = 0;
for($i=0; $isetActiveSheetIndex(0)
    ->setCellValueByColumnAndRow($col, $row, $p_colunas[$i]);
    $col++;
}
#Usando o substr, retiramos os ultimos dois caracteres, que no caso seriam o espaço e uma virgula, que estariamo na ultima coluna.
$sel_sintaxe = substr($sel_sintaxe, 0, -2);
#Concatena qual tabela sera pesquisada os dados
$sel_sintaxe .= " FROM ".$tabela."";
#recebe as condições que o usuario difiniu
 $RdNull = $_POST['rdNull'];
 $RdDescAsc = $_POST['rdDescAsc'];
if(isset($_POST['txtlimite'])){
    $txtLimite = $_POST['txtlimite'];
}
if($RdNull || $RdDescAsc || isset($txtLimite)){
    if($RdNull=="nao"){
        $sel_sintaxe .=" WHERE ";
        for($i=0; $i
#Após executamos a pesquisa
$sql_sel_tabela_preparado = $conexaobd->prepare($sel_sintaxe);
$sql_sel_tabela_preparado->execute();
// Podemos definir as propriedades do documento
$objPHPExcel->getProperties()->setCreator("Rech Lanches")
->setLastModifiedBy("Nome da Empresa")
->setTitle("Nome da Empresa - Avaliações")
->setSubject("Nome da Empresa - Avaliações - Exportação")
->setDescription("Dados Exportados do Banco de Dados");
// Alterando o tamanho da fonte
$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial');
$objPHPExcel->getDefaultStyle()->getFont()->setSize(11);
// Define a planilha ativa para o PHPExcel operar
$objPHPExcel->setActiveSheetIndex(0);
// Define o título da planilha
$objPHPExcel->getActiveSheet()->setTitle($tabela);
// Exemplo de preenchimento de dados de maneira dinâmica, a partir de um resultado do banco de dados por exemplo.
$linha = 3;
while($sql_sel_tabela_dados = $sql_sel_tabela_preparado->fetch()){
$col = 0;
for($i=0; $igetActiveSheet()->getStyle($colString."1")->applyFromArray(
            array('fill' => array(
                'type' => PHPExcel_Style_Fill::FILL_SOLID,
                'color' => array('rgb' => 'CBE28C')
            ),
            )
        );
        //Fazendo que as primeiras cédulas sejam em negrito
        $objPHPExcel->getActiveSheet()->getStyle($colString.'1')->getFont()->setBold(true);
        // Alterando o tamanho da fonte
        $objPHPExcel->getActiveSheet()->getStyle($colString.'1')->getFont()->setSize(14);
        // Qubra de linha ativada para todas as cédulas
        $objPHPExcel->getActiveSheet()->getStyle($colString)
        ->getAlignment()->setWrapText(true);
        // Alinha as cédulas ao meio
        $objPHPExcel->getActiveSheet()->getStyle($colString)
        ->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        // Alinha as cédulas ao centro
        $objPHPExcel->getActiveSheet()->getStyle($colString)
        ->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        // Alinha as cédulas.1 ao centro
        $objPHPExcel->getActiveSheet()->getStyle($colString.'1')
        ->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        // Define a largura das colunas de modo automático
        $objPHPExcel->getActiveSheet()->getColumnDimension($colString)->setAutoSize(true);
        //Cria as linhas em suas repectivas letras números e dados
        $objPHPExcel->setActiveSheetIndex(0)
        ->setCellValue($colString. $linha, $sql_sel_tabela_dados[$colunaInver]);
        $col++;
    }
 $linha++;
}
$nometabela = "nomedaempresa_".$tabela.".xls";
#redefinimos configurações para gerar o arquivo, definir um nome, e forçar seu download.
header('Content-Type: application/vnd.openxmlformats- officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$nometabela);
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
ob_end_clean();
$objWriter->save('php://output');
exit;
}
Comment: Esse `for` está muito errado `for($i=0; $isetActiveSheetIndex(0)
    ->setCellValueByColumnAndRow($col, $row, $p_colunas[$i]);
    $col++;
}`, o seu código gera algum erro?
Answer: Eu estava com mesmo problema, mude o ob_end_clean(); para abaixo da variavel $nometabela e atualize a extensão do arquivo para .xlsx Excel2007, e resolveu meu caso.
$nometabela = "nomedaempresa_".$tabela.".xlsx";
ob_end_clean();
header('Content-Type: application/vnd.openxmlformats- officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$nometabela);
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
}

Arquivo Corrompido em PHPExcel


Drupal 6 - Core Search Module Not Indexing Node Titles

Question: Search is working fine on my site if the search includes text that is in the body of a node, but it appears that node titles are not being indexed.
I'm just using the core search module.
Is this by design in Drupal 6 or is this a bug and how can I fix it?
Answer: I was able to fix this issue by changing the Indexing throttle setting for Number of items to index per cron run from 100 down to 10.
Once reindexing was complete all node titles appear to be indexed and appearing in search.


Process to put wamp server online

Question: Can anyone guide me, how to put wamp server online. Please tell me the whole process that i need to do to put it online. I want to host my own website.
Thanks in advance...
Answer: Wamp server is a Windows Web development environment for Apache, MySQL, PHP databases.it's a Web development platform on Windows that allows you to test dynamic Web applications LOCALLY.
You can't host you website with this.
You need a web host like OVH.
However, you can register a free DDNS ( like no-ip) ,implement it with your internet box, and configure WAMP with this.
And you will be able to host your website with your own computer
you can find a tutorial here : http://www.noip.com/support/.../diy-hosting-using-no-ip-wamp/
Answer: Windows: How to Host a Website Using Your PC as a WAMP Server
First, let's try hosting a website using your personal computer with the Windows operating system.
Step 1: Install the WAMP Software
To make this super easy, we'll use a WAMP installation program (of which there are several) called WampServer. You could also opt to install each package manually, but this process requires much more work and is error-prone.
The WampServer package is delivered with the latest releases of Apache, MySQL, and PHP.
WampServer is one of several environments available to create Apache, MySQL, and PHP applications on Windows.
First, download the 32-bit or 64-bit WAMP-binary here, and begin the installation. Just follow the on-screen instructions, and when it's done, launch WampServer.
Note: There may be a port 80 conflict with your Skype software, but there's a fix for that.
Step 2: Using WampServer
Upon installation, a www directory will be created automatically. You'll likely find it here: c:\wamp\www
From that directory, you can create subdirectories (called "projects" in WampServer), and put any HTML or PHP files inside those subdirectories.
The main screen of your localhost in WampServer should look something like this.
If you click on the localhost link in the WampSever menu or open your internet browser with the URL http://localhost, you should be shown the main screen of WampServer.
Step 3: Creating an HTML Page
To test our WampServer, we can put an example file called "info.php" into our www-directory.
Go directly to this directory by clicking "www directory" in the WampServer menu.
From there, create a new file with the contents below, and save it.
1
PHP Test
Now you can browse to http://localhost/info.php to see the details of your PHP installation. You can create any HTML and PHP file structure to suit your needs.
Step 4: Configure MySQL
If you click on the phpMyAdmin menu option, you can start configuring your MySQL databases (which may be needed for a CMS like WordPress).
The phpMyAdmin login screen will open in a new browser window. By default, the admin username will be root, and you can leave the password field blank.
From there, you can create new MySQL databases and alter existing ones. Most software, like WordPress, will automatically set up a new database for you, though.
Step 5: Make the Site Public
By default, the Apache configuration file is set to deny any incoming HTTP connections, except in the case of someone coming from the localhost.
To make your site publicly accessible, you need to change the Apache configuration file (httpd.conf). You can find and edit this file by going to the WampServer menu, clicking "Apache," and selecting "httpd.conf."
1
2
Order Deny,Allow
Deny from all
Replace the two lines above with the ones below:
1
2
Order Allow,Deny
Allow from all
Restart all WampServer services by clicking "Restart all Services" in the menu.
The site should now be accessible from beyond your localhost. Confirm there isn't a PC firewall blocking web requests. You may need to set up port-forwarding on your internet router as well.
Step 6: Using a Domain Name
To use a domain name, such as Example Domain, with your WAMP installation, we'll need to configure some files first. Let's assume our Example Domain domain has an A record in your DNS with the IP address 188.8.131.52.
First, we need to add the following line to the C:\Windows\system32\drivers\etc\hosts file:
1
18.104.22.168 Example Domain
Now, we need to edit httpd.conf again (accessible via the WampServer menu) to add a virtual host. Once that file is open, look for "Virtual hosts," and uncomment the line after it, like this:
1
2
Virtual hosts
Include conf/extra/httpd-vhosts.conf
Now we need to add a file manually in "C:\wamp\bin\apache\Apache-VERSION\conf\extra\" (VERSION is your Apache version).
Then create a file in Notepad with the following content, and save it in that Apache directory.
1
2
3
4
5
ServerAdmin firstname.lastname@example.com
DocumentRoot "c:\wamp\www"
ServerName mysite.local
ErrorLog "logs/example.com.log"
CustomLog "logs/example.com-access.log" common
Click "Restart All Services" in the WampServer menu to activate these changes.
Now your site should also be accessible via its domain name.
Linux: How to Host A Website on a Linux Machine
Let's now cover how to set up Apache, MySQL, and PHP on a Linux system.
Step 1: Install Software
To start our LAMP software install, type the following in the terminal:
1
sudo apt install apache2 mysql-server php libapache2-mod-php7.0
During the installation process, you will be asked to enter (and re-enter) a password for the MySQL root user.
Have your MySQL root password handy during the LAMP installation process.
Technically, it's not necessary (as it should have been done upon installation), but just to be sure, we will restart the Apache web server.
Any time you change the global configuration of Apache, you need to execute the command below, unless you do the configuration using local .htaccess files.
1
sudo /etc/init.d/apache2 restart
Step 2: Check PHP
To confirm your PHP server works and see what PHP modules are currently available, you can place a test PHP file in the web server root directory (/var/www/html/):
1
sudo echo "" > /var/www/html/info.php
We can now visit that PHP page by browsing to http://localhost/info.php.
You should see the currently running PHP version, current configuration, and currently installed modules. Note that you can later install other PHP modules using the Ubuntu package manager, as some PHP applications might require that.
To determine which extra modules are available, search within the graphical package manager, or simply use the command line:
1
apt search php | grep module
Step 3: Check MySQL
As most CMS systems (e.g., WordPress) use MySQL, we will also look at that part.
To see if your MySQL installation is working, type "service mysql status."
1
2
3
4
5
$ service mysql status
● mysql.service - MySQL Community Server
[...]
mrt 15 13:24:09 host1 systemd[1]: Started MySQL Community Server.
We see that MySQL is up and running. If you don't see this, you can type "sudo service mysql restart" to restart the MySQL server.
From here, we can use the MySQL command line client to manage databases.
For this, we need to use the admin credentials we typed earlier when MySQL was installed.
1
2
3
$ mysql -u root -p
[now you will be asked for our admin password and enter the mysql prompt]
From here, we can do anything we want with MySQL, e.g., create a new database:
1
2
CREATE DATABASE test;
USE test;
Often times, the CMS will automatically create the database for you, but sometimes you need to do something to the database manually (e.g., create a backup or optimize tables).
PHPMyAdmin is a friendly database management tool most web experts will recommend.
You can install PHPmyadmin by typing the following into the terminal:

Process to put wamp server online


Java - What Swing layout should i use?

Question: today i'm having a little problem, that probably is nothing for pros here :)
I want to have my Swing compononents in one horizontal line. I used FlowLayout and changed size of components on componentResized() according to the frame size, but it often bugged (sometimes the last component was placed in next row)... I've decided to use BoxLayout, but on that code:
    down=new JPanel(new BoxLayout(down,BoxLayout.X_AXIS));
    down.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
    down.add(Box.createHorizontalGlue());
    down.setPreferredSize(new Dimension(300,35));

it crashes with:
Exception in thread "AWT-EventQueue-0" java.awt.AWTError: BoxLayout can't be shared
at javax.swing.BoxLayout.checkContainer(Unknown Source)
at javax.swing.BoxLayout.invalidateLayout(Unknown Source)
at javax.swing.BoxLayout.addLayoutComponent(Unknown Source)
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at ButtonFrame.<init>(chat.java:278)
at chat$1.run(chat.java:20)
aso...

I dont know what to do, maybe i can make FlowLayout unable to make 2nd row, or make box layout work?
Thanks for any replies!
Comment: possible duplicate : http://stackoverflow.com/questions/761341/boxlayout-cant-be-shared-error
Answer: Copy-pasted from the Swing tutorial about BoxLayouts
JPanel listPane = new JPanel();
listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));

See how the panel is first created without any layout, and then the layout is set and created with the existing panel. This is different with your
down=new JPanel(new BoxLayout(down,BoxLayout.X_AXIS));

Adjusting this line (making it two separate statements as in the example) will remove the exception.
Oh yeah, a BoxLayout should allow to fulfill your requirement
Comment: Yes, the problem was that you were attempting create the JPanel's layout with itself.. And at that point the JPanel had not been properly initialized and cannot be used safely.
Answer: Take a look at http://www.miglayout.com/ which blows away anything Java provides itself. As soon as you need to do anything complex, it'll make your life worlds easier.
Answer: FlowLayout or BoxLayout are layout managers. The goal of a layout manager is to compute components position and size automatically, so you should not modify your components' size directly. Here, with componentResized() you are notified that a component has been resized. It may have been resized by layout manager automatically. If you modify your components' size here, it may trigger another automatic layout procedure, etc.
The preferred way to specify a size for your component is to set their preferred size before adding components to their container.
Answer: I often find that GridBagLayout has enough flexibility and control to do what I need.

Java - What Swing layout should i use?


Uploading files larger than ~4MB results in "The connection was reset" error

Question: On two of our servers we have an Ubuntu LAMP setup with PHP code designed to allow large image and audio uploads.  One of our clients is having an issue where they are unable to upload any files larger than ~4MB from any computer in their office. They get a "The connection was reset" this error in FireFox and in chrome they get "Error 101 (net::ERR_CONNECTION_RESET): Unknown error."  In chrome I can watch the upload percentage and see the upload fail around the time ~4MB is reached (53%) on an 7.79MB file.
It's not a speed issue as I've successfully uploaded files from slower networks.
Apache is returning no errors in the logs, and is recording the start of the post in the access log.
The PHP.ini is set to allow files up to 500MB and we have other clients doing this with no problems. I've upped the script timeouts of PHP as well.
I've tested uploading from a number of other locations to the servers with no errors; and I've also tested uploading from the clients location to other services, also with no errors.
I'm really at a loss i can't tell if it's a server error a client  and I'm hoping someone might know of something I can use to test or perhapses possibly a setting I might have missed.
Comment: I would start testing with some network tool like tracert, tcpdump and so on. I would also see if I could sftp a file to the server if that is an option from the client side. Is the client a PC or a Mac?
Comment: The client is a PC, I'll run a few tests using these options.
Answer:
and is recording the start of the post in the access log

No - apache only ever logs completion of a request in the access_log (unless you have some thing like mod_security which can be explicitly configured to post a log on submission). Which rather implies some of your other assertions may be wrong too.

The PHP.ini is set to allow files up to 500MB and we have other clients doing this with no problems. I've upped the script timeouts of PHP as well.

What is the apache config? (particularly LimitRequestBody, LimitRequestFieldsize, TimeOut) What version of apache?

One of our clients is having an issue ... from any computer in their office
  ...
  successfully uploaded files from slower networks.
  ...
  500MB and we have other clients doing this with no problems

That implies something specific to the connection between that office and your servers - e.g. a firewall. You can demonstrate by capturing a session using wireshark or similar (client is receiving a RST ostensibly from your server - you would be able to that packet at your end if it was your servers terminating the connection - if its something else terminating, then you won't see a RST packet leaving your server). Alternatively just direct them to the nerarest internet cafe and ask them to try from there to confirm its their problem.
Comment: Thanks this helped a lot in determining the final solution.
Answer: Is there a Firewall/IPS in between? We had this exact issue when a certain part of a file popped a false positive on our IPS, causing all sorts of drops and hangs with website access.
Comment: Turns out they had a filter that was being triggered by a rule associated with our domain.
Comment: No IPS on our end and I was able to upload the same file from their office to another service, on different servers.

I also wasn't able to upload the file to our development server which is using the same ISP as our production server although a different location entirely. Dev has the same server setup but a different firewall then our production system.
Answer: Have you checked the place where the uploads in progress are stored? /tmp or otherwise?
Do you have more than 4 MB space left? dmesg or system error log giving any clues?
Comment: The disk still has well over 400GB available and there's nothing in either dmesg or syslog.


Divisiblity by prime

Question: Find minimum positive integer pair $(x,y)$ such that $P$ divides $|C^x−D^y|$.
Here $P$ is a prime number and $C$ and $D$ are constants which are provided to us.
For example, if $P=7$,$C=1$,$D=5$, the minimum positive pair is $(x,y)=(1,6)$
(as $7$ divides $∣1^1−5^6∣=15624=7\times2232$).
How to approach this problem? Also how to check if such a pair exists or not?
I mean if in above example $C=8$ and $D=7$ then there is no such pair possible.
Comment: What is the order on the integer pairs? Suppose $p$ would divide both $C^2 - D^5$ and $C^3-D^3$, would $(2,5)$ or $(3,3)$ count as smaller?
Comment: If neither $C$ nor $D$ is a multiple of $P$, then the pair $(P-1,P-1)$ is a solution due to Fermat's little theorem. If $C$ and $D$ are both multiples of $P$, the pair $(1,1)$ is a solution. In the other cases (one constant is a multiple of $P$ and one not), there is obviously no solution.
Comment: How exactly do you define the minimum of the pair $(x/y)$?
Comment: sorry i did not mention it...We are defining minimum pair(x,y) if for given positive constants A and B ,Ax+By is minimum.(A,B will be provided)
Comment: for above example take A=1 , B=1
Comment: i will study fermat little theorem to understand your point..Thank you for your response
Comment: For large $P$, it is probably very hard to find the minimum solution.
Answer: As Peter noted, $(P-1,P-1)$ is a solution if $P$ does not divide either $C$ or $D$.  You can then calculate the values of $C^x, D^y \pmod P$ up through $P-1$ and search for a match.  This is of order $P^2$ in calculation because you have that many comparisons.

Divisiblity by prime


metafor zero variance level 2

Question: I'm running into zero variance at level 2 for a 3-level meta-analysis with metafor (rma.mv) in which effect sizes (esid) are clustered within studies (studyid). Here is my dataframe:
studyid <- c(1,1,1,1,3,3,4,5,5,5,5,6,6,7,7,7,7,7,7,7,7,8,8,9,10,10,10,10,11,11,11,11,12,12,13,13,14,14,
             15,15,18,18,18,18,19,19,19,20,20,20,20,21,21,21,21,22,22,22,23,23,23,24,24,25,28,28,28,
             29,29,30,30,30,31,32,32,34,34)
esid <- c(1:77)
yi <- c(4.20,2.90,2.70,3.90,1.40,0.80,11.40,5.00,21.50,20.84,28.73,7.40,4.00,1.38,0.47,1.44,0.46,1.63,
        0.46,0.67,0.41,9.24,9.27,8.80,27.30,22.83,18.25,20.08,0.94,0.97,0.77,0.88,14.00,10.40,0.52,0.86,
        29.39,33.82,15.30,15.92,45.60,63.10,46.40,44.60,0.10,0.11,0.12,0.17,0.26,0.26,0.31,8.20,1.80,
        1.70,9.58,10.15,8.05,0.53,18.95,17.44,23.50,12.62,15.62,4.60,35.10,44.85,33.30,13.30,11.90,0.34,
        0.35,0.26,0.69,0.50,0.62,23.80,20.40)
vi <- c(2.90,2.20,2.10,3.00,2.00,1.00,11.03,8.49,16.97,20.00,26.06,3.70,4.00,0.47,0.33,0.74,0.36,0.75,
        0.33,0.44,0.37,7.60,5.63,8.80,12.01,13.15,14.41,11.57,0.57,0.76,0.43,0.62,3.50,3.00,0.59,0.65,
        10.00,11.30,6.20,6.44,23.04,27.68,17.54,13.04,0.22,0.25,0.24,0.17,0.42,0.17,0.28,7.20,2.00,2.10,
        10.08,5.30,3.75,0.68,6.70,6.53,5.74,13.91,31.65,4.10,7.54,12.81,5.28,8.20,7.70,0.25,0.28,0.19,
        0.56,0.46,0.37,23.10,15.90)
df <- data.frame(authoryr,studyid,esid,yi,vi)

Here is my metafor code and output:
overall <- rma.mv(yi, vi,
                      data = df,
                      level = 95,
                      method = "REML",
                      slab = authoryr,
                      tdist = TRUE,
                      random = list(~ 1 | esid,
                                    ~ 1 | studyid))
summary(overall)

Multivariate Meta-Analysis Model (k = 77; method: REML)

   logLik   Deviance        AIC        BIC       AICc
-229.2872   458.5745   464.5745   471.5667   464.9078

Variance Components:

              estim     sqrt  nlvls  fixed   factor
sigma^2.1    0.0000   0.0000     77     no     esid
sigma^2.2  147.3645  12.1394     28     no  studyid

Test for Heterogeneity:
Q(df = 76) = 1930.1990, p-val < .0001

Model Results:

estimate      se    tval    pval   ci.lb    ci.ub
 10.7087  2.3165  4.6229  <.0001  6.0951  15.3224  ***

---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Visual inspection of the raw effect sizes suggests there is variance within-studies so I'm unsure what is wrong with my data (or code). I'd appreciate any guidance on solutions from the community.
Comment: Until the whole world uses R, it remains helpful to flag that that is your language.
Comment: Note that you forgot to include `authoryr` in the dataset. Not really needed, but then one either has to leave out the `slab = authoryr` line or use `slab = studyid` so that the code actually runs.
Comment: Thanks for the feedback Wolfgang and Nick. Apologies, I missed out the authoryr from the dataframe in my original post
Comment: Looking at the plot Wolfgang described it seems that different studies were measuring the effect on wildly different scales. Is there no way of making them more comparable?
Comment: @mdewey the scale is the same for all effects (grams) yet they differ with regard to the methods for clearing mucus in patients with respiratory diseases
Answer: There are really large differences between studies, but the estimates within studies do not vary more than one would expect based on their sampling variability alone. See:
forest(overall, efac=c(0,0.5))
abline(h=nrow(df) - cumsum(rle(df$studyid)$length) + 0.5, lty="dotted")

So it looks perfectly reasonable to me that the estimate of the between-study variance is very large while the estimate of the within-study variance is essentially 0.
Comment: Looking at the forest plot one would have to question what is going on here. Since the OP has not shared with us their scientific question that must remain a mystery.
Comment: @mdewey -  apologies for the excluding the research question; we are interested in the differences between methods for clearing mucus in patients with respiratory diseases.
Comment: @Wolfgang - thanks for the advice re visual inspection of the forest plot.

metafor zero variance level 2


DBContext object LINQ Sum(time) column to hours

Question: This is an ASP.Net Core Web API Project, using EntityFrameWorkCore.
I need to convert TotalLoggedInTime (format: 139:05:40) to Hours and Sum the hours and assign it to logonHours, it fails on that line.
The first line for callsOffered works fine.
C# Code:
internal void Hydrate(DbSet<MyObj> myObj)
{
    string callsOffered = myObj.Sum(a => a.CallsPresented).ToString();
    string logonHours = myObj.Sum(a => TimeSpan.Parse(a.TotalLoggedInTime).TotalHours).ToString();
}

SQL Table
SELECT total_logged_in_time FROM mytable

total_logged_in_time
139:05:40
157:22:46
157:26:51
148:17:42
157:23:14
138:04:28
175:27:41
162:35:44
163:13:13
144:36:12
9:01:56

Error

The LINQ expression 'TimeSpan.Parse((EntityShaperExpression:
      EntityType: MyObj
      ValueBufferExpression:
          (ProjectionBindingExpression: EmptyProjectionMember)
      IsNullable: False ).TotalLoggedInTime).TotalHours' could not be translated. Either rewrite the query in a form that can be translated,
  or switch to client evaluation explicitly by inserting a call to
  either AsEnumerable(), AsAsyncEnumerable(), ToList(), or
  ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for
  more information.

Solution:
Using the solution provided by @Arcord.
I had to add an extension method for converting the hours, but that's beyond the scope of this original issue.
string logonHours = myObj.ToList().Sum(a => a.TotalLoggedInTime.ToHours()).ToString();

public static double ToHours(this string valueInTimeFormat)
{
    double hours = 0;

    //hours = TimeSpan.Parse(valueInTimeFormat).TotalHours;

    int[] ssmmhh = { 0, 0, 0 };
    var hhmmss = valueInTimeFormat.Split(':');
    var reversed = hhmmss.Reverse();
    int i = 0;
    reversed.ToList().ForEach(x => ssmmhh[i++] = int.Parse(x));
    hours = (int)(new TimeSpan(ssmmhh[2], ssmmhh[1], ssmmhh[0])).TotalHours;

    return hours;
}

Comment: Is it okay to read the rows from the database and do the `Sum()` calculation in C# and not in the database?
Comment: What's up with the reversing, the extra ToList, the ForEach+callback and the closure over (and modification of) `i` in your extension method?? `new TimeSpan(int.Parse(hhmmss[0]), int.Parse(hhmmss[1]), int.Parse(hhmmss[2]))` would do the trick. `ToList().ForEach()` is an anti pattern--many people abuse `ToList` on an enumerable just to call `ForEach` instead of iterating normally with `foreach`. We wrote an analyzer to disallow it in our code base
Comment: @Progman I tried that, but since the data in time format could be like this 155:32:58, it's failing, throws this error in sql.
Operand data type datetime is invalid for sum operator.
Comment: @pinkfloydx33  I didn't actually pay attention to it, I had to quickly get it done, so I copied it from stackoverflow. It didn't make sense but it worked so I moved on. But you're right, it could be simpler. I'll fix it.
Answer: It's because it tries to convert your code to SQL.
string logonHours = myObj.Sum(a => TimeSpan.Parse(a.TotalLoggedInTime).TotalHours).ToString();

Of course everything is not convertible to SQL so in that case it fail.
You can use this :
string logonHours = myObj.ToList().Sum(a => TimeSpan.Parse(a.TotalLoggedInTime).TotalHours).ToString();

It should works but the ".ToList()" will force EF to fetch all data from the database and then (since everything is in memory) the code can be applied.
But only do this if you have a small amount of data! It's better not to put that kind of stuff in production if you don't know the expected load.
Edit
You could also also considers to store "ticks" instead of a string (like described here). In that case you will the able to do.
string logonHours = TimeSpan.FromTicks(myObj.Sum(a => a.TotalLoggedInTime)

More work will be done on the SQL server and you will only gather the sum.
You should also considers to use "async" version of methods (ToListAsync, SumAsync, ...)
Comment: I get this error now, it's the same format, not sure why it would fail.
The TimeSpan string '157:26:51' could not be parsed because at least one of the numeric components is out of range or contains too many digits.
Comment: This data is from Cisco box as xlsx file, and imported into SQL Server. I probably should convert it to ticks during the import process.
Comment: Instead of `ToList` it's better to use `AsEnumerable` that way you don't create an intermediate list that gets thrown away.
Comment: It's because you cannot create a timespan of more of 24h... So "24:12:45" will fail but not "1:00:12:45" will work (24h became 1 day). I'm afraid you will have to modify a little bit your code. You could maybe split the string, parse to int each part and convert it to seconds ?


Qt creator, insert custom menu at specified place into menu bar

Question: I have created a menu bar and some menus with Qt creator. One of the menus had to be coded to use QActionGroup features. Now it is easy to add my custom menu to the menu bar with:
printMenu = menuBar()->addMenu(tr("&Print"));

but my menu will be in the last position of the menu bar. How do I add my menu at a specified place? (e.g. the second place right after the File menu)
Greetings
Answer: Use QMenuBar::insertMenu in conjunction with QMenu::menuAction.
For example, if you want to dynamically insert the "Print" menu at the location before the "Help" menu, you can do something like this:
QMenu *printMenu = new QMenu(tr("&Print"));
menuBar()->insertMenu(ui->menuHelp->menuAction(), printMenu);

Comment: The usage of `new` caused some trouble: The menu was added, but *not* added to the child-list. Replacing `new` with `menuBar()->addMenu("whatever name")` did the trick (`QMenu *printMenu = menuBar()->addMenu(tr("&Print"))`). The menu is created correctly through the menubar and placed at the position of line 2 (if `insertMenu()` is not called, it's placed at the end).
Answer: If you want to add a sub menu in the middle of the menubar, this is not trivial. There is no direct API to do this but you can probably pull that out byt manipulating the internal actions of QWidget (QMenu::addMenu just calls QWidget::addAction(menu->menuAction()).
In theory, you can manipulate QMenuBar::actions(), but I never did it.
When I had to do handle this problem, I just reconstructed the menu from another dataset (look in your favorite search engine for qmdilib and you will see my solution).
Comment: Please explain why did you vote down, this helps me give better answers or learn. Thanks.


Laravel request file upload with content-type won't work

Question: When I remove content-type from Postman laravel request has the file, but if I add any content type in headers it is null? Problem is that browsers add content-type,and I can not exclude them to make it work? Any ideas? Thanks
Answer: You should probably get the Content-Type from the UploadedFile instead:
$request->file('form_input_name')->getClientMimeType();

The content-type of the entire request will be set to something like multipart encoding when you send a file with Postman.
I hope this helps.
Comment: When i call $request->file('form_input_name') it is always null if header content-type is on. I checked, file is exists in /tmp folder for sometime,when i call this endpoint, but not in request. :(
Comment: That's possible, I don't know. Don't set the Content-Type in Postman. How are you doing the file upload in Postman? I usually do POST request, body, form-data, file upload. This way postman will automatically set the correct content-type for you, like you would have a  submission from the browser with .


How to bulk re-index the whole site for core search?

Question: I have a website that has about 100,000 nodes.
In the core search page (admin/config/search/settings) it shows that:

There are 80801 items left to index.

It index 100 (or at most 500) nodes per cron run but it's useless.
I want to bulk index the whole site (all nodes) for core search.
How can I do that?
The Reindex and Batch indexing modules are created for this but there are only a few users use these modules and I couldn't be sure to use them. And also there is a module called Elysia Cron for modifying the cron per job but it's still useless for me because there are thousands of nodes to index.
(Note: I want to do this for core search not for other search solutions).
Comment: Reindex module has 257 reported installs; I wouldn't call that just a few people. I suggest making a clone of the site and trying out that module. If something goes wrong, your live site won't be affected.
Comment: @AramBoyajyan you're right. Actually for Reindex module it wasn't about a few it was about the "redness" of the module. Thanks.
Comment: Welcome; redness means that the module is still in development. I do agree that you should generally be more aware of this and look for potential issues, but you will need it only once (I guess) so if it works that one time, you are good to go. Also, always check if there are any critical issues - Reindex doesn't have any.
Answer: You can use the following drush command.
drush search-reindex --immediate --verbose


Serving the CSS and JavaScript files of the Bootstrap theme locally

Question: I have installed bootstrap theme on drupal 8 and instead of using CDN provider, I'd like to load my bootstrap files locally for offline intranet usage.
Does anyone knows where should I put my bootstrap css & js files to in order to achieve this? Are there any instructions I can follow to achieve this?

Thanks
Answer: You need Bootstrap Library module.
Quote:

Download Boostrap files on /libraries/bootstrap (you`ll have to
  create "libraries" folder in Dr8 install directory).
Then go to
  example.com/admin/config/development/bootstrap_library
  -configure on which pages you want to load the libraries (by default everything but admin/*).
Configure on which themes you want to load the libraries.
Drink some champagne coffee.


Is it possible to get the current URI from the model?

Question: I created a scaffold, but I'm trying to set some parameters according to the current URI (for example, if it's '/magazine/new', then do something, else if it's '/magazine/index', then do something else)
However, I can't manage to get the current URI by doing logger.debug request.fullpathto checkhow the current URI looks like, because I'm getting the error undefined local variable or method 'request' for #<Class:0x0000000d329d78>
How can I get what I need ?
Thank you in advance
Answer: For Rails 3.2 and 4+ you should be able to use:
logger.debug request.original_url

Here you have a full documentation of this method:
http://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-original_url


Only one module implements hook_tokens()?

Question: I've declared a [module-name]_tokens() hook but when I output the contents of module_implements('tokens'), only my module appears in the list.
I know that there are many more modules that implement hook_menu(); why do I get only my module listed? Where shall I look for possible errors?
Comment: There are 8 modules that implement it http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/implementations/hook_tokens/7
Comment: I know, but why do I get only my module listed?
Comment: It returns perfectly for me, try clearing your cache
Comment: Tried that. Only if I call `module_implements($hook, $sort = FALSE, $reset = FALSE)` with the last parameter set to false and immediately call `module_implements('tokens')`, then the list is complete. Otherwise, it lists just my module. I cannot explain why.
Answer: $hooks = module_implements('tokens');
print_r($hooks);

It returns the follwoing

Array
      (
       [0] => token
       [1] => date
      [2] => domain
      [3] => entity_token
      [4] => facetapi
      [5] => logintoboggan
      [6] => name
      [7] => node
      [8] => scheduler
      [9] => system
      [10] => taxonomy
      [11] => token_custom
      [12] => user
      [13] => views
      [14] => field
      [15] => menu )

The only place which i see is it is cached, try clearing the cache or try the following
 module_implements('tokens', FALSE, TRUE)

The third params is reset to reset the cache.
Comment: Tried that. Only if I call `module_implements($hook, $sort = FALSE, $reset = FALSE)` with the last parameter set to false and immediately call `module_implements('tokens')`, then the list is complete. Otherwise, it lists just my module. I cannot explain why.
Comment: If you have tried the same in a separate file and got the same result, Then i am sorry i do not have much idea in it.
Comment: Unfortunately, it doesn't work :(