Useful JavaScript code snippets for solving common problems