https://sourceforge.net/projects/gamersproxy/
This is an open-source program that can emulate constant ping, ping spikes and packet losses.
Download, extract wherever you want, launch the executable and read the instructions that are conveniently placed in the main window of the program.
The download site provides build for Windows only, but the program will compile and work just fine on Linux too. On Ubuntu all that is necessary is the standard compiler tools, cmake and libqt4-dev, and mercurial to check the repository out. Program should also compile on Mac, although getting that to work may require some hassle.
Some may remember that I released a similar program a few years ago, DelayedUDPProxy. That previous program was written in Java and required JRE to run - not nice. This new program is written in C++ using Qt library and should require no additional crap to run.
Spoiler: Screenshot of the program in action (Open)
Spoiler: Video demonstrating how the program works (1080 HD) (Open)