Skip to content

Instantly share code, notes, and snippets.

@codekitchen
Created October 3, 2013 15:37
Show Gist options
  • Save codekitchen/6811880 to your computer and use it in GitHub Desktop.
Save codekitchen/6811880 to your computer and use it in GitHub Desktop.
convert a key to cassandra token in the style of RandomPartitioner
require 'digest/md5'
digest = Digest::MD5.hexdigest(ARGV[0])
token = digest.to_i(16)
token = token - (1 << bits) if (token & (1 << (bits - 1))) != 0
puts token.abs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment