TITLE: Inverse of Heine–Cantor theorem
QUESTION [5 upvotes]: We have by  Heine–Cantor theorem that:

If $M$ and $N$ are metric spaces and $M$ is compact then every continuous function $f : M \to N$, is uniformly continuous.

Is the inverse of this theorem is satisfied?

REPLY [7 votes]: Let $(M,d)$ be a metric space that is not compact and has no isolated points.
Then there exists a countable discrete subspace $Z$.
For this, there exists an enumeration $Z=\{z_n\mid n\in\mathbb N\}$ and radii $ r_n>0$ such that $Z\cap B(z_n,r_n)=\{z_n\}$. Then the $B(z_n,\frac12r_n)$ are pairwise disjoint. 
We may assume wlog. that $r_n\to 0$.
Then for any $x\in M$, there exists $r>0$ such that $B(x,r)$ intersects only finitely many $B(z_n,\frac12r_n)$.
Therefore if for each $n$ we have a continuous function $f_n\colon M\to\mathbb R$ with $f_n(x)=0$ for all $x$ with $d(x,z_n)\ge \frac12r_n$, then the sum
$$\tag1f(x):=\sum_{n\in\mathbb N} f_n(x)$$
is in fact locally finite (that is each point has a neighbourhood where all but finitely many summands are identically $0$), hence continuous.
Since the $z_n$ are not isolated, we find $y_n$ with $0<d(y_n,z_n)<r_n$ and can define
$$f_n(x)=\max\left\{0, 1-\frac{d(x,z_n)}{d(y_n,z_n)}\right\}.$$
With this choice of $f_n$, the function $f$ is not uniformly continuous: No matter how small we choose $\delta>0$, we will find $n$ with $r_n<\delta$ and hence $d(y_n,z_n)<\delta$. But $f(y_n)=f_n(y_n)=0$ and $f(z_n)=f_n(z_n)=1$.
We also note that pointwise at most one summand in $(5)$ is nonzero, hence $0\le f(x)\le 1$ with our choice of $f_n$.
Conclusion: If $(M,d)$ is a metric space without isolated points and every continuous function $f\colon M\to\mathbb [0,1]$ is uniformly continuous, then $M$ is compact.