What Is the meaning of the residue of a complex function? Studying complex analysis I saw that, in many cases, the residue's theorem comes really handful. I learned how to find it and how to use it, but I didn't quite understand what it really means "geometrically", if this makes any sense.
Is there an intuitive way to explain what a residue is, or is it just a mathematical tool?
 A: Let's start with the prototypical example of the residue theorem in action, taking the contour integral of $1/z$ over a positively oriented circle containing the origin, say $\gamma : \theta \mapsto e^{i \theta}$. Doing the computation, we obtain
\begin{equation}
\int_\gamma \frac1z dz = \int_0^{2\pi} i d\theta = 2\pi i.
\end{equation}
Compare to an analytic function $f: \Omega \to  \mathbb C$ which has an anti-derivative $F$: by the fundamental theorem of calculus, we see that the contour integral of $f$ vanishes
\begin{equation}
\int_\gamma f dz = \int_0^{2\pi} (F \circ \gamma)' (\theta) d \theta = \left[ F(e^{i \theta}) \right]_0^{2\pi} = F(1) - F(1) = 0.
\end{equation}
What you notice is that the integral above vanishes due periodicity being "quotiented out" nicely, in algebraic terms. This is because we have an anti-derivative which is well-defined on our domain $\Omega$. 
The complex logarithm
Recall that $1/z$ also has an anti-derivative, the complex logarithm. The issue with the logarithm is that it is not well-defined on the domain of $\mathbb C \setminus 0$, it's what was classically called a "multi-valued function". Remember we say $i\theta = \log z$ if it satisfies the relation 
\begin{equation}
e^{i \theta} = z.
\end{equation}
But for any $\theta$ satisfying the above, $\theta + 2\pi n$ for any $n \in \mathbb Z$ would do the trick as well. To illustrate the point, think about the value of the logarithm as you follow its value on $\gamma$. Naturally you want the logarithm to be continuous, so you say to yourself, let's take the principal logarithm, namely $\theta \in [0, 2\pi)$. So you start at 1, and out pops $\log 1 = 0$. Nothing too fishy yet. You rotate around the circle $\log e^{i \pi /2} = \pi i/2$, $\log e^{i 3\pi/2} = 3\pi i/2$... but suddenly you get 
\begin{equation}
2\pi i = \log e^{2\pi i} = \log 1 = 0.
\end{equation}
Contradiction! So the logarithm can't be defined on the complex plane appropriately, you have to make what's called a branch cut in order to make it continuous: define the logarithm on $\mathbb C \setminus [0, \infty)$. But notice that the value of the logarithm is different depending on if you approach from the upper half plane, $\theta \downarrow 0$, which gives you $\log e^{i \theta} = 0$, and the lower half plane, $\theta \uparrow 0$, which gives you $2\pi$. Maybe there's a way to capture this idea mathematically. 
Winding around the origin
And there is! We can define the complex logarithm on the associated Riemann surface by gluing together sheets of $\mathbb C \setminus [0, \infty)$ together to capture this idea of approaching the branch cut from different directions. Moreover, this new surface captures the idea of winding number, which is how much a closed curve "winds" around a particular point. 
For example $\eta : \theta \mapsto e^{i \theta}$ for $\theta \in [0, 2\pi n]$ is a closed curve which wraps around the origin $n$ times. When you plot this in a graph, it looks exactly the same as our original $\gamma$; it's just a circle. But on our Riemann surface, if you follow the logarithm of $\eta$ and this notion of direction of approach to the branch cut, we find that $\eta$ "lifts" to curve taking you from  the first sheet of $\mathbb C \setminus [0, \infty)$ to the $n$-th sheet. When you compute the integral of $1/z$, you get
\begin{equation}
\int_\eta \frac1z dz = 2\pi i n.
\end{equation}
Out pops the winding number $n$, so integrating $1/z$ captures how much curves wind around the origin. This motivates a general formula for the winding number of a curve $\gamma$ around a point $a \in \mathbb C$. 
Poles and Residues
So I went on a few tangents which might not be entirely helpful, so let's get back on topic to the original question. We see that $z \mapsto z^k$ has an anti-derivative defined on $\mathbb C \setminus 0$ for all $k \neq -1$, so we don't have to deal with any funny branch cut business that we did for "$\int 1/z = \log z$". From here it is useful to introduce the concept of a Laurent series: if $f: \mathbb C \to \mathbb C$ is a meromorphic function, then it admits a "power series" expansion
\begin{equation}
f(z) = \sum_{k \in \mathbb Z} a_k z^k = \frac{a_{-1}}{z} + \text{stuff that vanishes under integral}.
\end{equation}
When you integrate along $\gamma$, all the extra stuff vanishes and you're left with 
$$\int_\gamma f dz = a_{-1} \int_\gamma \frac1z dz = 2\pi i a_{-1} \operatorname{wind} (\gamma, 0)$$
where recall $a_{-1}$ is the residue. Remember the $k$-th order coefficients tell you about the $k$-th order behaviour of a function, so the residue theorem is basically saying, look at the Laurent series, remember $-1$-th order growth is the only one that doesn't vanish, so write $f \sim a_{-1}/z$, and integrate appropriately. 
