Skip to content

Instantly share code, notes, and snippets.

# hotness = age_in_minutes / (votes**2.5)
def original_hotness(now, created_at, votes)
age_in_minutes = (((created_at.to_f / 60).floor * 60) - ((now.to_f / 60).floor * 60)) / -60
age_in_minutes / (votes**2.5)
end
def new_hotness(now, created_at, votes)
@erithmetic
erithmetic / routes.rb
Created October 24, 2012 19:11 — forked from codeodor/routes.rb
How do I keep all of these routes, but also make them available under a scope?
# I have read http://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper/Resources.html#method-i-resources
# and remain clueless.
MyApp::Application.routes.draw do
resources :blogs do
resources :comments
end
# then imagine tons of routing below this
end
@erithmetic
erithmetic / gist:180638
Created September 4, 2009 00:34 — forked from gdi/gist:180470
# Rake task for listing all Cucumber features defined
namespace :cucumber do
task :features do
list = { :given => [], :when => [], :then => [] }
files = Dir.glob(File.join(File.dirname(__FILE__),'features','**','*.rb')).each do |f|
File.readlines(f).select { |l| l =~ /\s*[^#]?\s*(Given|When|Then)\s\// }.each do |line|
line =~ /(Given|When|Then)\s+(\/\^?)?([^$\/]+)(\$?\/)?/
type = $1.downcase.to_sym
name = "#{$1} #{$3}".strip