Skip to content

Instantly share code, notes, and snippets.

View evizitei's full-sized avatar

Ethan Vizitei evizitei

  • Instructure
  • Columbia, MO
View GitHub Profile
class Reporter
class << self
def run_example_report(person,start_date,end_date)
sd_string = start_date.strftime("%Y%m%d")
ed_string = end_date.strftime("%Y%m%d")
filename = "#{person.name}_report_for_#{sd_string}_#{ed_string}"
self.run_report(filename,"EXAMPLE") do |sheet|
sheet.add_row [person.name]
namespace :db do
desc "abort rake if using bad memory techniques"
task :safety_migrate => :environment do
path = "#{RAILS_ROOT}/db/migrate/"
migration_directory = Dir.new(path)
proceed = true
migration_directory.each do |file|
if file != "." and file != ".."
migration = File.open("#{path}#{file}")
text = migration.read
class File
def uber_gets(delimiter)
segment = ""
self.each_byte do |byte|
char = byte.chr
if char == delimiter
yield segment
segment = ""
else
segment = "#{segment}#{char}"
require 'roo'
require 'csv'
class SpreadsheetParser
def self.parse(file)
name = file.path
if name =~ /\.csv/
CSV::Reader.parse(file).each do |row|
yield row
class BjJob < ActiveRecord::Base
set_table_name "bj_job"
set_primary_key "bj_job_id"
end
def restore_from_destroyed_string(string,clss)
clean_string = string.gsub(/>, #<[A-Za-z0-9]+\sid:/,'}, {:id=>').
gsub(/,\s([A-Za-z0-9_]+):\s/,', :\1=> ').
gsub(/>\]$/,"}]").
gsub(/^\[#<[A-Za-z0-9]+\sid:/,"[{:id=>")
attr_array = eval(clean_string)
attr_array.each do |attrs|
success = clss.new(attrs).save
puts "creating object #{attrs[:id]}...#{success}"
end
class ActiveSupport::TestCase
#...
def assert_contains(collection,item)
assert_not_nil collection.index(item)
end
def assert_does_not_contain(collection,item)
assert_nil collection.index(item)
end
@evizitei
evizitei / default_whenever.rb
Created October 29, 2010 19:24
Whenever Chef Recipe on EY AppCloud
#
# Cookbook Name:: whenever
# Recipe:: default
#
ey_cloud_report "whenever" do
message "starting whenever recipe"
end
# Set your application name here
@evizitei
evizitei / moonshado_env.rb
Created November 13, 2010 21:23
This is put into your cucumber env.rb file to collect all messages sent through Moonshado in an array that you can check later in your scenario.
module Moonshado
class Sms
cattr_accessor :sent_messages
def deliver_sms
raise MoonshadoSMSException.new("Invalid message") unless is_message_valid?(@message)
data = {:sms => {:device_address => format_number(@number), :message => @message.to_s}}
self.class.sent_messages ||= []
=form_for(brand,:url=>save_brand_content_path,:html => { :multipart => true }) do |f|
=hidden_field_tag :brand_id,brand.id
-if content
=hidden_field_tag :content_type,content.class.to_s
=hidden_field_tag :id,content.id
#page_header
#brand_name
=f.text_field :name
= image_tag(brand.logo.url(:medium))
=f.file_field :logo