For OS X implementation, see the comment https://news.ycombinator.com/item?id=11795351 and the linked implementation.
For GNU/Linux, no one seemed to have posted something and I could not easily find it. Hence I wrote my own that has been tested successfully on my own machine: https://github.com/gajjanag/config_files/blob/master/block_f....