Error-prone substr() usage

This fixes an issue when a `$gist` value having `.js` is passed.
Not that's likely an issue, but who knows.