Skip to content

Instantly share code, notes, and snippets.

@maxwell
Created July 31, 2012 21:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maxwell/3220776 to your computer and use it in GitHub Desktop.
Save maxwell/3220776 to your computer and use it in GitHub Desktop.
the reddit hot alg in ActiveRecord Postgres for rails
class Story < ActiveRecord::Base
# make likes count whatever basic score you want. it would be the sum of up plus down votes, or use whatever cache counters you have and weight them accordingly.
#the magic time should just be a unix time right before people started making stuff, for us, its just 6 months before we started makr.io
def self.ranked
order("(ln( 1 + posts.likes_count) + (EXTRACT(EPOCH FROM created_at) - 1327654606)/9000) desc")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment