Why is the Axiom of Choice not needed when the collection of sets is finite?

Question: According to Wikipedia:

Informally put, the axiom of choice says that given any collection of
  bins, each containing at least one object, it is possible to make a
  selection of exactly one object from each bin. In many cases such a
  selection can be made without invoking the axiom of choice; this is in
  particular the case if the number of bins is finite...

How do we know that we can make a selection when the number of bins is finite? How do we even know that we can make a selection from a single bin of finite elements?
Then it gives an example:

To give an informal example, for any (even infinite) collection of
  pairs of shoes, one can pick out the left shoe from each pair to
  obtain an appropriate selection, but for an infinite collection of
  pairs of socks (assumed to have no distinguishing features), such a
  selection can be obtained only by invoking the axiom of choice.

But how can we even make a selection out of a single pair of socks if they don't have any distinguishing features? Is there another axiom being assumed here?
Comment: I guess there are a few related post on the site. For example: [Axiom of Choice and finite sets](http://math.stackexchange.com/q/132717)
Comment: Somewhat of a "reverse question", http://math.stackexchange.com/questions/1318441/axiom-of-choice-confusion-what-does-it-mean-an-element-to-have-no-distinguishin, you might want to look at the comments on my answer there as well.
Comment: I think it's worth noting that in a constructive setting, the axiom of choice, suitably formulated, implies the law of excluded middle and that this proof only involves using the axiom of choice on "finite" sets. (Though, the notion of "finite" splits into multiple different concepts constructively.) The point being that the axiom of choice is saying something non-trivial even for finite sets.
Comment: @Derek: And in other situations the axiom of choice is in fact a theorem. Especially if you have a family of inhabited sets, then you should have an algorithm proving that each of the sets has an element, and that gives you a choice function. Namely, if you constructed the family of the sets, and they were all constructed and non-empty, then you should be able to construct a choice function. Of course, "not empty" and "inhabited" are different things in constructive settings. (And take all that I said above with a grain of salt, as it applies to some, but not all, constructive settings.)
Comment: @AsafKaragila: I'm interested in learning more about the "meta-finite integers", but a Google search seems to indicate these comments as the only reference. Do they go by another name?
Comment: @RghtHndSd: Those are the integers of the meta-theory. In effect this is only important when you consider (or at least, do not want to exclude) non-standard models. This is important, as a whole, but subtle to understand. But if you understand how non-standard models "interact" with the "standard integers", then you understand my point.
Answer: It's a matter of the basic rules of inference allowed in proofs.
Suppose $\mathcal B$ is a "collection" of bins with only one element, i.e., $\mathcal B = \{S\}$ for some set $S$. The assumption is that $S$ is nonempty. By definition, this means there exists $x \in S$. We can use the existential instantitation rule of inference to fix $x \in S$. Then the association $$\mathcal B \to \bigcup_{T \in \mathcal B} T = S$$ given by $$\{S \mapsto x\}$$ defines a choice function.
Similarly, one can prove by induction that if $\mathcal B$ is a finite collection of nonempty buckets, then a choice function exists - if $\mathcal B_n$ is a collection of $n$ nonempty buckets, then fixing $S \in \mathcal B_n$, it follows that $\mathcal B_n \setminus \{S\}$ is a collection of $n-1$ nonempty buckets.
Comment: @David: All the members of the empty set are non-empty sets themselves. Disagree? Show me a counterexample! :)
Comment: @Dustan: One has to be careful about "by induction". External induction can only take you through the meta-finite integers; internal induction can get you through all the integers of the universe. Of course, this is a delicate point and we can ignore it for the sake of beginnings; but it should always be remarked that this is somewhat delicate.
Comment: If $n$ is $1$,  $\mathcal B_n \setminus \{S\}$ is $\mathcal \varnothing$, correct? Is it fair to call it a collection of zero nonempty buckets? (Serious if tangential question.)
Comment: @AsafKaragila I figured the induction part would probably be more complicated. I think that's your turf more than mine. :)
Comment: Actually, your proof works just fine. It's just something that one needs to pay attention to: you can treat your proof as iterated existential instantiation, which would only work for meta-finite integers; or as using the fact ZF proves induction, and that if two families admit a choice function, then their union admits a choice function (in the process here we use existential instantiation, but differently).
Comment: I did not really understand the answer to the actual question. Given a finite collection of right and left sock sets, can you concretely provide a way to choose at least one sock from each set? Am I missing something?
Comment: I mean I understand logically how this works but I still feel that it is missing the concrete aspect posed in the question.
Comment: @user3494047 Many other answers address the concrete aspect. My answer addresses it from a proof-theoretic perspective.
Answer: The axiom of choice says precisely that if $I$ is a set and, for each $i \in I$, we have a non-empty set $X_i$, then the product $\prod_{i \in I} X_i$ is non-empty. (Elements of products can be identified with choice functions, so non-emptiness of the product is equivalent to existence of a choice function.) When $I$ is finite, this is a statement which can be proved by induction on $|I|$, which does not require choice.
Comment: The problem I have with this answer is that it doesn't address the fact that, in the induction step, we have to _choose_ an element of this new added set (so we essentially reduce to one-set AC). The reason I think it might be confusing is that some common expositions involving AC may imply that we need to _construct_ an element  of the set (which we don't).
Comment: Don't we need to say "if $I$ is a *non-empty* set, and..."?
Comment: @ChasBrown: no, it's fine as stands!  If $I$ is empty then the product $\prod_{i \in I} X_i$ has a unique element, so is non-empty as claimed.
Comment: @Neel: The empty function is indeed a choice function from the empty family.
Comment: It seems for me that this is a bit more complicated. For a finite set of indexes products can be simply defined as ordered tuples (which can be defined inductively from an ordered pair). And induction argument works for that definition. On the other hand products can be defined as sets of choice functions (this definition is particularly useful for infinite sets of indexes). Now for your argument to work you would have to prove that these two definition are "equivalent" in the finite case, right?
Comment: @freakish: Yes and you use induction to prove that they are isomorphic. But one actually shouldn't be iterating the pair construction to prove the axiom of choice for finite sets since that is patently not what the axiom states...
Comment: @ Peter LeFanu Lumsdaine  pardon my little knowledge, you are referring to empty function right?
Answer: This is a good question; the main answer is that making a single choice out of a single bin is a matter of logic.
Specialized to this particular situation, if $S$ is a set and you have proven $\exists x : x \in S$, then logic allows you to introduce a new constant symbol (say, $a$) along with the corresponding an axiom $a \in S$.
The usual interpretation of this mechanic is that $a$ represents a 'choice' of an element of $S$, although this is by no means the only way to interpret this sort of thing:

We might instead interpret $a$ as simply being a dummy variable, so that what we're doing is defining a function of $S$
We might interpret $a$ as some sort of 'generic' element of $S$ rather than a choice of a specific element
Some forms of logic allow you to introduce $a \in S$ even when $S$ is an empty set; naturally this does not lend itself well to interpreting $a$ as a choice of an element!

Whatever way we look at it, we can use it to prove we can make a choice from a single bin in set theory; the main steps are

Introduce $a \in S$
Show $\{ (S, a) \}$ is a choice function on $\{ S \}$

Whatever our philosophical opinions on logic are, this construction defines a function
$$ S \to \operatorname{ChoiceFunctions}(\{ S \}) $$
where $\operatorname{ChoiceFunctions}(X)$ means the collection of all choice functions on $X$. This, together with the hypothesis that $S$ is nonempty, implies that $\operatorname{ChoiceFunctions}(\{ S \}) $ is nonempty as well.

Finite choice is basically the same. In an ad-hoc fashion you could repeat this sort of argument by repeatedly introducing one variable at a time. Alternatively (in set theory) you can set up a recursive definition and show finite choices can be made by induction; IIRC the proof is straightforward, but complicated.
Answer: This isn't a direct answer to the question, but a way to think about the axiom of choice.
The axiom of choice is a generalization of finiteness. It's related (by, for instance, the compactness theorem in logic, and Tychonoff's theorem in topology) to topological compactness, which is another generalization of finiteness.
Without the axiom of choice, you can sometimes specify a choice: "Pick the left shoe from each pair." If you can make (read: define) such a specification, you don't need the axiom of choice, because you can point to that specification as your choice.
Consider how each equivalent definition of Choice is true in the finite setting:

"Every finite product of non-empty sets has at least one element."
If you're given a few sets, you can select one from each, one step at a time. (If you have an infinite number of sets, you'd need an infinite number of steps.)
"Every finite set can be well-ordered."
If you pull elements out one at a time, that's a well-ordering. (Again, you'd need an infinite number of steps for an infinite set.)
"Every finite vector space has a basis."
Choose a non-zero vector. Then take a vector not in the linear subspace generated by the first vector. Then take a vector not in the span of the first two vectors. Eventually, you'll run out of vectors.
"Every two finite cardinals are comparable."
Count up from 0 until you get to the first one. That's the smaller one. If you get to both at once, they're equal.

In an informal sense, the axiom of choice says you can always take an infinite number of (certain kinds of) steps in finite time. And you can only follow a statement/proof that takes finite time to read. The axiom of choice is also non-constructive: you can't use it to make a "real" example, because you'd need infinite construction time.

More on finiteness and statements:
Let $X = X_0 \times X_1 \times X_2 \times \dots$ be a product of sets. Then the axiom of choice says
$$\exists x_0 \in X_0 \ \exists x_1 \in X_1 \ \exists x_2 \in X_2 \ \exists \dots \ \text{s.t.} (x_0, x_1,x_2, \dots) \in X$$
But the first ellipsis doesn't actually make sense in logic. No mathematical logic rules allow an infinite number of quantifiers. The axiom of choice sort of says, "That's okay, it still works."
On the other hand, you can define the "left shoe" choice with only a finite number of quantifiers. Let $I$ be the index set for the product. Then
$$\{\text{left}_i \in X_i | i \in I\} \in X$$
is a choice of all the left shoes, with one implicit quantifier over the index set.
Comment: See the comment I left to Dustan on the accepted answer, it is relevant here. This method only lets you get through the meta-finite integers, not through all the integers of the universe. And while this might be "sufficient" for most mathematicians and it is certainly a good way to present this naively, this method still misses a large chunk of relevant information about the interactions of theory and meta-theory when it comes to foundations of mathematics.
Comment: @Asaf I'm not sure I understand what you're talking about. I think you're talking about nonstandard natural numbers, and how they can't be reached using "steps". I did mean to add some comments about this relying on induction (I had ultrafinite mathematics in mind), and another about ordinals and transfinite induction. I couldn't solidify the thoughts, though. I'm admittedly rusty, and intended this to be an informal answer. Everyone should feel free to add any necessary caveats to my answer.
Comment: The second part of your answer is based on the misconception that iterating the binary cartesian product is just the same as forming the collection of sequences such that the $k$-th item in each sequence is from the $k$-th set. For finitely many sets it is non-trivial and has to be done carefully to avoid merely getting cartesian products of meta-finite length (as per Asaf's comment), and a proof that they are the same is still lacking. For infinitely many sets it is simply meaningless. And the axiom of choice does **not** actually state anything about cartesian products...
Answer: This is essentially just the power of the pairing axiom. Consider the case $n=3$: If $A,B,C$ are nonempty, then so is $A\times B\times C$. The proof of this is easy: if $x\in A,y\in B,z\in C$, then $(x,y,z)\in A\times B\times C$.
We can write this schematically as:
$$\exists x\exists y\exists z\,((x,y,z)\in A\times B\times C)\implies \exists w\,(w\in A\times B\times C),$$
where we can see the pairing axiom (which asserts that $(x,y,z)$ is a set) doing the work of compressing $n$ existence quantifiers into one.
I want to make it clear that there is no actual choosing going on here. It is not required that there be any rule to find a particular element of $A$ - they might be "indistinguishable socks" for all we care. It doesn't matter, because the ambiguity of the original choices has been off-loaded to ambiguity in the output element of $A\times B\times C$.
The problem with this method is that pairing only works for $n=2$, or by induction, for finite $n$. Beyond this we must postulate an axiom or use additional structure in the $A_i$ sets in order to produce choice functions.
Comment: I upvoted this answer because I think it explains it the most clearly. That doesn't mean the other answers aren't good because it's easy for experts to show that adding the rule of inference of existential instantiation to ZF still ends up giving a formal system equivalent to ZF.
Comment: I find ZF a bit dubious. I don't really feel super sure that for any pair of nonempty sets at all, there exists an ordered pair of an element of the first set and an element of the second set. However, once you decide that the real meaning of that statement is a certain statement that's describable in the formal system of ZF, then it's easy to show that the formal system of ZF is consistent and proves that statement. I think this answer is a good answer because it's enough for its formal meaning to be provable in the formal system of ZF and it doesn't need to actually be true.
Comment: @Timothy The only thing ZF is bringing to the table is that for any two sets $a,b$ there exists a set that is the pair $(a,b)$. All the rest is pure first order logic. Let me put it a bit more logically. We want to prove $\exists a,a\in A,\ \exists b,b\in B\vdash\exists w, w\in A\times B$, and FOL says it suffices to prove $a\in A,\ b\in B\vdash\exists w,w\in A\times B$. Now the pairing axiom says that we can take $w=(a,b)$ because this is a set, and then the statement is true by definition.
Comment: I already saw how it was possible to prove it in ZF. I don't know how to write a formal proof in ZF but I seem to have good intuition of what's provable in it. If I learned how to write a formal proof in it, I'd probably be able to figure out how to write a formal proof of the statement that for any finite set of nonempty sets, there is a choice function, but that doesn't mean I will be willing to claim to have figured out a proof that ZF is a true model of set theory.
Comment: @Timothy My point is that you should actually look into formal proofs in first order logic first. In particular, see if you can understand the $\exists L$ rule in https://en.wikipedia.org/wiki/Sequent_calculus#Inference_rules , I think this will help. Because I would bet that your intuitions don't have any trouble with the claim that $a\in A,\ b\in B⊢∃w,w∈A×B$, because in this case the "choice" has already been made: you are given $a\in A$ and $b\in B$ and wish to prove the product is nonempty. The only thing between this and the full proof is that $\exists L$ rule of FOL.
Answer: If I buy a pair of white socks, and I have never worn either of them, then they don't have any distinguishing features. Nevertheless, people make these sort of choices on a daily basis.
You might argue, while indiscernible, the two socks surely have some feature which distinguishes them! And you'd be correct. Although you might not be able to actually point the finger and say "Aha! This is what distinguishes them!", and you might have to resort to something like their particles or some other microscopic-level sort of difference.
But if I now ask you to choose from several pairs at the same time, you first need to inspect each pair under a microscope (or some other more destructive tests) in order to be able to describe a choice process. Maybe in one pair the cotton impurity is higher in one, and maybe in another it is the same. So each pair needs to go under careful checks just so you can tell me what sock was chosen from each pair.
Of course, you can ditch this method, and just go "This sock, that sock, this sock, and that sock". But that is not going to work if you have infinitely many socks.
And indeed, in the formal version of the socks analogy—which is all that it is, an analogy, and we would do well to remember that—we have sets of two elements and we cannot choose from all these pairs simultaneously. Of course, given one pair, we can show there are differences between the two elements of the set, after all they are not the same element, but we cannot point at a single property that will work for all pairs at the same time. Which is why the axiom of choice is needed in such case.
Comment: Well, the key intuition is that proofs are finite. This is somewhat incorrect, since there can be non-standard integers, etc., so really this is ZF proving basic induction on the natural numbers (of the universe) and the fact that if you can choose from a family indexed by $I$, then you can choose by a family indexed by $I\cup\{I\}$ (since that's just one more element). But if that confuses you, fall back to the first sentence of this comment.
Comment: Thank you for your explanation. In your case, does AC only tells you that you can pull a sock out from infinite each pair, but still not sure of the pulling rule?
Comment: AC implies that there is a way, yes. But nobody said anything about no rule.
Comment: Thank you for your reply. one more dumb question, why is that the case is finite we can just say check one by one.  when it's infinite, we no longer accept this. Why we can't just say keep going with the same method. On what ground that we have this kind of restriction.
Answer:
But how can we even make a selection out of a single pair of socks if they don't have any distinguishing features? Is there another axiom being assumed here?

I wish to address a misconception here. The axiom of choice does not concern picking an object from indistinguishable ones, but rather that we do not need a way to distinguish them to be able to pick one of a collection. For example consider any infinite group $G$. There is no way you are going to be able to uniquely identify a non-identity element in $G$, because you know nothing about $G$. But the axiom of choice (applied to the non-identity elements in $G$) states that we can indeed pick one of them. Of course, since we only have one picking to do, we do not need the axiom of choice at all. But this illustration is to make clear what exactly is the issue of picking; the objects in each non-empty set may very well be distinguishable but we do not care.
Answer: This is a rider to the excellent answers given by Clive and Dustan. To address the case of a single pair of socks: assume you are given an unordered pair of socks $\{x, y\}$ such that the socks $x$ and $y$ have no distinguishing features. Then $x$ and $y$ are the same sock. In this case, you should take the sock back to the store and claim Leibniz's law of the identify of indiscernibles as an unchallengeable reason for a refund.
Comment: @RobinSaunders: that's what model theory using set-theoretic foundations is like. "Indistinguishable" in set theory has to mean "indistinguishable as sets" and if a model needs to contain $2$ objects with some property, then they will be distinguishable as sets, even if the abstract structure we are trying to model gives us no way to distinguish them.
Comment: @RobinSaunders: $i$ and $-i$ are only indistinguishable from the point of view of the first-order theory of fields. But to get the complex numbers we must have proven the existence of a **model** of the field axioms that contains the reals and has a square-root of $-1$. In any such model the two square-roots of $-1$ **will** be different. Labels are irrelevant. Just because conjugation is an isomorphism does not make $i$ and $-i$ in any such model indistinguishable, exactly like negation is an isomorphism on $(\mathbb{Z},<)$ but does not make $1$ and $-1$ indistinguishable.
Comment: @RobinSaunders: Also, as Rob says, there are certain practical issues in using pure set theory, since the axiom of extensionality implies that structures with different underlying sets are distinct even if there is an isomorphism between them. This is not a serious technical issue, since we can endeavour to prove theorems about the abstraction rather than a concrete representation. For example it is better to prove theorems about arbitrary structures isomorphic to $\mathbb{N}$ (or if possible just models of PA) rather than a specific representation of the natural numbers.
Comment: @RobinSaunders: we are taking about  set theory here. If you have constructed a set theoretic model of the complex numbers it will contain two distinct square roots of $-1$.  Set theory doesn't give you the option to abstract away representational differences. I would agree that this is from many points of view a weakness in set theory.
Comment: @RobinSaunders: Once again, as Rob says, you need to distinguish (pun not intended) between what the axiomatization can 'see' and what the meta-system can see. Worse still, the entire theory of the structure may be unable to distinguish between certain elements using a formula over the language, and these elements are called "indiscernibles" (see David Marker's introduction to model theory). For a simple example, in the graph that looks like o-o-o, there is no formula over the language of adjacency that distinguishes the 2 end nodes, but the meta-system considers them 2 distinct objects.
Comment: @RobinSaunders: I think it's fair to say that that is an open question. There is a recent initiative called [homotopy type theory](https://en.wikipedia.org/wiki/Homotopy_type_theory) in which logical equality can be seen as structural isomorphism, but it requires a major change of mindset from the set-theoretic approach.
Comment: I know you meant this as a joke, but this doesn't answer the question...
Comment: It isn't just a joke and it **does** answer the final part of the question (in a way that is intended to shake up the OP's thinking about number and identity).
Comment: Hmm I saw the last part of the question, but I feel it is better to address the misconception directly, so I've just done so in my answer. Thanks for bringing attention to it anyway.
Comment: @RobArthan: What if all the distinguishing features are themselves "symmetric with respect to the pair"? For example, what distinguishing feature between the complex numbers i and -i allows us to know which label to assign to which?
Comment: @user21820 I guess it depends on what you mean by "indistinguishable". Perhaps the formal terminology is in conflict with my intuition. For example, conjugation is certainly distinguishable from the identity (in any sense), and so the two square roots of $-1$ are distinguishable in the sense that conjugation transposes them but the identity does not. On the other hand, to actually make a concrete choice of one root rather than the other requires that the model we are using have some asymmetry "built into it" that has nothing to do with the theory that the model is intended as a realization of.
Comment: Thank you both for clarifying. Is there no less clunky ("structural"?) formalism for referring to objects which are distinct, but indistinguishable according to the theory we are interested in? And perhaps for keeping track of when we make an "arbitrary" choice between such objects, versus when there are more "canonical" ways of choosing objects?
Answer: Suppose discourse universe is formed by objects. Starting with
Axiom 1 (Empty set). There exists a set $\emptyset$ such which contains no elements, i.e., for every object we have $x\notin\emptyset$.
We can prove by contradiction the folling proposition:
Proposition 2 (Single choice).  Let $X$ be a non-empty set. Then there exists an objects $x$ such that $x\in X$.
Now we can show that for any collection of non-empty sets, we can choose a element for each set. (Use induction to prove it.)
Proposition 3 (Finite choice). Let $n\ge1$ be a natural number, and for each natural number $1\le i\le n$, let $X_i$ be a non-empty set. Then there exists an $n$-tuple $(x_i)_{1\le i\le n}$ such that $x_i\in X_i$ for all $1\le i\le n$. In other words, if each $X_i$ is non-empty, then the set $\prod_{1\le i\le n}X_i$ is also non-empty.
The axiom of choice asserts that this proposition is also true for infinite cartesian products.
Axiom 4 (Choice). Let $I$ be a set, and for each $\alpha\in I$, let $X_\alpha$ be a non-empty set. Then $\prod_{\alpha\in I}X_\alpha$ is also non-empty. In other words, there exists a function $(x_\alpha)_{\alpha\in I}$ which assigns to each $\alpha\in I$ an element $x_\alpha\in X_\alpha$.
This is very intuitively appealing axiom; in some sense one one is just apllying Proposition 2 over and over again. But it does not follow from the other axioms of set theory.


How to read a text file using pl/sql and do string search for each line

Question: I want to read text file and store(using clob datatype) its data in table . I want to do string comparison on loaded data.
Loaded text file contains DDL scripts and i want to get segregation of new/modified tables, new/modified indexes and constraints.
This can be done as Tom suggested Ask tom article
Challenge i'm facing here is that, i have to get above details before running those scripts, otherwise i would have used some DDL trigger to audit schema changes.
My qustion is , is it feasible to do string comparison on large text ? or is there any better alternative. please share your views/ideas on this.
Example file
<code>Create table table_one

Alter table table_two

create index index_table_one_idx table_one (column_one)

etc etc... 100s of statements
</code>
from above code i want to get table_one , table_two as modified tables, and index_table_one_idx as newly created index.
i want to achieve this by looking for 'create table','alter table' strings in large text file and get the table name using substring.
Comment: That's plenty of work to be done. You could split your assignment in a set of simple tasks (read text file, store text in CLOB, etc.), then do your work, and come back with a specific problem once your really stuck. Here it looks like you ask us to do your job.
Comment: Please read http://stackoverflow.com/help/how-to-ask before asking your next question.
Comment: i think you didn't understand the question.. i have put my analysis here and asked question later.. to avoid multiple clarifications from user who is willing to answer.   If you don't know the answer just move on.
Answer: It is perfectly feasible to do string comparison on large text.
There are a couple of different approaches. One is to read the file line by line using UTL_FILE. The other word be to load it into a temporary CLOB and process it in chunks. Probably the second way is is the better option. Make sure to use the DBMS_LOB functions for string manipulation, because they will perform better. Find out more.
Your main problem is a specification one. You need to isolate all the different starting points for SQL statements. If your script just as CREATE, ALTER and DROP then it's not too difficult, depending on how much subsequent detail you need (extract object type? extract object name? etc) and what additional processing you need to do.
If your scripts contain DML statements the task becomes harder. If the DDL encompasses programmatic objects (TYPE, PACKAGE, etc) then it's an order of magnitude harder.
Comment: Thanks... my scripts contains only DML that to modifies/creates tables , constraints , indexes .. if table is modified subsequently i want to get modified column names , index, constraints..


Memory usage doesn't decrease in node.js? What's going on?

Question: I am tracking the memory using task manager and my app is a webrtc app using socket.io.
So when I track the memory and open localhost, connect two browser windows, it obviously adds a little bit of memory. I think it starts at like 19.3 MB and then adds 0.5MB for each connection.
HOWEVER! When I close out of the connection, so no more localhost windows are open, it never decreases in memory usage! So if it goes up to 20MB or something, then it will stay there and never ever decrease.
Why is this? Is there some kind of memory leak?
By the way, is this the right way to track memory usage? Or should I not be using task manager?
Answer: What you are seeing is the total amount of memory allocated from the system by your application.  It is normal that it may go up with usage and then reach some sort of plateau and not go back down even though the application doesn't really need that much memory.
There are a number of reasons for this, but the main one is that most applications (including node.js) maintain a heap.  In that heap of memory are allocated blocks and free blocks.  When you request more memory than the heap contains, then the application requests more memory from the system and grows the heap.  When a number of those heap blocks are freed, they are not necessarily given back to the OS right away (or ever).
This doesn't mean the app is leaking memory because if more memory is requested from the heap, those free blocks in the heap will then get reused.
Any given heap manager has to decide when it is efficient to return memory back to the OS and when it is better to just hang onto the free memory for future use.  Most heap managers will have some sort of threshold that when more than xx% of memory in the heap is free, it will then figure out if it can give any memory back to the OS.  But, even then, giving memory back to the OS is not always easy or feasible because heaps can get fragmented with lots of smaller heap blocks allocated all over the heap with lots of free blocks in between, but not contiguous large block that could actually be given back to the OS.
In addition, many applications use various forms of caches.  These caches will likely all have some sort of maximum size, but if there is lots of free system memory available, these caches may grow fairly large.  For example, most template systems one might use with node.js cache parsed templates from disk.  As you visit more and more pages, the cache will grow larger and larger.
When looking from the outside like you are looking, the only real way to see if you actually have a problem is to just let the server run over thousands of requests and see if memory usage continues to grow and even grows beyond what the real system memory is (causing swapping).  If you see that happen, then you truly have some sort of memory leak.
Keep in mind that in a large memory system with an advanced memory manager, you actually WANT an application to use memory to improve performance as long as there is unused system memory (for things like caches) so seeing it take advantage of free system memory is a good thing.  You also want it to be smart enough to recognize when it's running out of free system memory and perhaps dial back what it uses to avoid paging to disk.

The only real way to see how much memory node.js is actually using and what it is using it for is to look at memory usage from inside of node.js using various memory analysis tools.  This can give you entire snapshots of what is in the heap and you can even do comparisons between two points in time in the heap to see what was allocated or freed between two points in time.  In my experience with the tools, the data is voluminous and it takes some time to understand how to read the data and draw some sort of useful conclusion.  Great tools - just takes some time to learn how to use it.
See this set of hits on node.js heap snapshot for lots of discussion about how to look "inside" of node.js at actual memory usage.
Comment: That's interesting. However, every time I connect a new connection (open more browser windows with localhost and connect them via webrtc) it always adds more memory, and doesn't reuse any of the other memory. Also, what is a good way to track down how much RAM the app uses, if this isn't a good way? Thanks!
Comment: Should mention that the magic phrase if OP wants to learn more is probably 'garbage collection'.  (This looks like a decent summary: https://strongloop.com/strongblog/node-js-performance-garbage-collection/)
Comment: Also: http://stackoverflow.com/questions/9152908/node-js-memory-leak-hunting-without-v8-profiler
Comment: @Hellothere - I've added a bunch more discussion about memory usage.


Webform show result table on webform node tpl

Question: I am trying to display results of a certain content type (webform: event)
So my idea is that i would embed the table into the the tpl (node--event.tpl.php)
I tried many different ways and the closest i can get is the following code
module_load_include('inc','webform','includes/webform.submissions');
$submissions = webform_get_submissions(array('nid'=> 4));

foreach ($submissions as $submission){
    foreach ($submission->data as $row=>$data){
        print '
';print_r($row);print '
';
        print '
';print_r($data);print '
';
    }
}

This works but just for a single node, in this case node 4, I would like to show this of the current node.
Answer: Try the Webform Report module, it looks perfect for what you need.
Or, Why not use views?
It would be easier to use webform 7.x-4.0-rc3 and create a view table for webform submission data. You can easily grab the separate values and arrange them into a table.
You also have the ability to create a reference so only the results from node 4 are being shown.
EDIT:
use $node->nid; , so...
$nid = $node->nid;

module_load_include('inc','webform','includes/webform.submissions');
$submissions = webform_get_submissions(array('nid'=> $nid));

foreach ($submissions as $submission){
    foreach ($submission->data as $row=>$data){
        print '
';print_r($row);print '
';
        print '
';print_r($data);print '
';
    }
}

Comment: The result has to be that there is a submission data tabel(Ex. the name and birth date of everyone who has signed up for the current event) on each eventpage.

How can I do that in views?
Or is this added in 7.x-4.0?
Comment: Create new view, change content to "webform submission data", click use fields, then click save. Webform submission data will now be available in "add field" as "webform-submission:data". Then just choose which field you want to use, e.g. name, or birth date.
Comment: But then you need to make a block for every event, it should show all fields except a few (but thats probably css) on every event
Comment: I would just create a contextual filter on the view of "get content from url". In the block configuration, make it appear on all of your nodes of that content type. Then set the permissions of that block so only admin can see them. That way, an admin can easily navigate to an event sign up page, and get a quick and easy submissions table.
Comment: I expect you mean by [Webform submission data: Value] But you need to enter manually a nid so how can a contextual filter fix that?
Comment: I see, so are you building a different webform for every event? In that case, stick with your custom template, and use $node->nid to get the current node id. see edited answer
Comment: Yes sorry i didn't mention that! And do you have any idea how i can display this in a table with headings now? now i just get everything in a different array..
Comment: I've only done it in webform-submission.tpl.php, but i believe  would work. Views handles submission data, and tables really easily. I just cant think of a way to do it in your case
Comment: I'm sorry I used drupal mainly front-end till now so i don't realy have an idea what i should do with print drupal_render($renderable[FIELDNAME] ); .

Views does that great but indeed in this case i don't think there is a way in views.
Comment: Shouldn't i be using theme_webform_results_table($variables)? I think this renders the result table under "results"? But in that case what would i use for $variables?
Comment: You can use that function for building your own custom module, but not in the node template. See updated answer for the webform report module, it looks perfect.
Comment: It looked perfect at first but it creates an extra content type where a report for a specific form is created and only shown at the node of the new content type. But the module looks pretty easy so I am gonna try to manipulate it a little so it can be used for my purposes.
Answer: I guess this is gonna hurt a lot of eyes but it works perfect for my case.
This is not the way I am suppose to work in drupal so if anyone can (help me) convert this to a hook or small module, i would love that.
I added the following code to my node--event.tpl.php to show a table of all results for the current node without a few unwanted results like e-mail.

        // Create connection
        $con=mysqli_connect("******","*******","********","*********");

        // Check connection
        if (mysqli_connect_errno()) {
          echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }
        // Get submitted data from current nodeform
        $result = mysqli_query($con,"SELECT data, cid, sid, nid FROM webform_submitted_data WHERE nid=".$nid);
        $data = array();
        $i =0;
        while($row = mysqli_fetch_array($result)) {
          $data[$i]['data'] = $row['data'];
          $data[$i]['sid'] = $row['sid'];
          $data[$i]['cid'] = $row['cid'];
          $data[$i]['nid'] = $row['nid'];
          $i++;
        }
        // Get headers for submitted data
        $result = mysqli_query($con,"SELECT name, form_key, cid FROM webform_component WHERE nid=".$nid);
        $headers = array();
        while($row = mysqli_fetch_array($result)) {
          $headers[$row['cid']]['name'] = $row['name'];
          $headers[$row['cid']]['form_key'] = $row['form_key'];
        }

        // Declare variables for composing table
            //unwanted fields
            $unwanted[] = 'productid';
            $unwanted[] = 'e_mail';
            $unwanted[] = 'algemene_voorwaarden';
        $newCello = '';
        $newCellc = '	';
        $presid = (isset($data[0]['sid'])) ? $data[0]['sid'] : '' ;
        $tablehead = '
';
        $tabledata ='
';
        $even = TRUE;
        //render table
        foreach ($data as $key) {
            if ($key['sid'] != $presid) {
                $tabledata .= "
";
                $tabledata .= ($even) ? '
' : '
' ;
                $firstrow = TRUE;
                $even = ($even) ? FALSE : TRUE ;
            }
            //filter unwanted fields
            $formkey = $headers[$key['cid']]['form_key'];
            if (!in_array($formkey, $unwanted)) {
                //create table headers
                if (!isset($firstrow)) {
                    $tablehead .= $newCello;
                    $tablehead .= $headers[$key['cid']]['name'];
                    $tablehead .= $newCellc;
                }
                $tabledata .= $newCello;
                $tabledata .= $key['data'];
                $tabledata .= $newCellc;

                //Get current field sid to compare with the next
                $presid = $key['sid'];
            }
        }

        $tablehead .= '
';
        echo $tablehead;
        echo $tabledata;
        mysqli_close($con);
        ?>


Solving $\sin x = 4\sin10°\sin40°\sin(70°-x)$

Question: So, I have this equation:
$$\sin x = 4\sin10°\sin40°\sin(70°-x)$$
And I'm trying to solve for $x$. Apparently $x=20°$ is the (smallest positive) solution but I can't arrive at it. I'm not very comfortable with this kind of equation so I just try to simplify it using prosthaphaere-something formulas, yet I don't get anywhere but to a messier equation to deal with.
Can someone solve it or at least point me in the right direction? Also, if you could tell me where I can find some material on solving equations like this (I can only find high school trig), that'd be great. Thanks.
Comment: How many solutions are there on $(0^\circ,70^\circ)$? There must be exactly one using intermediate value concerns. It is clear that the smallest positive solution must be in this interval.
Comment: The prostaphaeresis is a little known historical curiosity that was used to perform multiplies before the invention of the logarithms. It is based on product/sum trigonometric identities. http://en.wikipedia.org/wiki/Prosthaphaeresis
Answer: Note: All the work here, is in degrees.
First off all it is easy to prove this identity:
$\sin(3x)= 4\sin(x)\cdot \sin(60^{\circ}-x) \cdot \sin(60^{\circ}+x)$.
Now, $$ \sin x = 4\sin10°\sin40°\sin(70°-x) $$
$$ \sin x = \frac{4\sin10°\sin50°\sin(70^{\circ})}{\sin(50)\sin(70)} \cdot \sin(40)\cdot \sin(70-x)= \frac{\sin(30)\sin(40)\sin(70-x)}{\sin(50)\sin(70)}$$
$$ \frac{\sin(30)\sin(40)\sin(70-x)}{\sin(50)\sin(70)} = \frac{\sin(30)\sin(40)\sin(70-x)}{\sin(50)\cos(20)} = \frac{\sin(20)\sin(70-x)}{\sin(50)} $$
So we are left with,  $\sin(x) \sin(50) = sin(20) \sin(70-x)$ . Its clear that $x=20$.One can prove it is only solution, by expanding ..
$$\sin(x)\sin(50) = \sin(20)\sin(70)\cos(x)-\sin(20)\sin(x)\cos(70)$$
$$ \sin(70) \cos(20) - \sin(20)\cos(70) = \sin(70-20)= \sin(20)\sin(70)\cot(x)-\sin(20)\sin(70) $$
Thus $ \tan(x)  = \tan(20) $
Comment: Mind sharing where the first identity came from?
Comment: @DeathkampDrone, http://www.cut-the-knot.org/arithmetic/algebra/sin3x.shtml
Comment: Sorry, earlier there was some typo , now its right :) .
Proof:
$$4\sin(x)(\sin(60)\cos(x)-\sin(x)\cos(60))(\sin(60)\cos(x)-\sin(x)\cos(60)) = 4\sin(x)(\sin^2(60)\cos^2(x)-\sin^2(x)\cos^(60)) = \sin(x)(3\cos^2(x)-\sin^2(x)) = 3\sin(x) - 4 \sin^3(x) = \sin(3x)$$
Comment: And how can we, poor mortals, make the connection between this lemma and the starting equation ?
Answer: Using Werner Formulas,
$$2\sin10\sin40=\cos30-\cos50$$
Again, $$4\sin10\sin40\sin(70-x)=2(\cos30-\cos50)\sin(70-x)$$
$$=\sin(100-x)+\sin(40-x)-[\sin(120-x)+\sin(20-x)]$$
Now,
$$\sin x=4\sin10\sin40\sin(70-x)$$
$$\iff\sin x=\sin(100-x)+\sin(40-x)-[\sin(120-x)+\sin(20-x)] $$
$$\iff\sin x-\sin(40-x)=[\sin(100-x)-\sin(120-x)]+\sin(x-20) $$
$$\iff2\sin(x-20)\cos20=-2\sin10\cos(110-x)+\sin(x-20)$$
As $\displaystyle\cos(110-x)=\cos\{90-(x-20)\}=\sin(x-20),$ this becomes
$$\sin(x-20)(2\cos20-1)=-2\sin10\sin(x-20)$$
$$\iff\sin(x-20)(2\cos20-1+2\sin10)=0$$
But $\displaystyle\cos20+\sin10=\cos20+\cos80=2\cos50\cos30=\sqrt3\cos50\ne1$
$\displaystyle\implies\sin(x-20)=0\implies x-20=180^\circ n+20$ where $n$ is any integer
Comment: Thank you! Upvoted good/informative answers but this one serves me best since it doesn't require a calculator or memorizing more identities. (:
Answer: A way to address such trigonometric equations is to express everything in terms of the sine and cosine of the unknown. In your case, you can get rid of the argument $70°-x$ using the angle subtraction formula.
So, develop $$\sin x=4\sin10°\sin40°\sin70°\cos x-4\sin10°\sin40°\cos70°\sin x.$$
Doing that, you obtain a linear trigonometric equation of the form
$$A\cos x+B\sin x=C,$$ for which a general solution is known.
But your case is simpler, as $C=0$, and you directly derive
$$\tan x=\frac{4\sin10°\sin40°\sin70°}{1+4\sin10°\sin40°\cos70°}.$$
Using a calculator, you find $x=20°$.
As $\sin x=0$ is not a solution, you didn't change the equation by this transformation. And given that the tangent function has a half turn period, the complete solution is
$$x=20°+180°k.$$
Now you easily prove that $x=20°$ is an exact solution with
$$4\sin10°(\sin40°\sin50°)=4\sin10°\frac12(\cos10°-\cos90°)=2\sin10°\cos10°=2\frac12(\sin20°-\sin0°)=\sin20°,$$
by two applications of the the prosthaphaeresis formulas.
Answer: Hint: Use the fact that $\sin{x-y}=\sin x \cos y-\cos x \sin y$ to expand $\sin(70°-x)$. From there you should be able to solve for $x$.
Comment: Sorry, but I fail to see how it helps. I've tried doing that before, just to get to $4\sin10°\sin40°(\sin70°\mathrm{cot}\,x + \cos70°) = 1$. It's nice because now we only have one $x$ to solve for but I'm still clueless as for how to solve for $x$ from there.
Comment: @DeathkampDrone you would then rearrange to get $\cot x$ on one side, then take the inverse cotangent.
Answer: $\newcommand{\+}{^{\dagger}}
 \newcommand{\angles}[1]{\left\langle\, #1 \,\right\rangle}
 \newcommand{\braces}[1]{\left\lbrace\, #1 \,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\, #1 \,\right\rbrack}
 \newcommand{\ceil}[1]{\,\left\lceil\, #1 \,\right\rceil\,}
 \newcommand{\dd}{{\rm d}}
 \newcommand{\down}{\downarrow}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,{\rm e}^{#1}\,}
 \newcommand{\fermi}{\,{\rm f}}
 \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,}
 \newcommand{\half}{{1 \over 2}}
 \newcommand{\ic}{{\rm i}}
 \newcommand{\iff}{\Longleftrightarrow}
 \newcommand{\imp}{\Longrightarrow}
 \newcommand{\isdiv}{\,\left.\right\vert\,}
 \newcommand{\ket}[1]{\left\vert #1\right\rangle}
 \newcommand{\ol}[1]{\overline{#1}}
 \newcommand{\pars}[1]{\left(\, #1 \,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\pp}{{\cal P}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\vphantom{\large A}\,#2\,}\,}
 \newcommand{\sech}{\,{\rm sech}}
 \newcommand{\sgn}{\,{\rm sgn}}
 \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}}
 \newcommand{\ul}[1]{\underline{#1}}
 \newcommand{\verts}[1]{\left\vert\, #1 \,\right\vert}
 \newcommand{\wt}[1]{\widetilde{#1}}\newcommand{\c}{^{\circ}}$
$\ds{\sin\pars{x} = 4\sin\pars{10\c}\sin\pars{40\c}\sin\pars{70\c - x}:\
     {\large ?}}$

\begin{align}
&4\sin\pars{10\c}\sin\pars{40\c}
={\sin\pars{35\c}\cos\pars{35\c - x} - \cos\pars{35\c}\sin\pars{35\c - x}\over
\sin\pars{35\c}\cos\pars{35\c - x} + \cos\pars{35\c}\sin\pars{35\c - x}}
\\[3mm]&={1 - \cot\pars{35\c}\tan\pars{35\c - x}\over
1 + \cot\pars{35\c}\tan\pars{35\c - x}}
\\[3mm]&\imp\quad{4\sin\pars{10\c}\sin\pars{40\c} + 1 \over 4\sin\pars{10\c}\sin\pars{40\c} - 1}
={2 \over -2\cot\pars{35\c}\tan\pars{35\c - x}}
\end{align}

$$
\tan\pars{35\c - x}=
{1 - 4\sin\pars{10\c}\sin\pars{40\c} \over 1 + 4\sin\pars{10\c}\sin\pars{40\c}}\,
\tan\pars{35\c}
$$

$$
x = 35\c -\ \underbrace{\arctan\pars{{1 - 4\sin\pars{10\c}\sin\pars{40\c} \over 1 + 4\sin\pars{10\c}\sin\pars{40\c}}\,
\tan\pars{35\c}
}}_{\ds{15\c - n\times 180\c\,,\quad n \in {\mathbb Z}}}
$$


HTML5 localStorage populate form onload

Question: I am following the example in the O'Reilly "Building iPhone Apps with HTML, CSS and Javascript," I want the values entered from a form to populate after the app closes and reloads, similar to a php 'sticky form.'
The only aspects I changed from the example is that saveSettings is called on submit, and here I have it called on unload (previously on input blur).
Load settings is called on document ready rather than submit.
pageInit is not working though I have jquery mobile installed.
     <!DOCTYPE html>

        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.css" />

                Input
                Output

            <input type="number" min="500" max="10000" step="100" name="monthly-income" id="monthly-income" value=""/>
            <input type="number"  min="500" max="10000" step="100" name="saving-per-month" id="saving-per-month" value=""/>
            <input type="number" min="16" max="75" step="1" name="current-age" id="current-age" value=""/>

Comment: The code you have there works on my iPhone running iOS5. The `window` `unload` event only occurs in certain circumstances though, refreshing is one of them. I put an an alert in the `saveSettings()` method and it appeared on refresh. After that any page load including force quitting Safari reloaded the data I had entered originally.
Comment: ok thank you, does this work in webkit browsers?
Comment: I don't have an Android handy to know if it'll work in the Android Browser (WebKit too) but it works in Safari on Mac OS X Lion and MobileSafari on iPhone (iOS5)
Answer: 1) You could place your page in internet, at best providing QR code to fast load on mobile (free QR generator here), so everyone could easily test
2) Did the browser settings require to grant the domain the rights to store values in local storage? If so, onunload there's no place to accept such request. Place in your ready function one storage instruction to test
3) unload is a bit unreliable (example - browser crash). Have you considered saving values on onblur on inputs? When in large textareas, saving the value in timer, even if user is still editing, is practicised.
4) This question considers also problems with unload function. Maybe future answer to this question will solve your problem?

HTML5 localStorage populate form onload


VB6 app hangs for a while on Windows Server 2008 sp1

Question: I have a problem with our VB6 app. It's an old system with lots of forms run on our customers Terminal Servers.
One customer has a problem and they have two Windows Server 2008 (32 bit), I don't know of anyone else with the same problem.
Other customers has XP, Win7, Windows Server 2003 and Windows Server 2008 (64 bit). I haven't found another Windows Server 2008
(32 bit) yet.
The problem is that after clicking the OK button in a small subformand there by closing it, the parent form is unresponsive
for 1-4 minutes. This happens most of the time but I haven't found a pattern.
When you click the OK button, it does a small SQL INSERT via ODBC in an Access Database. After that the subform is unloaded. The subform
consists of a couple of textboxes and a button. There are no problems with larger subforms with way more controls.
I've tried logging but the timespan between the start of the click event and closing of the subform and returning to the main
form is under 10 seconds. Still the mainform hangs and is "Not responding" for minutes.
I can add that the mainform is a subform to another large form but these two doesn't cause a problem, just the small subform.
I would be more than happy if someone could suggest something I could try.
Comment: Are you able to share any source code with us for the click event?  I maintain a VB6/Access application as well and I've come across similar behavior, though it seemed to center more on network security settings rather than Windows version.
Comment: I'm sorry but I can't share any source code. I'll tell if I find something useful with ProcMon.
Answer: I'd throw ProcMon at it and see what registry keys and files are being hit when you run this subroutine.


Equivalence of $\mathbb{F}_p$ and $\mathbb{Z}/p\mathbb{Z}$

Question: I feel like I have some fundamental misunderstanding and I'm not really sure how to phrase this question, but here's a first attempt. In Child's Concrete Introduction to Higher Algebra (ISBN: 978-0387745275), the author uses $\mathbb{F}_p$ and $\mathbb{Z}/p\mathbb{Z}$ interchangeably (especially when talking about polynomials with coefficients in some field $\mathbb{F}_p$). I understand that if $p$ is prime, then
$\mathbb{Z}/p\mathbb{Z}$ is a field, but why is correct to say something like this:
Let $f(x),g(x) \in \mathbb{F}_3[x]$ and $f(x)=3x^2 + 2$.  If $g(x)=2$, then $f(x)=g(x)$.  Basically, why can I apply modulo...aren't there fields that aren't the set of congruence classes modulo $p$ (which is how I understand $\mathbb{Z}/p\mathbb{Z}$)?  Is this some fundamental property of finite fields that I haven't read about yet?
Comment: There is only one field (up to isomorphism, as Andreas says!) of size $p$. This follows (non-trivially) from the statement that there is only one group of size $p$, which in turn follows from the theorem that the order of any given element of a group divides the order of the group (why?). For fields of size $p^n$ the statement is still true, but the theorem rapidly becomes non-trivial. Still, it's well-enough established that people speak of 'the' field $\mathbb{F}_{p^n}$.
Comment: The point is that, *up to isomorphism*, there is only one field with a given prime number of elements.
Answer: As Andreas and Steven said, there is only one field which $p$ elements, for $p$ prime, up to isomorphisms. This fact is part of a more general result:

If $p$ is a prime and $n\in \mathbb{N}$, there there exists exactly one field with $p^n$ elements, up to isomorphisms.

The symbol $\mathbb{F}_{p^n}$ denotes the field with $p^n$ elements.
It is important to notice that:

$\mathbb{Z}/p\mathbb{Z}$ is a field and has got $p$ elements, then it is isomorphic to $\mathbb{F}_p$.
$\mathbb{Z}/p^n\mathbb{Z}$ is not a field if $n>1$.

Hence you are allowed to think about $\mathbb{Z}/p\mathbb{Z}$ when you read $\mathbb{F}_p$, but if $n>1$ then the field $\mathbb{F}_{p^n}$ cannot be identified with the set of congruence classes modulo $p^n$.
EDIT: my first answer of the following question was not completely correct.
The answer to "aren't there fields that aren't the set of congruence classes modulo $p$?" is "yes, every finite field is (isomorphic to) a set of congruence classes". As Pedro Tamaroff pointed out in his comments, every finite field can be realized as a quotient: $\mathbb{F}_{p^n}$ is isomorphic to
$$ \frac{\mathbb{Z}_p[X]}{(f_n)}$$
where $\mathbb{Z}_p$ is the field $\mathbb{Z}/p\mathbb{Z}$ and $f_n$ is an irreducible polynomial of degree $n$ with coefficients in $\mathbb{Z}/p\mathbb{Z}$. Indeed, the above quotient is a field which is an extension of $\mathbb{Z}_p$ of degree $n$, so it has got $p^n$ elements.
However, it is true that there are finite fields that cannot be realized as sets of integer congruence classes.
Comment: @StevenStadnicki I never said integer congruence classes. You take the congruence classes of $\Bbb Z_2[X]$ under the congruence induced by the ideal $(X^2+X+1)$.
Comment: Every finite field can be obtained as a set of congruente clases, just not of that specific set.
Comment: @PedroTamaroff Are you sure about that?  How do you build integer congruence classes that satisfy the field equations for $\mathbb{F}_4$, say?
Comment: @PedroTamaroff Fair enough - I prefer to use 'equivalence class' for those and reserve 'congruence class' for integer congruence, but it's certainly not inappropriate terminology.
Answer: To flesh out my comment a bit, here's a proof of the result for $\mathbb{F}_p$, using the fact (which you should already know or should be able to easily prove) that there's only one group of order $p$ (and that group is commutative and generated by any of its elements):
We know that the additive group of our field of order $p$ must be $C_p$, and that any of the non-zero elements will generate it.  Our field has a unit element for multiplication; we'll label this unit (of course) as $\bar1$.  Now, since $\bar1$ generates the additive group, we can supply labels $\bar2=\bar1+\bar1$, $\bar3=\bar2+\bar1$, $\ldots$ for the rest of the elements of the group; note that they all obey $\overline{m+n}\equiv \bar{m}+\bar{n}\pmod p$, so that (at least additively) the bars are superfluous.  From here, we just work by induction using the distributivity of multplication over addition: for all $n\in C_p$, $\bar2\times \bar n=(\bar1+\bar1)\times \bar n = \bar n+\bar n \equiv \overline{n+n}\equiv \overline{2\cdot n\pmod p}$ (where the first multiplication is the one in our field and the last multiplication is the canonical one over $\mathbb{Z}$); then $\bar3\times \bar n=(\bar2+\bar1)\times \bar n=\bar2\times \bar n + \bar1\times \bar n \equiv \overline{2\cdot n + n} \equiv \overline{3\cdot n\pmod p}$, etc.  This provides a canonical isomorphism of our field's multiplication operation to multiplication mod $p$.


Nginx bad gateway and connection errors

Question: I've followed this tutorial for a basic installation of nginx.
I always get bad gateway errors and when i look at the logs i see :

[error] 3226#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client

Here is my nginx.conf and contents of my sites-available/defaults
nginx.conf,
defaults
I am also seeing this error :

conflicting server name "explorable.com" on 0.0.0.0:80, ignored

I am using Ubuntu 12.04, PHP5-FPM
Thank you!
Comment: Is `php5-fpm` actually running and listening to 127.0.0.1 on port 9000?
Comment: How do i know that? Sorry Im very much new to PHP-FPM /Nginx combo
Comment: The command `sudo netstat -tlnp | egrep "php5-fpm|9000"` displays any running process called `php5-fpm` or listening on port 9000.
Answer: Check if php-fpm is really running with e.g. ps aux | grep php. You can start and stop php-fpm with /etc/init.d/php-fpm start|stop|restart.

Nginx bad gateway and connection errors


Understanding why $|g(z)| < 1$ for all $z \in \Delta$ in the proof of Scwar'z Lemma in Palka's book *An Introduction to Complex Function Theory*

Question: This question concerns the proof of theorem 3.14 in pages 172-173, namely why the Maximum Modulus Principle implies that $|g(z)| < 1$ for all $z \in \Delta$ for a certain open disk $\Delta$ when $|g(z)||z| \leq |z|$ for all $z \in \Delta$.
To be specific, the theorem is that

Let  $f$ be an analytic function in the open disk $\Delta := \Delta(0, 1)$ such that $f(0) = 0$, $\forall z \in \Delta: |f(z)| \leq 1$. Then $|f'(0)|\leq 1$ and $\forall z \in \Delta:|f(z)|\leq |z|$.

Palka begins by defining $g:\Delta \to \mathbb{C}, g(z) =  \frac{f(z)}{z}$ when $|z| \in (0, 1)$ and $g(0) = f'(0)$. Such a $g$ is continuous in $\Delta$ and analytic in the punctured disk $\Delta^*(0, 1)$. Then Palka states the following:

(Question:) What I don't understand is why the Maximum Modulus Principle implies that $|g(z)| < 1$ for any $z \in \Delta$ when $g$ is not a constant function with a modulus one. The given Maximum Modulus Principle is that

Let a function $f$ be analytic in an open connected set $D \subset \mathbb{C}$. Suppose that there exists a point $z_0 \in D$ such that for all $z \in D:|f(z)| \leq |f(z_0)|$. Then $f$ is constant in $D$.
Comment: If $|g(z)| \leq 1$ and if it is not true that $|g(z)| < 1$ what can you say? Doesn't it tell you that $|g(z)|=1$ so the maximum of $|g(z)|$ is attained at $z$?
Answer: Are you ok with the proof that $|g(z)|\leq 1$ on $\Delta$? With this at hand, suppose that there is a $z_0\in \Delta$ with $|g(z_0)|=1$. Can you get a contradiction from this when $g$ isn't constant?
Comment: Yes I am okay with the proof you asked. To be certain that I understood the proof correctly, is the reason that such a $z_0 \in \Delta$ cannot exist the fact that then $g$ would have a modulus 1 on $\Delta$, when we know that for some $z \in \Delta$, $|g(z)| < 1$?
Comment: @CartesianBear Since $|g|\leq 1$ on $\Delta$, if there exists $z_0\in \Delta$ such that $g(z_0)=1$, then $g$ attains it's maximum in $\Delta$ and therefore is a constant, by the maximum modulus principle. It's exactly the formulation you quote at the end of your post, $|g(z)\leq |g(z_0)|$ ($=1$). Therefore such $z_0$ cannot exist, meaning $|g(z)|<1$ on $\Delta$.
Comment: I see. In that case, I still have to ask what condition does $|g(z)| = 1$ on $\Delta$ violate? I understand clearly what immediate effect the MMP has: when attaining its maximum on $\Delta$, $|g(z)|$ would be a constant. What I fail to understand is what is the prior assumption that is contradicted by this fact?


Way to Configure IP Geolocation Views & Maps Module via Script

Question: The module IP Geolocation Views & Maps has a ton of great features. By default, the data collection option: Employ the Google Maps API to reverse-geocode HTML5 visitor locations to street addresses is turned on.
Is there a way to turn off this option via a drush command, or through some code? I have automated our site setup process, and would like to ensure this option is turned off without requiring admins to click off the option in the admin UI.
Answer: You can use the drush variable-set command for this:
~$ drush help variable-set
Set a variable.

Examples:
 drush vset --yes preprocess_css TRUE      Set the preprocess_css variable to
                                           true. Skip confirmation if variable
                                           already exists.
 drush vset --exact maintenance_mode 1     Take the site offline; skips
                                           confirmation even if
                                           maintenance_mode variable does not
                                           exist. Variable is rewritten to
                                           site_offline for Drupal 6.
 drush vset pr TRUE                        Choose from a list of variables
                                           beginning with "pr" to set to
                                           (bool)true.
 php -r "print                             Set a variable to a complex value
 json_encode(array('drupal',               (e.g. array)
 'simpletest'));"  | drush vset
 --format=json
 project_dependency_excluded_dependencies
 -

Arguments:
 name                                      The name of a variable or the first
                                           few letters of its name.
 value                                     The value to assign to the variable.
                                           Use '-' to read the object from
                                           STDIN.

Options:
 --exact                                   The exact name of the variable to
                                           set has been provided; do not prompt
                                           for similarly-named variables.
 --format=<boolean>                        Format to parse the object. Use
                                           "auto" to detect format from value
                                           (default), "string", "integer" or
                                           "boolean" for corresponding
                                           primitive type, and "json" for JSON.
 --yes                                     Skip confirmation if only one
                                           variable name matches.

To use this, you need to figure out the machine name for the variable.  On system settings forms, this will be the $form key in the builder function.  You can also poke through the variable list from the Devel module, and look for the variable name there.  If you use Inspect Element (or whatever it is called in your browser), it will be the name attribute on the input or select element.
Comment: Using your detective support, I derived the following command: drush vset ip_geoloc_google_to_reverse_geocode 0
Answer: You can always add it to your settings.php and set it to off.
Look in "variables" table for the value you need and add, something like this:
$conf['name_of_variable'] = 'value_you_want';
Simple example: $conf['maintenance_theme'] = 'bartik';


Entity Framework 5.0 - Writing a query for many to many relationship

Question: I currently have the following Model and DB Context set up for my Entity Framework.
Relationship is as follows: TableA and TableB both have a many to many relationship.
DBContext:
 public partial class MyContext : DbContext
    {
        public MyContext (string connString)
            : base(connString)
        {
            this.Configuration.ProxyCreationEnabled = false;
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {

            base.OnModelCreating(modelBuilder);

            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

               modelBuilder.Entity<TableA>().HasMany(x => x.TableB).WithMany(
                x => x.TableA).Map(m =>
                {
                    m.ToTable("TableC");
                    m.MapRightKey("B_ID");
                    m.MapLeftKey("C_ID");
                });

        }

        public DbSet<TableA> TableA { get; set; }
        public DbSet<TableB> TableB { get; set; }

    }

Entities:
public partial class TableA
{
     public TableA()
     {
         this.TableB  = new List<TableB>();
     }

     [Key]
     public int A_ID { get; set; }
     public string A_Name { get; set; }

     public virtual ICollection<TableB> TableB { get; set; }
}

public partial class TableB
{
   public TableB()
   {
       this.TableA  = new List<TableA>();
   }

   [Key]
   public int B_ID { get; set; }
   public string B_Name { get; set; }

   public virtual ICollection<TableA> TableA { get; set; }
}

Note: Because Table C is a Pure Junction Table, Entity Framework does not require a Entity for it.
When I run the following Command:
MyContext.TableA.GetList();

It returns the list of Table A objects as needed, however for each of the objects in the list it does not include the list of TableB property indicated in the Entity Definition.
Same Behaviour happens when I do
MyContext.TableB.GetList();

Have I set this up correctly or am I missing some subtle setup?
Comment: It's just a guess, but lazy loading is probably disabled because you have set ProxyCreationEnabled to false. You either need to remove that line or eager-load the related information.
Comment: This appeared to have solved my issue. Please go ahead and submit this as an answer if you like.  Thanks Morten Mertner.
Comment: Thanks, just happy to have helped.
Answer: Lazy loading is probably disabled because you have set ProxyCreationEnabled to false. You either need to remove that line or eager-load the related information.


Good introductory tutorial on writing sty files for latex?

Question: Where do I find a good introductory tutorial on writing sty packages for latex?
Answer: This question comes up a lot and doesn't have a good answer. See, for example, the StackOverflow question "Advanced LaTeX Tutorial/Book".
My best advice is to read lots of packages sources, clsguide.pdf (it will be in your distribution), as much of the LaTeX sources (source2e.pdf) as makes sense to you, as well as TeX by Topic and any other TeX programming resources you have access to.
If you're particularly motivated you might like to read about the LaTeX3 programming bundle expl3, and other such programming-related packages such as etoolbox and etextools, which takes quite a different approach than expl3.
Comment: I was afraid this was the case. I read the question you reference, but I was hoping there was some specific resources on writing packages for LaTeX. Thanks for your help and your references, I will be sure to check them out.


Is it possible to merge acceptance probability with proposal distribution in Metropolis Hastings algorithm?

Question: For an ergodic Markov chain, it doesn't necessarily have to be $Detailed\ Balanced $ when it converges to stationary distribution, which means that:
$\pi(\theta)\ P(\theta^{\prime}|\theta) \neq \pi(\theta^{\prime})\ P(\theta|\theta^{\prime})$ ;
In the MH algorithm, however, by multiplying the acceptance rate $\alpha$ for both sides of the equation above, we can get a detailed balanced equation:
$\pi(\theta)\ P(\theta^{\prime}|\theta)\ \alpha(\theta^{\prime}|\theta) = \pi(\theta^{\prime})\ P(\theta|\theta^{\prime})\ \alpha(\theta|\theta^{\prime})$ ;
By forcing one of the $\alpha$ equal to 1, for instance, the one of RHS, we can derive the acceptance probability as:
$\alpha(\theta^{\prime}|\theta) = min\{1, \frac{\pi(\theta^{\prime})\ P(\theta|\theta^{\prime})}{\pi(\theta)\ P(\theta^{\prime}|\theta)}\}$;
So my questions are:

Can I interpret the $\alpha$ as the "transition probability", for the posterior probability distribution, from $P(\theta|x)$ to $P(\theta^{\prime}|x)$?
Is it possible to join the product of $\ P(\theta^{\prime}|\theta)\ \alpha(\theta^{\prime}|\theta)$ to make them one probability like $Q(\theta^{\prime}|\theta)$. So all we need to compute is $Q(\theta^{\prime}|\theta) =min\{1, \frac{\pi(\theta^{\prime})}{\pi(\theta)}\}$, without worrying about the proposal distribution? Besides, I think $Q(\theta^{\prime}|\theta)$ is more intuitively acceptable as a "transition probability".
Answer: I think in the setting of MCMC the term transition probability refers to the probability of transitioning from one point to another, which should be the $P(\theta'|\theta)$ term in your fist equation and the $Q(\theta'|\theta)=P(\theta'|\theta)\alpha(\theta'|\theta)$ term in the second.
The goal of sampling algorithms is to generate samples from a known (unnormalized) distribution. As you said $Q(\theta'|\theta)$ should be easy to compute, however it's usually not easy to be sampled from. That's why we need a proposal distribution (to be easy to sample from) and an acceptance probability (to satisfy the detailed balance).
Answer: The condition for the probability distribution with density $\pi(\cdot)$ to be stationary for the Markov transition kernel $K$ with density $k(\cdot|\cdot)$ is that, for all measurable sets $A$
$$\pi(A)=\int_A \left\{\int\pi(\theta)k(\theta'|\theta)\text{d}\theta\right\}\text{d}\theta'$$
so indeed detailed balance does not have to hold for $K$ to be a correct transition kernel.
In the Metropolis-Hastings special case, the transition kernel $K$ is decomposed as $$K(\text{d}\theta'|\theta)=\alpha(\theta'|\theta)P(\theta'|\theta)\text{d}\theta'+(1-\varrho(\theta))\delta_{\theta}(\text{d}\theta')$$where $\text{d}\theta$ denotes the dominating measure of the target distribution (Lebesgue, counting &tc.), $\delta_\theta$ denotes the Dirac mass at $\theta$ and $$\varrho(\theta)=\int \alpha(\theta'|\theta)P(\theta'|\theta)\text{d}\theta'$$is the average acceptance probability when the Markov chain is standing at $\theta$.
With regard to your questions,

$\alpha(\theta'|\theta)$ is customarily called the acceptance probability, not the transition probability as the Markov chain does not necessarily move from its current value $\theta$ to the next value $\theta'$, which can thus be rejected. The term transition probability is attached to the kernel $K$;
Computing the product $\alpha(\theta'|\theta)P(\theta'|\theta)$ may prove handy to decide on the acceptance or rejection of the proposed value $\theta$ but in most situations the proposed value $\theta'$ must be simulated first. In any case, (i) the acceptance probability does not become$$\min\{1,\pi(\theta')/\pi(\theta)\}$$and (ii) the product $\alpha(\theta'|\theta)P(\theta'|\theta)$ is not a probability distribution.

In a paper with Randal Douc, we devised an approach that relates to this product, called vanilla Rao-Blackwellisation by integrating out the rejection step. That is, we considered only the accepted values and weighted them by their estimated number of replications: since an MCMC estimator of $\mathbb{E}[h(\theta)]$ writes as
$$\hat{h}=\frac{1}{T}\sum_{t=1}^T h(\theta^T)$$
for a Markov chain $(\theta^t)$, it also writes as
$$\hat{h}=\frac{1}{T}\sum_{i=1}^{I_T} n_i h(\xi^i)$$
where the $\xi^i$'s are the distinct values in the sequence $\{\theta^1,\ldots,\theta^T\}$ and the $n_i$'s the numbers of times they are repeated. Since this number $n_i$ is a Geometric rv with probability $\varrho(\xi^i)$, its expectation is $1/\varrho(\xi^i)$, which can be unbiasedly estimated. This step improves the variance of the MCMC estimator, but does not modify running simulations from $P(\cdot|\theta)$.
There also exist other versions of the Metropolis-Hastings algorithm where the decision to reject is taken before the new value $\theta'$ is simulated from $P(\cdot|\theta)$, called delayed acceptance.


characteristic equation's solution

Question: Consider the characteristic equation for $\lambda \in \mathbb{C}$ $$\lambda = -e^{-\tau\lambda}\tag1$$
a) For $\lambda$ a root of (1), write $\lambda = x+iy$ and consider the real and imaginary part of (1). Rewrite (1) as a system of two equations.
b) Show that if $\lambda$ is a solution to (1) then $\bar\lambda $ is also a solution to (1).
I did the first part:
\begin{cases} x= -e^{-\tau x}\cos(\tau y) \\ y= e^{-\tau x}\sin(\tau y) \end{cases}
I really need help for the second part.
Comment: It seems obvious: if $(x,y)$ satisfies both equations, $(x,-y)$ does too.
Comment: @Bernard Yes I agree it's obvious that $\bar  \lambda$ satisfies the equation.
Answer: $${\lambda} = -e^{-\tau{\lambda}}$$
$$ {\lambda} = -e^{-\tau x}(\cos (y\tau)-i\sin (y\tau))$$
$$\bar {\lambda} = -e^{-\tau x}(\cos (y\tau)+i\sin (y\tau))$$
$$\bar {\lambda} = -e^{-\tau x}e^{iy \tau}$$
$$\bar {\lambda} = -e^{-\tau (x-iy)}$$
$$\bar {\lambda} = -e^{-\tau \bar {\lambda}}$$
If $\lambda $ is a solution, so is $\bar {\lambda }$. You can read this page too

Or more simply.
$${\lambda} = -e^{-\tau{\lambda}}$$
Change $ \lambda  \to \bar {\lambda}$
$$\bar {\lambda} = -e^{-\tau \bar {\lambda}}$$

characteristic equation's solution


is every path-connected covering of the Moebius strip a Galois cover?

Question: Let $p : E → M$ be a covering of $M$ the Moebius Sttrip such that $E$ is path connected.
Is this a Galois covering?
My intuition is there must be some non locally path connected coverings that are not Galois. I know little about coverings of Moebius band. I know that its universal covering is $\Bbb R\times [0,1]$.
Thanks for your help.
Comment: Since $M$ deformation retracts onto $S^1$ and a space's theory of covering spaces is determined by its fundamental group, I think you can equivalently ask the same for $S^1$ to simplify things.
Comment: Locally, a covering will look like the Moebius strip, hence it can't be nonlocally path connected. Now by William's comment, the fundamental group is abelian, so path connected coverings are all Galois
Answer: Hint: The inclusion $S^1 \to M$ as the zero section induces a bijection
$$ Cov(M)/\cong \to Cov(S^1)/\cong $$
where $Cov(X)/\cong$ is the set of isomorphism classes of covering spaces. Moreover a covering space of $M$ is connected (respectively regular) iff its restriction to $S^1$ is connected (resp. regular).

Solution to problem over $S^1$:
The connected covering spaces of $S^1$ are isomorphic to quotients of $\mathbb{R}$ by subgroups of $\mathbb{Z}$. The $n$-fold cover $\mathbb{R}/n\mathbb{Z} \to S^1$ has automorphism group $\mathbb{Z}/n\mathbb{Z}$ which acts transitively in each fibre.
I think you can run a similar argument on the universal cover $\mathbb{R}\times [0,1]$ of $M$. The covering is the quotient map of the relation $$(x, t) \sim (x + n, f^{(n)}(t))\text{ for }n\in\mathbb{Z}$$ where $f$ is the "flip" homeomorphism of the interval. The deck transformations are again $\mathbb{Z}$, which acts by $n\cdot(x, t) = (x + n, f^{(n)}(t))$.

Update: as per Max's comment to the original question, this also follows from the general theory: if $X$'s fundamental group is abelian then all its connected covers are regular.
The idea is that all the connected covers are quotients of the universal cover $p\colon\tilde{X}\to X$ by subgroups of $G=\pi_1(X)$. If $H$ is a subgroup of $G$ then the fibres of $\tilde{X}/H \to X$ will have an action of $G$ that looks like its action on the quotient set $G/H$; if moreover $H$ is normal then this action descends to the group $G/H$ and the fibres are "$G/H$-torsors" (i.e. have a free, transitive action of $G/H$) and in fact $G/H$ is isomorphic to the group of deck transformations, hence the covering is regular. Therefore if all subgroups are normal then all connected covers will be regular.
Comment: Yes it is because of this bijection. Given a subgroup $H$ we get a connected covering $\tilde{X}/H$, and if we had chosen a conjugate subgroup $H'$ the resulting covering spaces would be isomorphic. Conversely, given a connected covering space $p\colon P\to X$ it is isomorphic to the quotient $\tilde{X}/p_*(\pi_1 P)$. For a reference on the relation between normality of $H$ and regularity of $\tilde{X}/H$, check out Proposition 1.39 in the [Fundamental Group](http://pi.math.cornell.edu/~hatcher/AT/ATch1.pdf) chapter of Hatcher (page 71).
Comment: Actually both of the sections "Classification of Covering Spaces" and "Deck Transformations and Group Actions" in Hatcher (starting page 63) are very relevant to this discussion.
Comment: Thank you @William. I am trying to understand why connected covers are quotients of the universal cover by subgroups of $G=π_1(X)$. Is it because of the bijection between coverings isomorphism classes and $π_1(X)$ subgroups conjugacy classes? the theory behind is not clear in my head.


Angular observable subscription issue

Question: I am trying to use the observables the way that I don't have to worry about unsubscribing them. The way I got it setup is exactly the way based on this article which is on manner one.
Observable declaration
campaigns: Observable<ICampaigns[]>;

the http method:
  getCampaigns() {
    return this.http.get<ICampaigns>(this.BASE_URL + '/campaigns/');
  }

calling the getCampaigns method and assigning the values to the campaigns observable:
this.campaigns = this.getCampaigns();

I get this error underneath he call statement
Comment: should be ```return this.http.get(this.BASE_URL + '/campaigns/');```
Comment: and would be good of you mention the error and error line both, not just the error line.
Comment: Thanks @fatemefazli. That worked
Comment: your welcome, i posted as an answer.
Answer: should be:
getCampaigns() {
   return this.http.get<ICampaigns[]>(this.BASE_URL + '/campaigns/');
}

Angular observable subscription issue


In Python, how do you import objects without executing the other code?

Question: For example take a.py
stringcheese = "hi"
print("I don't want this printed")

and now b.py:
from a import stringcheese
print(stringcheese)

The output is:
I don't want this printed
hi

How can I just import stringcheese without executing a.py's code?
Answer: You can't. The top-level code for a module must be executed for the module to load in the first place.
Only put executable statements in the top-level of your module that you are fine with being executed on import.
Comment: Sorry, what does top level mean?
Comment: @POSUMSHREDER: Any module code outside of functions (the function objects are created, but their code isn't executed until you call the function).
Answer: POSUM SHREDER, you can use if __name__ == '__main__' construction to hide unwated executables from import, they still wll be executed if you call python a.py.
a.py
stringcheese = "hi"
if __name__ == '__main__' :
    print("I don't want this printed")

main.py
from a import stringcheese
print(stringcheese)

for more details please read What does if __name__ == "__main__": do?
Comment: Your answer is right but explain your answer a little don't just dump code, so others and the OP can learn
Comment: @Trigremm Your answer could still use more love, such as quickly explaining what `__name__` is in addition to the link. I'm +1-ing your answer for the editing effort though, it's a significant improvement over your initial version. Welcome to Stack Overflow.


Docker GPU enabled version (>19.03) does not load tensorflow successfully

Question: I want to use docker 19.03 and above in order to have GPU support. I currently have docker 19.03.12 in my system. I can run this command to check that Nvidia drivers are running:
docker run -it --rm --gpus all ubuntu nvidia-smi
Wed Jul  1 14:25:55 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 430.64       Driver Version: 430.64       CUDA Version: N/A      |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 107...  Off  | 00000000:01:00.0 Off |                  N/A |
| 26%   54C    P5    13W / 180W |    734MiB /  8119MiB |     39%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

Also, if run locally my module works with GPU support just fine. But if I build a docker image and try to run it I get a message:

ImportError: libcuda.so.1: cannot open shared object file: No such file or directory

I am using cuda 9.0 with tensorflow 1.12.0 but I can switch to cuda 10.0 with tensorflow 1.15.
As I get it the problem is that I am probably using a previous dockerfile version with commands which does not make it compatible with new docker GPU enabled version (19.03 and above).
The actual commands are these:
FROM nvidia/cuda:9.0-base-ubuntu16.04

# Pick up some TF dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential \
        cuda-command-line-tools-9-0 \
        cuda-cublas-9-0 \
        cuda-cufft-9-0 \
        cuda-curand-9-0 \
        cuda-cusolver-9-0 \
        cuda-cusparse-9-0 \
        libcudnn7=18.104.22.168-1+cuda9.0 \
        libnccl2=2.2.13-1+cuda9.0 \
        libfreetype6-dev \
        libhdf5-serial-dev \
        libpng12-dev \
        libzmq3-dev \
        pkg-config \
        software-properties-common \
        unzip \
        && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN apt-get update && \
        apt-get install nvinfer-runtime-trt-repo-ubuntu1604-4.0.1-ga-cuda9.0 && \
        apt-get update && \
        apt-get install libnvinfer4=4.1.2-1+cuda9.0

I could not find a docker base file for fundamental GPU usage either.
In this answer there was a proposal for exposing libcuda.so.1 but it did not work in my case.
So, is there any workaround for this problem or a base dockerfile to adjust to?
My system is Ubuntu 16.04.
Edit:
I just noticed that nvidia-smi from within docker does not display any cuda version:
CUDA Version: N/A

in contrast with the one locally run. So, this probably means that no cuda is loaded inside docker for some reason I guess.
Answer: tldr;
A base Dockerfile which seems to work with docker 19.03+ & cuda 10 is this:
FROM nvidia/cuda:10.0-base

which can be conbined with tf 1.14 but for some reason could not found tf 1.15.
I just used this Dockerfile to test it:
FROM nvidia/cuda:10.0-base
CMD nvidia-smi

longer answer:
Well, after a lot of trials and errors (and frustration) I managed to make it work for docker 19.03.12+cuda 10 (although with tf 1.14 not 1.15).
I used the code from this post and used the base Dockerfiles provided there.
First I tried to check the nvidia-smi from within docker using Dockerfile:
FROM nvidia/cuda:10.0-base
CMD nvidia-smi

$docker build -t gpu_test .
...
$docker run -it --gpus all gpu_test
Fri Jul  3 07:31:05 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 430.64       Driver Version: 430.64       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 107...  Off  | 00000000:01:00.0 Off |                  N/A |
| 45%   65C    P2   142W / 180W |   8051MiB /  8119MiB |    100%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

which finally seems to find cuda binaries: CUDA Version: 10.1.
Then, I made a minimal Dockerfile which could test the successful loading of tensorflow binary libraries within docker:
FROM nvidia/cuda:10.0-base

# The following are just declaring variables and ultimately use
ARG USE_PYTHON_3_NOT_2=True
ARG _PY_SUFFIX=${USE_PYTHON_3_NOT_2:+3}
ARG PYTHON=python${_PY_SUFFIX}
ARG PIP=pip${_PY_SUFFIX}

RUN apt-get update && apt-get install -y \
    ${PYTHON} \
    ${PYTHON}-pip

RUN ${PIP} install tensorflow_gpu==1.14.0

COPY bashrc /etc/bash.bashrc
RUN chmod a+rwx /etc/bash.bashrc

WORKDIR /src
COPY *.py /src/

ENTRYPOINT ["python3", "tf_minimal.py"]

and tf_minimal.py was simply:
import tensorflow as tf

print(tf.__version__)

and for completeness I just post the bashrc file I am using:
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ==============================================================================

export PS1="\[\e[31m\]tf-docker\[\e[m\] \[\e[33m\]\w\[\e[m\] > "
export TERM=xterm-256color
alias grep="grep --color=auto"
alias ls="ls --color=auto"

echo -e "\e[1;31m"
cat<<TF
________                               _______________
___  __/__________________________________  ____/__  /________      __
__  /  _  _ \_  __ \_  ___/  __ \_  ___/_  /_   __  /_  __ \_ | /| / /
_  /   /  __/  / / /(__  )/ /_/ /  /   _  __/   _  / / /_/ /_ |/ |/ /
/_/    \___//_/ /_//____/ \____//_/    /_/      /_/  \____/____/|__/

TF
echo -e "\e[0;33m"

if [[ $EUID -eq 0 ]]; then
  cat <<WARN
WARNING: You are running this container as root, which can cause new files in
mounted volumes to be created as the root user on your host machine.

To avoid this, run the container by specifying your user's userid:

$ docker run -u \$(id -u):\$(id -g) args...
WARN
else
  cat <<EXPL
You are running this container as user with ID $(id -u) and group $(id -g),
which should map to the ID and group for your user on the Docker host. Great!
EXPL
fi

# Turn off colors
echo -e "\e[m"


Selenium Basico Python

Question: Saudações, sou iniciante em Selenium e segue abaixo o meu script:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time

links=['']
for link in links:

    browser=webdriver.Chrome(r'C:\Users\Administrador\Downloads\chromedriver.exe')
    browser.execute_script("window.open('https://www.onlinevideoconverter.com/pt/youtube-converter');")
    time.sleep(1)

    ak=browser.find_element_by_id('texturl')
    ak.send_keys(link)

    au = WebDriverWait(browser, 30).until( EC.element_to_be_clickable((By.XPATH, '//*[text() = "Começar"]')) )
    au.click()

    af = WebDriverWait(browser, 90).until(
    EC.presence_of_element_located((By.ID, 'downloadq'))
    )

    browser.execute_script('arguments[0].click();', af)

Que basicamente pega o link do download e o faz automaticamente.
O problema que acontece é que quando uso browser.execute_script("window.open('https://www.onlinevideoconverter.com/pt/youtube-converter');") o método ak=browser.find_element_by_id('texturl') não é carregado. Mesmo usando o time.sleep.
Queria saber se é possível resolver sem usar o browser.get('https://www.onlinevideoconverter.com/pt/youtube-converter')
O que está de errado?
Answer: O problema é que ao usares o método window.open() o browser abre uma nova janela, então tens de dar instrução ao teu webdriver para mudar o foco para essa nova janela:
browser = webdriver.Chrome(r'C:\Users\Administrador\Downloads\chromedriver.exe')
browser.execute_script("window.open('https://www.onlinevideoconverter.com/pt/youtube-converter');")
time.sleep(1)

new_window = browser.window_handles[1]
browser.switch_to.window(new_window)

ak = WebDriverWait(browser, 90).until(EC.presence_of_element_located((By.ID, 'texturl')))
ak.send_keys(link)

Selenium Basico Python


How to detect Heteroscedasticity in a residual plot?

Question:
In this residual plot, both the increase and the decrease in the y variables are observed. In this case, how do you conclude whether heteroscedasticity exist or not? I am not sure if I can just simply conclude that overall the value of y variable increases as the value for x variable increases. In this case, do you assume no conclusion can be drawn ?
Comment: You don't say what these are residuals from: I guess plain or vanilla regression in which price or value of property is the response.. The "y variable" is the residual. Putting a guide line on the graph at residual = 0 is often a good idea. Here although formal tests might appeal to some, informal examination would be enough for me: this is strong heteroscedasticity. The nature of your predictor and how it behaves in many analyses (a measure of area) suggests working with log area as well as using a generalised linear model with log link for price or value.
Answer: To my eyes the main body  suggests increased variability with increased X (square feet of footage).
Answer: I would split the data set with respect to SQFT into - let's say - 10 intervals. Then I would compute the variance of RESID in each interval, and you will see that the variance varies substantially.
edited after proposition by Nick Cox
Answer: When you look at residuals judgement is inherently involved. You can try the White's test for heteroscedasticity if you want a formal test (but it tests simultaneously for a misspecified model so you can not be sure what causes the results unless you are sure your model is not misspecified). You could also try one of the transformations or methods recommended with heteroscedasticity and see if the problem goes away when you transform the data... I suggest using White standard errors if nothing else  because you might have hetero....


Shinken - Anyone using it?

Question: I've recently discovered Shinken, which is a new implementation of Nagios using python. Shinken "divides" Nagios in 5 different types of daemons, each one performing separated tasks. I haven't tried it yet but for what I've seen the whole architecture idea seems great to me (it works the Unix way: one process, one task), but the project seems a little "green" yet.
So, has anyone tried Shinken? What's your opinion?
Comment: They weren't kidding when they said not ready for production. Documentation is quite incomplete (many sections still refer to Nagios). This definitely sounds promising though. Fast, reliable, redundant, what else could one ask for?
Comment: Add me to the tester list.
Comment: Guess I'll have to make my own tests :)
Comment: interesting... I will try it.
Comment: Very nice. I will definitely give it a try and report back. I see this at the bottom though:
> It's not ready for production environments, but it's good enough for QA!
Comment: I think this is a discussion that fits for a forum or something, but it's not a solvable question for which this site is intended!
Answer: Shinken is now used in small and large enterprise environments.
In March 2012, version 1.x was released and is considered stable with all features working as advertised.
The main documentation does have many references to Nagios, but most of the configuration -is- the same as Nagios. Shinken specific documentations has been improved and reorganized quite a bit. (some spell checking and style passes have been done, but it's a wiki so any spell checking is welcome. ;-))
Shinken is pure open-source with a high development velocity and the devs are industry pros, so it is a project to try and see if there is a fit with your requirements.
Cheers
Answer: So I've been playing with Shinken for a few days now. Seems to work as advertised with very low resource utilization, which is always a plus. The software is definitely not ready for production though and is very rough around the edges. This just replaces the core Nagios engine, as you still need an external web interface to interact with it (of which there are plenty of alternatives). Documentation really needs to be updated and spell checked :D
This is a very promising project though, one that I will keep a close eye on.
Answer: I'm not using it quite yet, but the idea is fascinating. I'll be working with the project owner to update documentation, as the project has developed quickly.
Has anyone used it since May? I've only run the installation; I haven't set up monitoring yet.

Shinken - Anyone using it?


Como ajustar altura da div conforme o texto?

Question: Criei uma div com largura definida, porém quando insiro uma palavra muito grande o texto continua saindo da div, como fazer para palavra continuar na linha de baixo?
Comment: só e você não definir a altura da div
ou usar o overflow hiden
Answer: Use:
word-wrap: break-word;

nessa div.
Comment: Funcionou perfeitamente no ie7, ie8, ie9, e ie10 :) @utluiz
Comment: http://caniuse.com/#search=word-wrap. Esse site é muito  bom para verificar a compatibilidade.
Comment: +1 funciona perfeitamente no Firefox e Chrome. Alguém poderia verificar a compatibilidade no IE? Fiz um exemplo: http://jsfiddle.net/tBNyz/
Comment: @PauloRoberto Obrigado!
Answer: Para resolver isso eu sempre faço uso da propriedade float:.
Por exemplo:
.minhaDiv { float:left; width:200px; }

Toda vez que o seu texto chegar perto do tamanho dessa div, ela irá "quebrar" para a linha de baixo.
Comment: Isso não funciona se tiver uma palavra maior que a div.


SQL count Occurency trouble

Question: I'm pretty new in the SQL world and i have some troubles about counting some row. I explain myself:
I have a DB like this:
NAME | (somenumbers)|
L1   | 2
L1   | 2
L2   | 3
L3   | 1
L3   | 1
L3   | 1

I expected result like this [L1:4,L2:3,L3:3], i have tried to read and test some count, group by or distinct but I am missing something. So if some people can help me, i would appreciate.
Answer: use sum() instead count()
select name,sum(somenumbers) from table_name
group by name

Comment: Damn it i feel dumb to bother you with that stupid little word, This work perfectly Thanks man for this fast answer !

SQL count Occurency trouble


Lib clipboard doesnot work inside of Promise

Question: I'm working with Angular 1 and clipboard.js in order to copy some data after a rest call.
My code looks like this:
clipboard.copy("Some random text"); //works!

service.getEmails(payload).then(function(emails){

    clipboard.copy("Some random text 2"); //error!

}).catch(function(error){

});

It just work outside the rest call.
The error is:
Uncaught (in promise) Error: Unable to copy.
Perhaps it's not available in your browser?

About the clipboard lib:
bower install clipboard.js --save

Do you have any idea of what it is?
Comment: What kind of promise does your `service.getEmails()` return? If it's just an ES6 promise and not made by any library, your browser might not support it yet. [Check the table here](http://caniuse.com/#feat=promises) for supported browsers.
Answer: The clipboard copy function must be invoked in a click handler (called by an user's action), as you can see here, which says:

"Just remember it has to be in a click event, as clipboard access
  requires user action.".

Unfortunately, this restriction is related to security issues.