Skip to content

Instantly share code, notes, and snippets.

View HashNuke's full-sized avatar
💭
Life happened. I now have varied interests. I may be slow to respond.

Akash Manohar HashNuke

💭
Life happened. I now have varied interests. I may be slow to respond.
View GitHub Profile

A sorting algorithm for sorting by "hotness", roughly based on Reddit's algorithm with a few tweeks.

scope :order_by_hot, ->
  { order("round((votes_count - 1) / POW(DATE_PART('day', Now() - created_at) * 24 + DATE_PART('hour', Now() - created_at) + 2, 1.5)::numeric, 8) DESC, votes_count DESC") }
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
{
{I have|I've} been {surfing|browsing} online more than {three|3|2|4} hours today, yet I never found any interesting article like yours. {It's|It
is} pretty worth enough for me. {In my opinion|Personally|In my view}, if all {webmasters|site owners|website owners|web owners} and bloggers made good content as
you did, the {internet|net|web} will be {much more|a lot more}
useful than ever before.|
I {couldn't|could not} {resist|refrain from} commenting. {Very well|Perfectly|Well|Exceptionally well} written!|
{I will|I'll} {right away|immediately} {take hold of|grab|clutch|grasp|seize|snatch}
your {rss|rss feed} as I {can not|can't} {in finding|find|to find} your {email|e-mail} subscription {link|hyperlink} or {newsletter|e-newsletter} service. Do {you have|you've} any?
{Please|Kindly} {allow|permit|let} me {realize|recognize|understand|recognise|know} {so that|in order that} I {may just|may|could} subscribe.
Thanks.|
updateSize: function(width, height){
// get current center
var centerX = this.pos.x + this.size.x/2,
centerY = this.pos.y + this.size.y/2;
// set new width / height
this.size.x = width;
this.size.y = height;