The Malbolge program in the show is almost the real thing. It is the same program given in the Wikipedia article on Malbolge except for three or four altered characters about 30 characters missing from the end. The program in the Wikipedia article just displays "Hello World!".
The firm hiring Holmes is called Casterly Rock. This is also the name of the homeseat of the Lannisters in Game of Thrones (2011). The Lannisters are known for their wealth.
In the opening scene, Gwen is wearing the very same t-shirt Sherlock donned in front of Joan in the pilot episode that says "I'm not lucky, I'm good".
During the lunch scene, Watson's mother mentions that she heard from Watson's brother, Oren. O-Ren Ishii is the name of Lucy Lui's character in Kill Bill, Vol 1 (2003).
At a moment as Sherlock is speaking about having a relapse, he use the sentence "chasing the dragon". This expression was used by people to say they were smoking opium or heroin.