Skip to content

Instantly share code, notes, and snippets.

View soulcutter's full-sized avatar

Bradley Schaefer soulcutter

View GitHub Profile
@soulcutter
soulcutter / gist:4055002
Created November 11, 2012 14:14
Understanding ruby coerce
class Price
include Comparable
attr_reader :amount
def initialize(amount)
@amount = amount
end
def <=>(obj)
@soulcutter
soulcutter / categories.rb
Created November 14, 2012 06:14 — forked from Drewch/categories.rb
categories
module Categories
ALL = [
:BUSINESS,
:CALL,
:CONTACT,
:KNOWLEDGE,
:ENTERTAINMENT,
:EMAIL,
:HELP,
:TRAVEL,
require_relative './upload_store'
class PhotoClaimer
attr_writer :photo_source
attr_writer :upload_storage_source
class FileNotFound < RuntimeError; end
def initialize(user_id, file_name)
@user_id = user_id
@soulcutter
soulcutter / _stacked.scss
Last active December 11, 2015 18:39
SCSS mixin creating a stacked block element
////
// Makes a div appear to be a stacked like 3 sheets of paper with each
// sheet offset by a given amount.
//
// Example: @include stacked(5px);
@mixin stacked($offset) {
border: 1px solid #494949;
&:after, &:before {
background: inherit;
@soulcutter
soulcutter / gist:5346232
Created April 9, 2013 14:42
Why we need to dup things in define_method blocks
class Obj
def self.new_method(name, options = {})
define_method(name) { options }
end
end
o = Obj.new
options = { one: :two }
Obj.new_method('baz', options)
@soulcutter
soulcutter / .powrc
Created June 7, 2013 18:54
Example powrc with rvm and ruby-gemset / ruby-version
if [ -f "$rvm_path/scripts/rvm" ] && [ -f ".ruby-version" ] && [ -f ".ruby-gemset" ] ; then
source "$rvm_path/scripts/rvm"
rvm use `cat .ruby-version`@`cat .ruby-gemset`
fi
if [ -f "~/.oh-my-zsh/custom/openssl.zsh" ] ; then
source "~/.oh-my-zsh/custom/openssl.zsh"
fi
@soulcutter
soulcutter / gist:5936232
Last active December 19, 2015 09:49 — forked from cstump/gist:5936186
require 'active_support'
module TestConcern
extend ActiveSupport::Concern
module ClassMethods
def test_class_method
puts "I gots class!"
end
end
@soulcutter
soulcutter / Backtrace
Created July 26, 2013 19:00
Weird stubbing error
Order rejecting an order sends reject email when status is updated
Failure/Error: Order.new.stub(:send_reject_email)
NoMethodError:
undefined method `method_defined?' for #<Order not initialized>
# /Users/matt/.rvm/gems/ruby-2.0.0-p247@uncommon-flow/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:436:in `method_missing'
# /Users/matt/.rvm/gems/ruby-2.0.0-p247@uncommon-flow/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:128:in `method_missing'
# /Users/matt/.rvm/gems/ruby-2.0.0-p247@uncommon-flow/gems/rspec-mocks-2.14.1/lib/rspec/mocks/instance_method_stasher.rb:34:in `method_defined_on_klass?'
# /Users/matt/.rvm/gems/ruby-2.0.0-p247@uncommon-flow/gems/rspec-mocks-2.14.1/lib/rspec/mocks/instance_method_stasher.rb:55:in `method_owned_by_klass?'
# /Users/matt/.rvm/gems/ruby-2.0.0-p247@uncommon-flow/gems/rspec-mocks-2.14.1/lib/rspec/mocks/instance_method_stasher.rb:29:in `method_defined_directly_on_klass?'
# /Users/matt/.rvm/gems/ruby-2.0
@soulcutter
soulcutter / barator.rb
Last active December 20, 2015 07:19
instance_method owners don't always respond to method_defined?
module Barator
def foo(*args)
"#{super(*args)}bar"
end
end
class Foo
prepend Barator
def foo
@soulcutter
soulcutter / Gruntfile.js
Created September 23, 2013 23:17
Grunt / Angular setup based originally on Yeoman
'use strict';
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
grunt.loadNpmTasks('grunt-contrib-watch');
// configurable paths
var config = {