Skip to content

Instantly share code, notes, and snippets.

View rikkipitt's full-sized avatar

Rikki Pitt rikkipitt

View GitHub Profile
@rikkipitt
rikkipitt / expression_validator.rb
Created June 9, 2015 15:15
Dentaku expression validator
class ExpressionValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
begin
Dentaku(value)
rescue Exception => e
record.errors[attribute] << (options[:message] || e.message)
end
end
end
{
"auto_complete_commit_on_tab": true,
"bold_folder_labels": true,
"detect_indentation": true,
"dictionary": "Packages/Language - English/en_GB.dic",
"ensure_newline_at_eof_on_save": true,
"font_size": 12.0,
"ignored_packages":
[
"Vintage"
@rikkipitt
rikkipitt / template.rb
Last active August 29, 2015 14:13
Ruby on Rails application template which "extends" from a common base template file
def source_paths
[File.expand_path(File.dirname(__FILE__))]
end
apply 'base.rb'
# Template specific commands to go here
@rikkipitt
rikkipitt / simple-linear-regression.rb
Last active April 20, 2018 18:47 — 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))