Why Listview showing duplicate entries with custom adapter android?

Question: I created custom adapter to bind with listview but it's showing duplicate songs in listview. please check out the code and let me know if anything is wrong
public class UnfavoriteSongAdapter extends BaseAdapter

{

private Activity activity;
private ArrayList<Media> data;
private static LayoutInflater inflater = null;

private Context context;

public UnfavoriteSongAdapter(Context context, Activity a, ArrayList<Media> d) {
    activity = a;
    this.context = context;
    data = d;
    inflater = (LayoutInflater) activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {
    return data.size();
}

@Override
public Object getItem(int position) {
    return position;
}

@Override
public long getItemId(int position) {
    return position;
}

GenreFavoriteClickListner genreFavoriteClickListner;

public interface GenreFavoriteClickListner {
    public void onFavoriteClickListner(int position,Media media);
}

public void setGenreFavoriteClickListner(GenreFavoriteClickListner genreFavoriteClickListner) {
    this.genreFavoriteClickListner = genreFavoriteClickListner;
}

public static class ViewHolder {
    public TextView textView_title, textView_artist, textView_time;
    public CircleImageView circleImageView_albumphoto, circleImageView_favorite;
    public ImageView imageView_play;

}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    View vi = convertView;
    final ViewHolder viewHolder;
    try {
        if (convertView == null) {
            viewHolder = new ViewHolder();
            final LayoutInflater inflater1 = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            vi = inflater1.inflate(R.layout.song_listitem_layout, null);
            viewHolder.textView_title = (TextView) vi.findViewById(R.id.textView_song_songname);
            viewHolder.textView_artist = (TextView) vi.findViewById(R.id.textView_song_artistname);
            viewHolder.textView_time = (TextView) vi.findViewById(R.id.textView_song_time);
            viewHolder.circleImageView_albumphoto = (CircleImageView) vi.findViewById(R.id.circleImageView_nowplaying_playing);
            viewHolder.circleImageView_favorite = (CircleImageView) vi.findViewById(R.id.circleImageView_song_favorite);
            viewHolder.imageView_play = (ImageView) vi.findViewById(R.id.imageView_song_playpause);

        } else {
            viewHolder = (ViewHolder) vi.getTag();
        }
        if (data.size() <= 0) {
            //viewHolder.textview_albumtitle.setText("No Appointment");
        } else {

            final Media p = data.get(position);
            viewHolder.textView_title.setText(p.getSongName());
            viewHolder.textView_artist.setText(p.getArtistName());
            long millis = Long.parseLong(p.getDuration());
            String hms = ReusableModules.getCalculatedTime(millis);
            viewHolder.textView_time.setText(hms);
            String isplaying = p.getIsPlaying();
            int playingid = R.mipmap.play;
            if (isplaying != null) {
                if(isplaying.contentEquals(Constants.ONE)){
                    playingid = R.mipmap.runing_music_play;
                }
            }
            viewHolder.imageView_play.setImageResource(playingid);

            ReusableModules.setFavoriteToggleButton(p.getIsFavorite(), viewHolder.circleImageView_favorite);

            viewHolder.circleImageView_favorite.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (genreFavoriteClickListner != null) {
                        genreFavoriteClickListner.onFavoriteClickListner(position,p);
                    }
                }
            });

            final String finalUrl = p.getAlbumUrl();
            viewHolder.circleImageView_albumphoto.post(new Runnable() {
                @Override
                public void run() {
                    BaseActivity.imageLoader.displayImage(finalUrl,
                            viewHolder.circleImageView_albumphoto, SplashScreenActivity.displayImageOptions, new SimpleImageLoadingListener() {
                                @Override
                                public void onLoadingComplete(Bitmap loadedImage) {

                                }
                            });
                }
            });
            vi.setTag(p);
        }

    } catch (Exception e) {

    }
    return vi;

}
}

Answer: Change in getView() method like this.
   viewHolder = new ViewHolder();
  if (convertView == null) {
        final LayoutInflater inflater1 = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    }
        vi = inflater1.inflate(R.layout.song_listitem_layout, null);
        viewHolder.textView_title = (TextView) vi.findViewById(R.id.textView_song_songname);
        viewHolder.textView_artist = (TextView) vi.findViewById(R.id.textView_song_artistname);
        viewHolder.textView_time = (TextView) vi.findViewById(R.id.textView_song_time);
        viewHolder.circleImageView_albumphoto = (CircleImageView) vi.findViewById(R.id.circleImageView_nowplaying_playing);
        viewHolder.circleImageView_favorite = (CircleImageView) vi.findViewById(R.id.circleImageView_song_favorite);
        viewHolder.imageView_play = (ImageView) vi.findViewById(R.id.imageView_song_playpause);

and remove this
 else {
        viewHolder = (ViewHolder) vi.getTag();
    }

in last of getView() method
convertView.setTag(holder);

try this and tell me it works or not?
Comment: It's not working.  when i bind with listview using custom adapter then it's shwoing duplicates items after every 7th positions.This may help you to know more about problem
Comment: try this @DharmeshDhameliya
Comment: I tried this solution and did some other changes. then it's worked. thanks -- Dalvinder Singh
Answer: Add vi.setTag(p) inside :
if(convertView == null){
 vi.setTag(p);
}

Answer: move
vi.setTag(viewholder);

inside
if(convert==null){
            viewHolder = new ViewHolder();
            final LayoutInflater inflater1 = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            vi = inflater1.inflate(R.layout.song_listitem_layout, null);
            viewHolder.textView_title = (TextView) vi.findViewById(R.id.textView_song_songname);
            viewHolder.textView_artist = (TextView) vi.findViewById(R.id.textView_song_artistname);
            viewHolder.textView_time = (TextView) vi.findViewById(R.id.textView_song_time);
            viewHolder.circleImageView_albumphoto = (CircleImageView) vi.findViewById(R.id.circleImageView_nowplaying_playing);
            viewHolder.circleImageView_favorite = (CircleImageView) vi.findViewById(R.id.circleImageView_song_favorite);
            viewHolder.imageView_play = (ImageView) vi.findViewById(R.id.imageView_song_playpause);

           // here
           vi.setTag(viewholder);
}

and remove this:
      final String finalUrl = p.getAlbumUrl();
        viewHolder.circleImageView_albumphoto.post(new Runnable() {
            @Override
            public void run() {
                BaseActivity.imageLoader.displayImage(finalUrl,
                        viewHolder.circleImageView_albumphoto, SplashScreenActivity.displayImageOptions, new SimpleImageLoadingListener() {
                            @Override
                            public void onLoadingComplete(Bitmap loadedImage) {

                            }
                        });
            }
        });
  remove this    **vi.setTag(p);**

Comment: i know that he is setting tag after if block so how he is going to get tag, and please check the code OP has given
Comment: where is v1.setTag(p) in if block of convertView
Comment: I set Media object as tag because i want that object when i click on item.
Comment: when u click on item u get position and from that position u can retrieve item from arraylist
Comment: Yeah. you are right. but your solution is not working here.
Comment: did u try removing and adding both?
Comment: yes. did both. I checked arraylist it's showing unique items. but when i bind with listview using custom adapter then it's shwoing duplicates items after every 7th positions.This may help you to know more about problem
Comment: change vi.setTag(p); to vi.setTag(viewholder);
Comment: Yeah. it's worked but i did some other changes in code. thanks -- ankitagrawal
Answer: set tag for view holder if view holder null. Add last line of code
if (convertView == null) {
                viewHolder = new ViewHolder();
                final LayoutInflater inflater1 = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                vi = inflater1.inflate(R.layout.song_listitem_layout, null);
                viewHolder.textView_title = (TextView) vi.findViewById(R.id.textView_song_songname);
                viewHolder.textView_artist = (TextView) vi.findViewById(R.id.textView_song_artistname);
                viewHolder.textView_time = (TextView) vi.findViewById(R.id.textView_song_time);
                viewHolder.circleImageView_albumphoto = (CircleImageView) vi.findViewById(R.id.circleImageView_nowplaying_playing);
                viewHolder.circleImageView_favorite = (CircleImageView) vi.findViewById(R.id.circleImageView_song_favorite);
                viewHolder.imageView_play = (ImageView) vi.findViewById(R.id.imageView_song_playpause);

                /************  Set holder with LayoutInflater ************/
                 vi.setTag( viewHolder );

            }

//check you data size getCount,its a good practice. not in getview method.
@Override
public int getCount() {
    if(data!=null && data.size()> 0)
    return data.size();
    else
    return 0;
}

I suggest you to replace getview method and check you data once because your adapter code seems perfect.
Comment: when i bind with listview using custom adapter then it's shwoing duplicates items after every 7th positions.This may help you to know more about problem
Comment: I tried your first solution earlier and it's working. thanks - Nil


If I consider the fixed factor as a random slope, the p-value changes from p<0,05 to p>0,05

Question: I'm having a hard time trying to understand the differences between these two models and why the first one shows correlation (p-value < 0,05) but the other one doesn´t (p-value > 0,05).
I would be very grateful if someone could help me, because I have to submit my thesis soon.
In this study we want to assess if the human balance improves after training.
We had 40 subjects. Our dependent variable (EnHL, the one that gives us the information about balance) was measured three times over one week for each subject (training, 1 day later and 7 days later). In the first day (training) each subject did 16 trials, 1 day later they did 4 trials and 7 days later they did 16 trials.
My table looks like this: (2881 rows and 4 columns)

Here's a plot of all the trials within the sessions for each subject

My question is: what model would be more accurate?
gamma <- glmmTMB(EnHL ~ Session + Trial + (1 | Subject) , data = original, family = "Gamma" (link = log))

glmmTMB:::Anova.glmmTMB(gamma,contrasts=list(Session=contr.sum, Trial=contr.sum), type = 3)

Response: EnHL
                Chisq Df Pr(>Chisq)
(Intercept) 2118.0801  1  < 2.2e-16 ***
Session       11.9676  2   0.002519 **
Trial          6.1979  1   0.012790 *

summary(gamma)

Family: Gamma  ( log )
Formula:          EnHL ~ Session + Trial + (1 | Subject)
Data: original

     AIC      BIC   logLik deviance df.resid
 -4738.3  -4706.9   2375.2  -4750.3     1391

Random effects:

Conditional model:
 Groups  Name        Variance Std.Dev.
 Subject (Intercept) 0.03568  0.1889
Number of obs: 1397, groups:  Subject, 40

Dispersion estimate for Gamma family (sigma^2): 0.0435

Conditional model:
                 Estimate Std. Error z value Pr(>|z|)
(Intercept)     -1.579152   0.034390  -45.92  < 2e-16 ***
Session7days     0.046246   0.020271    2.28  0.02253 *
Sessiontraining  0.012743   0.020226    0.63  0.52868
Trial           -0.003473   0.001271   -2.73  0.00627 **

here the p-value for the trials and for the sessions is less than 0,05 (there's a relationship between sessions (after 7 days) and EnHL and between trials and EnHL)
or
gammacrs <- glmmTMB(EnHL ~ Session + Trial + (Trial + Session | Subject), data = original, family = "Gamma" (link = log))

where I´m assuming that the sessions are allowed to vary between the subjects. (If this wasn't the case nothing should change, right?)
glmmTMB:::Anova.glmmTMB(gammacrs,contrasts=list(Session=contr.sum, Trial=contr.sum), type = 3)

Response: EnHL
                Chisq Df Pr(>Chisq)
(Intercept) 1638.3203  1     <2e-16 ***
Session        4.2577  2     0.1190
Trial          2.6027  1     0.1067

summary(gammacrs)

 Family: Gamma  ( log )
Formula:          EnHL ~ Session + Trial + (Trial + Session | Subject)
Data: original

     AIC      BIC   logLik deviance df.resid
 -4828.5  -4749.9   2429.3  -4858.5     1382

Random effects:

Conditional model:
 Groups  Name            Variance  Std.Dev. Corr
 Subject (Intercept)     0.0513038 0.226503
         Trial           0.0000902 0.009497  0.17
         Session7days    0.0126242 0.112357 -0.69 -0.31
         Sessiontraining 0.0250126 0.158154 -0.46 -0.51  0.59
Number of obs: 1397, groups:  Subject, 40

Dispersion estimate for Gamma family (sigma^2): 0.0369

Conditional model:
                 Estimate Std. Error z value Pr(>|z|)
(Intercept)     -1.583330   0.039118  -40.48   <2e-16 ***
Session7days     0.044660   0.025793    1.73   0.0834 .
Sessiontraining  0.011696   0.031197    0.37   0.7077
Trial           -0.003073   0.001905   -1.61   0.1067

With this model there are no correlations between sessions and EnHL or between trials and EnHL anymore (p-value > 0,05).
The function anova(gamma, gammacrs, test = "Chisq") tells us that the second model is better.
Models:
gamma: EnHL ~ Session + Trial + (1 | Subject), zi=~0, disp=~1
gammacrs: EnHL ~ Session + Trial + (Trial + Session | Subject), zi=~0, disp=~1
         Df     AIC     BIC logLik deviance  Chisq Chi Df Pr(>Chisq)
gamma     6 -4738.3 -4706.9 2375.2  -4750.3
gammacrs 15 -4828.5 -4749.9 2429.3  -4858.5 108.22      9  < 2.2e-16 ***

My interpretation of the results is: The sessions and the trials are different for every subject. Some of them improve but others don't (the differences between subjects are important). What do you think?
Edit:
I've extracted all the random effects.
Note 1 : Intercept = Training ; Session1 = 1day ; Session2 = 7days
$Subject
   (Intercept)      Session1     Session2         Trial
1    -1.713896  0.0965891767 -0.011518628  0.0067663851
2    -1.561364  0.0840375097  0.080187190  0.0137080183
3    -1.275755  0.0004848607 -0.042586717  0.0028534510
4    -1.278252 -0.0536642568 -0.020647458 -0.0122991059
5    -1.465870  0.0181134542  0.008405354 -0.0002592055
6    -1.610363 -0.0988696152  0.012303906 -0.0069000874
7    -1.464979  0.0925183339  0.015557069  0.0010255370
8    -1.804658 -0.1398576157  0.102382968 -0.0060396435
9    -1.801174 -0.0529431098  0.024780565 -0.0042638591
10   -1.421477 -0.0921801843  0.065533093 -0.0041786959
11   -1.480386  0.0144059690  0.057358732 -0.0047655723
12   -1.386061  0.0902745005  0.046153060 -0.0027204657
13   -1.668770  0.0219507766  0.084439469 -0.0037810769
14   -1.716096  0.0488681197  0.176934080  0.0043043320
15   -1.784928 -0.1327412005  0.085074360 -0.0086768685
16   -1.532577  0.0272251821 -0.038856126 -0.0077024692
17   -1.725039 -0.0909731768 -0.015877398 -0.0113995813
18   -1.322610  0.0287808148 -0.040762983  0.0031696644
19   -1.411264  0.0477764606 -0.007162943  0.0040797905
20   -1.429356 -0.0084597510 -0.033387436 -0.0047225067
21   -1.555885  0.0571250855  0.029741363  0.0072087558
22   -1.630751 -0.1443444132 -0.036059771 -0.0261584712
23   -1.796652 -0.0375694398  0.058203264 -0.0109808637
24   -1.469535 -0.0100575168  0.011208402 -0.0113491972
25   -1.973101 -0.0727788418  0.098841831 -0.0080184843
26   -1.675099 -0.0494589192  0.059443376  0.0071001076
27   -1.245882  0.0011772501 -0.019320935 -0.0034227885
28   -1.558100 -0.0239727664  0.062121576 -0.0057094588
29   -1.474227 -0.0059313380  0.091154895  0.0077893881
30   -1.404088 -0.0543213259 -0.023103316 -0.0004199302
31   -1.877645 -0.0784904402  0.070055279  0.0005748268
32   -1.409313 -0.0320830203 -0.038264689 -0.0014453813
33   -1.614586 -0.0427011119 -0.008117112 -0.0093748427
34   -1.452076  0.0320788297  0.039076646 -0.0182604601
35   -1.710346 -0.0326692685  0.002930763  0.0042231651
36   -1.836628 -0.0838170332  0.058713821 -0.0084572632
37   -1.623402 -0.0400794014  0.036481544  0.0029131856
38   -1.505535  0.0388458313 -0.007707702  0.0026484699
39   -1.292290 -0.0282789746 -0.008594992  0.0016093783
40   -1.681294 -0.0675433733  0.022157397 -0.0121784692

and ploted them

Note 2 : The plot doesn't exactly match the "coef" table. Some red points are positive in the table. Is this because of the standard error?
Comment: You really should not be using any arbitrary cutoff p-value for this type of question. There are several important reasons for that, but the trivial p=0.0499 vs p=0.5001 is one. There are a great many questions and answers on this site that will help you with p-values and their meaning. These are a start: https://stats.stackexchange.com/questions/16218/what-is-the-difference-between-testing-of-hypothesis-and-test-of-significance, and https://stats.stackexchange.com/questions/46856/interpretation-of-p-value-in-hypothesis-testing
Comment: *There are also no correlations within this model: gammacrs <- glmmTMB(EnHL ~ Session + (Session | Subject), data = original, family = "Gamma" (link = log))
Comment: What do you mean "no correlations" ? Please edit the question and  inc;lude the output from `summary()` of both models. Just enclose all the text with 3 backticks (````) at the start and the same at the end, and the system will format it nicely
Comment: Thank you so much Robert for taking the time to read my question. I´m really desperate trying to find the correct conclusion for my thesis. Sorry that my explanation wasn´t clear enough, I´m new to statistics. I just edited the question, I hope it´s more clear now!
Comment: No problem, you're very welcome. What is your research question(s) ?
Comment: Thank you Michael! Those answers are really helpful
Answer: This is a fairly common scenario and indicates that there is meaningful variation among subjects in their response to the Trial and Session variables. We can also observe this directly from the lattice plot you provided - it is clear that there is a wide range of responses. I would suggest that you extract the random effects themselves for these variables and visualise them, particularly with respect to the fixed effects for them. The fixed effect is the "global" effect and each subject then has their own offset from this. When these deviations are extremely small then both models would be expected to give similar results. However, when these deviations are sizeable then we will expect the results to differ. The point estimates for the fixed effects should be approximately the same, however the confidence intervals for the fixed effects that are specified as random slopes will be wider when we fit random slopes, as compared to when we do not fit random slopes. When we do not fit random slopes, the model tries to capture all the variation that is due to these variables as fixed effects only - if we happen to know that there is also subject-level variation in the response to these variables, some of this will be captured by the fixed effects, resulting in lower p-values. When we add random slopes, this aditional variation is then captured by the random effect, resulting in higher p-value for the fixed effects. Another way to look at this is to consider the precision of the fixed effects. When we add random slopes, the standard error for fixed effects increase, so we are estimating it with less precision. But it would be a mistake to think that this is bad, because it's not the whole story - we also now have the random effects (slopes) which tell us how each subject responds differently.
Another point to bear in mind is that p-values are not well defined for mixed models - they are computed based on an approximation for the denominator degrees of freedom. Therefore the p-values are also approximations. This in turn means that any "rule" based on a cut-off value of significance, such as 0.05, which is already a highly questionable procedure, even for well-behaved estimates, should not be applied blindly with mixed models.
As for interpretation,

My interpretation of the results is: The sessions and the trials are different for every subject. Some of them improve but others don´t (the differences between subjects are important)

I'm not really sure how you arrived at this, but I don't think it's correct.
First of all, it looks like the reference level for Session is "day 1". This means that the other estimates for Session are contrasts with day 1. To me this does not really make sense because the variable is time: 0 (training), 1 and 7 days. So, the estimate Session7days is the expected difference in the outcome between 1 and 7 days, whereas the estimate Sessiontraining is the expected difference in the outcome between day 0 (training) and 1 days. For me, it would make more sense to have 0 (training) as the reference level, with the 1 and 7 day estimates being the expected difference in outcome compared to day 0 (training). It's OK if you want to retain day 1 as the reference level, but I just think it makes more sense to have the reference as 0. Anyway, regardless of that, it appears that you have a nonlinear association with respect to time. Compared to day 1, day 0 is 0.01 higher, whereas, compared to day 0, day 7 is 0.04 higher. This that the overall/global response falls slightly from day 0 to day 1 and then increases  from to day 1 to 7.
As for Trial, the "effect" is negligible (ie very small). This may be because it should not be in the model in the first place. From what I can understand of the description, the Trial variable is simply an ID to count the number of repeated measures within subject, right ? So trial 1 in subject 1 has nothing to do with trial 1 in subject 2, right ? If so, then Trial should not be in the model at all. However, if there is something shared between trials - such as all subjects doing the same trial number at the same time/place (or some other condition), then it should be retained.
Edit: To extract the random effects and visualise them.
Obviously I don't have access to your model and code, so I will just use some boilerplate code that I often use for this type of thing, to simulate data for a simple model with random slopes and random intercepts. You should be able to adapt it to your situation easily:
set.seed(1)
n_group <- 10
dt <- expand.grid(X = 1:5, G = LETTERS[1:n_group])
X <- model.matrix(~ X, dt)

dt$Y <- 1
myFormula <- "Y ~ X + (X | G)"

foo <- lFormula(eval(myFormula), dt)
Z <- t(as.matrix(foo$reTrms$Zt))

betas <- c(1, 0.5) # Fixed effects parameters

s1 <- 2   #  SD of random intercepts
s2 <- 1   #  SD of random slopes

eps <- 1  # SD of residual error

rho <- -0.9  # correlation between intercepts and slopes
cormat <-  matrix(c(s1, rho, rho, s2), 2, 2)  # correlation matrix
covmat <- lme4::sdcor2cov(cormat)             # covariance matrix (needed for mvrnorm)

umat <- MASS::mvrnorm(n_group, c(0, 0), covmat, empirical = TRUE)  # simulate the random effects

u <- c(rbind(umat[, 1], umat[, 2]))  # lme4 needs the random effects in this order (interleaved)

e <- rnorm(nrow(dt), 0, eps)   # residual error

dt$Y <- X %*% betas + Z %*% u + e

So that completes that completes the simulation.
Now we can fir the model:
 m0 <- lmerTest::lmer(myFormula, dt)
 summary(m0)

Random effects:
 Groups   Name        Variance Std.Dev. Corr
 G        (Intercept) 6.3031   2.5106
          X           1.3187   1.1484   -0.93
 Residual             0.8599   0.9273
Number of obs: 50, groups:  G, 10

Fixed effects:
            Estimate Std. Error     df t value Pr(>|t|)
(Intercept)   1.2599     0.8514 9.0003    1.48    0.173
X             0.4611     0.3748 9.0002    1.23    0.250

Note that we recover good estimates of all the parameters.
Also, note that if we instead fit a model without random slopes, as in your situation, the p-values will be smaller:
Formula: Y ~ X + (1 | G)
   Data: dt

Random effects:
 Groups   Name        Variance Std.Dev.
 G        (Intercept) 1.524    1.235
 Residual             3.903    1.976
Number of obs: 50, groups:  G, 10

Fixed effects:
            Estimate Std. Error      df t value Pr(>|t|)
(Intercept)   1.2599     0.7627 37.3305   1.652   0.1069
X             0.4611     0.1976 39.0000   2.334   0.0249 *

Anyway, back to our model with random slopes, m0. To extract the random effects we simply use coef()
> coef(m0)
$G
  (Intercept)           X
A  4.31279623 -1.02364292
B  0.84684954  0.49626942
C  2.01312431 -0.42268395
D -4.33181597  3.20054211
E  2.20511436  0.24003270
F  0.90360461  0.05498340
G  0.09115903  1.05088031
H  2.49923613  0.41619280
I  3.35803048  0.09443749
J  0.70127157  0.50377219

so we can extract just the random slopes with:
coef(m0)$G['X']

            X
A -1.02364292
B  0.49626942
C -0.42268395
D  3.20054211
E  0.24003270
F  0.05498340
G  1.05088031
H  0.41619280
I  0.09443749
J  0.50377219

Here we can see that some these values are all quite large in comparison to the fixed effects for X, 0.25, which is reflected in the lower p-value for the model without random effects.
In your case you will use coef(m0)$Subject['Session7days'] to get the random effects for Session7days.
So you can plot these however you feel is best.
You might want to make use of the sjPlot package which is able to produce many types of plots for mixed models:
http://www.strengejacke.de/sjPlot/reference/sjp.lmer.html
library(sjPlot)
plot_model(m0, "re")

Finally, regarding confidence intervals, you can use:
confint(m0)
Computing profile confidence intervals ...
                 2.5 %     97.5 %
.sig01       1.4228205  4.1536262
.sig02      -0.9846120 -0.7165795
.sig03       0.7068525  1.8546587
.sigma       0.7342950  1.2224067
(Intercept) -0.4881105  3.0079844
X           -0.3084231  1.2305797

Comment: Wow! That´s a really good and detailed explanation. Thank you so much Robert, I´ve learned a lot reading your answer and everything makes perfectly sense now! I would still have a few questions, because I want to be sure that we have the same opinion about the conclusion of the study.
Comment: My interpretation of the results was based on the p-value. But now that I know, that this value is not reliable for mixed models I agree with you. My research question is: "Does balance improve/EnHL increase with practice?" I wanted to analyze if there´s an improvement of balance between sessions, and within sessions (trial 16 better than trial 1). That´s the reason why I added the variable trial to the model. But from what I´ve understood it´s clear that balance doesn´nt improve between trials. (Or should I add the nested factor Session/Trial?)
Comment: What about the Sessiontraining - Session7days contrast? Day 7 is 0,03 (s) higher which is very low in terms of EnHL and as we saw from the different models there is meaningful variation between subjects in their response to Session. So we couldn´t conclude that balance improves always after 7 days. It just happened for this specific study with these specific subjects (the improvement is extremly low and it didn´t happen for all of the subjects), right?
Comment: Now I would have two questions related to your answer. 1. What do you mean with " extract the random effects themselves for these variables and visualise them, particularly with respect to the fixed effects for them". Create a new model? If so could you please write it down?    2. Where can I find the confidence intervals? Should I use another function or are they in the summary?   Thank you again for your help
Comment: You're welcome. Thanks for the further info. So I would retain `Trial` in the model since it's part of your research question. As for Session, there is an expectation of a 0.03 higher outcome between session 1 and sessions 7 *on average* but like you say it some subjects probably had a reduction not an increase. We will be able to see that after extracing the random effects.  I will edit the question to see how to do that.
Comment: Alright, thanks! I've edited my question and added the table and the plot with the extracted random effects.


Trilateration with unknown fixed points

Question: I am able to measure my distance to a set of (about 6 or 7) fixed but unknown points from many positions.
The difference in position between measurements is also unknown.
I believe that I should be able to work out the relative position of the fixed points, and therefore where I measured from and the path I took.
I have looked at the wiki page for trilateration, but it only gives examples working from known points.
Any help?
Comment: Let's say the distances are 1,2,3,4,5,6. Now construct the following sets of points in $\mathbb{R}^2$: you are on position $(0,0)$, the next point is on position $(1,0)$, the next one on position $(2,0)$, etc... on the other hand, the following is also compatible with your distances: $(0,0),(0,1),(2,0),(0,3),(4,0),(0,5),(6,0)$. See?
Comment: I understand that, but it doesn't get me any closer to a solution. I will need to use differences in the distance sets of two or more readings.
Answer: For each distance measured, you can write an equation for the distance between that point on your path and that fixed point, both of which are unknown.  In two dimensions (on a flat plane), each unknown point has two unknown coordinates.  If you have $n$ fixed points and you measure from $k$ points on your path, you will have $nk$ distances and equations and $2n+2k$ unknowns.  As long as $nk\ge 2n+2k$, this should yield a system that can be solved (if the distances are exact), but it probably helps to have $nk$ be more than $2n+2k$ because the system when $nk=2n+2k$ might have multiple solutions (because the equations are nonlinear).  (If you are working in three dimensions, then $2n+2k$ changes to $3n+3k$.)
Comment: Since the whole setup is invariant under isometric transformations, there are three degrees of freedom which you can't conclude from the variables. Fixing them in an arbitrary way corresponds to an arbitrary choice of coordinate system. It makes sense to think of these three degrees of freedom as origin and orientation of the coordinate system. [This newer question](http://math.stackexchange.com/q/972462/35416) referenced the one here, which is how I noticed your answer.
Answer: I'm elaborating on the answer Isaac already gave, so I'll adopt his notation. I'm posting a second answer to elaborate the point of isometric transformations, but also because the question has been asked again and the author of that newer question found the existing answer insufficient.
Suppose you have $n$ fixed points and perform $k$ distance measurements to all of these, taken from different points. Also suppose that you are working on the plane, although the ideas can be easily generalized to 3D space. Let's assume the fixed point with index $i$ is at position $(a_i,b_i)$ and the measurements with index $j$ were taken from position $(x_j,y_j)$, then the equations are of the form
$$(a_i-x_j)^2 + (b_i-y_j)^2 = d_{ij}^2$$
where $d_{ij}$ is the distance you measured to fixed point $i$ from position $j$ along the trajectory. So you have $2n$ variables $a_i,b_i$ and $2k$ variables $x_i,y_i$ together with $n\cdot k$ equations.
But the whole setup is invariant under isometric transformations. Which means you can't know the origin or orientation of your coordinate system since that coordinate system is completely arbitrary. Therefore you might simply fix some coordinate system, by choosing $x_1=y_1=y_2=0$. So the origin of the coordinate system is defined as your starting point, and the $x$ axis of the coordinate system is the direction from the first to the second point of your trajectory. This adds three more equations. (If you were operating in 3D instead of 2D, then you'd end up with 6 parameters you may choose arbitrarily, three for position and three for orientation.)
A system of $n\cdot k+3$ equations with $2n+2k$ will often have a finite number of solutions if $2n+2k=n\cdot k+3$. At least if the equations are sufficiently independent. If the equations were linear, that solution would be unique, but as the equations are non-linear, there may be multiple solutions. If you have more than the required number of equations, that might help you pick one of these. I'll not discuss techniques of how to solve systems on non-linear polynomial equations, but I suggest you let some computer algebra system or some numerical tool designed for the task handle that.
Of course, if you have more equations than absolutely required, and if your measurements are subject to some error (measurement error, rounding error, …) then you may end up with no matching solution at all. So you'll want the solution which is closest to your measurements, even though it doesn't exactly reproduce the observed measurements. This would place the problem in the domain of unconstrained non-linear optimization. You'd definitely want to tackle this numerically, and would be well advised to use a tool designed for that task.
Comment: @jp36: When you have errors, "solving" is the wrong term, "approximating" and "optimizing" would fit. You'd try to minimize $$\sum_{i=1}^n\sum_{j=1}^k\left((a_i-x_j)^2+(b_i-y_j)^2-d_{ij}^2\right)^2$$ (at least in a least squares approximation) to find the solution which best matches your obervations.
Comment: @jp36: If you have $n=3$ fixed points (which is the absolute minimum), then $2n+2k=nk+3$ simplifies to $k=3$, so you need to measure distances from three different positions. For larger $n$ the resulting $k$ will be not an integer, so you'd round that up and will end up in the case of "more equations than absolutely required". The distance between the first two points, $x_2$, is just one of the variables of your system of equations; you don't neccessarily have to determine that before the others.
Comment: Ok, trying to make sure I understand this. In a situation with perfect measurements this requires at least two sets of (x,y)'s to determine the arbitrary positions of each (a,b)? and if you say x1=y1=y2=0 then you must know the x2 (the distance between the first two points) before you can calculate all of the (a,b) positions? So essentially you must use some other method to get the distance from the first location change, then can use the systems of equations to calculate future location changes?
Comment: Also, there will be measurement/calculation error. So when you say I want to tackle this numerically does that mean I'd still set up the same system of equations but I'd use a numerical solver tool to determine the solution instead of some simple solving method?
Comment: You mention using a tool designed for this task, I assume you mean something like matlab. I am trying to program this and thus I need some library or algorithm to use. I am having trouble finding finding what to use as I only have a high level understanding of most of this. I have been searching using key words such as "least squares approximation" and "unconstrained non-linear optimization". Does (http://en.wikipedia.org/wiki/NEWUOA) seem like something that would be appropriate to use? Or should I be looking for libraries that handle "non-linear programming." Sorry for my ignorance.
Comment: Or possibly something like  (http://people.sc.fsu.edu/~jburkardt/f77_src/uncmin/uncmin.html)? To clarify, I'm not asking you about the coding or anything, just if the description of what NEWUOA and UNCMIN say they do sounds like what I would need to solve this system of equations properly.
Comment: @jp36: I've never used or even heard of either of these before, butat a very quick glance they sound good. I guess I'd be using some interior point method from [COIN OR](http://www.coin-or.org/), simply because I had used their LP sover in the past.
Comment: I have ended up with the same problem as above, and have been struggling to think of a method for optimising a solution. In my case $i$ is large (10s of thousands potentially) and $j$ is small (e.g. 4). The quadratic programming tools all tend to have high computational complexity, and so I was wondering about a statistical method for an approximation.

(I've realised I can drop the degrees of freedom of the solution by defining an orthonormal coordinate system along $x_j x_{j+1}$)
Comment: @MvG, why do you recommended to use a tool? With noisy measurements, can't we start from the cost function you mentioned in a comment above and then determine the equations of [non-linear least squares](https://en.wikipedia.org/wiki/Non-linear_least_squares) to compute iteratively the Jacobian matrix and the solution?
Comment: @DanielleMadeley, how did you solve your problem at the end?
Comment: @James ahh I didn't, not in any convincing way as I realised I had much bigger problems related to actually collecting the data.

Trilateration with unknown fixed points


Contest math problem algebra proof

Question: Let $r, s$ be integers and let
$$a = (2011)^2 + (2011)r + s$$ and
$$b = (2012)^2 + (2012)r + s$$
Show that there exists an integer $c$ with $c^2 + rc + s = ab$.
Can anyone help me with this?
Comment: My answer concluded that the 2011 and 2012 does not matter and it could be anything as long as they are t and t+1.  Is the consensus that that is true?
Answer: The quadratic equation $c^2+rc+s-ab=0$ has two solutions, namely
$$
c=(2011r+s+2011\cdot 2012),
$$
or
$$
c=-(2012r + s + 2011\cdot 2012)
$$
And indeed, with this choice of $c$ it works.
Answer: $$a=t^2+rt+s$$
$$b=(t+1)^2+r(t+1)+s=t^2+2t+1+rt+r+s$$
$$ab = c^2+cr+s=(t^2+rt+s)(t^2+2t+1+rt+r+s) = a(a+2t+1+r)$$
$$c = 1/2(\sqrt{r^2-4s+4ab}-r)$$
c is an integer iff $r^2-4s+4ab$ is a perfect square and $\sqrt{r^2-4s+4ab}-r$ is even
$$r^2-4s+4ab = r^2+4a^2+8at+4a+4ar-4s$$
substiting back in a yields
$$r^2-4s+4ab = (2rt+r+2s+2t^2+2t)^2$$
note that the $\sqrt{r^2-4s+4ab}-r = 2(rt+s+t^2+t)$
Comment: Could you tell me a bit more about how you simplified the fifth equation after substituting a?
Comment: I assumed that r,2s,and $2t^2$ would be parts of the number that would appear under the exponent in equation 5 due to the presence of r^2, 4s^2, and 4t^4. I then expanded $(r+2s+2t^2+2k)^2$ to solve for k, got bored, and finished it on wolfram alpha.
Answer: Subtracting the first equation from the second, we have
$r = b-a-2012^2+2011^2 = b-a - (2012+2011) = (b-2012) + (-a-2011)$
Multiplying the first equation by $2012$, the second by $2011$ and subtracting, we have
$s = 2012a - 2011b - 2012\cdot 2011^2 + 2011\cdot 2012^2 = 2012a - 2011b + 2011\cdot 2012$
So $s - ab = -ab + 2012a - 2011b + 2011\cdot 2012 = (b-2012)\cdot(-a-2011)$
Thus we have clear choices for the sum and product of the roots of $c^2 + rx + s = ab$.
Answer: Choose r = 2 and s = 1
Then $2011^2 + 2.2011 + 1 = a$
and  $2012^2 + 2.2012 + 1 = b$
$a = (2011 + 1)^2$
$b = (2012 + 1)^2$
$ab = (2012.2013)^2$
Let 2012 = u
$ab = (u(u+1))^2$
$ab = u^4 + 2u^3 + u^2$
Let $c = au^2+bu+l$
$ab = (au^2+bu+l)^2 + (au^2 + bu +l)*2 + 1$
$a^2u^4 + b^2u^2+l^2+2(au^2bu+2bul+alu^2)+2au^2+2bu+2c+1$
$a^2u^4+2abu^3+u^2(b^2+2al+2a)+(2bl+2b)u+l^2+2l+1$
Expanding the expression
$a^2 = 1 > a = 1$
$2ab = 2 > b = 1$
$b^2 + 2al + 2a = 1 > l = -1$
Thus $c = (u^2 + u -1)$ which is an integer as u is an integer
Goes to prove that $ab = c^2 + c*2 + 1$ holds true for an integer c.
Thanks
Satish

Contest math problem algebra proof


PHP - Converter string em int

Question: Estou tentando converter a string '450.000,00' em int para inserir no banco de dados. Porém quando faço cast ou uso intval(), o valor retornado vai para 450 apenas. No caso eu preciso do 450.000.
Qual outra forma poderia fazer isso?
Comment: Primeiro você precisa remover os pontos, em seguida trocar vírgula por ponto, e só então converter.
Comment: amo php por isso number_format($numero, '2', '', ''); testa ai
Answer: Sem delongas a solução mais porca e útil:
$number = "450.000,00";
$numbers = explode(',', $number);
$numberss = explode('.', $numbers[0]);
$string = $numberss[0].$numberss[1].$numbers[1];

Comment: Votei -1 porque a solução é realmente ruim. Faz `explode` de forma desnecessária e basicamente só funciona para o exemplo apresentado na pergunta. Se a entrada fosse `"450000,00"` ou `"1.450.000,00"` não iria mais funcionar.
Comment: "Porca" eu não classificaria, mas é inútil.
Comment: haha, deixa ai a questão é duplicada achei um monte de solução!

PHP - Converter string em int


Strip parsed html text from html comments using AngleSharp

Question: I use the code below to strip specific html tags from parsed html using AngleSharp (as it is recommendable over using regular expressions to do such jobs (AngleSharp is currently maintained, HtmlAgilityPack not, hence I have been moving to the latter).
It works great - but now I want to remove html comments as well. Meaning whatever is found between  tags.
How would this be achieved using AngleSharp ? Using QuerySelector does not seem suiting here.
private string ExtractContentFromHtml(string input)
{
    List<string> tagsToRemove = new List<string>
    {
        "script",
        "style",
        "img"
    };

    var config = Configuration.Default.WithJavaScript();

    HtmlParser hp = new HtmlParser(config);
    List<IElement> tags = new List<IElement>();
    List<string> nodeTypes = new List<string>();
    var hpResult = hp.Parse(input);

    try
    {
        foreach (var tagToRemove in tagsToRemove)
            tags.AddRange(hpResult.QuerySelectorAll(tagToRemove));

        foreach (var tag in tags)
            tag.Remove();
    }
    catch (Exception ex)
    {
        _errors.Add(string.Format("Error in cleaning html. {0}", ex.Message));
    }

    var content = hpResult.QuerySelector("body");

    return (content).InnerHtml;
}

Answer: After playing with the code above and AngleSharp's API, I came up with the following working solution.
Initially I thought I could replace all my tag-removing stuff and solely rely on treating text nodes only, but this is not recommendable,
since some text nodes will be generated on the fly via javascript code, meaning, you need to remove javascript nodes anyway. So I left the style + img removals as well.
Worth mentioning as well that the DOM classifies nodes according to types, and one is able to find comments by searching for nodes of type 8.
private string ExtractContentFromHtml(string input)
{
    List<string> tagsToRemove = new List<string>
    {
        "script",
        "style",
        "img"
    };

    var config = Configuration.Default.WithJavaScript();

    HtmlParser hp = new HtmlParser(config);
    List<IElement> tags = new List<IElement>();
    List<string> nodeTypes = new List<string>();
    var hpResult = hp.Parse(input);

    List<string> textNodesValues = new List<string>();
    try
    {
        foreach (var tagToRemove in tagsToRemove)
            tags.AddRange(hpResult.QuerySelectorAll(tagToRemove));

        foreach (var tag in tags)
            tag.Remove();

/*
   the following will not work, because text nodes that are not immediate children will not be considered
   textNodesValues = hpResult.All.Where(n => n.NodeType == NodeType.Text).Select(n => n.TextContent).ToList();
*/

        var treeWalker = hpResult.CreateTreeWalker(hpResult, FilterSettings.Text);

        var textNode = treeWalker.ToNext();
        while (textNode != null)
        {
            textNodesValues.Add(textNode.TextContent);
            textNode = treeWalker.ToNext();
        }
    }
    catch (Exception ex)
    {
        _errors.Add(string.Format("Error in cleaning html. {0}", ex.Message));
    }

    return string.Join(" ", textNodesValues);
}


Selecting records where all joined rows match

Question: Given the following schema:
employees
id | name

employee_attributes
id | employee_id | key | value

I would like to select all employees that have the provided attributes.
The following statement works:
SELECT employees.* FROM employees
INNER JOIN employee_attributes ON employee_attributes.employee_id = employees.id
WHERE employee_attributes.key = 'foo' AND employee_attributes.value = 'bar'

but only allows me to find an employee by one attribute. How can I adapt this to retrieve employees by more than one attribute?
To be clear, if I supply two sets of attributes to match against, the query should only return employees that have at least those two attributes.
For example, if Bob has just one attribute:
key | value
===========
foo | bar

But I supply two attributes to the query (foo and bar, bin and baz), Bob should not be returned.
Answer: Use conditional aggregation:
SELECT employees.*
FROM employees
INNER JOIN employee_attributes
    ON employee_attributes.employee_id = employees.id
GROUP BY employee_attributes.employee_id
HAVING SUM(CASE WHEN employee_attributes.key = 'foo' AND
                     employee_attributes.value = 'bar' THEN 1 ELSE 0 END) > 0 AND
       SUM(CASE WHEN employee_attributes.key = 'bin' AND
                     employee_attributes.value = 'baz' THEN 1 ELSE 0 END) > 0

Comment: This would return the employees with just one key-value pair as well.
Answer: Following should work:
SELECT employees.id, employees.name, count(employee_attributes.id) as attribute_count FROM employees
INNER JOIN employee_attributes ON employee_attributes.employee_id = employees.id
WHERE (employee_attributes.key = 'foo' AND employee_attributes.value = 'bar') OR (employee_attributes.key = 'bin' AND employee_attributes.value = 'baz')
group by employees.id, employees.name
having attribute_count >= 2;

Answer: You can get the employee ids using aggregation:
SELECT ea.employee_id
FROM employee_attributes.employee_id
WHERE (ea.key = 'foo' AND ea.value = 'bar') OR
      (ea.key = 'bin' AND ea.value = 'baz')
GROUP BY ea.employee_id
HAVING COUNT(DISTINCT ea.key) = 2;

For the full information, you can use a JOIN:
SELECT e.*
FROM employee e JOIN
     (SELECT ea.employee_id
      FROM employee_attributes.employee_id
      WHERE (ea.key = 'foo' AND ea.value = 'bar') OR
            (ea.key = 'bin' AND ea.value = 'baz')
      GROUP BY ea.employee_id
      HAVING COUNT(DISTINCT ea.key) = 2
     ) ea
     ON ea.employee_id = e.id;


Finding a Clean/Overdriven Fender Tone

Question: I am trying to find this guitar tone, where it sounds solid and amped when clean, and, it seems like, when a player's hitting harder gets very nice sounding overdrive.
Like the telecaster in this video.

Everything I tried so far can't achieve this amp overdrive - it sounds too dirty, and loosy.
Could you give any advice on achieving the tone?
Comment: One problem with trying to replicate guitar tones that we hear in live shows and recordings is that it's not just the guitar, pedals, and amp we are hearing. The miking, mike preamp, and processing (compression, EQ, etc) can be a very big part of the final sound. Usually it's better to experiment with your own gear to find its best sounds.
Comment: You might get more helpful info if you describe what set up you have been using.
Comment: Two key things missing here. What pedals he might be using, and what amp/guitar/pedals you have available. It looks like he goes through a Marshall, but it ain't necessarily so. Guitarists have been known to use other amps/speakers from sponsors, but in sponsors' cabs!
Comment: Don't ask us, ask Jake. A quick search of "Jake Bugg guitar rig" turned up this, which might be informative: https://equipboard.com/pros/jake-bugg.  Also this video where he demonstrates some of his techniques: https://youtu.be/JVDFxP4XoMQ. Plenty more to discover, I'm sure.
Answer: Your start point on a vintage amp [I started on a Marshall but ended up with a Vox] is "everything on 7" & work from there.
Modern hi-gain amp you'd have to pull everything back a long way, but I never use hi-gain amps because they don't suit anything I ever play. I tried a hi-gain Marshall & it was still too fuzzy with input on 3. I quickly abandoned it - it was never going to work.
Guitar on full volume & tone.
After that it depends on your guitar's pickup output, brightness, string gauge & how hard you hit it.
Also, I'd have guessed 'front [or middle] pickup' from that sound - but he doesn't appear to have one… Pickup selector is at the back, but there's nothing visible at the front. There's no guessing what pickup that is. It looks like a standard tele/strat [& you can read the Fender on the headstock at some points in the video], but who knows. Tellys are always brighter & twangier than Strats on the back pickup anyway [strats can get a bit 'barky' on the back], which is probably what confuses my ears on that. I've never owned a real Telly.

Testing on my Variax through the different tele models, I'm finding I get closer to that sound with an old Vox AC30 with treble boost than I can with a Marshall. Gain about 7 [no numbers on a Vox] treble right up. If I recall correctly, old Voxes used to only reduce treble, not add it, which is why there's a modded model with increased top end, just nice for this sound.
As noted in comments above, the resulting sound you hear is not just 'a guitar & an amp' it's everything else between player & recording. One fun thing about modelling amps [& guitars] is you have a million things to play with. You can change the mic model, orientation & distance; change the speaker cab independently of the amp… add pedals of a myriad sorts, compressors & reverbs - lots of tweaks.
From the deleted answer/comment.
I use modelling for everything [except for one Strat]. Guitar is an original Line 6 Variax 500 from around 2004. Amps are again Line 6, Amp Farm.
I did have brief flirtations with other amp modelling structures, Guitar Rig, Amplitube etc - which were good but had various annoyances with updates sounding different or not being compatible, they also have some latency which the Line6 doesn't - so I went back to the Amp Farm.
Some might say, "Ooh, but is it quite as good as the real thing?"
Maybe not but if I can't tell the difference in the studio, no-one will by the time the track's finished.
Plus… I've got perhaps 50 grand's worth of guitars & amps for about 650 quid/bucks/euros.
Late, late edit
Further research tells me the 'single pickup tele' is actually an Esquire, precorsor to the Tele & is being made again. The pickup selector is a routing cvontrol for the tone aspects - see https://planetbotch.blogspot.com/2020/05/why-does-fender-esquire-have-pickup-selector-switch.html and
https://www.fender.com/articles/gear/70th-anniversary-esquire
Comment: Yeah, I wondered that too. Might even be a stacked humbucker in there, "quarter-pounder" style, with switching/phase options. That was part of my 'looks like a standard strat PU but can't tell by looking'. I used to have a quarter pounder in the back of my strat [fatter magnets but otherwise looked like a regular] but now have a hot rails instead, which you can tell by looking.
Comment: I'm interested to find out what the pup switch could be for...
Comment: Looks just like the bridge pup on my Tele, but you could be right. Not like a Strat pup, I think.
Comment: @Tim - I can't tell the difference between regular strat & tele rear pickups just by looking, though apparently Fender do consider them different. https://www.fender.com/articles/how-to/asked-answered-the-difference-between-strat-and-tele-bridge-pickups [well, tele pickups have three mount points, not two]
Comment: That was my thought. Not easy to mount a 2 screw  Strat pup into the Tele 'ashtray'. I guess the angles of the two differ, but that's not an issue.  Aren't most Strat pups white? (He asked naiively).
Comment: Mainly, but not always. I've a black strat with black pickups, the others are all white. With the covers off, though, they're all black.

Finding a Clean/Overdriven Fender Tone


An application of the Delta method

Question:
I have the sample $Y_{i}\overset{i.i.d}{\sim} N(0,\sigma_{y}^{2})$ of a population with normal distribution with mean $0$ and variance $\sigma_{y}^{2}$ unknown. I could also prove that $\frac{1}{n}\left(\frac{1}{n}\sum_{i=1}^{n}Y_{i}^{2}-\sigma_{y}^{2}\right)\overset{D}{\to}N(0,2\sigma^{4})$ using the CLT, but my question is:

Question: How can I find a function $f(t)$ such that the variance of the limiting distribution does not depend on the parameter of interest $\sigma_{y}^{2}$ in the sense of the Delta method: $$\sqrt{n}\left(f\left(\frac{1}{n}\sum_{i=1}^{n}Y_{n}\right)-f(\mathbb{E}X_{i})\right)\overset{D}{\to} N(0,\sigma^{2}(\mu)f'(\mu)^{2}) , \quad Y_{i}\overset{i.i.d}{\sim}N(\mu,\sigma^{2})$$

For example, I could see that $f$ might satisfy $2(f'(\sigma^{2}))^{2}\sigma^{4}$ shouldn't depend on $\sigma^{2}$.
Answer: I think there is no such $f$ in general unless there's some specifics to your problem that I'm missing.
We need $\sigma^2 f'(\mu)^2$ to not depend on $\sigma^2$. To try to formalize this, I'll interpret "not depend" to mean
$$
\frac{\partial}{\partial \sigma^2} [\sigma^2 f'(\mu)^2] = 0.
$$
In a typical Gaussian distribution $\mu$ and $\sigma^2$ are free to vary separately and neither is viewed as a function of the other, i.e. $\frac{\partial \mu}{\partial \sigma^2} = 0$. Furthermore you write $f$ and $f'$ as only functions of $\mu$, and in general I think it'd be very artificial to have them depend on $\sigma$ since then $f$ isn't a statistic, so I'll also assume that $f$ and $f'$ do not have $\sigma$ in them.
This means the derivative is just
$$
f'(\mu)^2 = 0 \implies f'(\mu) = 0 \text{ everywhere}.
$$
But functions with $f'(\mu) = 0$ are excluded from the delta method by hypothesis so there are no valid functions that satisfy our requirements here.
Comment: the function $g(x)=\ln x$ it does not work?
Comment: @АлександрПальма are you interested in functions where there is some value of $\mu$ such that the result doesn't depend on $\sigma$? I was answering if there was a function where for any $\mu$ the answer won't depend on $\sigma$. If we're allowed to choose $\mu$ then any function with $\sigma^{-1}$ in the image of its derivative would work. E.g. if we do $g(x) = x^{5/3}$ then $g'(x)^2 = \frac{25}{9}x^{4/9}$ and if we choose $\mu = \left(\frac{9}{25\sigma^2}\right)^{9/4}$ then the result won't depend on $\sigma$. But i don't think it's very interesting if we can just choose $\mu$ like that

An application of the Delta method


CSS Overflow - Bottom Assignment Issue (Bootstrap 3)

Question: My apologies for not being able to be more descriptive in the title (suggestions for editing it are welcomed...)
I have designed a Team Page made up of a grid of images. I have laid it out to be responsive in Bootstrap 3.
When the consumer clicks the 'more' tab next to the image, a hidden DIV appears below the image containing more information about that team member.
The problem that I am having is that the DIV that appears shows all of the content of the DIV, but the background color (and another DIV that serves as a close button) stops at the bottom of the row directly beneath the row that was clicked on.
http://jsfiddle.net/LL39h/

Jane DoeJob Title

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam molestie dui vitae libero pellentesque, quis accumsan enim tincidunt. Nam porta felis ipsum, nec vehicula massa placerat feugiat. Etiam at erat et neque fermentum accumsan. Nulla sit amet augue pellentesque, condimentum diam eget, vestibulum eros.

Nam fermentum eros non turpis suscipit fermentum. Aenean vitae convallis eros. Aliquam lorem odio, pulvinar nec interdum at, laoreet vitae enim.

firstname.lastname@example.com

+1.555.555.5555

Jane DoeJob Title

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam molestie dui vitae libero pellentesque, quis accumsan enim tincidunt. Nam porta felis ipsum, nec vehicula massa placerat feugiat. Etiam at erat et neque fermentum accumsan. Nulla sit amet augue pellentesque, condimentum diam eget, vestibulum eros.

Nam fermentum eros non turpis suscipit fermentum. Aenean vitae convallis eros. Aliquam lorem odio, pulvinar nec interdum at, laoreet vitae enim.

firstname.lastname@example.com

+1.555.555.5555

Jane DoeJob Title

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam molestie dui vitae libero pellentesque, quis accumsan enim tincidunt. Nam porta felis ipsum, nec vehicula massa placerat feugiat. Etiam at erat et neque fermentum accumsan. Nulla sit amet augue pellentesque, condimentum diam eget, vestibulum eros.

Nam fermentum eros non turpis suscipit fermentum. Aenean vitae convallis eros. Aliquam lorem odio, pulvinar nec interdum at, laoreet vitae enim.

firstname.lastname@example.com

+1.555.555.5555

Jane DoeJob Title

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam molestie dui vitae libero pellentesque, quis accumsan enim tincidunt. Nam porta felis ipsum, nec vehicula massa placerat feugiat. Etiam at erat et neque fermentum accumsan. Nulla sit amet augue pellentesque, condimentum diam eget, vestibulum eros.

Nam fermentum eros non turpis suscipit fermentum. Aenean vitae convallis eros. Aliquam lorem odio, pulvinar nec interdum at, laoreet vitae enim.

firstname.lastname@example.com

+1.555.555.5555

Jane DoeJob Title

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam molestie dui vitae libero pellentesque, quis accumsan enim tincidunt. Nam porta felis ipsum, nec vehicula massa placerat feugiat. Etiam at erat et neque fermentum accumsan. Nulla sit amet augue pellentesque, condimentum diam eget, vestibulum eros.

Nam fermentum eros non turpis suscipit fermentum. Aenean vitae convallis eros. Aliquam lorem odio, pulvinar nec interdum at, laoreet vitae enim.

firstname.lastname@example.com

+1.555.555.5555

Jane DoeJob Title

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam molestie dui vitae libero pellentesque, quis accumsan enim tincidunt. Nam porta felis ipsum, nec vehicula massa placerat feugiat. Etiam at erat et neque fermentum accumsan. Nulla sit amet augue pellentesque, condimentum diam eget, vestibulum eros.

Nam fermentum eros non turpis suscipit fermentum. Aenean vitae convallis eros. Aliquam lorem odio, pulvinar nec interdum at, laoreet vitae enim.

email@example.com

+1.555.555.5555

Jane DoeJob Title

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam molestie dui vitae libero pellentesque, quis accumsan enim tincidunt. Nam porta felis ipsum, nec vehicula massa placerat feugiat. Etiam at erat et neque fermentum accumsan. Nulla sit amet augue pellentesque, condimentum diam eget, vestibulum eros.

Nam fermentum eros non turpis suscipit fermentum. Aenean vitae convallis eros. Aliquam lorem odio, pulvinar nec interdum at, laoreet vitae enim.

firstname.lastname@example.com

+1.555.555.5555

Jane DoeJob Title

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam molestie dui vitae libero pellentesque, quis accumsan enim tincidunt. Nam porta felis ipsum, nec vehicula massa placerat feugiat. Etiam at erat et neque fermentum accumsan. Nulla sit amet augue pellentesque, condimentum diam eget, vestibulum eros.

Nam fermentum eros non turpis suscipit fermentum. Aenean vitae convallis eros. Aliquam lorem odio, pulvinar nec interdum at, laoreet vitae enim.

email@example.com

+1.555.555.5555

Jane DoeJob Title

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam molestie dui vitae libero pellentesque, quis accumsan enim tincidunt. Nam porta felis ipsum, nec vehicula massa placerat feugiat. Etiam at erat et neque fermentum accumsan. Nulla sit amet augue pellentesque, condimentum diam eget, vestibulum eros.

Nam fermentum eros non turpis suscipit fermentum. Aenean vitae convallis eros. Aliquam lorem odio, pulvinar nec interdum at, laoreet vitae enim.

email@example.com

+1.555.555.5555

CSS:
#staff-page div {padding: 0px; margin: 0px; height: 190px; position: relative; overflow: visible;}

#staff-page {overflow:visible;}

.bio-show, .bio-show:hover {color: #fff; text-decoration: none;}
.moreorless {padding: 0px 30px 0px 30px;}
.moreorless:after {content: "more"; }
.bio-full .moreorless:after {content: "less"; }
.bio-hide {position:absolute; bottom: 0px; left: 0px; width: 100%; height:30px; background: #B5B5B5 url(../images/arrow-up.png) 50% 50% no-repeat;}
#overlay {position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: #000; filter:alpha(opacity=70); -moz-opacity:0.7; -khtml-opacity: 0.7; opacity: 0.7; display: none; z-index: 20;}
.zindex10 {z-index: 10;}
.zindex30 {z-index: 30;}
.clear {clear: both;}

/* For mobile screen */
#staff-page div:nth-of-type(even) {background-color: #f1f1f1; color: #333;}
#staff-page div:nth-of-type(odd) {background-color: #ECA833; color: #fff;}
#staff-page img {float: left;}
#staff-page h3 {float:left; margin:0; padding:0; font-size:18px; font-variant:small-caps; text-transform:lowercase; position:relative; top:80px; left:20px;}
#staff-page h3 strong {display:block; font-size:16px; font-weight:normal; font-variant:normal; text-transform:none;}
#staff-page .bio-show {display:block; position: absolute; width:95px; height:30px; top:160px; left: 190px; background:#D75401 url(../images/arrow-down.png) 10px 55% no-repeat; line-height: 30px;}
#staff-page .bio {padding: 30px; display: none; clear: both; background: inherit; color: inherit; position: relative; overflow: visible;}
#staff-page .bio-full {background:#b5b5b5 url(../images/arrow-up.png) 73px 55% no-repeat!important;}
#staff-page div:nth-of-type(even) img {float: right;}
#staff-page div:nth-of-type(even) h3 {float: right; right:20px; left:auto; text-align: right;}
#staff-page div:nth-of-type(even) .bio-show {display: block; right:190px; left: auto; background:#D75401 url(../images/arrow-down.png) 73px 55% no-repeat; text-align: right;}

/* For medium/small screen */
@media (min-width: 768px) {
    /*evens*/
    #staff-page  div:nth-of-type(4n), #staff-page  div:nth-of-type(4n-1) {background: #f1f1f1; color: #333;}
    #staff-page  div:nth-of-type(4n) img, #staff-page  div:nth-of-type(4n-1) img {float: right;}
    #staff-page  div:nth-of-type(4n) h3, #staff-page  div:nth-of-type(4n-1) h3 {float:right; right:20px; left: auto; text-align: right}
    #staff-page  div:nth-of-type(4n).bio-show, #staff-page  div:nth-of-type(4n-1) .bio-show {right: 190px; left: auto; background:#D75401 url(../images/arrow-down.png) 10px 55% no-repeat;}
    /*odds*/
    #staff-page  div:nth-of-type(4n-2), #staff-page  div:nth-of-type(4n-3) {background: #ECA833; color: #fff;}
    #staff-page  div:nth-of-type(4n-2) img, #staff-page  div:nth-of-type(4n-3) img {float: left;}
    #staff-page  div:nth-of-type(4n-2) h3, #staff-page  div:nth-of-type(4n-3) h3 {float:left; left:20px; text-align: left;}
    #staff-page  div:nth-of-type(4n-2) .bio-show, #staff-page  div:nth-of-type(4n-3) .bio-show {left: 190px; background:#D75401 url(../images/arrow-down.png) 10px 55% no-repeat;}
}

/* For large screen */
@media (min-width: 992px) {
    /*evens*/
    #staff-page  div:nth-of-type(6n), #staff-page  div:nth-of-type(6n-1), #staff-page  div:nth-of-type(6n-2) {background: #f1f1f1; color: #333;}
    #staff-page  div:nth-of-type(6n) img, #staff-page  div:nth-of-type(6n-1) img, #staff-page  div:nth-of-type(6n-2) img {float: right;}
    #staff-page  div:nth-of-type(6n) h3, #staff-page  div:nth-of-type(6n-1) h3, #staff-page  div:nth-of-type(6n-2) h3 {float:right; right:20px; left: auto; text-align: right}
    #staff-page  div:nth-of-type(6n) .bio-show, #staff-page  div:nth-of-type(6n-1) .bio-show, #staff-page  div:nth-of-type(6n-2) .bio-show {right: 190px; left: auto; background:#D75401 url(../images/arrow-down.png) 10px 55% no-repeat;}
    /*odds*/
    #staff-page  div:nth-of-type(6n-3), #staff-page  div:nth-of-type(6n-4), #staff-page  div:nth-of-type(6n-5) {background: #ECA833; color: #fff;}
    #staff-page  div:nth-of-type(6n-3) img, #staff-page  div:nth-of-type(6n-4) img, #staff-page  div:nth-of-type(6n-5) img {float: left;}
    #staff-page  div:nth-of-type(6n-3) h3, #staff-page  div:nth-of-type(6n-4) h3, #staff-page  div:nth-of-type(6n-5) h3 {float:left; left:20px; text-align: left;}
    #staff-page  div:nth-of-type(6n-3) .bio-show, #staff-page  div:nth-of-type(6n-4) .bio-show, #staff-page  div:nth-of-type(6n-5) .bio-show {left: 190px; background:#D75401 url(../images/arrow-down.png) 10px 55% no-repeat;}
}

Thanks in advance. This one really has me stumped.
Comment: .bio {height:auto!important;} this fixes the issue at hand. It's best to put the code in your question. There's likely a height somewhere else, but this fixes the issue.
Answer: .bio {height:auto!important;}

DEMO: http://jsfiddle.net/LL39h/2/
There's something in your current css adding a height because it doesn't work without the !important.
Comment: That was exactly it. There was a nested div style. Thank you so much. Sometimes you look at things far too long to see something obvious.


Matrices that invert themselves when raised to the $n$-th power

Question: I'm trying to prove or disprove that if a matrix has the property
$$\begin{bmatrix}a & b\\c & d\end{bmatrix}^n=\begin{bmatrix}1 & 0\\0 & 1\end{bmatrix}$$
then
$$\begin{bmatrix}a & c\\b & d\end{bmatrix}^n=\begin{bmatrix}1 & 0\\0 & 1\end{bmatrix}$$
This problem isn't really about matrices, it's just method of proving something different about the iteration of rational functions. I don't know that much about matrices, so is there some property about multiplying transposed matrices that would make this any easier?
Comment: Hint: $(AB)^T=B^TA^T$.
Comment: See the third property [here](https://en.wikipedia.org/wiki/Transpose#Properties).
Comment: Assuming the matrix name is $M$, It means for example that $M^{n-1} = M^{-1}$. That $M^{-1}$ must exist is a prerequisite for that, but I think it is quite easily proven that it must exist for $M^n = I$ to hold.
Comment: Ok, thanks, I got it now.
Comment: Some related posts:
[Matrix chain multiplication with transpose: $(A^n)^T = (A^T)^n$](https://math.stackexchange.com/q/2054069) and
[Properties of a transpose: $(A^n)^T = (A^T)^n$ and $(A^T)^{-1}=(A^{-1})^T$](https://math.stackexchange.com/q/1170866)
Answer: This was essentially answered in comments (and judging by this comment, the answer was satisfactory for the OP). I'll summarize this in a CW-answer so that the question does not remain unanswered.
We will use this property of a transpose of a matrix:
$$A^TB^T=(BA)^T\tag{1}.$$
It is not difficult to show this directly from the definition of matrix product. (Probably there are also several posts with a proof on this site. I was able to find relatively quickly
Prove $A^tB^t = (BA)^t$ and
Assistance with proof of $(AB)^T=B^T A^T$.)
Using $(1)$ we get $$(A^n)^T = (A^T)^n$$ by induction.
In particular, if $A^n=I$, then $(A^T)^n = I^T = I$.


Book request: PDE's in Mathematical Finance

Question: Background:
I am an undergraduate maths student and I am tasked with writing a 10 page essay on a mathematical topic outside of what we studied yet, so something new and perhaps more advanced. The whole point of the essay is to get a student to learn about something new on his/her own by consulting various books.
Since my future interest lies in mathematical finance and since I enjoy Partial Differential Equations; I thought about choosing a topic concerning PDE's in finance. I have taken ODE's and PDE's undergraduate courses.
Aim: I would like to explore Brownian Motion, Black-Scholes Equation and topics such as Option Pricing and if I am not wrong I would have to learn about Stochastic Partial Differential Equations.
-How should I delve into this field? The issue I am having is that I do not really know which  areas of maths I actually have to learn in order to explore the above. Book recommendations would be helpful.
Thank you
Comment: I would think (I could be wrong) that as an undergraduate, you would have difficulty understanding and learning stochastic PDEs in a short space of time especially if you have only taken undergraduate ODEs and PDEs courses.
Comment: @Mattos I understand that I cannot really learn stochastic PDE's thoroughly. Although what I am looking for is at least some part so I can discuss some topic(s) related to finance. Ordinary PDE's would also suffice but I am not sure if I can discuss them in financial topics without SPDE's...
Comment: There's also HJB equations and optimal control theory, a quite "natural" link to finance
Answer: For books on SPDEs in general you can look at this question. There is also my faviorite book on SPDEs, namely PDE and Martingale Methods in Option Pricing by Pasucci. I think it is exactly the book you are looking for. It is carefully explaining everything you'll need later to investigate SPDEs in mathematical finance. The Black-Scholes model is thoroughly discussed and many more market models. There are also numerical methods.
Otherwise if you want to focus more on ODEs I'd recommend Stochastic Differential Equations by Oksendal. Here, also all concepts are introduced in mathematically rigoros sense and in the last chapter several applications in mathematical finance are discussed, e.g. in option pricing.


Controller recebendo parametro array como null

Question: Estou fazendo uma requisição AJAX, mas não consigo passar array...
Minha controller está assim:
<code>[Route("imoveis/BuscaDados/Json/Listas/ListaQuartos")]
    public JsonResult ListaQuartos(int idEstado, int idCidade, int[] idsBairros, int[] idStatus)
    {
        RealizaBuscaListas.BuscaNumQuartos(idEstado, idCidade, idsBairros.ToList(), IdsStatus);
        return Json(RealizaBuscaListas.ListaDeQuartos, JsonRequestBehavior.AllowGet);
    }
</code>
E minha função javascript assim:
<code>function preencheQuartos(Destino) {
var idEstado = 0;
var idCidade = 0;
var idsBairros = [];
idsBairros[0] = 1
idsBairros[1] = 2
var idStatus = [0];
Url = baseUrl + "imoveis/BuscaDados/Json/Listas/ListaQuartos/";
$.ajax({
    method: "GET",
    url: Url,
    data: { idEstado: idEstado, idCidade: idCidade, idsBairros: idsBairros, idStatus: idStatus },
    success: function (data) {
        $.each(data, function (i, quarto) {
            Faz coisas...
        });
    },
    error: function (data) {
        alert("Falha! Não foi possível retornar os números de quartos, tente novamente.");
    }
});
}
</code>
Porém ao inspecionar a action, percebo que os parametros int[] idsBairros e int[] idStatus sempre chegam nulos.
Será que terei que montar a url inteira com um looping para cada item dos arrays?
Comment: Já tentou mudar o tipo do parâmetro somente pra testes? Tenta mudar pra object e vê se envia certo. Ou tenta soltar um stringfy no array antes de enviar...
Answer: Consegui resolver adicionando à reuisição o traditional:true,
<code>$.ajax({
    method: "GET",
    url: Url,
    traditional:true,
    data: { idEstado: idEstado, idCidade: idCidade, idsBairros: idsBairros, idStatus: idStatus },
</code>


Choosing between multi-module and single-module design

Question: What are the differences between multi-module and single-module software architectures? What are the advantages and disadvantages of each? When should each one be used, and why?
Comment: Please don't write answers in question bodies. Instead, move your answer into an answer. That way, people can vote on the quality of the question and and answer separately, and you can eventually accept the answer.
Comment: Ok thanks, for future. I am a new user.
Comment: Not a problem, I understand. Although you can make that edit now; you don't have to wait for next time. Or I could make it for you.
Comment: I think I need your help because
Oops! Your answer couldn't be submitted because:

Users with less than 100 reputation can't answer their own question for 8 hours after asking. You may self-answer in 7 hours. Until then please use comments, or edit your question instead.

Thanks
Comment: Oh, right, that was a feature they put in to prevent people from using answers incorrectly. I can do it. Also, have an upvote and five "learning how to use the site" reputation points.
Answer: The main advantage using multiple modules is that you can re-use them, whereas single modules often contain multiple functionalities, not necesarilly related to each other, and are impractical for reuse. This depends on the size of the project, but for large projects multiple modules bring more advantages.
Multiple modules also provide an easier to update and change system. If you find a bug, you'd only need to update the module containing the bug, not the whole system.
Compile time is also better for a system with more modules as not necesarilly all of them need to be compiled for small changes (of course, with a smart enough compiler this shouldn't be a problem for single-module programs either).
Testing is another issue - testing smaller modules can decrease the number of bugs as they can be pinpointed to their specific module.
As for disadvantages, multiple modules can be harder to maintain; if they exist in a large number and aren't documented well enough, following dependencies can also be a tedious task.
Again, this depends on the size of the project.
Answer: Note: this answer was originally posted by the OP as a self-answer in the question body due to the eight-hour self-answer restriction for new users.
From http://www.jetbrains.com/idea/webhelp/project.html:

Depending on the logical and functional requirements to the project, you can create a single-module or a multi-module project.

A single-module project is most suitable for developing simple applications.
A multi-module project is used for complex tasks:

Creating a complicated logical structure.
Providing separate output for the various parts of the project, for example, deploying multiple JAR files.
Providing different SDKs for the various parts of the project.

Multi-module projects give you important advantages. Breaking your project into a number of independent modules, you can:

Reuse and share modules between projects, which can be useful for the collections of utility classes.
Build and test modules separately.
Keep each module under its own version control.

Project structure is initially defined on project creation, and can be modified. For example, you can create a single-module project and later add more modules.


Pipe file disappears but still works

Question: I have 2 programs, both written in Java. The first launches several instances of the second and then communicates with them via pipe files. When running 2 instances of the program, (I'll call the launcher A and the others B and C) everything works fine. The pipe files are in /tmp/[pid of A]/B and /tmp[pid of A]/C. If B or C close then other should keep on working, which it does except the entire /tmp/[pid of A] folder disappears.
The other program detects this and try to close itself because it shouldn't work without the pipe files.
My questions are why does it keep working if the pipe files are gone? and why do they disappear in the first place?
If C closes then A and B keep on running. The only code that runs is System.exit(0); and except for processes messages received from the pipes A doesn't do anything.
EDIT:
As per request the code that creates the directory and pipes.
File dir = new File("/tmp/" + pid);
dir.mkdirs();

File aDir = new File(dir, "A");
aDir.mkdirs();

File bDir = new File(dir, "B");
bDir.mkdirs();

Runtime.getRuntime().exec(new String[] {"mkfifo", PIPE_NAME}, null, aDir);
Runtime.getRuntime().exec(new String[] {"mkfifo", PIPE_NAME}, null, bDir);

The actual code is a little more complex but that is the basic idea.
When the program closes.
frame.addWindowListener(new WindowAdapter() {
  public void windowClosing(WindowEvent e) {
    System.exit(0);
  }
});

Reading and writing the threads is done in its own thread treating it as a normal file using BufferedReader and BufferedWriter objects.
Comment: As far as the delete goes, it's got to be somewhere in your code. You make the pipes using an OS command, so they aren't tied to the JVM execution. I recommend grepping for "delete" and "rm".
Comment: You should post some code on *how* you created the temporary files and "[pid of a]" directory.
Comment: You need to post code. And what do you mean by "pipe files"? The way you describe them, you're not using a shell pipe or an OS pipe. Show the exact code that you use to create these files, and the exact code that you run when B or C shut down.
Comment: Just thought I would check that A wasn't doing anything when C closed. I ran A in the debugger and after starting B and C paused all running threads in A and then closed C. Same thing happened.
Comment: Found it, there was a shutdown hook hiding away that deleted everything. I feel stupid now. Still, I know why it was working after they were deleted so not a total waste.
Answer: I can't answer why the pipe file gets deleted, not enough information.
I can answer why the program still works. In unix, deleting the name of a file from a directory does not delete the file. The file is only deleted when no more directory entries exist and the file isn't in use by a program.
Answer: In unix, the kernel keeps a reference count on all open files - if you open a file, that reference count increases, and when you close that file it decreases.  The file structure in the kernel remains valid until the reference count drops to 0.  Removing the pipe from the file system prevents new processes from opening the file, but processes that have the file open already can continue to use it, unaffected by the files deletion.

Pipe file disappears but still works


Connecting SAS tape unit to existing P410 controller in HP Proliant ML330-G6 under VMware ESXi 4.1

Question: I have an HP ML330-G6 server with a single SAS/SATA drive bay unit containing a pair of mirrored 250GB SATA disks, running off a P410 SAS controller - all working fine. Now I have just fitted an Ultrium 1760 SAS tape unit into the server and I can't get both the tape and the disks recognised under VMware.
So far I have tried two SAS configurations:

Disk unit on one port of the P410 + tape unit on the other port using its provided cable
Disk unit + tape unit on the SAS splitter cable supplied with the tape unit - tried on port 1 and port 2 of the P410 controller

If I use the Array Configuration Utilities for the server it always shows that I have a tape unit + disks attached, but VMware stubbornly only shows the tape unit.
I have tried generic ESXi 4.1 and also the 'HP tweaked' version.
Any relevant words of wisdom appreciated. Thanks.
Answer: I'd give the Ultrium drive a dedicated 1-port internal SAS controller and skip trying to to leverage the existing P410 controller. This way, you can do passthrough SCSI to an individual VM (assuming your backup software will be running in a VM).
Comment: Yep, that's our bailout option. I found a thread in the VMware forums where a person's problems with a P410 went away when the tape unit was moved elsewhere.
Comment: Running the tapes off of Smart Array controllers never worked well for me. In Linux, you can rescan for devices at the command line. Maybe it applies in ESXi... http://www.cyberciti.biz/faq/rhel-centos-redhat-debian-rescan-hp-smart-array/


Mysql on Windows XP on VirtualBox very slow

Question: For flyway (http://code.google.com/p/flyway) CI integration tests on Jenkins (Ubuntu) we use a Windows XP image on VirtualBox 4.1 on which the the supported DBs (DB2, MySQL, PostgreSQL, Oracle, SQLServer) are installed. Everything works fine and we connect via virtualbox port forwarding feature to the DBs on the virtual machine.
But only for MySQL the simple test's run extremely slow (minutes instead of several seconds) and we had to raise the timeout to get them green.
The tests are running fast if a local MySQL instance is used.
Does anybody have an idea what may be the reason for this, or how we can track/analyze the problem?
Greets Chris
Comment: Did you solve this? Was the VM 64bit?
Answer:
Are the tables in the same format (MyISAM, InnoDB etc.) on both host and guest?
Do you have same indexes on tables created on both machines? Try running EXPLAIN <query> in mysql console to see and compare the results, especially if both queries use same indexes and in the same order.
Do you use subqueries? They tend to be very slow at times. In case of subqueries, try to rewrite them using JOINs.
See the configuration files (my.ini / my.cnf) and check if the settings are the same. Look especially at temporary tables / buffers sizes and that kind of things. There might be the case that MySQL has small amount of memory available.


Como fazer requisições GET e POST no android, com uma ferramenta rápida e atualizada?

Question: Eu estou atualmente utilizando o volley para requisições web. Mas estou achando essa ferramenta muito lenta.
Pesquisei no google procurando por alternativas, mas todos resultados que encontro são antigos, de 2017, 2016 pra baixo.
Sobre o org.apache.http Dizem estar obsoleto, entre outras também obsoletas.
Encontrei pouca informação sobre o Gson e pelo que entendi, acho que nem faz requisições web.
Tem gente que fala do Retrofit e Retrofit 2, que não testei ainda.
Mas afinal, agora no ano de 2018, qual esta sendo o melhor modo de fazer isto? Existe um modo de utilizar as ferramentas nativas do android studio sem instalar nenhuma biblioteca e que não esteja obsoleta?
Desculpem não postar nenhum código, como eu disse não gostei do volley por ser muito lento. Então gostaria mesmo de uma ajuda sobre uma ferramenta mais atualizada. Se possível alguma documentação ou tutorial para utilizar.
Se não fiz a pergunta corretamente por favor me desculpem, eu não sei outro modo de perguntar sobre isto aqui. E pra mim aqui está sendo o único lugar com profissionais que realmente entende do que falam e que poderiam me ajudar.
Estou usando o android studio 3.1.2, com minSdkVersion 15 e targetSdkVersion 27
Comment: Utilize https://developer.android.com/reference/java/net/HttpURLConnection, ela é nativa.
Comment: Discordo de algumas coisas. Resultados de 2017, 2016 não são tão antigos assim. Se a Volley está lenta, seria bom examinar em busca da causa da lentidão que pode não ser a volley em si. Quanto à biblioteca nativa, ela é muito baixo nível, sugiro no lugar dela a [OkHttp](http://square.github.io/okhttp/).
Comment: @SamantaSilva Compare uma requisição POST na OkHttp e na HttpURLConnection, a segunda tem bem mais cerimônia, tanto para montar a conexão como para ler os dados recebidos.
Comment: @SsmantaSilva Não sei se entendi bem a questão do cache. Se em celulares mais lentos ele atrapalha a performance, talvez fosse o caso de tentar desabilitar o cache. Veja aqui: [https://stackoverflow.com/questions/25333351/disable-volley-cache-management](https://stackoverflow.com/questions/25333351/disable-volley-cache-management)
Comment: @SamantaSilva "baixo nível" = mais perto da máquina, menos abstração.
Comment: Uso para projetos empresariais a `Retrofit` há alguns anos, e antes disso usava a `Volley`. Nunca tive problemas com nenhuma das duas, sempre atenderam muito bem.
Comment: [Comparação entre todas as Bibliotecas para requisição Http no android! Vá de Retrofit =)](https://stackoverflow.com/questions/16902716/comparison-of-android-networking-libraries-okhttp-retrofit-and-volley?noredirect=1&lq=1)
Comment: @SamantaSilva nunca tive problemas. Usava um Pixi 3 pra testes na minha antiga empresa e nunca passei por lentidão assim. Certeza que não era problema no backend?
Comment: Dê uma olhada aqui: https://pt.stackoverflow.com/a/173757/35406
Comment: @ValdeirPsr Obrigado, pelo que verifiquei parece que na atualização do android 6.0 eles dizem pra retornar e usar o `HttpURLConnection`. Vou tentar ver como faz o POST e GET com ele. Obrigado.
Comment: @Piovezan Creio que o volley esta muito lento por conta do sistema de cache dele. Para celulares mais velhos e conexão mais lenta ele demora muito pra dar retorno. Mesmo que eu inicie um novo projeto vazio só com ele, a resposta é muita lenta em comparação com outros aplicativos pesados que tenho instalado no meu celular. Sobre o `OkHttp` vou dar uma olhada, mas pq na sua opinião a nativa é muito baixo nível??
Comment: @Piovezan Ahh sim, isso eu imaginava, por ser uma ferramenta nativa deve precisar de muito mais linhas de código. Meu medo é mais por questão de velocidade, performance, e que funcione em todos os dispositivos, desde os mais atuais, ate os mais antigos. Sobre os codigos para o que vou fazer, irei utilizar uma só vez. Então mesmo q seja muito mais trabalhoso não é problema. Desde q funcione bem esta ótimo. Mas eu to gostando tbm do `OkHttp` que você sugeriu. Estou lendo a documentação dele aqui. Obrigadaa.
Comment: @Piovezan Ahh eu não sabia que dava pra desabilitar, mas de qualquer modo acho que irei utilizar o `OkHttp` ou `HttpURLConnection`, acho que para meu uso, estes serão bem mais leve pro aplicativo. Mas se caso futuramente eu volte a usar o volley agora eu sei que da pra desabilitar o cache, obrigada mais uma vez pela resposta
Comment: @bfavaretto Obrigada pela explicação
Comment: @LMaker Mesmo em aparelhos mais antigos e conexões lentas você nunca teve problemas com eles?? Eu estava usando o volley, e uma requisição simples para retornar dados em json de 2 linhas estava demorando mais do que receber fotos no whatsapp, navegar no facebook, ou listar arquivos do google fotos.  Eu acho que o problema da demora do volley era por conta do cache, acima tem um amigo que me ensinou como desabilitar, mas to achando o metodo nativo muito mais rápido agora e estou gostando bastante.
Comment: @LMaker Acho que não era o backend não, mudei para o `Okhttp` utilizando os mesmos links e a mesma logica de requisição, e a diferença de velocidade foi muito grande. Muito mais rápido do que o volley. Não testei com Retrofit, pq eu li a documentação e vi que o retrofit trabalha com OkHttp, então fiz direto sem precisar passar por essa biblioteca.
Comment: @AllefSousa Obrigada pela indicação, eu ja resolvi com o OkHttp, e foi muito melhor que o volley. Adoreiii.
Comment: @Viana Eu vi o seu link, sobre a comparação entre volley e retrofit eu entendi, mas não entendi o que o AnsyTask está fazendo la. Pq o AnsyTask não tem nada a ver com requisições web, não é mesmo?? pelo que entendo ele serve para execução de uma thread em segundo plano não é isso?? me corrija se eu estiver errada.  Eu utilizei o OkHttp dentro de uma AnsyTask no meu aplicativo e ameiii o resultado e a velocidade.
Answer: em build.gradle
adicione
dependencies {
    compile 'com.koushikdutta.ion:ion:2.+'
}
depois chame em sua Activity Ion.with(Context).load(url);

exemplo
public class Login extends AppCompatActivity {

private String TAG = "Login";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_identidade_digital);
    EditText   mUsuarioView  = (EditText) findViewById(R.id.mUsuarioView);
    EditText   mPasswordView  = (EditText) findViewById(R.id.mPasswordView);
    Login(mUsuarioView.getText().toString(),mPasswordView.getText().toString());
}
public void Login(String user, String senha){

    Ion.with(this).load("https://wwww.meuwebservice.com.br")
            .setBodyParameter("user", user)
            .setBodyParameter("senha", senha)
            .asJsonObject().setCallback(new FutureCallback<JsonObject>() {
        @Override
        public void onCompleted(Exception e, JsonObject result) {
            if(e != null){
               // algo deu errado
                Log.d(TAG, e.toString());
            } else if (result.get("retorno").getAsString().equals("YES")) {
               //   tudo ceto trabalhe no seu retorno pegando o resultado
                //seu metodo aqui

            }

        }
    });

}

Rede Assíncrona Android e Carregamento de Imagens
Comment: Obrigado pela resposta Maycon, você sabe me dizer o que tem nessa biblioteca que você indicou que pode ser melhor que o OkHttp?? Até agora a biblioteca "OkHttp" que foi indicado aqui na resposta, esta parecendo ser o melhor método até agora.


How to show field collection items with comma separated in views?

Question: I have profile type programmer. This profile type having a field 'field_collection' type named language.
In the field collection we have two fields

Language
Year of experience

Now I am going to create a view that will show all the users associated with that profile type(programmer). I want to add an field(language) in that view which will have all the languages with comma separated.
NOTE : I don't want to show 'year of experience' in the field, just want to show the 'language' only.
Ex : C++, PHP, JavaScript
Answer: The basic setting for fields with multiple values actually has that as default. When you are adding the field into your view click on the multiple field settings tab and it will show you the functions to do just this.


Ignore str in sum()

Question: I have a list of lists containing predominantly numeric values. I need to find the highest value, determine the index of that list it contains, and sum up all values in that list.
I have this code that works fine:
results = [[213, 124, 100],
           [123.7, 444.6, 111, 12],
           [],
           [22, 11, 100, 2],
           [-1000]]

highest, row, total = -1, 0, 0
for a, b in enumerate(results):
    for i in b:
        if i > highest:
            highest = i
            row = a
            total = sum(b)

The problem is that I need to make sure, that the algorithm does not break if one of the values is a string.
Is there a way to ignore strings in sum, or I'd need to iterate through b as well and check for strings?
Comment: You initialize highest with zero, yet your list of lists can contain negative values. If all the values turn out negative, your code erroneously returns zero.
Comment: The correct way would generally be to use a try/except, not being a str does not make something a number
Comment: Why are any of the values strings? That's usually the kind of situation where you'd *want* your program to abort with a `TypeError`, so you can notice the problem and fix it.
Comment: How does  `total = sum(b)` work? You are continually looping even if you find a higher value and calling sum every time you find one
Comment: good point @bipll, thanks!
Comment: @PadraicCunningham: Yes, I need the total for that list only where the highest value is. So it works fine.
Comment: @Zorgmorduk. You are summing the same sublist  every time  `i > highest:`
Answer: You are already iterating through b; just check each value is not a string then. But yes, when using sum you need to filter out values that are strings too, use a generator expression:
for a, b in enumerate(results):
    for i in b:
        if not isinstance(i, str) and i > highest:
            highest = i
            row = a
            total = sum(i for i in b if not isinstance(i, str))

You could inverse the test and make sure the value is an int or float instead:
for a, b in enumerate(results):
    for i in b:
        if isinstance(i, (int, float)) and i > highest:
            highest = i
            row = a
            total = sum(i for i in b if isinstance(i, (int, float)))

It'd be much better if you could ensure the lists contained only numbers up front however:
highest, row, total = 0, 0, 0
filtered_results = [[i for i in b if isinstance(i, (int, float))] for b in results]
for a, b in enumerate(filtered_results):
    for i in b:
        if i > highest:
            highest = i
            row = a
            total = sum(b)

Comment: Well, the total = sum(for i in b if not isinstance(i, str)) does not work
Comment: @Zorgmorduk, that is because it should be `sum(i for i in b if not isinstance(i, str)) `, you need the `i` at the start
Comment: @Zorgmorduk: mea culpa, typo; there was an `i` missing at the start.
Comment: Thanks for both of you! Yes, this later one works perfectly.
Answer: If you want the index and the sublist with the highest single value:
results = [[213, 124, 100],
           [123.7, 444.6, 111, 12],
           [],
           [22, 11, 100, 2],
           [-1000]]

def try_mx(x):
    try:
        return max((i for i in x[1] if isinstance(i, (int, float))))
    except ValueError:
        return float("-inf")

mx_ind = max(enumerate(results), key=try_mx)

print(mx_ind)

Which will give you the index and the sublist:
 (1, [123.7, 444.6, 111, 12])

In your own code every time if i > highest is True you call sum, sum should only be called once per sublist  if you found a higher value not every time you find a higher value.
You can use max again so you call sum only if the highest value is greater than the current highest, using python3 you can give max a default to catch your empty lists:
highest, row, total = float("-inf"), 0, 0
for a, b in enumerate(results):
    mx = max((i for i in b if isinstance(i, (int,float))), default=float("-inf"))
    if mx > highest:
        highest = mx
        row = a
        total = sum(b)

Ignore str in sum()


Jenkins Selenium Jobs not running in Parallel

Question: Trying to run 2 selenium jobs parallel in Jenkins.
When I start 1st selenium job, it is running perfectly (till 6th iteration as shown below). But when i start the 2nd job, 2nd job is running without any error, but making other job driver stopped and showing
<code>org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:10964.
</code>
If we try to run both the jobs individually, it is running perfectly without any error wrt to chromedriver/ chrome/ java version
<code>-------------------------
Jenkins Output of 1st Job
-----------------------------
09/05 10:07:55 (LaunchMaxUptimeDowntime_NC2.java:119)[methodName-Steps] - Script Execution Time in Seconds for 1 Iteration: 126
09/05 10:07:55 (LaunchMaxUptimeDowntime_NC2.java:138)[methodName-Steps] - Script WaitTime for 2 iteration to start: 54

09/05 10:09:22 (LaunchMaxUptimeDowntime_NC2.java:119)[methodName-Steps] - Script Execution Time in Seconds for 2 Iteration: 33
09/05 10:09:22 (LaunchMaxUptimeDowntime_NC2.java:138)[methodName-Steps] - Script WaitTime for 3 iteration to start: 27

09/05 10:10:21 (LaunchMaxUptimeDowntime_NC2.java:119)[methodName-Steps] - Script Execution Time in Seconds for 3 Iteration: 32
09/05 10:10:21 (LaunchMaxUptimeDowntime_NC2.java:138)[methodName-Steps] - Script WaitTime for 4 iteration to start: 28

09/05 10:11:22 (LaunchMaxUptimeDowntime_NC2.java:119)[methodName-Steps] - Script Execution Time in Seconds for 4 Iteration: 33
09/05 10:11:22 (LaunchMaxUptimeDowntime_NC2.java:138)[methodName-Steps] - Script WaitTime for 5 iteration to start: 27

09/05 10:12:21 (LaunchMaxUptimeDowntime_NC2.java:119)[methodName-Steps] - Script Execution Time in Seconds for 5 Iteration: 32
09/05 10:12:21 (LaunchMaxUptimeDowntime_NC2.java:138)[methodName-Steps] - Script WaitTime for 6 iteration to start: 28

09/05 10:13:23 (LaunchMaxUptimeDowntime_NC2.java:119)[methodName-Steps] - Script Execution Time in Seconds for 6 Iteration: 34
09/05 10:13:23 (LaunchMaxUptimeDowntime_NC2.java:138)[methodName-Steps] - Script WaitTime for 7 iteration to start: 26

09/05 10:14:12 (LaunchMaxUptimeDowntime_NC2.java:144)[methodName-Steps] - Execution is stopped because of the following reason

org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:10964
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'PRINU', ip: '192.168.0.106', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: driver.version: RemoteWebDriver
-----------------------------------------------
TestSuite
Total tests run: 1, Failures: 0, Skips: 0
Configuration Failures: 1, Skips: 1
-----------------------------------------------
</code>
Comment: Are you using grid to distribute the load?
Comment: No.. i am not using grid
Comment: I think that problem in ports, used by grid. Make sure that used ports in jobs not conflict.
Answer: I used the below code in my project before initiating the ChromeDriver
Runtime.getRuntime().exec(System.getProperty("user.dir") +    "/release/killchromedriver.bat");
It was affecting other job to stop the chromedriver. Thanks for the help!


Colouring countries by region in ggplot2 (R):

Question: I've been trying to teach myself R and have run into a problem. Apologies if it is a silly question but I can't seem to find an answer to it in other topics.
I'm trying to plot a world map. I can plot a world map with color varying by country. My code is:
library("maptools")
library("tidyverse")

data("wrld_simpl")
new_wrld <- fortify(wrld_simpl, region = "NAME")

#new_tab<-data.frame(wrld_simpl$NAME,as.character(wrld_simpl$REGION))
#colnames(new_tab)<-c("id","region_num")
#str(new_wrld)
#new_wrld<-merge(new_wrld,new_tab, by.x = "id", by.y = "id")
#new_wrld$region_num<-as.character(new_wrld$region_num)
#str(new_wrld)

gg<- ggplot(data = new_wrld, aes(x = long, y = lat, map_id = id, fill = id))+ geom_map(map = new_wrld, color = "Black")
gg<- gg + theme(panel.background = element_rect(fill = "lightblue"),
                panel.grid = element_blank(),
                legend.position = "None")
gg<- gg + xlim(-180,180) + ylim(-90,90)
gg

As you may be able to guess, in the commented out lines I'm trying to extract the region (read: continent) and merge this into my dataframe so that I can colour the map by continent rather than by country. From the output of the two calls to str() as far as I can see I am achieving this: the only difference is the addition of an eighth variable, new_wrld$region_num. But as soon as I uncomment that chunk and run the code I get the error:
Error in unit(x, default.units) : 'x' and 'units' must have length > 0

And I don't know why. My plan was then to change the "fill = id" in the ggplot() call to "fill = region_num" to produce a map with each continent shaded a different colour.
Any help would be much appreciated.
Answer: You can save the merged dataset separately, & use that to define the fill palette while keeping the original fortified dataset for the map:
new_wrld2 <- merge(new_wrld,new_tab, by.x = "id", by.y = "id")

ggplot(data = new_wrld2,
       aes(x = long, y = lat, map_id = id, fill = region_num)) +
  geom_map(map = new_wrld, color = "Black") +
  theme(panel.background = element_rect(fill = "lightblue"),
        panel.grid = element_blank(),
        legend.position = "None") +
  xlim(-180,180) + ylim(-90,90)