Skip to content

Instantly share code, notes, and snippets.

@chilts
Forked from Gurpartap/gist:1141421
Created August 12, 2011 04:15
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 chilts/1141448 to your computer and use it in GitHub Desktop.
Save chilts/1141448 to your computer and use it in GitHub Desktop.
Generate unique alphanumeric incrementing string keys
#!/usr/bin/env node
var base_str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
console.log( number_to_base(process.argv[2], base_str) );
function number_to_base(n, str) {
if ( n === 0 ) return "0";
var b = '';
while ( n > 0 ) {
b = str[n%str.length] + b;
n = Math.floor(n / str.length);
}
return b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment