How to find for which real numbers $a$ and $b$, the following functions are differentiable at $0$? I need to find for which real numbers $a$ and $b$, the following functions are differentiable at $0$:
$$f(x)=\begin{cases}
ax+b & x < 0 \\
x−x^2 & x \geq 0
\end{cases}$$
$$f(x)=\begin{cases}
ax+b & x < 1 \\
x−x^2 & x \geq 1
\end{cases}$$

The geometrical motivation behind the derivative $f^\prime(x)$ of a real valued function $f(x)$ at a point $x_0$ is to be understood as the slope of the graph of $f$ at this point. If the function consists of two parts as in 
\begin{align*}
  f(x)=
  \begin{cases}
    ax+b & x < 0 \\
    x-x^2 & x \geq 0
  \end{cases}\tag{1}
  \end{align*}
and we are asked for the derivative of $f$ at $x=0$, we have to analyse under which conditions the slope of the first part $ax+b$ and the slope of $x-x^2$ coincide at $x=0$ provided they exist (i.e. are finite).

In a somewhat more rigid mathematical context we define the derivative $f^{\prime}(x)$ at $x=0$ as the limit
\begin{align*}
  f^{\prime}(x)=\lim_{x\rightarrow 0}\frac{f(x)-f(0)}{x-0}\tag{2}
  \end{align*}
Crucial for our analysis is the characterization of a limit by its right and left-hand limit.
The derivative $f^\prime(x)$ exists at $x=0$ if and only if the right and left-hand limit
  \begin{align*}
\lim_{x\rightarrow 0^-}\frac{f(x)-f(0)}{x-0}=L \quad \text{ and } \quad \lim_{x\rightarrow 0^+}\frac{f(x)-f(0)}{x-0}=R
\end{align*}
  exist and they are equal. These limits are then called right and left-hand derivative of $f(x)$ at $x=0$ provided they exist.

Now we have everything to properly analyse the function $f$ in (1). We start with the easy one

Value of $f(x)$ at $x=0$:
The definition (2) of the derivative explicitely uses the value $f(0)$. So, we have to assure that $f$ is well-defined at $x=0$ which means, that both parts of $f$ have to coincide at that point.
\begin{align*}
  a\cdot0+b=0-0^2
  \end{align*}
  which implies that
  \begin{align*}
  b=0
  \end{align*}

The next part is to analyse the left and right-hand derivative of $f$ at $x=0$

Left-hand derivative of $f(x)$:
\begin{align*}
  \lim_{x\rightarrow 0^-}\frac{f(x)-f(0)}{x-0}&=\lim_{x\rightarrow 0^-}\frac{(ax+b)-(0x+b)}{x-0}=\lim_{x\rightarrow 0^-}a=a
  \end{align*}
and finally the 
Right-hand derivative of $f(x)$:
\begin{align*}
  \lim_{x\rightarrow 0^+}\frac{f(x)-f(0)}{x-0}&=\lim_{x\rightarrow 0^+}\frac{(x-x^2)-(0-0^2)}{x-0}=\lim_{x\rightarrow 0^+}(1-x)=1
  \end{align*}
We see the left-hand derivative and the right-hand derivative coincide if and only if $$a=1$$

Btw it's plausible, that we could find only one value for the slope, since the part $f(x)=x-x^2$ for $x\geq 0$ of the function uniquely determines a slope. So, we could only hope to find a value with this specific slope at the other part.

The short way:
We could also simply write the derivative of both parts of the function $f(x)$ to obtain a function $g(x)$ with
\begin{align*}
  g(x)=
  \begin{cases}
    a & x < 0 \\
    1-2x & x \geq 0,
  \end{cases}\tag{2}
  \end{align*}
We observe this function $g(x)$ represents the derivative of $f(x)$ in (1) for general $a,b\in \mathbb{R}$ for all $x\neq 0$. 
If we analyse the situation for $x=0$ we consider the part
  \begin{align*}
  g(x)=a\qquad\qquad x<0
  \end{align*}
  and take it as the left-hand derivative of the function $f(x)$. Next we consider the part
  \begin{align*}
  g(x)=1-2x\qquad\qquad x\geq 0
  \end{align*}
  as the right-hand derivative and see immediately that $a=1$ in case $x=0$.

Note, that the second part of OPs question refers to a function
\begin{align*}
  h(x)=
  \begin{cases}
    ax+b & x < 1 \\
    x-x^2 & x \geq 1,
  \end{cases}
  \end{align*}
and differentiability at $x=0$ reduces to the analysis of the function
$$y=ax+b$$
at $x=0$, which is easily seen to be differentiable for all values of $a,b\in \mathbb{R}$.
