some useful JavaScript snippets