This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cycle < ActiveRecord::Base | |
belongs_to :user | |
belongs_to :decision, polymorphic: true | |
validates :user_id, presence: true | |
validates :decision_id, presence: true | |
validates :decision_type, presence: true | |
validates :effective_at, presence: true | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Self < self.class | |
def self.self | |
self.new.self | |
end | |
def self | |
self.to_s + " brain asplode" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In config/initializers/local_override.rb: | |
require 'devise/strategies/authenticatable' | |
module Devise | |
module Strategies | |
class LocalOverride < Authenticatable | |
def valid? | |
true | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Which specs do you prefer? | |
# | |
# These? | |
describe SalaryAverager do | |
before(:each) do | |
@averager = SalaryAverager.new("spec/fake_data.csv") | |
end | |
describe "#average_salary" do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def foo? | |
self.status == 'foo' | |
end | |
def bar? | |
self.status == 'bar' | |
end | |
# duplication! accomplish the same thing with define_method: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Top-level driver script for getting trials from clinicaltrials.gov into our database. | |
class ImportTrials | |
SEARCH_URL = "http://clinicaltrials.gov/ct2/results?term=%s&recr=Open&studyxml=true" | |
INSTITUTIONS = { "Dana-Farber Cancer Institute" => { :search_url => SEARCH_URL % '%22dana+farber%22', :abbrev => 'DFCI' }, | |
"Harvard Medical School" => { :search_url => SEARCH_URL % '%22harvard+medical+school%22', :abbrev => 'HMS' }, | |
"Harvard School of Public Health" => { :search_url => SEARCH_URL % '%22harvard+school+of+public+health%22', :abbrev => 'HSPH' }, | |
"Brigham and Women's Hospital" => { :search_url => SEARCH_URL % '%22brigham+and+women\'s+hospital%22', :abbrev => 'BWH' }, | |
"Children's Hospital Boston" => { :search_url => SEARCH_URL % '%22children%27s+hospital+boston%22', :abbrev => 'CHB' }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DIAGNOSES = [ "Bladder Cancer", "Brain/Neuro Cancer", "Breast Cancer", "Cervical Cancer", "Colorectal Cancer", "Cutaneous Skin Cancer", | |
"Endometrial/Uterine Cancer", "Esophageal Cancer", "Head and Neck Cancer", "Kidney Cancer", "Leukemia/MDS", "Liver Cancer", | |
"Lung Cancer", "Hodgkin's Lymphoma", "Non-Hodgkin's Lymphoma", "Melanoma", "Multiple Myeloma", "Ovarian Cancer", "Pancreatic Cancer", | |
"Pediatric Blood Related", "Pediatric Brain Tumor", "Pediatric Solid Tumors", "Prevention & Early Detection", "Prostate Cancer", | |
"Sarcoma", "Stomach Cancer", "Testicular Cancer", "Thyroid Cancer", "Other Cancers", "Other Trials" ] | |
namespace :trials do | |
namespace :diagnoses do | |
desc "Seed the database with a basic set of diagnoses." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExportOfMultiProgramMembers | |
def self.run | |
FasterCSV.open('multi_program_members.csv', "w") do |csv| | |
multi_program_members.each do |member| | |
csv << [formatted_name(member), *member.programs.map(&:name)] | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'open-uri' | |
FILE_NAME = '/home/beno/projects/training_checker/seats_left.txt' | |
previous_seats_left = File.open(FILE_NAME).read | |
doc = open('https://training.thoughtbot.com/courses/12-vim-for-rubyists/registrations/new').read |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def squish(str) | |
str = str.split('') | |
str.inject(str[0]) do |acc, char| | |
acc << char unless acc.split('').last.downcase == char.downcase | |
acc | |
end | |
end | |
puts squish("AQAaaBbbbbccCcc") | |
puts squish("ZzzzzXxxxyYY") |