Skip to content

Instantly share code, notes, and snippets.

View brianknapp's full-sized avatar

Brian Knapp brianknapp

View GitHub Profile
@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
@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 / 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