The general statement of Hardy's inequality is stated as:
Suppose $1<p<\infty$, $f\in L^p\left((0,\infty)\right)$, and $F : (0,\infty) \to \mathbb{C}$ is defined by
$$
F(x) = \frac{1}{x} \int_0^x fdm.
$$
Then
$$
\|F\|_p \leq \frac{p}{p-1} \|f\|_p.
$$
To prove it, assume first that $f \geq 0$ and $f\in C_c\left((0,\infty)\right)$. Integration by parts gives
$$
\int_0^\infty F^p(x) dx = -p \int_0^\infty F^{p-1}(x)xF'(x)dx.
$$
Not that $xF'(x) = f(x) - F(x)$. Apply Hölder's inequality to $\int F^{p-1}fdm$ and rearrange:
$$
(p-1)\int_0^\infty F^pdm \leq p \left(\int_0^\infty F^p dm\right)^{1-1/p} \left(\int_0^\infty f^pdm\right)^{1/p},
$$
which is
$$
\|F\|_p \leq \frac{p}{p-1} \|f\|_p.
$$
It is not difficult to generalize this to all $f\in C_c\left((0,\infty)\right)$, noting that
$$
|F(x)| \leq \frac{1}{x}\int_0^x |f|dm.
$$
Now suppose $f \in L^p\left((0,\infty)\right)$, and choose a sequence $\{f_n\}$ in $C_c\left((0,\infty)\right)$ such that $\|f_n-f\|_p \to 0$ as $n \to \infty$, and $\{f_n(x)\}$ converges to $f(x)$ for a.e $x$. This is possible because $C_c\left((0,\infty)\right)$ is dense in $L^p\left((0,\infty)\right)$, and because every $L^p$ convergent sequence has a pointwise convergent subsequence. By Fatou's Lemma and Jensen's inequality,
\begin{align}
|F(x)-F_n(x)|^p &\leq \frac{1}{x^p} \int_0^x \lim_{j\to \infty}|f_j-f_n|^pdm \\
&\leq \frac{1}{x^p} \liminf_{j\to \infty} \int_0^x |f_j-f_n|^pdm \\
&\leq \frac{1}{x^p} \liminf_{j\to \infty} \int_0^\infty |f_j-f_n|^pdm \\
&= \frac{1}{x^p} \|f-f_n\|_p^p
\end{align}
for all $x\in (0,\infty)$. Hence $F$ is the pointwise limit of $\{F_n\}$. Again, by Fatou's lemma,
\begin{align}
\int_0^\infty |F-F_n|^pdm &\leq \liminf_{j \to \infty}\int_0^\infty |F_j-F_n|^pdm \\
&\leq \liminf_{j\to \infty} \left(\frac{p}{p-1}\|f_j-f_n\|_p\right)^p \\
&= \left(\frac{p}{p-1}\|f-f_n\|_p\right)^p
\end{align}
Therefore, $\{F_n\}$ converges to $F$ in $L^p\left((0,\infty)\right)$, and we have
$$
\|F\|_p = \lim_{n\to \infty} \|F_n\|_p \leq \lim_{n\to \infty} \frac{p}{p-1} \|f_n\|_p = \frac{p}{p-1} \|f\|_p.
$$
To obtain the series inequality for $\{a_n\} \in \ell^2$, first assume that $|a_{n+1}| \geq |a_n|$. Then it follows from the integral inequality that
$$
\sum_{N=1}^{\infty}\left(\frac{1}{N}\sum_{n=1}^N |a_n|\right)^p \leq \left(\frac{p}{p-1}\right)^p \sum_{n=1}^\infty |a_n|^p.
$$
In the general case, since $|a_n|\to 0$ as $n\to \infty$, we can arrange the sequence so that $|a_n| \geq |a_{n+1}|$. Absolute convergence ensures that such rearrangements would not change the series.