Statistical Analysis on Sparse data?

Question: I had few data analysis and modelling roles and was always "unfortunate" to work with, let's call it bad data. Think of default probabilities 1 of 10 000, or sales time series that has 3 sold products per day which occasionally jumps to 10 or drops to 0 with certain seasonal component of course.
What do you think, can one even to proper analysis on these kinds of sparse data? If yes, what techniques would you recommend?
Comment: This question is too broad for a complete answer.
Answer: Pretty sketchy question but answerable nonetheless. The answer is "yes," there is lots one can do with sparse data. This response is far from "complete" but will review a few options in a kind of "DIY" shotgun listing. In other words, it is up to the analyst to decide which option may be appropriate to pursue.
The first consideration is to identify where the sparsity is occurring, e.g., is it in the features in terms of a large, complex, combinatorial set of possibilities or is it wrt the target or dependent variable which may have few observed responses, or both?
Wrt sparse or rare events in the target variable, e.g., when response to a stimulus is recorded as 0,1 or "yes/no," and the response rate is very small, one common error is to model this using logistic regression. The mistake is this: it is well known that the logistic curve does not provide a good fit to the tails of its distribution. This means that with sparse or rare event data, logistic regression will produce biased results. Commonly recommended "solutions" for this problem are to go out and get a larger sample of data or, alternatively, to specifically subsample those segments that are both important to the analysis and sparsely populated. This is a bad idea for at least two reasons: one, it's not always possible to simply "get more data" and two, even when possible, it can be prohibitively costly in terms of time and money. Better solutions are possible:

Gary King, Harvard political scientist and statistical methodologist, discusses rare event analysis... http://gking.harvard.edu/category/research-interests/methods/rare-events.
Quantification and prediction of extreme events in a one-dimensional
nonlinear dispersive wave model ... http://sandlab.mit.edu/Papers/14_PhysicaD.pdf
https://www.analyticsvidhya.com/blog/2014/01/logistic-regression-rare-event/

Concerning features, one needs to distinguish between structural zeros which occur for logically impossible combinations and sparsity where a combination of features is possible, there just isn't enough information to populate that particular cell in the table. Consider healthcare or hospital data where a combination such as male patients given a diagnostic code of "pregnancy" is possible from a purely computational point of view in terms of cross-classifying a set of features, but males actually giving birth is impossible, i.e., it is to be considered a structural zero. But sex and gender are different constructs. So, until transgender patients (e.g., female to male gender) have children, this will remain a structural zero.
As noted, sparsely populated features are different, requiring special tools to facilitate analysis from those employed for target variables. The following is a "laundry list" or shotgun set of options for dealing with sparse features. Much of it was gathered by simply browsing for the keywords "inference from sparse data." Choose carefully from the list:

Adopt a Bayesian modeling framework. For instance, Gelman and Hill state in chapter 13 of their book Data Analysis Using Regression and Multilevel/Hierarchical Models that it is possible to analyse features with a sample size of 1. Frequentists might object to this claim. MCMC sampling provides a workaround for sparsely populated categorical features in that pooling data across the sampling iterations builds a distribution about a feature in the posterior, even in cases where there is a sample size of 1.
Gelman, in his blog, also discusses sparsity here ... http://andrewgelman.com/2013/12/16/whither-the-bet-on-sparsity-principle-in-a-nonsparse-world/.
Alan Agresti, Approximate Is Better than "Exact" for Interval Estimation of Binomial Proportions ...http://www.stat.ufl.edu/~aa/articles/agresti_coull_1998.pdf
Data mining for rare events ... http://www-users.cs.umn.edu/~aleks/pakdd04_tutorial.pdf
comparison of different methods for modelling rare events data ... http://lib.ugent.be/fulltxt/RUG01/002/163/708/RUG01-002163708_2014_0001_AC.pdf
Statistical Inference Methods for Sparse Biological Time Series Data https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3114728/
Bayesian non-parametric models and inference for sparse and hierarchical latent structure ... http://cs.stanford.edu/people/davidknowles/daknowles_thesis.pdf
Statistical Inference: n-gram Models over Sparse Data .. http://www.sims.berkeley.edu/~jhenke/Tdm/TDM-Ch6.ppt
Lost in a random forest: Using Big Data to study rare events ... http://journals.sagepub.com/doi/pdf/10.1177/2053951715604333

And so on.
Good luck.
Comment: @MichaelChernick  Agreed, as already noted. Frankly, I don't know what a "complete" answer would be to such a vaguely worded question. Moreover, I'm probably guilty of giving the OP enough rope to hang himself.
Comment: This appears to be a nice long answer but not complete as I am sure the author would agree.
Comment: @DJohnson. Thanks for the answer and references. My bad I wasn't precise enough. What I had in mind is following. I want to model relationship between probability of default and credit rating (AAA to CCC) in some country where there are 1 000 publicly rated companies, out of which only hand full defaulted. Even worse, some BBB rated company might have defaulted, while none CCC company defaulted. Even if I fit some model, I guess the result will be counterintuitive and companies with better credit rating will have higher default probability. Bayesian with strong priors might help though..
Comment: To me, what you are asking for is a kind of risk management *shadow* credit rating. One approach would be to get known credit default probabilities from published sources such as provided by S&P or Fitch. It would be interesting if they were available by year as well as for different countries. Then, by pooling the information across time and country, a more robust estimate of default could be derived that would also adjust for differing levels (slopes) by country.
Comment: This could be done in a Bayesian framework based on iterative MCMC sampling evaluating the posterior or with random forest resampling using an OLS  (not CART) panel data structure as the core engine.

Statistical Analysis on Sparse data?


Hint required - Find values of $a$ and $b$ such that the limit equals $\frac{5}{12}$.

Question: Find the values of $a$ and $b$ such that $$\lim_{x\to 0} \frac{\sqrt[3]{ax+b}-2}{x}= \frac{5}{12}.$$
Can someone please provide me with a hint on how to approach this question?
Comment: Start with requiring limit of numerator to be zero. After that, how about L'Hospital?
Comment: Use L'Hopital an it is easy-
Comment: Two reasons why I am commenting rather than answering: [1] Posting has many defects, re [this article](https://math.meta.stackexchange.com/questions/33190/how-to-avoid-downvotes-for-beginners-questions/33236#33236) [2] I am Unsure: $$12^3(ax + b) = (5x + 24)^3 \implies (12)^3 b = (24)^3 = 8 \times (12)^3 \implies b = 8.$$  However, unclear to me whether this is valid or what constraint on $a$ is.
Answer: Can you link your expression with the definition of the derivative of a differentiable function $f$ at a point $c$?
$\lim_{h \rightarrow 0} \frac{f(c+h) - f(c)}{h}$
Answer: $$\lim_{x\to 0} \frac{\sqrt[3]{ax+b}-2}{x}= \frac{5}{12}$$
An approach without using L'Hôpital's rule:
Since the denominator approaches zero as $x$ approaches zero, the numerator must also approach zero as $x$ approaches zero for the limit to be finite, i.e.,
$$\tag{1} \lim_{x\to0}\sqrt[3]{ax+b}-2=0
\implies b^\frac13 - 2 = 0$$
Now, consider the numerator:
$$\begin{align}\sqrt[3]{ax+b}-2 &= \sqrt[3]{\left(\frac{ax}{b}+1\right)b}-2 \\
&= b^{\frac13} \left(1+\frac{ax}{b}\right)^{\frac13} - 2 \\
\end{align}$$
Using the binomial approximation, i.e., $(1+x)^n \approx1+nx$ for small $x$, we get
$$ b^{\frac13}\left(1+\frac{ax}{3b}\right) - 2 = \underbrace{(b^\frac13-2)}_{0} + \frac{ax}{3b^\frac23} = \frac{ax}{3b^\frac23}$$
Thus,
$$ \tag{2} \lim_{x\to 0} \frac{\sqrt[3]{ax+b}-2}{x} = \lim_{x\to 0} \frac{\frac{ax}{3b^{2/3}}}{x} = \frac{a}{3b^\frac23} = \frac{5}{12}$$
It is now easy to calculate $a$ and $b$ from $(1)$ and $(2)$


Campo UF que aceita apenas 2 letras maiúsculas

Question: Estou tentando criar um campo específico para UF, em que será permitido apenas 2 letras maiúsculas. Eu tentei usar expressão regular, porém, não consegui. Alguém poderia me dar um auxílio?
public class CampoUF extends TextField {

    public CampoUF() {
        textProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                if (!newValue.matches("\\W*")) {
                    //setText(newValue.replaceAll("[^\\W]", ""));
                    setText(newValue.toUpperCase());
                }
            }
        });
    }

Answer: Que tal algo parecido com isso?
import java.util.Locale;
import java.util.Objects;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.TextField;

public class CampoUF extends TextField {

    public CampoUF() {
        textProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(
                    ObservableValue<? extends String> observable,
                    String oldValue,
                    String newValue)
            {
                if (Objects.equals(newValue, oldValue)) return;
                if (newValue.length() > 2) newValue = newValue.substring(0, 2);
                newValue = newValue.toUpperCase(Locale.ROOT);

                if (newValue.length() > 1 && (newValue.charAt(1) < 'A' || newValue.charAt(1) > 'Z')) {
                    newValue = newValue.substring(0, 1);
                }
                if (newValue.length() > 0 && (newValue.charAt(0) < 'A' || newValue.charAt(0) > 'Z')) {
                    newValue = newValue.substring(1);
                }
                setText(newValue);
            }
        });
    }
}

Comment: @G1Win Não é necessário usar regex. Já estou editando a resposta.
Comment: Muito obrigado !
Comment: já agradeço pela ajuda ! Mais, não é necessário usar nenhuma "regex" pra bloquear os números ?
Comment: @G1Win Resposta editada.
Answer: Além da forma que está fazendo, pode-se disponibilizar um ComboBox<T> para o usuário, sendo <T> um enum com todas as unidades federativas disponíveis já que essas informações não mudam com frequência. Dessa forma você facilita o tratamento e a manipulação do dado, sem a necessidade de ficar validando o input digitado pelo usuário.
Considere o enum UF:
public enum UF {
    AC, AL, AM, AP, BA, CE, DF, ES, GO,
    MA, MG, MS, MT, PA, PB, PE, PI, PR,
    RJ, RN, RO, RR, RS, SC, SE, SP, TO;
}

No seu controlador, só precisará passar o array de values() do enum, por exemplo:
import java.net.URL;
import java.util.ResourceBundle;

import javafx.fxml.*;
import javafx.scene.control.ComboBox;

public final class ViewController implements Initializable {

    private @FXML ComboBox<UF> ufs;

    @Override
    public void initialize(URL url, ResourceBundle res){
        // carrega o combobox com todos os UFs.
        ufs.getItems().addAll(UF.values());
        // deixa o primeiro item selecionado.
        ufs.getSelectionModel().selectFirst();
    }
}

Para obter o UF selecionado, precisa somente de um UF ufSelecionado = ufs.getValue();.
Resultado:


search-api solr is nor performing OR search

Question: I am trying  to provide the OR feature for my solr search . when user type words, the search should be able to return result which matches with any word present in the query .
I changed the default operator from AND to OR in my schema.xml ,
After change it looks :<solrQueryParser defaultOperator="OR"/>
however , It still doesn't perform OR search . The result is empty when I type multiple words .
I am using search_api with solr  I have aplplied the changes to my drupal solr configuration as well as solr server .what could be wrong ? any pointers is really appreciated
Thanks
Answer: You can implement the hook :
hook_search_api_solr_query_alter(array &$call_args, SearchApiQueryInterface $query)

Have a look to your query & params and see if the solr query is what you were expected, if it's not you can alter it.


Random sampling methods for handling class imbalance

Question: https://www.svds.com/learning-imbalanced-classes/ explains quite nicely the different ways to handle an imbalanced dataset. But there is an information under the random undesampling and random oversampling technique which I am not sure is correct or not, as I could not find the same information in different research articles (paper1,paper2). The information for which I will highly appreciate clarifications are:

1) Does random oversampling the minority class increase the size of the final data set such that each class is the same size as that of the majority?
2) Does random undersampling decrease the total size of the dataset such that each class is the same size as that of the minority?
For example, if the minority class has 20 examples and majority class has 80 examples, then would the result of random oversampling be: (20+80) + 80 = 180
and for the random undersampling technique: 20 + (80-60) = 20+20 =40?
3) Are these methods random sampling with or without replacement?
Answer:
1) Does random oversampling the minority class increase the size of
  the final data set such that each class is the same size as that of
  the majority?

It does, however it doesn't have to. Depending on the implementation one could of course also oversample to a size that is bigger than the original majority class if the misclassification costs associated with the problem warrent that.
Same goes for undersampling - the general idea is to balance the data set, so getting them to matching size makes sense unless we have a reason to tip the class balance the other way.

3) Are these methods random sampling with or without replacement?

In the case of the first graphic you posted and assuming our objective is to even out the size of the classes, we will have to sample with replacement unless we synthezise new instances from the known ones, like SMOTE does.
In the case of undersampling both with and without replacement is possible, although I'm only aware of it being used without replacement then.
Comment: Unbalanced classes are almost certainly not a problem, and oversampling will not solve a non-problem: [Are unbalanced datasets problematic, and (how) does oversampling (purport to) help?](https://stats.stackexchange.com/q/357466/1352)
Comment: Stephan I agree with your position on this topic, as you might know. The question was directed at how this kind of resampling is performed. While the title of the question suggests it, I did not claim in my answer that it helps against class imbalance or even is the recommended approach to it. Maybe an edit to the questions title would put this in the right context.
Comment: Thank you for your answer. I would appreciate for the following clarifications: (1) The picture is for sampling techniques without replacement? Random Under and over sampling without replacement would change the size of the data set ? With replacement would not change the size of the data set?Is my understanding correct? (3) When to use with and without replacement methods?Is there a rule of thumb? (4)Can I use both undersampling and oversampling together?
Comment: ad 1) Consider this: if you were to sample from the red class in the top half of the graphic without replacement, what would be the maximum size of the sample?
ad 3) Both have their culprits, one of the factors to consider is the number of instances. I'm not aware of any general decision rule.
ad 4) So you mean undersampling the majority and oversampling the minority, meeting somewhere in the middle? Technically yes, but I've never heard of that being used.
Comment: Thank you for your reply. For point 1) It is not clear to me what happens if sampling without replacement of the minority (red class) (Oversampling method) and with replacement. I guess if I want to do without replacement then the class size may not be 50:50 or it will be equal to a user specified ratio. For sampling without replacement then we apply the SMOTE algorithm. This is still confusing to me. Can you please help
Comment: Sampling with and without replacement works the same here as it does in general probability theory. Imagine randomly grabbing pieces of paper with a number on them out of a hat. Without replacement, i.e. without putting the pieces back in the hat after drawing them, you can only draw as many samples as there are in the hat. Same with the minority class here, so you _have_ to sample with replacement if you want to come anywhere close to the same amount of instances
Comment: So for the number of samples of the minority class to be equal to the majority class, I have to do sample with replacement?
Comment: Yes, that is the case.


Can't write to external storage unless app is restarted after granting permission

Question: App unable to write to external storage on Android 6.0 (I'm testing on emulator), even after WRITE_EXTERNAL_STORAGE has been granted at runtime; unless the app is killed and restarted.
Snippet from AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

build.gradle
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    ......
    minSdkVersion 15
    targetSdkVersion 23
}

Whenever I need to write to external storage (for backup) I check whether or not I have permission.
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
                    getActivity().getBaseContext().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_RW_EXTERNAL_STORAGE);
                mPendingAction = PendingAction.Backup;
            } else {
                BackupRestoreService.startBackup(getActivity().getBaseContext());
            }

I also have the following
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        Log.d("SettingsActivity", "grantResultsLength: " + grantResults.length);
        if (requestCode == PERMISSION_REQUEST_RW_EXTERNAL_STORAGE) {
            Log.d("SettingsActivity", "grantResultsLength: " + grantResults.length);
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                switch (mPendingAction) {
                    case Backup:
                        BackupRestoreService.startBackup(getActivity().getBaseContext());
                        mPendingAction = PendingAction.None;
                        break;
                    case Restore:
                        break;
                    default:
                }

            } else {
                Toast.makeText(getActivity(),
                        "Permission denied",
                        Toast.LENGTH_SHORT).show();
            }
        }
    }

When the permission is granted by user, the following code
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), DIR_MY_PORTFOLIO);
if (!file.mkdirs())
        Log.d("Backup", "Unable to create directories");
final String outputFilename = new SimpleDateFormat("'Backup'-yyyyMMdd-hhmmss'.mpb'", Locale.US).format(new Date());
File outputFile = new File(getBackupStorageDir(), outputFilename);
Log.d("Backup", "Can write to file: " + outputFile.canWrite());
Log.d("Backup", "File exists: " + outputFile.exists());

produces
    in.whoopee.myportfolio D/Backup: Unable to create directories
    in.whoopee.myportfolio D/Backup: Can write to file: false
    in.whoopee.myportfolio D/Backup: File exists: false
    in.whoopee.myportfolio W/System.err: java.io.FileNotFoundException: /storage/09FD-2F0C/Download/My Portfolio/Backup-20151011-051318.mpb: open failed: EACCES (Permission denied)

If, after the permission is granted, the app is killed and restarted, everything goes perfect and backup file is created in external storage.
Please suggest what I am doing wrong.
Comment: It's a well known bug. You can look at the issue in the developer preview issue tracker. We can't do anything about it.
Comment: Thanks for the pointer
Answer: Add the following line in onRequestPermissionsResult() method after checking permission grant successfully.
android.os.Process.killProcess(android.os.Process.myPid());

Edit: Check you have set the target sdk version to 23.if You already have done that and it is not working(or you don't want to set it to 23) than you may go with this solution(killing the app process).
Comment: This approach is based upon a bug in Android; killProcess() normally does not restart your app, but under certain circumstances (specifically, when your app is run on a fresh install) it may, due to aforesaid bug.  See this: http://stackoverflow.com/questions/11726100/why-would-application-sometimes-restart-on-killprocess
Answer: Try to emulate a new device (for example a 6.0 x86_64 with Google api's). I had the exact same problem and i resolved it by running on a different emulator.


How to show that if $\int_a^b|{f(x)}|^p\,d\alpha = 0$ then $\int_a^b|{f(x)}|\,d\alpha = 0$

Question: How can I prove that if $\int_a^b|{f(x)}|^p\,d\alpha = 0$ then $\int_a^b|{f(x)}|\,d\alpha = 0$? (Assuming that $\alpha$ is increasing and $p > 1$). Intuitively this is clear but I'm having trouble proving it rigorously.
Comment: Can you edit the question to include 1) the non-obvious fact that you want to avoid depending on Hölder's inequality, and 2) exactly which type of integral you're referring to?  The question feels rather different for a Riemann integral versus a Lebesgue integral.  Also, you specifically mention $\alpha$ is increasing so perhaps you are referring to a Stieljtes integral instead.  So, which one is it?
Comment: @ErickWong I am referring to a Stieljtes integral. Basically, Holder's inequality says $|\int_a^bf(x)g(x)\,d\alpha| \leq \left[\int_a^b|{f(x)}|^p\,d\alpha\right]^{1/p}\left[\int_a^b|{g(x)}|^q\,d\alpha\right]^{1/q}$ and I am trying to prove using Young' s inequality, but I need to prove the case when $\int_a^b|{f(x)}|^p\,d\alpha = 0$ separately.
Comment: @MyGlasses Yes.
Comment: User1006 and MyGlasses mentioned Hölder's inequality.  You could also use the convexity of the map $\varphi(z)=z^p$.  By [Jensen's inequality](https://en.wikipedia.org/wiki/Jensen's_inequality), $\frac{1}{b-a}\int_a^b |f(x)|^p dx\geq \left(\frac{1}{b-a}\int_a^b |f(x)|\, dx\right)^p$.
Comment: @ihmth Thanks, these details need to be part of the question :).  Not too late to edit.
Answer: Edit: Here is another proof without using Holder's inequality.
First we prove that if
$$
\int_A|{g(x)}|\:d\mu=0
$$
then $g(x)=0$ almost everywhere on $A$.
Let $B_n=\{x:x\in A, \:|g(x)|\geqslant 1/n\}$. Then by Chebychev's inequality
$$
\mu(B_n)\leqslant n\int_A|{g(x)}|\:d\mu=0
$$
Hence
$$
\mu(\{x:x\in A, \:|g(x)|\ne0\})=\mu\left(\bigcup_{n=1}^{\infty}B_n\right)\leqslant \sum_{n=1}^{\infty}\mu(B_n)=0
$$
i.e. $g(x)=0$ almost everywhere on $A$.
Now since
$$
\int_a^b|{f(x)}|^p\,d\alpha=0
$$
$f^p(x)=0$ a.e. on $[a,b]$ and so $f(x)=0$ a.e. on $[a,b]$. Thus
$$
\int_a^b|{f(x)}|\,d\alpha=0\tag*{$\blacksquare$}
$$
This is a hint that use Holder's inequality.
$$
\int_a^b|{f(x)}|\cdot 1\,d\alpha\leqslant \left(\int_a^b|{f(x)}|^p\,d\alpha\right)^{1/p}\left(\int_a^b1\,d\alpha\right)^{1-1/p}=0
$$
Comment: I am using this to prove Holder's inequality, so this won't work for me
Answer: Let $q$ such that $\dfrac{1}{p}+\dfrac{1}{q}=1$ so $q>1$ and
$$\int_a^b|f|d\alpha\leq\Big(\int_a^b|f|^pd\alpha\Big)^\frac1p\Big(\int_a^b|f|^qd\alpha\Big)^\frac1q=0$$
Without Holder, we say for all step function $\phi$
$$\int_a^b|f|^pd\alpha\leq\sup_{|f|^p\leq\phi}\int_a^b\phi d\alpha=0$$
this shows $|f|=0$ almost-everywhere for $\alpha$ (measure) on $[a,b]$. That is
$$\int_a^b|f|d\alpha=0$$
Comment: @ihmth Is $f$ continuous.?
Comment: Actually, I am using this to prove Holder's inequality
Comment: How do you know with Holder's that $f$ is in $L^q$? If the integral is infinite the bound is invalid
Comment: @pasta My first question (I erased it, was on the top) was: Is it for every $p$ with positive answer.
Answer: If $|f(x)| > \epsilon$ then $|f(x)|^p > \epsilon^p$.
If $A_{\epsilon} := \{|f| > \epsilon\}$,
$0 = \int_{[a,b]} |f|^p d\alpha \ge \int_{A_{\epsilon}} |f|^p d\alpha \ge \epsilon^p \alpha(A_{\epsilon})$, from which it follows that $\alpha(A_{\epsilon})=0$.
Since $[a,b] = \{|f|=0\} \cup \bigcup_n A_{\frac{1}{n}}$, we have that $|f| = 0$ a.e., and the result follows.


Erro ao carregar JSON

Question: No link abaixo, tenho um retorno de JSON:
http://localhost/hotplateprensas.com.br/ws/produtos.php
está entregando o seguinte retorno:
[{"ProdutosidProduto":"1","Produtostipo":"mp","Produtosmodelo":"F540 2 BAN.PNEU. 100 X 60","Produtosbandejas":"2","Produtospeso":"0","Produtosprensagem":"0","ProdutosprecoUnitario":"6500","Produtoscomprimento":"100","Produtoslargura":"60","Produtoscabo":"0","Produtosligacao":"n","Produtospotencia":"0","Produtosconsumo":"0","Produtoscorrente":"0","Produtosdisjuntor":"0","Produtosdescricao":"
Bom Produto","Produtosestoque":"7","ProdutosfreteGratis":"s","Produtosbloqueado":"n"},

Sim, tem mais retorno. Porém, coloquei apenas esse para não ficar mais extensa do que está esta pergunta.
E no meu app, tenho o seguinte código:
package com.example.carlos.radiosingular;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import com.example.carlos.radiosingular.classes.Produtos;

public class form extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.form);
        List<Produtos> produtos = jSon("http://www.hotplateprensas.com.br/ws/produtos.php");

        for (Produtos p : produtos) {
            System.out.println(p.getModelo());
        }
    }

    private List<Produtos> jSon(String jsonString) {

        List<Produtos> produtos = new ArrayList<Produtos>();

        try {
            JSONArray produtosLists = new JSONArray(jsonString);
            System.out.println(produtosLists);
            JSONObject produtosList = produtosLists.getJSONObject(0);
            JSONArray produtosArray = produtosList.getJSONArray("produtos");

            JSONObject produto;

            for (int i = 0; i < produtosArray.length(); i++) {
                produto = new JSONObject(produtosArray.getString(i));
                Produtos produtoCada = new Produtos(

                        produto.getInt("ProdutosidProduto"),
                        produto.getString("Produtostipo"),
                        produto.getString("Produtosmodelo"),
                        produto.getInt("Produtosbandejas"),
                        produto.getInt("Produtospeso"),
                        produto.getInt("Produtosprensagem"),
                        produto.getInt("ProdutosprecoUnitario"),
                        produto.getInt("Produtoscomprimento"),
                        produto.getInt("Produtoslargura"),
                        produto.getString("Produtoscabo"),
                        produto.getString("Produtosligacao"),
                        produto.getInt("Produtospotencia"),
                        produto.getInt("Produtosconsumo"),
                        produto.getInt("Produtoscorrente"),
                        produto.getInt("Produtosdisjuntor"),
                        produto.getString("Produtosdescricao"),
                        produto.getInt("Produtosestoque"),
                        produto.getString("ProdutosfreteGratis"),
                        produto.getString("Produtosbloqueado")
                );
                produtos.add(produtoCada);
            }
        } catch (JSONException e) {
            Log.e("HOT PLATE PRENSAS", "Erro no parsing do JSON", e);
        }

        return produtos;
    }

}

O objetivo é, à principio, imprimir um objeto.
Mas, no console RUN sai o seguinte erro:
E/HOT PLATE PRENSAS: Erro no parsing do JSON
    org.json.JSONException: Value http of type java.lang.String cannot be converted to JSONArray
        at org.json.JSON.typeMismatch(JSON.java:111)
        at org.json.JSONArray.<init>(JSONArray.java:96)
        at org.json.JSONArray.<init>(JSONArray.java:108)
        at com.example.carlos.radiosingular.form.jSon(form.java:43)
        at com.example.carlos.radiosingular.form.onCreate(form.java:24)
        at android.app.Activity.performCreate(Activity.java:6687)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2631)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1490)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6165)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
I/ViewConfigCompat: Could not find method getScaledScrollFactor() on ViewConfiguration
W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
D/OpenGLRenderer: endAllActiveAnimators on 0x8e5d8c00 (RippleDrawable) with handle 0x8e5d5ea0

Eis a classe Produtos:
package com.example.carlos.radiosingular.classes;

public class Produtos {

private int idProduto;
private String tipo;
private String modelo;
private int bandejas;
private int peso;
private int prensagem;
private int precoUnitario;
private int comprimento;
private int largura;
private String cabo;
private String ligacao;
private int potencia;
private int consumo;
private int corrente;
private int disjuntor;
private String descricao;
private int estoque;
private String freteGratis;
private String bloqueado;

    public Produtos(
            int idProduto,
            String tipo,
            String modelo,
            int bandejas,
            int peso,
            int prensagem,
            int precoUnitario,
            int comprimento,
            int largura,
            String cabo,
            String ligacao,
            int potencia,
            int consumo,
            int corrente,
            int disjuntor,
            String descricao,
            int estoque,
            String freteGratis,
            String bloqueado) {
        this.idProduto = idProduto;
        this.tipo = tipo;
        this.modelo = modelo;
        this.bandejas = bandejas;
        this.peso = peso;
        this.prensagem = prensagem;
        this.precoUnitario = precoUnitario;
        this.comprimento = comprimento;
        this.largura = largura;
        this.cabo = cabo;
        this.ligacao = ligacao;
        this.potencia = potencia;
        this.consumo = consumo;
        this.corrente = corrente;
        this.disjuntor = disjuntor;
        this.descricao = descricao;
        this.estoque = estoque;
        this.freteGratis = freteGratis;
        this.bloqueado = bloqueado;
    }

    public int getIdProduto() {
        return idProduto;
    }

    public String getTipo() {
        return tipo;
    }

    public String getModelo() {
        return modelo;
    }

    public int getBandejas() {
        return bandejas;
    }

    public int getPeso() {
        return peso;
    }

    public int getPrensagem() {
        return prensagem;
    }

    public int getPrecoUnitario() {
        return precoUnitario;
    }

    public int getComprimento() {
        return comprimento;
    }

    public int getLargura() {
        return largura;
    }

    public String getCabo() {
        return cabo;
    }

    public String getLigacao() {
        return ligacao;
    }

    public int getPotencia() {
        return potencia;
    }

    public int getConsumo() {
        return consumo;
    }

    public int getCorrente() {
        return corrente;
    }

    public int getDisjuntor() {
        return disjuntor;
    }

    public String getDescricao() {
        return descricao;
    }

    public int getEstoque() {
        return estoque;
    }

    public String getFreteGratis() {
        return freteGratis;
    }

    public String getBloqueado() {
        return bloqueado;
    }

}

Não printa nada na tela.
Onde estou errando que está caindo em
Log.e("HOT PLATE PRENSAS", "Erro no parsing do JSON", e);

?
Answer: o que tu tem ali é um json dentro de um json. Terás de fazer algo semelhante com isso:
JSONObject cli = new JSONObject();
cli = (JSONObject) clientes.get(0);
JSONArray client = cli.getJSONArray("NomeCliente");
JSONArray cCpf = cli.getJSONArray("CPFCliente");
SONArray cId = cli.getJSONArray("IdCliente");

Onde o clientes é a variável que está armazenando o retorno do php
Comment: cli é um array de JSON
Comment: descobri dessa forma         produtos.forEach(produto -> System.out.println(produto.getModelo()));
, mas dá erro de que LAMBDA não é suportsdo na versão 7
Comment: "cli é um array de JSON" é isso. Tu recebe um objeto json que dentro tem um array json. Fazendo assim como te mandei da certo.
Comment: é o contrario então? A string inteira é um objeto e cada nó dese objeto é um array? [{"ProdutosidProduto":"1","......... isto tudo é um só objeto?
Comment: Eu tenho um array de objetos
Comment: Meio que isso, meio complicado de entender.
Comment: estou quase lá: veja essa dúvida, no final dela eu implemento do jeito que está me ensinando: https://pt.stackoverflow.com/questions/349577/percorrer-um-array-de-objetos-json-no-android-studio

Erro ao carregar JSON


Webdriver exception: "chrome not reachable"

Question: I am running selenium test cases in a ubuntu server which basically runs testcases in both firefox and chrome.
Firefox launches and test cases run successfully but chrome throws exception:
*****below is the snippet of the stacktrace:*****
Starting ChromeDriver (v2.8.240825) on port 21549
PAC support disabled because there is no system implementation
Test IntegrationTest.AdminUserelementscheck failed:
org.openqa.selenium.WebDriverException: chrome not reachable
 (Driver info: chromedriver=2.8.240825,platform=Linux 2.6.32-431.el6.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
[error] Command duration or timeout: 20.83 seconds

Hi Below is the small snippet of my code :
<code>public class IntegrationTest {

private static final String configFile="test.properties";

private final String FIREFOX="firefox";

private final String CHROME="chrome";

private final String PHANTOMJS="phantomjs";

private final String BROWSERNAME="browser";

private static Properties props = new Properties();

public WebDriver webDriver;

private static Configuration additionalConfigurations;

@BeforeClass

public static void setUp() throws IOException, SQLException{

props.load(IntegrationTest.class.getResourceAsStream("/" + configFile));
        }

@test

public void AdminUserelementscheck() throws SQLException, IOException {

String[] browsers = props.getProperty(BROWSERNAME).split(",");

System.out.println("Number of browsers specified in conf:"+props.getProperty(BROWSERNAME));

for(String browser:browsers){

System.out.println("Browser currently processing:"+browser);

if(browser.equalsIgnoreCase(FIREFOX))

webDriver = new FirefoxDriver();

else if(browser.equalsIgnoreCase(CHROME))

webDriver = new ChromeDriver();

else

webDriver = new PhantomJSDriver();

running(testServer(3333,fakeApplication()),webDriver, new Callback<TestBrowser>() {

********* LOGIN AND ASSERTION STATMENTS*******************

browser.quit()

}

});

}
</code>
Comment: It can also be a port forwarding issue between your docker container and a remote device/host.
Answer: This would be because Chrome is also making use of unix containers in order to run. If you want this to run within docker, pass the docker run command

--privileged

Otherwise you can start Chrome with

--no-sandbox
Comment: @Conor @ Immanuel Fredrick: Where do I put this command? Please help understand with above as example.
Comment: is it safe to rely on `--no-sandbox` for automated tests?
Comment: Additionally, you'll need to increase dev/shm
https://github.com/elgalu/docker-selenium/issues/20#issuecomment-133011186
Comment: Okay, I tried passing this to chrome args but it says environment not available in that case.
Comment: --no-sandbox works, but I didn't have to set this in previous versions and it's not so secure too
Answer: I have encoutered similar problem. I am running my Selenium tests locally and "webdriver exception chrome not reachable" error suddenly showed up.
The problem was that I already had too much tabs in my regular chrome browser. After getting frustrated I have closed few tabs and suddenly it worked. I am not sure if there is a certain limit of tabs, but if somebody encounters same problem, give it a try.
Comment: I'll try to be more straightforward next time :)
Answer: Your chrome driver seems to be old. Try downloading latest as of date from below and report back if you get any new errors.
http://chromedriver.storage.googleapis.com/index.html?path=2.14/
Comment: point to be noted is that the whole setup runs inside a docker container
Comment: I tried most of the versions of chromedriver right from 2.7 to 2.14.
It throws the same error
Answer: Also ensure that PATH environment variable has the path to chromedriver.
Comment: Did you configure XServer Display parameter such as DISPLAY=:0 before invoking the script?
Comment: I have chromedriver executable placed in system environment path. And it is able to pick the chromedriver but not launch it .


Export multiple tables from Access to one XML file

Question: I can only export 1 table from Access with this code.
Option Compare Database

Function ExportXML()

'Init root xml
Dim objDom As DOMDocument
Set objDom = New DOMDocument

Dim objRootElem As IXMLDOMElement
Set objRootElem = objDom.createElement("root")
objDom.appendChild objRootElem

Dim objChartElem As IXMLDOMElement
Set objChartElem = objDom.createElement("charts")
objRootElem.appendChild objChartElem
'At this point we will have root->charts

'Get current database file
Dim db As Database
Set db = CurrentDb

'Construct query
Dim strSQL As String
strSQL = "select * from TestTable"

'Get result set
Dim rs As DAO.Recordset
Set rs = db.OpenRecordset(strSQL)

'Create chartEntry in xml
Dim objSpecificChartElem As IXMLDOMElement
Set objSpecificChartElem = objDom.createElement("chart")
objChartElem.appendChild objSpecificChartElem

' Creates Attribute to the Member Element
Set objKeyRel = objDom.createAttribute("Key")
objKeyRel.nodeValue = "TestTable" 'Value corresponds to table name
objSpecificChartElem.setAttributeNode objKeyRel

'Looping through each row
Do While Not rs.EOF
    'Current row

    'Create entry in specific chart element
    Dim objRowElem As IXMLDOMElement
    Set objRowElem = objDom.createElement("col")
    objSpecificChartElem.appendChild objRowElem

    'We skip the ID column
    For i = 1 To rs.Fields.Count - 1
        'Each field

        Dim objColElem As IXMLDOMElement
        Set objColElem = objDom.createElement("string") 'Add logic to determine datatype
        objRowElem.appendChild objColElem

        'Extract value and add to element
        Set objColValue = objDom.createAttribute("val")
        objColValue.nodeValue = rs.Fields(i).Value
        objColElem.setAttributeNode objColValue

    Next i

    'Next
    rs.MoveNext
Loop

'Save
Dim path As String
path = CurrentDb.Name & ".export.xml"
objDom.Save (path)

'Show success
MsgBox "Succesfully exported at: " & path, vbDefaultButton1, "Export"

End Function

How do I use the format of this code but export multiple tables to one XML file?
The XML output will look like this.
<?xml version="1.0" encoding="UTF-8"?>
<root>
<charts>
<chart key="testtable">
<col>
<string val="quarter"/>
<string val="Q1"/>
<string val="Q2"/>
<string val="Q3"/>
<string val="Q4"/>
</col>
<col>
<string val="Group 1"/>
<double val="100.1"/>
<double val="200.6"/>
<double val="250"/>
<double val="300.8"/>
</col>
<col>
<string val="Group 2"/>
<double val="250"/>
<double val="100.1"/>
<double val="300.8"/>
<double val="200.6"/>
</col>
<col>
<string val="growth"/>
<double val="22.5"/>
<double val="-5.1"/>
<double val="3.8"/>
<double val="50.6"/>
</col>
</chart>
<chart key="halfyear">
<col>
<string val="Period"/>
<string val="spring"/>
<string val="winter"/>
</col>
<col>
<string val="numbers"/>
<double val="50"/>
<double val="150"/>
</col>
<col>
<string val="price"/>
<double val="8.3"/>
<double val="1.2"/>
</col>
<col>
<string val="difference"/>
<double val="0"/>
<double val="-7"/>
</col>
</chart>
</charts>
</root>

This is how the table should look:
Comment: can you also tag this with Access-VBA?  Can't you just parameterise it?  Make instances of "TestTable" a variable that you pass in as a parameter?
Comment: are the tables the same in size (width) you could use a UNION query, with a 'table name' addition?
Comment: You need to show some XML data and explain how you want to integrate as XML maintans nested tree structure? Where should tables be inserted?
Comment: The tables will be inserted in a powerpoint. But the guy who does it need the xml tables nested like this. the problem is i can only do it with that format with 1 table in this case "testtable". But i have 50 more tables i need exported to xml in one file, and i don't how to do it.
Answer: Consider looping through all tables of database using the TableDefs collection, iteratively calling your ExportXML() function with passed-in parameter. And at the same time build a special XSLT script to later bind all resulting XML files into one master file.
As information, XSLT is a special-purpose language designed to transform XML files and can import an external XML using its document() function. The XSLT must be saved to disk and not used in memory since it must read directory for other XML files.
XSLT Model
(script that is dynamically built in code below; notice first Table1.xml not declared since it is the original transformation source in VBA)
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output version="1.0" encoding="UTF-8" indent="yes" method="xml"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="/">
    <root>
      <xsl:copy-of select="*"/>
      <xsl:copy-of select="document('Table2.xml')/root/*"/>
      <xsl:copy-of select="document('Table3.xml')/root/*"/>
      <xsl:copy-of select="document('Table4.xml')/root/*"/>
      ...
      <xsl:copy-of select="document('Tabl50.xml')/root/*"/>
    </root>
  </xsl:template>
</xsl:transform

VBA (using original function with parameter of table name)
Public Function ExportXML(tblname As String)
    '...same exact code with following line changes...

    strSQL = "select * from [" & tblname & "]"
    '...
    path = Application.CurrentProject.Path & "\" & tblname & ".xml"

    ' REMOVE SUCCESS MSGBOX
End Function

Public Sub MasterXMLFile()
On Error GoTo ErrHandle
    ' ADD VBA REFERENCE: MSXML, v6.0
    Dim xmlDoc As New MSXML2.DOMDocument60, xslDoc As New MSXML2.DOMDocument60, newDoc As New MSXML2.DOMDocument60
    Dim xslstr As String, firstXML As String
    Dim tbl As TableDef
    Dim i As Integer: i = 1

    ' START XSLT
    xslstr = "<xsl:transform xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" version=""1.0"">" _
                    & " <xsl:output version=""1.0"" encoding=""UTF-8"" indent=""yes"" method=""xml""/>" _
                    & " <xsl:strip-space elements=""*""/>" _
                    & "   " _
                    & "   <xsl:template match=""/"">" _
                    & "     <root>" _
                    & "       <xsl:copy-of select=""*""/>"

    For Each tbl In CurrentDb.TableDefs
        If i = 1 Then firstXML = tbl.Name
        ' CALL ORIGINAL FUNCTION
        Call ExportXML(tbl.Name)

        ' CONCATENATE XSLT STRING
        xslstr = xslstr & "  <xsl:copy-of select=""document('" & tbl.Name & ".xml')/root/*""/>"
        i = i + 1
    Next tbl

    ' END XSLT
    xslstr = xslstr & "     </root>" _
                    & "   </xsl:template>" _
                    & "   " _
                    & "</xsl:transform>"

    xslDoc.loadXML xslstr
    xslDoc.Save Application.CurrentProject.Path & "\MasterFile.xsl"

    ' LOAD FIRST XML AND XSL
    xmlDoc.Load Application.CurrentProject.Path & "\" & firstXML & ".xml"

    Set xslDoc = New MSXML2.DOMDocument60
    xslDoc.Load Application.CurrentProject.Path & "\MasterFile.xsl"
    xslDoc.async = False
    xslDoc.SetProperty "AllowDocumentFunction", True

    ' TRANSFORM SOURCE TO NEW DOCUMENT
    xmlDoc.transformNodeToObject xslDoc, newDoc

    ' SAVE TRANSFORMED RESULT
    newDoc.Save Application.CurrentProject.Path & "\MasterFile.xml"

    Set xmlDoc = Nothing: Set xslDoc = Nothing: Set newDoc = Nothing
    MsgBox "Succesfully built Master database XML!", vbDefaultButton1, "Export"
    Exit Sub

ErrHandle:
    MsgBox Err.Number & " - " & Err.Description, vbCritical, "RUNTIME ERROR"
    Set xmlDoc = Nothing: Set xslDoc = Nothing: Set newDoc = Nothing
    Exit Sub
End Sub


How to stop Widget resizing based on content

Question: I'm using GTK3+ (3.22) on Ubuntu server 18 (beta2) / x11 / openbox.  Language is C.  I'm porting an embedded application from GTK2 which did not seem to do dynamic resizing of label widgets when the text content reached a certain limit.
On GTK3 the label (and button) widgets now seem to resize when the text content is close to the maximum size that can be displayed.
In the case of a button widget placed into a FIXED container on a window.  I have tried the following...
The gtk_widget_set_size_request seems only to set a default or minimum, not a max:
gtk_widget_set_size_request( GTK_WIDGET( GuiBottomFarLeftButton ) , GuiBottomButtonWidth , GuiBottomButtonHeight );

I have tried gtk_widget_size_allocate but that doesn't seem to limit the maximum size.
GtkAllocation gtkallocTestSize = { GuiBottomButtonFarLeftX , GuiBottomButtonY , GuiBottomButtonWidth , GuiBottomButtonHeight};
gtk_widget_size_allocate( GTK_WIDGET( GuiBottomFarLeftButton ) , &gtkallocTestSize );

There does not appear to be a gtk_widget_... function that limits the maximum size or sizing behavior that I can find.  So far I have not found a way to limit the maximum size of a specific widget.  I would settle for a way to limit the maximum width as the vertical size of the controls seems to behave as it did under GTK2 in the application I'm working on.  In most cases the resizing is only effecting the layout by 10 to 20 pixels but this creates a really bad user experience.
Is there a way to disable the resizing on a widget or limit it's maximum size?  Or some other work around that actually functions on latest GTK3+ (3.22)?
Comment: This is due to changes in the algorithms used to compute the widget size between GTK+ 2 and GTK+ 3. The behavior you want was mostly a problem in GTK+ 2, because labels for example couldn't span on multiple lines automatically. This was the ground for [height-for-width- and width-for-height geometry management](https://developer.gnome.org/gtk3/stable/GtkWidget.html#geometry-management).
Comment: Also you should add an [MCVE](https://stackoverflow.com/help/mcve).
Answer: UX is a hard balance of optimisation. In general you should not assume that the gtk2 behaviour is what you want to replicate. The body of knowledge re: UX has increased since then and changes are in general positive. You will either be clipping text, decreasing font sizes or oversizing widgets. You can't have it all.
Scrolled windows help in many cases but obviously not for buttons and labels. In this case it is best to keep text short and use tooltips for anything that needs a more lengthy explanation.
Comment: The GTK2 behavior is what I want to replicate EXACTLY.  This is an embedded application, NOT a general purpose application running in a desktop UI.  In the GTK2 version I don't clip any text or have any user experience issues.  With the GTK3 port I have several issues like this that I can't seem to find a good solution other than changing text messages or making fonts smaller and then harder to read.  The device uses a touchscreen so the entire concept of tooltips is not usable.


Find a missing message

Question: This is my first question, so please be gentle... :-)
I'm a department of one for a small engineering company. My primary job is to develop software, but my CS degree clearly makes me an expert on all things IT, right? We use a 2003 Small Business Server with as many default-settings as I can muster, but one of our remote users recently complained that she was expecting a couple emails with some large attachments (...some time in the last 10 days). She says she's getting other emails, and as usual, the SBS "Failed Mail" folder only contains emails from wealthy, deposed African princes (not Qaddafi...yet).
She's not even sure about one of these messages' sender address... Just that it should 'look like an architect/contractor address'... I know how to use "Message Tracking" but it doesn't let me look at message content--just when it was delivered. I've always avoided learning how to get into the mailboxes of other people, but after 5 years of annoying problems like this one, I'm starting to care less about the privacy of the sheep.
I realize that--at some point--she's just screwed, but what do you think? Should I open Pandora's box? If so, how can I do it without letting her know I've done it? I don't want to turn into anybody's email gopher.
Comment: If she doesn't know the address to tell you what to look for, tell her to go screw. IMO.
Comment: And your question is ... ?

You want to help her without letting her know that you are trying to help her?
Comment: Tell sender to send using something that looks like a USB thumb drive.
Answer: OK, I'm being gentle - I promise!
one of our remote users recently complained that she was
expecting a couple emails with some large attachments

Electronic Mail is NOT a file distribution system. Sending "large" files via email is like trying to send your car via the US Postal Service: There is a weight (file size) limit, and you may be exceeding it.

(...some time in the last 10 days).

If that's the best time frame she can produce it's not even worth looking in the logs.  If you want to try to help her have the messages re-sent at a known time, watch your server's logs for a window before/after that time (say an hour or 2 on each side), and see if anything turns up.
You will need to know the sender's address unless you enjoy long painful walks through mail server logs looking for the proverbial needle in the equally proverbial haystack :-)

Should I open Pandora's box?

If at all possible avoid getting involved with email. It is a bottomless pit of trouble and heartache and naught but insanity awaits those who meddle in it.

If so, how can I do it without letting her know I've done it?

You can't: You need the cooperation of both the sender and the recipient (and often the IT team on the sender's side) in order to really troubleshoot email.
Comment: If you're a sysadmin and you aren't used to users thinking you're an @#$%...you're probably new.
Comment: `You need the cooperation of both the sender and the recipient (and often the IT team on the sender's side) in order to really troubleshoot email.` True, but it takes so much longer and in the meantime they think you're an a##hole while you try to get something else done.
Comment: @phillihp I've found if you can get all of those parties together at the same time you can typically solve the problem in 15 minutes.  They fight getting together like harpooned whales like you mentioned, but at least it gets fixed, and then the IT guys are the heros who made it work, rather than the a##holes who got in the way :)
Comment: all that said -- if you can run away, RUN. :-)
Answer: as @voretaq7 said email is not a file distribution mechanism; anything large  is best sent via another mechanism.
She's screwed. Explain nicely and suggest alternative methods of sending large files privately and securely.
Don't open pandora's box, at all, as you will find that all the evils of the world are as nothing compared to email problems....
Answer: As others have said, finding out what happened is difficult and annoying at best, assuming you've done it before :)
Point her to yousendit.com for a free file distribution service.
If she complains, tell whoever is above you that many times even seasoned sysadmins have trouble figuring out what happened, and honestly, the answer is going to be "your email got lost because it had a big attachment".
Good luck :)

Find a missing message


Erro de instalação/Inicio de projeto com react-native

Question: Estou tentando iniciar um projeto react-native há 2 dias no meu PC para rodar no meu dispositivo físico Android.
Ao rodar o projeto com npx react-native run-android aparecem os seguintes logs:
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 967 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
info Installing the app...
:ReactNative:Unexpected empty result of running '[node, C:\Users\Pichau\Programação\Projetos\JavaScript\ControleDePagamentos-GrupoDaAgua\mobile2\node_modules\@react-native-community\cli\build\bin.js, config]' command.
:ReactNative:Running '[node, C:\Users\Pichau\Programação\Projetos\JavaScript\ControleDePagamentos-GrupoDaAgua\mobile2\node_modules\@react-native-community\cli\build\bin.js, config]' command failed.

FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\Pichau\Programa��o\Projetos\JavaScript\ControleDePagamentos-GrupoDaAgua\mobile2\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' line: 195

* What went wrong:
A problem occurred evaluating script.
> internal/modules/cjs/loader.js:984  throw err;  ^Error: Cannot find module 'C:\Users\Pichau\Programação\Projetos\JavaScript\ControleDePagamentos-GrupoDaAgua\mobile2\node_modules\@react-native-community\cli\build\bin.js'    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:981:15)    at Function.Module._load (internal/modules/cjs/loader.js:863:27)    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)    at internal/main/run_main_module.js:18:47 {  code: 'MODULE_NOT_FOUND',  requireStack: []}

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
:ReactNative:Unexpected empty result of running '[node, C:\Users\Pichau\Programação\Projetos\JavaScript\ControleDePagamentos-GrupoDaAgua\mobile2\node_modules\@react-native-community\cli\build\bin.js, config]' command.

Tentei mudar as variáveis de ambiente, mas o erro persiste. Podem me ajudar?
Answer: Opa, assiste o tutorial do Celke sobre como instalar o React Native, é bem explicado e funcionou comigo e com meus amigos!
https://www.youtube.com/watch?v=a3Ehi3cypDA&t=1s
Answer: cara, muda o nome da pasta onde está localizado o projeto. A pasta "programação" tem caracteres que não são reconhecidos como o "~"; "ç".
Fiz isso no meu e funcionou.
Comment: Sua resposta pode ser melhorada adicionando informações fundamentais. Basta [edit] para adicionar mais detalhes, como citações ou documentação para que outras pessoas possam confirmar que sua resposta está correta. Você pode encontrar mais informações sobre como escrever boas respostas [na Central de Ajuda](/help/how-to-answer).


self join table

Question: i have a table,

    new_id----old_id----created_on
    1234------5678------20100912
    5678------3456------20100808

etc.
i wrote this query,
$q = "select event1.new_id, event1.old_id, event1.created_on,event2.new_id, event2.old_id, event2.created_on
  FROM replaced_isbns event1
  JOIN replaced_isbns event2
  ON event2.new_id = event1.old_id
  WHERE event1.new_id='$id'";

but i get result as
5678 - 1234, ie only one row, i want all rows...
@webdestroya,
it gives only one row....
i want output like this,
For new_id 1234, old_id's are 5678,3456 etc
Comment: In your example, your table contains only 2 rows. Is this true for you actual data as well?
Answer: if you want all rows than try left outer join and replace null with new id for example
SELECT
    event1.new_id, event1.old_id, event1.created_on,
    IFNULL(event2.new_id, event1.new_id),
    IFNULL(event2.old_id, event1.old_id),
    event2.created_on
FROM replaced_isbns event1
LEFT OUTER JOIN replaced_isbns event2
  ON event2.new_id = event1.old_id
WHERE event1.new_id='$id'

check this may help you
Comment: @ pranay,
it returns no results

I want result like this,
For new_id 1234, old_id's are 5678,3456 etc
Comment: Hi,
it give me only 1234 - 5678

but i want, second result also ie    5678 - 3456

it should return all rows
Comment: problem is you are putting id in your where condition if you want all record remove where clause than u will get all data
Comment: by all rows i mean, rows matching the where clause. i get new_id from user, by that i have to select other rows. please help me. thanks.
Comment: does ORDER BY clause work with joins?

I tried to order by event1.created_on in above select query, but i dont see difference....
Comment: if it works than accept than answer and increase your acceptance percentange
Answer: Why make a self join?
SELECT replaced_isbns.*
FROM replaced_isbns
WHERE new_id = '$id'
OR old_id = '$id'

Now, for each row in your result check if new_id = $id, or if old_id = $id.
Comment: it gives me only, 1234 - 5678, but i want result as,

for new_id 1234, old_id's are 5678,3456 etc....
it should return all rows....as in table.
Answer: As far as i understood, you need all the old_ids for the new_id:-
for new_id:- 1234 old id' are 5678 and 3456.
similarly for second record:- for new_id:- 5678 old id' are 3456.
I have tested this and it is working fine.
select new_id,b.old_id from
   (select old_id from temp)
     as b inner join temp as a
       on a.new_id!=b.old_id

Do let me know if this is the one you wanted or not.
I hope this helps!
Answer: You won't be able to get the result you want using a query since there's no way to query recursive relations in SQL (well, ok, Oracle has START WITH ... CONNECT BY ... syntax and CTE, but I guess you're not using Oracle :p).
But on the other hand you could try to convert this adjacency list into a nested set, because getting a branch (all child records of a given parent) is very easy with nested sets. Managing Hierarchical Data in MySQL is an interesting article on that subject.

self join table


Boost serialization using separate .h and .cpp files

Question: I am experimenting with the boost serialization library and I've gotten most of it working. The only problem is when i try to serialize an object that has separate .h and .cpp files. When i compile using this command:
g++ boostSerialize.cpp Class.cpp -lboost_serialization

i get this error:
/tmp/cc8kbW6J.o: In function `void boost::serialization::access::serialize<boost::archive::text_oarchive, Class>(boost::archive::text_oarchive&, Class&, unsigned int)':
boostSerialize.cpp:(.text._ZN5boost13serialization6access9serializeINS_7archive13text_oarchiveE5ClassEEvRT_RT0_j[void boost::serialization::access::serialize<boost::archive::text_oarchive, Class>(boost::archive::text_oarchive&, Class&, unsigned int)]+0x25): undefined reference to `void Class::serialize<boost::archive::text_oarchive>(boost::archive::text_oarchive&, unsigned int)'

this is what is in my .h:
#ifndef CLASS_H
#define CLASS_H
#include <iostream>
#include <string>
#include <boost/serialization/access.hpp>

using namespace std;

class Class{

    friend class boost::serialization::access;
    int a,b,c;
    string stringy;
    template<class Archive>
        void serialize(Archive &ar, const unsigned int);
    public:
        Class(int ab, int bb, int cb);

};
#endif

and my .cpp:
#include <iostream>
#include "Class.h"

using namespace std;

Class::Class(int ab, int bb, int cb){
    a = ab;
    b = bb;
    c = cb;
    stringy = "Text";
}

template<class Archive>
    void Class::serialize(Archive &ar, const unsigned int){
        ar & a & b & c & stringy;
    }

I tried instead putting everything only into a .cpp and including that and it worked fine, so i know that it is something to do with the .h inclusion. For some reason it is not finding the serialize function? I guess i could just use a .cpp instead of both but i really like organization and i would like to use this for a big project.
Any ideas? Thanks in advance.
Comment: http://www.parashift.com/c++-faq-lite/templates.html#faq-35.15
Answer: Your problem is not with Boost.Serialization (as such), but that you are trying to separately compile a function template.
Class::serialize is a function template, which means that it gets instantiated on the basis of the types of the template parameters that get passed to is. When compiling Class.cpp, the compiler does not know what types Class::serialize will be instantiated with, and so it cannot generate the code.
Comment: Better (?) solution: Move the implementation of your `serialize` method into the header.  This is the typical approach for ALL templates - their full implementation has to go in the header.
Comment: So how do I tell the compiler what types it will be instantiated with? Or can i not?
Comment: @adamk33n3r: Good question! You can explicitly instansiate it in the .cpp file with `template void Class::serialize(boost::archive::text_oarchive &ar, const unsigned int);`.
Comment: Thanks so much! You are a brain meltdown saver! I've been trying to figure this one out for a while.


Inserir Função Apenas Se Não Existir

Question: A função "window.showModalDialog" existe em algumas versões de IE, porém não existe no Chrome, gostaria de inseri-la se ela não existir. Como posso fazer isso?
window.showModalDialog = function (arg1, arg2, arg3) {
//Minha função
}

Answer: Essa funcionalidade não é uniformizada, está deprecada, e deve ser evitada.
Acho que colocas questões diferentes aqui, e interessantes de separar.
Como/quando aplicar um polyfill
Podes detetar se a função existe e caso não exista aplicar uma função tua com comportamento semelhante. Algo como:
if (!window.showModalDialog) window.showModalDialog = function(){
    // etc ...

Como reproduzir essa funcionalidade (ie como criar um polyfill para este método)?
Isso existe já e podes encontrar no Github aqui: https://github.com/niutech/showModalDialog
A MDN também aponta para esse repositório que tem uma demo aqui.

Inserir Função Apenas Se Não Existir


Abstract algebraic definition of dual tangent spaces

Question: I know that if $(M,\mathcal{A})$ is a smooth manifold, the dual tangent space at $p\in M$ can be defined as $$ T^*_pM=I_p/I_p^2, $$ where $I_p$ is the ideal of the ring $C^\infty(M)$ consisting of smooth functions that vanish at $p$ and $I_p^2$ is the second power of this ideal.
I understand that this definition is useful, because, unlike other definitions, this one can be generalized to situations when you don't have the smooth structure $\mathcal{A}$, however this definition is so unintuitive I have a hard time grasping it.

According to wikipedia, the product of ideals $A$ and $B$ is defined as $$ AB=\{a_1b_1+...a_nb_n|\ a_i\in A,b_i\in B,n\in\mathbb{N}\}, $$ I assume the point of this definition is that by demanding that the functions vanish, we make sure that the functions' Taylor expansion has no zeroth order terms, and since the elements of the product ideal are second order expressions, I assume the quotient is needed to get rid of second order terms.

Seems logical, since by the usual definition we can infer that the contangent space is generated by differentials of functions, which are, of course, the first order part. Am I correct in this?

If I am correct on the first point, what about higher than second order terms? Shouldn't we need to quotient those out too?
Thinking about it as I write this post, elements of $I_p^2$ are second order algebraic expressions from $C^\infty(M)$, but they are not polynomials, a Taylor expansion, however is polynomial. I think I don't understand it now.
This line of thought seems to depend on the functions having Taylor expansions. However I know this definition is generalizable to algebraic varieties as well as locally ringed spaces in general. Without having a structure that allows Taylor expansions, how do we know that this grasps the concept of "functions having the same first order behaviour at $p$" for those cases as well?
How can we see that this quotient space is finite $n$ dimensional? If the proof is not particularily pleasant, I don't expect anyone to actually post it here, but a reference to a manifold theory textbook that utilizes this definition heavily enough to also contain related proofs would be nice.

I would appreciate any response, even if it doesn't address these points directly, if it can help me see intuitively why this particular quotient space has the same meaning as the usual definition of dual tangent space.
EDIT: Since there have been misunderstandings, I wish to clarify: In my last bullet point I am not asking how to prove that the tangent/cotangent space is $n$ dimensional for an $n$ dimensional manifold. I am asking how to see that the space $I_p/I_p^2$ is $n$ dimensional, or alternatively, how to see that it is isomorphic to the cotangent space (defined by any alternative means).
Comment: This is a bit much to read for me at the moment but as a quick reference: I think Nigel Hitchin (a trustworthy source!) takes this as the definition in his manifold notes.
Comment: Well, $I_p^2$ also contains all higher order products.
Comment: @hwong557 It does? That was the first book I checked before posting this question, but I didn't find any such treatment of tangent or cotangent spaces. Where is it in the book?
Comment: @hwong557 I think you misunderstood me. I did not ask how to prove the tangent space or cotangent space is $n$ dimensional. I asked how to prove it **when** we use the definition I gave above.
Answer: Not a full answer, but too long for a comment.
Terms of order greater than $2$ will be quotiented out automatically. Recall that an ideal is closed under multiplication by ring elements. So, if $x^2 \in I^2_p$, then $x^{2+k}=x^2x^k\in I^2_p$ also. Intuitively, if $x^2=0$ in the quotient, then $x^{2+k}=x^2x^k=0x^k=0$.
This does not in fact rely on full Taylor expansion; it seems that just a few terms are sufficient, like in Peano form: $f(x)=f(p)+f'(p)(x-p)+o(|x-p|^2)$. The non-trivial part is to show that $o(|x-p|^2)$ equals $I^2_p$.
The fact that for $n$-dimensional manifold the tangent space is $n$-dimensional follows from the chart that provides us with coordinates $x_1, \dots x_n$: the vectors $\frac{\partial}{\partial x_k}$ will form a basis.
Comment: Now I understand why $I_p^2$ contains higher order terms too, thank you.

However I do know how to check the dimension of the tangent space using the usual approaches. What I am curious about is if I only know $T_pM=(I_p/I_p^2)^*$, then how do I verify that.
Answer: I have learned the answer to my question quite a while ago, posting it here now.

We may write any $C^\infty$ function on $\mathbb R^n$ as $$ f(x)=f(x_0)+\partial_\mu f(x_0)(x^\mu-x_0^\mu)+(x^\mu-x^\mu_0)(x^\nu-x^\nu_0)R_{\mu\nu}(x), $$ where $R_{\mu\nu}(x)$ is a smooth remainder.
Now if $p\in M$ is any point, $U\subseteq M$ is a chart domain with chart map $\varphi$, and $\hat U\subseteq \mathbb R^n=\varphi(U)$, then $C^\infty(U)$ and $C^\infty(\hat U)$ are isomorphic (and our results are local, so we can use $C^\infty(U)$ instead of $C^\infty(M)$), so we can write any function $f\in C^\infty(U)$ as $$ f=f(p)+\partial_\mu f(p)(x^\mu-x^\mu(p))+(x^\mu-x^\mu(p))(x^\nu-x^\nu(p))R_{\mu\nu}, $$ where $\partial_\mu$ are the coordinate vector fields associated with the chart, and $x^\mu$ are now the coordinate functions.
We can project from $C^\infty(M)$ onto $I_p$ by $f\mapsto f-f(p)$, and we can project from $I_p$ to $I_p/I_p^2$ by $f\mapsto [f]$, so we have a projection from $C^\infty(M)$ to $I_p/I_p^2$ as $$ f\mapsto\mathrm df_p:=[f-f(p)]. $$
In the above form of the function, $f(p)$ is a constant that gets chopped of when we move from $C^\infty(M)$ to $I_p$, $\partial_\mu f(p)(x^\mu-x^\mu_0)$ is an element of $I_p$ that gets mapped to $\partial_\mu f(p)[x^\mu-x^\mu_0]=\partial_\mu f(p)\mathrm dx^\mu_p$, and the term involving the remainder $R_{\mu\nu}$ is in $I_p^2$, and thus it dies when taking the quotient.
Therefore, we have $$ \mathrm df_p=[f-f(p)]=\partial_\mu f(p)\mathrm dx^\mu_p, $$ which shows that the elements $$ \mathrm dx^\mu_p=[x^\mu-x^\mu(p)] $$ generate $I_p/I_p^2$, thus this space is finite dimensional. It is also easy to show that the elements $\mathrm dx^\mu_p$ are linearly independent, so $I_p/I_p^2$ is also finite dimensional.

For intuitive interpretation, we mention two points:

The cotangent space (at a point) essentially consists of first-order derivatives of functions (at that point). The construction outlined in this answer clearly constructs the space of first derivatives in a purely algebraic manner.
If $v\in T_pM$ is a tangent vector, then $v$ vanishes on constants, and $v$ vanishes on elements of $I_p^2$. We could try to define the dual space of $T_pM$ to be simply $C^\infty(M)$ by $f:v\mapsto v(f)$, but this space is too big, because two different functions may act the same way on all vectors. If we define $\mathrm df_p(v)=v(f)$, then this is independent of the representative $f$, it only depends on $[f-f(p)]$, thus by going from $C^\infty(M)$ to $I_p/I_p^2$, we cut out those parts of functions that tangent vectors are insensitive to.


User profile custom style (per user)

Question: Is there a way to theme a user's profile but make it per user instead of globally on all users?
Comment: are you using the profile2 module or the deprecated user-profile module?
Comment: Its the one that comes with Drupal 7.
Answer: You can use the Drupal theme suggestions to specify templates based on any of the users fields.
I've implemented a theme for each of the different roles on my site for instance:
<code>function [theme]_preprocess_user_profile(&$vars) {

foreach($vars['elements']['#account']->roles as $role):

    $vars['theme_hook_suggestions'][] = 'user_profile__'. str_replace(' ','-', $role);

endforeach;

}
</code>
To do the same with a users name for instance you could do:
<code>$vars['theme_hook_suggestions'][] = 'user_profile__'. str_replace(' ','-', $vars['elements']['#account']->name);
</code>
Then make sure you've got the corresponding theme files inside your theme folder. All underscores are converted by Drupal to dashes so a suggestion of user_profile__dave would become user-profile--dave.tpl.php for instance.

User profile custom style (per user)


$(H, *)$ is a subgroup of $G$ $\iff$ $a,b\in H $ implies $ab^{-1}\in H$

Question: [Duplicate? This question is not simply asking for a proof, it deals with the logical structure of the proof, and particularly, with the use of sustitutions in relation with quantifiers.]

Although Burton's Introduction To Abstract Mathematical Systems is
the most reader-friendly elementary book on abstract algebra, the
proof it gives of the above theorem is to me difficult
to understand, more precisely, in it's second part,
dealing with the reverse implication:

If $a,b\in H$ implies $ab^{-1}\in H$  then  $(H, *)$ is a subgroup of $G$.

Could anyone give a proof with an endeavour at making as clear
as possible the logical structure of the argument? A proof
using the natural deduction method would be much appreciated.
More precisely, what makes standard proofs of this theorem difficult
is the use of substitutions that seem arbitrary and ad hoc: the
underlying mechanism is not made explicit in terms of quantifiers and instantiation.
The theorem reads as follows:

Suppose that $(G,*)$ is a group and $H$ is a non-empty subset of $G$.
Then $(H, *)$ is a subgroup of $G$  if and only if $a,b\in H$ implies $ab^{-1}\in H$.
Comment: Thanks. I've just added this condition in the body of the question.
Comment: One has to assume that $H$ is also nonempty.
Comment: This is the subgroup criterion.
Comment: That's right. It gives a necessary and sufficient condition for H to be a subgoup of G.
Comment: [Here's a MathJax tutorial](http://meta.math.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference) :)
Comment: Possible duplicate of [If H is a subset of G, prove that H is also a subgroup.](https://math.stackexchange.com/questions/3161151/if-h-is-a-subset-of-g-prove-that-h-is-also-a-subgroup)
Answer: One direction is clear and I'll leave it to you to flesh out the details. As for the other direction . . .
Associativity of the operation in $H$ is inherited from that of $G$. (Showing this rigourously is a matter of restricting the domain of a predicate. Can you see why?)
Since $H$ is nonempty, there exists an $x\in H$ (by existential instantiation). Thus to prove that the identity is in $H$, we have $xx^{-1}=e\in H$ (by letting $a=b=x$ via universal instantiation).
Since now $e\in H$, we have for any $x\in H$ that $ex^{-1}=x^{-1}\in H$ (by letting $a=e, b=x$ via universal instantiation). Hence $H$ is closed under taking inverses.
For closure of $H$ under the operation, if $x,y\in H$, let $a=x, b=y^{-1}$ via universal instantiation. Then $x(y^{-1})^{-1}=xy\in H$.
Hence $H$ is a subgroup of $G$.
Comment: the idea is that what we are allowed to assume is that for **all** possible choices of $a$ and $b$ in $H$, then $ab$ is also in $H$. So if we have specific values for these "variables", then our assumption allows us to conclude in specific. This is the power of our assumption. What you should think, whenever you have this kind of assumption, is that you want to "cash in" on it for specific (or general) examples in order to draw conclusions, exactly as we have done here.
Comment: It's a matter of [universal instantiation](https://en.m.wikipedia.org/wiki/Universal_instantiation), @RayLittleRock; I've edited the question accordingly.
Comment: Thanks for this precision.
Comment: I meant , thanks for this point.  ( "Precision" can be used in french for "point"...).
Comment: @Shaun . Answer accepted !
Comment: @Shaun I'd detract points to a student's paper for that. `;-)`
Comment: Thanks  Shaun. Sure any  competent mathematician will say this proof is correct  and also elegant. What makes it difficult to me is the fact that substitutions ( for example : " let a=e , b=x) are taken as obvious to understand.". When I read it, the objection comes into my mind: " how can you give specific values to your variables, values that lead to the result you want? " That's why I was asking for a proof that would make clear even for beginners the logical structure, and more particuliarly, the use of quantifiers.
Comment: Helpful. Thanks!
Comment: You're welcome, @RayLittleRock. Please don't forget to accept this answer if it is sufficient for you :)
Comment: What's the reason for talking about associativity?
Comment: You're right, @egreg; I suppose it is a bit pedantic of me. I'll leave it there for completeness (although, having said that, there is at least one thing I omitted: the fact that $H\subseteq G$ needs a mention if I'm going to be thorough).


Como acessar a chave, pelo valor, em dicionário python?

Question: Ao preencher o nome de 10 pessoas e suas respectivas alturas, preciso mostrar na tela o nome da pessoa mais alta. No entanto, só consigo pegar o maior valor.
Alguém poderia me ajudar?
people = {}
count = 1
while count <= 2:
    name = str(input('Name: ').strip().title())
    while True:
        try:
            people[name] = float(input('Height: '))
            if type(people[name]) == float:
               break
        except ValueError:
            print('Numbers. Try again.')
    count += 1

print(people)

Comment: Fazendo uma busca no Stack Overflow encontrei uma pergunta que possui a resposta para o que precisa, segue link: https://pt.stackoverflow.com/questions/382490/python-maior-valor-de-um-dicion%C3%A1rio-por-chave
Comment: Só um detalhe, ao fazer `float(input(...))`, o resultado já é um `float`, então não precisa verificar se o `type` da variável é `float`. Se não for digitado um número válido, ele lança o `ValueError` e o código cai direto no `except`, então esse `if` é desnecessário, vc poderia chamar o `break` direto: https://ideone.com/7Ah4Ap
Answer: Pelo que entendi, você deseja implementar um script que seja capaz de montar um dicionário contendo nome e altura de 10 pessoas e, em seguida, exiba o nome da pessoa mais alta.
Pois bem, você pode utilizar o seguinte script:
# Montando um dicionário com nome e altura de 10 pessoas.
people = dict()
for c in range(1, 11):
    n = input(f'{c}º Nome: ').strip().title()
    a = float(input(f'Altura de {n}: '))
    people.update({n: a})

# Verificando a maior altura.
maior = people[max(people, key=people.get)]
print('\033[32mPessoa(s) de maior(es) altura(s):')
for n, a in people.items():
    if a == maior:
        print(f'{n}')

Observe que quando executamos este script é executado o 1º bloco for. É por intermédio dele que será montado o respectivo dicionário.
Então, quando executamos o script recebemos a seguinte mensagem: 1º Nome: . Neste momento devemos digitar o primeiro nome e pressionar enter. Em seguida, recebemos a seguinte mensagem: Altura de fulano: . Neste momento devemos digitar a altura do referido fulano e pressionar enter. Em seguida devemos digitar o nome e altura das demais pessoas.
Depois de digitar nome e altura da última pessoa - 10ª pessoa - e pressionarmos enter, será executado o 2º bloco for. Neste momento, será verificada a maior altura e o(s) nome(s) da(s) pessoa(s) que a possui. Em seguida é exibido o(s) nome(s) da(s) pessoa(s) de maior altura.
Observação
A FUNÇÃO PRIORITÁRIA DE UM LAÇO DE REPETIÇÃO - NO CASO AQUI UM FOR - É JUSTAMENTE REPETIR INTERAÇÕES. Pois bem, se não tivesse inserido o 2º FOR só seria exibido uma só pessoa que, porventura, tivesse a maior altura. Como inserir o 2º FOR o código será capaz de exibir O NOME DE TODAS AS PESSOAS que, porventura, tiverem a altura máxima.
Então, a utilização deste 2º FOR e ALTAMENTE NECESSÁRIO.
Pois se você prestar atenção o penúltimo print()...
print('\033[32mPessoa(s) de maior(es) altura(s):')

...faz referência aos casos de se ter apenas uma saída - um só nome de pessoa - ou a mais saídas - várias pessoas.
Comment: @Solkarped  -  legal você querer mostrar o texto colorido com a ANSI sequence - mas tem duas coisas legais pra voce ter em mente: (1) não é muito legível ou mantivel ter sequências loucas de caracteres em cada print - você pode por a sequencia pra mudar de cor em uma variável e aí usar prints do tipo  `print(f"{VERMELHO} Pessoa(s) de maior(es) altura(s): {NORMAL} )"` . Outra coisa: essas sequências não funcionam no Windows por padrão, então é legal mencionar isso.
Comment: Você deu uma volta na sua resposta - o `max` com Kye já ocnsegue o nome da maior pessoa, e aí é só usar o dicionário - é completamente desnecessário o  `for` final.: nome_maiior = max(people, key=people.get); maior_altura = people[nome_maior] `
Comment: @hkotsubo  - ok, para um feature a mais de "qual a maior altura" - mas isso passa por cima e não responde "como acessar a chave pelo valor" (que é a pergunta) - o melhor seria explicar "aqui é a chave - mas como podem haver repetições do valor, fazemos mais isso ... "
Comment: @jsbueno Concordo, faltou colocar uma explicação desse `for`...
Comment: @hkotsubo, expus de forma detalhada o `uso` do `2º for`. Outra coisa, como `uma pessoa` é um subconjunto de `várias pessoa`, então a minha resposta é suficiente para responder a esta pergunta.
Comment: Entendi. Muito Obrigada!
Comment: @jsbueno Acho que o `for` no final é interessante se tiver empate (mais de uma pessoa com altura igual à maior)
Comment: @jsbueno, quanto a `coloração` da resposta, vou aceitar seu parecer.
Answer: Aqui vai uma outra solução que lida com a situação em que há duas pessoas de altura máxima no dicionário:
pessoas = {
    "João": 1.71,
    "Maria": 1.69,
    "Alberto": 1.75,
    "Joana": 1.70,
    "Pedro": 1.75
}

mais_altas = [pessoa for pessoa, altura in pessoas.items() if
              altura == max(pessoas.values())]

mais_altas é uma lista de todos os nomes das pessoas cuja altura é a maior altura no dicionário pessoas.
A sintaxe usada na última linha é chamada de compreensão de lista, que é uma forma mais simples de escrever um for loop. Aqui é a versão equivalente do mesmo for loop, "por extenso":
mais_altas = []
maior_altura = max(pessoas.values())  # encontra maior altura nos valores
for pessoa, altura in pessoas.items():  # itera sobre pares chave-valor
    if altura == maior_altura:  # quando a altura da pessoa for a maior / uma das maiores:
        mais_altas.append(pessoa)

Comment: Simples demais! Obrigada por ajudar! Inclusive, entrei hoje na list comprehensions, já foi ótimo aprender um pouco sobre a aula hoje, com essa resposta.
Comment: Ótimo, que bom que consegui ajudar :-)
Answer: Você poder fazer igual essa resposta (mencionada no comentário):
print(max(people, key=people.get))

ou se preferir, percorrer direto as chaves do dicionário e ir comparando seus valores:
names = list(people.keys())
if len(names) > 0:
  # inicia o primeiro nome como sendo o maior
  taller = names[0]

  # percorre todos os nomes a partir do segundo
  for name in names[1:]:
    if people.get(name, 0) > people.get(taller, 0):
      taller = name

  print(taller)
else:
  print('no one')

Comment: Muito obrigada!


Infinite lineal combination on a space of functions, which convergence do I need?

Question: I have been wondering this question for a long time without getting an answer, I just arrive to necessary conditions but I would like to get a characterization of the problem. The problem is, if I have a linear operator, $T:V \to V$, on a space of functions $V$ then,
When is true that $T(\sum^{\infty}\alpha_nf_n) = \sum^{\infty} \alpha_nT(f_n)?$
In order to get a necessary conditions, if $V = C^{\infty}(\mathbb{R})$ and $T$ maps $f \mapsto f'$, then I need that there exist $x_0$ such that $\sum^{\infty}\alpha_nf_n(x_0)$ converges and also that $\sum^{\infty}\alpha_nf'_n$ converges uniformly on $\mathbb{R}$. To sum up, I need $C^1-$converge.
Indeed, one can extend the previous argument to see that it is needed $C^{\infty}-$convergence, for example take $T$ to be the second derivative, then we need $C^2-$convergence, and so do.
I would appreciate if someone could shed some light on the matter. Maybe we need to discuss about conditions on both, $T$ and $V$.
Answer: You are just talking about continuous operators in different linear topologies. Your condition is equivalent to $T$ being continuous from $(V,\tau_1)$ to $(V, \tau_2)$ for some linear topologies $\tau_1, \tau_2$ (the first infinite sum is taken with respect to $\tau_1$, the second with respect to $\tau_2$).
Comment: Ok, where can I read about that if I would like to study which topologies are needed for a given $T$. Thanks
Comment: The main point is that for linear operators your infinite sum condition is equivalent to just being (sequentially) continuous (i.e. $T(\lim x_n) = \lim Tx_n$ for all converging sequences $(x_n)$). For studying continuity it is enough to brush some introductory chapters on Linear Topology (e.g., Aliprantis-Burkinshaw "Hitchhiker's guide to Infinite-dimensional Analysis" is fine).
Concerning specifically derivation operators on function spaces, I guess you want to go with Operator Theory introductions. Consider, e.g., Davies' "Linear Operators..." or "Spectral theory and Diff. operators".
Comment: Great!! Thanks for the help!!


Upload files in GitHub

Question: I installed Git Bash 1.9.5. I have a repo created at www.github.com. I want to upload a file named test.txt from my local computer to the remote github. I looked at several old questions, but could not find a way to do this. Please help.
I tried git add test.txt and then git push but not really working. Any help will be appreciated.
Thanks
Comment: Have you fully read the GitHub tutorials? If you did, please provide more information including any errors you get. Also: You need to commit before you push.
Comment: "Not really working" is not really working to convey the output from your commands.
Comment: In my computer, GitBash repo is in "C:/Users/Sambit/localrepo" where I have created a text file called "test.txt" . Now coming to the GitBash console, I write `cd ~/localrepo` to specify my local repository. Then I write `git remote add origin "https://github.com/remoteusername/remoterepo"`, then I write `git add.` followed by `git commit -m "add test.txt"` which says `Changes not staged for commit....no changes added to commit"` then `git push` says `updates were rejected because the remote contains work that you do not have locally..."` but I did a cloning already
Comment: @user3096833 are you sure you did a `git clone https://github.com/remoteusername/remoterepo C:/Users/Sambit/localrepo` ? Because if you did a `git clone`, you don't need to add a remote. Follow the second approach I mention below and it will work.
Comment: Still throwing error. The cloning statement gives the error `destination path already exists and is not an empty directory` Then the add statement shows lots of warnings and finally gives the error : `unable to index file...` and then `fatal : adding files failed`
Answer: In your local repo, you can add the remote url of your remote GitHub repo
git remote add origin https://<yourAccount>@github.com/<yourAccount>/<yourRepo)
git commit -m "Add test.txt"
git push -u origin master

The other approach would be to clone your repo first, and add your file in it (then git add .; git commit -m "add test.txt"; git push)
Answer: git add adds a file to the index, but it doesn't create a commit.
To create a new commit from the index use git commit.
When you have a commit push it with git push.
Review what you're doing with gitk (for instance).
For more info, see any tutorial on git. For instance: http://www.gitguys.com/topics/whats-the-deal-with-the-git-index/

Upload files in GitHub


hook_schema install, but not uninstall

Question: I can't figure how it is possible that the table I define in a hook_schema is created when I enable my module, but it isn't deleted when I uninstall the module (after disabling).
Drupal 7 documentation sais that the table should be automatically created and deleted when these events occours.
Here is the relevant part of the code inside my_module.install:
function my_module_schema(){
    $schema = array();
    $schema["my_module_table_xyz"] = array(
            ...
    );
    return $schema;
}

I don't know if it could be related to the difference between the modue name and the table name... or from the code present in the hook_uninstall... or something else...
Considering I also define a node type, the hook_uninstall should delete it (see following code), then system should automatically uninstall previously defined schema.
function my_module_uninstall(){
    ...
    node_delete_multiple(...);
    // delete custom fields
    node_type_delete(...);
    field_purge_batch(...);
}

What do you think about?
Thanks
NOTE: I use Drush to disable, uninstall and reinstall the module and I get the error Table my_module_table_xyz already exist.

Update: I just verified that the same code in a clean Drupal installation works as expected (table defined in hook_schema have been successfully removed).
In the "problematic" Drupal installation I also tried to explicit run drupal_uninstall_schema("my_module_table_xyz") at the end of the hook_uninstall (and I inserted a log instruction just after that line, to verify it runs without breaking), but nothing change. The table is stille there!
Any idea/hypothesis about will be really appreciated.
Comment: Disabling a module does not explicitly delete nodes created under that custom type - so yes, you would need to do this yourself. Though, most do not do this and instead leave it to the site administrators to make that call.
Comment: @Kevin thanks for your reply. I suppose that every time you wrote "disable" you meant "uninstall". I know that uninstalling a module doesn't delete provided nodes: this question is related to "hook_schema", so I'm not speaking of nodes (the code in my hook_uninstall have just been reported to exlude problem with it). Yes, I'm also aware that if enabling a module it says "unable to create an existing table" I have to manually delete that table, then I can proceed. My question here is: "what is the problem with my code?" and not "what trick I can opt for?"
Comment: Also if you get a table installed, and then disable a module without the table going away, you will have issues re-enabling the module. In that case, delete the table manually, clear the cache, then enable the module. The table should appear without error. Disable the module, the table should be gone.
Answer: I had the same issue and finally I just manually did it in hook_uninstall(), I could find no other recourse.
function mymodule_uninstall() {
  $table_name = 'mytable';
  if (db_table_exists($table_name)) {
    db_drop_table($table_name);
  }
}

Hope this saves someone else some time.
Answer: For recent usage in Drupal 8-9, this is the equivalent:
function mymodule_uninstall() {

  $table_name = 'mytable';
  $schema = \Drupal\Core\Database\Database::getConnection()
    ->schema();
  if ($schema->tableExists($table_name) ) {
    $schema->dropTable($table_name);
  }

}

Comment: Not sure why anyone downvoted this answer. The documentation shows the same code: https://api.drupal.org/api/drupal/core%21includes%21database.inc/function/db_drop_table/8.9.x
Comment: @Beau Answer was probably downvoted because `db_drop_table()` is deprecated in drupal:8.0.0 and removed from drupal:9.0.0. Use `\Drupal\Core\Database\Database::getConnection()->schema()->dropTable()` instead. See https://www.drupal.org/node/2993033

hook_schema install, but not uninstall


Can't edit block

Question: I´m new with Drupal. I started a month ago with Drupal 8. Everything works fine. I had some own custom blocks. Then I added some javascript to one block.
Immediately after that editing of the block or other content was not possible. I can edit nodes, if I open them, there are tabs. But my own block is not possible to edit. If I remove this block, I can edit all other content. If I publish it again, edit button (pen) is missing.
How I can edit my own block again?
The code in the block is taken from here: http://kotisivuapu.suntuubi.com/?cat=194&aid=19&fid=57&mid=57&c=57
I have some code in the block before this script:
some links to
- own folders, like /sites/default/files/picture.gif"
- internet, www-pages
I see, this is problem with this code and I´ll do it with php.
Comment: It is probably related to the custom javascript code that is included in the block ... post some relevant code perhaps we can understand what is going on.
Comment: Do you see any browser console error ?
Comment: No, not any errors. Just the link is missing.
Comment: Apart from being written in very old syntax the code works and behaves correctly.  I just put it in a block myself and it does not create any problem.  And the edit pen still shows.  Perhaps you did something else wrong pasting the code ? or the the format is limiting js to function.
Answer: If you want to embed javascript into a block make sure that your format is not stripping out parts of your code.  Full HTML supplied with core is probably good enough.
Paste the following javascript code just to test that everything works properly.
<code><script>
document.write("test javascript");
</script>
</code>
And make sure your format is Full HTML

NOTE: The recommended way to introduce javascript into a Drupal site would be with a theme or a module as described here
Comment: Yes, with this test piece everything works fine. Problems are there in the copied code.
Comment: I did not have a problem with the test code, copied and pasted exactly as it is.  Perhaps the problem is with the specific theme that you are using ? Try with a different theme enabled/default.
Comment: Thanks for the tests. I´ll do this with php.
Answer: Problem solved!
This line:
document.write("Onnea: " + nimipv + "!");
Shortened like this and everything works:
document.write("Onnea: " + nimipv + "!");

Can't edit block


Executar php artisan em um diretorio diferente

Question: Como executar o comando:
php artisan ...

Em um diretório diferente de forma que os arquivos gerados fiquem na pasta que eu definir
Answer: Isso vai depender do comando ao qual você deseje executar, mas vamos partir do pressuposto que você queira executar uma migration, você consegue definir o path(Caminho) desta forma:
php artisan migrate --path=/app/database/migrations/relations

Fonte

1 - Lembrando que você deve esta dentro diretório onde esta o arquivo
  artisan
  2 - E o executável do php deve esta nas variáveis de ambiente

Mas se você quiser executar o comando em outra pasta, basca colocar o caminho completo de cada arquivo, como por exemplo:
c:\bin\php.exe c:\meu_projeto\artisan migrate --path=c:\meu_projeto\migrations

No exemplo, meu executável do php esta na pasta "bin" na raiz do c:, enquanto meu projeto esta na pasta "meu_projeto" e dentro de "meu_projeto" as migrations.

Isso gera muito trabalho, então é preferível entrar na pasta onde esta
  o arquivo artisan e colocar o executável do php nas variáveis de
  ambiente.


Batch script -> find a sentence and replace it by a new one

Question: I'm working on a DOS script in order to search a line and replace it into files from a specific folder. Here is what i have already done :
@echo off
setlocal enableextensions disabledelayedexpansion

set "search=@Interceptors({ RuntimeExceptionInterceptor.class }^)"
set "replace=@Interceptors({ RuntimeExceptionInterceptor.class, ReportInterceptor.class, CorrelationIdInterceptor }^)"

set "textFile=C:\Utilisateurs\a669884\Documents\test.txt"

for %%a in (*.txt) do (
echo "%%a"
for /f "Delims=" %%i  in (%%a ^& break ^> %%a) do (
    set "line=%%i "
    setlocal enabledelayedexpansion
    >>%%a echo(!line:%search%=%replace%!
    endlocal
      )
 )

Problem is that my first line is not replace by the new one, the new line is added under it like that :
@Interceptors({ RuntimeExceptionInterceptor.class })
@Interceptors({ RuntimeExceptionInterceptor.class, ReportInterceptor.class, CorrelationIdInterceptor })
Do you know why my first line isn't replaced? Thanks a lot
Seb
Comment: How is this related to Java ?
Comment: In a certain way, i will use it on my java project in order to replace a line in my WebServices
Comment: [Windows cmd is **not** DOS](https://superuser.com/q/451432/241386). There's nothing like for loop or delayed expansion in DOS. Anyway it's better to use powershell for tasks like this
Answer: Not sure what setting textfile has to do with the routine - it's not used.
Your original code produced a complaint that & was not found and created an empty file for me.
Changing the for to
for /f "Delims=" %%i  in ('type "%%a" ^& break ^> "%%a"') do (

seemed to make the substitution, given the one line (partial?) of sourcefile you've provided, plus a few dummy lines.
execute the type... with the filenames enclosed in quotes to ensure correct operation with separators, replacing the file; substitute as specified.


Convert link from node/nid to Pathauto url?

Question: Im using Pathauto to make my URLs nice and I may want to change the paths in the future. On some pages Im manually lining to other nodes.
The issue is that if I code the nice URL then the link will be broken if I change the Pathauto settings in the future. If I link to node/(the node id) then the link will always work, but its bad for SEO to not have keywords in the anchor text.
Is there a way to code in the NID so it always works but on the page show the nice URL?
Answer: I would, as Splat mentioned, check out the Global Redirect module, which will help out with google not seeing node/FOO and pretty/path pointing to identical content.  If, however you are wanting to make sure that when engines scan your page content and pretty/path shows up inside the HTML, you can either continue to hardcode the paths, or create a function that returns the aliased path based on the nid.
function make_my_path($nid) {
  $pretty_path=drupal_get_path_alias('node/' . $nid);
  return $pretty_path;
}

Then use that (or drupal_get_path_alias() directly) in your templates or preprocess functions, or just use l().  If it is passed 'node/FOO' as the path, it will return the aliased path if one is set. (Unless you explicitly tell it not to; see url().)
So, for example, print l('Hello World','node/23'); should return Hello World.
Comment: Thanks. Shame their isn't a module to remove the need for so much code.
Answer: If you're using CKEditor, you should use the CKEditor Link module. It allows searching content by title to insert, and in Drupal it saves the link as /node/[ID]. Then a text filter (which you'll need to enable for each text format it's being used on) replaces that URL with the current path alias in the rendered page.
Answer: I think you're looking for the Global Redirect module. This will make sure whenever you link to node/x that anyone following the link is redirected to the clean URL for that node.
Comment: No, I want it so on the page with the link the actual html isn't node/x but instead it's the nice Pathauto URL. Users will never notice the difference, but search engines do. Thanks