Suppose $(A, \le)$ is a partially ordered set. Define a relation $\preceq$ on $A\times A$ by $(a,b)\preceq (c,d)$ if

Question: if and only if
1) $a\le c$ and $a \ne c$
2) $a = c$ and  $b\le d$
Prove that $(A\times A,\preceq)$ is also a partially ordered set.
So to prove this I would start with trying to find 1) Reflexivity, 2) anti-symmetricy and 3) Transitivity right?
How would I do that, does the $A\times A$ mean anything special in this case?
For Reflexivity would i say 1) since $\le$ is reflexive then that means $A\le A$ ... I just dont know how to begin this?
Comment: I presume $A * A$ means $A\times A$, the *Cartesian product* of set $A$ with itself:  $A \times A = \{(a, b)\mid a \in A, b \in A\}$
Comment: I took the liberty of replacing the somewhat awkward notations $<<$ and $<<<$ by $\le$ and $\preceq$, respectively, and I corrected $A*$ to $A\times A$, the Cartesian product.
Comment: Question, why would they use <<, <<< in the first place? and just letting you know it cant be a <= c since a in not equal to c?
Comment: I expect that they used those symbols partly to emphasize that these orders are not necessarily any orders that you've seen before and partly because they're easy to produce on a standard keyboard. And it **is** $a\le c$; clause (1) handles the case in which $a\ne c$, and clause (2) the case in which $a=c$, but both are allowed to occur. If you like, you can introduce $a<c$ as an abbreviation for '$a\le c$ and $a\ne c$', and similarly for $\prec$, but the partial orders $\le$ and $\preceq$ are clearly intended to allow the possibility of equality.
Answer: The order $\preceq$ on $A\times A$ is known as the lexicographic order induced by $\le$. $A\times A$ is the Cartesian product of $A$ with itself: $A\times A=\{\langle a,b\rangle:a,b\in A\}$. To show that $\preceq$ is a partial order on $A\times A$, you do indeed have to show that it's reflexive, transitive, and antisymmetric.

Reflexive: You must show that for every $\langle a,b\rangle\in A\times A$, $\langle a,b\rangle\preceq\langle a,b\rangle$. This is completely straightforward: just check the definition of $\preceq$.
Transitive: You must show that if $\langle a_0,b_0\rangle,\langle a_1,b_1\rangle,\langle a_2,b_2\rangle\in A\times A$, $\langle a_0,b_0\rangle\preceq\langle a_1,b_1\rangle$, and $\langle a_1,b_1\rangle\preceq\langle a_2,b_2\rangle$, then $\langle a_0,b_0\rangle\preceq\langle a_2,b_2\rangle$. Since the definition of $\preceq$ has two clauses, you'll have to consider several cases. I'll do one of them to get you started. Suppose that $\langle a_0,b_0\rangle\preceq\langle a_1,b_1\rangle$ because $a_0\le a_1$ and $a_0\ne a_1$. We know that $a_1\le a_2$ (why?), so $a_0\le a_2$ and $a_0\ne a_2$, and therefore $\langle a_0,b_0\rangle\preceq\langle a_2,b_2\rangle$, as desired.
Antisymmetry: You must show that if $\langle a_0,b_0\rangle,\langle a_1,b_1\rangle\in A\times A$, $\langle a_0,b_0\rangle\preceq\langle a_1,b_1\rangle$, and $\langle a_1,b_1\rangle\preceq\langle a_0,b_0\rangle$, then $\langle a_0,b_0\rangle=\langle a_1,b_1\rangle$. Here again I'll get you started. Suppose that $\langle a_0,b_0\rangle\preceq\langle a_1,b_1\rangle$ because $a_0\le a_1$ and $a_0\ne a_1$; then $a_1\not\le a_0$ (why?), and it is therefore impossible to have $\langle a_1,b_1\rangle\preceq\langle a_0,b_0\rangle$. Thus, we must have $a_0=a_1$ and $b_0\le b_1$. Now finish the argument by showing that $b_0=b_1$.
Comment: is the definition is either related or equal so since (a,b) = (a,b) it is reflexive since the condition is related or equal?
Comment: so a = a and b << b, so because << can be equal it would also hold that b<<b so therefor since a=a, b<<b we know that (a,b) <<< (a,b)
Comment: thats for reflexivity, is it correct?
Comment: to show that b0 = b1 do we try and make b<<b, so that then for that to be true it would have to be b = b, b<<b (reflexive)? @Brian M. Scott
Comment: We know that $a_1\le a_2$ (why?). Why do we know this, is it because we supposed it at the start, because the only way for it to be transitive is if it was related?
Comment: i have resigned myself to failure...
Comment: I am now sacrificing a goat in hopes my prayers will be answered...
Comment: is mathematics considered torture?
Comment: in desperation i believe i have figured it out, well lets just say i have written down something that i hope will prove to be extremely accurate
Comment: @Ghozt: It's a little hard to tell, but I think that you got the reflexivity more or less right: $a=a$, and $b\le b$ (since $b=b$), so by clause (2) $\langle a,b\rangle\preceq\langle a,b\rangle$. I can't make much sense out of your fourth comment. For the fifth, we didn't actually assume that $a_1\le a_2$: we assumed that $\langle a_1,b_1\rangle\preceq\langle a_2,b_2\rangle$. However, whether this is true by clause (1) or by clause (2) of the definition of $\preceq$, it implies that $a_1\le a_2$. We assumed (for that case) that $a_0<a_1$, so $a_0<a_1\le a_2$, and therefore $a_0<a_2$.


How can I fetch the complete main navigation menu via JSON:API?

Question: How can I fetch the complete main navigation menu via jsonapi?
I've tried:
curl --header 'Accept: application/vnd.api+json' https://cms.example.com/jsonapi/menu/menu/

and
 curl --header 'Accept: application/vnd.api+json' https://cms.example.com/jsonapi/menu/menu/232fc942-51f3-4478-8535-e5dc482a166e

where 232fc942-51f3-4478-8535-e5dc482a166e is the id of the main-navigation menu BUT only the first level nodes are returned:
{
  "data": {
    "type": "menu--menu",
    "id": "232fc942-51f3-4478-8535-e5dc482a166e",
    "attributes": {
      "label": "Main navigation"
    },
    "links": {
      "self": {
    "href": "https://cms.garanteasy.com/jsonapi/menu/menu/232fc942-51f3-4478-8535-e5dc482a166e"
      }
    }
  },
  "jsonapi": {
    "version": "1.0",
    "meta": {
      "links": {
    "self": {
      "href": "http://jsonapi.org/format/1.0/"
    }
      }
    }
  },
  "links": {
    "self": {
      "href": "https://cms.garanteasy.com/jsonapi/menu/menu/232fc942-51f3-4478-8535-e5dc482a166e"
    }
  }
}

Comment: It's confusing, but instead of looking for _menus_ you need to look for _menu_link_content_. g.rocchini posted in [issue #3012062, comment #6](https://www.drupal.org/project/jsonapi/issues/3012062#comment-12847525) a few days ago about this very thing. Unfortunately you need to filter on your own based on the menu name after getting _all_ of the menu link content.
Answer: I did not get it to run with JSON:API, there are several long-standing issues...
However you can get it to run if you additionally install the REST Menu Tree module.
Be aware that this has several direct and indirect dependencies:
It has a direct dependency on Menu Normalizer and according to this issue you need to then activate that endpoint for example with the REST UI module - which in turn will activate the core REST module.
Then in your site activate the endpoint via the Rest UI in /admin/config/services/rest.
Afterwards you might also want to allow everyone to GET this endpoint via /admin/people/permissions#module-rest
And finally you get a JSON array in /entity/menu/main/tree.
Or query a different menu via /entity/menu/{internal_menu_name}/tree.
Answer: It is possible to pull all the menu items using the JSON:API exclusively. The main "long standing issue" is that the links are not available to non admin users, which probably defeats the purpose for most users. There are a couple patches, however, that allow this:
https://www.drupal.org/project/drupal/issues/2915792
And to add the url property:
https://www.drupal.org/project/drupal/issues/3066751
This allows you to hit this endpoint:
/jsonapi/menu_link_content/your-menu-machine-name
And get a standard JSON:API result.

Key takeaway: The state of Drupal's headless menu fetching is abysmal.
Answer: There is also the rest_menu_items module. This doesn't have any dependencies, the only thing you need to do is enable the endpoint. This also enables you to specify which values you want, and specify the depth of the tree.


Which tones or sounds can be made with a cajon?

Question: When playing the cajon, I know that the sound of the snare can be obtained by hitting the upper left and right corners of the cajon using the fingers and moving the wrist only.
The sound of the bass is found by hitting about the middle of the cajon with the palms and moving the entire arm.

Is it possible to get other notes of the drum beside the ones mentioned above e.g. closed hi-hat, open hi-hat, ride cymbal or crash cymbal?
Answer: I used to play the cajon a lot with brushes, this way I could get a hi-hat, kick and snare sound. When hitting the snare and kick sounds while holding brushes you have to hit with the stick part of the brush to get a fuller sound especially when playing without mic. And the hi-hat sound comes natural from the brushes hitting the box.
Without brushes I find it harder, I've seen people screw one of the top corner sides loose so that you get a different snare sound on one side, more like a rimshot, I have used this but never really stuck with. It also really depends on the string inside the box how this will work out for you, might just have to try it.
Another thing you can do with the sound is put one foot against the front and push against the box and slowly release pressure, this pitches the sound of the entire cajon, would experiment with this to see how it feels / works for you personally.
That being said, the cajon has its roots with people who had to invent instruments which they could disguise cause they were not allowed to play music. I would imagine it took them quite some experimenting and creativity to find/create this instrument. Don't think there is a right or wrong way with a cajon if it sounds good.
Answer: You've nailed down the two features a cajon has - snare and kick. Those are what the cajon is built for, and out of the box (...) it's not going to do anything else specifically.
Of course, feel free to experiment on them by tapping edges, using brushes etc to get different sounds, but they are built to do a kick and snare. You're not going to get crash or rides out of it. After all, they are just wooden boxes with various things inside them to produce the effect of a snare drum.
Comment: Adam Neely had a Q&A video in which he responded to a flammy hate comment from a viewer of his accusing a drummer in one of his videos of cultural appropriation for playing the cajon in terms of only kick and snare...
Answer: I have been working the cajon for the past 10 years or so on gigs from jazz to flamenco. The use of the Vater Blue Brushes are very effective in creative performance. Add the foot Afrushe-cabasa on one free foot, a bass foot pedal on the other and hand held castanets for Kata Palo Ceco patterns on the cajon's rim and see what happens.
Comment: Welcome to the site! Those are great ideas for adding to the cajon's characteristic sounds. Please check out the site's [tour page](http://music.stackexchange.com/tour) and have a look around! I added a link to the brushes, if you know of places to pick up some of the other instruments, that would be super helpful!
Comment: Study the drumming of Santeria as a Homefront nucleus to the cajon drum, basics baby. Look for Pancho Quinto, Patato, Los Papines, Tata Guines, Chango, Obatala, The Bata patterns in order to expand on the vocabulary of performing on the Cajon.


A question about the projection function

Question: Let $p:A\times B\to. A$
$p(x,y)=x$
The projection function $p$ is clearly subjective. I want to know if it is bijective? The projective function suspiciously looks like $1_A(x)=x$
Comment: I corrected my mistake. It should be A
Answer: If $|A|>1$ then we have two $a\ne a'$.
Since $p(a,x) = p(a',x)=x$ we see it is not injective and so it is...?
Comment: It is not bijective and can't be an isomorphism .If it was I could use it in a theorem


Suppose $p$ is a prime. Show that every element of $GL_2(F_p)$ has order dividing either $p^2 — 1$ or $p(p — 1)$

Question: Suppose $p$ is a prime. Show that every element of $GL_2(F_p)$ has order dividing either $p^2 — 1$ or $p(p — 1)$.
My thoughts - Can assume that an element of $GL_2(F_p)$ has one of the canonical forms:

Different roots so two jordan blocks.
Repeated Root with either one or two jordan blocks.

Where can I go from there? Not sure what I can say about the order of the matrices.
Comment: Fermat's little theorem should help in the case where the matrix is diagonalizable. Try figuring out how to express a general power of the JCF in the other case.
Comment: $p(p-1)$ looks like the order of $\scriptstyle a\begin{pmatrix} 1 & b \\ 0 & 1 \end{pmatrix}$ and $p^2-1$ as the order of $\scriptstyle \begin{pmatrix} a & b \\ -bc & a \end{pmatrix} = a+b \sqrt{c}$
Comment: It cannot be a coincidence that the order of the group is $(p^2-1)(p^2-p)$.
Answer: If the characteristic polynomial has roots in $F_p$, then you are in one of the situations described.
If $J =\begin{bmatrix} a & 0 \\
0 & b \end{bmatrix}$ then $J^{p-1}=\begin{bmatrix} a^{p-1} & 0 \\
0 & b^{p-1} \end{bmatrix}=I_2$.
If $J=\begin{bmatrix} a & 1 \\
0 & a \end{bmatrix}$ prove that $J^p$ is diagonal, and hence $J^{p(p-1)}=I_2$.
The other situation is if the characteristic polynomial doesn't have roots in $F_p$. Since the characteristic polynomial is quadratic, there exists an extension $F_p \hookrightarrow K$ of degree 2 where the characteristic polynomial has a root, and hence two roots.
Show that the two roots are different (hint: derivative) and hence, in this algebraic extension the Jordan form is
$$$J =\begin{bmatrix} \alpha & 0 \\
0 & \beta \end{bmatrix} \Rightarrow \\J^{p^2-1}=\begin{bmatrix} \alpha^{p^2-1} & 0 \\
0 & \beta^{p^2-1} \end{bmatrix}=I_2 \,.$$
Comment: Awesome answer! Thanks.
Comment: @tastykakes When you prove that the roots in the extension are distinct, pay extra attention to the case $p=2$ ;) 2 is often really annoying.
Comment: If the roots are not in $F_p$ then $F_p[J] = F_{p^2}$. I wonder about the case $GL_n$
Comment: @reuns The $GL_n$ case is trickier. For once, the splitting field of the characteristic polynomial can have degree up to $n!$, where $\deg(P)=n$. Also, the situation is complicated more by the fact that the characteristic polynomial could have roots of higher multiplicity in the splitting field.


$\lim_{x \rightarrow 0^+} e^{-1/x}/x^3$

Question: Sorry for asking a possibly silly question. I was evaluating a limit, and in the end, it boiled down to showing that $\lim_{x \rightarrow 0^+} e^{-1/x}/x^3=0$.
All WolframAlpha says is

Hint: as $x\rightarrow0$, $e^{-1/x}/x^3$ approaches $0$,

which makes me worry that I'm either missing something simple, or that the limit is harder to prove than it seems.
Using l'Hôpital's rule increases the degree of the denominator, which doesn't seem very useful. I also found it difficult to group terms for an epsilon-delta proof. I additionally thought about squeezing it between $0$ and $x$, but I could not find a way to show that $$e^{-1/x}<x^4,$$
so that route also felt like a dead end.
How can this limit be found or proven?
Answer: Note that:$$\lim_{x\to0^+}\frac{e^{-1/x}}{x^3}=\lim_{x\to+\infty}\frac{e^{-x}}{\left(\frac1x\right)^3}=\lim_{x\to+\infty}\frac{x^3}{e^x}.$$Can you take it from here?
Answer: By Taylor formula, we know that $e^{u}>u^{4}$ for large $u>0$, then for $x>0$ small, $1/x>0$ is large, then $e^{-1/x}<x^{4}$, so $e^{-1/x}/x^{3}<x$ now use Squeeze Theorem to conclude that $\lim_{x\rightarrow 0^{+}}e^{-1/x}/x^{3}=0$.
Answer: Let $x\gt 0:$
$e^{1/x} =$
$1+ 1/x+(1/2!)(1/x)^2 +(1/3!)(1/x)^3 + (1/4!)(1/x)^4...\gt (1/4!)(1/x)^4$
implies:
$\dfrac{e^{-1/x}}{x^3} = \dfrac{1}{(e^{1/x})x^3} \lt$
$\dfrac {1}{(1/4!)(1/x)} =(4!)x$
Limit $x \rightarrow 0^+$ is?
Comment: That's fine Peter!
Comment: Thanks, not so difficult:))How are you doing?
Comment: I wish I could give you an upvote right now. This is really nice, thank you!
Comment: Thanks , blue.Not so very difficult:))

$\lim_{x \rightarrow 0^+} e^{-1/x}/x^3$


If $S=\{\frac{1}{n},\frac{2}{n},\cdots,\frac{n-1}{n}\},T=\{\frac{1}{n+1},\frac{2}{n+1},\cdots,\frac{n}{n+1}\}$then$t_1<s_1<t_2<s_2<\cdots$

Question: If ordered sets $S=\{\frac{1}{n},\frac{2}{n},\frac{3}{n},\cdots,\frac{n-1}{n}\},T=\{\frac{1}{n+1},\frac{2}{n+1},\frac{3}{n+1},\cdots,\frac{n}{n+1}\}$ then $t_1<s_1<t_2<s_2<\cdots$
I cant even see how to apply induction for this, besides showing it is rue for some specific cases up 7 that lead me to believe it should be true in general.
No, this is not home work, it popped into my head, but if there is a text book example somewhere then I take it.
Also I am interested in knowing what type of inequality does this fall under, and want to see some examples.
Answer: What you want to show is that for all $n$ and for $k$ from $1$ to $n-1$ there is an inequality
$$\frac{k}{n+1} <\frac{k}{n} <\frac{k+1}{n+1}$$
The first inequality is not hard to see. Since $n < n+1$ we have $1/(n+1) < 1/n$, and multiplying by $k$ on both sides gives
$$\frac{k}{n+1} <\frac{k}{n}$$
To check the second inequality we can try to cross multiply. It amounts to showing that
$$ k(n+1) \leq n(k+1)$$
We can understand this by factoring things out and noting that $k < n$.
$$k(n+1) = kn + k < kn + n = n(k+1)$$


Asked in interview round

Question: Consider an undirected tree with N nodes, numbered from 1 to N. Each node has a label associated with it, which is an integer value. Different nodes can have the same label. Also, given a zero-indexed vector A of length N, where A[j] is the label value of the (j+1)-th node in the tree and a zero-indexed E of length K = (N-1) in which the edges of the tree are described (vector<pair<int,int>>E where E[i]={u,v} if there is edge between u and v ,0<=i<k). Find the number of  special path .
Special Path  follow following condition-

starting node and end node of path path have same label but starting node should not equal to end node.
All node present in path have label value<=label value of starting node.
path length should greater than 1.The length is the number of nodes in that path.

N = 5
A= {1, 1, 1, 2, 2}
E= {{1, 2},{ 1, 3}, {2, 4}, {2, 5}}
Output:
4
Explanation:
4->2->5 , 2->1 , 2->1->3 , 1->3
Constraints:
1≤N≤10^5, 1≤E≤N , 1≤A[i] ≤ 10^8
Answer: By the constraints given, it looks like the interviewer is expecting an O(N2) answer, but you can actually do this in O(N log N) time using a disjoint set data structure:
First, sort the vertices by label, then initialize an empty disjoint set structure, and set an accumulator total=0.
Then, for each label L:

Initialize a singleton set for each vertex with label L, and merge it with all adjacent vertices that have smaller or equal labels.
Each root set will then represent a connected component of the subgraph with labels <= L.  Since the graph is a tree, so are these connected components, and there will be exactly one (simple) path between each pair of vertices in each one.  For each root set, let nL be the number of vertices with label L that it contains, and if it's non-zero, then total += nL * (nL-1) / 2, i.e., the number of pairs with both labels equal to L.

Asked in interview round


Using path aliases how to identify node IDs from database and based on these IDs how to publish them?

Question: I have a content type called article. For this content type, I unchecked the "Published" checkbox under the publishing options tab.
I have 30000 nodes I changed to unpublished. Among those, I want to publish 900 records. I have the node URLs.
Using the path aliases, how to get the node IDs? Once I have the node IDs, how can I publish those nodes?
Answer: You can use drupal_get_normal_path() to get the node/id-paths for each of them.
Then you can use the following code to publish them.
// Load the node object.
$node = node_load($nid);
// Set the status property to 1.
$node->status = 1;
// Re-save the node.
node_save($node);

Comment: How to save status change only? If we give node_save($node) then all the changes get saved. I want status change only get saved.
Comment: not sure I get the question, you only change the status value here, so that the one that's changed in the new saved object right?
Answer: If you have the path alias, you can easily get the normal path and then the node object with two single functions. I assume you have the path alias available in the $path_alias variable.
$path = drupal_get_normal_path($path_alias);
$node = menu_get_object('node', 1, $path);

Once you have the node object, you just set $node->status to NODE_PUBLISHED, and save the node. So the full code becomes the following.
$path = drupal_get_normal_path($path_alias);
if ($node = menu_get_object('node', 1, $path)) {
  $node->status = NODE_PUBLISHED;
  node_save($node);
}

I am not sure how much safe it's assuming the path aliases are for nodes, but just to be sure, and avoid trying to load a node when Drupal didn't find any normal path matching the path alias, I would use the following code.
$path = drupal_get_normal_path($path_alias);
if (strpos($path, 'node/') === 0 && ($node = menu_get_object('node', 1, $path))) {
  $node->status = NODE_PUBLISHED;
  node_save($node);
}

Notice that === is necessary, since strpos() can either return 0 to mean the path starts with 'node/', or FALSE to mean 'node/' was not found in the path. (In PHP 0 == FALSE is TRUE.)


A question related to continuity and compositions

Question: Eric claims in this answer that, for $X$ and $Y$ topological spaces, then the following are equivalent

If for all continuous maps $c:\mathbb R \to X$, $f \circ c$ is continuous then $f:X \to Y$ is continuous
A subset of $X$ is closed iff its preimage under every continuous map $c: \mathbb R \to X$ is closed.

I can see how (2) implies (1), but not the converse. What am I missing?
Comment: I believe (1) should quantify over $Y$. Hint: let $Y$ be $X$ with the topology that $U$ is open in $Y$ iff for all continuous maps $c : \mathbb{R} \to X$, we have $c^{-1}(U)$ is open. Show that $Y$ and $X$ have the same topology.
Answer: Here is a proof of $(1) \Rightarrow (2)$.
We have to show that $A \subset X$ is closed if for each continuous $c : \mathbb R \to X$ the preimage $c^{-1}(A)$ is closed in $\mathbb R$.
So let $A \subset X$ be a subset such that for each continuous $c : \mathbb R \to X$ the preimage $c^{-1}(A)$ is closed in $\mathbb R$.
$\{ \emptyset, X, X \setminus A \}$ is a topology on the set $X$; call the resulting space $Y$. Its closed sets are $\emptyset, X,  A$.  Now consider the identity function $f : X \to Y, f(x) = x$. We have $f^{-1}(A) = A$.
We shall show that $f$ is continuous which implies that $A$ is closed in $X$.
Let $c : \mathbb R \to X$ be continuous. We have $(f \circ c)^{-1}(A) = c^{-1}(f^{-1}(A)) = c^{-1}(A)$ which is closed in $\mathbb R$ by assumption. Since $(f \circ c)^{-1}(\emptyset) = \emptyset$ and $(f \circ c)^{-1}(Y) = \mathbb R$, the function $f \circ c$ is continuous. It follows from $(1)$ that $f$ is continuous.


Unable to display URL in WebView from another view controller

Question: I have a UITableViewController that needs to open a web view.
In my function I have:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

                LinkViewController *linkViewController = [[LinkViewController alloc] initWithNibName:@"LinkViewController_iPhone" bundle:nil];

                [linkViewController.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];

                [self.navigationController pushViewController:linkViewController animated:YES];

}

I have connected all outlets and am not getting any warnings however I do not see the page pull up.
However if I go in the actual LinkViewController file and do something like:
- (void)viewDidLoad
{
    [super viewDidLoad];

        NSString *urlAddress = @"http://www.google.com";

    //Create a URL object.
    NSURL *url = [NSURL URLWithString:urlAddress];

    //URL Requst Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    //Load the request in the UIWebView.
    [self.webView loadRequest:requestObj];
}

everything seems fine. I do not understand why ?
Answer: You should add a URL property to your LinkViewController. Then in your table view controller you do this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    LinkViewController *linkViewController = [[LinkViewController alloc] initWithNibName:@"LinkViewController_iPhone" bundle:nil];
    linkViewController.URL = [NSURL URLWithString:@"http://www.google.com"];

    [self.navigationController pushViewController:linkViewController animated:YES];
}

Now in your LinkViewController you do:
- (void)viewDidLoad {
    [super viewDidLoad];

    //URL Requst Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:self.URL];

    //Load the request in the UIWebView.
    [self.webView loadRequest:requestObj];
}

There are two problems with what you had originally:

In the table view controller, you were accessing the webView property before it was initialized. This is why nothing happened.
You were exposing far too much implementation detail of the LinkViewController to the outside world. If you use LinkViewController in many places in your app, you are requiring every user of the class to know to create a URL, create a request, and then tell the internal web view to start loading. All of that logic belongs inside the LinkViewController. Now each user of the class only needs to know to set a simple URL property.
Comment: one of the most detailed answers. Your approach worked. Thanks much


Symfony and Doctrine: order by time difference

Question: I am trying to build a query that retrieves all the most recent and upcoming activities from database.
The entity activity has a field named date of type DateTime. So in my repository I was thinking of building something like this:
$query = $repository
          ->createQueryBuilder('a');
$query->orderBy( 'DATEDIFF( a.date, NOW())' , 'ASC');
$query->setMaxResults( 6 );
return $query;

Unfortunately I get the following error:
[Syntax Error] line 0, col 59: Error: Expected end of string, got '('

The Dql that is generated by my query:
SELECT a FROM MyBundle\Entity\Activity a ORDER BY DATEDIFF( a.date, NOW()) ASC

I also tried installing beberlei/DoctrineExtensions, but either it is not working or I was unable to configure it correctly.
Anyone has any suggestion?
Thanks in advance
Answer: Why don't you just use
$query = $repository
          ->createQueryBuilder('a');
$query->orderBy( 'DATEDIFF( a.date, CURRENT_TIMESTAMP())' , 'ASC');
$query->setMaxResults( 6 );
return $query;

?
Comment: Because I was hoping to get both recent (i.e. date < now) and upcoming (i.e. date > now) at once. Getting the absolute time difference with respect to current date would do it. On the other hand, your solution just order them chronologically.
Comment: Edited my answer above, it should work. But if I got your use case correct, you would probably need even an ABS function like http://stackoverflow.com/questions/7532886/doctrine-2-query-builder-abs-function
Answer: date_diff si already implemented as Doctrine DQL statement as described here
for use as ordering statement I suggest you to use the HIDDEN select keyword as explained in this article
So your DQL is like this:
SELECT
    a,
    DATE_DIFF( a.date, CURRENT_TIMESTAMP() ) AS HIDDEN score
FROM MyBundle:Entity a
ORDER BY score

And add the max result on the query. Let me know if you need help to adapt as query builder statement
Hope this help
Comment: Thanks, this is working. I added an abs to get both positive and negative values, and used the following query builder statement: `$query = $repository->createQueryBuilder('a'); $query->addselect('ABS( DATE_DIFF( a.date, CURRENT_TIMESTAMP() ) ) AS HIDDEN score');$query->orderBy( 'score' , 'ASC');`
Comment: HI @Alberto you are welcome! Feel free to edit my answer with your final solution


Conclude that $\frac{1}N\sum_{n=1}^{N}X_n\to 0$ almost surely (without using strong law of large numbers)

Question: Given a sequence of IID random variables with expectation zero and finite variance, $X_1,X_2,...$

Prove that $S_N=\sum_{n=1}^{N}\frac{X_n}{n}$ is a martingale, and
  conclude that $\frac{1}N\sum_{n=1}^{N}X_n\to 0$ almost surely using
  this exercise

So for showing that $\sum_{n=1}^{N}\frac{X_n}{n}$ is a martingale I think I got it right:
$E[S_{N}|S_1,...,S_{N-1}]=E[\frac{X_N}{N}+S_{N-1}|S_1,...,S_{N-1}]=E[\frac{X_N}{N}|S_1,...,S_{N-1}]+E[S_{N-1}|S_1,...,S_{N-1}]=\frac{1}{N}E[X_N]+S_{N-1}=0+S_{N-1}=S_{N-1}$
For the second part  though I'm not sure, can anyone help me?
Answer: The result follows immediately by the strong law of large numbers. The law states that for a sequence of iid random variables with finite mean,
\begin{align*}
P(\lim_n \bar{X}_n = EX) = 1
\end{align*}
i.e. the empirical mean $\frac{1}{N} \sum_{i=1}^N X_i$ converges almost surely to $EX=0$.
To show it using the linked exercise, we invoke the Martingale Convergence Theorem on $\{S_n\}$ so that $S_N = \sum_{n=1}^N \frac{X_n}{n}$ converges. Then by the linked exercise, the empirical average converges to 0.
To show the sufficient condition for MCT, namely that $\sup_N E|S_N| < \infty$, observe that
\begin{align*}
Var|S_N| &= Var\Big|\sum_{n=1}^N \frac{X_n}{n} \Big| \\
&\leq \sum_{n=1}^N \frac{1}{n^2}Var|X_n| \\
&= Var|X_1| \sum_{n=1}^{N} \frac{1}{n^2} < \infty
\end{align*}
by assumption. Since $Var|S_N| = E(S_N^2) - (ES_N)^2 = E(S_N^2) - 0 = E(S_N^2)$, we have that the measurable function $S_N$ is in $L^2$. Since the probability measure is finite, $S_N$ is also an element of $L^1$. Thus, $E|S_N| < \infty$.
Comment: I know it follows from the law of large numbers, but I need to prove it using the exercise I linked, do you know how?
Comment: use MCT. see my edit
Comment: I see, though checking the conditions for the MCT, it says that $supE(|S_N|)$ must be bounded, is it because of the finite variance?
Comment: well $E(S_N) = \sum_1^N E(X_i / i) = 0$, so it follows by the mean of $X$ being 0.
Comment: I'm sorry, the condition has the $S_N$ in absolute value so I'm not sure it works, unless the definition for the MCT is different from what I see
Comment: oops! sorry, yeah it follows by finite variance, and the fact that the series $\sum_1^{\infty} \frac{1}{n^2}$ converges. see my edit


Butcher tableau in Runge Kutta methods

Question: I'm studying RK methods using Butcher tableau.
I do not understand what this means. Can anyone explain what is the notation?
RK Butcher tableau matrix
It seems like matrices multiplication but MM does not look like that.
Thanks in advance.
Answer: It is just a scheme to hold the parameters of the method, just as a general matrix is a scheme to hold the coefficients of a linear map.
\begin{array}{c|ccc}
\color{red}{c_1}&\color{green}{a_{11}}&\cdots&\color{green}{a_{1s}} \\
\vdots&\vdots&&\vdots\\
\color{red}{c_s}&\color{green}{a_{s1}}&\cdots&\color{green}{a_{ss}} \\
\hline
&\color{blue}{b_1}&\cdots&\color{blue}{b_s}
\end{array}
If you have seen a general Runge-Kutta method, you should have seen these parameters applied in their correct place,
\begin{alignat}{1}
\vec k_i&=\vec f\bigl(t+\color{red}{c_i}h, &\vec y&+\sum_{j=1}^s \color{green}{a_{ij}}\vec k_jh\bigr),~~~
i=1,...,s,\\
\vec y_{+1}&=&\vec y&+\sum_{i=1}^s \color{blue}{b_i}\vec k_ih
\end{alignat}
So in some sense there is some kind of matrix-vector multiplication done with the coefficients $a_{ij}$.

Butcher tableau in Runge Kutta methods


24 averages for values in array based on what hour they are in

Question: I have a record that holds one DateTime array and 2 double arrays all of the same length and related by index.
I want to get the average of the delta between the 2 double arrays based the hour of the DateTime. So I'll have 24 averages in the end. All data in index 0 of the arrays are related / happen at the same time, and so on for all the indexes. Perhaps I should instead have 1 array of tuples or records that each holds just one datetime, and 2 doubles.
But anyway this is what I have so far:
let data2 = [ for i in 0..data.Date.Length-1 do
                                    yield data.Date.[i].Hour, data.High.[i] - data.Low.[i]]

And here is where my inexperience hurts the most. The only thing I can think of is to do some kind of matching or if statements that go through all of those 24 hours (0 - 23) and having individual mutable values for each hour. There must be an easier way. I've been unsuccessful so far in finding a way.
Answer: I think you want to do
let grouped = data2 |> Seq.GroupBy (fst) |> Seq.map (fun (a,b) -> Seq.average (b |> Seq.map (snd)))

Here Seq.groupBy will group all the elements which have an identical first element.  You can then take the average with Seq.average.
Note:
I think your original expression for data2 would be better written as
data.Date |> Array.mapi (fun i t -> t.Hour,data.High.[i]-data.Low.[i])

Comment: Thanks for the answer. This is definitely close to correct however I get the error "Expecting a type supporting the operator '+' but given a tuple type" -- This error points to the last b after Seq.average
Comment: Because b has type int * double, so I need to go into that and average the second value it appears. I'll see if I can't figure it out and then report here.
Comment: Sorry for the endless comments. Its weird how groupBy doesn't remove the original hours and represents them all just once. Instead it represents them twice each: (hour, [(hour, value); (hour, value) ]). That is nasty. Surely we need only one hour value for each, and then an array of values. I'll see if I can't get some practice by re implementing this function.


How to hide file extension using .htaccess + Restricting access

Question: Guys how to remove a file extension using .htaccess.
example :
file name was "/home.php"
of course after using .htaccess
it can now access using link "/home"
it is possibly to redirect using into 404 error if they visit "/home.php" instead of "/home"
Thanks!
Answer: You can just use Multiviews:
Options +Multiviews
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+([^\?\ ]+)\.php
RewriteRule ^ /%1 [L,R=301]

This redirects /home.php to /home, but you can replace the 301 in the square brackets with 404 if you insist on returning a "not found".
Comment: I put 404 in [L,R=404] but its shows error:    500 Internal Server Error when trying to use ErrorDocument to handle request
Comment: @LuisEdwardMiranda Don't think you can't use errordocument 404 with R=404.
Answer: This snippet will rewrite *.php to *
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Answer: You can use this rewrite rule in your .htaccess to remove the php extension
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Regards,
Source: http://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/


The method getText() is undefined for the type EditText -- How?

Question: Yes, I'm totally new to this platform, but getText() IS a method of EditText, is it not?
I just copied and pasted the exact error from my simple app, which I copied word-for-word from a web tutorial.  I believe it's self-explanatory.  It's an error that might only come up if there was a misspelling.  Below is the context.  Error is on the 3rd line down.
public void sendMessage (View view) {
    Intent intent = new Intent(this, DisplayMessageActivity.class);
    EditText editText = (EditText) findViewById(R.id.edit_message);
    String message = editText.getText().toString();
    intent.putExtra(EXTRA_MESSAGE, message);
    startActivity(intent);
}

Would there be ANY circumstance where getText() would NOT be considered a method of EditText?
Comment: Try cleaning your project. (Go to **Project** -> **Clean...**)
Comment: That is weird. Funny, I saw something like this before and it turned out the guy had defined a class with the same name as the object he was tying to use from a library. Unlikely to be the issue here I know but thought I'd mention it. Strange that the compiler knows about the type EditText but not its getText() method.
Comment: @Ruairi I was just writing this as an answer. :)
Comment: Thanks Sam...I wish that was it.  I tried that, closed and opened Eclipse a couple of times, no change.  I'll look into Ruairi's suggestion now.
Comment: Double check your imports, do you have `import android.widget.EditText;`?
Comment: Didn't have that.  Added that.  Same error.  Also, didn't see any other occurrences of EditText except as... public class MainActivity extends Activity { blah blah -- which Eclipse seemed have generate for me.
Comment: Great website and great denizens here. I'll try not to abuse it by being too much of a n00b in the future.  :)
Answer:
Would there be ANY circumstance where getText() would NOT be considered a method of EditText?

No, getText() is a method in every version of android.widget.EditText. Unless you have created another class with the name EditText, this error is probably Eclipse being confused. Simply clean your project by going to Project -> Clean...

Addition
By subtyping MainActivity with EditText, you are inadvertently creating a new, local class named EditText which obscures Android's EditText class... In general, Activities do not need subtypes. So change this line:
public class MainActivity<EditText> extends Activity {

To:
public class MainActivity extends Activity {

Comment: While the problem still exists, I truly believe that this answer is 100% correct and accurate, and that I need to go back to square one and redo it (it's a very small app) carefully.
Comment: The advice to clean your Eclipse is useful advice, though.  I have seen Eclipse get confused, and just cleaning it un-confused Eclipse.
Comment: BINGO!  Yep, that MainActivity, which oddly enough was generated by Eclipse without my help, was the culprit!  Thanks!


What note would be used to fit 4 notes in a 5/8 time signature

Question: What note represents 1.25 beats. Or in other words 4 notes in 5/8 time.
Answer: There is no individual symbol representing 1.25 beats. To do it in 5/8 time, one would either use:

eighth note (1 beat) tied to a 32nd note (.25 beats)
a sixteenth (.5 beats) tied to a dotted sixteenth (.75 beats) (or vice versa)
a four-tuplet

The first solution is better for a single note; the second might be easier for a reader uncomfortable with tuplets; but the last solution works better for the title problem of four equal divisions of five beats.
Comment: There's also another option: it's still a bit obscure, but it keeps a consistent reference of the pulse and it's also the commonly accepted simplification (and explanation) of the actual "subdivision": https://i.stack.imgur.com/z258B.png


Laravel auth emails localisation

Question: Laravel uses Illuminate\Auth\Notifications\ResetPassword class to send password reset email. The message is written in english. How do I translate it into another language. Publishing vendor files doesn't copy this class. I can't edit it since it is in vendor files and is not in the vcs repository.
Answer: The email notification is sent from CanResetPassword trait, you need to override the method responsible for this and provide your own notification class.
User extends Authenticatable
{
    // ...
    public function sendPasswordResetNotification($token)
    {
        $this->notify(new MyResetPasswordNotification($token));
    }
    // ...
}

And create the notification:
MyResetPasswordNotification extends Notification
{
    public $token;

    public function __construct($token)
    {
        $this->token = $token;
    }

    public function via($notifiable)
    {
        return ['mail'];
    }

    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->line(trans('reset_password.first_line'))
            ->action(trans('reset_password.action', ['route' => route('password.reset', $this->token)))
            ->line(trans('reset_password.last_line');
    }
}

Now you just need to provide the translations.

Laravel auth emails localisation


Drupal Development : Should I use the built in content type or create my own content type?

Question: I want to create an online Arabic-Hebrew Dictionary for one of my clients and this is my first experience in Drupal Module Development. If I were to create the Dictionary in custom PHP and MySQL, I would create a number of database tables and do my queries accordingly.
I know that there is a built-in content type in Drupal 7, should I use it or create my own content type, If I should create my own content type, how can I do it ?
Thanks!
Answer: The built in content type will give you a Title and a Body, you can also use taxonomies in order to get more specific queries.
Creating your own content type will depend on your site structure. If the above is sufficient, simply use  or modify the built in content types, otherwise create your own.
My advice would be for you to experiment with Drupal, watch various tutorials, then decide on the structure that would be best fit your requirements.
Your question is very vague, there are a lot of resources out there for Drupal beginners, you'll get a more detailed answer by checking tutorials first.
Comment: You didn't get me right ..... In other words, If you were to create a dictionary in Drupal which has a custom search on the words/verbs , would you begin by adding a new content type from "#overlay=admin/structure/types/add" and benefit from the built in content type system and then query the content type from a module, or creating the content type (Entity) in your module.
Answer: I believe that it depends. It generally is better to build upon the existing content types as much as you can. But if you determine that it would be too awkward/inconvenient to build upon the pre-existing content types in order to get the best solution to your problem, then you should programmatically create your own content type in your module.
Whichever path you choose, make sure that you properly document your content type structure, so that whenever you or someone else has to use that module, they will know exactly what each field is being used for, any dependencies, etc.


N-Knights - JAVA

Question: I tried to write N-Knight's problem, but failed.
Could you guide me on this, please go through my below coding(8-by-8 two-dimensional array),
I am not sure whether my coding is matching to  - The Knight can move in the shape of the letter, 'L', over two in one direction and then over one in a perpendicular direction.
And, how to - If the Knight rests at the square marked X ?
package knightstour;
import java.util.*;

public class KnightsTour
{
    private static int board[][] = new int[8][8];
    private static int stepCounter = 1;

    public KnightsTour() {
        initBoard(board);
        tour(0,0);
        printSol(board);
    }

    public static void printSol(int[][] a) {
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j 9) {
                    System.out.print(a[i][j] + "  ");
                } else {
                    System.out.print(a[i][j] + "   ");
                }
            }
            System.out.println();
        }
        System.out.println();
    }

    public static void initBoard(int[][] a) {
        for (int i = 0; i < a.length; i++)
        {
            for (int j = 0; j < a[i].length; j++)
            {
                a[i][j] = -1;
            }
        }
    }

    public void tour(int x, int y) {
        if (((x < 0) || (x >= 8) || (y < 0) || (y >= 8)) || (board[x][y] != -1)) {
            return;
        }
        else {
            board[x][y] = stepCounter++;
            tour(x+2, y+1);
            tour(x+1, y-2);
            tour(x+1, y+2);
            tour(x-1, y+2);
            tour(x-2, y-1);
            tour(x-2, y+1);
            tour(x-1, y-2);
            tour(x+2, y-1);
        }
    }

    public boolean spaceAvailable(int X, int Y) {
    }

    public static void main(String[] args) {
        new KnightsTour();
    }
}

Comment: I'm not sure what you're question is (I have no clue what the N-Knights problem is). Can you describe what you're trying to do and what the N-Knights problem is? And then can you describe instead what your code is doing. It would help us answer if we knew what you wanted to do and what instead was happening (how is what your code is doing different from what you want it to do)
Comment: My understanding is that the N knights problem is to find a way to place N knights on a chessboard, so that no knight is attacking any other knight.  A knight's tour is a path in which a single knight visits every square on the board.  These two concepts are entirely unrelated, so it doesn't make sense to me to have code that talks about knight's tours in a solution to the N knights problem.
Comment: Hi Dawood, I am new in Java. I try to write my coding to fulfil the below requirements, but failed. - The Knights must visits the maximum number of board positions without attacking each other. The Knight can move in the shape of the letter, 'L', over two in one direction and then over one in a perpendicular direction.
If the Knight rests at the square marked X.
Answer: Assuming your code is starting at 0,0 and trying to see the minimum number of steps it takes to visit every other space in your board while only moving like a Knight does in Chess then your code actually looks fine logic-wise.
Your issue seems to be board[x][y] = stepCounter++;
stepCounter++ is actually a shortcut for writing stepCounter = stepCounter + 1. So that doesn't really make any sense.. stepCounter++ isn't an assignable value, its a command to do something.
It would be like writing board[x][y] = (stepCounter = stepCounter + 1);
Try executing that command first, THEN assigning the value.
public void tour(int x, int y)  {
    if (((x < 0) || (x >= 8) || (y < 0) || (y >= 8)) || (board[x][y] != -1)) {
        return;
    } else {
        stepCounter++;
        board[x][y] = stepCounter;
        tour(x+2, y+1);
        tour(x+1, y-2);
        tour(x+1, y+2);
        tour(x-1, y+2);
        tour(x-2, y-1);
        tour(x-2, y+1);
        tour(x-1, y-2);
        tour(x+2, y-1);
    }
}

Comment: Hi Gadu, Could you help me on below ?
Comment: The N-Knight's problem must attempts to move around the chess board so that the Knights must visits the maximum number of board positions without attacking each other. The Knight can move in the shape of the letter, 'L', over two in one direction and then over one in a perpendicular direction.
And if the Knight rests at the square marked X.
Comment: Can you use my coding to further develop or ? Thanks.

N-Knights - JAVA


Could the home field advantage in baseball be due to the "principle of last action?"

Question: It has been observed that in baseball, a home team has a statistical 54-46 advantage, all other things being equal. There have been various theories to account for this, including the impact of fan support, and possible "home team" bias by umpires.
But there may be a more tangible home team advantage called the "principle of last action." This advantage derives from the fact that the home team bats and score last in every inning, and in the game itself.
In poker, there is a large advantage to being last, and seeing what other people have done. For instance, if you are "last" with a mediocre hand, and have observed other people betting timidly (or not at all), you might bet to steal the pot. If others have "raised" each others' bets, you might "fold" and let the stronger hands fight it out. If you were first to go with the same, mediocre hand, you would have to bet (or not) without knowing what others wanted to do.
Beginning in the ninth, and all the extra innings, if the home team ever takes the lead, the visiting team will not have a "return" opportunity in a subsequent inning. The home team can win in a one-run "walk-off," while the visiting team will have to score as many runs as they can in the top of the ninth, and hope that they are "enough."
Say the game is tied at the end of the eigth inning, and the visiting team scores x runs in the TOP of the ninth. The home team knows that it needs to score exactly X runs to tie, and x+1 runs to win. It can manage it "bench" in the bottom of the ninth for maximum effect. On the other hand, if the visiting team has a one run lead in the top of the ninth, it must wonder, is that enough? Can we save the bench for tomorrow, or do we need to "pile on," now? Likewise, the visiting team has to make a decision in the bottom of the ninth whether to use as many pitchers as it takes to stop the tying run, or save relievers for an extra inning game.
Other sports such as football and basketball don't have such a clear separation of offensive and defensive "rounds." (In those sports, unlike baseball, it is possible for a defender to "run back" the ball for a touchdown or basket.) Could this separation of offense and defense be what lends a home field advantage in baseball?
Comment: I'm sure it contributes. But so does fan support, better knowledge of field conditions, the shaping of the team to the stadium, and the advantage of being in your own house rather than travelling.
Comment: @Oldcat Freakonomics even goes so far as to say that referees and umpires call games more favorably for the home teams. That's potentially a far bigger factor
Answer: Yes. Homefield advantage does play a role late in close games. Though my brief analysis indicates that it doesn't account for all of the record disparity.
Fangraphs has a great model that predicts, based on game state, how likely a given team is to win at any given moment in the game based on historical data.
Let's look at a recent 0-0 game that went all the way into the bottom of the 10th and was won in a walkoff. Cubs vs Pirates, opening day.
We can see in this game, that starting in the first inning, the home team had about a 4 percentage point better odds in the middle of the inning then they did at the beginning of it. This increased as the game continued until the 9th and 10th innings where the odds are 11.4 percentage points higher. However, it's worth noting that at the top of each inning the odds are 50-50. When both teams have equal numbers of at-bats remaining, the odds are about the same when the score is tied at 0.
Let's look at one more situation. Let's look at a one run lead going into the 9th inning. We'll need to examine two games for this one. In the first game, the home team is up one to begin the 9th. We'll use this Orioles vs Redsox game also from opening day. The odds of the Orioles winning was 83.3. Contrast this to the odds of the Away team winning a 1 run game in the 9th. For that we'll use this Braves vs Nationals game. Looking at the odds going into the top of the 9th, we see that the Braves had a 84.9% chance of winning it, but after going hitless in their final at-bat, their odds of winning were only 81.6%.
The contrast to note here is the 1.7 percentage point difference going into the last at-bat for the losing team. When the home team has another at-bat it makes a difference nearly 2% of the time.
Obviously these two examples don't account for the full home field advantage, but the fangraphs data does show a clear edge for the home team historically due to last action.
Comment: In the Fangraphs model, the home team always has an advantage in the MIDDLE of an inning, because it has one more batting opportunity. My hypothesis was that the home team has an advantage even in the TOP of the ninth, because of the principle of last action.
Comment: One thing I should probably note is that Fangraphs does not start the game with an imbalance weighted to the home team. It bases it's win probabilities only on what happens during the game.


Quickest way to transfer a file from remote Linux to Windows?

Question: I need to transfer a file (~15 Mb) from a remote Linux machine to my local Windows box over the Internet and I was just wondering what would be the best way to do it? The Linux machine is a server sitting behind firewalls so that solutions need to open other ports may not be suitable. I'm currently connected to the Linux machine via SSH(Putty) and I prefer to use the command line.
Thanks in advance.
Answer: I'd give scp a try. Or WinSCP if you want a GUI.
Answer: If you prefer the command line, try pscp.exe on the local machine, from the lovely Putty people.
pscp.exe <user>@<remote ip>:<remote file> <local file>
e.g. pscp.exe email@example.com:/etc/hosts ./hosts

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Answer: Two ways:

python -m SimpleHTTPServer
This will start a web server on port 8000 (if you need an alternate port, specify it as next argument) which will expose all files in the current directory and you could download them directly with the web browser or with any http downloader.
Use netcat! Just google for "netcat file transfer", you'll find a lot of examples.
Comment: Sure, either of these *would* work, but why require another port/configuration/etc when ssh is obviously already running, especially when considering that either of the above options sends the file across the network unencrypted.
Comment: It's a good recommendation, as he's asking for the *quickest* way.  I pipe tar through netcat all the time on a LAN when I want to reduce overhead for a large transfer.
Comment: @Warner, yes, that's correct. I guess I was reading too much into the question..."remote linux system" usually means across the WAN somehow, which in most cases, you'd want to use some encrypted method.
Comment: Good point.  Over the Internet, encrypted protocols are the best idea.
Comment: sorry, i should have stated clearer in the question. The question has been updated.
Comment: I just provided options. It's up to the guy who asked to pick the one that suits him best.
Answer: my preference goes to filezilla, for it supports SSH protocol (as well as FTP and such)
http://filezilla-project.org/
Answer: Using notepad++ with NppFTP plugin is another way. Its faster than pscp.exe
For download :

For Upload :


Gold, silver, and bronze medal sweep in Winter Olympics by a single country?

Question: I am proud to see that the Dutch athletes have now obtained Gold, Silver and Bronze for one event, and that even twice.
When trying to figure out whether this happened before, I found several occurrences of a country getting all medals for an event during the Summer Olympics. But has this ever happened before in the winter games? And has it ever happened twice in the same games?
Comment: And another one: http://espn.go.com/olympics/winter/2014/freestyleskiing/story/_/id/10448899/2014-sochi-olympics-us-men-sweep-podium-slopestyle-skiing
Answer: At the Sochi 2014 Winter Games, the Netherlands won gold, silver, and bronze in 4 different speed skating events:

Men's 5000m: Sven Kramer, Jan Blokhuijsen, and Jorrit Bergsma
Men's 500m: Michel Mulder, Jan Smeekens, and Ronald Mulder
Men's 10000m: Jorrit Bergsma, Sven Kramer and Bob de Jong
Women's 1500m: Jorien ter Mors, Ireen Wüst and Lotte van Beek

Clearly, the Netherlands were a powerhouse in speed skating this year.  Out of 36 medals total awarded in men's and women's (long track) speed skating, Dutch skaters took home 23 of them.  They won at least one medal in every speed skating event, and won gold in both the men's and women's team pursuit events.
It is not all that unusual for one country to sweep gold, silver, and bronze in a single event.  It happens on average perhaps once or twice per Winter Olympics.  In addition to the four events listed above at Sochi 2014, the USA swept men's slopestyle skiing, and France swept men's ski cross.  No country did it at Vancouver 2010, but it happened twice in Torino 2006, when the Austrians swept the men's slalom medals and the Germans took every medal in the women's singles luge.
It is also not unheard of for one country to sweep two events in a single year.  The last time this happened was at Nagano 1998, when Germany took every medal in both women's combined alpine skiing and women's 3000m speed skating.
The Netherlands, however, is the first country to sweep four events in a single Winter Olympics.
Comment: France sweep today all the medals in men Skicross..
Answer: I verified what Ben said using a database (http://webscraping.com/data/default/database/54/winter-olympic-medal-count and then cross-referencing the events at http://www.sports-reference.com/olympics/winter/) and his recent answers are correct.

Before the Dutch multisweep listed, the last multisweeps by one country were:
Germany in 84 (speed skating & luge)
USSR in 64 (skiing and speed skating)
Norway in 32 (nordic and ski jumping)
Norway in 28 (nordic and cross country ski)
Norway in 24 (nordic and cross country... same 3 guys in both)

So it dates back to at least 1932 for two sweep by one country in related sports , and I'm not sure even those are truly considered the same discipline.  So while sweeps and even double sweeps happen... this is the most dominating a team has been at a certain skill in at least the modern era.
Answer: There is a full overview of all the sweeps in the Winter Olympics at this site: http://www.bsports.com/iotd/sochi-winter-olympics-sweeping-history.
However, it hasn't updated (yet) for the latest 2 sweeps of The Netherlands.
Based on this, for The Winter Olympics.

Total sweeps: 41
2 sweeps by 1 country: 3 Norway, 1 West Germany, 1 Sovjet Union, 1 Germany
3 sweeps by 1 country: none
4 sweeps by 1 country: 1 The Netherlands (of which one Sweep Plus, having placed 1, 2, 3 and 4)

Unfortunately, I've not found any record of Sweep Pluses, however at least in Speed Skating, it has never happened before.
Answer: It is nice to mention that the Dutch speed skaters also had a "single sweep" before, in Nagano 1998, 10K men, with gold for Gianni Romme, Silver for Bob De Jong, and bronze for Rintje Ritsma. De Jong may well take his fourth 10K medal this Olympics, 16(!) years after his first. In a sense he also has a sweep, since his previous three 10K medals are gold (2006), silver (1998) and bronze (2010).
Answer: See this link. Four times at winter only done by Netherlands. Maximum of other country is 2.
http://olympstats.com/2014/02/13/medal-sweeps-at-the-winter-olympics/
Comment: That's a nice list, but looking at it briefly, I see an inaccuracy.  As I mentioned in my answer, no country swept an event in Vancouver 2010, but this list says that Germany swept the [Women's Singles Luge](https://en.wikipedia.org/wiki/Luge_at_the_2010_Winter_Olympics_%E2%80%93_Women%27s_singles).


Solver first order differential matrix equation Netlogo

Question: To design the movement of one agent based on agent's neighbors position. We come usually to this control protocol:
x'_i(t) = ai1*x_i(t)+ +aij*x_j(t) ; j=1,..,N,

N is the total neighbor of i.
aij : are the constant (design coefficient).

at the end we come to solve this equation:
x'(t) = Ax(t) : A is a design matrix, x is the position of the agent.

one of the simplest case could be:  (x,y are neighbors)
x'(t) = x(t) + 2y(t)
y'(t) = 2x(t) + y(t)

Is there any numerical method to solve this equation. So that at each tick time, I can display the x(t) and y(t).
In matlab we have ode45 solver to do this. But with Netlogo I don't know how. With Runge-Kutta Method it work only with one variable x(t) = f(x,t).
Comment: Have you looked at https://stackoverflow.com/q/29564018/3088138 as an example of changing Euler to RK4 in LOGO
Comment: I have looked carefully with the answer, but it 's still not clear for me. The runge Kutta method can be used for first order matrix equation but in Centralized method, with agent-based method, I don't know how.
Answer: NetLogo is inherently discrete in its treatment of time, not continuous. It is also agent-centric (so work out the model rule from the perspective of the agent, not someone external).
Treat this as a difference equation. You could store attributes (in your case: x, x-prime) for each agent. Having decided on your meaning of neighbor (eg the closest agent, the agent at the other end of a randomly chosen link), then you directly calculate the new value of x-prime and set the agent's variable to that value.
If you want them all to update at the same time, your code could look something like this:
turtles-own
[ x
  x-prime
  next-x
  next-x-prime
]

to setup
  clear-all
  create-turtles 10
  [ setxy random-xcor random-ycor
    set x random-float 10
    set x-prime random-float 10
  ]
  reset-ticks
end

to go
  ask turtles
  [ let partner one-of other turtles
    set next-x x + x-prime
    set next-x-prime x + 2 * [x] of partner * [x-prime] of partner
  ]
  ask turtles
  [ set x next-x
    set x-prime next-x-prime
  ]
  tick
end


Nginx php-fpm in docker - Getting 404s

Question: I'm trying to launch to containers an nginx container and a php-fpm container. php-fpm container exposes port 9000 and the nginx container exposes port 80. I updated the conf file to point the
Once both are up I can load the application in the browser. However all of my css/js files return a 404.  I don't see any errors in the php-fpm/error.log or the nginx/error.log. I'm guessing there is a fault with my nginx or php-fpm conf files.
Does nginx need access to the actual files being requested or is that php-fpm's responsibility?
Thanks in advance
php 5.5.18
nginx 1.6.2
OS centos 6.5
Here is my nginx.conf file
<code>user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    #include /etc/nginx/sites-enabled/*;
    upstream mysite_backend {
       server 10.1.0.4:9000;
    }

    server {
        #listen 80;
        #server_name 172.17.9.101 mysite.com;
        server_name _;
        listen 80 default_server;
        listen [::]:80 default_server;
        #access_log logs/mysite.access.log;
        root /var/www/mysite/public;

        try_files $uri $uri/ /index.php$uri /index.php?$args;

        location / {
            index  index.html index.htm index.php $uri;
        }

        location ~* \.(jpg|jpeg|gif|png|html|css|zip|tgz|gz|rar|doc|xls|pdf|ppt|tar|wav|bmp|rtf|swf|flv|txt|xml|docx|xlsx|js)$ {
            try_files $uri $uri/ /index.php$uri =404;
            access_log off;
        }

        # unless the request is for a valid file (image, js, css, etc.), send to bootstrap
        if (!-e $request_filename)
        {
            rewrite ^/(.*)$ /index.php?/$1 last;
            break;
        }
        location ~ \.php$ {
           #fastcgi_pass   unix:/tmp/php-fpm.sock;
           fastcgi_pass mysite_backend;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           fastcgi_param   PATH_INFO               $fastcgi_path_info;
           include        fastcgi_params;
        }
    }

}

#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
#
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

daemon off;
</code>
Here is my www.conf for php-fpm
<code>; Start a new pool named 'www'.
[www]

; Per pool prefix
; It only applies on the following directives:
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = ac
group = ac

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 9000
;listen = /tmp/php-fpm.sock

; Set listen(2) backlog.
; Default Value: 128 (-1 on FreeBSD and OpenBSD)
;listen.backlog = 128

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
;                 mode is set to 0666
listen.owner = ac
listen.group = ac
listen.mode = 0666

; List of ipv4 addresses of FastCGI clients which are allowed to connect.
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
; listen.allowed_clients =

; Choose how the process manager will control the number of child processes.
; Possible Values:
;   static  - a fixed number (pm.max_children) of child processes;
;   dynamic - the number of child processes are set dynamically based on the
;             following directives. With this process management, there will be
;             always at least 1 children.
;             pm.max_children      - the maximum number of children that can
;                                    be alive at the same time.
;             pm.start_servers     - the number of children created on startup.
;             pm.min_spare_servers - the minimum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is less than this
;                                    number then some children will be created.
;             pm.max_spare_servers - the maximum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is greater than this
;                                    number then some children will be killed.
;  ondemand - no children are created at startup. Children will be forked when
;             new requests will connect. The following parameter are used:
;             pm.max_children           - the maximum number of children that
;                                         can be alive at the same time.
;             pm.process_idle_timeout   - The number of seconds after which
;                                         an idle process will be killed.
; Note: This value is mandatory.
pm = dynamic

; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 50

; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 5

; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 5

; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 35

; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
;pm.process_idle_timeout = 10s;

; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
;pm.max_requests = 500

; The URI to view the FPM status page. If this value is not set, no URI will be
; recognized as a status page. It shows the following informations:
;   pool                 - the name of the pool;
;   process manager      - static, dynamic or ondemand;
;   start time           - the date and time FPM has started;
;   start since          - number of seconds since FPM has started;
;   accepted conn        - the number of request accepted by the pool;
;   listen queue         - the number of request in the queue of pending
;                          connections (see backlog in listen(2));
;   max listen queue     - the maximum number of requests in the queue
;                          of pending connections since FPM has started;
;   listen queue len     - the size of the socket queue of pending connections;
;   idle processes       - the number of idle processes;
;   active processes     - the number of active processes;
;   total processes      - the number of idle + active processes;
;   max active processes - the maximum number of active processes since FPM
;                          has started;
;   max children reached - number of times, the process limit has been reached,
;                          when pm tries to start more children (works only for
;                          pm 'dynamic' and 'ondemand');
; Value are updated in real time.
; Example output:
;   pool:                 www
;   process manager:      static
;   start time:           01/Jul/2011:17:53:49 +0200
;   start since:          62636
;   accepted conn:        190460
;   listen queue:         0
;   max listen queue:     1
;   listen queue len:     42
;   idle processes:       4
;   active processes:     11
;   total processes:      15
;   max active processes: 12
;   max children reached: 0
;
; By default the status page output is formatted as text/plain. Passing either
; 'html', 'xml' or 'json' in the query string will return the corresponding
; output syntax. Example:
;   http://www.foo.bar/status
;   http://www.foo.bar/status?json
;   http://www.foo.bar/status?html
;   http://www.foo.bar/status?xml
;
; By default the status page only outputs short status. Passing 'full' in the
; query string will also return status for each pool process.
; Example:
;   http://www.foo.bar/status?full
;   http://www.foo.bar/status?json&full
;   http://www.foo.bar/status?html&full
;   http://www.foo.bar/status?xml&full
; The Full status returns for each process:
;   pid                  - the PID of the process;
;   state                - the state of the process (Idle, Running, ...);
;   start time           - the date and time the process has started;
;   start since          - the number of seconds since the process has started;
;   requests             - the number of requests the process has served;
;   request duration     - the duration in µs of the requests;
;   request method       - the request method (GET, POST, ...);
;   request URI          - the request URI with the query string;
;   content length       - the content length of the request (only with POST);
;   user                 - the user (PHP_AUTH_USER) (or '-' if not set);
;   script               - the main script called (or '-' if not set);
;   last request cpu     - the %cpu the last request consumed
;                          it's always 0 if the process is not in Idle state
;                          because CPU calculation is done when the request
;                          processing has terminated;
;   last request memory  - the max amount of memory the last request consumed
;                          it's always 0 if the process is not in Idle state
;                          because memory calculation is done when the request
;                          processing has terminated;
; If the process is in Idle state, then informations are related to the
; last request the process has served. Otherwise informations are related to
; the current request being served.
; Example output:
;   ************************
;   pid:                  31330
;   state:                Running
;   start time:           01/Jul/2011:17:53:49 +0200
;   start since:          63087
;   requests:             12808
;   request duration:     1250261
;   request method:       GET
;   request URI:          /test_mem.php?N=10000
;   content length:       0
;   user:                 -
;   script:               /home/fat/web/docs/php/test_mem.php
;   last request cpu:     0.00
;   last request memory:  0
;
; Note: There is a real-time FPM status monitoring sample web page available
;       It's available in: @EXPANDED_DATADIR@/fpm/status.html
;
; Note: The value must start with a leading slash (/). The value can be
;       anything, but it may not be a good idea to use the .php extension or it
;       may conflict with a real PHP file.
; Default Value: not set
;pm.status_path = /status

; The ping URI to call the monitoring page of FPM. If this value is not set, no
; URI will be recognized as a ping page. This could be used to test from outside
; that FPM is alive and responding, or to
; - create a graph of FPM availability (rrd or such);
; - remove a server from a group if it is not responding (load balancing);
; - trigger alerts for the operating team (24/7).
; Note: The value must start with a leading slash (/). The value can be
;       anything, but it may not be a good idea to use the .php extension or it
;       may conflict with a real PHP file.
; Default Value: not set
;ping.path = /ping

; This directive may be used to customize the response of a ping request. The
; response is formatted as text/plain with a 200 response code.
; Default Value: pong
;ping.response = pong

; The access log file
; Default: not set
;access.log = log/$pool.access.log

; The access log format.
; The following syntax is allowed
;  %%: the '%' character
;  %C: %CPU used by the request
;      it can accept the following format:
;      - %{user}C for user CPU only
;      - %{system}C for system CPU only
;      - %{total}C  for user + system CPU (default)
;  %d: time taken to serve the request
;      it can accept the following format:
;      - %{seconds}d (default)
;      - %{miliseconds}d
;      - %{mili}d
;      - %{microseconds}d
;      - %{micro}d
;  %e: an environment variable (same as $_ENV or $_SERVER)
;      it must be associated with embraces to specify the name of the env
;      variable. Some exemples:
;      - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e
;      - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e
;  %f: script filename
;  %l: content-length of the request (for POST request only)
;  %m: request method
;  %M: peak of memory allocated by PHP
;      it can accept the following format:
;      - %{bytes}M (default)
;      - %{kilobytes}M
;      - %{kilo}M
;      - %{megabytes}M
;      - %{mega}M
;  %n: pool name
;  %o: ouput header
;      it must be associated with embraces to specify the name of the header:
;      - %{Content-Type}o
;      - %{X-Powered-By}o
;      - %{Transfert-Encoding}o
;      - ....
;  %p: PID of the child that serviced the request
;  %P: PID of the parent of the child that serviced the request
;  %q: the query string
;  %Q: the '?' character if query string exists
;  %r: the request URI (without the query string, see %q and %Q)
;  %R: remote IP address
;  %s: status (response code)
;  %t: server time the request was received
;      it can accept a strftime(3) format:
;      %d/%b/%Y:%H:%M:%S %z (default)
;  %T: time the log has been written (the request has finished)
;      it can accept a strftime(3) format:
;      %d/%b/%Y:%H:%M:%S %z (default)
;  %u: remote user
;
; Default: "%R - %u %t \"%m %r\" %s"
;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"

; The log file for slow requests
; Default Value: not set
; Note: slowlog is mandatory if request_slowlog_timeout is set
;slowlog = /var/log/php-fpm.log.slow

; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_slowlog_timeout = 0

; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_terminate_timeout = 0

; Set open file descriptor rlimit.
; Default Value: system defined value
;rlimit_files = 1024

; Set max core size rlimit.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0

; Chroot to this directory at the start. This value must be defined as an
; absolute path. When this value is not set, chroot is not used.
; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
; of its subdirectories. If the pool prefix is not set, the global prefix
; will be used instead.
; Note: chrooting is a great security feature and should be used whenever
;       possible. However, all PHP paths will be relative to the chroot
;       (error_log, sessions.save_path, ...).
; Default Value: not set
;chroot =

; Chdir to this directory at the start.
; Note: relative path can be used.
; Default Value: current directory or / when chroot
;chdir = /var/www

; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Note: on highloaded environement, this can cause some delay in the page
; process time (several ms).
; Default Value: no
catch_workers_output = yes

; Limits the extensions of the main script FPM will allow to parse. This can
; prevent configuration mistakes on the web server side. You should only limit
; FPM to .php extensions to prevent malicious users to use other extensions to
; exectute php code.
; Note: set an empty value to allow all extensions.
; Default Value: .php
;security.limit_extensions = .php .php3 .php4 .php5

; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
; the current environment.
; Default Value: clean env
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp

; Additional php.ini defines, specific to this pool of workers. These settings
; overwrite the values previously defined in the php.ini. The directives are the
; same as the PHP SAPI:
;   php_value/php_flag             - you can set classic ini defines which can
;                                    be overwritten from PHP call 'ini_set'.
;   php_admin_value/php_admin_flag - these directives won't be overwritten by
;                                     PHP call 'ini_set'
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.

; Defining 'extension' will load the corresponding shared extension from
; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
; overwrite previously defined php.ini values, but will append the new value
; instead.

; Note: path INI options can be relative and will be expanded with the prefix
; (pool, global or prefix)

; Default Value: nothing is defined by default except the values in php.ini and
;                specified at startup with the -d argument
;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f firstname.lastname@example.com
php_flag[display_errors] = on
php_flag[display_startup_errors] = on
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = On
;php_admin_value[memory_limit] = 32M
php_admin_value[max_input_vars] = 2000
php_admin_value[error_reporting] = E_ALL & ~E_DEPRECATED & ~E_STRICT
</code>
Comment: Thank you for the replies, I'm now mounting the volumes from  php-fpm container onto the nginx container. That worked.
Comment: Can you answer the question with the solution that worked for you and accept the answer so this isn't listed as an unanswered question?
Comment: Seconded. This is the second StartPage result for `docker nginx php-fpm sock`; it's counterproductive for it to be unanswered.
Comment: What does nginx log? Where did you get this nginx configuration?
Comment: For simplicity, both nginx and php-fpm will need access to the files. I would set your error_log to debug level to see exactly what's going on. You should also move your index line a level up to the server block, and remove $uri.
Comment: Got the config from a multitude of places. The application is based laravel 3 php framework.
Answer: I used the comment from @user2108258 to fix a similar issue that I had. I was getting 404 errors when trying to access .css and .js files as they were mounted in my PHP container but not in my NGINX container.
<code>ANSWER: Mount your volume in the NGINX and PHP containers.
</code>
For Example:
docker-compose.yml with issues (static files were serving 404 errors)
<code>php:
    image: php:latest
    container_name: php
    volumes:
      - ./php/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
      - ./php/site:/var/www/site
      - ./style:/var/www/site/style
    depends_on:
      - mysql
    restart: always

 nginx:
    image: nginx:latest
    container_name: nginx
    ports:
      - '8080:8080'
    volumes:
      - ./nginx:/etc/nginx/conf.d
      - ./logs/nginx:/var/log/nginx
      - ./php/site:/var/www/site
    depends_on:
      - wordpress
    restart: always
</code>
docker-compose.yml without issues
- Add "- ./style:/var/www/site/style" to your nginx service block.
<code> php:
    image: php:latest
    container_name: php
    volumes:
      - ./php/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
      - ./php/site:/var/www/site
      - ./style:/var/www/site/style
    depends_on:
      - mysql
    restart: always

 nginx:
    image: nginx:latest
    container_name: nginx
    ports:
      - '8080:8080'
    volumes:
      - ./nginx:/etc/nginx/conf.d
      - ./logs/nginx:/var/log/nginx
      - ./php/site:/var/www/site
      - ./style:/var/www/site/style
    depends_on:
      - wordpress
    restart: always
</code>

Nginx php-fpm in docker - Getting 404s


Linear algebra proof regarding matrices

Question: I'd like a hint rather than a full solution.
The problem I am considering is the following:

$X$ is an $n\times m$ matrix $Y$ is $m\times n$
Show that
$(I - XY)^{-1}\cdot X = X\cdot(I - YX)^{-1}$

The first $I$ is of dimension $n$ and the second $I$ is of dimension $m$.
Answer: Hint
Verify that
$$(I-XY)X=X(I-YX)$$
Comment: @KimJongUn Invertibility of $I-XY$ is equivalent to $1$ not being an eigenvalue of $XY$; but $XY$ and $YX$ have the same non zero eigenvalues.
Comment: Okay....this is easy enough to verify. Am I now trying to work backwards from here or am I going about this the wrong way.
Comment: +1 great hint. A quick question: is the invertibility of $I-XY$ equivalent to that of $I-YX$?
Comment: I wonder if it would be a better hint to flip the sides of the equation.
Comment: I'm still having trouble making the leap from verifying the above equation to the one in the OP
Comment: @KimJongUn See also https://math.stackexchange.com/questions/17831/how-can-we-prove-sylvesters-determinant-identit

Linear algebra proof regarding matrices


Vue enter transition on router

Question: I'm following this image from vue docs

my html
<transition name="fade">
  <router-view/>
</transition>

and css
.fade-enter-active, .fade-leave-active {
  transition: opacity 2s;
}
.fade-enter, .fade-leave-to {
  opacity: 0;
}
.fade-enter-to, .fade-leave {
  opacity: 1;
}

it fade out correctly but instantly pop in instead of fade-in. Why?
I've created demo repository with just 2 components, steps to reproduce:

git clone https://github.com/BorysTyminski/vue-transition-issue.git
cd vue-transition-issue
npm install
npm run dev

And demo codesanbox:
https://codesandbox.io/embed/vue-template-4e4oy
Comment: It should work. Are you sure the element doesn't have a stronger selector applying `transition-duration`? Can you provide a [mcve]?
Comment: Sure I created demo repo with just 2 routes and nothing more.
Comment: Did you check it? Is it not working on your machine as well?
Comment: I can't install random projects on machines at work, I'll check it from home, when I have time. You could have used codesandbox.io, btw.
Comment: Sure, here you go https://codesandbox.io/embed/vue-template-4e4oy Just click huge link "Go to second"
Answer: The problem is both your divs transition at the same time.
Which means they're both present in DOM at the same time.
Which means the second one, like any good ol'
, will be rendered below the first one.
Below as in "...further down the page".
Unless it's absolutely positioned with top:0, of course.
So I guess you're missing...
#app {
  position: relative;
  > div + div {
    position: absolute;
    top: 0;
  }
}

See it.
Comment: `` works like that and it's completely transparent. It basically doesn't care what it transitions as long as it's a DOM object.

Vue enter transition on router


Determine invertible elements of a monoid

Question: I have the following excercise.

In the set $\mathbb{Z}_6\times\mathbb{Z}_6$ consider the follow:
  $$(\overline{a}, \overline{b})\cdot(\overline{c}, \overline{d}) = (\overline{a}+\overline{c}+\overline{3}, \overline{b}\overline{d})$$
   Prove that $(\mathbb{Z}_6\times\mathbb{Z}_6, \cdot)$ is a monoid,
  and determine the invertible elements.

Yes, it's a monoid.
Associative:
$$\big((\overline{a}, \overline{b})\cdot(\overline{c}, \overline{d})\big) \cdot  (\overline{e}, \overline{f})=(\overline{a}, \overline{b})\cdot\big((\overline{c}, \overline{d}) \cdot  (\overline{e}, \overline{f})\big)$$
through various steps (and considering $\overline{3}+\overline{3}=\overline{6}=\overline{0} $, is that correct???):
$$(\overline{a}+\overline{c}+\overline{e}, \overline{b}\overline{d}\overline{f})=(\overline{a}+\overline{c}+\overline{e}, \overline{b}\overline{d}\overline{f})$$
Identity:
 $$(\overline{a}, \overline{b})\cdot(\overline{e_1}, \overline{e_2}) = (\overline{a}, \overline{b})\quad \forall (\overline{a}, \overline{b}) \in \mathbb{Z}_6\times\mathbb{Z}_6$$
follow:
$$(\overline{a}+\overline{e_1}+\overline{3}, \overline{b}\overline{e_2})=(\overline{a}, \overline{b})$$
thus:
$$\overline{a}+\overline{e_1}+\overline{3} = \overline{a}\Rightarrow \overline{e_1}=\overline{-3}$$
and
$$\overline{b}\overline{e_2}= \overline{b}\Rightarrow \overline{e_2}=\overline{1}$$
The structure is even commutative, than exist right and left identity.
Invertible elements:
$$(\overline{a}, \overline{b})\cdot(\overline{i_1}, \overline{i_2}) = (\overline{-3}, \overline{1})\quad \forall (\overline{a}, \overline{b}) \in \mathbb{Z}_6\times\mathbb{Z}_6$$
so:
$$(\overline{a}+\overline{i_1}+\overline{3}, \overline{b}\overline{i_2})=(\overline{-3}, \overline{1})$$
follow (and considering: $\overline{3}+\overline{3}=\overline{6}=\overline{0}$):
$$\overline{a}+\overline{i_1}+\overline{3} = \overline{-3}\Rightarrow \overline{a}+\overline{i_1}+\overline{3} +\overline{3} = 0 \Rightarrow \overline{i_1}=\overline{-a}$$
and
$$\overline{b}\overline{i_2}=\overline{1} \Rightarrow \overline{i_2}=\overline{b^{-1}}$$
Is (until now) all right? Now, how can I find $\overline{b^{-1}}$?
Comment: The invertible elements in $\mathbb Z /6\mathbb Z$ are $\overline 1$ and $\overline 5$ since these are the residue classes which are coprime to the modulus 6. We have $\overline 5^{-1} = \overline 5$ because $\overline 5 = \overline {-1}$.
Answer: A crucial observation to simplify the study of this structure is that the first and second components are treated entirely independently. So if you can show that the operations $\bar a\cdot_1\bar c=\bar a+\bar c+\bar 3$ and $\bar b\cdot_2\bar d=\bar b\bar d=\overline{bd}$ individually define monoid structures on $\mathbb Z/6\mathbb Z$, then you will have shown that the defined structure is the direct product of these two monoids, and therefore a monoid.
Now the second structure is just multiplication modulo $6$, which defines the multiplicative monoid $(\mathbb Z/6\mathbb Z,\times)$; this is certainly a (commutative) monoid with identity element $\bar1$. The first structure is more like addition modulo $6$, but it is shifted. Once you find the neutral element for this operation, which is easily seen to be $\bar3$, you can see that the shift by $\bar3$ transforms the usual addition modulo $6$ into the operation $\cdot_1$: it is a bijection, and if $x+y=z$ in $\mathbb Z/6\mathbb Z$, then
$$(x+\bar3)\cdot_1(y+\bar3)=(x+\bar3)+(y+\bar3)+\bar3=z+\bar9=z+\bar3
$$
in $(\mathbb Z/6\mathbb Z,\cdot_1)$. So the latter structure is a monoid (in fact a commutative group), and $x\mapsto x+\bar3$ is an isomorphism $(\mathbb Z/6\mathbb Z,+)\to(\mathbb Z/6\mathbb Z,\cdot_1)$. This avoids the tedious verification of the associative law and identity property.
One concludes that $(\mathbb Z/6\mathbb Z,\cdot)$ is a commutative monoid as well, with identity $(\bar3,\bar1)$; it is isomorphic to the product monoid $(\mathbb Z/6\mathbb Z,+)\times(\mathbb Z/6\mathbb Z,\times)$ by the isomorphism $(x,b)\mapsto(x+\bar3,b)$. Since the first factor of this product monoid is in fact a group, the invertible elements of the product are those which have a second component that is invertible for $\cdot_2$, in other words that is $\bar1$ or $\bar5$.
Answer: Since you are in $\mathbb Z_6, \overline{b}^{-1}$ only exists for $\overline b= \overline 1$ or $\overline b= \overline5$.
Answer: Looks okay to me, so far. You've shown that, if you want
$$ (a,b)(c,d) = e = (3,1)$$ to hold, you need to have $a + c = 0$ and $bd = 1$.
The first equation is easy to satisfy for all $a$; when does the second have a solution?
If you can answer that question, you will have found the invertible elements. So the problem is not so much "how can I find $b^-1$", but "when is $bd = 1$ solvable for $d$, working modulo 6?".


interpreting the standard errors from a simple linear model

Question: I am having a basic doubt about the interpretation of the standard errors from the R output of a linear model in which you have a single explanatory categorical variable.
Let's say we are using the iris dataset in R and we are modeling the relationship between Sepal.Length and Species, so we have the following:
m1<-lm(iris$Sepal.Length~iris$Species)

summary(m1)

which gives:
Call:
lm(formula = iris$Sepal.Length ~ iris$Species)

Residuals:
    Min      1Q  Median      3Q     Max
-1.6880 -0.3285 -0.0060  0.3120  1.3120

Coefficients:
                       Estimate Std. Error t value Pr(>|t|)
(Intercept)              5.0060     0.0728  68.762  < 2e-16 ***
iris$Speciesversicolor   0.9300     0.1030   9.033 8.77e-16 ***
iris$Speciesvirginica    1.5820     0.1030  15.366  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.5148 on 147 degrees of freedom
Multiple R-squared:  0.6187,    Adjusted R-squared:  0.6135
F-statistic: 119.3 on 2 and 147 DF,  p-value: < 2.2e-16

Species has 3 levels (setosa, versicolor and virginica) and I know that for the estimate the (Intercept) gives me the estimate for setosa (5.0060) and that for the other species the estimate value shown is the difference to the setosa estimate, so their values would be 5.0060+0.9300 for versicolor and 5.0060+1.5820 for virginica.
Now, I would like to report the std. error for these estimates. So can I simply take the standard error that is shown for each species (e.g. versicolor:5.936+/-0.1030), or are these std. errors for the difference and I would have to sum the (Intercept) error to get the error for versicolor or virginica?
Answer: 5.0060+0.9300 is the estimate of mean of $Y$ for versicolor. you are correct. But its variance is $0.0728^2+0.1030^2 +2\times \text{Cov(two estimates)}$. So you need to find Covariance between them. Then square root of variance is the standard error. the same for virginica.
Another tricky method: Fit another model by replacing "versicolor" with "aversicolor" in the data, you get the answer for versicolor. I think you know how to get answers for virginica following the same way.
Comment: great, I will try your later suggestion. simply changing the baseline factor level with `relevel()`, as described in http://tinyurl.com/owsjkof, should do it.
Comment: when I change the reference level for `Species`, the `std. error` value always stays the same. I don't think I am doing anything wrong, would you know why this is the case?
Comment: sample size in each group are equal?
Comment: yes, they are the same
Comment: Then they should be the same. If not same, your statistical software would be problem. If you want, you can delete some of the data to make the sample sizes are unequal among groups, and you should get different SEs.


Is it possible to define a block in a zone file as constant in Dynamic DNS (using bind)?

Question: bind mangles my zone file every time a DNS update is done. If defining a block as constant isn't possible, is it possible to have 2 or more zone files describing one domain? The intent being one zone file is for fixed RR's and the other for dynamic RR's.
Lastly, if none of the above is possible, is it possible to revert to the original zone file every time DNS starts?
As a last resort, I'm going to have to write a script to manually copy or create a base zone file then start bind. But this doesn't seem like the right way to do it.
Comment: I'm new to DNS. I have a setup where a few test VMs add A and PTR records on boot and remove them on shutdown through a script. I could be wrong but no matter how you organize the conf and zone files, you'll always have at least an NS RR in every zone file. The setup is working now but I want to prevent scripts that might be written in the future from accidentally changing "constant" RRs like NS and MX.
Comment: How your script adds/removes the records ? - By editing zone file ?
Comment: Adding new RR: /etc/NetworkManager/dispatcher.d/25mydnsupdatescript, The script is just a wrapper for nsupdate. Removing RRs (on shutdown): /etc/init.d/mydnsupdatescript stop. Same thing. Script is just a wrapper for nsupdate but remove RRs this time.
Answer: Yes, you can have two files for a single zone. In addition suggest doing all dynamic updates in a subdomain. Combining both of these you can keep all the machine edits isolated.
Add this to the end of your zone file:
$INCLUDE dynamic-zone-file.conf dyn.example.com

All dynamic updates would then go to dynamic-zone-file.conf. This file should exist and be writable by the named user.
Answer: At my place we keep dynamic updates contained in their own zones. I can't think of any way to keep a zone file tidy if it receives dynamic updates. I am not sure what you are trying to say with "is it possible to revert to the original zone file". Are you saying you don't need the dynamic updates to be persistent between BIND restarts? If so, just write a script that copies  the master zone file you store and edit somewhere before BIND is started.
Answer: Define "mangle".  If you mean "rewrite", well then yeah, BIND needs to rewrite the zone file every time you make an update.  My policy was always that once a zone file was open for dynamic updates, it was never manually modified ever again, and you had to use the automatic update mechanism to do anything (lots of nsupdate calls, or just use the web interface API we setup).
To answer your other questions:

"is it possible to have 2 or more zone files describing one domain?" -- the correct term for "domain" in BIND is "zone", so if we rewrite your question to be "is it possible to have 2 or more zone files describing one zone?", the answer becomes pretty obvious.  Have two separate zones, as mghocke described, if you need something like that.
"is it possible to revert to the original zone file every time DNS starts?" -- Sure, just have your DNS startup script copy the base zone file into place.  There isn't a better way to do it because it isn't something that anyone would ever want to do -- accept dynamic updates and then throw them away every time you restart the DNS server.  One caveat with this method is that you'll need to update the serial when you copy the base zone file, otherwise your slaves won't do a zone transfer.

My psychic powers are suggesting that you're trying to mix manual (direct) edits to a zone file with dynamic updates.  Just so you know, that won't work (in the naive case) -- sooner or later you're going to get in a race between a dynamic update and a manual file edit, and the dynamic update will win, resulting in the loss of your manual update.  You'll need to freeze and unfreeze the zone every time you want to edit (good luck universally enforcing that one).  This is the reason for my "all edits to dynamic zones must be done via the DDNS interface" policy.
Comment: I'm new to DNS. This is for my VM test setup. If this were for a real world setup, then I would do as you suggested on performing updates only through a DDNS interface.


Go to very beginning of UINavigationController after going some pages deep

Question: I want to go to the very beginning of the UINavigationController after going deep several pages.  If I try the following code, it will only go back one view.
[self.navigationController popViewControllerAnimated:YES];
I want to do this action on a "cancel" button placed on the top right.
Comment: how do i do that?  you mean answer other questions?
Answer: [self.navigationController popToRootViewControllerAnimated:YES];