Error-prone substr() usage

This fixes an issue when a `$gist` value having `.js` is passed.
Merge pull request #1 from kix/patch-1

Error-prone substr() usage