Correction for multiple comparisons using sum contrasts with linear regression

Question: I am computing the following model using the lme4 package in R:
score ~ expertise*(mood + condition + course) **(EDIT: + (1|participant))**

Outcome:
score / numeric (1-7)

Inputs:
expertise / factor (NOVice, expert)
condition / factor (ALOne, together)
mood / numeric (1-7)
course / factor (YES, NO)

All the factors are coded using sum contrasts. The result looks like this:
        Predictor                             b          Std.Er  df
        (Intercept)                           1.52941    0.22044 152.36196   6.938 1.07e-10 ***
        expertiseNOV                         -0.26262    0.22044 152.36196  -1.191  0.23539
        condALO                               0.02033    0.03133 710.39747   0.649  0.51666
        mood                                  0.31964    0.03153 744.54866  10.137  < 2e-16 ***
        courseYES                            -0.07763    0.10865 417.97130  -0.714  0.47533
        expertiseNOV:condALO                 -0.17815    0.03133 710.39747  -5.686 1.90e-08 ***
        expertiseNOV:mood                     0.09947    0.03153 744.54866   3.154  0.00167 **
        expertiseNOV:courseYES                0.12540    0.10865 417.97130   1.154  0.24908

If I interpret this model correctly, expertiseNOV to courseYES should be the main effects at the average level of the other predictors. Furthermore, the interaction "expertiseNOV:condALO" is for example telling me that there is a significant difference between experts and novices for the condition "alone". I now would like to know if there is also a significant difference for the condition "together". I could now reorder the factors and get the results for the following interaction: "expertiseNOV:condTOG"
Would I then need to correct my results for multiple comparisons? Or is this just the wrong way to approach this issue?
EDIT 04.10.2022
As I assigned the contrast schemes manually, I seem to have made a small mistake when assigning the names for the factor "condition". Here is the complete procedure I am using based on simulated data as proposed by @dipetkov. The code features one model using treatment contrasts and one using sum contrasts.
set.seed(1234)
n <- 100

data <- data.frame(
  expertise = sample(c("NOV", "EXP"), n, replace = TRUE),
  cond = sample(c("ALO", "TOG"), n, replace = TRUE),
  course = sample(c("YES", "NO"), n, replace = TRUE),
  mood = sample(seq(7), n, replace = TRUE),
  score = rnorm(n)
)

data <- data %>% mutate(
  expertise = as.factor(expertise),
  cond = as.factor(cond),
  course = as.factor(course),
)

#sum contrasts
contr_sum <- contr.sum(2)
colnames(contr_sum) <- c("NOV")
contrasts(data$expertise) <- contr_sum

colnames(contr_sum) <- c("TOG")
contrasts(data$cond) <- contr_sum

colnames(contr_sum) <- c("YES")
contrasts(data$course) <- contr_sum

model_sum <- lm(
  score ~ expertise * (mood + cond + course),
  data = data
)

summary(model_sum)

#treatment contrasts
contr_treatment <- contr.treatment(2)
colnames(contr_treatment) <- c("NOV")
contrasts(data$expertise) <- contr_treatment

colnames(contr_treatment) <- c("TOG")
contrasts(data$cond) <- contr_treatment

colnames(contr_treatment) <- c("YES")
contrasts(data$course) <- contr_treatment

model_trea <- lm(
  score ~ expertise * (mood + cond + course),
  data = data
)

summary(model_trea)

Output model_sum:
Coefficients:
                       Estimate Std. Error t value Pr(>|t|)
(Intercept)             0.09177    0.23428   0.392    0.696
expertiseNOV            0.28286    0.23428   1.207    0.230
mood                    0.01672    0.05225   0.320    0.750
condTOG                 0.03264    0.10073   0.324    0.747
courseYES               0.15819    0.10194   1.552    0.124
expertiseNOV:mood      -0.06743    0.05225  -1.290    0.200
expertiseNOV:condTOG    0.06188    0.10073   0.614    0.541
expertiseNOV:courseYES -0.04754    0.10194  -0.466    0.642

Output model_trea:
Coefficients:
                       Estimate Std. Error t value Pr(>|t|)
(Intercept)             0.57980    0.41055   1.412    0.161
expertiseNOV           -0.59440    0.60245  -0.987    0.326
mood                   -0.05071    0.06741  -0.752    0.454
condTOG                -0.18903    0.26240  -0.720    0.473
courseYES              -0.22131    0.26476  -0.836    0.405
expertiseNOV:mood       0.13485    0.10451   1.290    0.200
expertiseNOV:condTOG    0.24750    0.40291   0.614    0.541
expertiseNOV:courseYES -0.19014    0.40774  -0.466    0.642

Answer: You say you use the lme4 package (designed for fitting mixed-effects models) but your model formula seems to have fixed effects only. How come?

expertiseNOV to courseYES should be the main effects at the average level of the other predictors

This is wrong. We know (from the naming convention used in the summary table) that the model is fitted with the treatment coding, which is the default in R. The intercept corresponds to:
(expertise, condition, mood, course) = (expert, together, 0, NO)

the interaction "expertiseNOV:condALO" is for example telling me that there is a significant difference between experts and novices for the condition "alone"

Actually, it's telling you that there is a significant interaction between expertise and condition. Since expertise is interacted with mood and course as well, the interpretation of the interaction terms is a bit more involved. expertiseNOV:condALO is the expected difference in score between novices and experts when mood=0 and course="NO". (Substitute either mood>0 and/or course="YES", to see how the other two interactions contribute to the expected difference as well.)
So what to do? Learn about contrasts and how to use them to make the post-hoc comparisons that you'd like to make.
A popular package for post-hoc comparisons is emmeans. I generate fake data to illustrate how to use it (that code is attached at the end) but the best place to start is to read the vignettes.
# Not the same summary table since you don't provide your data.
#> Coefficients:
#>                        Estimate Std. Error t value Pr(>|t|)
#> (Intercept)             0.57980    0.41055   1.412    0.161
#> expertiseNOV           -0.59440    0.60245  -0.987    0.326
#> mood                   -0.05071    0.06741  -0.752    0.454
#> condTOG                -0.18903    0.26240  -0.720    0.473
#> courseYES              -0.22131    0.26476  -0.836    0.405
#> expertiseNOV:mood       0.13485    0.10451   1.290    0.200
#> expertiseNOV:condTOG    0.24750    0.40291   0.614    0.541
#> expertiseNOV:courseYES -0.19014    0.40774  -0.466    0.642

Making post-hoc comparisons in a model with multiple interactions is not equivalent to looking at individual regression coefficients.
library("emmeans")

pairs(emmeans(model, ~ expertise | cond))
#> cond = ALO:
#>  contrast  estimate    SE df t.ratio p.value
#>  EXP - NOV    0.139 0.287 92   0.485  0.6288
#>
#> cond = TOG:
#>  contrast  estimate    SE df t.ratio p.value
#>  EXP - NOV   -0.108 0.284 92  -0.381  0.7037
#>
#> Results are averaged over the levels of: course

You can also use the contrast package to specify the comparisons you want to make as contrasts. (Be careful loading contrast and emmeans at the same time. They both define a contrast function.)
Let's reproduce the emmeans output for the comparison between expert and novices when the condition is "together". We set (condition, moon, course) = ("TOG", average mood, either "YES" or "NO")`.
library("contrast")

contrast(
  model,
  list(expertise = "EXP", cond = "TOG", mood = mean(data$mood), course = c("YES", "NO")),
  list(expertise = "NOV", cond = "TOG", mood = mean(data$mood), course = c("YES", "NO")),
  type = "average"
)
#>     contrast
#> lm model parameter contrast
#>
#>     Contrast     S.E.     Lower     Upper     t df Pr(>|t|)
#> 1 -0.1082324 0.283703 -0.671691 0.4552262 -0.38 92   0.7037

If we choose a different mood setting, the contrast between the two expertise levels changes because of the expertise-mood interaction.
contrast(
  model,
  list(expertise = "EXP", cond = "TOG", mood = 7, course = c("YES", "NO")),
  list(expertise = "NOV", cond = "TOG", mood = 7, course = c("YES", "NO")),
  type = "average"
)
#> lm model parameter contrast
#>
#>     Contrast      S.E.     Lower     Upper     t df Pr(>|t|)
#> 1 -0.5019994 0.4301315 -1.356278 0.3522789 -1.17 92   0.2462

And if you are not interested in a particular mood, you may prefer to visualize the expected score differences between experts and novices for all combinations of course and condition as a function of mood. This can be done quickly with the ggeffects package.
library("ggeffects")

plot(
  ggemmeans(model, terms = c("mood [1:7]", "course", "expertise", "cond"))
)

In short, multiple interactions make post-hoc comparisons more complex and more fun.

The R code used to simulate data for illustration purposes.
set.seed(1234)

n <- 100

data <- data.frame(
  expertise = sample(c("NOV", "EXP"), n, replace = TRUE),
  cond = sample(c("ALO", "TOG"), n, replace = TRUE),
  course = sample(c("YES", "NO"), n, replace = TRUE),
  mood = sample(seq(7), n, replace = TRUE),
  score = rnorm(n)
)

model <- lm(
  score ~ expertise * (mood + cond + course),
  data = data
)

Comment: You change the parametrization, but not the model, and therefore not the inference. Statistically, you change nothing. That's why interpreting the regression coefficients directly can end up being not especially meaningful. Why do you want to do it?
Comment: I think you do. You want to make a statement about the difference between expert and novices for each of the conditions. You can't ignore the other factors, however, because of the multiple interactions. You have to decide whether to fix mood and course at a specific level or to marginalize them out. You have to think about that and the best approach is contrasts. The interaction terms in the summary table are at mood = 0 (since mood is numeric). It's not even one of the possible mood levels, so  the "raw" interaction is not particularly interpretable. (You can rescale mood I guess....)
Comment: Thanks @dipetkov for you detailed reply. You are completely right in that I forgot the varying intercept in my initial post. As mentioned in the edit above, I actually used sum contrasts, I just made a mistake when naming one of the factors.  I would still be interested in also clarifying my initial question if I could just reorder the factors to run an additional comparison using sum contrasts. (So not only the interaction for "expertiseNOV:condTog", but "expertiseNOV:condALO" in my second model.)
Comment: A couple of small details in my answer are now irrelevant (and I update later). But the gist remains: one interaction term on its own is not meaningful to interpret because there are other interactions in the model. When you vary mood you change several terms in the model at the same time. You should use contrasts instead. They don't depend on the encoding/parametrization. So much easier to interpret. And explain actually.
Comment: The encoding (treatment or sum) doesn't change the model. So the inference (statistical conclusions) are exactly the same, no matter what the parametrization is.
Comment: I don't exactly understand where the difference lies for you between encoding and contrasts. As far as I know, contrasts can be directly used to test hypothesis ( https://www.sciencedirect.com/science/article/pii/S0749596X19300695).

Setting different contrasts (Treatment / Sum) changes the interpretation of the coefficients. Treatment coding gives you simple effects (at the base level of all other factors), sum contr. give you main effects (at the avg. level of the other factors).

I agree that one can also calculate marginal effects instead, but how could I solve it without?
Comment: Solve what? I'm not sure we have the same definition of contrasts. For me "treatment" / "sum" are two different parametrizations. While a contrast is a comparison, eg., the difference between novices and expert when the rest of the predictors are either fixed at specific values or averaged out. Whether the model uses the treatment or the sum parameterization, the comparison between novices and experts would be the same. Note: R confusingly refers to parametrization as "contrast coding".
Comment: Oh, I see what you mean. I agree that a post-hoc calculated contrast will be the same independent of the parametrization of the model. But the parametrization of the model will change how the coefficients can be interpreted. The coefficient expertiseNOV tells us if there is a significant difference between expertise groups at the average level of all the other factors(with sum contrasts). So I do not need calculate a contrast for this anymore. However, due to the parametrization and factor ordering some comparisons are not directly displayed in the coefficients.
Comment: By reordering the factors I would know change the parametrization again, showing a coefficient which would allow further inferences about the differences (in my case the interaction).

However, it is unclear if such new parametrizations also require a quasi "multi-comparison" correction.
Comment: The main reason is that by interpreting the models parameters directly I do not need to run post-hoc comparisons for which I need to calculate corrections, which reduce the power of these tests.
Comment: Thanks a lot, I get the point. Even after rescaling the interpretation of the correlation coefficients is hard. So it is definitely a good idea to estimate marginal means.


What is the iron:router 1.0 equivalent of this.setLayout() and this.lookupLayoutTemplate()?

Question: Calling this.setLayout() or this.lookupLayoutTemplate(), for instance in this example:
https://github.com/EventedMind/iron-router/issues/655
gives:
Exception in callback of async function: TypeError: undefined is not a function

Answer:
this.setLayout is now this.layout().
this.lookupLayoutTemplate is now Router.lookupLayoutTemplate

Also take note that onBeforeAction now has three arguments:
Router.onBeforeAction(function(req, res, next) {

  next(); // or this.next();
          // still the same as pause()..
          // you MUST call next so the route renders.
});

Comment: Any idea why `Router.lookupLayoutTemplate` returns `undefined` when visiting index? `Router.map -> this.route('/', {name: 'index', layoutTemplate: 'headered'})`
Comment: Try `Router.map -> this.route('index', {path: '/', layoutTemplate: 'headered'})` instead.
Comment: Still undefined, both in `onBeforeAction` and after page has loaded.
Comment: Filed bug. Simplified example: http://meteorpad.com/pad/82MLzBqYZYcx7NkR8/Copy%20of%20Leaderboard
Comment: You're right. I think the issue is caused by the actual on-creation options not being passed properly from configuration context to instance/run time context. [You can see what I mean here]. (http://imgur.com/xFBLXFB.png) It is easily overridden by `Router.configure` but it would not be the desired output. However a work around is to just store `this.options.layout._template` somewhere before modifying the layout if in case you want to revert to it at some time.


How do I set the display suite default region for newly created fields?

Question: What needs to be done:
Newly created fields in any content type should go to the hidden region of the DS Layout.
Short background:
In our project we use the Display Suite module, and we have the following custom layout that is used for all the content types.
project_layout:
  label: Project layout
  category: Display Suite
  class: '\Drupal\ds\Plugin\DsLayout'
  type: partial
  template: ds_layouts/project_layout/project_layout
  icon: ds_layouts/project_layout/project_layout.png
  regions:
    header:
      label: Header
    left:
      label: Left
    middle:
      label: Middle
    right:
      label: Right
    comments:
      label: Comments
    footer_top:
      label: Footer top
    footer_middle:
      label: Footer middle
    footer_bottom:
      label: Footer bottom

`
If a new field is added it always goes to the header region.
What I have tried that does NOT work:

Setting
default_region: hidden

2.Setting
default_region: disabled

Creating new region called test and placing it before  the header region.

In that scenario, the new fields go to the "test" region. In a way this is a workaround, but there should be better solution.
Answer: Have you tried ds_hidden as region_name?
UPDATE, or none (still guessing).
Comment: I tried adding
default_region: ds_hidden , but it doesnt work
Comment: Sorry - bad guess then..


! Heroku push rejected, failed to compile Ruby/rails app

Question:    --with-opt-dir
   --without-opt-dir
   --with-opt-include
   --without-opt-include=${opt-dir}/include
   --with-opt-lib
   --without-opt-lib=${opt-dir}/lib
   --with-make-prog
   --without-make-prog
   --srcdir=.
   --curdir
   --ruby=/usr/local/bin/ruby
   --with-sqlite3-dir
   --without-sqlite3-dir
   --with-sqlite3-include
   --without-sqlite3-include=${sqlite3-dir}/include
   --with-sqlite3-lib
   --without-sqlite3-lib=${sqlite3-dir}/lib
   --enable-local
   --disable-local
   Gem files will remain installed in /tmp/build_3dsid22g5kvhv/vendor/bundle/ruby/1.9.1/gems/sqlite3-1.3.7 for inspection.
   Results logged to /tmp/build_3dsid22g5kvhv/vendor/bundle/ruby/1.9.1/gems/sqlite3-1.3.7/ext/sqlite3/gem_make.out
   An error occurred while installing sqlite3 (1.3.7), and Bundler cannot continue.
   Make sure that `gem install sqlite3 -v '1.3.7'` succeeds before bundling.

 !
 !     Failed to install gems via Bundler.
 !
 !     Heroku push rejected, failed to compile Ruby/rails app

Answer: heroku uses postgresql so you should also use it when developing if you plan to deploy to heroku.  in your Gemfile, remove the line gem 'sqlite3' and replace it with gem 'pg'.  You need to install the pg server first.
Answer: if you have postgre configured at your system, then you can replace

gem "sqlite3"

with

gem "pg"

otherwise, add

group :development do  gem "sqlite3" end group :production do  gem "pg" end

and run bundle as

bundle install --without production

then push it.
Comment: problem still exist , my gemfile is here,    source 'http://rubygems.org'
gem 'rails', '3.2.11'
gem 'bootstrap-sass', '2.1'
gem 'bcrypt-ruby', '3.0.1'
gem 'jquery-rails', '2.0.2'
group :development, :test do
  gem 'sqlite3', '1.3.5'
  gem 'rspec-rails', '2.11.0'
  gem 'guard-rspec', '1.2.1'
  gem 'guard-spork', '1.2.0'
  gem 'spork', '0.9.2'
end
group :assets do
  gem 'sass-rails',   '3.2.5'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier', '1.2.3'
end

group :production do
  gem 'pg', '0.12.2'
end


Verificar se um arquivo existe, dentro de um IF em Python

Question: Boa tarde,
Gostaria de fazer uma verificação:
Se um arquivo existe - excluir
Se não existe seguir o fluxo do programa.
Estou usando o Pycharm, está retornando erro de sintaxe,
Mas já coloquei 4 espaços na linha de baixo.
Obs O resto do código está comentado.

Segue o código:
import os
import os.path

str(input("Digite Enter Para continuar01"))

if os.path.exists('TM.ext'):
    os.remove("TM.txt")
else:
    print("Arquivo nao existe")

Comment: @Sidon Os dois pontos depois do `if` e do `else` foram adicionados [na revisão 2](https://pt.stackoverflow.com/posts/348078/revisions), o que pode ter sido um equívoco, pois eles são a causa do erro de sintaxe, e ao colocá-los, descaracterizou a pergunta, pois agora não ocorre mais o erro.
Comment: Marcos, o código que vc esta usando é o que esta na foto ? ou o que vc colocou em forma de texto ? o da foto esta cheio de erros de digitação , mas o do texto do post parece bem identado. Qual dos dois se refere ?
Comment: O codigo que vc apresenta esta de uma forma, mas a imagem de outra, na imagem falta os dois pontos na linha do `if`
Comment: @OtávioReisPerkles editei a pergunta, posso ter corrigido a identação, estava mal formatada tb.
Comment: É, na verdade é o tipo da pergunta que poderia ser evitada se o usuario tivesse cuidade ao fazer a pergunta. :-)
Comment: Meu ultimo comentario virou quase uma recursão. :-)
Answer: Note que você não está colocando : nas linhas do if e do else e também se o path for uma pasta os.path.exists() retornará True e os.remove() lançará um erro.
Você pode testar se o arquivo existe com os.path.isfile(), e se existir remover com os.remove. Ex.:
import os

if os.path.isfile('TM.ext'):
    os.remove("TM.txt")

Ou você pode deletar sem testar se o arquivo existe e captura o OSError que o módulo lançará. Ex.:
import os

try:
    os.remove("TM.txt")
except OSError:
    pass

Repl.it com o código funcionando

Edit
Para não ficar nada implícito de onde tirei o OSError.
Na documentação do modulo os é especificado no topo:

Note:
All functions in this module raise OSError in the case of invalid or inaccessible file names and paths, or other arguments that have the correct type, but are not accepted by the operating system.

Traduzindo:

Nota:
Todas as funções deste módulo lançam OSError no caso de nomes de arquivos ou paths inválidos ou inacessíveis ...
Answer: usa este comando é o que eu utilizo nos meus cods:
import os.path

if os.path.isfile('arquivo.txt'):
    print("é arquivo")

Comment: Com esse codigo, um erro sera gerado, falta os dois pontos na linha do if.Edite sua resposta.
Comment: obrigado. o teclado comeu rsss


How is adjusted coefficient of determination ($R^2$) linked to the F-values of a test against zero when adding a new variable?

Question: Someone claims that the  adjusted $R^2$ will increase with the addition of an extra variable.
I wonder why, as it is called adjusted (in contrast to the normal $R^2$).
The only condition it has to satisfy (to increase the adjusted $R^2$) is that the F-value (by the way, how is it simple to calculate it?) of the null hypothesis that the new variable is greater than 1.
Can someone give me a hint where the links between the adjusted $R^2$ and the F-Stat of that test are?
And however, who wants to include a new variable in a multiple OLS regression model anyway, if the beta was tested to be 0? Therefore adjusted $R^2$ always changes.
Comment: The claim is wrong: the "usual" $R^2$ increases, but this is not true for the adjusted $R^2$.
Comment: The link between $R^2$ and a certain $F$ statistic is explained here: http://stats.stackexchange.com/questions/58107/conditional-expectation-of-r-squared/58133#58133
Comment: Merci. But  am sorry, that I do not understand this subspace notation. I did not even know, that one can always use the normal + something to describe models. Is there any other explanation, maybe a bit more related to OLS ?
Comment: Not for all models, only Gaussian linear models. What is the model you use exactly ? And do you use a software ?
Comment: Well, my model is (in vector) Y= xb + u where I have t observations and k bs (including an intercept). U is iid. I do not use software, it is a theoretical question - but i could use stata or matlab.
Answer: The assertion of the question is true. We usually show the inverse situation, i.e. the case of dropping one variable.
In a linear multiple regression model $y_i = X\beta +u_i,\; i=1,...,n$, with $k$ regressors (including the constant term), if the t-ratio $t$ of a variable is less than 1, then dropping this one variable will increase adjusted R_squared, $\bar R^2$. When dealing with dropping one variable, then the corresponding F-statistic (reflecting just one linear restriction) is equal to $t^2$ (see this post). So both should be smaller than unity for $\bar R^2$ to increase.
This result can be proven as follows:
$\bar R^2$ is defined as
$$ 1- \bar R^2 = \frac {n-1}{n-k} (1-R^2) \qquad [1]$$
Denoting $S_{yy} = \sum_{i=1}^{n}(y_i-\bar y)^2$ and since $R^2 = 1 - \frac{\sum_{i=1}^{n}\hat u_i^2}{S_{yy}}$we can write
$$ (1- \bar R^2) = \frac {n-1}{n-k} \left(1-1 + \frac{\sum_{i=1}^{n}\hat u_i^2}{S_{yy}}\right) = \frac {n-1}{S_{yy}} \frac{\sum_{i=1}^{n}\hat u_i^2}{n-k}$$
$$\Rightarrow (1- \bar R^2)\frac {S_{yy}}{n-1} = \hat \sigma^2 \qquad [2]$$
By dropping a regressor, $S_{yy}$ and $n$ remain unaffected. So as a matter of mathematical necessity, the term $(1- \bar R^2)$ in the LHS of $[2]$ moves in the same direction as its RHS - meaning that as the OLS estimated variance of the regresion decreases, so is $(1-\bar R^2)$, and hence, $\bar R^2$ increases as $\hat \sigma^2$ decreases.
Consider now dropping one regressor, and index the various quantities related to this restricted regression with $r$. Denote $RSS$ the residuals sum of squares
The F-statistic to test whether the restricted regression with $k-1$ regressors is "better" than the regression with $k$ regressors is
$$F(1,n-k)= \frac{RSS_r -RSS}{RSS/(n-k)} = \frac {(n-k+1)\hat \sigma_r^2 - (n-k)\hat \sigma^2}{\hat \sigma^2}$$
$$=(n-k+1)\frac {\hat \sigma_r^2}{\hat \sigma^2} - (n-k) \Rightarrow \frac {\hat \sigma_r^2}{\hat \sigma^2} = \frac {F+(n-k)}{1+(n-k)} \qquad [2]$$
From $[2]$ it is obvious that if
$$F<1 \Rightarrow \hat \sigma_r^2 <\hat \sigma^2 \Rightarrow \bar R_r^2 >  \bar R^2$$
And $F(1,n-k)=t^2 <1 \Rightarrow t<1$
Beware that the above results hold only when considering dropping just one regressor. Assume that we run the initial regression with $k$ regressors and we observe that two of them have t-ratios smaller than unity. This does not imply necessarily that if we drop both simultaneously, we will end up with a higher $\bar R^2$.
Now think in reverse - start from the "restricted" model and add one variable.


SQL: Column B entries of column A are also in column A --> Match column C attribute of A's B entry in A to original A

Question: in a SQL server database SQLBASE I have a table article with three columns:
artnr (Article number)
succesor (Successor article number)
color (Color of article number)
Not every article number must have a successor number, but every successor number is always also listed somewhere in column A, like below:
Input
Article1   |   Article3    |   green

Article2   |    empty      |   blue

Article3   |   Article2    |   red

Article4   |    empty      |   yellow

For any article number of column A I need the color of the corresponding successor number (if there is any successor, otherwise leave blank).
Output:
Article1   |   red

Article2   |   empty

Article3   |   blue

Article4   |   empty

Please, I would appreciate any help on how to link the successor material's color to the predecessor material using an SQL query.
Thanks!
Answer: You can use a self join:
select a1.artnr, a2.color
from Articles a1 left join Articles a2
on a1.succesor = a2.artnr


Use Google analytics to alert on traffic spike source

Question: I use Google Analytics today to notify me of big traffic spikes.  In my case, a big traffic spike is typically due to a link from a prominent website.
Google Analytics includes a new "Intelligence" feature to report on spikes.  Unfortunately, today it only reports that I had a spike, but doesn't report the referring site; instead it reports the geographic region of the traffic, e.g. "California."
This isn't a very useful dimension to report on, because geography is almost never the cause of the traffic spike; it's almost always due to a referring site.
Is there a way to configure Google Analytics Intelligence to report on the cause (the referring site) of traffic spikes?
Comment: Have you asked on the Google forums? Seems to me to be the obvious place to start.
Comment: Yup http://www.google.com/support/forum/p/Google+Analytics/thread?tid=6d15c64413a16535&hl=en No response so far
Answer: I would use the following Alert Conditions:

This applies to: Referral Path
Condition: Does not match exactly
Value: (not set)
Alert me when: Visits
Condition: % increases by more than
Value: 25
Compared to: Previous day

You could also change the 'applies to' condition to a regex to filter out any regular refers that fluctuate above the increase % you treat as a spike.
Comment: Best answer so far.  Looks like Google Analytics isn't really meant to do this, and I can't test the alert before the bounty runs out, soooo here you go.
Comment: Thanks :-) I think Analytics should do this... it's a great use-case for the Intelligence component. If the settings I posted don't work for you (I still believe they should), then it would be a reasonable feature request.
Answer: I'd take the Google Analytics alert as an indicator you should take a look at your logs.  Something like webalizer or awstats will give you the detail you want.  Analytics is good, but it can't tell you everything your log files can.


Order of the suspension of the Hopf map

Question: I am working on the following problem from an old qualifying exam in algebraic topology:

The Hopf map $\eta:S^3 \rightarrow S^2$ can be defined as $\eta(z_0,z_1) = z_0/z_1$, with $S^3$ the unit sphere in $\mathbb{C}^2$ and $S^2 = \mathbb{C} \cup \infty$. (a) Show that $k \eta \simeq \eta k^2$, where $k$ and $k^2$ denote maps of degree $k$ and $k^2$, respectively.
(b) Using the fact that, after suspension, the compositions here are commutative, show that $\Sigma \eta$ has (additive) order at most $2$.
(c) Show that $\Sigma \eta$ has (additive) order exactly $2$.

I was able to complete part (a), but I'm struggling with completing parts (b) and (c).
In part (b), I know that suspension is a covariant (homotopy) functor, so from the homotopy we showed in part (a), we have $\Sigma(k \eta) \simeq \Sigma (\eta k^2)$ $\Rightarrow$ $\Sigma k \circ \Sigma \eta \simeq \Sigma \eta \circ \Sigma k^2$. I'm not quite sure how to proceed from here to show that $\Sigma \eta$ has additive order at most $2$, though -- for example, where does the commutative property of suspensions mentioned come in handy here?
For part (c), I found something related in the answer to this post, where the user comments that the Freudenthal suspension theorem (which I'm most familiar with of all the ideas expressed there) can be used here. Indeed, by the Freudenthal suspension theorem, the suspension map $\pi_3(S^2) \rightarrow \pi_4(S^3)$ is surjective. I fail to see why this gives that $\Sigma \eta$ has additive order exactly $2$. Firstly, is it easy to see why $\pi_4(S^3) \cong \mathbb{Z}_2$? Then, how does surjectivity of the suspension map $\pi_3(S^2) \rightarrow \pi_4(S^3)$ give that $\Sigma \eta$ is a generator of $\pi_4(S^3) \cong \mathbb{Z}_2$?
Any thoughts would be appreciated.
Thanks!
Answer: The point is that $\eta\circ k=\eta+\eta+\dots+\eta$ is the $k$-fold sum of $\eta$ in $\pi_3S^2$. In particular $\eta\circ(-1)=-\eta$. Now,
$$k\circ\eta=\eta\circ k^2$$
and
$$\Sigma(k\circ\eta)=\Sigma k\circ\Sigma\eta=\Sigma\eta\circ\Sigma k=\Sigma(\eta\circ k)$$
by the commutativity of these elements after suspension. Hence
$$\Sigma(\eta\circ k)=\Sigma(\eta\circ k^2).$$
With $k=-1$ we have
$$\Sigma(\eta\circ(-1))=\Sigma(-\eta)=-\Sigma\eta$$
on the left, and
$$\Sigma(\eta\circ(-1)^2)=\Sigma(\eta\circ 1)=\Sigma\eta$$
on the right. In particular
$$\Sigma\eta=-\Sigma\eta,$$
showing that this element has order no greater than $2$.
Thus to show that $\Sigma\eta$ has order $2$ it will suffice to show that it is nontrivial. One way to accomplish this is by noting that the mapping cone construction commutes with suspension. In particular, the mapping cone of $\Sigma\eta$ is $\Sigma\mathbb{C}P^2$. If $\Sigma\eta$ were null-homotopic, then $\Sigma\mathbb{C}P^2$ would be homotopy equivalent to $S^3\vee S^5$ (which is the mapping cone of the constant map $S^4\rightarrow S^3$). That $\Sigma\mathbb{C}P^2$ does not split as a wedge of spheres is a consequence of the non-trivial Steenrod square
$$Sq^2:H^3(\Sigma\mathbb{C}P^2;\mathbb{Z}/2)\rightarrow H^5(\Sigma\mathbb{C}P^2;\mathbb{Z}/2).$$
If this is unfamiliar, then let us stick to the EHP sequence. We know that the suspension $\Sigma:\pi_3S^2\rightarrow\pi_4S^3$ is surjective by Freudenthal's Theorem. Since $\eta$ generates $\pi_3S^2\cong\mathbb{Z}$, and $\Sigma\eta$ has order $\leq2$, the group $\pi_4S^3$ is either $\mathbb{Z}/2$ or is trivial. Both of these groups are devoid of odd torsion, so to answer our problem it will suffice to work 2-locally.
Thus introduce the EHP sequence,
$$\dots\rightarrow\pi_5S^5\xrightarrow{P}\pi_3S^2\xrightarrow\Sigma\pi_4S^3\rightarrow 0$$
which becomes exact after localisation at $2$. By exactness, the right-hand group is trivial if and only if $P$ is surjective. But it is well-known that
$$P(\iota_5)=[\iota_2,\iota_2],$$
where $[\iota_2,\iota_2]$ is the Whitehead product of $\iota_2$ with itself. I calculated the valued of this Whitehead product here (at least up to sign), showing that
$$[\iota_2,\iota_2]=\pm2\eta$$
(the exact sign will depend on your particular conventions).
The point is that $P$ is not surjective, so it must be that $\pi_4S^3\cong\mathbb{Z}/2$, generated by $\Sigma\eta$.
Comment: It's about how the addition is defined in $\pi_*$. The homotopy groups are always covariantly functorial, so that $\alpha\circ k=\alpha_*(k)=\alpha_*(1+1+\dots+1)=\alpha_*(1)+\dots+\alpha_*(1)=\alpha+\dots+\alpha$. The fact that $(-1)\circ\eta=\eta\circ(-1)^2=\eta$ shows that you can't expect much from the other direction.
Comment: Thanks a lot! Could you shed some light on why we need the formula $\Sigma (k \circ \eta) = \Sigma (\eta \circ k)$? Isn't $\Sigma(-1 \circ \eta)$ also equal to $-\Sigma \eta$?

Order of the suspension of the Hopf map


How to get All items associated to a user in mongoose

Question: I have a collection of Items that a particular make and perform a transaction.  In my schema, I associate the userId to each item.  I want to be able to display as a list all the items that the user owns.
Here I have managed to total up all sizes of each item but I cant work out a way how to get a total for each user
  {
    id: Number,
    x: Number,
    y: Number,
    xSize: String,
    ySize: String,
    imageSource: String,
    user: { type: mongoose.Schema.ObjectId, ref: 'User' }
  },
  { timestamps: true }
);

const UserSchema = new Schema(
  {
    id: Number,
    name: String,
    website: String,

  },
  { timestamps: true }
);

  Item.find({}, function (err, items) {
    var itemMap = {};
    items.forEach(function (item) {
      itemMap[item._id] = item;
    });
    var countedNames = items.reduce(function (allNames, name) {
      if (name.xSize in allNames) {
        allNames[name.xSize]++;
      }
      else {
        allNames[name.xSize] = 1;
      }
      return allNames;
    }, {});

Essentially i want to get a list basically saying
{name:"Dave", website:"www.google.com, items:[item1, item2]}
where item1 and item2 relate to the item schema
Answer: You should rewrite your UserSchema to contain a reference to the item, in this format:
const UserSchema = new Schema(
  {
    id: Number,
    name: String,
    website: String,
    items:
    [{
       item: {type: mongoose.Schema.ObjectId, ref: 'Item'}
    }]
  },
  { timestamps: true }
);

This will simply allow you to perform the following query:
User.find({}).populate('Item')

Which would return the User document, and all items associated under the document.
You could do the following:
let users = User
    .find({})
    .populate('Item')
    .exec(function (err, users) {
       if (err) { console.log(err); }
       console.log(users)
    }

Rewriting the schema will make querying users for their items much easier.


What is the maximum number of squares that can fit in a circle?

Question: The conditions for this are

No overlapping
The answer can be in decimals (so the number of squares doesn't have to be whole)
The radius of the circle and the side length of the square is same

My best guess is π (approximately 22/7) squares.
I get this by dividing the area of the circle by the area of 1 square.
Thanks!
Comment: If you're allowing fractions of squares, you are not actually putting squares into a circle. You've simply found that the area of the unit circle is pi, which has nothing to do with subdividing the circle into squares.
Comment: It depends on the size of the square. That a circle with radius 1 has greater area than 3 squares of side length 1 doesn't mean you can fit all those shapes inside the circle simultaneously. Consider a narrow, long rectangle with one side of length 2 and one of length 0.1 - not even a single one will fit inside the unit circle despite the fact the circle has over 10x as much area. That one shape has less area than another in no way implies the first can fit inside the second.
Comment: Start by trying to fit two at the same time?
Comment: @NuclearHoagie So, if that exception was overridden would the answer just be 3?
Comment: Oh I get it now, my logic was flawed. Thanks alot!
Answer: Any square of side length $1$ that you try to fit in the circle of radius $1$ will need to include the centre of the circle (and a small neighbourhood around it). This is a simple geometric proof that I will not give here.
The consequence is that you can fit at most one of these squares unless they overlap.
Comment: The idea for the proof is that the centre of the circle must always be located between opposite sides of the square. Doing it twice (once for each pair of sides) shows the result.


WebSphere - Horizontal Scalability

Question: Does WebSphere 6.1 (not the ND edition) support the creation of a server group/cluster with multiple nodes possibility spanning across multiple machines. The idea is to create a horizontal cluster for load-balancing and fail-over support. Some previous versions of WAS supported this out-of-the-box through an advanced admin. console but what about this version.
The Base Edition of WAS allows the creation of multiple WAS instances but what about the creation of clusters?
Answer: Sorry to tell you that bud, but as far as i know - only ND allows you to do clustering from the WAS perspective. If you want a failover, just create dmgr profile and add node. That should not be a problem since in 6 and above you don't need any additional software - it's just another profile. But if you don'w want to do this, you may think about doing a failover on the different level, for example on F5 or something like that. It's not the sam, but in some cases might work.
Comment: You can use edge level load balancing/fail over with the IBM Load Balancer and the IBM HTTP Server-Plugin. However more sophisticated clustering (session failover, etc.) is only available in ND.

WebSphere - Horizontal Scalability


How can I pad an integer with zeros on the left?

Question: How do you left pad an int with zeros when converting to a String in java?
I'm basically looking to pad out integers up to 9999 with leading zeros (e.g. 1 = 0001).
Comment: Yup, that's it! my bad... I typed it in on my phone.  You dont' need the "new String" either : Integer.toString(num+10000).subString(1) works.
Comment: see also http://stackoverflow.com/questions/35521278/printing-an-integer-in-java-that-have-zero-in-front-of-it/35521965#35521965 for a solution with diagram
Comment: Long.valueOf("00003400").toString();  Integer.valueOf("00003400").toString(); --->3400
Comment: There is a problem with the `new String(Integer.toString(num + 10000)).substring(1)` approach if `num` is any bigger than 9999 though, ijs.
Answer: Use java.lang.String.format(String,Object...) like this:
String.format("%05d", yournumber);

for zero-padding with a length of 5. For hexadecimal output replace the d with an x as in "%05x".
The full formatting options are documented as part of java.util.Formatter.
Comment: If you have to do this for a large list of values, performance of DecimalFormat is at least 3 times better than String.format().  I'm in the process of doing some performance tuning myself and running the two in Visual VM shows the String.format() method accumulating CPU time at about 3-4 times the rate of DecimalFormat.format().
Comment: And to add more than 9 zeros use something like `%012d`
Comment: This is for Java 5 and above. For 1.4 and lower DecimalFormat is an alternative as shown here http://javadevnotes.com/java-integer-to-string-with-leading-zeros
Comment: Should I expect the options in `String.format` to be akin to printf() in C?
Comment: Hi guys! I have some problems using: `%d can't format java.lang.String arguments`
Comment: @Shurane mostly, yes.
Comment: Long.valueOf("00003400").toString(); Integer.valueOf("00003400").toString(); --->3400
Comment: To get "0001" (four digits) as was asked for in the question you do "%04d". .
Comment: This only works to pad the String up to the number of characters specified in the format string. This **does not** add 5 zeros onto the String. More generally, this means you have to know that your string is between 0-N characters for a format string specified by "%0Nd". Any dynamic String that is longer than N, and this solution falls apart.
Answer: Let's say you want to print 11 as 011
You could use a formatter: "%03d".

You can use this formatter like this:
int a = 11;
String with3digits = String.format("%03d", a);
System.out.println(with3digits);

Alternatively, some java methods directly support these formatters:
System.out.printf("%03d", a);

Comment: @Omar Koohei indeed, but it explains the reasoning behind the "magic constants".
Comment: @chiperortiz afaik it's not possible with the above formatting tools. In that case, I calculate the required leading characters (e.g. `int prefixLength = requiredTotalLength - String.valueOf(numericValue).length`), and then use a repeat string method to create the required prefix. There are various ways to repeat strings, but there isn't a native java one, afaik: https://stackoverflow.com/questions/1235179/simple-way-to-repeat-a-string-in-java
Comment: Nice answer! Just a comment, the `F` of format() should be `f`:  `String.format(...);`.
Comment: what if i dont want to append a leading 0 but another letter/number? thanks
Comment: @chiperortiz starting from java 11 there is a String.repeat method though.
Answer: If you for any reason use pre 1.5 Java then may try with Apache Commons Lang method
org.apache.commons.lang.StringUtils.leftPad(String str, int size, '0')

Answer: Found this example... Will test...
import java.text.DecimalFormat;
class TestingAndQualityAssuranceDepartment
{
    public static void main(String [] args)
    {
        int x=1;
        DecimalFormat df = new DecimalFormat("00");
        System.out.println(df.format(x));
    }
}

Tested this and:
String.format("%05d",number);

Both work, for  my purposes I think String.Format is better and more succinct.
Comment: Yes, I was going to suggest DecimalFormat because I didn't know about String.format, but then I saw uzhin's answer.  String.format must be new.
Comment: It's similar how you'd do it in .Net Except the .Net way looks nicer for small numbers.
Comment: In my case I used the first option (DecimalFormat) because my number was a Double
Answer: Try this one:
import java.text.DecimalFormat;

DecimalFormat df = new DecimalFormat("0000");

String c = df.format(9);   // Output: 0009

String a = df.format(99);  // Output: 0099

String b = df.format(999); // Output: 0999

Answer: Here is how you can format your string without using DecimalFormat.
String.format("%02d", 9)

09

String.format("%03d", 19)

019

String.format("%04d", 119)

0119
Answer: If performance is important in your case you could do it yourself with less overhead compared to the String.format function:
/**
 * @param in The integer value
 * @param fill The number of digits to fill
 * @return The given value left padded with the given number of digits
 */
public static String lPadZero(int in, int fill){

    boolean negative = false;
    int value, len = 0;

    if(in >= 0){
        value = in;
    } else {
        negative = true;
        value = - in;
        in = - in;
        len ++;
    }

    if(value == 0){
        len = 1;
    } else{
        for(; value != 0; len ++){
            value /= 10;
        }
    }

    StringBuilder sb = new StringBuilder();

    if(negative){
        sb.append('-');
    }

    for(int i = fill; i > len; i--){
        sb.append('0');
    }

    sb.append(in);

    return sb.toString();
}

Performance
public static void main(String[] args) {
    Random rdm;
    long start;

    // Using own function
    rdm = new Random(0);
    start = System.nanoTime();

    for(int i = 10000000; i != 0; i--){
        lPadZero(rdm.nextInt(20000) - 10000, 4);
    }
    System.out.println("Own function: " + ((System.nanoTime() - start) / 1000000) + "ms");

    // Using String.format
    rdm = new Random(0);
    start = System.nanoTime();

    for(int i = 10000000; i != 0; i--){
        String.format("%04d", rdm.nextInt(20000) - 10000);
    }
    System.out.println("String.format: " + ((System.nanoTime() - start) / 1000000) + "ms");
}

Result
Own function: 1697ms
String.format: 38134ms
Comment: Above there's a mention of using DecimalFormat being faster. Did you have any notes on that?
Comment: @Patrick For DecimalFormat performance see also: http://stackoverflow.com/questions/8553672/a-faster-alternative-to-decimalformat-format
Comment: Shocking!  It's nuts that function works so poorly.  I had to zero pad and display a collection of unsigned ints that could range between 1 to 3 digits.  It needed to work lightning fast.  I used this simple method: `for( int i : data ) strData += (i > 9 ? (i > 99 ? "" : "0") : "00") + Integer.toString( i ) + "|";` That worked very rapidly (sorry I didn't time it!).
Comment: How does the performance compare after it's been run enough for HotSpot to have a crack at it?
Answer: You can use Google Guava:
Maven:
<dependency>
     <artifactId>guava</artifactId>
     <groupId>com.google.guava</groupId>
     <version>14.0.1</version>
</dependency>

Sample code:
String paddedString1 = Strings.padStart("7", 3, '0'); //"007"
String paddedString2 = Strings.padStart("2020", 3, '0'); //"2020"

Note:
Guava is very useful library, it also provides lots of features which related to Collections, Caches, Functional idioms, Concurrency, Strings, Primitives, Ranges, IO, Hashing, EventBus, etc
Ref: GuavaExplained
Comment: This method actually gives much better performance results than JDK String.format / MessageFormatter / DecimalFormatter.
Comment: Above sample code is usage only, not really sample code.  The comment reflect this, you would need "String myPaddedString = Strings.padStart(...)"
Answer: Although many of the above approaches are good, but sometimes we need to format integers as well as floats. We can use this, particularly when we need to pad particular number of zeroes on left as well as right of decimal numbers.
import java.text.NumberFormat;
public class NumberFormatMain {

public static void main(String[] args) {
    int intNumber = 25;
    float floatNumber = 25.546f;
    NumberFormat format=NumberFormat.getInstance();
    format.setMaximumIntegerDigits(6);
    format.setMaximumFractionDigits(6);
    format.setMinimumFractionDigits(6);
    format.setMinimumIntegerDigits(6);

    System.out.println("Formatted Integer : "+format.format(intNumber).replace(",",""));
    System.out.println("Formatted Float   : "+format.format(floatNumber).replace(",",""));
 }
}

Answer: int x = 1;
System.out.format("%05d",x);

if you want to print the formatted text directly onto the screen.
Comment: But OP never asked for it. Internally `String.format` and `System.out.format` call the same `java.util.Formatter` implementation.
Comment: ... and System.out can be redirected.
Answer: You need to use a Formatter, following code uses NumberFormat
    int inputNo = 1;
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumIntegerDigits(4);
    nf.setMinimumIntegerDigits(4);
    nf.setGroupingUsed(false);

    System.out.println("Formatted Integer : " + nf.format(inputNo));

Output: 0001
Answer: Use the class DecimalFormat, like so:
NumberFormat formatter = new DecimalFormat("0000"); //i use 4 Zero but you can also another number
System.out.println("OUTPUT : "+formatter.format(811));

OUTPUT : 0000811
Comment: In this case the output is 0811.
Answer: In Kotlin, you can use format() function.
val minutes = 5
val strMinutes = "%02d".format(minutes)

where, 2 is the total number of digits you want to display(including zero).
Output: 05
Answer: If you are on Java 15 and above,
var minutes = 5
var strMinutes = "%02d".formatted(minutes)

where, 2 is the total number of digits you want to display(including zero).
Output: 05

This uses formatted method part of instance method on Strings called which does the same as the static String.format(str,x,y,z)
Answer: Check my code that will work for integer and String.
Assume our first number is 2. And we want to add zeros to that so the the length of final string will be 4. For that you can use following code
    int number=2;
    int requiredLengthAfterPadding=4;
    String resultString=Integer.toString(number);
    int inputStringLengh=resultString.length();
    int diff=requiredLengthAfterPadding-inputStringLengh;
    if(inputStringLengh<requiredLengthAfterPadding)
    {
        resultString=new String(new char[diff]).replace("\0", "0")+number;
    }
    System.out.println(resultString);

Comment: `(new char[diff])` why
Comment: `replace("\0", "0")`what is... what
Comment: @Isaac - First I created a char array, and using that char array I created a string. Then I replaced null character(which is the default value of char type) with "0" (which is the char we need here for padding)
Answer: You can add leading 0 to your string like this. Define a string that will be the maximum length of the string that you want. In my case i need a string that will be only 9 char long.
String d = "602939";
d = "000000000".substring(0, (9-d.length())) + d;
System.out.println(d);

Output : 000602939
Answer: Use this simple Kotlin Extension function
fun Int.padWithZeros(): String {
   return this.toString().padStart(4, '0')
}

Answer: No packages needed:
String paddedString = i < 100 ? i < 10 ? "00" + i : "0" + i : "" + i;

This will pad the string to three characters, and it is easy to add a part more for four or five. I know this is not the perfect solution in any way (especially if you want a large padded string), but I like it.
Comment: Hmm...I like it.
Answer: Here is another way to pad an integer with zeros on the left. You can increase the number of zeros as per your convenience. Have added a check to return the same value as is in case of negative number or a value greater than or equals to zeros configured. You can further modify as per your requirement.
/**
 *
 * @author Dinesh.Lomte
 *
 */
public class AddLeadingZerosToNum {

    /**
     *
     * @param args
     */
    public static void main(String[] args) {

        System.out.println(getLeadingZerosToNum(0));
        System.out.println(getLeadingZerosToNum(7));
        System.out.println(getLeadingZerosToNum(13));
        System.out.println(getLeadingZerosToNum(713));
        System.out.println(getLeadingZerosToNum(7013));
        System.out.println(getLeadingZerosToNum(9999));
    }
    /**
     *
     * @param num
     * @return
     */
    private static String getLeadingZerosToNum(int num) {
        // Initializing the string of zeros with required size
        String zeros = new String("0000");
        // Validating if num value is less then zero or if the length of number
        // is greater then zeros configured to return the num value as is
        if (num < 0 || String.valueOf(num).length() >= zeros.length()) {
            return String.valueOf(num);
        }
        // Returning zeros in case if value is zero.
        if (num == 0) {
            return zeros;
        }
        return new StringBuilder(zeros.substring(0, zeros.length() -
                String.valueOf(num).length())).append(
                        String.valueOf(num)).toString();
    }
}

Input
0
7
13
713
7013
9999
Output
0000
0007
0013
7013
9999


cp and cat on Centos 5.5/ext3 is 10x slower for files in certain directories

Question: I was sorting some large files (91GB across 27 files) with GNU sort when I noticed that iostat -dxk 3 showed very slow read speeds, between 5 MB/s and 10 MB/s, with 100% disk utilization. I tried cat large-file > /dev/null, and got similar performance, only slightly higher. The same for cp large-file /tmp/, with /tmp on a separate disk. vim experiences the same, as well as scripts I write in Ruby reading files, if that helps. Write speed is fine and fast though.
EDIT: It looks like these operations are only slow on files in a certain directory. The same operations on other files in a sibling directory (same disk partition), end up being fast, with above 90 MBPS read speed. This makes no sense to me. Could it possibly be due to the manner in which these files were constructed? I created them by reading in a lot of other files, and writing each line into an appropriate "bucket file", depending on the first character in the line (so a-z, and a single file for others). So I was pretty much simultaneously appending lines to 27 files, one at a time, through 8 processes while reading a couple thousand files. Could this cause the sequential order the blocks representing a file to be out of order instead? Hence the slow sequential reads afterwards?
However, I tried using fio to measure sequential read performance, and it clocked in at 73 MB/s. Also notable is that my boss got proper read speeds when downloading some files via FTP from the same machine.
So I'm guessing this is some configuration issue somewhere, but I have no idea where. What could the reason be and how can I try to fix it?
Edit: This machine is running under Citrix Xen virtualization.
Edit: Output of iostat -dxk while sort is loading a large file into its buffer (get similar output for cat/cp):
Device:         rrqm/s   wrqm/s   r/s   w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
xvdb              0.00     0.00 1000.00  0.00  6138.61     0.00    12.28    24.66   24.10   0.99  99.41
xvdb1             0.00     0.00 1000.00  0.00  6138.61     0.00    12.28    24.66   24.10   0.99  99.41
xvda              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
xvda1             0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00

Edit: Further performance degradation after a few hours (with breaks for the disk when sort was processing). It almost looks like random IO, but there's only a single sort operation going on, with no other processes doing any IO, so reads should be sequential =/ :
Device:         rrqm/s   wrqm/s   r/s   w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
xvdb              0.00     0.00 638.00  0.00  2966.67     0.00     9.30    25.89   40.62   1.57 100.00

Device:         rrqm/s   wrqm/s   r/s   w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
xvdb              0.33     0.00 574.67  0.00  2613.33     0.00     9.10    27.82   47.55   1.74 100.00

Device:         rrqm/s   wrqm/s   r/s   w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
xvdb              0.00     0.00 444.33  0.00  1801.33     0.00     8.11    28.41   65.27   2.25 100.00

Comment: How much free space in the vdisk and the underlying storage? What's the underlying storage?
Comment: Lots of free space, and just a single, regular spinning HDD for stoarge. Thanks for inquiring, but the problem is most definitely the file fragmentation, which mattdm suggested below.
Answer: Are your slow files highly fragmented? Run /usr/sbin/filefrag -vfilename to find out. You'll get output like:
Checking big.file
Filesystem type is: ef53
Filesystem cylinder groups is approximately 4272
Blocksize of file big.file is 4096
File size of big.file is 96780584 (23629 blocks)
First block: 88179714
Last block: 88261773
Discontinuity: Block 6 is at 88179742 (was 88179719)
Discontinuity: Block 12233 is at 88192008 (was 88191981)
Discontinuity: Block 17132 is at 88197127 (was 88196911)
Discontinuity: Block 17133 is at 88255271 (was 88197127)
big.file: 5 extents found, perfection would be 1 extent

or perhaps much worse.
You mention that the system is running under virtualization. Is this access with a virtual disk image file?
Comment: This is exactly it. Found 1188454 discontinuities in a 7GB file. The reason I'm guessing is what my latest edit in bold in my question says. I made the files by appending line by line on all 27 files simultaneously, while also reading other files from the same disk. Does that sound right? I guess I'll have to do a less naive scheduling of read/writes in my scripts, at least make them work in bulk. Thanks so much!
Comment: Cool — glad I could help!
Answer: Soo, i believe this is a simple case of not enough RAM...
For a start when reading/writing a file smaller than your RAM ( every thing is fast - like your "fio" test..)
Once you start working with data larger than your OS can cache, your OS cache begins to swap ( sometimes even to disk) ( in fact you should check your ram usage when you have 4mb's read speed)
It sounds like something ive experience before, your getting slow speed for reading such a large file.. ( ive seen a DB do exactly the same when it was using large index's that didnt fit into RAM )
Given also the overhead of working on a VM ( this sounds very typical to me )
I would check that your disks arent swapping or your active memory isnt full ( and let me know ) :D
Comment: Good try, but this is not the case here. I've got 16GB of RAM, and all my "large" files are smaller, upto 11GB (which is on purpose btw). I've actually got plenty of free memory, and am not swapping at all. In fact, with the `sort` I'm doing now, I've specified with the `-S` option a buffer size of 12GB, so that sort itself doesn't make files in /tmp as it usually does given large files, and instead makes use of the free memory. Also, this slowness in cp/cat/sort occurs with small files as well. Also, look at the commands like `cat file > /dev/null`, which take no memory.


What to do with time series model, if residuals are autocorrelated for a certain lag?

Question: I'm doing a time series forecast (with hourly data), and after plotting the autocorrelation of the residuals, I get a bigger value for every 24th lag (the pikes in the picture). I tried to include the 24th lag of the dependent variable in the model, but no change.
What are my options in this case, if I want to remove the autocorrelation between the residuals?
Answer: Seasonality can be treated by adding 23 seasonal dummies. Seasonal arma or seasonal differences are often deficient.
The whole idea is that time series modelling requires evaluating alternative approaches thus it is an iterative self-checking process.  You have roughly 7 years of hourly data. You have assumed among other things that there is 1 trend and only 1 trend and there are no level or step shifts. You have assumed a 0/1 variable for holidays (assuming all holifdays are similar in their effect) while demand would probably be dependent (for some holidays) on a number of days around specific holidays. You don't know the underlying and waiting to be discovered arima structure including possible first order or seasonal(24) order differencing. You don't know about about any unusual readings but they can distort and obfuscate a useful model.
Furthermore there can be non-constant error variance and/or non-constant parameter changes over time.
You need to use more powerful software that can be useful aid with problems as complicated as yours. Simple tools can sometimes be useful for simple problems . You have a complicated problem , thus you may possibly need to up-armor !
Comment: I already added the 23 dummies, but even with these, the residuals are autocorrelated. So not sure what can be the problem.
Comment: if you post your data or send it to me at firstname.lastname@example.com , I will try and help you further
Comment: Sent you the data via email.
Comment: If you found this answer helpful, then please consider
[upvoting](https://stats.stackexchange.com/help/why-vote)
and/or
[accepting](https://stats.stackexchange.com/help/accepted-answer)
it.
Answer: This shows seasonality in your data, so you have to take the preprocessing step of removing this seasonality (through differencing).
Comment: The apparemtly seasonal structure can often be the resultd of an omitted set of seasonal pulses  (in this case 23 seasonal dummies) rather than an autogressive seasonal structure (lag 24) as you are suggesting.


Dedicated IP vpn for linux

Question: I have a linux redhat enterprise 5.5 86_6x server inside my network .
My network hasn't dedicated IP and i want to use this server as web server in internet.
can i use a dedicated IP vpn for my linux server to receive traffic from internet?
How can i do this?
Answer: No, a VPN IP address is private and only works within your VPN. It would not work for traffic outside your network.
Dynamic DNS
You can use a dynamic DNS service like dyndns or no-ip which will provide you with an domain like yourname.dyndns.org, but they also give other choices (no-ip.com, dnsalias.com, homeip.net).
How it works
This pretty much links your dynamic internet IP address to a domain name and when your IP changes, it will updates the domain name to point to that new IP.
Answer:
You need to have either a static IP address or dynamic DNS service for the part of your network that faces the internet so that others in the internet can find you with ease. There are many choices out there; just google it. I use no-ip.com. Most companies offer free service but force to update your host registration once a quarter (or less or more often) or they delete it. Or you can pay $10/year (at No-IP) for getting rid of that bother.
Once a request makes it to your network, the router/firewall needs to open the port, or forward it, to the internal IP address (and port) of the web server. This is called port forwarding.

That is it. A majority of home router/firewalls can do both of the above with ease.
If you want to segment the web server from the rest of your network you will have to invest in some extra hardware. If, however, you want to do it for zero hardware cost then just pick a port on your router/firewall (I assume you are using a consumer device) assign it an address in your new subnet, update your firewall rules, etc. It is not that complicated but you probably won't be able to do it with the software that comes with most consumer routers. You will have to install OpenWRT or DDWRT or some other similar router OS.
Answer: Just a quick note: what you probably want has been described by Allen and Weboide already.
But it is indeed perfectly possible to set up a VPN to pull a public IP to other places, but it requires having an endpoint with spare IP's routed to/through it and involves some advanced routing tricks on both ends.

Dedicated IP vpn for linux


In SAS, does the using the GLM statement ABSORB invalidate the standard errors of the parameter estimates?

Question: SAS provides a handy tool for handling panel models with a large number of groups by 'absorbing' those groups (PROC GLM; ABSORB). My understanding is that it factors the effect of the absorbed parameters out of the data before estimating the remaining parameters. It seems like this may invalidate the standard errors of the parameter estimates. The variance covariance matrix would not be calculated with the full set of parameters. Hence, we would be calculating the variance covariance matrix conditional on the absorbed parameters, where we would really want the unconditional variance. Am I misunderstanding what is going on here? I haven't found any good explanations in the help files.
Comment: BrentL given that the SAS code- and SAS help-related aspect of the question would be [off topic](http://stats.stackexchange.com/help/on-topic) (see under programming there), could you explain what "absorbing" is? If you clarify that, the remainder of the question (about how it impacts standard errors) should be on topic.
Answer: In SAS, if you ABSORB a variable in PROC GLM, it adjusts its effects but does not include it in the VCV matrix of the estimated parameters. This means that the other parameter standard errors and other inferential statistics (such as confidence intervals and p-values) are conditional on the absorbed variable. They do not account for the variability created by evaluating the impact of the absorbed variable.
This conditional method may result in underestimating of standard errors for the other parameters in your model, which may result in too tight confidence intervals and reduced p-values. This can be especially troublesome if the absorbed groups vary significantly or if their effects are important in your research.
Personally I would rather use a model with random effects for a categorical variable with a very large number of levels, if you are interested in individual level inference. PROC MIXED and PROC GLIMMIX are able to fit a wide range of mixed effects models. If you are interested in population level inference then generalised estimating equations with PROC GENMOD.


Rewriting state-space to error dynamics in order to achieve tracking a constant

Question: Given the following system
$$\begin{equation}
    \begin{bmatrix}
    \dot{x_1} \\ \dot{x_2}
    \end{bmatrix} =
    \underbrace{\begin{bmatrix}
    0 & 1 \\ -2 & 3
    \end{bmatrix}}_A\begin{bmatrix}
    x_1 \\ x_2
    \end{bmatrix} +
    \underbrace{\begin{bmatrix}
    0 \\ 1
    \end{bmatrix}}_B u,
\end{equation}$$
I which to track $x_1 = x_2 = r$, where $r$ is a piece-wise continuous constant value. This is equivalent to driving $x_1-r$ and $x_2-r$ to $0$. The pair $(A,B)$ is controllable. I rewrote my state-space in terms of error dynamics with states $z_1 = x_1-r$ and $z_2 = x_2-r$. \begin{equation} \label{eq:rewritten}
    \begin{bmatrix}
    \dot{z_1} \\ \dot{z_2}
    \end{bmatrix} =
    \underbrace{\begin{bmatrix}
    0 & 1 \\ -2 & 3
    \end{bmatrix}}_A\begin{bmatrix}
    z_1 \\ z_2
    \end{bmatrix} +
    \underbrace{\begin{bmatrix}
    0 \\ 1
    \end{bmatrix}}_B u,
\end{equation}
The output is given by
\begin{equation}
    y = \begin{bmatrix}
    y_1 \\ y_2
    \end{bmatrix} = \begin{bmatrix}
        1 & 0 \\ 0 & 1
    \end{bmatrix}\begin{bmatrix}
    z_1 \\ z_2
    \end{bmatrix} = \begin{bmatrix}
    z_1 \\ z_2
    \end{bmatrix}
\end{equation}
Now, if I know the reference $r$, let's say it's 1, how can solve this tracking problem by just using the error dynamics state-space (so no adding integrators)?
Comment: Are you sure that what you want to do is even possible?
Comment: I am actually unsure, but in that case, I'm unsure how to prove the impossibility.
Answer: Let us consider the control law $u=Kx+v$ where $K$ is the state-feedback gain and $v$ is an exogenous input. This the maximum you can do with your assumptions.
The closed-loop system is given by
$$\begin{bmatrix}\dot{x}_1 \\ \dot{x}_2\end{bmatrix}=\begin{bmatrix}0 & 1\\-2+k_1 & 3+k_2\end{bmatrix}\begin{bmatrix}x_1\\x_2\end{bmatrix}+\begin{bmatrix}0\\1\end{bmatrix}v,$$
where $K=\begin{bmatrix}k_1 & k_2\end{bmatrix}$.
Now we need two things: 1) The closed-loop system should be asymptotically stable (i.e. $A+BK$ Hurwitz stable), and 2) $v$ should be chosen such that $x_1,x_2$ are both equal to $r$ at equilibrium.
The first objective is achievable since your system is controllable. So, we can safely assume that we have a gain $K$ such that $A+BK$ is Hurwitz stable. We show now that the second objective is not achievable. Let $x_1^*,x_2^*$ be the values of $x_1,x_2$
at equilibrium. Solving for the system of equations, we get
$$\begin{bmatrix}x_1^*\\x_2^*\end{bmatrix}=-\begin{bmatrix}0 & 1\\-2+k_1 & 3+k_2\end{bmatrix}^{-1}\begin{bmatrix}0\\1\end{bmatrix}v.$$
This can be simplified to
$$\begin{bmatrix}x_1^*\\x_2^*\end{bmatrix}=\dfrac{1}{2-k_1}\begin{bmatrix}1\\ 0\end{bmatrix}v.$$
Obviously, the second state cannot be set to anything else than 0 at equilibrium. In fact, this can be easily explained since the first state is the integral of the second, so if we want the system to reach an equilibrium then $x_2^*$ must necessarily be zero.
If you just want the first state-to be equal to $r$ at equilibrium, this is fairly easy. You just need to set $v=(2-k_1)r$ and $K$ such that $A+BK$ is Hurwitz stable.


PHP: Number of bytes in a string, raw HTTP

Question: I am trying to get the number bytes in a PHP string. I seem to be running into a problem trying to send raw HTTP requests (PROPFIND, REPORT), and getting the proper length of the content. From which point, following the headers, do I start counting the content? And at which point, do I stop?
Comment: I didn't understand much, but if it doesn't have to do with dynamic content, you may want to just read the `Content-Length` header.
Answer: You count the complete content, starting after the two linebreaks that delimit the header section:
$contentlength_bytes = strlen(strstr($http, "\r\n\r\n")) - 4;

If you're doing it that way already i guess you might have run into problems with encoding...
When your content has multibyte characters, using strlen() to return it's bytelength might not work correctly as multibyte characters might get interpreted as one byte under certain system configurations (see edit below - and comments for that part).
This will give you the correct bytelength of any content-string you feed it under any system configuration:
$contentlength_bytes = mb_strlen(strstr($http, "\r\n\r\n"), 'latin1') - 4;

Edit:
As Jon pointed out in the comments, this is not always needed as strlen() will return the correct bytecount of a string in most circumstances.
I just added this method of measuring as on multibyte systems and under certain circumstances (for example mbstring.func_overload set to 2) strlen() is not safe to use against binary strings.
The above method is the only known (to me) way to completely binary safe calculate the byte-length of a given string. And i tripped over this a couple of times already..
Comment: -1: **This is factually wrong.** Multibyte characters will be counted as multiple bytes with pure `strlen`, that's how that function works. You only need `mb_strlen` if you want the *character length*.
Comment: I know about those options (and have answered questions regarding them). But I do not accept this argument because by the same token, any code posted here that does not take into account the possibility that `magic_quotes_gpc` is on would be buggy. Those options are not standard configuration, so if you *do* enable them you should be aware of the changes in behavior. To say that `strlen` does not work because *there is an option* that makes it not work does not sit well with me. Also note that both those cases involve using "compatibility hacks" as the lesser evil.
Comment: `latin1` only contains 8byte characters, that's why. You can use any single-byte character charset for this. The `Content-Type` headers don't matter for this as you need to specify content length in bytes, not characters. PHP is a little stubborn when it comes to determine a byte length for a string. That's all that's behind this workaround. It's just a multibyte safe version of `strlen()` that will always give you bytelength regardless of encoding.
Comment: @Jon: wrong - `strlen()` is not always safe to use - for example see this problem i found when poking google with this: http://php.bigresource.com/size-of-binary-string-on-multi-byte-system--PAWEYTMl.html - i had this issue myself a couple of times. `strlen()` is only safe to use as long as you are working in a single byte encoded environment. Using `mb_strlen` with explicit 8byte charset is the only binary safe way to do this. (Except from writing to a file and using `filesize()`). Using `strlen()` on systems with enabled `mbstring.func_overload = 2` is also unsafe and will return chars.
Comment: This is not an argument, this is just my experience since i had this issue myself already. This answer was meant and formulated to be a "if you are already doing it the correct way, try this as your system configuration might be affecting strlen" type of additional hint. Sorry if that hasn't been very clear, i edited a little bit into the answer.
Comment: Downvote removed since the answer is better now. But it would be even better if an edit was made at the "using strlen to return..." part, and also if it tackled the "how do I know where the content starts?" part of the question.
Comment: I think i broke my own record for edits on a single post on this one... happy now? :)
Answer: If you have your entire request in a variable, say $request, then:
list($headers,$body) = explode("\r\n\r\n",$request,2);

Basically, the two CRLFs mark the end of the headers, and the contents start after that.
Comment: That's a good fact to rely upon (and it sounds like the right answer as well).


How to theme views using Taxonomy Terms?

Question: The site on which I'm working has a variety of views for multiple sections of the website. These different sections, which are defined by Taxonomy terms, use different themes. So, for example, sections 'X' and 'Y' each have views which we want to be displayed in themes 'X' and 'Y.'
Is there a way in Views to assign the page created by Views a taxonomy term, so that, using ThemeKey, it can be assigned a theme by it's taxonomy term, like the other nodes with that taxonomy term?
I'd really like to do this without using templates, so that it can be easily managed within Drupal's UI.
Comment: So all views will have the same tax term/theme?
Comment: After re-reading I think I would suggest not using page Views and use blocks instead. This way you can assign the tax term to the page and all pages will be under the content menu.
Comment: Different views would have different taxonomy terms and therefore, different themes. But the problem is I don't know how to assign a view a taxonomy term, or if that is even possible.
Comment: Honestly I think you should consider using block displays instead of page displays. You can then use Contextual filters if necessary to use the tax term as an argument in your view once you set it for the node.
Answer: Are you saying that you are using the not-yet-stable 7.x module Taxonomy Theme? Terms are assigned by Term Reference fields on fieldable entities.  Since drupal is open source, there is always more than one way to do something.  If you wanted to build a site that can do exactly as you have asked here, then I suppose it is possible to make a new entity that has a term reference and also embeds the view in its custom theme processes to get the fusion you are requesting.  You will have to crawl into the Taxonomy Theme module code and see if it is using hook_node_view to do the check/change.  If so, it would not fire on a straight view anyway but this custom entity (maintenance nightmare) should trigger it.
An easier method would be the template files that you dont want.  Use theme_hook_suggestions where you have different tpl.php files for the different views based on path or whatever else you want.  Different templates by path alias.  You then just have the different templates use the different theme styles.  I would also recommend putting the taxonomy term values as body level css classes so you can have one theme, and it just trigger different stylesheets based on term classes. Option1 | Option2  This would relieve your dependence on the dev-version module.
Option 3.  In whatever theme is your default, copy the relative style sheets over from the other themes and just use the view-specific css class for each one, applying it manually.  This means that you have duplicated style commands, so it will be a little harder to maintain what is coming from where, but at least you dont have to code any php.
Option 4.  Sareed's comment about using block displays and embedding the views on other pages that have the terms.  (...I should have thought of that)
Comment: We are using the ThemeKey module to define themes (not Taxonomy Theme). Currently, it is configured to use the URL of a page to determine the theme that page will take. We would like to change this so that ThemeKey, instead, reads the taxonomy term of a page and determines the theme this way. The reason for this is so that the Theme and the URL are both using the Taxonomy term of a page to define the theme and URL so its not a daisy-chained set-up of taxonomy -> URL -> theme. I hope that makes sense.
Comment: That makes sense, but I think it is adding complications.  With the URL as the theme key, you now have the taxonomy portion of the process as optional.  For the views, you can specifically put in the path the term you want without it being a term, and thus evoke the right theme.  The configuration that you currently have is the more [orthogonal](https://en.wikipedia.org/wiki/Orthogonality_%28programming%29) choice.
Answer: In your comment you said : Currently, it is configured to use the URL of a page to determine the theme that page will take so by this assumption:
Use hook_preprocess_views_view as follow and suggest your theme
function YOURTHEME_OR_MODULE_preprocess_views_view(&$vars) {
$path = current_path();
$view = $vars['view'];
switch ($view->name) {

case 'SOME_VIEW_NAME' :
  if($path == "SOME_PATH1_OR_PATTERN1")
       $vars['theme_suggestion'][] = 'views_view__custom_blocks';

  if($path == "SOME_PATH2_OR_PATTERN2")
       $vars['theme_suggestion'][] = 'views_view__ANOTHER_custom_blocks';
break;

case 'ANOTHER_VIEW_NAME' :
  ;
break;

}
}

If the first condition get satisfied create file views-view--custom-blocks.tpl.php and theme your view.
you can also use hook_preprocess_views_view_fields to set the values of the variables of the view.


Approximative formula for normal distribution being above threshold

Question: Suppose that $X \sim \mathcal{N}(r + \frac{1}{N}, s) $ and $Y \sim \mathcal{N}(r, s)$ for some $r, s \approx 1$ and $N \approx 10^6$.
What are good approximate formulas for the quantity
$$\frac{ \mathbb{E}(X 1_{X > n})}{\mathbb{E}(Y1_{Y > n}) + \frac{1}{N}}$$
as a function of $r$ in the limit where $r \approx n$?
The problem arises as one potential answer here: https://math.stackexchange.com/questions/4555069/assessing-the-efficiency-of-a-single-vote-in-a-multiparty-presidential-election?noredirect=1#comment9582038_4555069
This problem is unanswered on MathSE:
https://math.stackexchange.com/questions/4555651/approximative-formula-for-normal-distribution-being-above-threshold
Comment: I don't see so clearly how this question connects with your question about the elections.
Answer: You can express the expectation values of normal distributions, with mean $\mu$ and standard deviation $\sigma$ truncated at 1 as
$$E[y_{\text{truncated at } 1}] = \mu + \sigma \frac{\phi\left(\frac{1-\mu}{\sigma}\right) }{1-\Phi\left(\frac{1-\mu}{\sigma}\right)} \approx \mu + \sigma \frac{\phi\left(0\right) }{1-\Phi\left(0\right)} $$
where the approximation comes from $\mu, \sigma \approx 1$.
In the case of $\mu + 1/N$
$$E[x_{\text{truncated at } 1}]  \approx \mu + 1/N + \sigma \frac{\phi\left(-\frac{1}{\sigma N}\right) }{1-\Phi\left(-\frac{1}{\sigma N}\right)}$$
this we may approximated by a linear approximation of ${\phi\left(x\right) }/(1-\Phi\left(x\right))$ around $x=0$, then we get
$$E[x_{\text{truncated at } 1}]  \approx \mu + \frac{1}{N} + \sigma \frac{\phi\left(0\right)}{1-\Phi\left(0\right)} - \frac{1}{N} \left(\frac{\phi\left(0\right)}{\left(1-\Phi\left(0\right)\right)}\right)^2  \approx E[y_{\text{truncated at } 1}] + \frac{1}{N} \left( 1 - \frac{2}{\pi} \right)$$


Escalar imagem e oculta legenda com jquery e css3

Question: Fala pessoal, estou com um problema no zoom de imagem e oculta a legenda da própria, no hover da imagem eu aumento a escala dela no css, já no jquery eu oculto a legenda, porem ao escalar, as imagens ao lado fica por cima já tentei alterar o z-index porém nao funcionou e quando uma legenda de uma imagem some, todas as outras também são ocultadas, alguém ajuda?
<?php
$Read = new Read;
$Read->ExeRead("ws_categories_product", "WHERE category_parent = '1'");
foreach ($Read->getResult() as $v) {
    extract($v);
    ?>

<?= $category_title; ?>

                <?= $category_content; ?>

            <?php
            $Read->ExeRead("ws_product", "WHERE post_category = :id", "id={$category_id}");
            foreach ($Read->getResult() as $value) {
                ?>

                        <img class="img-product" alt="<?= $value['post_title']; ?>" title="<?= $value['post_title']; ?>" src="<?= HOME; ?>/tim.php?src=<?= HOME; ?>/adm/uploads/<?= $value['post_cover']; ?>&w=460&h=300" />

                                <?= $value['post_title']; ?>

                                <?= $value['post_content']; ?>

                <?php
            }
            ?>

    <?php
}
?>

CSS:
.article-img-product {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
}

.article-img-product article {
    padding: 5px;
    width: 25%;
    /* z-index: -1; */
}
.figure-product {
    position: relative;
}
.img-product {
    -webkit-transition: all 200ms ease-in;
    -webkit-transform: scale(1);
    -ms-transition: all 200ms ease-in;
    -ms-transform: scale(1);
    -moz-transition: all 200ms ease-in;
    -moz-transform: scale(1);
    transition: all 200ms ease-in;
    transform: scale(1);
    z-index: -1;
    opacity: 0.9;
}
.img-product:hover {
    transform: scale(1.5);
    z-index: 9999;
    opacity: 1;
    /* border: 5px solid transparent; */
}

JQUERY:
$('.figure-product').on('mouseover', function () {
        $('.fig-img').hide();
    });
    $('.figure-product').on('mouseout', function () {
        $('.fig-img').show();
    });

Print1:
Answer: Cara fiz esse modelo, primeiro para esconder o texto não precisa de jQuery basta apenas quando fizer o :hover no article vc da um display:none no figurecaption, não precisa de hide() ou show() para isso.
Depois vc coloco o evento :hover no lugar errado, o ideal é que fique no container "pai de todos" no seu caso é o
 então eu mudei isso... E o z-index do article com :hover vc coloca maior dos que não tem o :hover tipo
article:hover  {
    z-index: 100;
}

Da uma olhada pra ver se isso que vc precisa.
OBS: Repare que nem precisou de JS no código! Deu pra resolver só com CSS

.article-img-product {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
}

.article-img-product article {
    padding: 5px;
    width: 25%;
    /* overflow: hidden; */
    /* z-index: -1; */
}

.figure-product {
    position: relative;
}

.img-product {
    -webkit-transition: all 200ms ease-in;
    -webkit-transform: scale(1);
    -ms-transition: all 200ms ease-in;
    -ms-transform: scale(1);
    -moz-transition: all 200ms ease-in;
    -moz-transform: scale(1);
    transition: all 200ms ease-in;
    transform: scale(1);
    z-index: -1;
    opacity: 0.9;
}

article:hover .img-product {
    transform: scale(1.5);
    z-index: 9999;
    opacity: 1;
    /* border: 5px solid transparent; */
}
article:hover .figure-product figcaption {
    display: none;
}
article:hover  {
    z-index: 100;
}

/* esse CSS é apenas para vc vsualizar a sobreposição correta das imagens, depois vc pode deleta-lo */
img {
width: 200%;
height: auto;
}

categ title

            categ content

                        post title

                        post content

                        post title

                        post content

                        post title

                        post content

Comment: Valeu!!! esqueci que poderia usar o display:none no hover, até faço isso no sub-menu do nav, obrigado, deu certinho!
Comment: @JASL isso ai! Nem sempre o jQuery é a melhor solução, principalmente para casos simples como esse. Boa sorte ai no projeto!


calculus of variations with double integral textbook?

Question: I am interested to learn about doing calculus of variations with double integrals.
i.e. maximizing a functional
$$J(f(x,y))=\int_0^1\int_0^1f(x,y)dxdy$$
w.r.t. $f$.
Are there good textbooks on this?
Comment: I believe the correct notation would be $J(f)=\int_0^1\int_0^1f(x,y)dxdy$. After all, the arguments $x$ and $y$ are exhausted within the double integral. In addition, you must specify the degree of regularity of the $f$ function. Is it class $C^1$ or just continuous?
Answer: I do not know of a book that is entirely devoted to variational cálculus in $R^2$. But I know of a collection of books that contains problems of calculus of variations in $R^2$, $R^3$ and in general in $R^n$. These problems are scattered throughout the chapters of the following books:

V. Barbu and T. Precupanu. Convexity and optimization in Banach spaces. D. Reidel Publishing Co., Dordrecht, third edition, 1986.
P. Blanchard and E. Bruning ¨ . Variational methods in mathematical physics. Texts and Monographs in Physics. Springer-Verlag, Berlin, 1992.
B. Dacorogna. Direct Methods in the Calculus of Variations. Springer-Verlag, Berlin, 1989.
B. Dacorogna. Introduction to the calculus of variations. Imperial College Press, London, 2004.
I. Ekeland and R. Temam. Convex Analysis and Variational Problems. North Holland, 1976.
M. Giaquinta and S. Hildebrandt. Calculus of Variations I. The Lagrangian Formalism. Springer, Berlin, 1996.
M. Giaquinta and S. Hildebrandt. Calculus of Variations II. The Hamiltonian Formalism. Springer, Berlin, 1996.
Struwe. Variational Methods. Applications to Nonlinear Partial Differential Equations and Hamiltonian Systems. Springer-Verlag, Berlin, 1990.
J. L. Troutman. Variational calculus and optimal control. Undergraduate Texts in Mathematics. Springer-Verlag, New York, 1996.
Comment: Wow, thanks. I have never heard of $n$-integrals. Where are these applied? physics?


How to get one or certain number of columns in json format in Laravel 5.2?

Question: Below is my code.
$users = DB::table('users')->get();
return json_encode($users);

I want to get only one column or specific number of columns in JSON format.
I am getting this output:
[{ "user_id":1,"email_id":"firstname.lastname@example.com","name":"John David" }]

I want only user_id as JSON format data.
How can I get it?
Thank You.
Answer: Try this
$users = DB::table('users')->select('user_id')->get();
return json_encode($users);

or this
$users = DB::table('users')->get(['user_id']);
return json_encode($users);

Also it would probably make your life easier to use User model class so you could then do this
$users = User::select('user_id')->get();
return json_encode($users);

or this
$users = User::get(['user_id']);
return json_encode($users);

Comment: It Worked. Thank You... :)
Comment: Please mark answer as correct than so question is closed :)


GPO backup fails

Question: When trying to backup a GPO using the GP management console (choosing the GP to backup, right click, hitting backup, and choosing a target directory "c:\ADB"), the backup fails.
In the Application eventvwr I can see the error is:
Backup of GPO failed. Error [The filename or extension is too long.]

But the detials are :
 Details -
     Source GPO:
          DisplayName: Default Domain Policy
          ID:
          Domain: accad.int

      Backup:
         Directory: \\share\
         Instance :
         Comment  :

Which doesn't help me...
How can I get to the file that fails?
How can I turn on logging that can show me how to do it?
Is there any command line method to run this backup?

After running:
PS C:\Users\administrator> import-module grouppolicy
PS C:\Users\administrator> Backup-Gpo "Default Domain Policy" -Path c:\ADBackup -Comment "Backup-08-22-14"
Backup-GPO : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 c
haracters, and the directory name must be less than 248 characters.
At line:1 char:11
+ Backup-Gpo <<<<  "Default Domain Policy" -Path c:\ADBackup -Comment "Backup-08-22-14"
    + CategoryInfo          : NotSpecified: (:) [Backup-GPO], PathTooLongException
    + FullyQualifiedErrorId : System.IO.PathTooLongException,Microsoft.GroupPolicy.Commands.BackupGpoCommand

I still don't know where to start looking for the specific path / directory that is problematic...
THANKS!!

Since I couldn't find any small app that searches files with path longer than... - I wrote one.
You can find it at :
https://sourceforge.net/projects/pathlength/
It's a very small application that allows you to search the conditions that the AD (or generally apps) require.
The only thing to remember - run it on the DC that hosts the policies files (since in my case  - the share name was shorter, but the c:...\SYSVOL was longer.
hope it will help.
Answer: You may have to troubleshoot a little further. Are you able to backup other GPOs? Did you try using an alternative admin account? Can you create a test one and back that up? If you can, then I would check permission on the previous GPO where you are receiving the error.
There is a powershell command you can use:

Backup-Gpo -Name MYGPO -Path C:\GpoBackup -Comment "Backup-08-21-14"
Comment: Have you seen my update? still stuck with it...
Comment: One other way you can backup is simply copying Policies folder. You can write a simple script to automate this process or do it manually. So basically in Windows Explorer, open: `\\local.domain\SYSVOL\local.domain\Policies` folder and copy it somewhere. In order to troubleshoot your particular issue, did you try installing RSAT tools on a Windows 7/8 machine and make a gpo backup using the gui?
Comment: Hey, I left the office already, I'll try it first thing in the morning and let you know.
I have not tried neither - a different user nor powershell script.. didn't even know it would affect. I'll let you know tomorrow :) thanks!!
Comment: I ran the backup that way - and although got a bit more information (path is longer than X chars) - it still doesn't direct me to the specific path that I need to shorten..

I also think that the paths in the backup are relative to the root, so it would not be the NTFS path that is too long.. so I really wanna find the file from a backup log, and not from an OS search.

Any ideas?

GPO backup fails


Constructing a bijection from A to A where |A| is finite satisfying ordering conditions.

Question: I'm given two total orderings, set $(A,<)$, and $(A,<')$, where $A$ has a finite cardinality and am trying to prove/disprove that there exists a unique bijection $f:A \rightarrow A$ such that $x < y$ implies $f(x)<'f(y)$ for all $x,y \in A$.
I've been attempting to construct a function $f$ that satisfies these conditions, but am not sure where to start. The two different orderings are confusing me as I'm not sure how one is to have both $x,y$ and $f(x), f(y)$ ordered differently based on a single function $f$.
Any guidance on where to begin or what to consider would be greatly appreciated.
Comment: @Masacroso What? That's false: any two finite linear orders of the same cardinality are isomorphic via a unique isomorphism.
Comment: I'm a bit confused though: "one is to have both x,y and f(x),f(y) ordered **differently**" *(emph. mine)* seems to contradict the statement of the question ("x < y implies f(x)<'f(y) for all x,y in A") in which we want *agreement*. I suspect there's  a typo?
Answer: This is a situation where I think a slightly more general question is actually going to be easier to think about, namely:

Suppose $(A,<)$ and $(B,\triangleleft)$ are two finite linear orders with $\vert A\vert=\vert B\vert$. Show that there is a unique $f:A\rightarrow B$ such that $$x<y\iff f(x)\triangleleft f(y).$$

This is a bit easier to think about in my opinion since we've freed up our mental picture by considering two different sets. It's not a substantive difference, but I suspect it will make things a bit more concrete.
Now here's my hint - which a priori is just for existence, but will quickly lead to uniqueness as well:

Where should we map the "first" (in the sense of $<$) element of $A$? What about the "second" element of $A$? Etc.

There are a couple assumptions hidden in this hint which you need to tease out and prove of course; for example, why do we know that $A$ even has a "first" element at all? This is where finiteness will come in, both in the existence and uniqueness steps. (To see why we definitely need finiteness in both pieces, show that existence fails if we consider the naturals and the negative naturals with the usual orderings, and uniqueness can fail if we take both $A$ and $B$ to be the naturals with the usual ordering.)
Comment: I see. So it's my understanding that I'd map the first element of A to the first element of B, as this would ensure that f(min(A))<x for any x in B. I understand intuitively, but how could I show this mapping mathematically? I tried f(a)=min(B) if a=min(A) and =min(B\a) if a=/=min(A), but this is not correct of course.
Comment: @wundering That's exactly right. As to the actual proof: try induction ...
Comment: should I approach it as taking the nth element in A and mapping to the nth in B? I'm not familiar with using induction on these types of problems.
Answer: A total order $<$ over a finite set $A$ is always a well-order, because every nonempty subset of $A$ is finite and hence has a minimum.
Hence $(A,<)$ is isomorphic to $(n,\in)$ through a unique order isomorphism $f\colon A \to n$, beign $n$ the unique natural number such that $n = |A|$.
Analogously, $(A,<')$ is isomorphic to $(n,\in)$ through a unique order isomorphism $f'\colon A \to n$.
Hence $(f')^{-1} \circ f$ is the isomorphism $(A,<) \to (A,<')$ that you where looking for. Moreover it is the unique one.
Comment: Going through well-orderings works, but is massive overkill in my opinion.


What's this L symbol in piano notation called?

Question: There's a symbol used in piano manuscript notation that means "play this in the other hand, even though it's written in this one". It looks like a capital L shape:

As you can (maybe) see in my bad drawing, the manuscript suggests playing the first chord exclusively in the right hand, and the second chord exclusively in the left hand (despite the fact that that's harder; it's a bad example okay?).
I'd like to use this symbol in LilyPond (because my handwriting is atrocious), but I don't know what to call it in order to search for it.
What is this symbol called?
Comment: Related questions: [What is this symbol that looks like an elongated "L" on the left-hand piano staff, and how can I write it in Musescore?](https://music.stackexchange.com/q/99571/70803); [What does the L-shaped symbol attached to C5 and G4 on the top staff mean?](https://music.stackexchange.com/q/103442/70803).
Answer: These symbols for left or right hand notes in the other staff don't really have a good names, but I've seen them called L-shaped brackets, or LH/RH half brackets in a music context.
In Elaine Gould's Behind Bars - The definitive guide to music notation on p. 305, they are called "incomplete brackets".  But this is merely descriptive and not particularly useful if you are trying to search for them.
Gould also mentions the complete "square brackets" which are used for arpeggios that are wider than the spread of both hands.  LilyPond calls these complete brackets "arpeggio brackets", as seen in links given in @Richards answer.

Unfortunately the most recent version of LilyPond still doesn't have a standard inbuilt way to print the incomplete L-shaped half brackets.
However, you can use unicode characters:

Top Left Half Bracket (U+2E22) : ⸢
Bottom Left Half Bracket (U+2E24) : ⸤

in place of fingering numbers as demonstrated below. (You'll need to tweak the Y-offset if the notehead appears in a space.)
\version "2.23.6"

\score {
    \new PianoStaff {
        \set PianoStaff.fingeringOrientations = #'(left)
        <<
            \new Staff {
                \clef "treble"
                    <c' f'>4
                    <e'-\finger"⸢">
            }
            \new Staff {
                \clef "bass"
                    <g -\tweak Y-offset #-0.5 -\finger"⸤">4
                    4
            }
        >>
    }
    \layout { }
}

Another option with more control than the unicode characters (and only slightly more code heavy) is to draw these symbols with lines and store them in macros, as demonstrated on Leigh Verlag's blog:
Answer: I'm not sure of a term, but I can at least point you to the right direction in terms of LilyPond.
These "cross-staff chords" are often notated by using an arpeggio bracket as shown here in the LilyPond Snippet Repository. It's also included at the bottom of this page in the LilyPond notation manual.
This symbol is a little bit different than what you're specifically asking for, but it's very similar.
Comment: That's the topic of my [other question](https://music.stackexchange.com/q/61989/44151) - this is good to know, though.
Comment: @wizzwizz4 Ah, so it is! I missed that one somehow.