The Hanky Code originated in 1970s San Francisco gay culture, although some have suggested that it goes back to the time of the Gold Rush, when access to women was limited.
It is a way for men looking to have sex with men can communicate the type(s) of sex they like, and what type of role they would like to play (e.g., top versus bottom). It may vary slightly by region to region, but generally the code is pretty consistent.
The Gay Entertainment Directory created the following decoder that captures most combinations. Check it out (click to make larger):