Computing $\int_{-\infty}^\infty \frac{\sin x}{x} \mathrm{d}x$ with residue calculus
Since $e^{iz}$ is small in the upper half plane but large in the lower, and $e^{-iz}$ is small in the lower half plane but large in the upper, you cannot handle both terms with the same contour, thus you must separate the two parts, and that means you get a pole in $z = 0$ for the integral. Thus you must treat the pole somehow. One way is to shift the contour of integration away from the real axis like robjohn did. Another way is to treat the integral as a principal value integral.
Since the integrand is real, we have
$$\begin{align} \int_{-\infty}^\infty \frac{\sin x}{x}\,dx &= \operatorname{Im} \operatorname{p.v.} \int_{-\infty}^\infty \frac{e^{ix}}{x}\,dx\\ &= \operatorname{Im} \lim_{\varepsilon\searrow 0} \int_{\lvert x\rvert \geqslant \varepsilon} \frac{e^{ix}}{x}\,dx\\ &= \operatorname{Im} \lim_{\substack{\varepsilon\searrow 0\\ R\nearrow\infty}} \int_{\varepsilon \leqslant \lvert x\rvert \leqslant R} \frac{e^{ix}}{x}\,dx, \end{align}$$
which allows us to consider only one exponential for the sine.
To compute the latter integral, we close the contour by adding a semicircle $C_\varepsilon$ of radius $\varepsilon$ around $0$ in the upper half plane, and either a semicircle of radius $R$ around $0$ in the upper half plane, or three straight line segments connecting $R,R+iR$, $R+iR,-R+iR$ and $-R+iR,-R$ respectively; call the latter contour $C_R$, whichever of the two you choose. Let $C$ be the closed contour obtained from joining the two intervals on the real axis, $C_\varepsilon$ and $C_R$. Since the integrand is holomorphic in a neighbourhood of the region bounded by $C$, Cauchy's integral theorem asserts
$$\int_C \frac{e^{iz}}{z}\,dz = 0,$$
and hence
$$\int_{-\infty}^\infty \frac{\sin x}{x}\,dx = -\operatorname{Im} \lim_{\substack{\varepsilon\searrow 0\\ R\nearrow\infty}} \left(\int_{C_R} \frac{e^{iz}}{z}\,dz + \int_{C_\varepsilon} \frac{e^{iz}}{z}\,dz\right).$$
By Jordan's lemma, or an elementary estimate if we chose the rectangular $C_R$, we have
$$\lim_{R\to\infty} \int_{C_R} \frac{e^{iz}}{z}\,dz = 0.$$
Parametrising $C_\varepsilon$ by $\varepsilon\cdot e^{i(\pi-t)}$, we see
$$\lim_{\varepsilon \searrow 0} \int_{C_\varepsilon} \frac{e^{iz}}{z}\,dz = -\pi ie^{i\cdot 0} = -\pi i,$$
and hence overall
$$\int_{-\infty}^\infty \frac{\sin x}{x}\,dx = \pi.$$
Before we use $\sin(x)=\frac{e^{ix}-e^{-ix}}{2i}$, we should move the contour so that it does not cross the origin. One way to do this is to use the contour $$ [-R,R]\cup\color{#C0C0C0}{[R,R-i]}\cup[R-i,-R-i]\cup\color{#C0C0C0}{[-R-i,-R]} $$ and notice that since $\frac{\sin(x)}{x}$ has no poles, the integral along the contour is $0$. Furthermore, the integral along the grayed out pieces tend to $0$ as the integrand is $\sim\frac1R$ along a length of $1$. This tells us that $$ \int_{-\infty}^\infty\frac{\sin(x)}{x}\,\mathrm{d}x =\int_{-\infty-i}^{\infty-i}\frac{\sin(x)}{x}\,\mathrm{d}x $$ Now, we can use $\sin(x)=\frac{e^{ix}-e^{-ix}}{2i}$. We will use the contours $$ U=[-R-i,R-i]\cup Re^{[0,i\pi]}-i $$ and $$ L=[-R-i,R-i]\cup Re^{[0,-i\pi]}-i $$ Since the integrands vanish quickly on the circular parts, we get $$ \begin{align} \int_{-\infty}^\infty\frac{\sin(x)}{x}\,\mathrm{d}x &=\frac1{2i}\int_U\frac{e^{iz}}{z}\,\mathrm{d}z-\frac1{2i}\int_L\frac{e^{-iz}}{z}\,\mathrm{d}z\\ &=\frac1{2i}2\pi i-\frac1{2i}0\\[9pt] &=\pi \end{align} $$ Since $U$ circles the pole at $0$ with residue $1$ once counterclockwise, and $L$ contains no poles.
Since $\frac{\sin(x)}{x}$ is an even function, we get $$ \begin{align} \int_0^\infty\frac{\sin(x)}{x}\,\mathrm{d}x &=\frac12\int_{-\infty}^\infty\frac{\sin(x)}{x}\,\mathrm{d}x\\ &=\frac\pi2 \end{align} $$