Skip to content

Instantly share code, notes, and snippets.

@dajare
Created January 30, 2018 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dajare/368dc935ddbb212e034db73968d35b70 to your computer and use it in GitHub Desktop.
Save dajare/368dc935ddbb212e034db73968d35b70 to your computer and use it in GitHub Desktop.
Bash shell script to return last four characters of base62 conversion of unix timestamp
#!/bin/bash
# takes unix timestamp and converts to base62
# source: https://stackoverflow.com/a/14472352/232251
function u2b {
v=$(date +%s)
BASE62=($(echo {0..9} {a..z} {A..Z}))
for i in $(bc <<< "obase=62; $v"); do echo -n ${BASE62[$(( 10#$i ))]}
done
}
r=$(u2b)
echo ${r: -4}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment