Continuous Extension of Densely Defined Continuous (but not Uniformly Continuous) Function. 
*

*Here https://math.stackexchange.com/q/76864 for example is the proof that a uniformly continuous function on a dense subset of a metric space to a compact space can be uniquely extended to the whole space.

*And,  $f: \mathbb R \setminus 0 \to \mathbb R$ is continuous on its domain but doesn't have a continuous extension to all $\mathbb R$ (in which $\mathbb R \setminus 0$ is dense). One sees that $f$ is not uniformly continuous on its given domain and its range is not compact. So, this result is not unexpected in the context of (1).

*Then consider $f: \mathbb Q  \to \mathbb R: f(q) = q^2$. Here $f$ is continuous but not uniformly so and the range is not compact. But $f$ does have a unique continuous extension to all $\mathbb R$, being the well known $f(x) = x^2$.


So my question is whether there is an easily stated condition for the extension of a densely defined continuous function which is not uniformly continuous ?
I note in case (3) that if one considers any closed interval $N = [-n, n] \subset \mathbb R$ then in the subspace topology,  $f: \mathbb Q \cap N  \to \mathbb R: f(q) = q^2$ we have $f$ is uniformly continuous and the range is a compact subset of $\mathbb R$.  Then $f$ has a continuous extension on every interval $N$ and therefore on $\mathbb R$.
Does this generalize in some way ?
 A: One of the few really general criteria I know (besides the classic and very useful uniform continuous one, where the range need not be compact but complete metric), is for compact Hausdorff co-domain:

Let $A$ be a dense subset of a space $X$ and $Y$ compact Hausdorff.
  Also suppose $f:A \to Y$ is a continuous function.
  Then $f$ can be (automatically uniquely) extended to a function from $X$ to $Y$ iff for every pair $B_1, B_2$ of disjoint closed subsets of $Y$, $f^{-1}[B_1]$ and $f^{-1}[B_2]$ have disjoint closures in $X$.

For a proof, see Engelking General Topology, 2nd ed. Thm. 3.2.1, and is due to Taimanov (Russian paper, reference in Engelking), or independently Eilenberg and Steenrod (the book Foundations of Algebraic Topology), both in 1952.
A very specific one, for homeomorphisms on subsets of complete metric spaces, is Lavrentiev's theorem:

Let $X$ and $Y$ be complete metric spaces, and $f:A \to B$ be a homeomorphism between subsets $A \subseteq X, B \subseteq Y$. Then there are $G_\delta$ sets $A^\ast$ and $B^\ast$ of $X$ resp. $Y$ such that $A \subseteq A^\ast$ and $B \subseteq B^\ast$ and a homeomorphism $f^\ast: A^\ast \to B^\ast$ extending $f$.

So at least for your example 3. you have a guaranteed extension from $\mathbb{Q}^+$ and $\mathbb{Q}^-$ (on which your $f$ is a homeomorphism with a subset of $\mathbb{R}$) to some larger $G_\delta$ subset ($\mathbb{Q}$ is not a $G_\delta$ in the reals, as you probably know), which you can glue together at $0$. You could see 3. as a map to the two-point compactification of the reals, $Y=[-\infty, +\infty]$, and show the above closed-set criterion, to extend $f$ and then argue no point can map to $\pm \infty$, e.g. 
To see that $f(x)= \frac1x$ cannot be extended from $\mathbb{R}\setminus\{0\}$ to $\mathbb{R}$ (which I suppose was your intended example), try the inverse images of $B_1 = \{2z: z \in \mathbb{Z}\}$ and $B_2 = \{2z+1: z \in \mathbb{Z}\}$ and see that $0$ is in the closure of $f^{-1}[B_1]$ and $f^{-1}[B_2]$, e.g.; of course you can also use sequences to refute it.
