Skip to content

Instantly share code, notes, and snippets.

View nanosplit's full-sized avatar

Jacob Montgomery nanosplit

  • Texas
View GitHub Profile
@nanosplit
nanosplit / simple-linear-regression.rb
Created December 12, 2016 08:15 — forked from rweald/simple-linear-regression.rb
Simple Linear Regression in Ruby
class SimpleLinearRegression
def initialize(xs, ys)
@xs, @ys = xs, ys
if @xs.length != @ys.length
raise "Unbalanced data. xs need to be same length as ys"
end
end
def y_intercept
mean(@ys) - (slope * mean(@xs))
@nanosplit
nanosplit / gist:db42e507c5d1d984b664868db10a3669
Created December 12, 2016 03:51 — forked from jrochkind/gist:2636355
reddit 'hot' algorithm, in ruby, with typo fixed
require 'date'
# Actually doesn't matter WHAT you choose as the epoch, it
# won't change the algorithm. Just don't change it after you
# have cached computed scores. Choose something before your first
# post to avoid annoying negative numbers. Choose something close
# to your first post to keep the numbers smaller. This is, I think,
# reddit's own epoch.
$our_epoch = Time.local(2005, 12, 8, 7, 46, 43).to_time
# Function to print strftime results
def print_strftime_formats(a,cur_date)
a.each do |format|
b = "%#{format}"
output = cur_date.strftime(b)
puts "t.strftime('#{b}'), => #{output}"
end
end
a = ('a'..'z').to_a