Skip to content

Instantly share code, notes, and snippets.

View maliabadi's full-sized avatar

Matt Aliabadi maliabadi

  • None
  • Seattle, WA
View GitHub Profile
@peterc
peterc / methods_returning.rb
Last active October 29, 2023 03:10
Object#methods_returning - to work out which method on an object returns what we want
require 'stringio'
require 'timeout'
class Object
def methods_returning(expected, *args, &blk)
old_stdout = $>
$> = StringIO.new
methods.select do |meth|
Timeout::timeout(1) { dup.public_send(meth, *args, &blk) == expected rescue false } rescue false
@actsasgeek
actsasgeek / line.rb
Created July 20, 2012 21:11
ruby implementation of gradient descent linear regression
require 'generator'
samples = [
{ :xs => [ 1.0, 0.25], :y => 0.98},
{ :xs => [ 1.0, 0.49], :y => 0.82},
{ :xs => [ 1.0, 0.60], :y => 0.41},
{ :xs => [ 1.0, 0.89], :y => 0.31}
]
# line is the sum of the dot product of the weight (thetas)