Code for my answers in stackoverflow.