Skip to content

Instantly share code, notes, and snippets.

View ClayShentrup's full-sized avatar
🏗️
🗳️🌱🌷🌐🏗️🏓☢️

Clay Shentrup ClayShentrup

🏗️
🗳️🌱🌷🌐🏗️🏓☢️
View GitHub Profile
@ClayShentrup
ClayShentrup / stub.go
Created November 3, 2013 00:40
Stubbing in Go (Golang)
package main
import (
"fmt"
"reflect"
"time"
)
func main() {
stubPrototype := func(in []reflect.Value) []reflect.Value {
@ClayShentrup
ClayShentrup / buckets_controller_spec.rb
Created December 16, 2012 08:58
Pristine RSpec controller spec using latest syntax and general minimalism
require 'spec_helper'
describe BucketsController do
render_views
login_admin
def valid_attributes
FactoryGirl.attributes_for(:bucket)
end
@ClayShentrup
ClayShentrup / beget.js
Created July 20, 2012 06:59
beget question
function beget(parent, child){
// put code here to make test() return true
};
function test(){
function Parent(){
throw 'exception';
};
Parent.prototype = {code: Math.random()};
@ClayShentrup
ClayShentrup / whale_test.rb
Created July 20, 2012 05:12
Whale question
require 'test/unit'
class Whale
def self.attr_validated(method_name, &validation)
# Enter code here to make all tests pass.
end
attr_validated :num_teeth do |v|
v <= 4
end
@ClayShentrup
ClayShentrup / wrap.rb
Created June 26, 2012 05:04 — forked from garybernhardt/wrap.rb
Probably a really bad implementation of word wrapping
class Wrap < Struct.new(:string, :max_length)
def self.wrap(s, max_length)
raise ArgumentError.new("Maximum wrap length can't be 0") if max_length == 0
new(s, max_length).wrap
end
def wrap
return [""] if blank?
string.scan(regexp)
end
@ClayShentrup
ClayShentrup / gist:2528600
Created April 29, 2012 03:16
Devil's advocate argument for having the case statement in Ruby
case some_value
when 1..10
"do some stuff here"
when 11..20
"do something else here"
else
"out of range"
end
# compared to