Skip to content

Instantly share code, notes, and snippets.

View brianknapp's full-sized avatar

Brian Knapp brianknapp

View GitHub Profile
@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 / 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 / tweet contract thingy.rb
Created September 14, 2012 18:32
tweet pre-post condition contract
class Contract
@@disable_override = false
@@contracts = []
def self.method_added name
unless @@disable_override
@@contracts.each do |method|
if name == method.to_sym
method_alias = "#{method}_alias".to_sym
@brianknapp
brianknapp / gist:3756197
Created September 20, 2012 14:14
clean tweet gateway contract tests
require_relative '../../contracts/tweet_gateway_contract'
class TG < TweetGatewayContract
def save input
return input
end
end
class TGoutput < TweetGatewayContract
def save input
@brianknapp
brianknapp / gist:4150482
Created November 26, 2012 20:40
Self contained knockout error bubble with close button
<div class="alert error" data-bind="css: { hidden: !errorMessage() }">
<span data-bind="text: errorMessage"></span>
<button class="close" data-bind="click: function(data, event){ errorMessage(null); } ">&times;</button>
</div>
@brianknapp
brianknapp / example_action.yml
Created December 24, 2012 02:11
Example Obvious Descriptor
Action: ExampleAction
Description: should do something awesome
Code:
- c: validate input
- c: set default id and values for new Thing entity
- c: create/populate Thing object
requires: Thing.populate
- c: save thing to jack
requires: ThingJack.save, Thing.to_hash
- c: return the result
@brianknapp
brianknapp / sign_in_user.rb
Created February 5, 2013 18:38
This is a overly simplistic sign in user action that demonstrates roughly how a sign in might work in Obvious with users and user sessions
require_relative '../entities/user'
require_relative '../entities/user_session'
class SignInUser
def initialize user_jack, user_session_jack
@user_jack = user_jack
@user_session_jack = user_session_jack
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
@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 / 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