play both sides against the middle
play both ends against the middle
work both sides against the middle
work both ends against the middle
bang one's head against a brick wall
a house divided against itself cannot stand
beat one's head against a stone wall