Skip to content

Instantly share code, notes, and snippets.

@jongacnik
Created December 2, 2018 20:22
Show Gist options
  • Save jongacnik/c7f6c690aaf2358cf04190feb971a7b2 to your computer and use it in GitHub Desktop.
Save jongacnik/c7f6c690aaf2358cf04190feb971a7b2 to your computer and use it in GitHub Desktop.
shash: short hashes using php crc32 method

shash

I add this function to my .bash_profile so I can create short hashes from the command line. Not for anything serious, mainly when I want to generate a random username or something. There's of course many ways (likely better) to create short hashes, but I use the crc32 approach w/in my php code often, so I like the consistency.

usage

$ shash hello

outputs: 3d653119

shash () {
if [ -z "$1" ]
then
echo "Usage: shash string"
else
php -r 'echo hash("crc32", "'$1'", FALSE)."\n";'
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment