Let $C$ be the complex contour consisting of the lines $x=\pm2$ for $y\in[-2,2]$ and of the lines $y=\pm2$ for $x\in[-2,2]$; let $C$ be oriented counterclockwise. Compute
$$\int_C\frac{z}{2z+1}\,dz$$
I tried this problem many times but could not solve it. I took $z = x + iy$ and differentiated with respect to $x$, getting $dz/dx =1$, implying $dx= dz$.
The intended path $C$ is a square path of side length $4$ going counterclockwise around $0$. It follows that $C$ goes once around the pole $z=-{1\over2}$ of the integrand, and the integral is $$\int_C{z\over2z+1}\>dz=2\pi i\>{\rm res}{z/2\over z+{1\over2}}\Biggr|_{z=-{1\over2}}=2\pi i\left(-{1\over4}\right)=-{\pi i\over2}\ .$$