Skip to content

Instantly share code, notes, and snippets.

Bradley Schaefer soulcutter

Block or report user

Report or block soulcutter

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@soulcutter
soulcutter / auto_annotate_models.rake
Created Feb 13, 2014
My default lib/tasks/auto_annotate_models.rake
View auto_annotate_models.rake
# NOTE: only doing this in development as some production environments (Heroku)
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
# NOTE: to have a dev-mode tool do its thing in production.
if(Rails.env.development?)
task :set_annotation_options do
# You can override any of these by setting an environment variable of the
# same name.
Annotate.set_defaults({
'position_in_routes' => "after",
'position_in_class' => "after",
@soulcutter
soulcutter / datapoint.rb
Last active Aug 29, 2015
Conversion methods
View datapoint.rb
# encoding: utf-8
require 'datapoint_value'
class Datapoint < ActiveRecord::Base
include DatapointValue::Conversions
before_save :normalize_value
def self.upsert(params)
dp = where(token: params[:token], at: params[:at]).first
@soulcutter
soulcutter / foo_spec.rb
Created Apr 4, 2014
I guess you have to understand the implementation to understand this error…
View foo_spec.rb
describe ActiveSupport::TimeZone do
it "has an invalid fraction, clearly" do
rub_a_dub_double = double.as_null_object
ymd = [rub_a_dub_double.year, rub_a_dub_double.month, rub_a_dub_double.day]
ActiveSupport::TimeZone['UTC'].local(*ymd) # ArgumentError: invalid fraction
Date.new(*ymd) # => ArgumentError: invalid date -- now that makes sense
end
end
@soulcutter
soulcutter / filter_manager.rb
Created Apr 24, 2014
Proposal for ExclusionFilters
View filter_manager.rb
class ExclusionRules < FilterRules
CONDITIONAL_FILTERS = {
:if => lambda { |value| !value },
:unless => lambda { |value| value }
}.freeze
def include_example?(example)
example.any_apply?(@rules) || example.any_apply?(CONDITIONAL_FILTERS)
end
end
View twilio_country_report.rb
class TwilioCountryReport < TwilioReport
def generate_stats
@country_stats = HashWithIndifferentAccess.new { |h, country| h[country] = TwilioCountryStat.new(country) }
build_country_stats
country_stats
end
def country_stats
@country_stats.values
end
@soulcutter
soulcutter / spec_helper.rb
Created May 7, 2014
sample spec_helper in rspec-rails 2.14.2
View spec_helper.rb
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
require 'capybara/rails'
# Requires supporting ruby files with custom matchers and macros, etc,
@soulcutter
soulcutter / have_xml.rb
Created Jun 10, 2014
General purpose RSpec 2.14 XML matcher
View have_xml.rb
require 'nokogiri'
RSpec::Matchers.define :have_xml do |xpath, matcher|
match do |body|
doc = Nokogiri::XML::Document.parse(body)
nodes = Array(doc.xpath(xpath))
nodes.map! { |node| node.respond_to?(:content) ? node.content : node }
if nodes.empty?
false
@soulcutter
soulcutter / SassMeister-input-HTML.html
Created Jul 16, 2014
stacked sass mixin experiment
View SassMeister-input-HTML.html
<div class="stack">
lorem ipsum
</div>
@soulcutter
soulcutter / zones.rb
Created Sep 9, 2014
Date#in_time_zone monkeypatch for Rails 3
View zones.rb
# this comes included in ActiveSupport 4+
unless ActiveSupport::VERSION::MAJOR > 3
require 'date'
module DateAndTime
module Zones
# Returns the simultaneous time in <tt>Time.zone</tt> if a zone is given or
# if Time.zone_default is set. Otherwise, it returns the current time.
#
# Time.zone = 'Hawaii' # => 'Hawaii'
@soulcutter
soulcutter / delegating_form_object.rb
Last active Aug 29, 2015
Basic rails delegating form object factory
View delegating_form_object.rb
class PartialReportForm
include DelegatingFormObject.new(Report)
delegate :name, :name=,
to: :report
validates :name,
presence: true
end
You can’t perform that action at this time.