Question: I am reading a computation that $\int\_{0}^{\infty} \frac{1 - \cos x}{x^{2}}\, dx = \frac{\pi}{2}.$ They integrate over the indented semicircle. Let $R\_{\varepsilon}$ be the semicircle in the upper half plane of radius epsilon around the origin going from $-\varepsilon$ to $\varepsilon$. My question is: what is the reasoning behind the following statement:

$$\int\_{R\_{\varepsilon}}\frac{1 - e^{iz}}{z^{2}}\, dz \rightarrow \int\_{\pi}^{0}(-ii)\, d\theta = -\pi$$

as $\varepsilon \rightarrow 0$.

Answer: 
Since $z = -\epsilon \mathrm{e}^{-i \phi}$, where $\phi$ varies from $0$ to $\pi$. Then $\mathrm{d} z = i \epsilon \, \mathrm{e}^{-i \phi} \mathrm{d} \phi$, so 

$$
 \int\_{R\_\epsilon} \frac{1 - \mathrm{e}^{i z}}{z^2} \mathrm{d} z = \int\_0^\pi 
 \frac{ 1-\exp( -i \epsilon \mathrm{e}^{-i \phi} )}{ \epsilon^2 \mathrm{e}^{-2 i \phi}} (i \epsilon \, \mathrm{e}^{-i \phi} ) \mathrm{d} \phi =
 \int\_0^\pi 
 \frac{ 1-\exp( -i \epsilon \mathrm{e}^{-i \phi} )}{ \epsilon} (i \, \mathrm{e}^{i \phi} ) \mathrm{d} \phi
$$ 
Now, as $\epsilon \to 0$, $\frac{ 1-\exp( -i \epsilon \mathrm{e}^{-i \phi} )}{ \epsilon} \sim i \, \mathrm{e}^{-i \phi} + o(\epsilon) $, thus
$$
 \int\_0^\pi 
 \frac{ 1-\exp( -i \epsilon \mathrm{e}^{-i \phi} )}{ \epsilon} (i \, \mathrm{e}^{i \phi} ) \mathrm{d} \phi \to \int\_0^\pi \left( i \, \mathrm{e}^{-i \phi} \right) ( i \, \mathrm{e}^{i \phi}) \mathrm{d} \phi = \int\_0^\pi (i)^2 \mathrm{d} \phi = -\pi
$$
Consider the Laurent series
$$
\frac{1-e^{iz}}{z^2}=-\frac{i}{z}+\frac{1}{2}+\frac{iz}{6}-\frac{z^2}{24}-\dots
$$
The only part that doesn't vanish as $\epsilon\to0$ is $-\frac{i}{z}$. The integral of $\frac{1}{z}$ is $\log(z)=\log|z|+i\arg(z)$. Since $\arg(z)$ drops by $\pi$ over $R\_\epsilon$ (and $|z|$ doesn't change), we get that the integral is $(-i)(-i\pi)=-\pi$. In the statement you cite, it looks as if they have converted the integral of $-\frac{i}{z}$ to polar coordinates:
$$
\begin{align}
\int\_{R\_\epsilon}-\frac{i}{z}\;\mathrm{d}z
&=\int\_\pi^0\frac{-i}{r}e^{-i\theta}\;\mathrm{d}re^{i\theta}\\
&=\int\_\pi^0-ie^{-i\theta}ie^{i\theta}\;\mathrm{d}\theta\\
&=\int\_\pi^0-ii\;\mathrm{d}\theta\\
\end{align}
$$