Troubleshooting High Load on Plesk LAMP Dedicated Server

Question: I have 2 nearly identical dedicated servers with the same provider. They also run a nearly identical software stack: RedHat 5 64-bit, Plesk, PHP, Apache, & MySQL. We use them for hosting custom sites we build.
The problem is, while our 1st server has a load average (in top) of around 0.3, the 2nd server consistently has a load average of around 4.0 or higher. Basic functions in Plesk are delayed and there is a bit of latency when executing shell commands.
Anyone have ideas why it would be so high? And why it would differ from our other server so much?
Here is my current top output (sorted by %MEM) ...
Any help is much appreciated ...
<code>top - 21:48:04 up 100 days,  4:28,  1 user,  load average: 3.74, 4.20, 4.23
Tasks: 336 total,   1 running, 335 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.8%us,  0.4%sy,  0.0%ni, 91.3%id,  7.5%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  12290884k total, 11886452k used,   404432k free,  2920212k buffers
Swap:  2096472k total,      244k used,  2096228k free,  6560692k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
22536 apache    15   0  860m 547m 6484 S  0.0  4.6   0:10.96 httpd
26467 apache    15   0  859m 546m 6408 S  0.0  4.5   0:07.67 httpd
 3620 apache    15   0  859m 545m 5552 S  0.0  4.5   0:06.15 httpd
 1895 apache    15   0  858m 544m 6356 S  0.0  4.5   0:08.25 httpd
16933 apache    15   0  858m 544m 5488 S  0.0  4.5   0:01.57 httpd
 6431 apache    15   0  856m 542m 6076 S 10.6  4.5   0:05.32 httpd
14417 apache    15   0  856m 542m 5568 S  0.0  4.5   0:03.88 httpd
15403 apache    15   0  855m 541m 5616 S  0.0  4.5   0:03.73 httpd
19165 apache    15   0  853m 539m 6252 S  0.0  4.5   0:12.40 httpd
15898 apache    15   0  852m 539m 5376 S  0.0  4.5   0:02.68 httpd
14401 apache    15   0  851m 538m 5460 S  0.0  4.5   0:02.97 httpd
15393 apache    15   0  851m 538m 5404 S  0.0  4.5   0:03.12 httpd
15427 apache    15   0  851m 538m 5496 S  0.0  4.5   0:02.44 httpd
14412 apache    15   0  851m 538m 5324 S  0.0  4.5   0:02.15 httpd
18330 apache    15   0  851m 537m 5136 S  0.0  4.5   0:01.30 httpd
18303 apache    15   0  848m 535m 5140 S  0.0  4.5   0:00.47 httpd
21190 apache    15   0  845m 533m 3988 S  0.0  4.4   0:00.33 httpd
15923 root      18   0  822m 521m 9928 S  0.0  4.3  10:04.81 httpd
22021 apache    15   0  828m 520m 4964 S  0.0  4.3   0:00.16 httpd
22146 apache    15   0  823m 515m 3016 S  0.0  4.3   0:00.02 httpd
22345 apache    15   0  822m 514m 2408 S  0.0  4.3   0:00.00 httpd
14721 apache    15   0  733m 510m  488 S  0.0  4.3   0:00.00 httpd
 5094 root      15   0 1452m 122m  15m S  1.0  1.0 852:24.24 java
 4636 mysql     15   0  532m  57m 6440 S  1.0  0.5 488:05.84 mysqld
 4799 popuser   15   0  166m  53m 2368 S  0.0  0.4   0:36.64 spamd
16761 popuser   15   0  159m  46m 2312 S  0.0  0.4   0:00.38 spamd
 4797 root      15   0  158m  45m 2448 S  0.0  0.4   0:01.27 spamd
 5074 root      34  19  255m  20m 2144 S  0.0  0.2   1:37.53 yum-updatesd
 9917 named     15   0  366m 9804 1980 S  0.0  0.1   0:10.26 named
 4332 sso       18   0  119m 8028 5212 S  0.0  0.1   0:00.06 sw-engine-cgi
 4341 sso       18   0  119m 8028 5212 S  0.0  0.1   0:00.07 sw-engine-cgi
 4350 sso       18   0  119m 8028 5212 S  0.0  0.1   0:00.09 sw-engine-cgi
 4352 sso       18   0  119m 8028 5212 S  0.0  0.1   0:00.11 sw-engine-cgi
 4376 ntp       15   0 23388 5020 3896 S  0.0  0.0   0:00.58 ntpd
 4331 sw-cp-se  15   0 61336 4572 1480 S  0.0  0.0   5:53.22 sw-cp-serverd
 4213 haldaemo  15   0 31252 4460 1684 S  0.0  0.0   0:01.52 hald
 4778 postgres  18   0  117m 4164 3484 S  0.0  0.0   0:00.11 postmaster
18555 root      16   0 98.3m 3716 2852 S  0.0  0.0   0:00.01 sshd
 4488 sso       18   0  119m 3044  224 S  0.0  0.0   0:00.00 sw-engine-cgi
 4489 sso       18   0  119m 3044  224 S  0.0  0.0   0:00.00 sw-engine-cgi
 4492 sso       18   0  119m 3044  224 S  0.0  0.0   0:00.00 sw-engine-cgi
 4493 sso       18   0  119m 3044  224 S  0.0  0.0   0:00.00 sw-engine-cgi
 4490 sso       18   0  119m 3040  220 S  0.0  0.0   0:00.00 sw-engine-cgi
</code>
Answer: run something to track server behavior over time - for instance sar or even better munin. see how high-load correlates with other parameters.
problem might be related to your io system. maybe you have heavy writes on the machine with higher load? or maybe you have degraded raid? or hard drive is about to die? or raid controller has disabled cache? or something uses more memory and system needs to swap?
Comment: Will sar or munin identify any/all of those possible issues you mentioned?
Comment: @Callmeed - they will surely be helpful


Probability problem about polynomial

Question: Let $\xi$ and $\eta$ be independent random variable and their expected value and variances are $m_{\xi}, \sigma_{\xi}^2$ and $m_{\eta}, \sigma_{\eta}^2$ respectively. Consider a random polynomial $t^2+\xi t + \eta$. Let $t_1$ and $t_2$ be this polynomial roots.
I need to find the expected value of coefficients of random polynomial with roots $t_1^2, t_2^2$.
Answer: If polynomial has roots $t_1^2, t_2^2$, it must be like:
$$(x - t_1^2)(x- t_2^2) = x^2 - x(t_1^2 + t_2^2) + t_1^2t_2^2 $$
so coefficients will be:
$$a = -(t_1^2 + t_2^2)$$ and $$b = t_1^2t_2^2$$
Now we can find expected value of $a$ and $b$. From Vieta's formulas:
$$t_1 + t_2 = -\xi$$ and
$$t_1t_2 = \eta$$
Hence:
$$b=\eta^2$$ and
$$a=-((t_1+t_2)^2 - 2t_1t_2) = -(\xi^2 - 2\eta) = 2\eta - \xi^2$$
Now we can find expected value:
$$\mathbb{E}a = 2m_{\eta} - \sigma_{\xi}^2 - m_{\xi}^2$$
$$\mathbb{E}b = \sigma_{\eta}^2 + m_{\eta}^2$$

Probability problem about polynomial


How do I disable a fieldset?

Question: I read How to unset fieldset in hook_form_alter? to disable fieldsets in an hook_form_alter() implementation, but it didn't work.
I tried using the following code, but neither of them worked.
// First try.
foreach ($form['#fieldgroups']['group_employment']->children as $form_element_id) {
  $form[$form_element_id]['#attributes']['disabled'] = TRUE;
}

// Second try
foreach ($form['#fieldgroups']['group_employment']->children as $form_element_id) {
  $form[$form_element_id]['#attributes']['disabled'] = 'disabled';
}

How can I disable fieldsets?
Comment: you work with field_group module ?
Answer: You can not access directly to #fieldgroups in form_alter you should add pre_render function like the following:
function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if ($form_id == 'YOUR_FORM_ID') {
    $form['#pre_render'][] = 'mymodule_form_pre_render';
  }
}

/**
 * @param $form
 *
 * @return mixed
 */
function mymodule_form_pre_render($form) {
  foreach ($form['#fieldgroups']['group_employment']->children as $form_element_id) {
    $form[$form_element_id]['#access'] = FALSE;
  }
  return $form;
}

Edit :
if you want to just disable the fields change the pre_render function by:
function mymodule_form_pre_render($form) {
  foreach ($form['#fieldgroups']['group_employment']->children as $form_element_id) {
    if (isset($form[$form_element_id])) {
      //- For entity reference fields
      if (isset($form[$form_element_id]['widget'][0]['target_id'])) {
        $form[$form_element_id]['widget'][0]['target_id']['#attributes']['disabled'] = 'disabled';
      }
      //- For normal input form
      if (isset($form[$form_element_id]['widget'][0]['value'])) {
        $form[$form_element_id]['widget'][0]['value']['#attributes']['disabled'] = 'disabled';
      }
    }
  }
  return $form;
}

Comment: How can I disable the fieldgroup? I can unset them successfully but how can I set the disable attribute?
Comment: i edited my answer check it out.

How do I disable a fieldset?


Differential equation question

Question: Consider the differential equation $\dfrac{dx}{dt}=x^3−x^2−6x$ .
Find all equilibria.
Determine the stability of each equilibrium analytically (not from the phase line diagram).
Sketch the phase-line diagram.
I have solved---
$x=-2$ (unstable), $0$ (stable), and $3$ (unstable)
Comment: what have you done?
Comment: I have done all parts of the question except i do not know how to sketch the phase plane diagram for this equation.
Comment: can you add your contribution to the question?
Comment: Equilibrium: x= -2, 0, and 3
Comment: Edit the question. Then what have you done concerning stability?
Comment: x= -2(unstable), 0(stable), and 3(unstable)
Answer: I see you showed two parts of the problem solution in the comments and it is important to show your work!
The equilibrium are found by solving:
$$x' = x^3 - x^2 - 6x = 0 \implies x_{1,2,3} = -2, 0, 3$$
To analytically test stability, we evaluate the derivative of $f(x) = x^3 - x^2 - 6x$ at each equilibrium point and this yields:

$f'(x) = 3x^2 - 2x - 6$
$f'(-2) = 10 \gt 0 \implies$ unstable
$f'(0) = -6 \lt 0  \implies$ stable
$f'(3) = 15 \gt 0  \implies$ unstable

A phase line is:
$~~~~~~~~~~~~~~$
Compare the phase line drawing to a direction field plot and what do you notice?

Differential equation question


How to estimate log-normal distribution parameters from a set of data?

Question: I don't have any background in statistics, so maybe I may say things that are incorrect.
I have to model the production of waste deposition at each container of a set of containers and I have access to the values of the fill-up rates for certain intervals of time. I need to generate future values based on the historical past values.
First I thought that a Normal Distribution could be adopted, but since there's no negative waste deposition rates I thought on using the Log-Normal Distribution as it starts at the zero value.
Imagine that I have the following ten values: 5; 0; 9; 2; 6; 4; 1; 0; 5; 3
My question is: How can I obtain the parameters μ and σ that are needed to model the probability distribution?
I see that an approach is to use:
But then, since I have values of xk that are 0, I have ln (0) which is a problem that I don't know how to work around.
From the wikipedia page I see also that when the individual values  x1,x2,...,xn   are not available I can calculate the parameters using the following formulas:
So, from my sample, $\bar{x}$ = 3.5 and $\hat{\sigma}$ = 2.8771. So, can I say that μ and σ are equal to 0.9946 and to 0.7185, respectively?
If yes, then what bugs me the most is that I have the individual values but some of them happen to be 0. How could it be that I could use those first formulas only if the values are different than 0?
Any help would be great! Thank you in advance!
Comment: The support of the lognormal distribution is $(0, +\infty)$. The fact that you have values of $0$ thus immediately rules out the lognormal distribution as a suitable model for these data. What exactly do these fill-up rates mean (e.g. what does a value of $5$ mean)?
Comment: @COOLSerdash given we know that there are exact 0's, the beta itself would be unsuitable for the same reason the lognormal is. A 0- & 1- inflated beta might be a better choice.
Comment: A value of 5 means that for a specific day a container was filled up by 5%. A value of 0 represents that no waste was deposited during that day. If there are 0 values but no negative ones, what suitable models could be used to characterize this?
Comment: So it's always a percentage between 0% and 100%? Am I understanding this correctly?
Comment: Yes. It could get overfilled, but let's neglect that
Comment: The [Beta distribution](https://en.wikipedia.org/wiki/Beta_distribution) is commonly used to model proportions. It would be helpful if you would edit your question to explain *why* you need a distribution for these fill-rates. What do you hope to learn from such a model?
Comment: To simulate future values based on the past values.
Comment: +1 for a 0 inflated model. The actual model for the positive data is irrelevant, you can use some model fit statistics like a BIC to decide, but the problem is a continuous model will never predict exactly 0 yet you seem to encounter such issues when no actual waste is deposited.
Comment: Does your business case require you to know the wast in each individual container, or is it ok to just know the mean? In the latter case you can model the sum and for that a model with a normal distribution might be sufficient.
Answer: Because your data appear to be rounded to the nearest integer, "0" really means some value in the interval $[0, 1/2]$ and "$k$" for $k\gt 0$ means some value in the interval $[k-1/2, k+1/2].$  Let's denote that interval as $[k^-,k^+],$ even for $k=0.$
Writing $\Phi$ for the Normal distribution, the likelihood that the parameters of $\log X$ are $(\mu, \sigma)$ for data $x_1, x_2, \ldots, x_n$ therefore is
$$\mathcal L = \prod_{i=1}^n \left(\Phi(\log x_i^+;\mu,\sigma) - \Phi(\log x_i^-;\mu,\sigma)\right).$$
Here, when $x_i=0$ and (therefore) $x_i^-=0,$ take $\log 0 = -\infty$ for the sake of computing.  Since $\Phi(-\infty;\mu, \sigma) = \lim_{x\to-\infty}\Phi(x;\mu,\sigma)= 0$ there is no problem.
This is readily maximized numerically to give a Maximum Likelihood estimate for the parameters.  For the data in the question, the estimates are $\hat\mu = 0.7652$ and $\hat\sigma = 1.2155.$  These are close to crude estimates $\hat\mu = 0.7613,$ $\hat\sigma = 0.1.2856$ obtained by using the midpoints of the intervals: that is, replacing $[0,1/2]$ by $1/4$ and replacing $[k-1/2, k+1/2]$ by $k$ throughout and estimating $\mu$ as the mean logarithm and $\sigma$ as the standard deviation of the logarithms.  But there is a difference in the estimates of $\sigma,$ suggesting something might be gained by the more careful calculation.
(In response to a long-standing answer in this thread, replacing the zeros by $0.00001$ gives $\hat\sigma = 5.4,$ which is grossly wrong.  The reason is predictable: the logarithms of $0.00001$ are so far from the data that they exaggerate the value of $\sigma.$)
The following R code does the work.  It minimizes $-\log \mathcal L$ as a function of $\mu$ and $\log \sigma$ (thereby avoiding the usual numerical problems and requiring no constraints).
With the estimated parameters in hand, you can generate additional random values easily: use them to generate Normally distributed values and then exponentiate and round them.
#
# Negative log likelihood of theta = (mu, log sigma).
#
lambda <- function(theta) {
  mu <- theta[1]
  sigma <- exp(theta[2])
  -sum(log(pnorm(log(x + 1/2), mu, sigma) - pnorm(log(pmax(0, x - 1/2)), mu, sigma)))
}
#
# The data (nonnegative integers).
#
x <- c(5,0,9,2,6,4,1,0,5,3)
#
# Use the midpoints for an initial estimate.
#
y <- log(pmax(1/4, x))
theta <- c(mean(y), log(sd(y)))
#
# Maximize the likelihood.
#
b <- nlm(lambda, theta)
#
# Extract the estimates.
#
m <- b$estimate[1]
s <- exp(b$estimate[2])

Answer: Pad it with an arbitrary small number, e.g. 0.00001; basically your minimum precision. It will yield a highly negative value of the logarithm, but that's fine.
Assuming the production was continuous in time, you can never actually measure a point where it's exactly zero in reality anyway, it's asymptotic too, so it's not entirely unprincipled.
Comment: The "yield a highly negative value" looks like it's going to bias any estimation procedure strongly, so please explain why you think this is "fine."
Comment: +1 or +0.1 or +0.01 turns out to be very arbitrary and very hard to generalize in predictive modeling in my experience.


Why JSONB is returning as a string?

Question: I have started a "instagram clone" backend to try learn somethings about golang, but I'm having a problem that I do not know how to solve.
I have build a simple API with Fiber that get some posts:
package server

import (
    "fmt"
    "instagram/internal/psql"
    queries "instagram/internal/sql"
    "net/http"

    "github.com/gofiber/fiber/v2"
)

type Like struct {
    Username string
    Name     string
    picture  string
}

type Post struct {
    Id          string `json:"id"`
    Description string `json:"description"`
    Media       string `json:"media"`
    Type        string `json:"type"`
    Likes       string `json:"likes"`
    User_id     string `json:"user_id"`
    Created_at  string `json:"created_at"`
    Updated_at  string `json:"updated_at"`
}

func ListPosts(c *fiber.Ctx) error {
    rows, err := psql.DB().Query(queries.GetAllPosts)

    if err != nil {
        c.SendStatus(400)
        return nil
    }

    defer rows.Close()
    var data []Post

    for rows.Next() {
        var post Post
        err := rows.Scan(&post.Id, &post.Description, &post.Media, &post.Type, &post.Created_at, &post.Updated_at, &post.Likes, &post.User_id)
        if err != nil {
            fmt.Print(err)
            c.SendStatus(400)
            return nil
        }

        data = append(data, post)
    }

    return c.Status(http.StatusOK).JSON(data)
}

The problem is that likes attribute is returning as a string:
[
    {
        "id": "...",
        "description": "...",
        "media": "...",
        "type": "...",
        "likes": "[]",
        "user_id": "...",
        "created_at": "...",
        "updated_at": "..."
    }
]

I have tried some things, like use json.Marshal(data), I also wrote that Like struct, but I could not make it work, because when I change the type of Likes from string to []Like the following message appears when Scan is called

sql: Scan error on column index 6, name "likes": unsupported Scan, storing driver.Value type []uint8 into type *[]server.Likesql: Scan error on column index 6, name "likes": unsupported Scan, storing driver.Value type []uint8 into type *[]server.Like

I'm using a postgresql database, and I'm trying to work with jsonb columns for the first time, so likes is in the database a jsonb column.
My ideal payload would be like:
[
    {
        "id": "...",
        "description": "...",
        "media": "...",
        "type": "...",
        "likes": [],
        "user_id": "...",
        "created_at": "...",
        "updated_at": "..."
    }
]

Note that likes is now a array instead of a string. So anybody knows how to solve this?
Answer: You most likely need to implement the interface for sql.Driver to "know" how to scan into your struct, probably something like
type Like struct {
    Username string
    Name     string
    picture  string
}

type Likes []Like

func (l Likes) Value() (driver.Value, error) {
    return json.Marshal(l)
}

// Make the Likes implement the sql.Scanner interface.
func (l *Likes) Scan(value interface{}) error {
    b, ok := value.([]byte)
    if !ok {
        return errors.New("type assertion to []byte failed")
    }

    return json.Unmarshal(b, &l)
}

Answer: Maybe that's just because the database driver you use does not support the data type jsonb.
I have tested the package github.com/jackc/pgx/v5, and it can decode the jsonb field correctly. See the example below:
package main

import (
    "context"
    "log"

    "github.com/jackc/pgx/v5"
)

func main() {
    // remember to modify the connString below.
    connString := "postgres://username:password@localhost:5432/database_name"
    conn, err := pgx.Connect(context.Background(), connString)
    if err != nil {
        log.Fatalf("Unable to connect to database: %v\n", err)
    }
    defer conn.Close(context.Background())

    type Like struct {
        Name    string
        Picture string
    }

    type Post struct {
        Id    string
        Likes []Like
    }

    var post Post
    err = conn.QueryRow(context.Background(), `select 'the_id', '[{"name":"a","picture":"a.png"},{"name":"b","picture":"b.png"}]'::jsonb`).Scan(&post.Id, &post.Likes)
    if err != nil {
        log.Fatalf("QueryRow failed: %v\n", err)
    }

    log.Printf("%#v", post)
}

Output:
main.Post{Id:"the_id", Likes:[]main.Like{main.Like{Name:"a", Picture:"a.png"}, main.Like{Name:"b", Picture:"b.png"}}}

Why JSONB is returning as a string?


Can a switch that doesnt know anything about 802.1ae macsec route macsec frames?

Question: If one device (e.g. A wireless router) is attempting to communicate with another device (e.g. some gateway to another network) through a unmanaged switch and the router is ciphering frames it transmits using 802.1ae macsec (which the gateway also supports), but the switch that connects them doesn't know anything of 802.1ae and can't decipher the portions of the message that are ciphered, will the switch still be able to route the message between the two?
Or nominally, would most switches drop the message, in this case?
For managed switches, which need to read the VLAN ID from the encrypted part of the message, I assume it would drop it if it didn't support 802.1ae.
But for unmanaged switches, it would seem (nominally) that it would be able to route it correctly based solely on the mac address.
Answer: Frames, like 802.1X or 802.1AE (protocols that apply to multiple LAN type use capital letters) use a special multicast OUI (01-80-C2) defined by the IEEE that prevents bridges (switches) from forwarding them to any other interface.
That means that MACsec (802.1AE, a superset of 802.1X) cannot cross a bridge that doesn't know how to use it. The same applies to all the 802.1x protocols. See the IEEE 802.1D™-2004 standard.

But for unmanaged switches, it would seem (nominally) that it would be
  able to route it correctly based solely on the mac address. But maybe
  that's not a correct assumption.

By the way, switches do not route. Routing is a layer-3 function, but bridges (switches) switch at layer-2.
Comment: Apologies, but I'm not sure I understand the point about the OUI value which you mentioned - In performing simple Google searches, there are plenty of examples of network captures, where the OUI in the MAC is the actual organizational value (e.g. http://costiser.ro/uploads/macsec-encrypt-on-vs-off.png).
Comment: @Rob: That's merely the capture software/package resolving the first three octets of the MAC address to the OUI of the organization to which that OUI has been assigned. That's not how the MAC address appears in the actual Ethernet frame.
Comment: @Rob, the IEEE has reserved that OUI for Link-Local protocols, including 802.1X and 802.1AE. Frames with those protocols are sent to a destination MAC address with that OUI. Any frames sent to an address with that OUI are not allowed to be forwarded to a different bridge interface. That is why they are Link-Local protocols.
Comment: @RonMaupin This appears to be in contradiction with the notion in example 1 of https://developers.redhat.com/blog/2016/10/14/macsec-a-different-solution-to-encrypt-network-traffic#lan that two peers can use end-to-end Macsec over a unaware switch.
Comment: @ysdx, I would suggest not depending on any particular switch model ignoring the IEEE standards. There are certainly some switch models that blindly ignore such frames, but the IEEE sets ethernet and MAC standards, and frames with such a link-local, multicast OUI are not supposed to be sent to other interfaces, and business-grade switches are likely to follow the standards.
Answer: Switches which are not MACsec-capable can, in general, forward Ethernet frames which have been authenticated and/or encrypted with MACsec. RedHat has a blog post here with some pictures, and it describes this case as "the main use case for MACsec". This clearly makes sense, or the chances of MACsec adoption would be next to zero.
As you more-or-less say, the switch will forward frames based on an internal routing table which is loaded only with MAC addresses, which are in the clear in MACsec. The OUI stuff mentioned elsewhere is only relevant to MKA setup.
There is an issue with VLANs, as you point out. The 802.1Q tag is beyond the SecTAG and will be encrypted (if encryption is enabled). Vendors generally have work-arounds to prevent tag encryption, which you may be able to use - look up "802.1Q tag in the clear", for example.
Comment: This is a great answer and should be the accepted one. Page 10 of https://www.cisco.com/c/dam/en/us/td/docs/solutions/Enterprise/Security/MACsec/WP-High-Speed-WAN-Encrypt-MACsec.pdf describes exactly this. What would be the purpose of Q tag in the clear otherwise?
Comment: Wouldn't setting up several MACsec networks be an alternative to using VLANs?


PHP find function without found element html

Question: I'm trying to figure out how to grab the string inside H1 without actually H1 inside the string.
$html = "

hello world

"

foreach($html->find('div[id=test] h1') as $test1){
        echo '
';
        echo $test1;
        echo '
';
}

$test1 returns "
hello world
"

I'd like for $test1 to be just "hello world" and without the h1 tags.  Thank you in advance
Comment: That doesn't appear to be valid PHP at all.
Comment: `echo "".strip_tags("hello world")."";`
Comment: Ahh, strip tags. Thank you so much!
    echo strip_tags($test1);
Answer: You can use regex for this:
$str = '

hello world

';
$matches = array();
preg_match('/
(.*)<\/h1>/', $str, $matches);
echo $matches[1];

Outputs: hello world

Docs:

http://www.php.net/preg_match

Demos:

https://eval.in/78867
http://regex101.com/r/lG3dO8
Comment: I like this answer, however, strip tags works well for me too. Thank you for answering


Changing programmatically print area in OpenOffice Calc

Question: I'm creating a Calc document on the fly with vb6. I need to repeat 1 row and 1 column in every page when i print it.
This is the code:
<code> Dim mPrintOptions(2) As Object
 Dim OO_Dispatcher As Object
 Set OO_Dispatcher = oServiceManager.createInstance("com.sun.star.frame.DispatchHelper")
 Set mPrintOptions(0) = MakePropertyValue(oServiceManager, "PrintArea", "")
 Set mPrintOptions(1) = MakePropertyValue(oServiceManager, "PrintRepeatRow", "$A$2")
 Set mPrintOptions(2) = MakePropertyValue(oServiceManager, "PrintRepeatCol", "$A$1")

 OO_Dispatcher.executeDispatch oDeskTop, ".uno:ChangePrintArea", "", 0, mPrintOptions
</code>
I've got this code making a macro in a saved document.
Service manager and Desktop objects are previously instanced. The document is being created fine, but when I send it to the printer it does not repeat the row and the column I specified above.
Answer: I've found my solution here:
https://wiki.openoffice.org/wiki/ES/Manuales/GuiaAOO/TemasAvanzados/Macros/StarBasic/TrabajandoConCalc/Imprimiendo
My code finally got like this:
<code>Dim OO_TitulosR As Object
Dim OO_ActiveSheet As Object
Set OO_TitulosR = OO_Document.Bridge_getStruct("com.sun.star.table.CellRangeAddress")
Set OO_ActiveSheet = OO_Document.getCurrentController.getActiveSheet
OO_TitulosR.StartColumn = 0
OO_TitulosR.EndColumn = 0
OO_TitulosR.StartRow = 1
OO_TitulosR.EndRow = 1
OO_ActiveSheet.setTitleColumns OO_TitulosR
OO_ActiveSheet.setTitleRows OO_TitulosR
</code>


An error occurred loading a configuration file: Failed to start monitoring changes to '\\share'

Question: I had this same problem last week, which resolved itself after I enabled impersonation. Now, I've moved this box to a different location and am now receiving it again. However, this time it is much less descriptive. The only error I'm receiving is:
<code>An error occurred loading a configuration file: Failed to start monitoring changes to '\\share'
</code>
I've changed both the web server and file server's local administrator password to what it should be and also the power user that connects between. I've even hit the share from the local machine using both accounts and can see the files no problem.
Any ideas what can be causing this?
TIA!
Comment: After 15 minutes, it worked out of the blue. I'll reopen if necessary.
Comment: For me work this perfect (build succeeded)
http://www.jlgaines.net/2011/04/how-to-run-visual-studio-2010-on.html
Answer: Reboot and be patient for IIS7 to figure things out and after 15 minutes, it should just work.


is there supposed to be a default folder in sites/default?

Question: Just noticed I have a default folder in my sites/default folder so that I have sites/default/files and sites/default/default/files
Found out-
The node with audio file upload is HIDING the file as protection from third party download.That is why only occurring with that particular content type.
Comment: Have you configure `multisite` feature in your Drupal site?
Comment: yes it is a multi-site
Comment: I know what has happened now. The node with audio file upload is HIDING the file as protection from third party download.
Answer: It depends what you mean by 'supposed to'.
Drupal core doesn't place that folder there, no. But that doesn't mean that someone/something else hasn't. You'd have to give us that information, we couldn't possibly know.
What I will say is that no module should be writing to that path unless you've explicitly told it to, and if you have your permissions set up correctly, then the web server won't have been responsible for creating the folder.
Again, though, impossible to say from here.
Comment: I know what has happened now. The node with audio file upload is HIDING the file as protection from third party download.
Answer: A sites/default/default/* structure is certainly a-typical of a standard install.
A possible source for this odd behavior is accidentally configuring your Drupal installation's public or private files directories that way.
It's not necessarily wrong, but it could be an indicator of misbehaving modules.  If module code introduced the extra default directory it could be possible the same module is ignoring other expected/appropriate methods to handle files.
Comment: I know what has happened now. The node with audio file upload is HIDING the file as protection from third party download.
Comment: Interesting.  I'll have to take a look at that module and see what they're doing.  Seems like an unusual approach.


Is it reasonable to use Chi Square data in a bivariate analysis?

Question: I am currently working on a report about the frequency of hand types in Texas Hold'em and whether or not the frequencies change when there are multiple players involved. For example, is there a change to the frequency of straights when there are five players compared to when there is one player? With each player having two whole cards and five community cards used by each player?
I am trying to answer this question through simulation. I wrote a program to simulate as many hands as needed with $n$ number of players ($n$ is user inputted). The program performs a $\chi^2$ test with the observed number of each hand type and the expected number of each hand type for any set of seven random cards.
What I am unsure about is how I should use this $\chi^2$ data? My current approach is to perform $10-20$ tests each ($10$ million hands per test) for $2$ through $10$ players, then plot the median $\chi^2$ value vs. number of players to see if there is any correlation between the number of players and the difference in hand frequency from the expected value.
Is it appropriate/meaningful to use $\chi^2$ data in this way? Or should I use a different approach to make a conclusion about my original question?
Comment: Changing the number of players should not change the frequency of particular hands dealt for an individual.  But what will change with the number of other players is betting and folding strategy, so there may be a change in the number of times an individual sees all the community cards while still playing with particular hands.
Answer: I think one of the issues here is that you have potentially several categories here with the number of players involved, which makes interpretation with the chi-square difficult to ascertain. If you run a $\chi^2$ test on something with 10 categories against some other categorical variable (this is specifically a chi-square test of independence), you have to remember that this functions like an omnibus test...sure it will tell you there is some general difference in hand x player associations, but it won't tell you specific differences other than some vague inspection of your counts. What's more, because it only tests the overall association, you are more likely to have a flagged test with many heterogenous groups, but what this means in practice is vague without something quantifiable like phi-coefficients, which are still generalizations that are not going to tell you exactly the relationship between the categories here.
What may be a lot more illustrative is running the simulations but replacing it with a regression model instead. One option may be an ordinal logistic regression, with hand type as your outcome and number of players as your predictor. Number of players could be treated as continuous or categorical. I imagine it would be much more illustrative to use a continuous analysis, as it will give you a better idea of the overall trend (I doubt for example you have any specific hypotheses about $n_{players} = 6$). From there you could obtain probabilities from the model and make an approximation of what predictions your model should illicit.
You may be interested in the book Analysis of Categorical Data in R. R is particularly well suited for both simulation and statistical analysis, so this book may be a good compliment for your use case, and I believe that Chapter 3 covers multinomial cases such as these (one example I recall is a wheat kernel analysis where they treated the kernel type as response and several predictors of each).


How to send different-encoded data through same stream?

Question: I wanna send images and texts from android client to Node.js TCP server.
You know the size of data in 'data' callback in Node.js is unpredictable.
My question is how can the server separates images and texts?
I think it's impossible, so I will divide the stream(make another server) or
encode image using base64...but,
If you have any opinion, welcome!
Answer: No matter what, you will have to incorporate some sort of protocol. If you want to use binary as-is without encoding it, you will have to pick (or create) a protocol that supports that.
You could use something like WebSockets, but that only solves the framing problem. You still need to define your own message format (since IIRC WebSockets does not provide fields in its protocol for end user use). So with that in mind, you may as well just DIY.
One easy solution might be to create a TLV (Type-Length-Value) protocol. This kind of protocol is one where you have a type field, followed by a length field, and then a data field that is [length field value] bytes long. Make the fixed sizes of the type and length fields large enough to support your use case. As an example, you might have the type field be a single byte (allowing 256 message types), and have the length field be 4 bytes (allowing a single message to contain up to 4GB of data). Parsing these messages is simple: read 5 bytes, which gets you the type and length, then parse the latter 4 of the 5 bytes as an unsigned 32-bit integer, and then read that many bytes. You can buffer the data or stream it, whatever your need may be.
Comment: TLV.. it is very helpful hint! Thanks:)
Comment: But I wanted to minimize server processing because the server have to work like a proxy as many as possible.
I was just wondering...anyways, thanks!
Comment: I think TLV-style protocols are about as minimal as you can get. It's just reading 5 bytes, then n bytes, then repeat.


How to find $\lim_{n\to\infty}\frac{n}{\log(n)^k}$?

Question:
How to find
  $$
\lim_{n\to\infty}\frac{n}{\log(n)^k}\ \ ?$$

I know the limit is infinity, but I can't manage to do it step by step using l'Hopital. Could someone explain how it is done?
Comment: Why won't you simply write $$\frac n{(\log n)^k}\;?$$ This must make things really simpler.
Comment: @DonAntonio, I guess that only the $n$ is raised to the power $k$ as in $log [(n)^k]$ and not the entire $log (n)$
Comment: After simplifying, as @DonAntonio suggested, check https://socratic.org/questions/how-do-you-find-the-limit-of-ln-n-n-as-n-approaches-infinity
Comment: @NoChance Perhaps so...and then the limit is even simpler!
Comment: You are true, I should have written $$\frac{n}{\log(n)^k},\qquad\mbox{ as $n\to\infty$}.$$ my problem is to apply the derivate to  $log(n)^k$ as the derivative is another logarithm https://math.stackexchange.com/questions/18069/derivative-of-logkx so, how can I simplificate to solve the limit?
Answer: L'Hopital's Rule shows $\frac {e^{x}} {x^{k}} \to \infty$ as $x \to \infty$. Put $x =\log \, n$.
Comment: But the top part would be $e^x$ instead of $x$ is it relevant for the limit?


What chords does Rule of the Octave use?

Question: Rule of the Octave seems to have been fazed out from music. But I find it really interesting as greats such as Bach, Mozart, etc used it to improvise and make music. Also today's musicians that focus on classical improvisation, such as Mortensen, use it in their playing.
My understanding is that rule of the octave are just "what chords to pick" when you harmonize a bass line. But they usually show it as figured bass. What chords (in roman numerals) does it use in major and minor, ascending and descending?
Edit: a comment was made that the wikipedia page already had the chords. So I may have asked a bit too soon. If anyone can find the minor scale equivalent it will be very appreciated. These are the chords for the major scale:

Image Source:
Hiles, John (1882). A catechism of harmony, thorough-bass, and modulation, with examples, p. 82.
Comment: I'm unclear on what you mean by "why did diatonic roman numeral chords 'win'?" Often the chords in the Rule of the Octave are diatonic Roman-numeral chords. Or do you mean "why did chord progressions with basslines that aren't ascending/descending scales 'win'?" (Admittedly that doesn't roll off the tongue as easily!)
Comment: I don't understand, literally the answer to the question is on the Wikipedia article you linked. Directly underneath the figures bass is a translation to Roman numerals. What more are you looking for?
Comment: @PatMuchmore you're right wow. I never noticed since the roman numerals were such a weird order, maybe that threw me off. Do you think getting the minor form of that would be different or is it just a shift of roman numerals?
Answer: The key principle behind the Rule of the Octave is that scale degrees ➀ and ➄ receive what we would call a root position triad -- notated in figured bass by a 5 over a 3 (which I will typeset as 5/3) although these are typically left implied and no figures are are written. Meanwhile, most other notes of the scale generally receive what we would call a first position triad -- notated as 6/3 (some 6/3 chords have additional intervals added). The one major exception to this is the 6/4/2 chord on the descending ➃, which is what we would call a third inversion seventh chord.
It's also worth pointing out that there is not a single definitive Rule of the Octave; various authors occasionally made minor tweaks to suit there purposes, often to improve voice leading options. You'll see this as a 6/3 chord, with an additional interval added. Giorgio Sanguinari, in The Art of Partimento, has a "synoptic view" of several different author's versions of the major scale, which I'll simplify and summarize below.
Major Scale, Ascending

➀ 5/3
➁ 6/3 or 6/4/3
➂ 6/3
➃ 5/3 or 6/5/3
➄ 5/3
➅ 6/3
➆ 6/3 or 6/♭5/3
➇ 5/3

Major Scale, Descending

➇ 5/3
➆ 6/3
➅ ♯6/3 or ♯6/4/3
➄ 5/3
➃ 6/4/2
➂ 6/3
➁ 6/4/3
➀ 5/3

He also discusses the minor scale, and while he doesn't give the same convenient table, he does show Fenaroli's version, which is basically the same as the major. Note that the bass uses the melodic minor scale (so ➅ and ➆ are raised when ascending, and lowered when descending), and note that ➄ must always have a major third. In fact, most of the ♯'s in the figures below are to indicate a raised seventh scale degree (i.e. leading tone).
Minor Scale, Ascending

➀ 5/3
➁ ♯6/4/3
➂ 6/3
➃ 6/5/3
➄ 5/♯3
➅ 6/3
➆ 6/♭5/3
➇ 5/3

Minor Scale, Descending

➇ 5/3
♭➆ 6/3
♭➅ ♯6/4/3
➄ 5/♯3
➃ 6/♯4/2
➂ 6/3
➁ ♯6/4/3
➀ 5/3

One thing that may seem a bit unexpected in the above is the ♯6 over the ♭➅ scale degree. In the key of C minor, for example, this would be an A♭ in the left hand, with an F♯ in the right hand's chord, which creates an interval known as an augmented sixth.
Answer: At a basic level the 'Rule of the Octave' TELLS you what chords to play over an ascending or descending scale in the bass.  As such, it might help you get through an elementary harmony exercise.   Look deeper and it actually deals with the stability (or otherwise) of each degree of the scale.  And that remains the basis behind all functional harmony.
Read THIS PAGE  (and also click through to THIS ONE


Extensão de função no laravel

Question: Estou usando o Laravel 5.3 e aparentemente tenho um Controller chamando a função:
(new AnuncioRepository())->getListagemAnuncios()

e o SQL referente a isso é:
return DB::select('
            SELECT
                anuncio.id,
                cliente.nome AS "cliente",
                anuncio_area.nome AS "area",
                DATE_FORMAT(anuncio.data_inicio, "%d/%m/%Y") AS "inicio",
                DATE_FORMAT(anuncio.data_fim, "%d/%m/%Y") AS "fim",
                CONCAT(DATE_FORMAT(anuncio.hora_exibicao_inicio,"%H:%i"),
                    " - ",DATE_FORMAT(anuncio.hora_exibicao_fim,"%H:%i")) AS "horario",
                anuncio.valor,
                anuncio.ativo
            FROM
                anuncio
                RIGHT JOIN anuncio_area ON (anuncio_area.id = anuncio.id_anuncio_area)
                RIGHT JOIN cliente ON (cliente.id = anuncio.id_cliente)
            WHERE anuncio.ativo != "x"
                  AND anuncio.deleted_at is null
            ORDER BY anuncio.id DESC
        ');

O que eu queria fazer era estender uma função de contador no repository por exemplo:
(new AnuncioRepository())->getListagemAnuncios()->count();

E ele contasse os registros que o SQL retornou, como posso fazer isso?
Comment: Se fizeres `DB::select('
            SELECT
               ...
        ')->count();` ele não retorna o número de linhas?
Answer: Utilize a classe collection da seguinte forma:
$result = DB::select('
            SELECT
                anuncio.id,
                cliente.nome AS "cliente",
                anuncio_area.nome AS "area",
                DATE_FORMAT(anuncio.data_inicio, "%d/%m/%Y") AS "inicio",
                DATE_FORMAT(anuncio.data_fim, "%d/%m/%Y") AS "fim",
                CONCAT(DATE_FORMAT(anuncio.hora_exibicao_inicio,"%H:%i"),
                  " - ",DATE_FORMAT(anuncio.hora_exibicao_fim,"%H:%i")) AS "horario",
                anuncio.valor,
                anuncio.ativo
            FROM
                anuncio
                RIGHT JOIN anuncio_area ON (anuncio_area.id = anuncio.id_anuncio_area)
                RIGHT JOIN cliente ON (cliente.id = anuncio.id_cliente)
            WHERE anuncio.ativo != "x"
                  AND anuncio.deleted_at is null
            ORDER BY anuncio.id DESC
        ');

return collection($result);

com esse ajuste tem objeto da classe collection com os métodos implementados, por exemplo o método count. Nesse link está a relação de métodos que pode ser utilizado. Para mostrar agora todos os registro utilize all().
Como usar:
$result = (new AnuncioRepository())->getListagemAnuncios();
$result->count(); //quantidade de registros retornados
$result->all(); //os registros

Referencias:

Collections
Collection - Available Methods
Collection - Available Methods - count
Collection - Available Methods - all
Comment: Muito obrigado! dúvida respondida

Extensão de função no laravel


Why would a piece start in G♭ Major then modulate to F♯?

Question: I saw a question regarding F# vs. Gb in a given song. The song began in Gb Major then went to F# minor . . . and then it was question as to why the change. Why not just write the song in one Key?
I believe it has to do with the flattened 3rd in Gb caused a problem in the writing. One would have a doubled flat for the third in Gb minor, which is played as "A" on the keyboard. I believe it becomes cumbersome to interpret the notes in the key of Gb major . . . so there needed to be a change to F# minor to make the reading of the music easier.
I hope I made my point clear.
Comment: If that was the case, why not write the first part in F# major? 6# instead of 6b.
Answer: G-flat minor is, as you note, a terribly awkward key, since its relative major is B-double-flat.  That is, the third scale degree is enharmonically equivalent to A, but it's actually B-double-flat.  That has nine flats in its key signature (or, actually, five flats and two double flats).  F-sharp minor has the rather more normal relative major of A major, with a three-sharp signature.
I don't know why the major part of the piece wasn't in F-sharp major, however, since that key has six sharps in its signature while G-flat major had six flats: these two keys are equally awkward.
Perhaps some consideration was given to transposing instruments.  For a b-flat instrument, F-sharp major is notated as G-sharp major, with eight sharps (actually six sharps and one double sharp), but G-flat major is notated as A-flat major, with four flats.
Comment: Good point about the reading for transposing instruments. If it's going to be that bad, why not write the piece in a more friendly key anyway...
Comment: Actually, for a b-flat instrument, F-sharp major is also notated in A-flat major (and an e-flat instrument in E-flat major). Without seeing the actual score and/or talking to the composer or arranger, any attempt at giving a reason for choosing F# major over Gb major is just guessing. The answers give good reasons for preferring F# minor to the (theoretical) key of Gb minor.
Comment: @alephzero fair enough, for the players of the B-flat instruments, but for the conductor it is probably harder to read a score with the B-flat instruments in A-flat major and the concert-pitch instruments in F-sharp major.  I'd much rather have the concert instruments in G-flat major so the visual relationship between the transposing instruments and the concert instruments is as expected.
Answer: TL;DR: It's just better to write since F♯-minor has a lot less signs to write than G♭-minor.

The original tonality you listed was G♭-major; it has six ♭s.
"Converting" major tonality to same-named minor one requires to flatten it triply:
add three ♭, or remove three ♯s.
(Of course, you should use circle of fifths; this is a sort of shortcut)
This means that G♭-minor will have nine ♭s (every note is ♭ except for B, E and A, which are ♭♭).
Same pitch and, of course, interval structure has an anharmonically equal F♯-minor.
Except for it has only three ♯s.
Much simpler to write, isn't it?


Mapeamento de tabelas Associativas com Entity Framework

Question: Estou com o seguinte problema: Um cliente tem tarefas para cada dia da semana.
Exemplo:

Cliente A - Sábado - Lavar Carro, Limpar Casa...

Mapeie da seguinte forma:
public class Cliente
{
    [Key]
    public int Id { get; set; }

    [MaxLength(250)]
    public string Nome { get; set; }

    public virtual ICollection<DiaSemana> DiasSemana { get; set; }
}

public class DiaSemana
{
    public DiaSemana()
    {
        Tarefas = new List<Tarefa>();
        Clientes = new List<Cliente>();
    }

    [Key]
    public int Id { get; set; }

    [MaxLength(20)]
    public string Dia { get; set; }

    public virtual ICollection<Tarefa> Tarefas { get; set; }

    public virtual ICollection<Cliente> Clientes { get; set; }
}

public class Tarefa
{
    public Tarefa()
    {
        DiasSemana = new List<DiaSemana>();
    }

    [Key]
    public int Id { get; set; }

    [MaxLength(20)]
    public string Nome { get; set; }

    public virtual ICollection<DiaSemana> DiasSemana { get; set; }
}

Quando comecei a popular o banco, utilizando o Entity Framework, virou uma confusão e comecei a ver que o Entity Framework entendeu tudo errado rs (EF burro rs)...
Sei que o jeito que mapeie está incorreto, mas não estou conseguindo perceber como posso estar mapeando as classes corretamente.
Edit:
O EF criou as seguintes tabelas:
Tarefa
Id          Nome
1           Lavar Louça
2           Limpar Casa

TarefaDiaSemana
Treafa_Id        DiaSemana_Id
1                2
2                2

DiaSemana
Id             Dia
1              Segunda
2              Terça
3              Quarta

DiaSemanaCliente
DiaSemana_Id         Cliente_Id
2                    99
2                    66

Cliente
Id        Nome
99        Diego
66        Felipe

Neste caso o banco está assumindo que Diego e Felipe tem as duas tarefas. Porém Diego de terça tem apenas a tarefa de Lavar Louça e Felipe apenas a tarefa de Limpar Casa.
No meu entendimento precisava do id cliente na tabela TarefaDiaSemana
Comment: Não entendi seu problema. O mapeamento está correto. O que estaria errado?
Comment: @CiganoMorrisonMendez editei a pergunta, ficou mais claro o problema agora.
Comment: Ah, agora que eu vi. Falta de atenção minha. Vou responder.
Answer: Isto aqui está errado:
public class DiaSemana
{
    public DiaSemana()
    {
        Tarefas = new List<Tarefa>();
        Clientes = new List<Cliente>();
    }

    ...

    public virtual ICollection<Tarefa> Tarefas { get; set; }

    public virtual ICollection<Cliente> Clientes { get; set; }
}

Em primeiro lugar, isto não precisa:
    public DiaSemana()
    {
        Tarefas = new List<Tarefa>();
        Clientes = new List<Cliente>();
    }

O Entity Framework inicializa as propriedades de navegação pra você. Este código não faz diferença alguma para a aplicação.
Em segundo lugar:
public class DiaSemana
{
    ...

    public virtual ICollection<Tarefa> Tarefas { get; set; }

    public virtual ICollection<Cliente> Clientes { get; set; }
}

Se DiaSemana é a entidade que associa Tarefas e Clientes, ela não pode ter N Tarefas e N Clientes, afinal, ela associa apenas uma Tarefa com apenas um Cliente.
Mude para o seguinte:
public class DiaSemana
{
    [Key]
    public int DiaSemanaId { get; set; }
    // Importante incluir os campos de chave estrangeira também!
    [Index("IUQ_DiaSemana_TarefaId_ClienteId", IsUnique = true, Order = 1)]
    public int TarefaId { get; set; }
    [Index("IUQ_DiaSemana_TarefaId_ClienteId", IsUnique = true, Order = 2)]
    public int ClienteId { get; set; }
    ...

    public virtual Tarefa Tarefa { get; set; }
    public virtual Cliente Cliente { get; set; }
}

[Index], introduzido nesta forma a partir do Entity Framework 6.1.0, garante a unicidade do registro associativo. Validações adicionais podem ser necessárias na aplicação para evitar erros estranhos de duplicidade de chave para o usuário.
Comment: Então para eu estar recuperando todas as tarefas de um determinado cliente seria: `var tarefas = cliente.DiasSemana.Where(x=>x.Dia == "Segunda").ToList();`
Comment: É, na verdade, considerando por dia, seria: `var tarefas = cliente.DiasSemana.Where(x=>x.Dia == "Segunda").SelectMany(x => x.Tarefas).ToList();`
Comment: Show... Seria melhor eu criar talvez um `enum` para não precisar ficar lotantdo o banco com um monte de string como "segunda", "terça", e sim como como 1, 2, 3...
Comment: Sim, é o que eu usaria no seu lugar.


Authentication Required (packagist.org)

Question: Estou tentando criar um projeto em laravel com o comando:
composer create-project --prefer-dist laravel/laravel blog

Porém está exigindo uma autenticação:
Authentication required (packagist.org)
  Username:
  Password:

Não lembro de ter me cadastrado nesse site.
Alguém sabe como corrigir isso?
Comment: Está utilizando algum proxy?
Comment: Não estou usando
Answer: Passei por isso usando o macOS... só deixei em branco os dois campos (clicando no enter) e depois que apareceu uma mensagem eu cliquei enter de novo. Pronto, ele rodou o composer update

Authentication Required (packagist.org)


Center of a circle

Question: Suppose we are given the following equations $$\dot x=p_x-ky\\\dot y=p_y+kx\\\dot p_x=-k(p_y+kx)\\ \dot p_y=-k(-p_x+ky)$$
I can see that it describes circular motion. but why it it true that  for a circle with origin $(a,b)$ the following equation stands:$$2a+{p_y\over k}=x$$?
I suspect it's something rather obvious, but which has managed to elude me...
Please?
Answer: Just take the time derivative of both sides of the equation:
$$\frac{\mathrm{d}}{\mathrm{d}t}\left(2a + \frac{p_y}{k}\right) = \frac{\mathrm{d}x}{\mathrm{d}t}\\
\iff \dot p_y = k \dot x\\
\iff -k(-p_x + ky) = k(p_x - ky)$$
So your equation is valid if we set the initial values correctly. this can be done by chosing $x(0) = 2a$ and $p_y=0$, say, which corresponds to a circle around your specified origin with radius $a$.

Center of a circle


Web audio api - The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page

Question: So I've this warning on my console.
I read the documentation : https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
I did everything as they said but I still have this warning.
Here's my code :
let context;
window.onload = function() {
    context = new AudioContext();
    ...
}

// click event
document.addEventListener('click', function (e) {
    if (e.target.closest('.play1')) {
       context.resume().then(() => {
            source.start(0);
       });
    }
})

The warning text is about this line : context = new AudioContext();
Does anyone see what I'm missing ? Thank you very much
Comment: Does it mean I can not load my audio before the click event ? Because the idea was to load my audio inside a BufferSource before the user click to play the song
Comment: onload is not a user generated UI interaction . Common to use a btn 'click' as the user-input event req'd by web-audio AND then to get the new Context and to wire it up to streams and to get permissions per the API docs
Comment: You can do whatever you want.  You're only prevented from hearing any audio until you get a user gesture to resume the context or start the buffer source.
Comment: Yes but from my example, I only declare a contexte inside an onload event. So basically I'm not supposed to get this warning no ?
Comment: Does this answer your question? [Google Chrome Javascript issue in getting user audio - The AudioContext was not allowed to start](https://stackoverflow.com/questions/55026293/google-chrome-javascript-issue-in-getting-user-audio-the-audiocontext-was-not)
Answer: Yes, the warning is because you did not create the context in a user gesture.  I find the warning quite annoying because it is not wrong to create the context without a user gesture.  What is not allowed is starting/resuming the context without a user gesture.
Since you resume the context with a user click, everything is fine.
I would ignore it.  Or create the context with a click or other user gesture.
I wish Chrome would fix the warning so that it only shows up when you try to resume a context without a user gesture.
Comment: firefox does it too.
Comment: Does it mean I can not load my audio before the click event ? Because the idea was to load my audio inside a BufferSource before the user click to play the song
Comment: You should be able to load audio.  You are only blocked from playing audible sounds until you use a user-gesture to resume a context or to start your AudioBufferSourceNode.  (If you do these without a gesture, it may look like things are working, but they're not and you won't hear anything.)


Exploratory factor analysis for clustered data in R

Question: I am new to both R and factor analysis, and I need to run EFA for a dataset that used cluster survey design. Is there any package for FA in R that can handle cluster data?
Answer: Accounting for survey clustering doesn't alter your parameter estimates, only the standard errors. EFA is a descriptive technique, which doesn't care about standard errors.
For the purpose of EFA, you can ignore the clusters.
Comment: Thanks indeed for the idea. Could you please also give any journal or book reference for it?
Comment: I don't know of one that links those two facts together. But you can confirm them separately yourself by running an analysis with clusters, and by doing a factor analysis and changing the sample size (but not the correlation matrix). If you are challenged, I would reverse it and ask the challenger why they think it matters.


Using UUIDs for passwords

Question:
Does anyone have an opinion on using UUIDs as passwords? This is intended for accounts created for external users, such as customer access to private SFTP folders. Or are people using public key instead? These users don't have a shell and are chroot'd to their directory.

From the manpage:

UUIDs are 128 bit numbers which are intended to have a high likelihood of uniqueness over space and time and are computationally difficult to guess. They are globally unique identifiers which can be locally generated without contacting a global registration authority. UUIDs are intended as unique identifiers for both mass tagging objects with an extremely short lifetime and to reliably identifying very persistent objects across a network.

I'm on Ubuntu 9.10, but the OSSP uuid package is available for most *nix distributions.
Answer: There are many ways to generate a UUID, some of which are likely highly guessable.  For instance, the current time is often a component and sitting right there, as is the machine's MAC address, etc.  Don't confuse unique with unguessable.
I would not try to re-purpose UUIDs for passwords, but instead choose a strong password generator.  If you're thinking about using a UUID for a password, clearly being able to remember it is not important, so I'd choose something like the output of MD5 with a few bytes from /dev/random or /dev/urandom:
dd if=/dev/random bs=128 count=1 | md5

Or, better yet, use a tool designed specifically for generating strong passwords.  Ideally ones that users can remember without writing them down.
Comment: Yes, in the past I've used apg(1) to generate passwords, which isn't bad. What's happening here is that users are using WinSCP, and saving the password in their profile. The risk of someone else using their account is limited to them being able to read that customers' reports - the shell is /bin/false, and I'm using the new chroot capabilities of OpenSSH. So memorability isn't really a concern.
Comment: apg is a great tool. Thanks for suggesting it.
Answer: The higher the level of complexity in the password the higher the chance that the user will write it down on a post it note and stick it to their monitor, that is in addition the the support costs when the user forgets the password.
When using SSH Keys some form of password is recommended (but not required) to secure the key. Pass phrases are easier to remember than passwords so something like:

Firefox&is&JUST&a&browser
NotTheFirstHackI'dTry
The Quick Brown Fox

Will both reduce the incidence of calls to reset forgotten passwords, and improve security because your users are going to be able to remember them without writing them down.
Comment: It should be noted that passwords are not strictly required to secure SSH keys, they're completely optional.
Comment: Updated, not using a password significantly reduces the security of the system, whilst technically it may not be required I would be surprised if company policy didn't require it.
Comment: Yea, but in his case he knows people are storing the passwords in their profile, so an unprotected SSH key is only slightly worse than storing the key in the registry or some other file.
Answer: I think in theory, using random UUIDs for machine passwords, API keys and such is a good idea.  But they need to be written down, or copy/pasted.  They aren't great when people have to type them in.  (but you said they are going to get saved)
The OSSP uuid command, by default, generates a version 1 UUID.  This is based on the MAC address of the current machine and the current time. So not as secure as they look.
If you run uuid -n 10, which generates 10 UUIDs, you will see a lot of characters are the same.
If you do uuid -v4   this will give you a random UUID. Better than the default.
I've had a look at the source for OSSP UUID and I can't decide whether or not the randomness is good enough or not.   The source has not been updated for 10 years, and there has been much research and viewpoints on making cryptographic random numbers since then. It is probably ok.
My favourite way to get a random uuid on a linux machine is cat /proc/sys/kernel/random/uuid
For the truly paranoid, you might also want to consider how much random data is available on the machine you are using.   cat /proc/sys/kernel/random/entropy_avail    You are looking for a big number, like more than 1000.   If you are on a virtual machine, not doing much, you might struggle.

Using UUIDs for passwords


Prometheus Monitor Host Network Traffic From Within Docker Container

Question: Is it possible / intended to use a prom/node-exporter container to monitor the network traffic of the docker host? In my setup, all the host interfaces show up in node_network_iface_id but node_network_iface_id only has time series for the container's interfaces.
My docker-compose.yml looks like this:
networks:
    backend:
        driver: bridge
        internal: true
    outside:
        external: true

node-exporter:
        image: prom/node-exporter
        volumes:
           - /proc:/host/proc:ro
           - /sys:/host/sys:ro
           - /:/host:ro
        command:
           - '--web.listen-address=:9100'
           - '--path.procfs=/host/proc'
           - '--path.sysfs=/host/sys'
           - '--path.rootfs=/host'
           - --collector.filesystem.ignored-mount-points
           - "^/(sys|proc|dev|host|etc|rootfs/var/lib/docker/containers|rootfs/var/lib/docker/overlay2|rootfs/run/docker/netns|rootfs/var/lib/docker/aufs)($$|/)"
        restart: always
        networks:
           - backend

...

Answer: I don't know if this is an update to node_exporter as your question was a while ago but I'm monitoring node_network_transmit_bytes_total for this using the full query below and it works well.
rate(node_network_transmit_bytes_total {device=~"eth.",host=~"$Host"}  [1m]) * 8

Naturally there is the equivalent receive value.


onAmbientModeChanged is not calling when in ambient watchface android wear

Question: Recently i tried to implementing ambient mode in android wear watchface, after implement some coding, i found out that onAmbientModeChanged will not be called when turn into ambient mode (emulator), but turn to normal mode it will called twice, first trigger,the inAmbientMode is true, second trigger the inAmbientMode is false.
private class Engine extends CanvasWatchFaceService.Engine {
    ...
    ...
     @Override
     public void onAmbientModeChanged(boolean inAmbientMode) {
        Log.e(TAG, "isInAmbientMode():" + inAmbientMode);
        super.onAmbientModeChanged(inAmbientMode);
        if (mLowBitAmbient) {
            boolean antiAlias = !inAmbientMode;
            setPaintAntiAlias(antiAlias);
        }

        invalidate();
        updateTimer();
    }

    @override
    public void onDraw(Canvas canvas, , Rect bounds){
      ...
      for(int i=0;i<node.length;i++){
        //drawing canvas
      }
    }
}

AndroidManifest.xml

<uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET"/>

What would it be the problem for not triggering when ambient is on? Is it a bug or i need to add some permission or class to trigger this? Any help would be appreciated.
EDIT: When ambient, the watchface won't redraw until it turn back to normal mode, then the watchface will draw the ambient watchface then only draw the normal watchface
After testing and debugging for something, i found out that the for loop is the main cause that didn't trigger the onAmbientModeChanged, after comment out the for loop, when ambient change, the onAmbientModeChanged will also trigger correctly but still don't know why it happen and solution.
Comment: is it for loop inside ondraw is a bad method?
Answer: I got a similar problem, where my Watch face would randomly not turn to Ambient mode after Marshmallow update, until the onTick() when the OS wakes the Watch Face for some milliseconds so it updates the time. I guess this problem is linked to more aggressive sleep policy on wearables, with Doze mode.
I looked at the WatchFaceService code, decompiled by Android Studio and it's bundled Jetbrains java bytecode decompiler, on I saw that the onTick()method holds a non reference counted wakelock for 100ms. I tried to do the same in the onAmbientModeChanged() callback, and I never saw my Watch Face with it's intercative style in ambient mode.
Here are the code snippets:
In onCreate():
final PowerManager powerManager = (PowerManager) context.getSystemService(POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
mWakeLock.setReferenceCounted(false);

In onAmbientModeChanged(…):
mWakeLock.acquire(100L);

You can try to fine tune the wakelock acquire time value by setting it to 10ms for example, and making it increment by 10ms each time to tap the Watch Face.
I personally changed this value to something more appropriate as my Watch Face animates ambient mode switching.
BTW, check that the code in the for loop which is repeated as many times as you told it is not too long to execute as performance on mobile devices is critical. I personally had a for loop in my Watch Face to draw ticks, but I made it smoother by first making it once and cache it in a Bitmap, and now, I'm going to use Canvas#drawLines(…) instead.
Comment: you really save my day, but instead of using 100ms, i tried to not use any timeout, because in my case after i use the timeout, sometime it will not turn to Ambient the successrate about 8/10 but eventually your solution work, so thanks again !!!
Comment: sorry i don't understand the holding the wakelock permanently meant. i release it in ondestroy and acquire it when inAmbientMode equal true. Is it any problem when i acquire without using timeout?
Comment: Yes, there's a problem! Holding a wakelock will drain the battery! `onDestroy()` is only called when the device is shut down or when the user changes the watch face. If 100ms is too short, then you should optimize your code to make it draw in less than 16ms, or draw once on a Bitmap and then draw it with `Canvas#drawBitmap(...)`. If you animate ambient mode changes, Android Wear will go in deep sleep and skip frames, so you will need to make the wakelock timeout longer. Avoid exceeding 500ms of Wakelock for such case.
Comment: i see, i'll try to optimize and see how's the result, will update here as soon as i tested. Thanks.
Comment: hi @louis cad, i have optimize my code but eventually the timeout used still more then 3 seconds, after research then find out that the clock hands  is the main problem. The 3 clock hands size is 520x520. After remove the clock hands and tinting to the image, i can squeeze the timeout into 1 second.
Answer: On my Polar M600 with USB-Connection I don't receive onAmbientModeChanged() calls and isInAmbientMode() does not work either.
Without USB-Connection onAmbientModeChanged() and isInAmbientMode() is not working reliably (more often not than so).
My hack is to use:
onTapCommand() for setting mAmbient = true
(I call onAmbientModeChanged(true) myself)
(first tap is consumed to wake the clock, but if I need more information I tap again)
onTimerTick() for setting mAmbient = false
(I call nAmbientModeChanged(false) myself)
(up to 1 minute delay, but doesn't matter)
Works for me.


Does the Burnside $\mathbb Q$-algebra $A$ of a group depend only on $\dim_{\mathbb Q}A$?

Question: The Burnside $\mathbb Q$-algebra $\mathbb QB(G)$ of a group $G$ is usually considered only when $G$ is finite; see Section 3.1 of the text
[1] Serge Bouc, https://pdfs.semanticscholar.org/aff3/8005a0c57f36a15b01747616e738f1f9eb4d.pdf
Moreover, we have in this case $\mathbb QB(G)\simeq\mathbb Q^n$ with $n=\dim_{\mathbb Q}\mathbb QB(G)$, and thus $\mathbb QB(G)\simeq\mathbb QB(H)$ whenever $G$ and $H$ are finite groups such that $\dim_{\mathbb Q}\mathbb QB(G)=\dim_{\mathbb Q}\mathbb QB(H)$; see Section 3.3 of [1].
But, if we replace the expression "$G$-set" with "finite $G$-set", the definition of  $\mathbb QB(G)$ makes sense for any group $G$, and it seems natural to ask

Question. Do we have $\mathbb QB(G)\simeq\mathbb QB(H)$ if $G$ and $H$ are groups such that $\dim_{\mathbb Q}\mathbb QB(G)=\dim_{\mathbb Q}\mathbb QB(H)$?

The Burnside $\mathbb Q$-algebra $\mathbb QB(G)$ of a group $G$ is canonically isomorphic to that of its profinite completion. The dimension of the Burnside $\mathbb Q$-algebra of a profinite group is finite if and only if the group is finite (but an infinite group may have a finite profinite completion).
For any group $G$ we chose a set $S(G)$ of representatives of the conjugacy classes of finite index subgroups of $G$.

The Burnside $\mathbb Q$-algebra $\mathbb QB(G)$ is von Neumann regular.

Indeed, if $b$ is in $\mathbb QB(G)$, then there is a largest finite index normal subgroup $N$ of $G$ such that $b\in\mathbb QB(G/N)$. Let $\phi_{G/N}:\mathbb QB(G/N)\to\mathbb Q^{S(G/N)}$ be the $\mathbb Q$-algebra isomorphism defined in Section 3.3 of [1], and define $b'\in\mathbb QB(G/N)\subset\mathbb QB(G)$ by
$$
b'=(\phi_{G/N})^{-1}\Big(w\circ(\phi_{G/N}(b)\Big),
$$
where  $w:\mathbb Q\to \mathbb Q$ is defined by $w(\lambda)=\frac1\lambda$ if $\lambda\ne0$ and $w(0)=0$ (that is, $w$ is a witness to the von Neumann regularity of $\mathbb Q$), so that we have $b^2b'=b$ in $\mathbb QB(G)$, which shows that $\mathbb QB(G)$ is von Neumann regular.
(In this post $X\subset Y$ means "$X$ is a (not necessarily proper) subset of $Y$".)
Assume from now on that all the finite index subgroups of $G$ are normal (for instance because $G$ is abelian).
In particular $S(G)$ is the set of all finite index subgroups of $G$.
We will "compute" $\mathbb QB(G)$ in this case.
Using the notation and results in Section 3.2 of [1] we have a  $\mathbb Q$-algebra injective morphism $\phi_G:\mathbb QB(G)\to\mathbb Q^{S(G)}$ given by
$$
\Big(\phi_G(G/K)\Big)(H)=m(H,K),
$$
and we see that
$$
\phi_G\left(\frac{G/K}{|G/K|}\right)
$$
is the characteristic function $f_K$ of the subset
$$
S(G)_{\subset K}:=\{H\in S(G)\ |\ H\subset K\}.
$$
Then the $f_K$ with $K\in S(G)$ form a $\mathbb Q$-basis of $\mathbb QB(G)$ satisfying
$$
f_Kf_L=f_{K\cap L}
$$
for all $K,L\in S(G)$. In particular, up to isomorphism $\mathbb QB(G)$ depends only on the ordered set $S(G)$.
Here are two examples:
$\bullet$ If $k$ is an integer with exactly $n$ prime factors, and if $\mathbb Z_k$ is the group of $k$-adic integers, then the ordered set $S(\mathbb Z_k)$ is opposite to $\mathbb N^n$.
$\bullet$ The ordered set $S(\mathbb Z)$ is opposite to the set of all sequences $x\in\mathbb N^{\mathbb N}$ such that $x_n=0$ for $n$ large enough (depending on $x$).
Answer: In general, $\mathbb{Q}B(G)$ is the filtered colimit of $\mathbb{Q}B(H)$ where $H$ ranges over all finite quotients of $G$.  In particular, this means $\mathbb{Q}B(G)$ is generated by idempotent elements and is determined up to isomorphism by its Boolean algebra of idempotent elements, which I will call $I(G)$. (See this answer for some related discussion.)
In the case that all finite index subgroups are normal, then $I(G)$ can be identified with the Boolean subalgebra of $\mathcal{P}(S(G))$ generated by the sets $S(G)_{\subseteq K}$ which you consider.  This can also be described as the Boolean algebra freely generated by $S(G)$ as a meet-semilattice (proof sketch: reduce to the finite case and use the explicit description of the free Boolean algebra on a finite set).
In particular, if $p$ is prime, then we see that $I(\mathbb{Z}_p)$ is isomorphic to the algebra of finite and cofinite subsets of $\mathbb{N}$, and in particular the ordered set $\mathbb{Z}$ does not embed into $I(\mathbb{Z}_p)$.  On the other hand, $\mathbb{Z}$ does embed into $I(\mathbb{Z})$, as exhibited by the following chain of elements of $I(\mathbb{Z})$ (considered as subsets of $S(G)$):
$$\dots\subset S(\mathbb{Z})_{\subseteq 8\mathbb{Z}}\subset S(\mathbb{Z})_{\subseteq 4\mathbb{Z}}\subset S(\mathbb{Z})_{\subseteq 2\mathbb{Z}}\subset S(\mathbb{Z})_{\subseteq 2\mathbb{Z}}\cup S(\mathbb{Z})_{\subseteq 3\mathbb{Z}} \subset S(\mathbb{Z})_{\subseteq 2\mathbb{Z}}\cup S(\mathbb{Z})_{\subseteq 3\mathbb{Z}} \cup S(\mathbb{Z})_{\subseteq 5\mathbb{Z}} \subset\cdots$$
Thus $\mathbb{Q}B(\mathbb{Z}_p)$ and $\mathbb{Q}B(\mathbb{Z})$ are not isomorphic, even though they have the same vector space dimension.
(In fact, with a bit more work, you can show $I(\mathbb{Z})$ is atomless, so it must be the free Boolean algebra on countably many generators.  Thus $\mathbb{Q}B(\mathbb{Z})$ is isomorphic to the algebra of locally constant $\mathbb{Q}$-valued functions on the Cantor set.  Similarly, $\mathbb{Q}B(\mathbb{Z}_p)$ is isomorphic to the algebra of locally constant $\mathbb{Q}$-valued functions on $\mathbb{N}\cup\{\infty\}$, or equivalently the algebra of eventually constant sequences of elements of $\mathbb{Q}$.  The latter description can be made very explicit: given a finite $\mathbb{Z}_p$-set, send it to the sequence whose $n$th term is the number of elements which are fixed by $p^n$.)

A natural followup question would be which Boolean algebras are isomorphic to $I(G)$ for some group $G$ (and so which idempotent-generated algebras are isomorphic to $\mathbb{Q}B(G)$ for some group $G$).  I don't know how to answer that, but here is a necessary condition: if $I(G)$ is infinite, then it must have a countable descending chain of nonzero elements whose meet is $0$.  So, for instance, it is not possible for $I(G)$ to be isomorphic to the Boolean algebra $\mathcal{P}(\mathbb{N})/\mathrm{fin}$.
To prove that such a chain exists, note that any normal finite index subgroup $H\subseteq G$ gives an idempotent $i_H=\frac{G/H}{[G:H]}$, and $K\subset H$ implies $i_K<i_H$ in $I(G)$.  If $I(G)$ is infinite, then $\mathbb{Q}B(G)$ is infinite dimensional, so $S(G)$ is infinite.  If $H_1,\dots,H_n\subset G$ are finite index subgroups then the kernel of the action on $G/H_1\times\dots\times G/H_n$ is a normal finite index subgroup contained in all of them.  So there is no minimal normal finite index subgroup (otherwise it would be contained in all finite index subgroups and so $S(G)$ would be finite), and so we can find an infinite descending chain $G\supset H_1\supset H_2\supset\dots$ of normal finite index subgroups.
I then claim that the meet of the idempotents $i_{H_n}$ is $0$; i.e. no nonzero idempotent of $\mathbb{Q}B(G)$ is less than all of them.  To prove this, let $e\in\mathbb{Q}B(G)$ be any idempotent which is less than every $i_{H_n}$ and choose a normal finite index subgroup $H$ such that $e\in\mathbb{Q}B(G/H)$ (i.e., $H$ fixes all the $G$-sets which appear in $e$).  Then there is some $n$ such that $H\not\subseteq H_n$, since $[G:H_n]\to\infty$.  Now note that no $G$-set appearing in $i_{H_n}e$ is fixed by any element that is not in $H_n$, and so no $G$-set appearing in $i_{H_n}e$ is fixed by all of $H$.  But $e\leq i_{H_n}$, so $i_{H_n}e=e$.  Since every $G$-set appearing in $e$ is fixed by $H$ but also no $G$-set appearing in $e$ is fixed in $H$, we must have $e=0$.
Comment: I have added more detail on that.
Comment: Thanks a lot for this answer which looks awesome to me even if I'm far from understanding it all! In particular I don't understand the phrase "if $I(G)$ is infinite, then it must have a countable descending chain of nonzero elements whose meet is $0$ (such a chain comes from any infinite descending sequence of normal finite index subgroups of $G$)". I'd be most grateful if you could give me some explanation.


Show that the groups $G$ and $\langle G, * \rangle$ are isomorphic.

Question: Let $G$ be a group and $g\in G$. Define a new operation $*$ on $G$ by $a*b=agb$.
What I have done so far is up to showing that indeed $\langle G,*\rangle$ is a group. When showing that these groups are isomorphic I ended having trouble finding a function.
Any hint will be greatly appreciated.
Answer: Consider the map from the original $G$ into $(G,*)$ defined by $h\mapsto g^{-1}h$ and prove that it is a group isomorphism.
Comment: Thanks, I'll be working on it.
Comment: This $g^{-1}$ here is the same as the identity element of $(G,*)$, right?
Comment: @Traveler Yes, it is. It had to be, because a group homomorphism always maps the identity element into the identity element. But you already knew that, right?! After all, you told us that you proved that $(G,*)$ is a group.
Comment: Got it. Very much appreciated.
Comment: May I just add on how can I find such mapping?
Comment: @Traveler Since $g^{-1}$ is the identity element of $(G,*)$, it would have to be a map the mapped $e$ into $g^{-1}$. This one seemed to be a natural choice for me.


Any known example of research project being led by statistician in public health

Question: (I am fully aware that my topic may not be relevant here, do let me know if this is true.)
I am a research staff with training in epidemiology and biostatistics, working in government organization on public health matters like disease surveillance and infection control. Being a research staff here keeps giving me a feeling that I cannot lead a research project in this position, because I lack the context needed to ask sensible research questions. Doctors/PhDs in our service, although they know little about statistics, can become principal investigators of research projects, and then assign research staff to handle the technical parts.
I wonder if this kind of "statistician can only take supportive role" curse is universal to other fields also? Any comment or counter argument on this, and any suggestion of breaking this kind of curse?
Comment: I'm not sure what you are talking about... Lacking the context to ask sensible questions is not intrinsically related to you having knowledge of research or statistics. Are you asking whether statisticians can (or have in the past) led projects in health-related field?
Answer: I don't see it as a curse.  I think in most cases statisticians are not the subject matter experts, hence they lack the deep knowledge to identify the important problems and the expertise needed to tackle them.  Whereas, the subject matter experts usually lack the deep statistical knowledge required to solve those problems.  Becoming aware of those strengths and weaknesses necessarily lead to collaboration. The best collaborative efforts are usually those where the investigator seeks the statistician's input early on.
Great collaboration usually lead the statistician to explore and dig deeper on aspects of the project beyond what the original question was. In fact, that's how many new methods are initially thought of. Cox's proportional hazard is probably the best example illustrating how collaboration leads to new ideas.
There are also rare examples of professionals crossing bridges. Some epidemiologists are excellent statisticians (e.g. Sander Greenland) and I've also seen some statisticians becoming epidemiologists, as well as social scientists beoming excellent statisticians (Rand Wilcox, Paul Allison).
As someone famously said, statisticians get to play in everyone's sandbox.  A corollary is that in many cases, we do not own the sandbox.


Nagios3 saying localhost is down on ping, but no ping check is written

Question: Nagios3 and Ubuntu 14 with ping requests disabled.
The localhosts keeps reporting in the GUI nagios interface that it is down.
This is the default "localhost_nagios2.cfg" found in the conf.d dir after install:
# A simple configuration file for monitoring the local host
# This can serve as an example for configuring other servers;
# Custom services specific to this host are added here, but services
# defined in nagios2-common_services.cfg may also apply.
#

define host{
        use                     generic-host            ; Name of host template to use
        host_name               localhost
        alias                   localhost
        address                 127.0.0.1
        }

# Define a service to check the disk space of the root partition
# on the local machine.  Warning if < 20% free, critical if
# < 10% free space on partition.

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       localhost
        service_description             Disk Space
        check_command                   check_all_disks!20%!10%
        }

# Define a service to check the number of currently logged in
# users on the local machine.  Warning if > 20 users, critical
# if > 50 users.

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       localhost
        service_description             Current Users
        check_command                   check_users!20!50
        }

# Define a service to check the number of currently running procs
# on the local machine.  Warning if > 250 processes, critical if
# > 400 processes.

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       localhost
        service_description             Total Processes
                check_command                   check_procs!250!400
        }

# Define a service to check the load on the local machine.

define service{
    use                             generic-service         ; Name of service template to use
    host_name                       localhost
    service_description             Current Load
            check_command                   check_load!5.0!4.0!3.0!10.0!6.0!4.0
    }

This is pretty much out of the box config. I altered the generic-host so as not to ping anything:
# Generic host definition template - This is NOT a real host, just a template!

define host{
        name                            generic-host    ; The name of this host template
        notifications_enabled           1       ; Host notifications are enabled
        event_handler_enabled           1       ; Host event handler is enabled
        flap_detection_enabled          1       ; Flap detection is enabled
        failure_prediction_enabled      1       ; Failure prediction is enabled
        process_perf_data               1       ; Process performance data
        retain_status_information       1       ; Retain status information across program restarts
        retain_nonstatus_information    1       ; Retain non-status information across program restarts
                max_check_attempts              10
                notification_interval           0
                notification_period             24x7
                notification_options            d,u,r
                contact_groups                  admins
        register                        0       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
        }

The other servers i am monitoring are fine and nagios doesn't run any ping checks on them. however, nagios wont stop complaining that the local host is down with a critical state... on the PING:

I have scrutinized Google's offerings for over an hour now and cannot figure out how to turn this check off.
My Question:
Is this actually turned off and in a locked "down" state, or is there another setting i have missed to stop the local host running a ping check?
Thanks.
John
Answer: You have to use something for a host check, otherwise the state will never change.
Notice how it says "Last Check" was on the 17th, even though you took this screenshot on the 19th?
If you don't want to use check_ping, pick another plugin to use for a host check. Or just let it ping localhost; there's no harm in that, even though it seems unnecessary.
There's also check_dummy, which you can use to always return UP for the host check.


apply search filter to list of table table rows in jsp page coming from db using servlets

Question: I have list of data coming from db in a web page.Jsp page using servlets.
Its in the table format with  generating dynamically for list of objects picked from db.
I want to apply filter on the result items like a search box where as I type the corresponding rows will only show.
Can it be done using servlets JSP only or need to be done from front end side using jquery?
Answer: This is a UI feature, so you need to use jquery auto complete feature. for example :
<code>$( ".selector" ).autocomplete({
  appendTo: "#someElem"
});
</code>


Randomizar a posição das imagens

Question: Tenho uma lista com 10 imagens e preciso fazer com que cada vez que houver um refresh na página essas imagens mudem de posição.
Comment: Breno, bem vindo! Se você colocar aqui o código HTML das imagens que têm, vai ter uma resposta acertada.
Comment: Você pode explicar melhor o que você quer fazer, especialmente o "mudem de posição"?
Answer: Assumindo que quando você diz "tenho uma lista com 10 imagens" você se refere a algo como:

    ...

Se você quer essas imagens numa ordem aleatória, eu sugiro usar o algoritmo de Fisher-Yates:
var ul = $("#minhaLista");
var lis = $.makeArray(ul.children().detach()); // Remove todos os lis e converte num array
for ( var i = 0 ; i < lis.length ; i++ ) {
    var proxima = Math.floor(Math.random()*(lis.length - i) + i); // Sorteia um
    ul.append(lis[proxima]); // Coloca de volta na lista
    lis[proxima] = lis[i];  // Retira ele dos "ainda não sorteados"
}

Exemplo no jsFiddle.
Se seu objetivo por outro lado for que uma imagem aleatória seja a "primeira", mas as demais continuem na mesma ordem (como se você tivesse "passado pra frente" um número aleatório de vezes), é só sortear uma imagem e passar todas as anteriores pro final da lista:
var ul = $("#minhaLista");
var lis = ul.children();
var sorteada = Math.floor(Math.random()*lis.length);
for ( var i = 0 ; i < sorteada ; i++ )
    lis.eq(i).detach().appendTo(ul);

Exemplo no jsFiddle.
Comment: Sua resposta é melhor que a minha. Pode anotar que ela exige jQuery?
Comment: @EmersonRochaLuiz Eu achei desnecessário, uma vez que a tag jquery está na pergunta (em geral, perguntas com a tag javascript somente "pedem" uma resposta em JavaScript puro, enquanto pergunta com a tag jquery já deixa implícito que as respostas podem envolver jQuery). De todo modo, dei +1 no seu comentário, isso deve se suficiente pra chamar a atenção para o fato.
Comment: Bem lembrado. A questão nem mesmo está tageada com javascript, mas sim só jquery. Você está certo.
Answer: Um jeito de fazer isso, usando javascript puro e sem jQuery está listado abaixo
/**
 * Shuffle Fisher-Yates algorithm
 *
 * @see http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/
 * @param   {Array}   array
 * @returns {Array}
 */
function shuffle (array) {
    var i = array.length, j, temp;
    if (i === 0) {
        return array;
    }
    while (--i) {
        j = Math.floor(Math.random() * (i + 1));
        temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
    return array;
}

/**
 * Para um elemento pai e um array contendo nomes de arquivos, adiciona randomicamente filhos a este pai.
 *
 * @param   {DOMElement}   el      Elemento pai. Ex: document.getElementById('id-do-elemento'), jQuery('#id-do-elemento')
 * @param   {Array}        array   Array contendo a parte que muda do local da imagem
 * @param   {String}       [base]  Base do caminho
 * @returns {DOMElement}
 */
function randonImgAppendChild (el, array, base) {
    var i, base = base || '', img;
    array = shuffle(array);

    for (i = 0; i < array.length; i += 1) {
        img = new Image(); // Imagem. Poderia ser qualquer outro elemento
        img.src  = base + array[i];
        el.appendChild(img);
    }
    return el;
}

No caso, a função shuffle é usada para randomizar um array (Array.sort e Math.randon não são muito eficientes dependendo de como são usadas), e a função randonImgAppendChild é que efetivamente faz o serviço. O código está comentado então é só ler nele.
Exemplo de uso:
randonImgAppendChild(document.body, ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg'], '/pasta/base/');
randonImgAppendChild(document.getElementById('mainbar'), ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg'], '/pasta/base/');

Nota: a resposta anterior estava baseada na resposta do SO de extramaster, porém ela não é muito boa.
Comment: @mgibsonbr Editei a resposta. Agora definitivamente está compreensível. Mais fácil fazer direito do que explicar a POG do cara.
Comment: Para quem quer uma solução em jQuery em vez de javascript puro, a resposta do @mgibsonbr é melhor
Comment: Uma coisa que não entendi nem na sua resposta nem na original do extramaster é o valor do `for`: por que `23` (ou `18`)? Na pergunta linkada, o OP queria 16 imagens vindas de um conjunto de 10 (aí faz mais sentido, mas na minha leitura ainda deveria ser `16`). Tem alguma razão pra esse número?
Answer: 1 - Renomeie as imagem de 1 a 10, por exemplo:
1.jpg, 2.jpg e assim por diante.

2 - Adicione um id ao elemento onde ficaram as imagens, por exemplo:
id="bannerRandom"
var totalCount = 10;
function ChangeIt(){
  var num = Math.ceil( Math.random() * totalCount );
  document.getElementById("bannerRandom").style.backgroundImage = "url('/images/"+num+".jpg')";
}

no url, passe o local onde estão localizada as imagens.
Lembrando que dessa forma as imagens não vão seguir uma ordem e sim vão apresentadas randomicamente.
Answer: Se estiver usando PHP, isso vai lhe ajudar:
$randomImg = ['img1.jpg', 'img2.jpg', 'img3.jpg', 'img4.jpg', 'img5.jpg', 'img6.jpg', 'img7.jpg', 'img8.jpg', 'img9.jpg', 'img10.jpg'];
shuffle($randomImg);
echo $randomImg[0];

prefiro fazer nele próprio do que no css/javascript

Randomizar a posição das imagens


Questions about Maximum Likelihood Maximization

Question: (Please excuse potential error, English is nor my first language, nor am I learning stats in english). In my university statistics class, we have been discussing Maximum Likelihood functions, but I am confused as to why we sum over continuous functions as opposed to integrating. I understand that integrating would be useless because we would go right back and derive but it still seems counter intuitive. Not sure if this is a super dumb question but insight would be appreciated!
Comment: because the likelihood of a sample of independent  points is the product of the likelihood of each point. taking logs takes product into sum
Comment: Could you give an example? It's unclear what you are referring to.
Comment: Do you mean summing the log densities over the available sample?
Comment: @Xi;an, yes thats what I mean :)
Answer: This is why, in your situation,

You assume each observation is independent. This allows you to compute the joint probability of the data $x_i$ over all the observations $i$ in a sample is the product of each individual sample observation's probability:

$$\prod_{x_{i}} p(x_{i};\theta)$$

To
i. make taking derivatives easier when we symbolically maximize the likelihood
ii. avoid underflow when numerically maximizing the likelihood

we compute the log-likelihood:
$$ \sum_{x_{i}} {\log(p({x_{i}};\theta))}$$

to find the paramter $\theta$ which maximizes the likelhood we usually maximize the negative log likelihood over theta

$$\max_{\theta} \sum_{x_{i}} {-\log(p({x_{i}};\theta))}$$
Comment: Thank you! this was very helpful!
Comment: You are welcome!


Default front page not showing https

Question: My website URL shows in browser https
But on https://test.com/admin/config/system/site-information

It's showing http.
What will be cause of this? Server configuration (apache)?
Does it relate to Base URL?
Answer: Yes. The field prefix is populated by the RequestContext:: getCompleteBaseUrl() method, the underlying property, completeBaseUrl, is assigned from $GLOBALS['base_url'] if it's set.
You'll have to test that out to see if that's the case for you, because you might have a web stack configuration that causes Drupal only to see unencrypted requests (e.g. HTTPS only handled at your load balancer / proxy server level), thus displaying the HTTP base.
Comment: We r not setting `$GLOBALS['base_url']`. What can be solution?

Default front page not showing https


How to Process file on S3 event through AWS lambda using C#

Question: I am looking for C# code blocks to read file from S3 on PUT event and upload the file to another bucket. I am fairly new to C# and see most of the blogs are either written for python and java. Any help will be highly appreciated.
Thanks,
Answer: I know it's too late but maybe this will help someone else.
You need to add Amazon.Lambda.S3Events Nuget package. See code, this is how your Lambda Function should look like:
using System;
using System.Threading.Tasks;
using Amazon.Lambda.Core;
using Amazon.Lambda.S3Events;
using Amazon.S3;
using Amazon.S3.Model;

public async Task<string> FunctionHandler(S3Event evnt, ILambdaContext context)
{
    var s3Event = evnt.Records?[0].S3;
    if(s3Event == null)
    {
        return null;
    }

    try
    {
        var destinationBucketName = "your_bucket_to_upload";
        var destinationKey= "folder/subfolder/fileName.txt";

        var s3 = new AmazonS3Client();
        var request = new CopyObjectRequest
        {
            SourceBucket = s3Event.Bucket.Name,
            SourceKey = s3Event.Object.Key,
            DestinationBucket = destinationBucketName,
            DestinationKey = destinationKey
        };

        var response = await s3.CopyObjectAsync(request);
        return response.HttpStatusCode.ToString();
    }
    catch(Exception e)
    {
        context.Logger.LogLine($"Error getting object {s3Event.Object.Key} from bucket {s3Event.Bucket.Name}. Make sure they exist and your bucket is in the same region as this function.");
        context.Logger.LogLine(e.Message);
        context.Logger.LogLine(e.StackTrace);
        throw;
    }
}

You can find AWS Toolkit for Visual Studio here:
https://docs.aws.amazon.com/lambda/latest/dg/csharp-package-toolkit.html
Comment: `S3Event ` FTW
Answer: The flow would be:

Configure an Amazon S3 Event to trigger the AWS Lambda function when a new object is created
Details of the object created will be passed to the Lambda function via the event
Your Lambda function should then call CopyObject() to duplicate the object to another bucket (no need to download/upload)

See also: Copying Objects - Amazon Simple Storage Service
Comment: I was able to implement S3 event in C# .Net Core 2.1, however some of custom .DLLs are using VisualBasic function intensively and due to same reason i cant use .Net core 2.1. Could you please assist me how to call S3 event function in the main function of Custom .Net Core 3.0?
Comment: You might want to create a new Question.
Answer: Create a bucket and create IAM role that has access to the bucket you created. Assign to that role to your lambda function ( either thru AWS console or AWS SDK if you use Visual studio. the option is available in the following screenshot1)

After you published go to the Event Trigger tab and add the bucket you created. Make sure you upload the code again once you set this trigger

Upload a file and check from the cloud watch log to see function has executed. Some sample code is attached here