Skip to content

Instantly share code, notes, and snippets.

View r00k's full-sized avatar
💭
Working on Tuple (https://tuple.app)

Ben Orenstein r00k

💭
Working on Tuple (https://tuple.app)
View GitHub Profile
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
class Self < self.class
def self.self
self.new.self
end
def self
self.to_s + " brain asplode"
end
end
@r00k
r00k / gist:906356
Created April 6, 2011 19:33
Custom devise strategy
# In config/initializers/local_override.rb:
require 'devise/strategies/authenticatable'
module Devise
module Strategies
class LocalOverride < Authenticatable
def valid?
true
end
@r00k
r00k / gist:868487
Created March 13, 2011 22:10
Which specs do you prefer?
# Which specs do you prefer?
#
# These?
describe SalaryAverager do
before(:each) do
@averager = SalaryAverager.new("spec/fake_data.csv")
end
describe "#average_salary" do
def foo?
self.status == 'foo'
end
def bar?
self.status == 'bar'
end
# duplication! accomplish the same thing with define_method:
# 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' },
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."
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
#!/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
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")