I'm not sure how to get from the first line to the simplified second line. Equations are from Charles Elkan's notes here: http://cseweb.ucsd.edu/~elkan/250Bwinter2012/logreg.pdf
$$ \begin{split} \frac{d}{d\theta} \theta^h (1-\theta)^{n-h} &= h \theta^{h-1} (1-\theta)^{n-h} + \theta^h (n-h)(1- \theta)^{n-h-1}(-1)\\ &= \theta^{h-1} (1-\theta)^{n-h-1} \left[ h(1-\theta)- (n-h)\theta \right] \end{split} $$
Notice that $(1-\theta)^{n-h} = (1-\theta)\cdot(1-\theta)^{n-h-1}$ and $\theta^h = \theta \cdot\theta^{h-1}$. The common factor of the two terms on the right hand side of the first equation is $\theta^{h-1}\cdot(1-\theta)^{n-h-1}$, so he extracts it (as suggested in the comments).