Skip to content

Instantly share code, notes, and snippets.

View mattbeedle's full-sized avatar

Matt Beedle mattbeedle

View GitHub Profile
@mattbeedle
mattbeedle / keybase.md
Created September 30, 2014 09:40
keybase.md

Keybase proof

I hereby claim:

  • I am mattbeedle on github.
  • I am mattbeedle (https://keybase.io/mattbeedle) on keybase.
  • I have a public key whose fingerprint is F463 5667 D1A8 320F EF77 4E74 D15A 6818 9C39 D501

To claim this, I am signing this object:

@mattbeedle
mattbeedle / gist:436f619e78047ba5e9ea
Created September 5, 2014 21:24
Alternative Rails architecture with mediators and runners
class API:V1::Companies
helpers do
def create_company_runner
CreateCompanyRunner.new(create_response, current_user, params[:company])
end
def create_response
CreateResponse.new(self)
end
end
@mattbeedle
mattbeedle / gist:4e3555b3b23729741b90
Last active May 27, 2016 13:14
Hexagonal / DDD / Architecture Astronauting ;)
# Here's my experimentation so far with DDD and hexagonal architecture from the past few weeks.
# Code all written straight into this gist so probably full of typos and bugs.
# App consists of controllers, use_cases, policies, responses, services, forms, repositories, adapters, errors.
# Everything can be unit tested and mocked using bogus (https://www.relishapp.com/bogus/bogus/v/0-1-5/docs)
# Controllers can be tested with Rack::Test to ensure they run authetication and call the correct use case.
# All business logic is isolated from the delivery mechanism (grape) so that the delivery mechanism could
# be switched out.
# It would be easy for example to switch to Torqubox and JRuby to take advantage of the massive
# 10000 req/s performance (http://www.madebymarket.com/blog/dev/ruby-web-benchmark-report.html) compared
# to the slowness of Grape.
@mattbeedle
mattbeedle / gist:edf275a03628cf4992bf
Last active August 29, 2015 14:04
strong_params vs object oriented rails
# strong_params version, with business logic tied to controller.
class Something
validates :name, :age, :miles_travelled, presence: true
validates :age, :miles_travelled, :coffee_consumed, :children_eaten,
numericality: { allow_blank: true }
end
class SomethingController < ApplicationController::Base
respond_to :html
@mattbeedle
mattbeedle / gist:c34058ab1b7882e5a1b8
Created May 26, 2014 05:24
Getting ember-easyForm to display errors returned from 422 responses
# This is a little ember easyform hack to make errors display when the form is
# submitted
Ember.EasyForm.Input.reopen
errorsChanged: (->
@set('hasFocusedOut', true)
@showValidationError()
)
didInsertElement: ->
@addObserver("context.errors.#{@property}.@each", @, 'errorsChanged')
@mattbeedle
mattbeedle / replicate
Created November 22, 2013 16:27
A simple bash script to replicate your heroku database onto your development database. Stick it in to your scripts folder in a rails app and chmod+x it. Then you can run ./script/replicate and debug any production issues with the production data.
#!/usr/bin/env bash
echo "Running: heroku pgbackups:capture --remote production"
heroku pgbackups:capture --remote production
echo "curl'ing the latest.dump"
curl -o latest.dump `heroku pgbackups:url --remote production`
echo "restoring the dump"
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d project_name_development latest.dump
@mattbeedle
mattbeedle / devise_param_protected.rb
Created March 6, 2012 16:17
config/devise_param_protected.rb
Devise::ConfirmationsController.class_eval do
param_accessible user: [ :email ], only: [ :create ]
end
Devise::PasswordsController.class_eval do
param_accessible user: [ :email ], only: [ :create ]
param_accessible :reset_password_token, only: [ :edit ]
param_accessible user: [
module MultiParameterAttributes
def attributes=(attrs)
multi_parameter_attributes = []
attrs.each do |name, value|
return if attrs.blank?
if name.to_s.include?("(")
multi_parameter_attributes << [ name, value ]
else
writer_method = "#{name}="
if respond_to?(writer_method)
module Pickle
class Config
def predicates
@predicates ||= Pickle::Adapter.model_classes.map do |k|
k.public_instance_methods.select{|m| m =~ /\?$/} + k.fields.map(&:first)
end.flatten.uniq
end
end
class Adapter
module Pickle
class Config
def predicates
@predicates ||= Pickle::Adapter.model_classes.map do |k|
k.public_instance_methods.select{|m| m =~ /\?$/} + k.fields.map(&:first)
end.flatten.uniq
end
end
class Adapter