Nginx reverting to sslv3

Question: I'm using nginx as a reverse proxy and I'm trying to turn off sslv3 support.
I have found various answers both on here and other various sites. They all suggest all I need to do is add something like the following to the default http block in my nginx.conf
ssl_protocols               TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers                 "ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS:!RC4";
ssl_prefer_server_ciphers   on;

I've done that and have even tried this full config from https://cipherli.st/
ssl_ciphers "AES128+EECDH:AES128+EDH";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
ssl_session_tickets off; # Requires nginx >= 1.5.9
ssl_stapling on; # Requires nginx >= 1.3.7
ssl_stapling_verify on; # Requires nginx => 1.3.7
resolver $DNS-IP-1 $DNS-IP-2 valid=300s;
resolver_timeout 5s;

I still only get a 'C' rating on SSL Labs (regardless of any change I make), with the following reasons
This server is vulnerable to the POODLE attack. If possible, disable SSL 3 to mitigate. Grade capped to C.
This server accepts the RC4 cipher, which is weak. Grade capped to B.
I have also restarted the server so I know the configuration changes have been applied.
nginx -v
nginx version: nginx/1.9.0
/etc/issue
Ubuntu 14.04.2 LTS \n \l
openssl version -a
OpenSSL 1.0.1f 6 Jan 2014
built on: Thu Mar 19 15:12:02 UTC 2015
platform: debian-amd64
options:  bn(64,64) rc4(16x,int) des(idx,cisc,16,int) blowfish(idx)
compiler: cc -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -m64 -DL_ENDIAN -DTERMIO -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -Wl,-Bsymbolic-functions -Wl,-z,relro -Wa,--noexecstack -Wall -DMD32_REG_T=int -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM
OPENSSLDIR: "/usr/lib/ssl"
Any suggestions?
Answer: I believe your openssl version is the problem. The openssl group recommends version 1.01j minimum.
Also, check your cipher. Isn't there supposed to be a colon before !RC4?
Comment: Thanks for the response, I missed the end of the line off when doing a copy paste and typed it in, there is a colon on the config. As for upgrading openssl apt-get update, apt-get upgrade doesn't update the version but that date above is the latest build date
Comment: Ok, so now I understand that ubuntu backport their security fixes, but it seems strange that they don't see this as a security fix. Anyway by the looks of it I have to wait for ubuntu to release an actual package update. Unless you have any other suggestins.
Comment: @MichaelLewis I always suggest _not using Ubuntu_.
Comment: @MichaelHampton what would you suggest as an alternative? Specifically for using nginx, but only as a reverse proxy
Comment: @MichaelLewis Most of my servers are running CentOS 7 or Fedora.
Comment: @MichaelHampton Ok thank you, I've used CentOS7 for other servers so I'll start there
Comment: @MichaelLewis Personally I'd recommend FreeBSD so ... there ya' go.

Nginx reverting to sslv3


how to prove a parametric relation to be a function

Question: For example lets suppose that I have given the functions $f:\mathbb{R}\longrightarrow \mathbb{R}$ and $g:\mathbb{R}\longrightarrow \mathbb{R}$. If my relation is $R=\{(x,(y,z))\in \mathbb{R}\times \mathbb{R}^{2}: y=f(x) \wedge z=g(x)\}$ How to prove formally (from a set theoretic stand point) that $R$ is a function. I have a try but I'm not convince:
Let suppose to have $(x,(y,z))\in R$ and also $(x,(y',z'))\in R$. Then $y=f(x), z=g(x)$ and also $y'=f(x), z'=g(x)$ by definition. Then $y=y'$ and also $z=z'$. Therefore $(y,z)=(y',z')$.
In a more general case if I have the functions $f_1, f_2,...,f_n:\mathbb{R}^m\longrightarrow \mathbb{R}$ and I define the function $f:\mathbb{R}^{m}\longrightarrow\mathbb{R}^{n}$ such that $f(x_{1},x_{2},...,x_{m})=(f_{1}(y),f_{2}(y),...,f_{n}(y))$ with $y=(x_1,x_2,...,x_m)$, how to justify that it is indeed a function? If my try is fine I suppose this can be done by induction. Any comment will be appreciated.
Comment: Your proof for $R$ is fine.
Answer: Let's prove a vastly more general statement.

Let $I$ be an index set, and for every $i\in I$ let $f_i$ be a function. Then the relation $F$ defined on $X=\bigcap_{i\in I}\operatorname{dom}(f_i)$ by $F=\{\langle x,\langle f_i(x)\mid i\in I\rangle\rangle\mid x\in X\}$ is a function.

Proof. Let $x\in X$, and suppose that $\langle x,\langle y_i\mid i\in I\rangle\rangle,\langle x,\langle z_i\mid i\in I\rangle\rangle\in F$, then for every $i\in I$ we have $y_i=f_i(x)=z_i$, therefore the sequences are equal and $F$ is a function. $\square$

Now you care about the case where $\operatorname{dom}(f_i)$ are all equal, so the intersection creating $X$ is trivial.
Comment: This is something I have to learn about generalizations, the proof is very elegant and concise. Also I don't understand the last sentence, do you mean $dom(f_{i})$ are not equal so the intersection is empty?
Comment: Daniela, no. In your case $\operatorname{dom}(f_i)=\Bbb R$ for all $i\in I$, so it makes things "slightly simpler" because we don't need to reduce to a smaller domain.
Comment: ok.  thank you so much.


Syntax in Sublime Text 2 Converts From "HTML" to "HTML (RAILS)" on save

Question: I've tried various fixes with this, and it is really annoying me now.
Whenever I open a file as html, the default syntax for the file changes to HTML (RAILS).  I can flip it back to HTML by the little select list in the corner, but it reverts.  I've tried changing syntax specific files, setting extensions, etc.  I even grepped HTML (RAILS) in my Sublime root folder recursively, and found nothing.
The thing that makes it hard to pin down, is that there is no extension difference.  No matter  which syntax highlighting I choose, the tag is the same.
I don't need syntax highlighting or autocomplete for HTML, but I do really like how matching tags are underlined in HTML syntax highlighting, and without it, I often miss unmatched tags, and cause lots of extra work for myself.
Any guesses on what this is / how to restore HTML to proper clean HTML highlighting?
(Note: The behaviour is identical for HTML and HTML5 and as I discussed in this post, I can't get tag matching to work in HTML5 anyway.  That problem preceeded this one, but using HTML instead of HTML5 was an acceptable fix - that no longer works.)
Answer: In case anyone else has this bizarre issue, I've solved it.
There is a package installed (dont' remember if it was installed from the beginning, or if I added it) called Syntax Matcher.  I commented out the following lines in a file called SyntaxHighlighter.py:
    if self.ext == '.html':
         self.set_syntax('HTML (Rails)', 'Rails')
          return True

And the problem was solved instantly.


How to Group By 2 fields in SQL Query?

Question: I have Two tables in Postgresql and I'm trying to get the number of times a hashtag is repeated by place.
I've made this query:
SELECT tweets_with_location.user_location,
       tweets_with_location.my_new_id,
       all_hashtags_with_location.regexp_split_to_table
FROM tweets_with_location, all_hashtags_with_location
WHERE tweets_with_location.my_new_id = all_hashtags_with_location.my_new_id;

Which returns the Location, the tweet id and the hashtag:

USER_LOCATION | MY_NEW_ID | HASHTAG
New York, NY | 33 | Happy
New York, NY | 40 | BigApple
Bronx, NY | 12 | Happy
Bronx, NY | 45 | Happy
Queens, NY | 23 | Trump
Queens, NY | 20 | Trump

Then, I've made another SQL Query but it seems it doesn't sums up the number of times a hashtag was displayed by place, the Count value is always 1:
SELECT tweets_with_location.user_location,
       all_hashtags_with_location.regexp_split_to_table,
       COUNT(DISTINCT all_hashtags_with_location.regexp_split_to_table) AS CountOf
FROM tweets_with_location, all_hashtags_with_location
WHERE tweets_with_location.my_new_id = all_hashtags_with_location.my_new_id
GROUP BY tweets_with_location.user_location,
         all_hashtags_with_location.regexp_split_to_table
ORDER BY CountOf DESC;

I need is this result:

USER_LOCATION - HASHTAG - COUNT
New York, NY | Happy | 1
Bronx, NY | Happy | 2
Queens, NY | Trump | 2
New York, NY | Happy | 1

How do I do this? What is wrong with my SQL Query?
Answer: You were really close, you are counting the wrong field:
SELECT tweets_with_location.user_location,
       all_hashtags_with_location.regexp_split_to_table,
       COUNT(DISTINCT tweets_with_location.my_new_id) AS CountOf
FROM tweets_with_location, all_hashtags_with_location
WHERE tweets_with_location.my_new_id = all_hashtags_with_location.my_new_id
GROUP BY tweets_with_location.user_location,
         all_hashtags_with_location.regexp_split_to_table
ORDER BY CountOf DESC;

Comment: @JaquelinePassos -- it really depends on your data.  From your first post `my_new_id` are the fields you are trying to `count`.  However in your attempt, you were counting the distinct `hashtag` fields and grouping by them -- that will always return 1.  If you don't need the distinct count, you could just remove distinct and your query would work as well.  If there are duplicates and you don't want to count them multiple times, then go with this approach.
Comment: This is the tweet id, not the hashtag id. Because one tweet can have like 3 hashtags or more... I'll try it anyways.
Comment: Seems like it worked, but I didn't understand why... can you please explain it to me? I want to learn it...
Answer: Or just remove the DISTINCT qualifier in the COUNT() function.

How to Group By 2 fields in SQL Query?


git merge default options

Question: When I git merge a branch in another one, I like to pass the --edit --log options. I would like to make it automatic, but cannot get how.
What I tried:
Set the [merge] part of my global .gitconfig
[merge]
    edit = true
    log = 20

Git merge does not change its default behavior.
Note: I believe those options are not available for configuration file as I cannot see them in the output of git help -c | grep merge
Create an alias of merge
If I define my alias that first way:
[alias]
    merge = merge --edit --log

or that second one:
[alias]
    merge = "! git merge $* --edit --log #"

Then I cannot see any change in git's behavior.
If I call my alias anything else that merge, then it works as expected (adding edit and log options).

So, is there any solution to make git merge use --edit --log by default?
Comment: Short answer : name it differently. Treat commands as reserved keywords.
Comment: (to emphasize one point on RomainValeri's comment) : treat *built-in* commands (`merge`, `add`, `checkout` ...) as reserveed keywords
Comment: The alias solution was only a workaround: I would have liked to enforce the `edit=true ; log = 20` options of the `[merge]` section, so that it is the default behavior for all the software that send git merge commands
Comment: That's tricky because it wouldn't be just git that would need to support that. Probably libgit2 would also need to support it because that's what is normally implemented in other pieces of software that support git (like IDEs).
Comment: @eftshift0: should I conclude that what I want to do is simply not supported? I thought I was missing sth, but if is just not possible, I accept working with an alias.
Answer: As others mentioned in comments, if you name an alias merge, Git completely ignores it.  That is, given:
[alias]
    merge = foo
    marge = foo

running git merge runs the standard git merge, but running git marge gets you an error about git foo not being a Git command (assuming you have not made yourself a git-foo command, of course).
This is true for all standard Git commands.

There is no merge.edit setting.  Or—equivalently—you can set merge.edit to anything you like,1 but git merge never inspects the setting so it makes no difference.
There is a merge.log setting.  This defaults to false, i.e., if you have not set it, or if you set it to false, git merge behaves the way it does by default.  Setting it to true has the same effect as setting it to the number 20.
The default for git merge is --edit unless a merge message is specified with -m or -F.  If you use the merge run by git pull, the --edit action is also the default.
The one special case where merge.log has no effect is a fast-forward, which is not a merge at all.2  Since no new commit is being created by the fast-forward action, there is no place to put any messages, so merge.log is ignored as well.
All of this is specific to the command line as implemented by Git itself.  If you're using other software (e.g., Eclipse), that other software probably has its own implementation and may completely ignore the way Git does things.

1Git's settings framework is very general, so it allows you to set all kinds of things that Git never checks.  This has a nice side effect: it means you can write your own commands that use these settings.  It has a bad side effect too: if you misspell a setting name, for instance, you never get any warning about this.
The git config documentation is supposed to have a master list of all settings that are meaningful to all of Git's commands.  Note that sometimes things slip: e.g., log.decorate can be set to auto, and this was true for a long time but not documented until Git 2.9.0.
2I think it's a bit unfortunate that Git calls this a fast-forward merge in places.

git merge default options


Determining $\mathbb{P}$-names

Question: Will you look at my answer to the following homework and tell me where I made a mistake? Thanks for your help!
Let $\mathbb{P} = (P, \leq)$ be a forcing poset and let $p,q \in P$ denote two different conditions. We define the following $\mathbb{P}$-names:
$$\begin{align}
&\underset{\widetilde{\hphantom{x}}}{x} := \{ \langle \emptyset , p \rangle\} \\

&\underset{\widetilde{\hphantom{y}}}{y} := \{ \langle \emptyset , q \rangle, \langle \underset{\widetilde{\hphantom{x}}}{x}, q \rangle\}\\

&\underset{\widetilde{\hphantom{z}}}{z} := \{ \langle \underset{\widetilde{\hphantom{y}}}{y} , p \rangle, \langle \underset{\widetilde{\hphantom{x}}}{x} , q \rangle, \langle \underset{\widetilde{\hphantom{x}}}{x} , p \rangle\}\\

&\underset{\widetilde{\hphantom{u}}}{u} := \{  \langle \underset{\widetilde{\hphantom{z}}}{z} , p\rangle,
\langle \underset{\dot{\hphantom{q}}}{q} , p\rangle,
\langle \underset{\dot{\hphantom{p}}}{p} , q\rangle \}\\

&\underset{\widetilde{\hphantom{v}}}{v} := \{
\langle \underset{\widetilde{\hphantom{u}}}{u} , q\rangle,
\langle \underset{\dot{\hphantom{p}}}{p} , p\rangle,
\langle \underset{\widetilde{\hphantom{z}}}{z} , p \rangle
\}
\end{align}
$$
Determine $ \underset{\widetilde{\hphantom{v}}}{v}[\{ p \}], \underset{\widetilde{\hphantom{v}}}{v}[\{ q \}],
\underset{\widetilde{\hphantom{v}}}{v}[\{ p, q \}]$
My answer:
$$ \underset{\widetilde{\hphantom{v}}}{v}[\{ p \}] =
\{ \underset{\dot{\hphantom{p}}}{p}[\{ p \} ], \underset{\widetilde{\hphantom{z}}}{z}[\{ p \}] \} =
\{ \underset{\dot{\hphantom{p}}}{p}[\{ p \} ], \{ \emptyset, \{ \emptyset \} \} \}$$
Because
$$\begin{align}

&\underset{\widetilde{\hphantom{x}}}{x}[\{ p \}] = \{ \emptyset \}\\

&\underset{\widetilde{\hphantom{y}}}{y}[\{ p \}] = \emptyset \\

& \underset{\widetilde{\hphantom{z}}}{z}[\{ p \}] = \{ \underset{\widetilde{\hphantom{y}}}{y}[\{ p \}], \underset{\widetilde{\hphantom{x}}}{x}[\{ p \}]\} = \{ \emptyset, \{ \emptyset \} \}
\end{align}$$
The next one is
$$ \underset{\widetilde{\hphantom{v}}}{v}[\{ q \}] = \{ \underset{\widetilde{\hphantom{u}}}{u}[\{ q \}] \} = \{ \emptyset \}$$
Because
$$ \underset{\widetilde{\hphantom{u}}}{u}[\{ q \}] = \{ \underset{\dot{\hphantom{p}}}{p}[\{ q \} ] \}= \emptyset$$
And the last one:
$$ \begin{align*}
&\underset{\widetilde{\hphantom{v}}}{v}[\{ p, q \}] = \\

&\{ \underset{\widetilde{\hphantom{u}}}{u}[\{ p, q \}], \underset{\dot{\hphantom{p}}}{p}[\{ p, q \}],
\underset{\widetilde{\hphantom{z}}}{z}[\{ p, q \}] \} = \\
&\{
\{
\{ \{ \emptyset \}, \{ \emptyset, \{ \emptyset \} \} \},
\underset{\dot{\hphantom{q}}}{q}[\{ p, q \} ] ,
\underset{\dot{\hphantom{p}}}{p}[\{ p, q \} ]
\},
\underset{\dot{\hphantom{p}}}{p}[\{ p, q \}],
\{ \{ \emptyset \}, \{ \emptyset, \{ \emptyset \} \} \}
\}
\end{align*}
$$
Because
$$\begin{align}
&\underset{\widetilde{\hphantom{u}}}{u}[\{ p, q \}] = \{
\{ \{ \emptyset \}, \{ \emptyset, \{ \emptyset \} \} \},
\underset{\dot{\hphantom{q}}}{q}[\{ p, q \} ] ,
\underset{\dot{\hphantom{p}}}{p}[\{ p, q \} ]
\} \\

&\underset{\widetilde{\hphantom{z}}}{z}[\{ p, q \}] = \{ \{ \emptyset \}, \{ \emptyset, \{ \emptyset \} \} \}
\end{align}$$
Comment: This question is due to typos in the assignment. For every $x[G]$ they omitted $0 \in G$. Now that there is a corrected version of the assignment, this question becomes obsolete.
Answer: (Again, I will use the Jech-ian notation of $\check x$ for $\mathbb P$-names)
Note that $\check x[\{p\}] = \{\check y[\{p\}] \mid \langle\check y,p\rangle\in\check x\}$. Now we can determine the interpretation by $\{p\}$ of each set in a recursive algorithm:
$$\begin{align}
\check v[\{p\}] &= \Bigg\{p[\{p\}], \check z[\{p\}]\Bigg\}\\
&=\Bigg\{p,\bigg\{\check y[\{p\}],\check x[\{p\}]\bigg\}\Bigg\}\\
&=\Bigg\{p,\bigg\{\varnothing,\{\varnothing\}\bigg\}\Bigg\}
\end{align}$$
For the $\check v[\{q\}]$ your answer is mostly correct, note that $\check u[\{q\}] = \{p\}$ though.
Your answer for the final has the same issue, but it looks okay.
Comment: So $ \underset{\dot{\hphantom{p}}}{p}[\{ p \} ] = p$? Yesterday you said $\underset{\dot{\hphantom{p}}}{p}[\{ p \} ] $ [didn't make any sense](http://chat.stackexchange.com/transcript/message/2577543#2577543)...
Comment: I can kind of believe you that $\underset{\dot{\hphantom{p}}}{p}[\{ p \} ] = p$ but $\underset{\widetilde{\hphantom{u}}}{u}[\{ q \} ] = \{ \underset{\dot{\hphantom{p}}}{p}[\{ q \} ]\} = \{ p \}$ seems weird.
Comment: @Matt: I thought about it and I understood what was the question. As for $p[\{p\}]=p$ it is exactly what I said before, you stop distincting between an element of the ground model and its canonical name.
Comment: Yes! And what about my second comment?
Comment: Sorry, this is all due to a typo where the omitted $0$ in all the sets $G$. They just uploaded a corrected version of the assignment.

Determining $\mathbb{P}$-names


React com TypeScript

Question: Olá, estou aprendendo  a fazer aplicações React com TS, e dentro dos meus estudos me deparei com um problema.
Estou exportando um componente da seguinte forma
<code>const Button = styled.button`
background-color: Transparent;
background-repeat:no-repeat;
border: none;
cursor:pointer;
overflow: hidden;
font-size: 1.2em;
margin: 2px;
float: right;
color: white;

`

export const RaisedButton = (props:IProps) => <Button>{props.label}</Button>

interface IProps {
label: string
}
</code>
Quando importo RaisedButton na minha index, ela entra como a classe button e o botão se atribui somente as propriedades .css definidas a cima.
Gostaria de saber se é possivel atribuir multiplas propriedades .css dentro do mesmo componente Button, assim, exporto varias propriedades e não preciso recriar o componente, somente as propriedades.
Comment: você quer então aplicar estilos diferentes em determinada importação do seu componente button? é isso ?
Answer: Não sei se é bem isso que você deseja, mas você pode passar os atributos padrão de um botão para o componente filho da seguinte maneira:
<code> const Button = styled.button<BtnProps>`
      height: 50px;
      width: 150px;
      color: white;
    `;

   interface MyButtonProps {
      label?: string;
    }

   type CustomButtonProps = MyButtonProps &
      React.ButtonHTMLAttributes<HTMLButtonElement>;

   export const CustomButton = (props: CustomButtonProps) => {
       const {label, ...defaultButtonProps} = props

       return <Button {...defaultButtonProps}>{props.label}</Button>;
    };
</code>

React com TypeScript


Naming and casing guidelines for ALFA and XACML

Question: Are there guidelines or at least best practises for naming and casing namespaces, attributes, rules, policies etc. in the ALFA language?
As ALFA depends on XACML, is there anything similiar for XACML?
Answer: There are no hardcore guidelines. I like to use camel casing. There are characters that you cannot use inside ALFA identifiers e.g. hyphen (-) and whitespace of course.
Good names are things like userRole. ALFA is namespace-based i.e. everything is defined inside a namespace. That lets you create a graph of attributes e.g.
user.internal.department

Where user.internal is a namespace and department is the attribute's local name. Note that you can name your corresponding XACML attribute anything you like but I recommend you still the fully-qualified ALFA name (i.e. user.internal.department).
ALFA does not depend on XACML: it translates into XACML. You can roundtrip between both languages.


Pairwise exclusions

Question: I am running a logistic model on insurance data. I have a field agent gender which matters for a channel A (say) and doesn't matter for B. I want to put null values in case of B. The only thing I risk is exclusion by SAS (as SAS excludes every missing case by default). I heard that pairwise exclusion can solve my problem. Please tell me the following:

What is the difference between normal exclusion and pairwise exclusion?
How to do this is SAS?
What is listwise exclusion?
Answer: This doesn't sound like a missing data problem to me: it sounds like a question of model structure.
Distilling it to its essence, it seems you have two independent categorical variables gender ($X$, say) and "channel" ($Y$) and a binary response ($Z$).  Conceptually the model is
$$logit(\Pr(Z=1)) = \beta_0 + \beta_1 X + \beta_2 Y + \varepsilon$$
when $Y$ = "A" and otherwise
$$logit(\Pr(Z=1)) = \beta_0 + \beta_2 Y + \varepsilon$$
when $Y \ne $ "A" (with parameters $\beta_0$, $\beta_1$, and $\beta_2$ and zero-mean random error $\varepsilon$).  If this interpretation is correct, just set $X = 0$ in the data whenever $Y \ne $ "A".  This will cause such cases to have no effect on the value of $\beta_1$, which will be estimated solely from the other cases where $Y$ = "A".
Comment: +1 for actually solving his problem, as opposed to answering about missing data.
Comment: @richie Thanks.  The conversation initiated by your reply clued me in; so, as in many threads on this site, developing a solution is really a collaborative effort.  I look forward to the next replies which take our tentative first steps even further!
Comment: thanks..Agree. My concern is that "is placing a zero" there equal to placing a .( missing). Forgive my ignorance but I understand that 0 may give that an entirely new meaning. Lets say if I have a variable "agent's plcy rate"..and I give it a number 0 in place of missing doesnt it alter the meaning. ?? Just a thought that came to my mind.
Comment: @ayush That's exactly the issue.  If you put missing values in, the software has to skip those records and you lose information.  Normally it would be bad to just stick in zeros mindlessly.  That's why you have to do a little math.  If you want to be really convinced, write down the likelihood equations for the model.  The Chain Rule shows that $X$ multiplies $\beta_1$, so by setting $X=0$ appropriately you eliminate $\beta_1$ from all terms where it doesn't belong.  That's why 0 works and that's why *only* 0 works in this case.
Answer: There are two main types of traditional treatments of missing data.
These are:
1) listwise
2) pairwise
Listwise is (from what you have said) the default in SAS. It means that you exclude any observation that has missing values in any of the terms in your model.
The advantage of this is that it ensures that all variables have the same n in the model. The disadvantage is that if you have one variable with a high proportion of missing data, much of the rest of the data can be ignored.
Pairwise, by contrast, only excludes cases where the value is missing for that particular variable. This has the advantage of keeping more data in the model that listwise does. However, the disadvantage is that some of your results will be based on different subsets of the data, and this can cause problems with p values and confidence intervals.
A better approach is probably multiple imputation where you attempt to predict the missing values using all of the data you have. This normally involves simulating a number of datasets with the missing data filled in, and then performing all analyses on each of the datasets individually, and averaging the results.
A good paper on treatment of missing data is Graham 2009 Missing Data: Making it work in the real world which goes into much more detail than I have here. You also need to determine if the missingness in your data is random or not, as if the probability of missingness depends on exogenous variables to your dataset, then none of these approaches will work correctly.
A good resource on multiple imputation is here
This article on missing data in SAS may prove helpful, or someone else may answer as to how to do this in SAS.
Comment: thanks..I am not much concerned about missing value imputations..nor can I do many analysis and then average them..Basically as I said, I have 5 channels. 1 channel out of those have right values..for the rest 4 channels, I need to fill missing in those variables. My concern is , how to tell SAS that dont delete these variables, these are created deliberately by me as actually it doesnt make any business sense to have agent characteristics for those 4 channels..Hope you got my point..or any setting in which I can tell SAS that dont delete missing values.

Pairwise exclusions


How to show that $V= \text{Im }f \oplus \text{Ker }g$.

Question: Let $U, V, W$ be vector spaces over a field $K$, and let $f: U \to V$ and $g: V \to W$ be linear transformations such that $g \circ f$ is an isomorphism. I have to show that  $V= \text{Im }f \oplus \text{Ker }g$.
I really don't know what to do, I've solved some similar problems but always with just one linear transfromation, not with two. I hope you can give me some hint or idea to handle this problem. Thank you in advance.
Comment: Point one: show $\operatorname{Im} f \cap \ker g = \{0\}$. Point two: show every $v \in V$ can be written as $f(u) + k$, where $g(k) = 0$.
Comment: @DanielFischer: That sounds like an answer...
Answer: Hint.
$g\circ f\colon U\to W$; call $h\colon W\to U$ its inverse; then you have a way to go from $V$ back to $V$ with $\varphi=f\circ h\circ g$. If $v\in V$, consider $v=\varphi(v)+(v-\varphi(v))$ and go on.


grep after match

Question: I have the following lines in text file
myname aaa age 22
age 23 myname bbb

How can i find the word after myname using linux grep command .?
I want the output to be the word after myname ( aaa and bbb )
Answer: $ grep -Po '(?<=myname\s)\w+' inputFile

Answer: $ grep -o "myname [[:alnum:]]\+" /tmp/sample | cut -f2 -d' '
aaa
bbb

Answer: solution with sed:
sed -n '/myname/{s/.*myname \([^ ]*\).*/\1/;p}'

grep after match


How do I create a simple javascript server?

Question: I want to create a server where if I pressed "w", a variable (lets say me1) would equal to 1. And if another user (from a different browser and IP) pressed the same key, another variable (lets say other2) would equal to 1.
I don't need everything to be JavaScript (as long as it's easy to understand), I just need the end variables to be JavaScript.
Comment: Javascript server? You want a script that responses with your desired logic, right? Any server-side scripting language will serve your needs. But what have you tried? Why server-side?
Comment: To be clear, are these variables `me1 , other2, ...` shared between these different IP's?
Answer: Do your users from different IP's need to be able to talk to each other?
You could use NodeJS as one way to do this. I only recommend Node because its very simple to setup sockets if your answer to my above question is yes.
However both technologies would require a medium to advanced skill set.


MCMC samples for constructing a histogram

Question: I am interested in generating samples from a density $\pi(\theta)$ to construct a histogram for $\pi(\theta)$ and to use these samples to generate samples of $f(\theta)$ for some function $f$. I may be interested in probabilities of $f(\theta)$ but my main goal is not the computation of statistics of $f(\theta)$ like its mean or variance. I am more interested in constructing histograms of $f(\theta)$ and kernel densities.
Since Metropolis MCMC returns correlated samples, I am curious as to how I should employ it for  my objective. According to this post, the ergodicity of the chain enables the use of the samples for constructing histograms.
I then wonder about the practical side of MCMC sampling: After reading some books, it appears to be advocated that the step size of the chain be chosen correspondingly such that the correlation between consecutive samples is as small as possible. It seems that the objective of these practitioners is to compute the mean, variance of $\theta$. It makes sense because if the samples are almost independent, then the performance is comparable to standard Monte Carlo.
But if your goal is to construct the histogram, what benefits would you have from finding the optimal step size such that consecutive samples are highly uncorrelated? is it for better exploration of the state space?
I am asking this question because my trace plot (for the 2 most dominant components of a 10-dimensional random vector) look like:

This already has an acceptance rate of 23%. I've played around with other step sizes but I couldn't get a beautiful white noise trace plot as in the figures here.
Comments appreciated. Thanks!
Answer: If you are interested in constructing a histogram then there is no reason you need the samples from your MCMC to be (close to) uncorrelated.  It is legitimate to take a long string of correlated values, discard the burn-in, and form a histogram with all the remaining values.  Having said this, please bear in mind that a histogram is just a poor-man's kernel density plot; you are better off taking your MCMC values and making a kernel density plot with an appropriate kernel.


Como normalizar este banco de dados?

Question: Estou com um problema ao criar uma Base de dados onde uma empresa pode ter ate 16 trabalhadores. Onde cada trabalhador pode ter estes dados:
<code>$sqlupdate3 = "Update tb_detalhe_trabalhador SET
Nome3='$Nome3',Funcao3='$Funcao3',
MedicaValidade3='$MedicaValidade3',
MedicaAnexo3='$MedicaAnexo3',
EPISValidade3='$EPISValidade3',
ProjectistaNumero3='$ProjectistaNumero3',
ProjectistaValidade3='$ProjectistaValidade3',
GasNumero3='$GasNumero3',
GasValidade3='$GasValidade3',
RedesNumero3='$RedesNumero3',
RedesValidade3='$RedesValidade3',
SoldadorNumero3='$SoldadorNumero3',
SoldadorValidade3='$SoldadorValidade3',
MecanicoNumero3='$MecanicoNumero3',
MecanicoValidade3='$MecanicoValidade3',
ClasSoldadorNumero3='$ClasSoldadorNumero3',
ClasSoldadorValidade3='$ClasSoldadorValidade3'
  where id=$id ";

 mysql_query($sqlupdate3) or die(mysql_error());
</code>
Será melhor criar uma tabela empresa e 16 trabalhador ou apenas uma trabalhador?
Comment: Dê uma espiada nisso depois, tem um exemplo de uso aqui: http://sqlfiddle.com/#!2/98bf7/2 . -
No exemplo tem mais de uma empresa, e um select que mostra como pegar de uma só, e tem um JOIN para mesclar os dados da empresa e do trabalhador num select só depois.
Comment: @Bacco Eu não marcaria como duplicata porque este caso é específico, enquanto a outra pergunta é generalista.
Comment: @Andrey lembre-se que você pode votar para reabrir, se quiser.
Comment: Chris, pesquise sobre normalização: http://www.luis.blog.br/normalizacao-de-dados-e-as-formas-normais.aspx e http://pt.wikipedia.org/wiki/Normaliza%C3%A7%C3%A3o_de_dados
Comment: Chris, vou te dar uma dica: O título da sua pergunta não está apropriado. Mude para algo como *"Como normalizar este banco de dados?"* Eu também colocaria o `CREATE TABLE` em SQL ao invés do `UPDATE` em PHP na pergunta.
Answer: Você pode normalizar seguindo o padrão das 5 Formas Normais(FNs) dado esse exemplo abaixo de uma locadora por ser mais simples e apresentar menos tabelas após ser normatizada:

Penso que a proposta desse site seja esclarecer ou ajudar na solução do problema e não fazer por completo um dado problema apresentando toda sua solução. O desenvolvimento do problema parte da sua pessoa a partir do entendimento do problema.
Comment: Ainda poderias acrescentar uma tabela de Categorias de Filmes, essa Base de Dados não está normalizada.
Comment: Esta sim normalizada.. o que pode você pode fazer é apenas uma melhoria para diminuir a redundância de dados/valores repetindo as regras 4F e 5F. Pois as regras 1F,2F 3F são as que determinam realmente a normalização do banco de dados.
Answer: O ideal seria separar tudo o que fosse possível, por exemplo até as funções dos funcionários, deveria haver uma tabela chamada funções e ali serem cadastradas e depois vinculadas por ID aos funcionários. A questão é que são poucos, funcionários o que resultaria em fazer apenas uma tabela para generalizar, mas é como eu penso: Hoje existem 16 amanhã pode ter 20, 30, 100...
Comment: @ChrisAdler inserindo o ID da empresa em cada uma das linhas de trabalhadores. Do seu jeito você está perdendo um tempo imenso pra resolver uma coisa simples, por insistência. De qq forma, desejo boa sorte. Mas vá tentando, quem sabe alguém responde da forma que você quer, tem um pessoal bem bacana no site. O que eu digo é, com 16 tabelas, voce se complica, e com tudo numa linha só, tambem se complica. Se tiver uma tabela só pra empresa, e uma só pra trabalhadores, com varias linhas, o ID resolve.
Comment: @ChrisAdler uma tabela com 16 linhas nao seria extensa. Está ficando extensa por que você está pondo mais de um trabalhador na mesma linha, simplesmente isso. Você precisaria de uma tabela com UM nome, UMA função só, etc, e nesta tabela faria varios INSERTS, um para cada trabalhador.
Comment: ok, mas sendo apenas necessario 16 tabelas como consigo relacionar as 16 tabelas as empresas? E como consigo por exemplo em algum caso que a empresa tenha 4 trabalhadores como consigo dizer a bd que as tabelas 5,6,7,8,9 e por ai fora que está vazia?
Comment: @ChrisAdler eu reli quase todas as suas perguntas e as respostas, e ainda nao entendi uma coisa. Qual o problema de ter UMA tabela "trabalhadores", e colocar os registros nesta tabela? Mas nao na mesma linha, como você faz, e sim em linhas separadas.
Comment: Porque ter uma tabela muito extensa e estar a dar erro pelo tamanho dos campos. Queria uma solução para resolver este meu problema
Comment: @ChrisAdler Na linha 1 você teria o nome do primeiro trabalhador, na linha 2 o nome do segundo trabalhador, etc. Do jeito que está fazendo, você pos o nome1 e o nome2 na mesma linha. Aí não há tabela que caiba. Tabelas normalmente tem colunas e linhas (sinonimo de campos e registros). Você está criando campos onde deveria criar registros.
Comment: E depois como consigo relacionar a tabela 1 tabela 2 e tabela 3 com a tb_empresa?
Comment: Era aqui que queria chegar.. Agora imagine que apenas tem 2 trabalhadores. as outras tabelas ficam com id vazio correcto? quando for preencher a empresa seguinte fica com o id da empresa anterior
Comment: Vamos [continuar esta discussão no bate-papo](http://chat.stackexchange.com/rooms/15363/discussion-between-bacco-and-chrisadler).

Como normalizar este banco de dados?


Find the number of positive integers not containing digit $0$ whose digits add up to $10$.

Question: Find the number of positive integers not containing digit $0$ whose digits add up to $10$.
Comment: Obviously the maximum number is 1111111111, which has 10 digits, so we are looking for 9-digit numbers at maximum (and we will add 1 to the total).
Comment: Look up _ordered partition_ . This question may help: http://math.stackexchange.com/questions/31562/number-of-ordered-partitions-of-integer . And see https://en.wikipedia.org/wiki/Composition_(combinatorics)#Number_of_compositions
Answer: Suppose that you have $10$ unities written down in a row:
$$1 \quad 1 \quad 1\quad  1 \quad 1 \quad 1 \quad 1 \quad 1 \quad 1 \quad 1$$
You can see that there are 9 empty spaces between them, where you can put a separator. Any arrangement of separators (except for the case when there are no separators) can be mapped to a number with the sum equal to 10: we should merely count the number of unities in each obtained block. For example:
$$1 \quad 1~~~|~~~1\quad  1 \quad 1~~~|~~~1 \quad 1 \quad 1~~~|~~~1 \quad 1$$
This arrangement corresponds to the number $2332$. On the other hand, you can see that for any number there is a unique arrangement of separators representing this number. Thus, it is a bijection.
Since we can select any subset of spaces (except for the empty one) to fill them with separators, the number of ways to make such an arrangement is $2^9 - 1 = 512 - 1 = 511$.
Comment: @N.Shales good spot, thanks! I edited the answer accordingly.
Comment: $(+1)$ from me. This is a very nice bijection! Don't forget to $-1$ for the case where there are no separators between unities.
Comment: No problem. The thrust of your work came across loud and clear so that's the main thing :)


MongoDB 3.2 mongod.conf master/slave replication cant be configured via mongod.conf

Question: I need to setup master/slave replication for mongodb 3.2 server. Servers are Centos 6.7 and mongodb is latest 3.2 from offical RPMS. My /etc/mongod.conf is pretty much with default options from the RPM package. I know that 3.2 version is using YAML style for config file but no matter how i put master: enable , master: true or whatever mongod startup fails. I tryed to put the option into /etc/sysconfog/mongod file but this does not work also. My question is what is the correct way or command to put in to enable master mode. I putted --master into the startup script of the daemon and its looks OK but i don't think this is the right way to do this.
Thanks in advance.
Answer: Referring to MongoDB manual
You should try to use replication setting if any chance, and the master-slave behavior you want should be able to be simulated using replication settings.
Also you can convert your current master-slave nodes to a replica set, you can find the paragraph in the same page.
I guess you don't feel it's right because it's not recommended by mongodb to use this command line feature any more.


How to find the asymptotic complexity of 3Sum.java

Question: how do you get the time complexity of the functions count and printall in ThreeSum.java?
public static void printAll(int[] a) {
    int n = a.length;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            for (int k = j+1; k < n; k++) {
                if (a[i] + a[j] + a[k] == 0) {
                    System.out.println(a[i] + " " + a[j] + " " + a[k]);
                }
            }
        }
    }
}

public static int count(int[] a) {
    int n = a.length;
    int count = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            for (int k = j+1; k < n; k++) {
                if (a[i] + a[j] + a[k] == 0) {
                    count++;
                }
            }
        }
    }

Comment: plz post your code here only.
Comment: okay thanks :) done
Comment: you dont have to put this comment on your own question other people will put it if they find it as a duplicate.
Comment: oh sorrry :oooo
Answer: Although time complexity questions are sometimes very tough but this one is an easy cake. You can simply check it out as follows,
for (int i = 0; i < n; i++) // it runs for n times
        for (int j = i+1; j < n; j++) // it runs for n-i-1 time
            for (int k = j+1; k < n; k++) // it runs for n-j-1 times

Now since they are nested loops that means each of inner loop runs as many number of times as outer loop.
total = n * ( n-i-1 ) * ( n-j-1 )
      = n^3 ... // ignoring all other lower power terms

So time complexity of this code will be O(n^3).
Comment: If it helps you kindly accept the answer so that others can also take help from this.
Comment: done. so the if statement doesn't affect the time complexity at all?
Comment: yes its contributing but very little when you compared it with `n^3`. For time complexity we generally take loops as major cause of time taking in program.


How to think of a function as a vector?

Question: In order to apply the ideas of vector spaces to functions, the text I have (Wavelets for Computer Graphics: Theory and Applications by Stollnitz, DeRose and Salesin) conveniently says

Since addition and scalar multiplication of functions are well defined, we can then think of each constant function over the interval $[0,1)$ as a vector, and we'll let $V^0$ denote the vector space of all such functions.

Ok, so I've heard this notion before, and it kind of makes sense.  You want to apply the rules of vector spaces (and define things like inner product) for functions, so you go and say "a function is a vector."
But how does this mesh with the traditional physics definition of vector?  A vector must have a magnitude and direction.  What's going on here between algebra and physics?
Comment: I finally found something that made intuitive sense to me linking the traditionally taught idea of a vector to these vectors as functions. I could never quite understand where the integral product $\langle\cdot,\cdot\rangle=\int_0^1 f(x)g(x)dx$ came from. I was always told it was just defined that way, but the lecturers never explained why this might be the case... http://eng.fsu.edu/~dommelen/quantum/style_a/funcvec.html. Seems that a suitably well-behaved function defined over a finite interval $[0,1]$ can represent an infinite dimensional vector. Makes sense now.
Answer: Mathematics and physics are not really compatible.
In the plane, or the 3D space (and so forth) it is fine to represent a vector space as a magnitude and direction.
However, the formal definition of a vector space requires not the need for either of those in order to represent a vector. In fact, a vector - formally - is just an element of a vector space.
This can go on, not all vector spaces have norms defined on them. Without the axiom of choice, not all have a basis, decomposition into a direct sum, nontrivial functionals, and so on.
Similarly, not all topological spaces are normal, regular, Hausdorff, etc., however we like to think of the physical world as $\mathbb R^3$ which is normal, regular, Hausdorff, etc..
In the finite dimensional case, or assuming the axiom of choice, we have a basis for the space. That is every vector can be written as a linear combination of the elements of the basis. You can think of the vector, if so, as a function from a set into the field.
The set, of course, is the basis; or some other set with the same number of elements. For a vector $v = \sum_{n=1}^k\alpha_n\cdot v_n$ we can think of $v$ as a function from the set $\{1,\ldots,k\}$ into the field: $v(n)=\alpha_n$. Of course, after changing a basis we "change the function", but this is why vector spaces are isomorphic and not the same.
Answer: Any vector is a function in the trivial sense that you can re-interpret it as the trivial constant map sending anything to that particular vector, $f_v:D\to\{v\}\in V$. In this way every $v\in V$ can be understood as the associated "function" $f_v$ regardless of domain $D$.
The other direction - the idea that functions can form a vector space - is more general than that of the usual $\mathbb{R}^n$ vector spaces with canonically understood magnitude and direction, which both come from an inner product $\langle\cdot,\cdot\rangle$ on $V$. The general idea is that vector analysis provides a model for situations where mathematical objects can be decomposed into a linear combination of components over a field of scalars (and modules if over a ring). In this way they form the natural backdrop for linear algebra, which again doesn't always come with a geometric formalism in all circumstances, but they coincide exactly in the obvious cases. Bottom line: It's just the universal practice in mathematics of noticing one structure is a smaller case of a bigger one, where sometimes the first or smaller structure has special meaning (e.g. geometry) associated to it.
Comment: Can we say the same about a function $f(u,y,z)$? Will we have then $f_u$, $f_y$, $f_z$?
Answer: What's going on here is that physics and mathematics use the word with different (but related) meanings. It's just a problem of terminology, not really hiding anything deep technically.
Everything that physics calls a vector is also a vector in mathematics. But there are things that mathematicians call vectors which physicists wouldn't. My understanding is that the physicist's sense of "vector" corresponds best to what mathematics would call a "tangent vector" of a manifold. (The familiar $\mathbb R^3$ vectors in Euclidean space are a special case of this).
Computer science has a third, related but again different, sense of "vector". That's somewhat unfortunate, but eventually just the way the world is.
Comment: Agreed, this was my first thought. Even within physics, the meaning of "vector" varies from one context to another, and sometimes can correspond to the mathematical definition (physicists do talk about vector spaces frequently).
Comment: The CS vector comes from the math vector. A `std::vector` is supposed to be an N-element vector, with constant time random element access.  I always thought this was misnamed (better to name it `array`)
Answer: Vectors by construction are 'algebraic objects that can be added and scaled.'
Many of us as students are first shown vectors while illustrating forces or direction in physics courses. One of my favorite math professors used to begin his first vector calculus and linear algebra courses by drawing a circle on a board and posing the question: 'can this circle can be a vector?' It is a common misconception to deem vectors as objects that carry only direction and magnitude, and at first thought many of us would agree.
Though thinking about it, can circles actually be vectors? Can functions be vectors? If so, they ought to follow the aforementioned addition and multiplication operations (check out linear combination).
There's an important topic in linear algebra called the inner product, which begets geometry, interestingly enough. The inner product can be thought of as a functional, that takes two vectors and produces a scalar. There are various ways to produce a scalar with two vectors. One example is: you can integrate a product of two functions (functions can be vectors!) on specified limits to produce a scalar.
The only conditions that must be met for an inner product are: bilinearity, symmetry, and bearing a norm. Further analysis of the inner product will lead one to orthogonal basis expansion or Fourier expansion and Hilbert spaces. Real juicy stuff and a really good question!

How to think of a function as a vector?


How to match specific position based on offset number with a specific number of length with regex?

Question: I need to match characters without knowing what characters they will be and the only data I have is an offset number telling me where to start the match and a length number telling me how long the match has to be.
For example:
My string is: "Susan go to the store everyday"
"offset":17
"length":5
Would match "store"
^.{5} This regex matches the length, but is there a way to add an offset rule to this?
My tool doesn't support capture groups.
Answer: Assuming your regex tool/language support it, you could use a capture group here:
<code>^.{17}(.{5})
</code>
Demo
This would skip the first 17 characters, and then capture the following 5 characters in the first capture group.
Edit:
If your regex tool doesn't have capture groups, you could also use a fixed width lookbehind, e.g.
<code>(?<=^.{17}).{5}
</code>
Demo
Comment: My tool doesn't support capture groups :/
Comment: @DavidToledo Then use a fixed width lookbehind.  If your tool also doesn't support that...then you need a more powerful tool unfortunately.


How can you test an angular form validation directive

Question: I have searched for a very long time and found no solution. I'm new to karma/jasmine testing, but so far it has murdered my productivity. I tried to write my tests in a TDD way but I can't get the tests to work, even though the code does what I want.
I've got this directive that validates an input and displays an error on blur:
angular.module('myApp')
.directive('formValidate', function() {
    var message = {
        error: '',
        warning: '',
        notification: ''
    };

    return {
        link: function(scope, element, attrs) {
            scope.message = message;
            var formElements = element.find('input');
            for (var i = 0; i < formElements.length; i++) {
                switch (formElements[i].getAttribute('type')) {
                    case 'email':
                        validateEmail(scope, formElements[i]);
                        break;
                    case 'password':
                        validatePassword(scope, formElements[i]);
                    default:
                        break;
                }
            }
        }
    };

    function promptUser(scope, text) {
        scope.$apply(function() {
            scope.message.error = text;
        });
    }

    function validateEmail(scope, element) {
        var element = angular.element(element);
        element.bind('blur', function() {
            if (element.hasClass('ng-invalid-email')) {
                promptUser(scope, 'Invalid email format');
            } else {
                promptUser(scope, '');
            }
        });
    }

    function validatePassword (scope, element) {
        var element = angular.element(element);
        element.bind('blur', function() {
            if (element.hasClass('ng-invalid-minlength')) {
                promptUser(scope, 'Password must be at least 6 characters');
            } else {
                promptUser(scope, '');
            }
        });
    }
});

I am trying to test it with:
'use strict';

describe('formValidation directive', function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50;

beforeEach(module('myApp'));
beforeEach(module('ui.router'));

var $compile, $scope;

beforeEach(module('myApp'));
beforeEach(module('ui.router'));

beforeEach(inject(function(_$rootScope_, _$compile_) {
    $compile = _$compile_;
    $scope = _$rootScope_.$new();
}));

describe('register', function() {
    var $element, $controller, testForm, form;

    beforeEach(function() {
        testForm = angular.element('<form name="form" form-validate>' + '
{{ message.error }}
' + '<input type="email" ng-model="register.email" name="email" placeholder="email">' + '<input type="password" ng-model="register.password" name="register-password" placeholder="password" ng-minlength="6">' + '<input type="password" ng-model="register.passwordVerify" name="password-verify" placeholder="password verify" ng-minlength="6">' + '<input type="submit" id="login-btn" value="Submit" >' + '</form>');

        $element = $compile(testForm)($scope);
        $scope.$digest();

    });

    describe('individual field', function() {
        it('adds correct content to error message', function() {
            //How can I set the value of an input here
            //And then trigger a blur event to run the directive
            var input = testForm.find('input')[0];
            var angInput = angular.element(input);
            angInput.val('test'); // I console.log'd this and it doesn't seem to do anything
            expect($scope.message.error === 'Invalid email format').toEqual(true);
        });
        it('does not add error if format is valid', function() {

        });
        it('unhides error element when valid', function() {

        });
    });

    describe('all fields', function() {

    });
});

I would really like to start working with angular TDD, but this is taking way too long.
Comment: what's the problems with those tests? do they give you any kind of errors?
Comment: The "adds correct content to...." test fails. The expect() is not gonna work because when I call angInput.val(), it doesn't change anything. The input is still pristine and untouched. I suppose the real problem here is that I can't change the input value and make it dirty or invalid.
Answer: The important line you are after is:
angular.element(dirElementInput).val('Some text').trigger('input');

(got from Setting view value an input field in a unit test of an angular form directive)


Stack TOP pointer is always null

Question: I am creating a new stack using linked list. I dont know why the TOP pointer is always pointing to NULL. I think I am not setting the top pointer correctly, or it is not visible outside the function.
#include "stdio.h"
#include "stdlib.h"

typedef struct StackItem
{
      int itemValue;
      struct StackItem* NextItemPtr;
}StackItem;

typedef struct Stack
{
    struct StackItem *TOP;
}Stack;

int IsStackEmpty(StackItem *TOP)
{
     if(TOP==NULL)
         return 1;

}

void pushItem(StackItem *headPtr,int n)
{
    StackItem* Newnode;
    Newnode=(StackItem*)malloc(sizeof(StackItem));
    Newnode->itemValue=n;
    printf("Checking Head TOP %d\n\n",IsStackEmpty(headPtr)); //Everytime it is giving 1
    Newnode->NextItemPtr=IsStackEmpty(headPtr)?NULL:headPtr;
    headPtr=Newnode;
}

int main()
{
   Stack* stackptr;
   stackptr=(Stack*)malloc(sizeof(Stack));
   stackptr->TOP=NULL;
   pushItem(stackptr->TOP,3);
   pushItem(stackptr->TOP,6);
   return 0;

}

Comment: You're passing your TOP pointer by-value. You should pass it by address.
Comment: I can't believe this has been up for 10 minutes and no one has commented yet on the malloc-cast. Durp... nm. so much for that P. Or the system includes with open quotes (`#include "stdio.h"`) rather than angle brackets (`#include `).
Comment: Why you people don't learn C before trying to write an OS...
Comment: @H2CO3 I don't think that's relevant at all. The OP isn't trying to write an OS. He's trying to learn C. Where is the problem?
Comment: @WhozCraig I'm too tired to notice that :D Anyways I can hardly read the code given that it *lacks whitespace...* But here, take my upvote for that comment.
Comment: @corsiKa I was being sarcastic. OP is obviously trying to solve a problem for which his programming knowledge hasn't yet grown up.
Answer: This statement does nothing for the caller:
headPtr=Newnode;

You can:

Pass a double pointer and assign to *headPtr
Return Newnode instead of assigning to headPtr

This C FAQ explains this very subject.
Comment: @WhozCraig I think "This statement does nothing **for the caller**" is clear enough.
Comment: @H2CO3 that would be the 5-min no-history. the initial post did not have "for the caller", but since it does now, Ill drop the comment.
Comment: He could also pass the Stack itself in instead of the stack item.
Answer: headPtr = Newnode;

Since headPtr is an argument of the function, it's passed by value. Modifying it inside the function does not have any effect in the caller. You need to pass a pointer to it and modify it through the pointer:
void pushItem(StackItem **headPtr, int n)
*headPtr = NewNode;

Stack TOP pointer is always null


CSS Set multiple colors gradient in pixels?

Question: How do I map out 6 different colors from top to bottom on the y-axis co-ordinates 1, 2, 3, 4, 5 and 6 and those colors take up 1 px each and have a 7th color take up the rest of the div? I have tried this but it does not work:
background-image: linear-gradient(to bottom, #e2e2e2 0%, #e8e8e8 2px, #efefef 3px, #f4f4f4 4px, #f7f7f7 5px, #f8f8f8 6px, #f9f9f9 100%);

Comment: Try this to create any kind of gradient...
https://www.colorzilla.com/gradient-editor/
Answer: Try like below:

html {
 min-height:100%;
 background-image:
  linear-gradient(to bottom,
    orange  0 10px,
    red     0 20px,
    purple  0 30px,
    green   0 40px,
    #f7f7f7 0 50px,
    blue    0 60px,
    yellow 0);
}

Or like this if you want a fading transition

html {
 min-height:100%;
 background-image:
  linear-gradient(to bottom,
    orange  10px,
    red     20px,
    purple  30px,
    green   40px,
    #f7f7f7 50px,
    blue    60px,
    yellow  0);
}

Another idea with multiple gradient:

html {
 min-height:100%;
 background:
  linear-gradient(to bottom,
    orange  ,
    red     ,
    purple  ,
    green   ,
    #f7f7f7 ,
    blue    ) top/100% 25% no-repeat, /* 25% = height */
   yellow;
}
Answer: There you go

#grad1 {
    height: 200px;
    background: red; /* For browsers that do not support gradients */
    background: -webkit-linear-gradient(bottom, orange , yellow, green, cyan, blue, violet); /* For Safari 5.1 to 6.0 */
    background: -o-linear-gradient(bottom, orange, yellow, green, cyan, blue, violet); /* For Opera 11.1 to 12.0 */
    background: -moz-linear-gradient(bottom, orange, yellow, green, cyan, blue, violet); /* For Firefox 3.6 to 15 */
    background: linear-gradient(to bottom, orange , yellow, green, cyan, blue, violet); /* Standard syntax (must be last) */
}

Answer: I think this does what the question is asking - the sizes were edited to make the effect discernible on-screen and admittedly the first example is very garish

.graded{
    background: linear-gradient(
      yellow 0%,
      blue 10px,
      red 20px,
      green 30px,
      pink 40px,
      orange 50px,
      #f9f9f9 60px,
      #f9f9f9 100%
     );
}
.re-graded{
    background: linear-gradient(
    #e2e2e2 0%,
    #e8e8e8 10px,
    #efefef 20px,
    #f4f4f4 30px,
    #f7f7f7 40px,
    #f8f8f8 50px,
    #f9f9f9 60px,
    #f9f9f9 100%
  )
}
div{
    width: 100%;
    height:10rem;
    border:1px solid black;
}

obvious

subtle

Answer: try this:

div {
  background: #466368;
  background: linear-gradient(to right, #e2e2e2 40px, #f8f8f8 50%, #e8e8e8 10%, #293f50 );
  border-radius: 6px;
  height: 120px;
}


How to run a docker container with specific GPUs using Docker SDK for Python

Question: In the command line I am used to run/create containers with specific GPUs using the --gpus argument:
docker run -it --gpus '"device=0,2"' ubuntu nvidia-smi
The Docker SDK for Python documentation was not very helpful and I could not find a good explanation on how to do the same with the python SDK. Is there a way to do it?
Answer: This is how you can run/create docker containers with specific GPUs using the Docker SDK for Python:
client.containers.run('ubuntu',
                          "nvidia-smi",
                           device_requests=[
                           docker.types.DeviceRequest(device_ids=["0,2"], capabilities=[['gpu']])])

This way you can also use other GPU resource options specified here:
https://docs.docker.com/config/containers/resource_constraints/


Find $\int_{\mathbb{R}^n}e^{-\frac{\| x- a\|^2+\| x- b\|^2}{2}} dx$

Question: How to integrate
\begin{align}
\int_{\mathbb{R}^n}e^{-\frac{\| x- a\|^2+\| x- b\|^2}{2}} dx
\end{align}
where $\| \cdot \|$ is the euclidean distance.
I did this for the case of $n=1$ (scalar} and got
\begin{align}
\int_{\mathbb{R}}e^{-\frac{ ( x- a)^2+ ( x- b)^2}{2}} dx=\sqrt{\pi} e^{-\frac{(a-b)^2}{4}}
\end{align}
However, I am having trouble doing this for any $n$.
Comment: Did you try to complete the square?
Comment: @mickep This is what I did for the scalar case. Can you show me how to complete the square for euclidean distance?
Comment: @Lisa - your integral is just a product of the one-dimensional ones which you arleady computed.
Answer: HINT:
Note the kernel is separable with
$$\begin{align}
e^{\frac12\left(\|x-a\|^2+\|x-b\|^2\right)}&=\prod_{i=1}^ne^{\frac12\left((x_i-a_i)^2+(x_i-b_i)^2\right)}\\\\
&=\prod_{i=1}^ne^{x_i^2-(a_i+b_i)x_i+\frac12\left(a_i^2+b_i^2\right)}\\\\
&=\prod_{i=1}^ne^{\left(x_i-\frac12\left(a_i+b_i\right)\right)^2+\frac14(a_i-b_i)^2}\\\\
\end{align}$$
Answer: The problem seems to be completing the square. In $n$ dimensions it works pretty much the same. Here we go (tell me if there is anything that is unclear):
$$
\begin{aligned}
\frac{\|x-a\|^2+\|x-b\|^2}{2}&=\|x\|^2- a\cdot x-b\cdot x+\frac{\|a\|^2+\|b\|^2}{2}\\
&=\Bigl\|x-\frac{a+b}{2}\Bigr\|^2-\Bigl\|\frac{a+b}{2}\Bigr\|^2+\frac{\|a\|^2+\|b\|^2}{2}\\
&=\Bigl\|x-\frac{a+b}{2}\Bigr\|^2+\Bigl\|\frac{a-b}{2}\Bigr\|^2
\end{aligned}
$$
Next, use the fact that the integral is translation invariant, so you get
$$
\begin{aligned}
\int_{\mathbb R^n}\exp\Bigl(-\frac{\|x-a\|^2+\|x-b\|^2}{2}\Bigr)\,dx
&=
\exp\Bigl(-\Bigl\|\frac{a-b}{2}\Bigr\|^2\Bigr)
\int_{\mathbb R^n}\exp\Bigl(-\Bigl\|x-\frac{a+b}{2}\Bigr\|^2\Bigr)\,dx\\
&=
\exp\Bigl(-\Bigl\|\frac{a-b}{2}\Bigr\|^2\Bigr)
\int_{\mathbb R^n}\exp(-\|y\|^2)\,dy.
\end{aligned}
$$
I assume you can take it from here.
Comment: Mmm, clear as supper. Bon appetit! ;)
Answer: We can translate the entire space, moving $a$ to $0$ and $b$ to $b-a$.  We can then rotate the space such that the second locus is on the $x$ axis.
If we let r = $\|a-b\|$, and decompose the now-independent integrals, we get:
$$
\begin{align}
\int_{\mathbb{R}^n}e^{-\frac{\| x- a\|^2+\| x- b\|^2}{2}} dx &=
\int_{\mathbb{R}^{n-1}}e ^ {-x^2}dx \int_{\mathbb{R}}e^{-\frac{x^2+(x- r)^2}{2}} dx
\end{align}$$
Which yields:
$$
\sqrt{\pi}^n e^{- \frac{r^2}\4}
$$


C# Unity. Control variable causes loop when value is 2

Question: I have this code, when the variable waveNumer equals 1 the code works just fine, spawns the enemies and all that, but when is 2 Unity crashes. I'm guessing that is entering a weir loop but I cant figure it out why its happening.
        int percentForWave=0;
        int percentForType=0;

        int TotalEnemies = (int)enemySpawnsThisRound;
        if (waveNumer == 1)
        {
            Debug.Log("Entro al wave 1");
            percentForWave = 20;
            percentForType = 20;
            startList = 0;

        }
        if (waveNumer == 2)
        {
            Debug.Log("Entro al wave 2");
            percentForWave = 70;
            percentForType = 70;
            startList = endList;

        }
        if (waveNumer == 3)
        {
            Debug.Log("Entro al wave 3");
            percentForWave = 10;
            percentForType = 10;
            startList = endList;
        }

        int enemiesThisWave = Decimal.ToInt32(Math.Round(TotalEnemies * ((decimal)percentForWave / 100), 1));
        int enemiesForType = Decimal.ToInt32(Math.Round(lenghtList * ((decimal)percentForType / 100), 1));

        endList = enemiesForType + startList;

        clonesASpawnear = new GameObject[enemiesThisWave];
        int i = 0;

        while ( i < clonesASpawnear.Length)
        {

            for (int j = startList; j == endList; j++)
            {
                Debug.Log("Numero j = " + j);
                if (clonesASpawnear[i] == null)
                {

                    clonesASpawnear[i] = Instantiate(enemyTypeList[j], spawnPoints[j].transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
                    clonesASpawnear[i].SetActive(true);//lo activo
                    clonesASpawnear[i].GetComponent<EnemyMovement_DCH>().player = Target;
                    aliveEnemies += 1;
                    clonesASpawnear[i].GetComponent<EnemyDamageHandler_DCH>().SpawnerEnemies = this;
                    i++;
                }

            }

        }

Also It would be usefull if I could see the unity log after the program crashes, but no idea on how to do that.
Comment: At a first look, I suspect that you want j < endList, not j == endList
Comment: "It crashes" is not a sufficient problem description. What is the Exception message? What line does the debugger say it comes from?
Comment: I cant provide aditional information because the program just crashes when the variable value reaches 2. And no debug information is stored.
Comment: when J<endList  the program crashes right away (when the value is 1).
Answer: From here what I can see I see a problem in your for loop's condition statement, see here you have
for (int j = startList; j == endList; j++)
in your condition, you only have a single to get is true. when the value of j is equal to endList since in your for loop j is incrementing each and every iteration your condition will only be true for only one iteration which I guess the first iteration according to you. And if the for loop is not going to iterate value of i which is a control variable of an outer while loop is never going to increment hance your while loop will go to infinite-state where it'll never stop iterating, everything freezes and crash.
as I can read in comment that j < englist immediately result in a crash when j = 1
I would like to have the value of a few of the variables at the time of the crash.

clonesASpawnear.Length
startList
endList
i
Comment: I'm with @Ankit on this one. If you get no error messages/debug info, it is likely that infinite loop situation caused by unintended looping problems. Changing your `j` for loop should get you a step closer to what you'd want.
Comment: I cant see any values at the time of the crash. No logs are printed
Comment: But this gave me enough idea of what is wrong to continue by myself, so tks a lot!
Answer: We ended up solving the issue this way. I post the solution in case anyone is in the same pickle.
 while ( i < clonesASpawnear.Length)
    {

        if(j <= endList)
        {
            Debug.Log("Numero j = " + j);
            //se fija que ya no este en el escenario el que va en ese punto asi no superpone items
            if (clonesASpawnear[i] == null)
            {

                clonesASpawnear[i] = Instantiate(enemyTypeList[j], spawnPoints[j].transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
                clonesASpawnear[i].SetActive(true);//lo activo
                                                   //Aca le asigno el blanco que quiero que siga al spawnear
                clonesASpawnear[i].GetComponent<EnemyMovement_DCH>().player = Target;
                aliveEnemies += 1;
                //aca le asigno este spawner para que pueda afectar luego las variables cuando lo maten por ejemplo
                clonesASpawnear[i].GetComponent<EnemyDamageHandler_DCH>().SpawnerEnemies = this;

            }
            j++;
            i++;
        }
        else
        {
            j = startList;
        }

     Debug.Log("Numero i = " + i);

    }

}


Comparing the cardinalities of infinite sets

Question: What is the set that has the greatest cardinality?

$\mathbb{R}$
The set of all functions from $\mathbb{Z}$ to itself.
The set of all functions from $\mathbb{R}$ to $\{0,1\}$.
The set of all finite subsets of $\mathbb{R}$.
The set of all polynomials with coefficients in $\mathbb{R}$.

How do I compare the cardinalities?
Answer:
That of $\mathbb R$
That of $\mathbb R$
That of $2^\mathbb R$
That of $\mathbb R$
That of $\mathbb R$

That is all have the same cardinality except 3 which has greater cardinality.
Basically you have to use the definition for cardinality comparision:
$|A| \le |B|$ means that there exists a surjection from $B$ to $A$
$|A| = |B|$ means that there exists a bijection between $A$ and $B$
Now we can start with concluding that the first and second have the same cardinality. First we can transform the functions in the second a little to be the set of functions from $\mathbb N$ to $\mathbb N$ by just mapping $\mathbb Z$ to $\mathbb N$. Now the functions corresponds to a sequence of numbers which can be mapped to a single number (just concatenate the numbers in base 8 and separate them by 8 and interpret it as a decimal part of a number).
Next the third we note that these functions are characteristic function for some subset of $\mathbb R$. The cardinality for that set is same as $2^\mathbb R$, which is larger than $\mathbb R$.
The fourth and fifth are the same because a polynomial is given by a finite number of coefficients and consequently the number of polynomials of degree n is the same as $\mathbb R^n$ (which is the same as for $\mathbb R$). The number of subsets with $n$ elements are the same ($|\mathbb R|/n!$). Then all of them are just the countable union of sets of specified size, so the cardinality is again that of $\mathbb R$.


rackspace cloudfiles delay before on CDN after upload

Question: I am implementing rackspace cloudfiles for a site. If a user uploads a profile image we want to store it on cloudfiles in a CDN enabled container. This works only it takes a couple of secs before the file is available on the CDN.
So when you upload your profile -> we store it in cloud -> reload the page it often isn't available yet resulting in a broken image.
Has anybody experienced this issue and if so how did you work around it?
Answer: Yes,this is a function of how CDN's work.
The CDN (in the case of RackSpace, Akamai) must become aware of your content, so it takes some time for your content to show up on a CDN (usually just a matter of minutes).


Paint job estimator rounding up

Question: I'm suppose to create a program that calculates the cost of doing a paint job. For every 125 square feet of wall space, one gallon of paint an eight hours of labor are required. The company charges $42.50 per hour for labor. The program should ask the user to enter the square feet of wall space to be painted and the price per gallon. The program is to display the following:

The number of gallons of paint required rounded up to whole gallons
The hours of labor required
The cost of the paint based on the round up whole gallons
The labor charges
The total cost of the paint job

Negative numbers, zero,  and non-number inputs are not allowed; number of gallons should be rounded up always; a prompt should appear at the end asking for another estimation; hours of labor should be displayed to one decimal paint; gallons of paint should be displayed as an integer value with nothing shown to the right of the decimal; total labor charges should be displayed to two decimal points and a $ is to be displayed at the start of the total charge value.
This is what I have so far:
print("This program calculates the cost of doing a paint job.")

do_calculation = True
while (do_calculation):

    while (True):
        try:
            # Input amount of square feet of wall space
            square_feet = float(input("How many square feet of wall space do you need painted? "))
            if (square_feet <= 0):
                print ("Zero and negative numbers can not be accepted.")
                continue
        except ValueError:
            print("The value you entered is invalid. Only numericals are valid.");
        else:
            break
    while(True):
        try:
            # Input cost per gallon
            cost_per_gallon = float(input("Cost per gallon of paint? $"))
            if (cost_per_gallon <= 0):
                print ('Zero and negative numbers can not be acepted.')
                continue
        except ValueError:
            print("The value you entered is invalid. Only numericals are valid.");
        else:
            break
    while(True):
        try:
            # Input number of gallons needed
            gallons_needed = float(square_feet)/125.0
        except ValueError:
            print("The value you entered is invalid. Only numericals are valid.");
        else:
            break

    # Hours of labor expected
    hours_of_labor = 8 * gallons_needed

    # Cost of Labor expected
    labor_costs = 42.5 * hours_of_labor

    # Paint cost
    paint_costs = float(cost_per_gallon) * gallons_needed

    # Number of gallons of paint
    print("The number of gallons of paint required is %f" % gallons_needed)

    # How long labor lasts
    print("The number of gallons of hours of labor required are %f" % hours_of_labor)

    # Charged for labor
    print("The labor charges are $%f" % labor_costs)

    # Total amount of labor
    print("Total labor is: %f" % (labor_costs + paint_costs))

    another_calculation = input("\nDo you want to try another estimate? (y/n): ")
    if (another_calculation != "y"):
        do_calculation = False

Comment: What's your question?
Comment: I actually have three - all with rounding: How do you have hours_of_labor displayed to one decimal point (ex: 26.5 hours), How do you display gallons_of_paint as an integer value with no decimals (ex: 6), And how do you display the total of labor charges to two decimal points (ex: $144.69)
Answer:
I actually have three - all with rounding: How do you have
  hours_of_labor displayed to one decimal point (ex: 26.5 hours), How do
  you display gallons_of_paint as an integer value with no decimals (ex:
  6), And how do you display the total of labor charges to two decimal
  points (ex: $144.69)

You should have added these in your actual question
Formatting of numbers is controlled by adding various format specifiers to the string that is output.  Keep in mind that $144.69 is a string and not a valid number.
You are using some of these already in your code (%f is a specifier), you just have to modify these.
Finally - rounding is something you'll have to take care of with respect to the total hours, in this case you'll have to round up (as most contractors in real life do) have a look at the built-in round function with help on that.

gallons_needed = round(float((square_feet)/125.0),1)? Will this make
  the input by the user rounded UP always for calculations

You can try it and see:
>>> round(1.24, 1)
1.2
>>> round(1.25, 1)
1.3

So the answer here is no, it will not always round up. You can read the documentation for more hints on how to make it always round up.

one minor annoyance: with 'print("The labor charges are:
  $",(labor_costs))' the program adds an annoying space between the
  amount and $: 'The labor charges are: $ XXX.XX' How do I get rid of
  the space between?

Its printing the space because you are passing in two arguments to the print function, its just printing one after the other:
>>> print('The costs are $',(i))
The costs are $ 144.43

If you pass it one string, it will print it correctly. Here I am passing in one string, with the argument formatted as a string (%s):
>>> print('The costs are $%s' % (i))
The costs are $144.43

Note here the () are unnecessary, (they don't do anything useful). You can omit them:
>>> print('The cost are $%s' % i)
The cost are $144.43

You can also use the newer string formatting mini-language, like this:
>>> print('The costs are ${}'.format(i))
The costs are $144.43

Comment: Like: gallons_needed = round(float((square_feet)/125.0),1)? Will this make the input by the user rounded UP always for calculations?

Also, one minor annoyance:
with 'print("The labor charges are: $",(labor_costs))'
the program adds an annoying space between the amount and $:
'The labor charges are: $ XXX.XX'
How do I get rid of the space between?

Paint job estimator rounding up


Allowing role permissions to a content type based on the date

Question: I'd like to allow a certain role can add new content of a certain content-type ONLY between two dates. Before or after these dates the role shouldn't be able to create a new content of this content-type.
Is it possible through the Drupal core or any module? I haven't found anything about it.
Answer: You can implement hook_node_access() (This is now a real hook in Drupal 7) and implement whatever you want.
Comment: Mmmm, It sounds great. I hadn't thought about this hook. Nevertheless, I would have to create some frontend to save the date interval and role affected. I don't want to edit ".module" file every time. Thanks.
Comment: Yeah, sure, but you will have to do that whatever way you implement the access check.
Comment: I've created a "date field" in my content-type with a default value (maximum date for which an user has permissions to add new content for this content-type). The problem is I can't access to this field from "hook_node_access". Furthermore, this value is encrypted in database and I can't do a db_query to retrieve this value. Any suggestions?


Find an explicit solution to the SDE $dX_t = \frac{1}{2} X_t B_t^4dt + X_t B_t^2 dB_t$

Question: Problem statement:
Let $(B_t)_{t\geq0}$ be a one-dimensional standard Brownian motion. Find an explicit solution to the SDE $$dX_t = \frac{1}{2} X_t B_t^4dt + X_t B_t^2 dB_t$$
with initial condition $X_0 = 1$. Hint: Apply the Itô formula to $Y_t :=\text{log}X_t$.
Attempted solution:
Let $Y_t = g(t,X_t) = \text{log}X_t$  where $g(t,x) = \text{log} x$. The partial derivatives are $\partial_t g = 0, \partial_x g= \frac{1}{x}, \partial_x^2 g = -\frac{1}{x^2}.$
Itô's formula in differential form then yields:
\begin{equation}
\begin{split}
dg(t,X_t) &= \partial_x g(t,X_t)dX_t + (\partial_tg(t,X_t) + \frac{1}{2}\partial_x^2g(t,X_t))dt \\
dY_t &= \frac{1}{X_t}(\frac{1}{2} X_t B_t^4dt + X_t B_t^2 dB_t) + (0 - \frac{1}{2} \frac{1}{X_t^2})dt \\
&= \frac{1}{2}(B_t^4-\frac{1}{X_t^2})dt + X_tB_t^2dB_t
\end{split}
\end{equation}
I don't know how to continue. It's an old exam question, so I have the solution:

I don't know why $d\langle X \rangle_t = dt = X_t^2Bt^4dt$.
Answer: The function $g$ depends only on $X_t$, we have :
\begin{equation}
\begin{split}
dg(X_t) &= \partial_x g(X_t)dX_t + \frac{1}{2}\partial_x^2g(X_t))dt \\
dY_t &= \frac{1}{X_t}(\frac{1}{2} X_t B_t^4dt + X_t B_t^2 dB_t) -\frac{1}{2} \frac{1}{X_t^2}d\langle X\rangle_t \\
\end{split}
\end{equation}
Since $$dX_t = \underbrace{\frac{1}{2} X_t B_t^4}_{b(X_t)}dt + \underbrace{X_t B_t^2}_{\sigma(X_t)}dB_t$$
then $d\langle X \rangle_t$ is given by :
$$\implies d\langle X\rangle_t = \sigma^2(X_t)dt=(X_tB_t^2)^2dt=X_t^2B_t^4dt$$
You get
$$dY_t=B_t^2dB_t\implies Y_t=\underbrace{Y_0}_{=0}+\int_0^tB_s^2dB_s=\int_0^tB_s^2dB_s$$
Finally,
$$X_t=\exp\left(\int_0^tB_s^2dB_s\right)$$
Note :  Itô processes of the form
$$X_t=X_0+\int_0^t b(s,X_s)ds+\int_0^t \sigma(s,X_s)dB_s$$
have the quadratic variation
$$\langle X\rangle_t=\int_0^t \sigma^2(s,X_s)ds$$
For a detailed proof on why it is equal to the previous quantity, check this answer here.
EDIT
A quick explanation on why $dB^2_t=d\langle B\rangle_t = dt$:
Since $$B_t=\int_0^tdB_s=\int_0^t \textbf{1}\times dB_s\implies \langle B\rangle_t=\int_0^t \textbf{1}^2 ds=t \implies d\langle B\rangle_t = dt$$
As for your formula : Suppose $X_t=X_0+\int_0^t b(s,X_s)ds +\int_0^t \sigma(s,X_s)dB_s$. Then for any twice-differentiable scalar function $g$ :
\begin{equation}
\begin{split}
dg(t,X_t)&=\frac{\partial g}{\partial t}(t,X_t)dt+\frac{\partial g}{\partial x}(t,X_t)dX_t+\frac{1}{2}\frac{\partial^2 g}{\partial^2 t}(t,X_t)d\langle X \rangle_t\\
&=\frac{\partial g}{\partial t}(t,X_t)dt+\frac{\partial g}{\partial x}(t,X_t)\left(b(t,X_t)dt + \sigma(t,X_t)dB_t\right)+\frac{1}{2}\frac{\partial^2 g}{\partial^2 x}(t,X_t)(\sigma^2(t,X_t)dt)\\
&=\left(\frac{\partial g}{\partial t}(t,X_t)+ b(t,X_t)\frac{\partial g}{\partial x}(t,X_t)+\frac{1}{2}\frac{\partial^2 g}{\partial^2 x}(t,X_t)\sigma^2(t,X_t)\right)dt\\
&+\left( \sigma(t,X_t)\frac{\partial g}{\partial x}(t,X_t) \right)dB_t
\end{split}
\end{equation}
I guess you can see the term you missed out.
Hope this explains your questions.
Comment: I think OP's question is exactly '*why* $d\langle X,X\rangle_t=\sigma(X_t)^2dt $ holds?'
Comment: In that case, should not the substitution yield $dt = d \langle X \rangle_t / \sigma(X_t)^2$?
Comment: @Oskar You don't need to substitute anything. The problem is : The Itô formula you used is not correct. I'll edit my answer to explain further (I'll use your two variable formula).
Answer: Some mathematicians don't like the following abuse of notation, but it has the advantage to be limpid; it goes as follows :
$$
\mathrm{d}\langle X\rangle_t = \mathrm{d}X_t \cdot \mathrm{d}X_t = \left(\frac{1}{2} X_t B_t^4\mathrm{d}t + X_t B_t^2 \mathrm{d}B_t\right)^2 = X_t^2B_t^4\,\mathrm{d}t + \mathcal{O}(\mathrm{d}t)
$$
since $\mathrm{d}B_t^2 \equiv \mathrm{d}t$.
Comment: Could you please elaborate $\text{d}B_t^2 \equiv \text{d}t$?


How is the .similarity method in SpaCy computed?

Question: Not Sure if this is the right stack site, but here goes.
How does the .similiarity method work?
Wow spaCy is great! Its tfidf model could be easier, but w2v with only one line of code?!
In his  10 line tutorial on spaCy andrazhribernik show's us the .similarity method that can be run on tokens, sents, word chunks, and docs.
After nlp = spacy.load('en') and doc = nlp(raw_text)
we can do .similarity queries between tokens and chunks.
However, what is being calculated behind the scenes in this .similarity method?
SpaCy already has the incredibly simple .vector, which computes the w2v vector as trained from the GloVe model (how cool would a .tfidf or .fasttext method be?).
Is the model simply computing the cosine similarity between these two w2v, .vector, vectors or comparing some other matrix? The specifics aren't clear in the documentation; any help appreciated!
Comment: "how cool would a .tfidf or .fasttext method be?"  the [docs](https://spacy.io/usage/vectors-similarity#custom-loading-other) provide an example of replacing the GloVe vectors with FastText.  It's maybe not exactly the same as having them together. [Github](https://github.com/explosion/spacy/blob/master/examples/vectors_fast_text.py)
Answer: Found the answer, in short, it's yes:
Link to Source Code
return numpy.dot(self.vector, other.vector) / (self.vector_norm * other.vector_norm)

This looks like it's the formula for computing cosine similarity and the vectors seem to be created with SpaCy's .vector which the documentation says is trained from GloVe's w2v model.
Answer: By default it's cosine similarity, with vectors averaged over the document for missing words.
You can also customize this, by setting a hook to doc.user_hooks['similarity']. This pipeline component wraps similarity functions, making it easy to customise the similarity:
https://github.com/explosion/spaCy/blob/develop/spacy/pipeline.pyx#L50
Comment: Tecnically, you appear to have linked to the `SentenceSegmenter` strategy.


R language:choose the max element one-on-one of two vectors

Question: a <- c(12,13,32,46,14)
b <- c(9,24,43,32,57)
result <- c(12,24,43,46,57)

The vector result is from the comparision between vector a and b.For example,as for the first element of a and b,12 is greater than 9 so the first element of vector result is 12.In order to obtain the vector result,what is the code of R?
Comment: You can accept my answer by clicking the grey check mark. Thanks.
Answer: You are looking for pmax:
pmax(a, b)

But this also makes a good demonstration of ifelse:
ifelse(a > b, a, b)


Removing Unit Roots

Question: If I have the following AR(p) process \begin{align} y_t=a_1 y_{t-1} + a_2 y_{t-2} + ... + a_p y_{t-p}+u_t, \end{align}where $ u_t $ is white noise, and I suppose the AR polynomial has 2 unit roots, how can I mathematically show that the process can be made stationary by second-order differencing? (Further, I assume finite moments for the process.)
Edit: I guess this question was not precisely formulated above. Looking at the AR polynomial
\begin{align}
1-a_1 z - a_2 z^2 - ... - a_p z^p = (1-\lambda_1 z) \times ... \times(1-\lambda_p z),
\end{align} where $\lambda_1, . . . , \lambda_p$ are the reciprocals of the roots of the polynomial, how can I see that multiplying my process by $(1-L)^2$ removes both of my unit roots?
Answer: Your problem here is that you are multiplying by $(1-L)^2$ instead of defining a new observable value that absorbs this term.  Without loss of generality, consider the case where you have two unit roots and $p-2$ non-unit roots.  Using the factorised form of the AR model, you have:
$$\Bigg( (1-L)^2 \prod_{i=1}^{p-2} \Big( 1-\frac{L}{r_i} \Big) \Bigg) Y_t = \varepsilon_t.$$
Applying second-order differencing gives you the observable series $Z_t = (1-L)^2 Y_t$ so you can now write your model as a standard AR($p$) model in terms of this new variable as:
$$\Bigg(\prod_{i=1}^{p-2} \Big( 1-\frac{L}{r_i} \Big)  \Bigg) Z_t = \varepsilon_t.$$
If the remaining roots $r_1,...,r_{p-2}$ are outside the unit circle (i.e., $|r_i|>1$ for $i=1,...p-2$) then you have a standard AR($p-2$) model, which converges to a stationary distribution (and is stationary if you set the starting distribution equal to this stationary distribution).  Of course, if any of these roots is inside the unit circle you get an explosive process, but in that case the problem is not the unit roots, but the explosive roots.
Answer: In terms of mathematical proof, I don't know (I am not well versed in those).
Empirically, the way to deal with prospective unit roots within your autoregressive model is as follows...
The way you set up your autoregressive variable, it is not unlikely that every single variable within your model have a unit root and are non-stationary (saying essentially the same thing).  That is because your variables are not differenced at all.  They are all "level" variables.  And, if they are embedded within time series, longitudinal data, they will by definition trend somewhat or a lot, and have unit roots.
The first thing to check is if the residuals of such a model are stationary.  And, if they are... then your model could be considered adequately specified and resolving the unit root issue due to Cointegration.  In other words, you would have a successful Cointegration model suggesting that even though both sides of the equation of your regression have unit roots, there is a stable relationship between your dependent variable and your independent variables.
Now, even if the above is indeed a successful Cointegration model one may argue this model is still somewhat spurious.  And, that you would need to make an effort to remove the unit roots.  You would do that through first differencing (not yet second differencing).  And, that is instead of taking Ys as variables you would take the change in Ys as variables (Y - Yt-1).  This would fully detrend your variables.  And, you could test them for unit roots.  Most likely, the unit roots are gone.  Sometimes, unit roots still remain (but to a far lesser degree).  That is because the majority of unit root tests are very sensitive if not overly sensitive.  However, you could demonstrate that the remaining unit roots are benign and don't need to be resolved further based on the following set of arguments: 1) your variables are fully detrended (most often it does not make sense to go on to second differencing); 2) again test the residuals, and if they are stationary you again have a successful cointegration model; 3) check for the autocorrelation of residuals, including the Durbin Watson score, those are also good diagnostics of the severity of unit roots (serious unit roots have very autocorrelated residuals with DB score much under 1.4 or so).
I suspect your model as modified would demonstrate that either your model has no unit root or really benign one.  This is because autoregressive models have very well behaved residuals.  With so many autoregressors it is almost impossible for your residuals to be autocorrelated.
Comment: Thank you. This was very helpful for empirical application. However, I am looking for a mathematical display of eliminating multiple unit roots. Many textbooks say that by looking at the AR polynomial you can see how differencing removes the unit roots. I would like to see a display of this for higher order integration.

Removing Unit Roots


Busca PHP/MySQL (mostrar apenas resultado exatamente igual ao digitado)

Question: php recolhe os dados de inputs usando método POST. Ele está conectado direitinho, tá pesquisando, mas ao digitar o UF e Município ele não me mostra apenas exatamente o que digitei, mas também os relacionados! tipo digitei SP - São Paulo, ele não me mostra só isso ele mostra SP - São Carlos, SP- São Fulano, SP - São Siclano etc. enfim, mostra todos de tem s, ou ã e eu quero que mostre SOMENTE EXATAMENTE O QUE DIGITEI. Se Alguém souber e puder ajudar fico muito grata. Segue meu cógido:
<?php

include ('conectar.php');

$connection = mysqli_connect($host, $user, $pass,$database);
 if (!$connection) { echo ("Erro ao conectar"); }

$opcao = $_POST["opcao"];
if($opcao == "2"){
    $sg_uf = '"%'. $_POST["txtsg_uf"] .'%"';
    $nm_municipio = '"%'. $_POST["txtnm_municipio"] .'%"';
    $nm_candidato = '"%'. $_POST["txtnm_candidato"] .'%"';
    $dt_ano = '"%'. $_POST["txtdt_ano"] .'%"';

$query = "SELECT * FROM resultado "
. "WHERE sg_uf LIKE ".$sg_uf." OR nm_municipio LIKE ".$nm_municipio." OR nm_candidato LIKE ".$nm_candidato." OR dt_ano LIKE ".$dt_ano."";

    $result =  mysqli_query($connection,$query);
    if (!$result) {
      die("Query inválida na seleção dos dados");
    }

    while ($dados=  mysqli_fetch_array($result,MYSQLI_ASSOC)) {

        if ($result > 0){
            echo "Opção de Busca Avançada/Eleições Municipais:
";
            echo "Encontramos!
";
            echo "UF do Estado: $dados[sg_uf]
";
            echo "Nome do Município: $dados[nm_municipio]
";
            echo "Nome do Candidato: $dados[nm_candidato]
";
            echo "Ano da Eleição: $dados[dt_ano]
";
            echo "
";
        }
        else {
            echo "Desculpe, nada foi encontrado.";
        }
    }
}

?>

Comment: use `AND` se quer resultados com todas as condições. `OR` vai te retornar coisas que tem a condição A, OU a condição B, ou a condição C. Outra coisa, `LIKE` não é pra buscas exatas. Pra buscas exatas basta o `=`
Comment: @Bacco Fiz assim mas não apareceu nada `$query = "SELECT * FROM resultado_votacao_candidato_zona_eleicaomunicipal "
. "WHERE sg_uf = ".$sg_uf." AND nm_municipio = ".$nm_municipio." AND nm_candidato = ".$nm_candidato." AND dt_ano = ".$dt_ano."";`
Answer: Bom, agradeço a todos que me ajudaram, principalmente ao Bacco, muito obrigada! A partir do que me passaram por aqui cheguei ao seguinte resultado:
<?php
include ('conectar.php');

$sg_uf = '"%'. $_POST["txtsg_uf"] .'%"';
$nm_municipio = '"%'. $_POST["txtnm_municipio"] .'%"';
$nm_candidato = '"%'. $_POST["txtnm_candidato"] .'%"';
$dt_ano = '"%'. $_POST["txtdt_ano"] .'%"';

$connection = mysqli_connect($host, $user, $pass,$database);
 if (!$connection) {
 echo ("Servidor temporariamente fora de servi?o");
}

$query = "SELECT * FROM resultado "
. "WHERE sg_uf LIKE ".$sg_uf." and  nm_municipio LIKE ".$nm_municipio." and  nm_candidato LIKE ".$nm_candidato." and  dt_ano LIKE ".$dt_ano."";
$result =  mysqli_query($connection,$query);
if (!$result) {
  die("Query invalida");
}

while ($dados=  mysqli_fetch_array($result,MYSQLI_ASSOC)) {

if ($result > 0){

echo " Encontramos!
";

    echo "UF do Estado: $dados[sg_uf]
";
    echo "Nome do Municipio: $dados[nm_municipio]
";
    echo "Nome do Candidato: $dados[nm_candidato]
";
    echo "Ano das Eleicoes: $dados[dt_ano]
";
    echo "
";

}
else {
    echo "Desculpe, nada foi encontrado";
}
}
?>

É isso ai tá funcionando direitinho, só me mostra exatamente o que digitei.
Answer: Sarah, tente mudar a sua SQL para a seguinte forma:
    $query = "SELECT * FROM resultado "
. "WHERE sg_uf LIKE '%".$sg_uf."' OR nm_municipio LIKE '%".$nm_municipio." OR      nm_candidato LIKE ".$nm_candidato." OR dt_ano LIKE ".$dt_ano."";

O que eu fiz foi colocar uma aspa simples após o LIKE com o curinga %.
Comment: Diego, feito conforme sugerido.
Comment: Fiz exatamente como vc colocou mas deu query inválida ai modifiquei assim: `$query = "SELECT * FROM resultado_votacao_candidato_zona_eleicaomunicipal "
. "WHERE sg_uf LIKE '%".$sg_uf."' OR nm_municipio LIKE '%".$nm_municipio."' OR nm_candidato LIKE '%".$nm_candidato."' OR dt_ano LIKE '%".$dt_ano."'";` mas não deu certo, não mostrou nada


Significance test between two samples when positions matter

Question: Let's say that I have two samples:
A    B  C    D
100  5  17   12  #<- Method 1
90   2  4    15  #<- Method 2

And want to compare to test whether method 1 is different from method 2. However, that observations in the samples are tied together, say 100 and 90 come from the same market A. What is the proper way to test this?
I am pretty sure that lumping everything together and doing a t-test or Mann-Whitney U test is not the way to go.
Comment: What do "A", "B", "C", "D" mean?  Could they correspond to factors that have a natural order?  What do the numbers mean?  (Are they counts, measurements of physical quantities, percents, ...?)  How were the numbers obtained--are they the result of a complete census of something, of random samples, of samples of convenience, or something else?
Comment: We can think of "A", "B", "C", "D" as events; they have no order, but values corresponding to those events are paired. I am very sure that paired t-test (as suggested by @Greg Snow) is what I need.
Comment: Exactly how would you apply the paired t-test to these data? It's still not possible to tell whether it would be appropriate or not because you haven't disclosed the (essential) information I mentioned.
Comment: @whuber Let's say we used marketing strategy method 1 in on half of customers in market A, and  marketing strategy method 2 on the other half. Method 1 generated 100 purchases in market A, and method 2 generated 90 purchases in market A, and so on. Does this answer your question?
Comment: Sort of--at least it shows me this is not a matter for a paired t-test! You have 100+90+5+...+15 total results and they are not paired. Although you could (somewhat artificially) pair the *groups* and perform a t-test of the differences 10,3,13,-3 against 0, it would have little power and cannot be recommended. (It reports that $p=0.21,$ which is not significant.) Many people would routinely begin with a *chi-squared* test to see whether any differences between the methods seem to hold. (There is a difference at the 5% level: $\chi^2=8.1$, $p\approx 0.04$ via simulation.)
Comment: @whuber, thank your for your reply, I will read up on those tests, to have proper understanding. Maybe you should post your comment as an answer.
Comment: I hesitate to post an answer because I still do not understand how these numbers were actually obtained. For instance, one of my concerns is that if there were any variation in the amounts of exposure of the individual markets to the two methods, then none of this analysis would produce meaningful results.
Comment: @I have no way of knowing about the amount of exposure for sure, but I don't think the difference is big. What about the if assume that exposure was exactly the same for both groups.
Comment: The problem is that even a little variation, when properly accounted for, will increase the p-value and you're already in a very gray area. I would tentatively conclude that your data are suggestive of a slight superiority of method 1 but if much depends on your conclusion, the evidence may be weak enough to warrant additional data collection.
Comment: Oh, I really have more than 4 observation points, this was just an example (but I don't think this changes the nature of the question). If we assume that variation in exposure is not biased towards any one method over all markets, wouldn't it cancel out as white noise?
Comment: You *hope* it will cancel out. (There may be a lot of value in contemplating why it might not because that could suggest ways to improve your experiments.)  Assuming such cancellation, the noise needs to be accounted for in the testing: that's why the p-value should go up. If you have no control over the exposure variation and cannot measure it, then a rough and ready recourse is to increase the stringency of your criterion for significance.
Comment: McNemara's test would work here if you can reduce this to a 2x2. Otherwise, I'm thinking a logistic regression on the differences with clustered se's and indicator variables for each group on each coefficient. Significant coefficients will indicate a positive.
Answer: If you are willing to assume normality of the differences (with your sample size, the assumption will be very important, but if your real data is much larger then the Central Limit Theorem makes this assumption less important) you can use a paired-T test, essentially take the difference between each pair (always the same direction) then do a 1 sample t test on the differences testing if the mean difference is 0.
There are non-parametric tests that will also test pairs and don't require the assumption of normality, but they are going to have very low power given your sample size (the sign test and exact permutation tests will have 0 power for any alpha level less than 0.0625).
Answer: Your observations appear to be counts (number of purchases). You would be best to use analyses that relate to that kind of data. A paired t-test won't be particularly suitable for a number of reasons (the variance of the difference isn't constant, for starters)
In this case, a chi-squared test of homogeneity will allow you to test for site-differences.


hook_preprocess_page for mobile detection

Question: I am attempting to set a variable $is_mobile that I can use in my page.tpl.php function.
<code>function mytheme_preprocess_page(&$vars)
{
    require_once(libraries_get_path('mobile_detect').'/Mobile_Detect.php');
    $detect = new Mobile_Detect();
    $is_mobile = $detect->isMobile() or $detect->isTablet();
    $vars['is_mobile'] = $is_mobile;
}
</code>
It seems the result is cached and whatever the first hit will be used.
My overall goal is to create a dynamic menu for mobile and desktop. (One for each)
What is the best way to approach to this?
Answer: You could use panels and create a variant for mobile and other for non mobile.
the mobile detect module provide a selection rule for that by using
mobile_detect_ctools