Skip to content

Instantly share code, notes, and snippets.

@Voker57
Created April 7, 2018 12:28
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 Voker57/7eaf8a4f0b5a9fa43d2434535ad53c79 to your computer and use it in GitHub Desktop.
Save Voker57/7eaf8a4f0b5a9fa43d2434535ad53c79 to your computer and use it in GitHub Desktop.
def int_to_pstoid(int)
int = int.to_i
result = ""
while int > 0
result.prepend(((int % 27) + 'a'.ord - 1).chr)
int = int / 27
end
result
end
def pstoid_to_int(postid)
result = 0
chars = postid.chars.to_a.reverse
chars.each_index do |i|
result += (chars[i].ord - 'a'.ord + 1) * (27 ** i)
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment