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 / 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.
task :set_annotation_options do
# You can override any of these by setting an environment variable of the
# same name.
'position_in_routes' => "after",
'position_in_class' => "after",
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 / 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,]
ActiveSupport::TimeZone['UTC'].local(*ymd) # ArgumentError: invalid fraction*ymd) # => ArgumentError: invalid date -- now that makes sense
soulcutter / filter_manager.rb
Created Apr 24, 2014
Proposal for ExclusionFilters
View filter_manager.rb
class ExclusionRules < FilterRules
:if => lambda { |value| !value },
:unless => lambda { |value| value }
def include_example?(example)
example.any_apply?(@rules) || example.any_apply?(CONDITIONAL_FILTERS)
View twilio_country_report.rb
class TwilioCountryReport < TwilioReport
def generate_stats
@country_stats = { |h, country| h[country] = }
def country_stats
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 / 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))! { |node| node.respond_to?(:content) ? node.content : node }
if nodes.empty?
soulcutter / SassMeister-input-HTML.html
Created Jul 16, 2014
stacked sass mixin experiment
View SassMeister-input-HTML.html
<div class="stack">
lorem ipsum
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></tt> if a zone is given or
# if Time.zone_default is set. Otherwise, it returns the current time.
# = 'Hawaii' # => 'Hawaii'
soulcutter / delegating_form_object.rb
Last active Aug 29, 2015
Basic rails delegating form object factory
View delegating_form_object.rb
class PartialReportForm
delegate :name, :name=,
to: :report
validates :name,
presence: true
You can’t perform that action at this time.