how many rectangles in this shape I've learned in my high school the solution to such riddle:
How many rectangles are there in this shape:

the solution is through combinations:
in this shape is a $5\times 6$ grid so the number of rectangles would be:
$C^2_5 * C_6^2 $
I would like to know if this is possible in case of triangles? squares? is there a general rule for this?

For a big equilateral triangle with sidelength $n$ filled with unit triangles it's 
$$
\sum_{i = 1}^{n} \binom{n + 2 - i}{2} = \binom{n + 2}{3} = \frac{n(n+1)(n+2)}{6}
$$
triangles pointing upwards (exception. Triangles pointing downwards is a bit more tricky. The answer is (credit to WolframAlpha for the closed form)
$$
\sum_{i = 1}^{\left\lfloor \frac{n}{2}\right\rfloor}\binom{n + 2-2i}{2} = \frac{1}{6} \bigg\lfloor\frac{n}{2}\bigg\rfloor \left(4 \bigg\lfloor\frac{n}{2}\bigg\rfloor^2-3 (2 n+1) \bigg\lfloor\frac{n}{2}\bigg\rfloor+3 n^2+3 n-1\right)
$$
If you want some help finding these formulas yourself, the sums are built around the question "How many triangles of side length $i$ are there?", and it turns out to always be a triangular number, although slightly nicer spaced for the upward-pointing triangles. A figure for the case $n = 4$ below.

For squares, we have, following the same rule of "How many of size $i$ are there?", we get
$$
\sum_{i = 1}^n (n - i + 1)^2 = \frac{2n^3 + 3n^2 + n}{6}
$$
This is basically just a sum of consecutive squares, only summing from the largest to the smallest because that's the way it turned out.
A figure for $n = 4$ is supplied below.

