Cardinality of the set of an atmost countable number of functions

Question: If $\beth_0$ is the cardinality of the natural numbers, $\beth_1$ the cardinality of the continuum, $\beth_2$ the cardinality of the set of all functions from $\mathbb{R}$ to $\mathbb{R}$, where $\mathbb{R}$ is the set of Real numbers, then is the cardinality of the set of sequences of functions from $\mathbb{R}$ to $\mathbb{R}$, $\beth_1$?
Thanks in advance !
Comment: @f.nasim: Yes, that what these mean.
Comment: Do you mean $\beth_0$ and $\beth_1$ by Beth null and Beth one?
Answer: If I understand this correctly, you are asking what is $(\beth_2)^{\beth_0}$, which is the cardinality of the set $\left(\Bbb{R^R}\right)^\Bbb N$.
This is easier to think of in terms of repeated exponentiation, and in terms of $\aleph$'s. Remember $\aleph_0=\beth_0$.
$$(\beth_2)^{\beth_0}=\left(2^{2^{\aleph_0}}\right)^{\aleph_0}=2^{2^{\aleph_0}\cdot\aleph_0}=2^{2^{\aleph_0}}=\beth_2.$$
Generally, if a set has size $\kappa$, then $\kappa\leq\kappa^\lambda$, whenever $\lambda>0$. So if we start with a set of size $\beth_2$ it is impossible that by raising it to the power of $\aleph_0$ we get $\beth_1$.
Comment: Firstly,thanks !
I myself am not quite sure if what I'm asking translates into $(\beth_2)^{ \beth_0}$.Intuitively,it seems conflicting to me that $\beth_2$ can be used to represent the cardinality of both:The set of all functions from R to R and the set of only an atmost countable number of function from R to R.I feel so,because the former represents an uncountable set of functions,where each function maps onto an uncountable set($\mathbb{R}$),whereas the latter represents a countable number of functions,where each function maps onto an uncountable set($\mathbb{R}$)
Comment: Perhaps I don't fully understand what does it mean "at most countable number of function from $\Bbb R$ to $\Bbb R$". Do you mean sets of functions which are at most countable? If so, then this is the correct calculation. Note, for example that $\beth_1$ is both the cardinality of the real numbers, but also the cardinality of sequences of real numbers.
Comment: By "at most countable number of function from $\mathbb{R}$ to $\mathbb{R}$", I meant the cardinality of the set of sequences of functions,$f_{n}:\mathbb{R}\rightarrow\mathbb{R}$.
I was trying to imply that for any $c\in\mathbb{R}$,the sequence $f_{n}(c)$ is countable,but for $\forall x\in\mathbb{R}$,the sequence is uncountable.This,however,is different from the set of all functions from $\mathbb{R}$ to $\mathbb{R}$.My question,simply rephrased,is are the cardinalities of above two mentioned sets the same ?
Comment: Which one of the two: $$1.\left\{\langle f_n\mid n\in\Bbb N\rangle\mid f_n\colon\Bbb{R\to R}\right\}$$ $$2.\left\{f\mid f\colon\Bbb{N\to R}\right\}$$
Comment: :The first one.
Comment: So I understood you the first time, and there is no need to edit my answer.


How to differentiate b/w text files, images, documents using java?

Question: I am working with text files, images and documents (.log, .txt, .pdf, .doc, .docx, .jpeg, .jpg, .png, .tiff etc.).I need to get some metadata from files based on their content not from extensions. So, my questions are:
Q1. How can I differentiate b/w these category of files (plain text files, text documents(.docx), pdfs, images) using Java?
Q2. Any library in Java that would be helpful in this process?
Q3. Are pdfs containing scanned images and pdfs containing texts are different in terms of any properties or anything for that matter?
PS: I don't have much expertise on this, so kindly correct me if I am wrong in my questionnaire.
Comment: Please, take a look at **Apache Tika**. https://tika.apache.org/1.18/gettingstarted.html
Answer: You can use something like Apache Tika for detecting the MIME type. It analyses the binary data to detect the MIME type.
PDFs are detected from the first few bytes (it's %PDF). If you want more information about metadata, you could use something like Apache PDFBox, which allows retrieving the metadata (see: https://pdfbox.apache.org/1.8/cookbook/workingwithmetadata.html)
Answer: You can use Apache Tika content detection.
<code>import java.io.File;

import org.apache.tika.Tika;

public class Typedetection {

   public static void main(String[] args) throws Exception {

      //assume example.mp3 is in your current directory
      File file = new File("example.mp3");//

      //Instantiating tika facade class
      Tika tika = new Tika();

      //detecting the file type using detect method
      String filetype = tika.detect(file);
      System.out.println(filetype);
   }
</code>
Q3. Are pdfs containing scanned images and pdfs containing texts are different in terms of any properties or anything for that matter?
You can also extract image and text files from pdfs containing image & text files. This is called embedded extraction.
Check this :
https://svn.apache.org/repos/asf/tika/trunk/tika-example/src/main/java/org/apache/tika/example/ParsingExample.java


Views and Panels: Exclude already displayed items from view

Question: I have two views on the frontpage, first one is a gallery and it should show only articles which have "promoted to frontpage" checked. The second view should show all the articles except the ones show in the first view.
I saw this question, but the answer does not help me, because in the second view, i don't want to exclude the "promoted to frontpage" articles, i just want to exclude the first 6 of them, all the other should appear mixed up with the other articles.
I also found this question, but as i use panels, i think it's not working for me.
How can i pass varibales from one view to another, or how to setup conditions to work like that? Or how can i set up more complex filters in a view, like
(promoted_to_frontpage== 1 && offset == 6) || (promoted_to_frontpage == 0)
Answer: If your views are not using pager then its easy just add a contextual filter with the following php code
$offset = 5

However, it is very unlikely. The best path is to use hook_views_pre_view($view)
Something like this
function YOUR-MODULE-NAME-HERE_views_pre_view($view, &$items) // note the '&' here!
{
  global $pager_page_array;

  // if this is our view...
  if ($views->name == "my-view-name"
       // ..and we're on its first page...
       && $pager_page_array[0] == 0 ) {
    $items = array_splice($items, 0, 5); // ...then eat up the first 5 nodes
  }
}

Comment: but what happens on the second page?
Comment: if you are using pager, then you should use the second snippet
Comment: Thanks for your help, in the end, i solved it with the PHP-Code in the contextual filter
Answer: Ok in the end, i was able to handle it with the answer of the maclean, which allowed me to configure everything in the views itself:
I have got two different views, not different displays, so in the first view, my gallery, i ad the Content:nid to the available fields and set it to not visible.
In the second view, i use - as he described - the contextual filter content:nid.

Provide default value, enter the code and - also as he described - Under "More" check both "Allow multiple values" and "Exclude".


PHP mail() not sending

Question: I have a WebFaction server and the following code:
$to = "firstname.lastname@example.com";
$reply_to = "From: " . $_POST['email'];
$name = $_POST['name'];
$subject = "Outreach Request Session for " . $_POST['school'] . " on " . $_POST['date'];

$em = $_POST['message'] . "\n-" . $name;

$sentmail = mail($to, $subject, $em, $reply_to);

$sentmail returns true, but the email is not sending for some reason.
Comment: The return value of `true` only means that the message was accepted for delivery by the server. Not arriving could mean it has ended up in spam, the server is not correctly configured to send mail, etc. You should probably try serverfault.com instead.
Comment: If the PHP `mail()` function returns `true` then the problem is not with PHP. You should look at your mail server's logs. The mail could also be in a spam folder...
Answer:
$sentmail returns true, but the email is not sending for some reason.

The mail function in PHP simply sends the mail via an MTA (mail transfer agent) on the server. A true can just mean the local MTA accepted it. But that is not all you need.
First, does your hosting provider actually allow outgoing mail? Or are messages sent to a virtual "black hole?"
Now, let's assume that your local MTA—most likely sendmail—works, and the mail jumped off of the server & made it into the real world.  Okay, great!
But not so fast…
The thing is just because you send a mail, it doesn't mean that the receiving end thinks the mail is valid. And chances are the receiving end has decided a random e-mail sent off of a random server is simply SPAM.
I have posted a more detailed answer here, but when it comes to SPAM it basically boils down to this: Do you have an SPF (Sender Policy Framework) record setup for your domain? Do you also have a PTR (reverse DNS) record set for that domain?
If you do not have an SPF or PTR record, the chance of your message simply being flagged as SPAM is quite high.
If you are serious about sending mails off of your server, you need to at least get your SPF record & PTR record set.
Answer: You don't have any headers in your email.
Although they don't seem to be required, your emails will be blocked by spamcheckers a whole lot sooner.
This is an example:
<?php
        $headers = "MIME-Version: 1.0\n" ;
        $headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
        $headers .= "X-Priority: 1 (Highest)\n";
        $headers .= "X-MSMail-Priority: High\n";
        $headers .= "Importance: High\n";

 $status   = mail($to, $subject, $message,$headers);
?>

Comment: saying your sending html email when your not is more likely to get you blocked.
Comment: It was just an example of how to use headers. A standard, nothing more. Looking at the poster I assume he'll know what to do with it.

PHP mail() not sending


docker swarm nfs volume not showing all directories

Question: I've hit a wall with trying to figure this out.  I'm running docker swarm on two nodes and I created an nfs volume to my synology.
Inside of the container:
root@container:/data# ls -ltr
drwxr-xr-x 4 root root 4096 Jun 24 22:59 unprocessed

which is missing directories.  If I ssh into the host and check the docker mount there, I see this:
root@box:/var/lib/docker/volumes/vol_multimedia/_data# ls -ltr
total 4
drwxrwxrwx 1 1024 users  0 Sep  6  2021  images
drwxrwxrwx 1 1024 users 38 Dec 19  2021  unprocessed
drwxrwxrwx 1 1024 users 66 Apr  1 08:39  processed
-rwxrwxrwx 1 1026 users 41 May 29 23:21  multimedia-readme.txt
drwxrwxrwx 1 root root  36 Jun  3 22:47 '#recycle'

which is what I expect to see.  Why would there only be a subset of files visible from within the docker container?
The docker command i used to create the volume is
docker volume create --driver local \
  --opt type=nfs \
  --opt o=addr=synology.local,rw,soft,nfsvers=4 \
  --opt device=:/volume1/multimedia \
  vol_multimedia

compose file looks like
version: "3.8"
services:
  jellyfin:
    # ... removed for brevity
    volumes:
      - type: volume
        source: vol_multimedia
        target: /data
    # ... removed for brevity

volumes:
  vol_multimedia:
    external: true

UPDATE: What I had above seems to be misleading.  The container which was bad was running on a different node of the same swarm.  One node is correct but the other isn't.  Very bizarre two nodes in the same swarm would behave differently.
Answer: I never got this working.  I ended up mounting the NFS share on the host and doing a bind volume.
Comment: This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/524871)
Comment: I'm the author.  are you suggesting i move my "answer" to a comment under my question? @mforsetti


DirectRunner does not read from Pub/Sub the way I specified with FixedWindows in Beam Java SDK

Question: I am currently working on a Dataflow pipeline that reads streaming data from Pub/Sub with Apache Beam Java SDK 2.8.0. The pipeline is just the PubsubToText.java template from Google.
https://github.com/GoogleCloudPlatform/DataflowTemplates/blob/master/src/main/java/com/google/cloud/teleport/templates/PubsubToText.java
While deployment to the Cloud with DataflowRunner works as expected, it does not run correctly with DirectRunner, namely when I work on a local environment, making it so much hard to develop pipelines.
When I set the FixedWindows rate to 30s, for example, Dataflow Runner on the Cloud generates files every 30 seconds, which is expected.
When I set the same rate to the DirectRunner on a local environment, however, it won't emit files every 30 seconds. Instead, it generates files in a unstable way.
For example, it emits first data after 4 minues and creates 8 files that are supposed to have been created is actually generated at once, and next after 5 minues, next after 3 minutes, ... and so on, which makes the local development process extremely time-consuming and frustrating.
Why am I observing this?
Switching Java SDK from 8 to 11, Beam SDK from 2.8.0 to 2.9.0 or 2.10.0, environment from local to a GCE instance, nor pipeline output from GCS to local did not help.
Here is all to reproduce the problem:

git clone https://github.com/GoogleCloudPlatform/DataflowTemplates
remove the <scope>test</scope> line for beam-runners-direct-java from pom.xml to make it support DirectRunner at runtime.
Do compiling and running the program, as suggested on https://github.com/GoogleCloudPlatform/DataflowTemplates/blob/master/src/main/java/com/google/cloud/teleport/templates/PubsubToText.java , but changing runner to DirectRunner and adding --outputShardTemplate=W-P-SS-of-NN, which is a omitted option and required when running locally.
Remove --project, --stagingLocation, and tempLocation lines simultaneously, since it won't be deployed to the Cloud.
It takes extremely long to emits files, although I set, for example, windowDuration=30s

I suspected it was a Pub/Sub related problem, but when I run tcpdump, it starts to connect to Pub/Sub and pull data immediately. It's likely to be a DirectRunner specific issue.
Answer: While I don't know why this happens, I found the resolution to this problem. While DataflowRunner does not require for you to set triggers for it to work as it's supposed to, you must specify a explicit trigger for DirectRunner.
Appending .trrigering to the Window.into, the problem goes away.


O que eu coloco no gitignore?

Question: Estou aprendendo a mexer no git e GitHub essas semanas. Me deparei com uma certa dúvida:
Descobri que podemos colocar um arquivo .gitignore no nosso projeto para ele "ignorar" certos arquivos, então, é necessário mesmo usar ele? Que tipo de arquivos eu coloco nele?
Também estou criando uma aplicação em typescript:

Vendo esses arquivos, tem algum que eu posso ignorar antes de subir no gitHub?
Comment: Não é necessário usar. Vê [isto](https://fjorgemota.com/gitignore-ou-como-ignorar-arquivos-no-git/). Para NodeJs é conveniente ignorar a pasta `node_modules` pois qualquer um que tenha o código poderá fazer `npm install` para instalar as dependências.
Comment: O gitignore é usado para você não versionar arquivos desnecessários do projeto. Toda linguagem de programação possui alguns arquivos que são gerados quando você compila o projeto porém esses arquivos não são uteis para quem for baixar e executar o projeto e nesses casos são definidos arquivos ou pastas que devem ser desconsiderados quando você for versionar alguma coisa.
Comment: Relacionado: [Arquivos de TypeScript no histórico de versão](https://pt.stackoverflow.com/q/447686/100416)
Comment: coloca nele o que ignorar, depende do projeto, arquivos jar, exe, dll, etc
Answer: O arquivo oculto .gitignore irá permitir que decidas quais os arquivos que estão no teu repositório local que não queres que suba para o repositório remoto, como o nome o diz eles serão ignorados mesmo que faças alguma alteração nelas.
Por exemplo, certos arquivos que são gerados automaticamente por uma determinada linguagem de programação ou até ficheiros com credenciais como exemplo, isto depende de cada caso é claro.
Algo interessante com os documentos .gitignore é que te permite usar certas macetes. Por exemplo, ignorar todos os arquivos com uma determinada extensão poderás o fazer da seguinte maneira:
*.pdf
Podes aceder a este repositorio do github:
https://github.com/github/gitignore
Nele estão diversos arquivos .gitignore para diversas linguagens do programação como java, javascript, python entre outras que acredito que iram te ajudar e pessoalmente uso e acabo adicionando outras coisas.
Espero ter te ajudado
Answer: Boa noite Kaiky Santos,
O arquivo .gitignore não é obrigatório para a sua aplicação, porém, ele é de grande ajuda quando você não pretende não subir um arquivo ou pasta especifico.
Abaixo segue alguns links úteis sobre gitignore e alguns exemplos de gitignore para nodejs e typescript.
Link sobre gitignore: https://git-scm.com/docs/gitignore
Link contendo exemplo simples de gitignore nodejs: https://gist.github.com/ericelliott/a9c8e7810d94fdd90993e30552674244
Link para debatendo sobre gitignore typescript: https://stackoverflow.com/questions/39679722/gitignore-js-files-made-from-typescript
Answer: Bem, no gitignore você pode adicionar arquivos que não serão necessários no repositório, como pasta de módulos, arquivos de testes etc. Este arquivo serve basicamente para facilitar seu dia, voce não precisa enviar arquivos desnecessários para seu repositório!
Até mais, e tenha um ótimo dia!

O que eu coloco no gitignore?


apache httpd.conf subdomain setting cause 500

Question: I am trying to adding a subdomain for my mobile site. But when I add below code into my httpd.conf, i could open m.domain.com in my browser, but failed all www.domain.com with 500 Internal Server Error return.
NameVirtualHost *:80
<VirtualHost *:80>
    ServerName domain.com
    ServerAlias www.domain.com
    DocumentRoot /var/www/html
    RewriteEngine on
    RewriteCond  %{HTTP_USER_AGENT} "iphone|ipod|android|blackberry|opera mini" [NC,OR]
    RewriteCond  %{HTTP_USER_AGENT} "pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine" [NC,OR]
    RewriteCond  %{HTTP_USER_AGENT} "iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile" [NC,OR]
    RewriteCond  %{HTTP_USER_AGENT} "mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320|vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo" [NC]
    RewriteCond  %{HTTP_USER_AGENT} "!ipad|xoom" [NC]
    RewriteRule ^(.*) http://m.domain.com$1 [R,L]
</VirtualHost>

<VirtualHost *:80>
    ServerName m.domain.com
    DocumentRoot /var/www/html/mobile
</VirtualHost>

Here is my full httpd.conf, where am i wrong?
ServerTokens OS
ServerRoot "/etc/httpd"
PidFile run/httpd.pid
Timeout 60
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 15
<IfModule prefork.c>
StartServers       3
MinSpareServers    3
MaxSpareServers    10
ServerLimit        256
MaxClients        256
MaxRequestsPerChild  1024
</IfModule>
<IfModule worker.c>
StartServers       1
MaxClients        100
MinSpareThreads    1
MaxSpareThreads    4
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>
Listen 80
Include conf.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
ServerName www.domain.com:80
UseCanonicalName Off
DocumentRoot "/var/www/html"

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName domain.com
    ServerAlias www.domain.com
    DocumentRoot /var/www/html
    RewriteEngine on
    RewriteCond  %{HTTP_USER_AGENT} "iphone|ipod|android|blackberry|opera mini" [NC,OR]
    RewriteCond  %{HTTP_USER_AGENT} "pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine" [NC,OR]
    RewriteCond  %{HTTP_USER_AGENT} "iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile" [NC,OR]
    RewriteCond  %{HTTP_USER_AGENT} "mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320|vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo" [NC]
    RewriteCond  %{HTTP_USER_AGENT} "!ipad|xoom" [NC]
    RewriteRule ^(.*) http://m.domain.com$1 [R,L]
</VirtualHost>

<VirtualHost *:80>
    ServerName m.domain.com
    DocumentRoot /var/www/html/mobile
</VirtualHost>

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
<IfModule mod_userdir.c>
    UserDir disabled
</IfModule>
DirectoryIndex index.html index.html.var
AccessFileName .htaccess

BTW: how to set a different ip for my subdomain?
for an exapmle, my main domain ip is 18.104.22.168, and i want to setting ip 220.127.116.11 to my subdomain, many thanks.
EDIT 1
Now, i only add these lines at the end of the https.conf.
NameVirtualHost *:80
<VirtualHost *:80>
    ServerName domain.com
    ServerAlias www.domain.com
    DocumentRoot /var/www/html
    RewriteRule ^(.*) http://m.domain.com$1 [R,L]
<directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from all
</directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName m.domain.com
    DocumentRoot /var/www/html/mobile
<directory "/var/www/html/mobile">
    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from all
</directory>
</VirtualHost>

then move RewriteRule into wordpress .htaccess,
    <IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteBase /
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule ^(.+)$ /index.php/$1 [L,QSA]
    </IfModule>

    RewriteEngine on
    RewriteCond  %{HTTP_USER_AGENT} "iphone|ipod|android|blackberry|opera mini" [NC,OR]
    RewriteCond  %{HTTP_USER_AGENT} "pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine" [NC,OR]
    RewriteCond  %{HTTP_USER_AGENT} "iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile" [NC,OR]
    RewriteCond  %{HTTP_USER_AGENT} "mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320|vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo" [NC]
    RewriteCond  %{HTTP_USER_AGENT} "!ipad|xoom" [NC]
    RewriteRule ^(.*) http://m.domain.com$1 [R,L]

it works. but a new problem apears. when i access http://m.domain.com, the httpd/error_log will print Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.. How to fix this problem? thanks again.
Comment: What is appearing in the apache errorlog?
Comment: Why do you have the Server Name outside the virtual hosts, if you have an alias of the same name inside one the hosts?
Comment: The one rewrite in the provided config wouldn't cause this problem - are there `.htaccess` files in your content?
Comment: @Zabuzzman, sorry, i do not have permission to access ssh. so no `wget` to use.
Comment: @Shane Madden, yes, i have a wordpress default `.htaccess` file.
Comment: @cj333 Can you set a `RewriteLog` location and turn up `RewriteLogLevel 9` so we can see which rules are causing the problem?
Comment: If you want different IPS, just change the `*:80` to `188.8.131.52:80` and `220.127.116.11:80` on the domains you want.
Comment: @NickW, thanks, i will try, but at first, when i setting subdomain in `httpd.conf`, i can not access in my main site.
Comment: @NickW, so how to setting correctly?
Comment: @Zabuzzman, `Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.`
Comment: That error is due to your rewrite probably, I'll let someone better with apache regexes set you straight.
Comment: Can you try the request with wget and post us the output?
Answer: Your current mod_rewrite rules have a redirect loop. Both in the apache config, and .htaccess
You can resolve this by either creating seperate .htaccess files for domain.com and m.domain.com or by excluding m.domain.com from the rewrite rules. The following exclusion would be required for each rule you have checking if mobile, whether its in .htaccess or the conf file.
To disable m.domain.com from looping, add an exclusion (line 2)
RewriteEngine on
RewriteCond  %{HTTP_HOST} !^m\.domain\.com$ [NC]
RewriteCond  %{HTTP_USER_AGENT} "iphone|ipod|android|blackberry|opera mini" [NC,OR]
RewriteCond  %{HTTP_USER_AGENT} "pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine" [NC,OR]
RewriteCond  %{HTTP_USER_AGENT} "iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile" [NC,OR]
RewriteCond  %{HTTP_USER_AGENT} "mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320|vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo" [NC]
RewriteCond  %{HTTP_USER_AGENT} "!ipad|xoom" [NC]
RewriteRule ^(.*) http://m.domain.com$1 [R,L]

Current logic:
Is the client using a mobile browser? Yes, Redirect to m.domain.com. Connect, is browser mobile? Yes, Redirect, etc, etc, etc.
If you created separate .htaccess files for each domain, you could reverse the code for m.domain.com, redirecting them to domain.com if they are NOT using a mobile browser.
Binding to specific IP
<VirtualHost 22.214.171.124:80>
    ServerName domain.com
...
<VirtualHost 22.214.171.124:80>
    ServerName m.domain.com
...

Note:
The ServerName directive does not require a port number.
ServerName www.domain.com:80

should be:
ServerName www.domain.com


Http request retorna ZoneAwarePromise

Question: Criei um service para executar as solitações GET / POST / DELETE e PUT. Quando faço o primeiro request recebo ZoneAwarePromise no corpo da mensagem. Como acessar os dados dentro do ZoneAwarePromise ou alterar o meu código para não retornar o ZoneAwarePromise?

Abaixo o GET dentro do service
  public get(url: string) {
    const header = this.createHeader();

    return new Promise(async(resolve) => {
      try {
        const result = this._HttpClient.get(url, { headers: header }).toPromise();
        resolve({ success: true, data: result, error: undefined });
      } catch (error) {
        resolve({ success: false, data: {}, error });
      }
    });
  }

Aqui o meu request dentro do component.
this._HttpService.get(`${ServerUrl.ApiUrl}MarkingGet`).then(data => console.log(data));

Comment: Não entendi, pq envolveu o *get* em uma `Promise`? Alíás deveria ir na documentação do **`Angular`** e ver como faz um service get e como consome, não tem nada a ver com isso aí. Só para ter uma ideia o Angular utiliza **Observables** e para a chamada do método utiliza **subscribe**.
Comment: @LeAndrade a idéia é criar um service e diminuir a quantidade de códigos repetidos. Mas de qualquer jeito irei sim dar uma lida na documentação
Answer: Achei um documento explicando como fazer a requisição, muito bom para iniciantes como eu.
https://www.techiediaries.com/angular/angular-9-8-tutorial-by-example-rest-crud-apis-http-get-requests-with-httpclient/
No service
 handleError(error: HttpErrorResponse) {
        let errorMessage = 'Unknown error!';
        if (error.error instanceof ErrorEvent) {
          // Client-side errors
          errorMessage = `Error client: ${error.error.message}`;
        } else {
          // Server-side errors
          errorMessage = `Error server: ${error.status}\nMessage: ${error.message}`;
        }
        window.alert(errorMessage);
        return throwError(errorMessage);
}

 public get(url: string) {
   const header = this.createHeader();

   return this._HttpClient.get(url, { headers: header }).pipe(catchError(this.handleError));
 }

No componente
this._HttpService.get(`${ServerUrl.ApiUrl}MarkingGet`).subscribe(data => {
   this.result = data;

   console.log(this.result);
})

Http request retorna ZoneAwarePromise


Jquery focus not working initially in chrome

Question: I am trying to set a webpage's focus to a text input on document ready like this:
<code>$(document).ready(function() {
    $("#company_search").focus();
})
</code>
I have also tried to use setTimeout in the same manner:
<code>setTimeout(function(){
    $("#company_search").focus();
}, 5000);
</code>
But no matter what I do Chrome (desktop and mobile) will focus on the input initially and then lose focus in about a second. I can actually see it gain and lose focus, and I can even type in the text box while it has focus.
All other browsers work.
It does the same thing no matter what I focus on in the page (button, div, other inputs).
Perhaps even stranger, after I interact with the page (click a button, hide/show something) focus seems to work just fine. I can focus on anything and it stays focused.
Any ideas on what is going on? Thanks in advance.
Comment: Your code should work just fine as it is. Do you have any other code in the page? Or more than one element with the same ID (invalid markup)?
Comment: Yes, I have tried stripping all other javascript out. And have stripped out all javascript that isn't jquery. And have stripped out all css. Have tried different jquery versions too.
Comment: I figured it out. I had some iframes in my html, that are initially hidden, that didn't have a src attribute set yet. The src attribute gets set later. So the src attribute was defaulting to the current page in chrome. So there was more than one instance of every element in the dom.
Answer: After getting dom ready then use setTimeout.
<code>$(document).ready(function() {
setTimeout(function(){
    $("#company_search").focus();
}, 0);
})
</code>
Answer: I figured it out. I had some iframes in my html, that are initially hidden, that didn't have a src attribute set yet. The src attribute gets set later. So the src attribute was defaulting to the current page in chrome. So there was more than one instance of every element in the dom.


Handle async DB calls

Question: I did a couple of projects with node.js and I'm aware of the async behaviour and that one should usually use callback functions, etc. But one thing that bothers me ist the following.
I'm developing an Alexa skill and I have a function that handles the User intent:

'MyFunction': function() {
  var toSay = ""; // Holds info what Alexa says

  // Lot of checks and calculations what needs to be said by Alexa (nothing special)
  if(xyz) {
    toSay = "XYZ";
  }else if(abc) {
    toSay = "ABC";
  }else{
    toSay = "Something";
  }

  // Here is the "tricky" party
  if(someSpecialEvent) {
    toSay += " "+askDatabaseForInput(); // Add some information from database to string
  }

  this.emit(':ask', toSay, this.t('REPROMT_SPEECH')); // Gives the Info to Alexa (code execution stops here)
}

As mentioned in the code, there is some code which is usually used to find out what the output to Alexa should be.
Only on rare events, "someSpecialEvent", I need to query the database and add information to the String "toSay".
Querying the DB would look something like:

function askDatabaseForInput() { // The function to query the DB
  var params = {
    TableName: "MyTable",
    OtherValues: "..."
  };

  // Do the Query
  docClient.query(params, function(err, data) {
    // Of course here are some checks if everything worked, etc.
    var item = data.Items[0];
    return item; // Item SHOULD be returned
  });

  return infoFromDocClient; // Which is, of course not possible
}

Now I know, that in the first function "'MyFunction'" I could just pass the variable "toSay" down to the DB Function and then to the DB Query and if everything is fine, I would do the "this.emit()" in the DB Query function. But for me, this looks very dirty and not much reusable.
So is there a way I can use "askDatabaseForInput()" to return DB information and just add it to a String? This means making the asynchronous call synchronous.
Making a synchronous call wouldn't affect the user experience, as the code isn't doing anything else anyway and it just creates the String and is (maybe) waiting for DB input.
Thanks for any help.
Comment: You can make `askDatabaseForInput` take a callback too. Just a regular argument.
Comment: I'm somehow stuck. How would that help in my situation?
Comment: Seems pretty much like a dup of:https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call/14220323#14220323.  Can't take an async value and return is synchronously.  Javascript simply can't do that and your DB calls are only asynchronous.  So, the result from the DB must be used asynchronously - period.
Answer: So you could do 2 things:
Like the person who commented says you could use a callback:
function askDatabaseForInput(callback) {
  var params = {
    TableName: "MyTable",
    OtherValues: "..."
  };

  docClient.query(params, function(err, data) {
    if (err) {
      callback(err, null)
    } else {
      var item = data.Items[0];
      callback(null, item);
    }
  });
}

or you could use promises:
function askDatabaseForInput() {
  var params = {
    TableName: "MyTable",
    OtherValues: "..."
  };
  return new Promise(function (resolve, reject) {
    docClient.query(params, function(err, data) {
      if (err) {
        reject(err)
      } else {
        var item = data.Items[0];
        resolve(item);
      }
    });
  });
}

you can then either put a function in where you call askDatabaseForInput or do askDatabaseForInput.then(....).
In the function or the .then you would add what you retrieved from the database to the variable toSay
hope this helps
Comment: Oh yes. I really was stuck yesterday. Thanks Jack and Ryan. Of course using a callback helps here. It is not as "good looking" as if "askDatabaseForInput()" would just return the info, but by using "askDatabaseForInput(function(err, data) { xxx});" it at least keeps the logic where it belongs.

Handle async DB calls


Macro to build enum with different "kinds" of elements

Question: I am trying to come up with a macro which I would call like
create_states!(S0, S1, final S2, final S3);

It will create an enum to represent state machine states and some of them will be final (accepting) states - S2, S3. The resulting enum and its impl should look like:
enum State {
    S0,
    S1,
    S2,
    S3,
}

impl State {
    fn is_final(&self) -> bool {
        match self {
            Self::S2 => true,
            Self::S3 => true,
            _ => false,
        }
    }
}

My naive attempt:
macro_rules! create_states {
    ($($r:ident),+, $(final $f:ident),*) => {
        #[derive(Copy, Clone)]
        enum State {
            $($s),*
            $($f),*
        }

        impl State {
            fn is_final(&self) -> bool {
                match self {
                    $(Self::$f => true,)*
                    _ => false,
                }
            }
        }
    }
}

is ending up with the following error:
error: local ambiguity: multiple parsing options: built-in NTs ident ('r') or 1 other option.
  --> src/lib.rs:20:24
   |
20 | create_states!(S0, S1, final S2, final S3);
   |                        ^^^^^

Trying to remove the comma between the patterns in the second line:
($($r:ident),+ $(final $f:ident),*) => { ...

is producing another one:
error: no rules expected the token `S2`
  --> src/lib.rs:20:30
   |
1  | macro_rules! create_states {
   | -------------------------- when calling this macro
...
20 | create_states!(S0, S1, final S2, final S3);
   |                              ^^ no rules expected this token in macro call

I think I understand what causing these errors - it thinks that final is another identifier matching r. But what would be the right way to write such a macro (if possible at all without overcomplicating)?
I have full flexibility with the macro invocation as this is my personal learning exercise. The main objective is to learn the right way to do things. It would be nice to have this macro to accept the final at any position if possible.
Answer: This can be accomplished with a TT muncher, push-down accumulation, and handling the trailing separators.
macro_rules! create_states {
    // User entry points.
    (final $name:ident $($tt:tt)*) => {
        create_states!(@ {[] [$name]} $($tt)*);
    };
    ($name:ident $($tt:tt)*) => {
        create_states!(@ {[$name] []} $($tt)*);
    };

    // Internal rules to categorize each value
    (@ {[$($n:ident)*] [$($t:ident)*]} $(,)? final $name:ident $($tt:tt)*) => {
        create_states!(@ {[$($n)*] [$($t)* $name]} $($tt)*);
    };
    (@ {[$($n:ident)*] [$($t:ident)*]} $(,)? $name:ident $($tt:tt)*) => {
        create_states!(@ {[$($n)* $name] [$($t)*]} $($tt)*);
    };

    // Final internal rule that generates the enum from the categorized input
    (@ {[$($n:ident)*] [$($t:ident)*]} $(,)?) => {
        #[derive(Copy, Clone)]
        enum State {
            $($n,)*
            $($t,)*
        }

        impl State {
            fn is_final(&self) -> bool {
                match self {
                    $(Self::$t => true,)*
                    _ => false,
                }
            }
        }
    };
}

See also:

What does an @ symbol mean in a declarative macro?
How to allow optional trailing commas in macros?
Comment: @rodrigo probably (I didn't copy this code into the playground and make the suggested change), but I was following the [advice from TLBORM](http://danielkeep.github.io/tlborm/book/pat-incremental-tt-munchers.html): *It is recommended that, when writing a TT muncher, you make reasonable efforts to keep recursion as limited as possible. This can be done by adding additional rules to account for variation in the input (as opposed to recursion into an intermediate layer)*
Comment: Ouch.. First conclusion - no easy way here. +1, will accept once I understand it..
Comment: Could you replace the first two rules with this single one `($($tt:tt)*) => {
        create_states!(@ {[] []} $($tt)*);` and make it a little bit simpler?
Answer: Shepmaster's answer is more general, but in your specific case, since you "have full flexibility in the macro invocation", you could just replace final with @final and the naive attempt works barring a couple of minor typos:
macro_rules! create_states {
    ($($r:ident),+, $(@final $f:ident),*) => {
        #[derive(Copy, Clone)]
        enum State {
            $($r,)*
            $($f),*
        }

        impl State {
            fn is_final(&self) -> bool {
                match self {
                    $(Self::$f => true,)*
                    _ => false,
                }
            }
        }
    }
}

create_states!(S0, S1, @final S2, @final S3);

playground
Comment: So just to understand why it works.. is it because `@something` will never be matched with `ident`?
Comment: @EugeneSh. Correct. This is also the reason why it is [customary to use `@something` for internal rules when writing macros](https://stackoverflow.com/a/54406657/5397009).


Question Regarding Floquet Theory and Characteristic Exponents

Question: My classmates and I are trying to figure out the following question: given the system $y'\left(t\right) = A\left(t\right)y\left(t\right)$, where $A\left(t\right) =
  \left[ {\begin{array}{cc}
   0 & 1 \\
   \cos \left(t\right) & \sin \left(t\right) \\
  \end{array} } \right]
$, find its characteristic exponents and determin e whether it has a periodic solution of period $2π$. So far, we have written it as $\left[ {\begin{array}{cc}
   x \\
   y \\
  \end{array} } \right]' = \left[ {\begin{array}{cc}
   0 & 1 \\
   \cos \left(t\right) & \sin \left(t\right) \\
  \end{array} } \right]\left[ {\begin{array}{cc}
   x \\
   y \\
  \end{array} } \right]$, meaning $x' = y$ and $y' = x\cos \left(t\right) + y\sin \left(t\right)$. We can then write this as $x'' = x\cos \left(t\right) + x'\sin \left(t\right)$, so $x'' - x'\sin \left(t\right) - x\cos \left(t\right) = 0$. In another post, someone gave us a hint to solving this differential equation, and we came up with $x = ce^{-\cos \left(t\right)}$. However, from here we are lost; we understand the question involves u\sin g Floquet Theory, but it was not covered in great detail in class and the online resources we have found are difficult for us to understand because while the theory is described in a lot of higher-level detail, there aren't many worked through examples. Would someone be able to briefly explain Floquet Theory to us and how this question is relevant without providing a full answer so that we have a step in the right direction?
Thank you very much in advance.
Comment: Your formula for the solution is not correct: in the answer to [Trying to Solve A Differential Equation Using Variation of Parameters?](https://math.stackexchange.com/questions/3149854/trying-to-solve-a-differential-equation-using-variation-of-parameters) one is left with solving $x'(t)-x(t)\sin{t}=c$, where $c$ is constant. Its solution is $c_1e^{-\cos{t}}+c_2e^{-\cos{t}}\int e^{\cos{t}}dt$. And the last integral cannot be expressed in terms of elementary functions: [What is the integral of $e^{\cos{x}}$](https://math.stackexchange.com/questions/2468863/what-is-the-integral-of-e-cos-x).
Answer: As @user539887 already noted, the solution of the system is
$$
x(t)=c_1 e^{-\cos t}+c_2 e^{-\cos t} \int e^{\cos t}\, dt.
$$
However, it will be more convenient if we choose
$$
x(t)=c_1 e\cdot e^{-\cos t}+ c_2 e^{-\cos t} \int_0^{t} e^{\cos \tau}\, d\tau;
$$
then we have
$$
y(t)= c_1 e\cdot\sin t\cdot e^{-\cos t}+c_2\left( \sin t\cdot e^{-\cos t}\int_0^{t} e^{\cos \tau}\, d\tau+1 \right)
$$
and $x(0)= c_1$, $y(0)=c_2$. Hence, the solution can be written as
$$
\left(\begin{array}{c}
x(t)\\y(t)
\end{array}\right)=
\Phi(t)
\left(\begin{array}{c}
x(0)\\y(0)
\end{array}\right),
$$
where
$$
\Phi(t)=\left(\begin{array}{cc}
  e^{1-\cos t} & e^{-\cos t} \int_0^{t} e^{\cos \tau}\, d\tau\\
\sin t\cdot e^{1-\cos t} & \sin t\cdot e^{-\cos t}\int_0^{t} e^{\cos \tau}\, d\tau+1
\end{array}\right)
$$
is the principal fundamental matrix of the system (i.e. the fundamental matrix that satisfies $\Phi(0)=I$).
Now we can calculate the Floquet multipliers. They are equal to the eigenvalues of the matrix
$$
\Phi(2\pi)=\left(\begin{array}{cc}
  1 & e^{-1} \int_0^{2\pi} e^{\cos \tau}\, d\tau\\
0 & 1
\end{array}\right),
$$
thus, $\lambda_1=\lambda_2= 1$ and the Floquet exponents are equal to zero.
Another way to solve this problem is to use the formula
$$\prod_{i=1}^n\lambda_{i}=e^{\int_0^T {\mathrm trace}A(t)\,dt}.$$
For this system we have
$$\tag{1}
\lambda_1\lambda_2= e^{\int_0^T \sin t\,dt}=1.
$$
Since $x(t)=e^{-\cos t}$, $y(t)=\sin t\, e^{-\cos t}$ is a periodic solution,
there is a Floquet multiplier $\lambda_1=1$; the other one is given by (1).


Confused about DOE and repeatability

Question: I'm trying to design an experiment. I want to vary Pressure and temperature at two levels (high and low) and measure the effect on quality and flowrate.
I'm new to DOE and from my research I need to do a 2x2 full factorial design giving a total of 4 tests to run.
The literature mentions replication sets (where I do all 4 tests again) and center points (where i do 4 tests between the original tests). But how do I know how many replication sets I need to do? and whether center points are necessary.
I want to be able to report my repeatability but I thought this requires test being repeated at least 3 times to determine the variance etc.
Am I correct in saying that an ANOVA test is what will 'quantify' the effect of pressure/temperature on the quality and flowrate? and is a 2-way ANOVA the correct choice?
----- EDIT ----

This is a laboratory experiment and the effect of environment and
other variables is minimal.
I have randomised the order in which my runs are done to try
minimise the effect of random error and noise on the experiments
each experiment takes roughly 5 hours, I can do one per day
I have planned to do center points as a check for linearity.
my ultimate goal is to determine the effect that temperature and
pressure have on the quality and flowrate and then suggest an
operating point (Temp/pressure combination) which is the best.
thus far I have only completed the 2x2 base case tests.
Ive noticed that both temperature and pressure have significant
effects.
I repeated a single one of those tests and the results were very
similar
Answer: First: Is this a lab experiment or an experiment on a production plant? Especially in the last case there would probably be other variables than pressure and temperature that would influence the outcome. If so, can you control those other factors, or not? If they can be controlled, they could be included in the factorial design. If not, they could be seen as noise variables, and for instance if they are varying slowly, you could block the experiment, maybe using time intervals as blocks.
So, how many experimental runs can you do in a day?
If you replicate a $2\times 2$ factorial design only once (so $n=4$) and use a linear model including interaction for analysis $y = \beta_0 + \beta_1 x_1 + \beta_2 x_2 +\beta_{12} x_1 x_2 + \epsilon$, you have 4 parameters to estimate so no degrees of freedom for estimation of variance. So you should replicate the design at least twice. Then, center points is usually included as an expedient way to get some check on linearity. To say more about how many times you should replicate, we need to know about your experimental variance, do you have some idea? If not, you can do a preliminary experiment just to get some variance estimate.
So now, I have made you many questions, if you can answer them maybe we can propose something more concrete. Especially, tell us what is the ultimate goal of your experiment. If that is process optimization, you need to see into response surface design.
Comment: hello K. halvorsen, this is a laboratory experiment and I have pretty good control of the environment and can say, with relative certainty, that only pressure and temperature will be changed between experiments. I have randomised the order in which my runs are done to try minimise the effect of random error and noise on the experiments - I hope this is a sensible thing to do.
Comment: each experiment takes roughly 5 hours, I can do one per day and have just over 1 week to finish (i've done the 4x base tests). I have planned to do center points as a check for linearity as you suggested.

my ultimate goal is to determine the effect that temperature and pressure have on the quality and flowrate and then suggest an operating point (Temp/pressure combination) which is the best. This seems to me as an optimisation so I'm currently researching response surface design as suggested.
Comment: thus far I have only completed the 2x2 base case tests. Ive noticed that both temperature and pressure have significant effects. I repeated a single one of those tests this morning and the results were very similar
Comment: Thanks for this. Please note that this new information preferably should be added as an edit to the original question---then more people will see it, few read the comments.
Comment: Some update? How did the experiment go?

Confused about DOE and repeatability


How to add button to header

Question: I have a header like this:

I would like to add a button "Buy tickets" that links to a html page. How can I do this in easy way?
Comment: go to structure/blocks, add  new block, set full html on format, write your html there, save block, now on blocks page find your block and place it in top bar section.
Answer: There are a couple of ways of achieving this:
First way is to edit your theme's page.tpl.php file and add your custom html into the correct region. This will ensure your button will appear on all pages, unless you have any custom templates (page-front.tpl.php for example) that override specific pages. In this case you would simply add your code to the custom templates also.
Second method (and probably the easiest) is to create a custom block by visiting www.site.com/admin/structure/blocks and slicing on "+add block". You can then create a block with the html you need - you may need to change the input format of the text box in order to allow all your html code.
As you create this custom block you can decide which region the block will be placed into, making sure it's for the correct theme, and which pages it will appear on. Hopefully it should clear how you can achieve this from the UI.
Save your block and it should now appear!

How to add button to header


Chi-square test for checking if values are close to zero?

Question: I have a number of set of data points. For each set I have done linear regression to find the lines of best fit for the data.
I hypothesise that the gradients of all the lines of best fit should be zero.
I took the average and standard deviation of all the gradients and these are the values I calculated:
mean = $5.72 \times 10^{-5}$, standard deviation = $5.02 \times 10^{-4}$
To me, a layman, I would say that this shows that the gradients should be zero given the very small mean value and the tight standard distribution.
However I've been told that I need to be a bit more rigorous - apparently I should do a chi-squared test to prove my hypothesis.
Could someone please give me a set of steps detailing how I would go about this?
Thanks.
Comment: I think you're supposed to do a $t$-test, not a $\chi^2$-test. See [this](http://www.weibull.com/DOEWeb/hypothesis_tests_in_simple_linear_regression.htm).
Comment: @J.M. I believe that the t-test assumes a normal distribution. For my data nothing is assumed about the distribution.
Comment: Yes it does. Which means more work for you to do, i.e. a test for normality. Otherwise, I'm no longer up to date with what they use when the errors are non-normal.
Comment: Rigor definitely is needed, but a conventional chi-squared test probably won't achieve that, either.  The sampling distributions of the slopes differ from one regression to another due to differences in the x coordinates, differences in the amount of data, and differences in the mean square error.
Answer: This problem could be complex but it has a simple solution.
Let me start by explaining why the mean and SD of the estimated slopes are not relevant for testing whether all the true slopes are zero.  Consider several illustrative hypothetical alternatives:

The true slopes are all zero, so that any nonzero estimates are the result of chance variation in the errors.
The true slopes all differ from zero, their estimation errors are small enough to show that every estimated slope significantly differs from zero, but the average slope is close to zero.
Some of the true slopes are zero but at least one is not, and for that one the estimated slope is significantly different from zero.

Note, in passing, that changing the units of measurement of the dependent variable will simultaneously change all estimated slopes and the SD of those slopes by the same amount, so that only the ratio mean(slope):SD(slope) is meaningful.  In this case that ratio is approximately 1:10.  Although this indicates there is a wide variation in estimated slopes, it cannot distinguish among any of these alternatives.  That is why these two statistics are useless.
One problem is that these regressions are not necessarily related.  They could involve different values of the independent variables.  More importantly, the variation of the dependent variables could differ.  Imagine (again hypothetically) a series of experiments in which a crude (but fast and cheap) measurement is made of the dependent variable, and then later is followed up by other experiments in which the measurement is made in a more precise way.  We couldn't just dump the combined data into one regression model, due to the possibly large differences in distributions of the errors.
Another problem is that the residuals might not have Normal distributions.  When each regression includes enough data (typically 30 points is "enough," but as always it depends), the sampling distribution of the estimated slope is still approximately normal, so the t-testing apparatus applies.  With small amounts of data, or when some data have high leverage, the t-tests are suspect.  However, that's a common problem having many cures, including using generalized linear models, re-expressing (transforming) the independent variables and/or the dependent variable, and other more specialized approaches.  So let's assume that the regressions have been appropriately done.  This means that we can trust the p-values for the slope tests.
Now we're off and running.  The p-value for a single regression, under the null hypothesis that the slope is zero, will have a uniform distribution.  Therefore the p-values obtained from each regression should behave like a set of independent draws from a uniform distribution.  Small p-values suggest significant differences, so we are interested in whether there are more small p-values than would be expected by chance.  (We should also be interested in whether the set of p-values really does look uniform: significant deviations from uniformity would suggest problems with the regressions or subtle violations of the null hypothesis.)  A useful statistic, then, is the minimum p-value.
The axioms of probability immediately imply the minimum $p$ of $n$ independent draws from a uniform distribution has a CDF of $\Pr{[p \le t]} = 1-\Pr{[p \gt t]} = 1-(1-t)^n$.  To test the null hypothesis that all slopes are zero at the $\alpha$ level (say $\alpha=0.05$, corresponding to $1-0.05 = 95\%$ confidence), we therefore follow this simple procedure:
(a) Let $p_0$ be the smallest p-value of all the $n$ regressions.
(b) Compare $1-(1-p_0)^n$ to $\alpha$.  If it is smaller, conclude that at least one slope is nonzero.  If it is not smaller, do not reject the hypothesis that all slopes are zero.
Note that this is algebraically the same as checking whether $p_0$ is smaller than $1-(1-\alpha)^{1/n}$.  For small $\alpha$ this is close to $\alpha/n$.  (The relative error made by this Bonferroni approximation is always less than $-\log(1-\alpha)/\alpha$, which is about $1+\alpha/2$.  For $\alpha=0.05$ that's a relative error of about $1.025$, which for most purposes is negligible.)  These considerations lead to a simple procedure indeed:
Reject the hypothesis that all slopes are zero only when the smallest p-value of the regressions is less than $\alpha/n$.
Answer:
"To me, a layman, I would say that this shows that the gradients should be zero given the very small mean value and the tight standard distribution."

One can infer from the numbers you provided (using, e.g., Chebyshev's inequality) that the observed gradients, not only their mean and SD, were small.   To the extent that the gradients derived from the data sets are independent observations (from similar distributions) of one underlying "true" gradient this is evidence that the parameter itself is small.
That the SD is ten times larger than the mean is consistent with the idea that the observed gradients are random errors around a true value of zero.  It is also consistent with the mean being small (but nonzero) for systematic reasons, maybe similar to whatever reasons led to the suspicion that the mean is exactly zero, and observational noise larger than the true size of the mean.
To say more, additional information is needed about the number, size and nature of the data sets used to determine the gradients.
Comment: Much of this reply assumes that $10^{-4}$ is "small," but @John rightly points out this is a matter of units of measurement (and therefore is meaningless).  The large SD (compared to the mean) shows that there is *considerable variation* of the individual slopes compared to their average.  This might or might not be consistent with the true mean being zero.  Finally, we cannot assume these slopes have a common sampling distribution; in fact, that's unlikely.  Thus the SD actually tells us little about what's really going on.  We need more information to say *anything* here.
Comment: As I have tried to explain, assumptions are needed to justify most of your conclusions, whether or not you were aware of them.  So, yes, you "made no such assumptions," *but you needed to.*  Also, perhaps because my example was communicated in a telegraphic manner, I think you may have misunderstood it.  The value of 22000 (wherever it comes from) is not relevant.  The $\pm$ values express standard errors of estimation, nothing more.  If only a single slope has a low SD compared to its estimate, we should conclude that not all slopes are zero.
Comment: The OP called 1/10000 "small" and knows what units and meaning it has in his problem.  Here the mean and SD have the same units and their ratio is dimensionless.  It is not necessary to assume a single common sampling distribution, only similar variances (and if that is not the case, a small ratio of mean to SD still imposes strong constraints). More information is needed but as e.g. the Chebyshev calculation indicates one can say something, just a lot less than with full information.
Comment: @whuber: re "that might *or might not* be consistent with the true mean being zero" -- how could it be *inconsistent* with the mean being zero?  It is consistent with the mean being zero, and also consistent with the mean being nonzero but the observations of the mean having SD higher than the value of the mean.  As was pointed out in the answer.  Are you saying there are relevant classes of models where a small observed ratio (mean/SD) *disfavors* the hypothesis that the true mean is zero?
Comment: I agree a process with zero slope could produce these statistics.  But suppose, hypothetically, that one of two regressions has a slope of $0.0005 \pm 0.000001$ and another has a slope of $-0.00045 \pm 1$.  Their mean is $0.00005$ and SD is $0.0005$, as in the question, but there is extremely strong evidence that one of the slopes is nonzero.  That's why you cannot deduce *anything* about whether all slopes are zero from these statistics alone.  Chebyshev doesn't tell you anything of relevance.
Comment: @whuber: Notice, as in your example, that in order for such things to occur, a conspiracy (that is, an actual phenomenon in the data generation) has to occur to suppress the high-variance terms from contributing to the mean. So one *still* can say something, and it will likely be interesting in relation to the problem of interest.  It will not be as simple as the canonical case of i.i.d or nearly iid gradients.  But you still have to explain how a mean that "could" have been larger is ten times smaller than the SD.  Numerical accidents can be ruled out by taking subsamples.
Comment: You assume (among other things) that all the regressions concern the same dependent variable, involve similar numbers of data, and span the same ranges of independent values.  There's no "conspiracy" in having any of those differ, and any such differences can create large differences in the variances of the sampling distributions, which is the crux of the matter. Beyond pointing out any one of these possibilities, I don't need to explain anything, but your speculations have to assume quite a lot (which was unstated). Your assumptions may be true, but so far we have no evidence that they are.
Comment: @whuber: I made no such assumptions. As your own example illustrates, it is not true that "large differences in the variance of sampling distributions" can explain a high SD/mean ratio (without having even higher unexplained ratios in the observations for the high variance components).  In that example of two regressions, an overall SD/mean ratio of 10 was derived from a ratio of 22000 for the higher-variance regression.  This phenomenon and its generalizations are calculations and theorems, not "assumptions".
Answer: The answer to your question would depend greatly upon a number of things you didn't mention, but what you're attempting is called a random coefficients analysis (RCA) and you'd want a t-test here against 0.  It might be better to just generate a confidence interval around your coeffcient.
One might say that your standard deviation isn't small, it's rather large.  It's 10x larger than the slope.  Then again, I can't tell if any of the values are large or small because you haven't given a reasonable range of values that it could possibly be.  Let's say the predictor in your regression is some very wide ranging value, perhaps mass of ships in grams.  If your predicted value was something with a relatively small but meaningful range, like length of time for the hull to rust through in years, then your coefficient would be a very small number but still be a very large effect.  So you need to give a lot more information before you can get a good answer.
Comment: "RCA" is so obscure I can't figure out exactly what it is from Web-accessible documents, but it seems to assume much more than given in the question.  In particular, separate independent regressions need not even have comparable error variances (or even error distributions).  So that's one more piece of information needed here: what, if anything, do all these regressions have in common?
Comment: Yes, you are correct, I did sort of assume they had something in common, like came from similar power plants in different location, or something like that.  RCA is sort of a replacement for repeated measures.  It is possible that the regressions are unrelated.  It was used extensively in early FMRI research because the amount of data made analysis using something like mixed effects intractable.  It has been shown to be pretty good given a minimal amount of standard assumptions.
Comment: I should say that there are still lots of ERP or FMRI researchers who use what could only be called RCA analysis.
Comment: Oh, and I did a quick web search and found loads on random coefficients analysis.  RCA has too many alternatives.


Authenticating to Exchange 2010 smarthost?

Question: I have a postfix mail server that should relay all outgoing mail to an Exchange 2010 server (the Exchange box is my smarthost).  I have administrator access to the Exchange 2010 system, but I'm not very familiar with it.  How should I set up authentication on the Exchange 2010 system?
I guess I could add a standard user with a mailbox on the Exchange box, then configure my postfix box to log in to port 587 to relay mail.  That option doesn't feel right -- it seems like there should be way to do server to server authentication, not just client to server authentication.  Is there?  If so, how would I set it up?
Edit:

the postfix mail server is at a remote site with a dynamic IP address, so authenticating by IP address won't work
I would like the email traffic between the two to be encrypted
I would like mutual authentication (the Postfix box knows it's talking to the Exchange box and not a man in the middle; Exchange knows that it is talking to the Postfix box)
setting up an IPsec tunnel seems overly complicated for what should be a trivial Exchange configuration
Exchange must allow the Postfix box to send messages to any destination
the messages submitted by the Postfix box must not be rejected as spam even if they look like spam
Comment: I see your edits. You can turn on encryption... SSL or TLS. You didn't initially say that the server was offsite. Ideally, you have an IP range you can limit to. If not, use authentication. The menus in my answer are the same, without the IP and Anonymous relay portions.
Comment: @ewwhite:  Apologies for forgetting to mention that the server was off-site.  If I choose 'Basic Authentication', what do I use as the username and password?  What 'Permission Groups' should I use?  Can I somehow extend the existing client receive connector so that I can still use the standard message submission port (587)?
Answer: I usually don't have my Linux and internal servers authenticate to the Exchange server if they're on the same network. Same for other devices that may need to relay (copiers, monitoring systems, etc.). I still may need the smarthost funcationality, though.
The approach I take to enable a dumb server/device-to-server relay like what you're looking for is to enable the smarthost on the Postfix or Sendmail system. It seems as though you know that part. For Sendmail, it's a matter of uncommenting the "dnl" line related to the SMARTHOST entry in /etc/mail/sendmail.mc, and defining an address. For Postfix, it's defining relayhost in /etc/postfix/main.cf. (restart both daemons after the change)
On the Exchange 2010 side, you need to create a new Receive Connector:
Exchange System Manager -> Server Configuration -> Hub Transport -> Receive Connector

Add a new one by right-clicking the frame and selecting "New Receive Connector".
Name it something descriptive, like the FQDN of the Linux server you wish to send from (e.g. postfix.abc.com).

Specify the address/mask of the relaying server; 172.16.2.30/32 in this example.

Continue through the prompts and add the receive connector.
Open the Exchange Management Shell command line window.
You'll want to grant your new receive connector Anonymous privileges.
Execute:

Get-ReceiveConnector RelayConnector | Add-ADPermission -User "NT
  AUTHORITY\ANONYMOUS LOGON" -ExtendedRights
  "ms-Exch-SMTP-Accept-Any-Recipient"

...where "RelayConnector" is postfix.abc.com in my example.
Immediately select the newly-created entry in the Management GUI and select "Properties".
In the "Authentication" tab, deselect all entries. In the "Permission Groups" tab, ensure "Anonymous users" is checked. That's all!
Comment: what happens if we don't add the ADPermission and just do it from the console?
Comment: @fmysky It won't work the way you'd want. It's a matter of treating the relaying source as [trusted versus untrusted](http://exchangepedia.com/2007/01/exchange-server-2007-how-to-allow-relaying.html). Try it and see.
Comment: just the matter of granular permissions to be set. Thanks for the link.
Comment: Thanks for the answer.  Unfortunately, the Postfix box has a dynamic IP address (see updated question), so authenticating by IP address won't work for me.  Is there a way to authenticate by username and password instead?
Answer: I believe there are 2 components to the solution:

Configure postfix to relay: There's a guide here which details the sendmail config. http://www.walkernews.net/2010/05/18/how-to-configure-sendmail-to-relay-email-to-exchange-server/
Exchange Server Config to relay emails sent by postfix: You need to configure Exchange server to allow emails from Unix to be relayed. Guide here: http://blogs.technet.com/b/exchange/archive/2006/12/28/3397620.aspx

You can control email relay in exchange by IP, by permission, by using IPSec or mTLS. For an internal unix postfix box, the easiest would be to restrict by IP. You need to create a Send Connector and limit the IP-scope, as detailed in the guide above.
You may need to look-up specific smarthost forwarding guides for postfix.
Configuring Server-Server Authentication between postfix and exchange:
Exchange 2010 uses mTLS for externally secured mail relay. Here's a guide on how to set this up from Exchange end. http://technet.microsoft.com/en-us/library/bb123543.aspx
Postfix also supports TLS authentication, but I am not sure how to configure the postfix side of the solution.
http://www.postfix.org/TLS_README.html


How do you cross validate a regression model with a variable derived from historic information

Question: I have a logistic regression model for conversion rate after sending a customer a voucher. The dataset consists of all previous occasions where customers were sent a voucher, with the response whether they used the voucher or not.
One of the predictors in the model is a recency-weighted calculation of their spend, on previous occasions where they were sent, and used a voucher, for example,
$$\text{previous spend} := \sum_d \frac{1}{d} s_d,$$
where the summation is taken over days $d$ previous to today with a non zero transaction for the customer, with $s_d$ equal to how much was spent on that day while using a voucher. As an example, if a customer had 3 previous transactions, at weekly intervals before today, for $1 each, their previous spend is calculated as:
$$\frac{1}{7} + \frac{1}{14} + \frac{1}{21}$$
I am unsure whether I have done the recency weighting correctly, in the sense that while this variable is significant in the regression, I am unsure whether it will remain so on new data.
Thus I would like to use cross validation on my model. I am unsure how to calculate this variable in this case, should I:

Pre-calculate the values for $\text{previous spend}$, and calculate model parameters and fit via usual cross validation.
Re-calculate the values for $\text{previous spend}$ on the train and test set for each cross validation fold, before model fitting and evaluation via usual cross validation.
Some how include the historic averaging as a model parameter, so that it can be cross validated directly.

Please throw some light on the advantages/disadvantages of the methods listed above, or any other you think is suitable.
Comment: Thanks.  This is a nice question that I don't have an immediate answer for.  I'll think about it, but in the meantime hope someone smarter comes along!
Comment: Just to clarify, your data set has multiple records for each customer (each time a voucher is sent), and also multiple customers?  Also, do you want to use the model on new customers who have not received a voucher (its unclear how you would do so with this setup)?
Comment: yes, multiple records for each customer and also multiple customers. The model will not be used on new customers.
Answer: This is an excellent opportunity to bootstrap the regression coefficient. This will get you from A to B more directly than if you were to use cross-validation.
Think of bootstrapping as the following:

Take a random sample (this could be of transactions or of people: you should make this judgement call after considering both)
Estimate the regression coefficient associated with the logistic regression

At the end of this process you will have a distribution of beta values. From this you can calculate a confidence/credible interval.
Programmatically, this can be accomplished using the boot package in R, or you could merely perform the sampling in a for loop.
Comment: thank you for your answer. I am not quite sure how bootstrapping helps to measure predictive performance of the model, even after reading http://stats.stackexchange.com/questions/18348/differences-between-cross-validation-and-bootstrapping-to-estimate-the-predictio
Comment: however, your methodology does not cover my fundamental question: that is, when taking random samples (either for bootstrapping or cv purposes), what value should you use for the $\text{previous spend}$. Do you recalculate this based on the sample you have, keep the precalculated values, or???


Size of content in iframe in iOS Safari (iPhone)

Question: I have a problem with some content that I (sadly) need to use an iframe for. (It has to do with picky clients and domain names - it's out of my hands...)
Here is a page with the iframe:
http://madslund.dk/test/iframepage.html
Here is the page with the actual content:
http://madslund.dk/test/content.html
The iframe page basically just shows the content from the other page. No problem so far.
Here is the problem:
The content inside the has a set width (700px) but resizes to fit the screen (max-width: 100% in the css). This works fine when viewing both pages in the browser, but on the iPhone, it only works when you view the content page directly.
Javascript: alert(window.outerWidth) outputs 320 (as expected) in iframepage.html, but 735 in content.html. So it seems like the iphone simply resizes the iframe to fit the content inside.
Answer: It seams that in iOS 7 the Mobile Safari turned the seamless attribute for the iframe on by default with no way to turn it off. (Or at least form my own test on the Mobile Safari, this seams the case.) As of yet, I have not found of a way to make the IFrame responsive and retain the scrolling of the frame, but if you are willing to sacrifice the vertical scrolling you can use this code:
HTML:

CSS:
iframe {
    min-width: 100%;
    width: 100px;
    *width: 100%;
}

This solution works in a cross browser way, but keep in mind, if you turn the scrolling to "yes" then it won't anymore so you do need to know the height of your content.
Comment: Why in the world does width: some large number px have to be set for max-width to work? Is it a known iOS bug?
Comment: @NoBugs its not a bug exactly as far as I know Apple did it intentionally it has to do with horizontal scrolling areas within a page, [you can see this question here](http://stackoverflow.com/questions/23083462/how-to-get-an-iframe-to-be-responsive-in-ios-safari/23083463#23083463), where I posted the problem and solution when I understood it completely, but it's basically down to the seamless attribute. As to your problem, then as long as the screen width is smaller than the allocated width, then there should not be a problem.


Prove that $\|f\|_{L^r}\leq \|f\|_{L^p}^\alpha \|f\|_{L^q}^{1-\alpha }$ if $\frac{1}{r}=\frac{\alpha }{p}+\frac{1-\alpha }{q}$

Question: How can I prove that $$\|f\|_{L^r}\leq \|f\|_{L^p}^\alpha \|f\|_{L^q}^{1-\alpha }$$ if $\alpha \in[0,1]$, $\frac{1}{r}=\frac{\alpha }{p}+\frac{1-\alpha }{q}$ and $f\in L^p\cap L^q$. It looks to be something with Holder, but I can' conclude.
Comment: [this is](https://math.stackexchange.com/questions/2421496/if-frac1p-frac1q-frac1r-then-fg-lr-leq-f-lp-g) same type of question, isn't?
Answer: One can show using Hölder's inequality that if $r,p,q\in [1,\infty]$ with
$$ \frac{1}{r} = \frac{1}{p} + \frac{1}{q}, $$
then
$$ \|fg\|_{L^r}\le \|f\|_{L^p}\|g\|_{L^q} $$
for every $f\in L^p$, $g\in L^q$. Now, since we are given
$$ \frac{1}{r} = \frac{\alpha}{p} + \frac{1-\alpha}{q} = \frac{1}{p/\alpha} + \frac{1}{q/(1-\alpha)}, $$
applying the result I just mentioned yields
\begin{align*}
\|f\|_{L^r} = \|f^\alpha f^{1-\alpha}\|_{L^r} & \le \|f^\alpha\|_{L^{p/\alpha}}\|f^{1-\alpha}\|_{L^{q/(1-\alpha)}} \\
& = \left(\int |f^\alpha|^{p/\alpha}\right)^{\alpha/p}\left(\int |f^{1-\alpha}|^{q/(1-\alpha)}\right)^{(1-\alpha)/q} \\
& = \|f\|_{L^p}^\alpha\|f\|_{L^q}^{1-\alpha}
\end{align*}
for any $f\in L^p\cap L^q$.


Pipe processing to extract tar buffer in Node.js Child Processes

Question: I would like to do this by Node.js:
git archive email@example.com:repo.git HEAD | tar -x - -C /path/to/extracted/

So, I wrote codes something like this:
git = spawn 'git', ['archive', "--email@example.com:repo.git", 'HEAD']
tar = spawn 'tar', ['-x', '-', '-C /path/to/extracted']

git.stderr.on 'data', (data) ->
  console.log "git error: #{data}"

git.stdout.on 'data', (data) ->
  tar.stdin.write data

tar.stderr.on 'data', (data) ->
  console.log "tar error: #{data}"

git.on 'exit', (code) ->
  console.log "git process done with code #{code}"

tar.on 'exit', (code) ->
  console.log "tar process done with code #{code}"

However this doesn't work as I expected. What should I change to make this work properly?
Thanks in advance.
UPDATE
Proper command actually doesn't need - between -x and -C
git archive email@example.com:repo.git HEAD | tar -x -C /path/to/extracted/

Answer: You should use the function exec and not spawn in that case. As seen in the exec documenation it accepts pipes exec documentation
exec('git archive firstname.lastname@example.com:repo.git HEAD | tar -x - -C /path/to/extracted/', function (error, stdout, stderr) {
    // logic here
}

Answer: You should beware of command injection when using child_process.exec. You can accomplish a similar behavior with spawn by using .pipe which you can apply to streams (which is what spawn uses). https://nodejs.org/api/stream.html#stream_event_pipe


Skewed population example

Question:
"Consider a strongly skewed population (e.g., waiting times at airport security screening)."

My book always uses that example when referring to skewed populations. I don't understand why would that specific situation have a skewed graph.
Comment: Waiting times vary from small positive to arbitrarily large. Usually small positive, at least compared with the arbitrarily large. Now imagine sketching that.
Answer: Airlines wait times, in the US, are about 30 - 45 minutes in major hubs. However, time to time major delays or increased travelers can create extremely large outliers, skewing the average wait time up.
If you're interested to know more, day-to-day average wait time and tallies on wait time brackets in the US can be downloaded here. Nothing beats checking the facts ourselves. It does not include, as far as I know, the security check time, but I believe they are likely quite correlated.
Comment: Security screening has an additional component that your correct answer misses.  Airline wait times are all roughly equal on any give day, people queue up in one line and wait their turn to be in the front.  The security line behaves slightly differently.  _Most_ passengers have roughly equal weight time (e.g. ~10 minutes on a light travel day) but some get pulled aside for additional screen that can take hours.  This is the skew I assumed the book was talking about.

Skewed population example


non-linear fit problem with high Pr

Question: I would like to find the appropriate model to my data:
x <- c(10, 40, 70, 100, 130, 160, 190, 220)
y <- c(0.190000, 0.857500, 3.845714, 11.194000, 20.208462, 36.257500, 62.077895, 109.726818)
I used symbolic regression to reach the correct analytic formula in fitness and complexity.
Since a*x**b looked the best.
After I did the the non-linear fit:
nr <- nls(y ~ a * x**b, start = list(a = 0.001, b = 2), trace=TRUE)
Which result in:
Formula: y ~ a * x^b
Parameters:
   Estimate Std. Error t value Pr(>|t|)
a 1.408e-06  1.132e-06   1.244     0.26
b 3.366e+00  1.510e-01  22.283 5.34e-07 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 2.493 on 6 degrees of freedom
Number of iterations to convergence: 35
Achieved convergence tolerance: 3.87e-06
Probably this is by far the best fit what I can reach:
cor(y,predict(nr))
0.9984649

a <- coefficients(nr)[1]
b <- coefficients(nr)[2]
t <- seq(from = 0, to = 300, length = 50)
plot(x,y)
lines(t, a * t**b, lty = 2, col = "red")

Plot
But the 'Pr' value of 'b' parameter looks high,
since can I accept this model, or it is problematic?
Can you suggest a better way for this fitting?
Thanks

Answer: If you draw the data on log-log scale, you should obtain a straight line with the function $y=ax^b\quad\to\quad$ log(y)=log(a) + b log(x).
On the first figure one can see that is well obtained, except the first point (10, 0.19).

This draw to think that there is a typo in the data.
On the second figure the first point is (10, 0.019) instead of (10, 0.19). The alignment of the points is much better. So, the hypothesis of a typo is strengthened :

If there is no typo, the bad alignment of the points means that the function $y=ax^b$ isn't convenient.
A better result can be obtained with the function :
$$y=ax^b+c$$
which requires a regression with three parameters instead of two :

This is drawn with the not corrected data : first point (10, 0.19).
Comment: There isn't any typo in the data. Thence I found a better model to the data: y ~ a * e^(b*x), this one is more stable.
Comment: As you confirme that there is no typo in the data, I post a new answer related to the new kind of model $y\simeq ae^{bx}$.
Answer: The first answer considers models of the kind $y\simeq ax^b$ as suggested by pnz.
Meanwhile, pnz observed that models of the kind $y\simeq ae^{bx}$ are better. That is true in some extend.
This leads to a different answer.
$$y=ae^{bx} \quad\to\quad \ln(y)=A+bx \qquad A=\ln(a)$$
So, the relationship should be linear in the $x,\ln(y)$ graph. This is far to be the case in the range of small values of $y$, as appearing on the next figure.
As a consequence, the fitting cannot be accurate on the whole range.

In order to try to correct the discrepancy a constant term $c$, in fact negative, can be introduced in the model :
$$y\simeq ae^{bx}+c$$
The fitting is improved in the small range of $y$ as shown on the next figure :

non-linear fit problem with high Pr


Hamming distance for strings with different length

Question: I am working on a project that involves computing similarity metrics between strings. I was would like to know whether it is possible to use hamming distance on strings with differnt length, and if possible, how to go about it. I step by step explanation would be grately appreciated.
Thanks.
Comment: Given that you only want a crude fast measure, why not just pad out the shorter strings with empty characters?  In effect, define the Hamming distance to be the number of places in which the two strings differ plus the difference in their lengths.
Comment: [*Here's a search for Levenshtein on stackoverflow.*](http://stackoverflow.com/search?q=levenshtein)
Answer: Hamming distance fundamentally assumes that the input strings are the same length.  You can generalize hamming distance a bit to allow for insertions and deletions and arrive at the Levenshtein distance.  How big are your strings?  The edit distance is much harder to compute for long strings.
Comment: I am working on address field of a database. My strings have varying length; say 4 to 6 words. Please can you break down how to generalise the hamming distance to allow for insertion?
Comment: That wikipedia article does a much better job explaining it than I will.  It's not a particularly simple idea, you shouldn't expect to understand it, and especially how to compute it, immediately.  The basic idea is to add costs to the delete and add operations on strings. Then find the minimum cost sequence of edits between strings, which can be done with dynamic programming.  You can probably find an implementation of the algorithm in your language of choice, or implement it yourself from the pseudocode on that page.
Comment: my aim is to use a variant of levenshtein distance that requires relatively less computational cost, thats why I opted for hamming distance. However, the variablity in string length might pose a problem.


dRAID, Parity 1 + 1 Distributed Spare Better than basic RAIDz2 for 5x12TB HDDs?

Question: Stumbled on dRAID recently and was grokking the docs for OpenZFS on linux and I came away with a conclusion from the chart that I wanted to double check.
This is a brand new system that I'm currently building from scratch and trying to plot out how to use my 5x12TB HDD disks. My priorities:

Data Integrity
Storage capacity
I/O Performance
Uptime (home lab use)

I was happy with the capacity and write performance of RAIDz1, but because of the size of these drives, I couldn't risk a second drive failure while rebuilding a failed one (my impression was that a 12TB drive could take a day or so, linked chart seems to agree). So I was forced to choose RAIDz2, which hits my overall capacity, but I'm fine with that. What I was worried about was write performance hit (I might just have to run tests...for another post).
Anyway, the chart on dRAID docs in the link above suggests that even for 5 drives, having parity 1 (equivalent to RAIDz1) and a distributed spare shortens rebuild time to just about 4 hours and greatly reduces the load on the single new drive. Faster rebuild for 1 drive and less write load seems to greatly diminish the risk of a second failed drive of this size while rebuilding the first as the burden is shared.

Question 1: I know that dRAID is for pools with many more disks, but other than complexity of setup (which I'll figure out), I only see upsides to choosing the dRAID route over RAIDz2.
Would you agree? Am I missing something about dRAID?
Question 2: More specifically, is the risk of a second drive failure reduced enough in the dRAID strategy so that I can get the capacity and performance back of only having 1 parity? My cake and eat it too?
Update: If anyone had some pointers on how to test this setup with the two methods, I'm down to try so that we could get some real data. I'm new to ZFS, so I'd need some help.
Answer: Your are misreading the chart: it depicts a total of 90 disks, with various groups/vdevs configuration. You can't extrapolate any useful info for a single 5x RAIDZ1 array.
DRAID is not meant for such low number of disks. The breakeven point probably is at around 24 disks, possibly more. Don't use it for a single 5-way RAIDZ1 array.
Regarding RAIDZ1, I would not use it for any array bigger than 4x 4 TB HDD except for very specific cases (it is fine with SSD, tough).
Comment: I would love your source material on where you got that "break-even" number of 24 disks. Break even for what? What's the trade off at that point between?
Comment: I use dRAID for 8 disks or greater. I even have it running on some 400-disk systems. My main consideration is rebuild time. There's no rule of thumb, but for home use, I think there's a trend towards overanalyzing the topic of "Which ZFS layout should I use?"
Comment: @brianclements it was the "ballpark number" discussed on the mailing list, if I remember it correctly. It is not an hard limit (but I would not go less than 8). The tradeoff vs RAIDZ is the two step resilver (raw copy + healing resilver) and a less intuitive available space calculation.


Odd log entries: is it indicative of an attack?, is there anything other than IP blocking that I should do?

Question: So I've been getting some odd log entries in my Drupal 7 install:
Here's two:

As far as I can see they haven't done anything and I've blocked the IP addresses but they keep coming with different IP addresses so I'm wonder what they actually mean? Like if they were for manager/html I'd know they were (probably automated) attack testing for Apache Tomcat apps to hack. But these with a location that isn't even my site I'm confused by.
Also wondering why the message starts with ttp:// instead of http:// or something normal.
Answer: Well continued my research and a day without no answer was enough time for me to figure it out. As I suspected yes this is an attempted attack/test. It is not specifically an attack on Drupal although it does show up in the Drupal log.
Specifically this is checking to see if your server is set up in such a way that it can be used as an open proxy; in other words if you give it a get request for a domain it doesn't serve will it GET the content from the right server and pass it on. This is bad without a login, since it lets anyone appear to be your server while they are spamming/etc - see the Apache Proxy Abuse Page.
In this case since Apache passed the request on to the virtual hosts it shows that the server is not configured as an open proxy and is safe (at least from that attack vector at this time). The server logs show a 404 as well which confirms that either the url was invalid or that there is no open proxy:
126.96.36.199 - - [03/Dec/2014:08:08:52 -0500] "GET http://6.url.cn/zc/chs/img/body.png HTTP/1.1" 404 716 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.3072; .NET CLR 2.0.50727; .NET CLR 3.0.30729; Tablet PC 2.0)"

If it was a successful attack test/attack it wouldn't appear in the Drupal logs, only in the server logs. In the server logs it would appear something like:
220.127.116.11 - - [03/Dec/2014:08:08:52 -0500] "GET http://6.url.cn/zc/chs/img/body.png HTTP/1.1" 200 716 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.3072; .NET CLR 2.0.50727; .NET CLR 3.0.30729; Tablet PC 2.0)"

with a response code that indicates a valid resource.
As to why the Drupal log strips the initial h for the message I don't know and it doesn't really matter; that being said if I have time I'll probably investigate it and submit a patch to fix it.


How to extrapolate my sample results to population

Question: We have tested randomly selected bacteria ($k = 198$) for antibiotic resistance over a period of 3 years (total isolates $n = 444$) and observed $117$ resistant strains.
I would like to extrapolate my results to total isolates. I presume,
$$\hat{q} = \frac{117 \times 444}{198} = 262.$$
Is there any specific statistical method for this analysis?
Answer: First of all, the selected bacteria must have been selected randomly to do any inference.
262 is indeed a good estimate of the resistant strains you would have in your population.
But what you would like to get - I guess - is to know how accurate is this estimation. The simplest way to do that is to compute confidence interval.
The 95% confidence interval for your proportion would be (if your population was infinite) :
$$\hat{p}\pm z_{\alpha/2}\sqrt{\dfrac{\hat{p}(1-\hat{p})}{n} }$$
In your case, this is different, as you study almost half of your population, you can pretend to have a better estimate of your proportion :
$$\hat{p}\pm z_{\alpha/2}\sqrt{\dfrac{\hat{p}(1-\hat{p})}{n} \cdot \frac{N-n}{N-1}}$$
In your case you have $z_{\alpha/2}=1.96$, $N=444$, $n=198$, $\hat{p}=\frac{117}{198}$
If I typed it right wolfram alpha gives $0.066$
This means that in your population $0.591-0.066<p<0.591+0.066$ which in turns mean that you are 95% confident that $444*(0.591-0.066)<Nresistant<444*(0.591+0.066)$
To wrap it up :
$$P(233.1<Nresistant<291.7)=95\%$$
Comment: $z_{\alpha/2}$ is a value which **only** depends of the size of your confidence interval $\alpha=0.95$. Mathematically you have $P(|Z|>z_{\alpha/2}=0.95)$ with Z following normalized gaussian distribution($Z \sim N(0,1)$). Unless I mistyped the formula in wolfram alpha, this is then the confidence interval you can use.
Comment: Thanks for your kind help in attaining extrapolation with 95% Confidence interval.
Comment: I did understand that 0.591 is derived from 117/198. But I couldn't understand how to calculate Za/2 i.e., 1.96. Can I conclude my extrapolation as 262 (233.1 - 291.7) with 95% CI


javascript grabbing span tag with both class and id

Question: I have a span tag
US $99.00

I would like to grab it using pure javascript. JQuery or any other library is not allowed. Is that possible?
I recon that
getElementById('v4-25')

won't work since I have to specify class, too, correct?
Thank you,
So,

asdasdasdasdasd

var string = document.getElementById('v4-25');
document.getElementById('listprice').innerHTML = string;

should print value of 'v4-25' in 'listpirce' ?
H
Comment: getElementById looks only at the id and since id values must be unique in the page, what you have proposed should work just fine.
Answer: getElementById will work just fine.  Just make sure you're running it after the page has loaded.
Comment: So,

asdasdasdasdasd
var string = document.getElementById('v4-25');
document.getElementById('listprice').innerHTML = string;

should print value of 'v4-25' in 'listpirce' ?
Comment: Maybe you're abbreviating the code; no, that doesn't make sense.  If you have both a div with the ID `listprice` and `v4-25` in the page, then you can set the innerHTML of `listprice` to that of `v4-25` by doing this: `document.getElementById('listprice').innerHTML = document.getElementById('v4-25').innerHTML`
Answer: There is no reason to add a class. Run the script after that dom element is loaded like this.
US $99.00

Answer: First of all, ids are unique.  You can't have more than one.  therefore, when you select element by id, you can only bring back one element (this is good).
Secondly, after you get an element, you have to do something with it. var string = document.getElementById('v4-25'); only gets you the element, but it looks like you want var string = document.getElementById('v4-25').innerHTML; for the price.  If you do want the id instead you can do var string = document.getElementById('v4-25').id; but because that just returns "v4-25" it's a bit redundant.


How can I get attributes from the MANIFEST.MF file in a EAR-packaged application?

Question: I'd like to be able to get attributes like Implementation-Version that are set in my EAR file's MANIFEST.MF, so that I can make them available in a webapp.
What's the best way to go about doing that?
Thanks
Answer: There is no way to do this within the standards.  I would suggest extracting the data at build time and copying it into a more convenient location inside the WAR.
Comment: Thanks, just checking there was no better way


How to write after a score with Lilypond

Question: So I want to write not just at the end of a score, but after it, like the dal segno on this snippet :

I find it really neat, but don't find how to do it. It is not a text script, spanner or mark. It is not an object. So I'm a loss at how to do it.
For now, I just add _"D.S. al Fine" \bar "S-S" at the end of my score, so the dal segno is below the score.
Answer: Here I am overriding the barline stencil:
fancyMarkup = \markup \with-dimensions #'(0 . 0) #'(0 . 0) {
  \raise #-2.5 \center-column { "D.     S." "al" "Fin" }
}

\new StaffGroup <<
  \new Staff { b1 b b b b
               \once \override Staff.BarLine.stencil =
               #(lambda (grob)
                  (ly:stencil-combine-at-edge
                   (ly:bar-line::print grob)
                   X RIGHT
                   (grob-interpret-markup grob fancyMarkup)
                   0))
               \bar "S-S"
               }
  \new Staff { b1 b b b b }
>>

Answer: To be honest, I don't know an elegant way to do this and I would be very happy to see one. However, in the meantime, you can engrave it with use of a hack like this: lilybin.
What I did there is essentially this: I attach a markup to the last note in the right hand like so:
b-\tweak extra-offset #'(6 . 1.5) _\markup{\with-dimensions #'(0 . 0) #'(0 . 0) \center-column{ "D. S." "al" "Fin" }} \bar "S-S"

The main idea is to take what you want to typeset, which is \center-column{"D. S." "al" "Fin"}, make it take up no space using \with-dimensions #'(0 . 0) #'(0 . 0) ... and put the markup to the right place (found by trial and error) using -\tweak extra-offset #'(X . Y). It's very ugly, but sadly I don't know of anything better and it at least gets the job done.