Skip to content

Instantly share code, notes, and snippets.

View brianknapp's full-sized avatar

Brian Knapp brianknapp

View GitHub Profile
@brianknapp
brianknapp / message.rb
Created December 1, 2014 19:55
Messages
## This is an experiment in stronger message handling protocols in Ruby.
module BasicProtocol
def method_missing(method, *args, &block)
if respond_to? :handle_missing_method
return handle_missing_method(method, *args, &block)
else
return { error: "no method found!" }
end
@brianknapp
brianknapp / gist:cafdb0320e4c2cba6970
Created October 10, 2014 16:09
Ruby Benchmarks, The Final Frontier

#Ruby Benchmarks, The Final Frontier

This is a pitch for a talk I was planning on giving at RubyConf, maybe I'll give it somewhere else

Abstract

Lets go on a journey across space and time to build the fastest possible Ruby applications. Explore the vast universe of Ruby Gems to find what frameworks, databases, algorithms, and runtimes can make high performance Ruby a reality.

Details

@brianknapp
brianknapp / develop.sh
Created September 15, 2013 14:31
Go project autoreload on OS X. Replace 'your_go_app' with whatever your app name is You run develop.sh to have it watch the project folder and run rebuild when files change.
#!/bin/bash
fswatch ./ ./rebuild.sh
@brianknapp
brianknapp / hello.mirah
Last active December 20, 2015 18:49
Playing with basic Obvious ideas in different languages
class Entity
def initialize(input:String)
@data = input
end
def get_output
@data
end
@brianknapp
brianknapp / message.rb
Last active December 17, 2015 16:19
Making your code more obvious with descriptive message passing
require 'objective-ruby'
class Sandwich
end
me = Object.new
cheese_sandwich = Sandwich.new
puts "With Objective Ruby:"
@brianknapp
brianknapp / page_should_contain.rb
Created April 16, 2013 18:29
Webrat page_should_contain matcher monkeypatch
# This is an alias method to give better language to the assert_contain matcher
module Webrat::Matchers
def page_should_contain content
assert_contain content
end
end
@brianknapp
brianknapp / user.rb
Created April 12, 2013 14:03
Obvious User Entity
class User < Obvious::Entity
value :email, String
value :password, String
value :id, Fixnum
validation :check_email, Proc.new {
raise StandardError.new 'invalid email address' unless email =~ /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i
}
@brianknapp
brianknapp / objective-ruby.rb
Last active December 16, 2015 02:29
Objective-Ruby? This is an attempt add type checking and more descriptive named parameters to ruby. This might make it in to Obvious at some point...
module ObjectiveRuby
class << self
def included(base)
base.extend ClassMethods
end
end
module ClassMethods
def obj method, input = {}, &block
@brianknapp
brianknapp / immutable_entity.rb
Last active December 15, 2015 07:09
Obvious immutable entity with validation
module Obvious
module EntityMixin
class << self
def included(base)
base.extend ClassMethods
end
end
@brianknapp
brianknapp / create_request.rb
Created February 12, 2013 01:44
This is sample code for a CreateRequest object. I don't know exactly what this is supposed to do, so I'm going to make this up as I go. Hopefully it is helpful to show multiple jacks on one action.
class CreateRequest
def initialize request_jack, notification_jack, payment_jack
@request_jack = request_jack
@notification_jack = notification_jack
@payment_jack = payment_jack
end
def execute input
unless input.has_shape? user_id: Fixnum, text: String, amount: Float, who_to_notify: Fixnum