Guest User

Untitled

a guest
Nov 21st, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. ###The Problem:
  2.  
  3. How do you create URLs that are short, easy to remember, and unique? Also, how do you store 60M rows so they are easily accessable?
  4.  
  5. ###Getting the data
  6.  
  7. Get all 5 letter permutations for the letters between `a` and `z` as well as `A` through `F`.
  8.  
  9. ###The Source
  10.  
  11. First, you get all the permutations and write them to disk.
  12.  
  13. #! /bin/ruby
  14.  
  15. open('/tmp/random.out', 'w') do |f|
  16. (('a'..'z').to_a + ('A'..'L').to_a).permutation(5) do |p|
  17. f.puts [p.to_a.join, Time.now.to_s(:db), Time.now.to_s(:db)].join(',')
  18. end
  19. end
  20.  
  21. Why disk? Having a flat file would allow you do do interesting things like pipelining to redis, or `LOAD DATA` calls in mysql.
  22.  
  23. ###Storage
  24.  
  25. Ok, so we got the data, but how do we store it? First though was redis, so we did this:
  26.  
  27. ###Questions
  28.  
  29. Why did we stop at `F`? Franky, we felt like approximately 60 million hashes would get us by for a while. We can always generate more.
Add Comment
Please, Sign In to add comment