Skip to content

Instantly share code, notes, and snippets.

View nicholasjhenry's full-sized avatar

Nicholas Henry nicholasjhenry

View GitHub Profile
@nicholasjhenry
nicholasjhenry / gist:4176826
Created November 30, 2012 16:34
Heroku S3 Mirror (Bamboo)
export `heroku config \$@ | grep S3_ | sed -e "s/ //g" -e "s/>//g" | tr "\\n" " "`¬
@nicholasjhenry
nicholasjhenry / example.rb
Created January 11, 2013 23:14
DCI example from Lean Architecture
#!/usr/bin/env ruby
# Lean Architecture example in Ruby -
# with ContextAccessor
# Module that can be mixed in to any class
# that needs access to the current context. It is
# implemented as a thread-local variable.
#
module ContextAccessor
def context
Notes from: https://groups.google.com/d/msg/rubyparley/7grAQjnjwe0/A6PcFITW9U4J
Also see: http://railscasts.com/episodes/146-paypal-express-checkout
Use ActiveMerchant::Billing. When you're ready to have someone checkout, send them to a rails controller action Paypal#checkout. This will:
0. "gateway" is a ActiveMerchant::Billing::PaypalExpressGateway.new
1. send a message to gateway.setup_purchase.
2. #setup_purchase has a method redirect_url_for that you'll use to redirect the user to Paypal.
3. Paypal will redirect the user back to Paypal#complete
4. on the complete page, you show the user the order form again with a finalize button
@nicholasjhenry
nicholasjhenry / services.rb
Last active December 14, 2015 21:39
Latest thoughts on service implementation
# Inspired by this thread:
# https://groups.google.com/forum/?fromgroups=#!msg/rubyparley/Rnm2tC0Ry8g/xoyIfH4Qb_AJ
#
# "My habit is to pass all the data for the operation in the constructor, and then have a generic `run` method to make it go.
# That way I can separate creation from execution should I want to, just as you can with a block." - Martin Fowler
class CheckoutController
def purchase
purchase_order
end
@nicholasjhenry
nicholasjhenry / gist:5247401
Created March 26, 2013 17:34
XPath sample
//table//tr[@class='store_credit']
[
td[@class='description' and .='Order Refund'] and
td[@class='remaining_amount' and contains(., '10')] and
td[@class='amount' and contains(., '10')] and
td[@class='expires_on' and contains(., '2013')] and
td[@class='expires_on' and contains(., '03')] and
td[@class='expires_on' and contains(., '10')]
]
@nicholasjhenry
nicholasjhenry / myapp.rb
Last active December 19, 2015 08:39
Thoughts from Internals and Peers discussion
# Create a nice DSL around the service factories. The DSL becomes a list of commands the Applicaton supports.
module MyApp
module_function
def ship_package(package_id)
service = ShipIssueFactory.build(package_id)
service.call
end
end
@nicholasjhenry
nicholasjhenry / gist:6721892
Created September 26, 2013 23:11
Pipe to pbcopy
open(“| pbcopy”, “w”) { |clipboard| clipboard.write array.inspect }
@nicholasjhenry
nicholasjhenry / example.rb
Last active December 24, 2015 09:58
Alternative implementation to LightService example https://github.com/adomokos/light-service
class TaxController < ApplicationController
def update
update_tax.call(order)
redirect_to checkout_shipping_path(order), :notice => "Tax was calculated successfully"
rescue BusinessException => e
render :action => :edit, :error => e.message
end
private
class UsersController < ApplicationController
def create
CreateUser.new(User).call(params[:user], CreateResponse.new(self))
end
class CreateResponse < SimpleDelegator
def user_created(user)
flash[:notice] ="The user was created successfully"
redirect_to :index
@nicholasjhenry
nicholasjhenry / gist:7904165
Created December 11, 2013 02:19
Quarto Install Instructions
brew install haskell-platform
cabal update
cabal install cabal-install
export PATH=$PATH:~/.cabal/bin
cabal install pandoc
brew install xmlstarlet
brew install fontforge
curl -o prince-9.0r2-macosx.tar.gz http://www.princexml.com/download/prince-9.0r2-macosx.tar.gz
tar -xzvf prince-9.0r2-macosx.tar.gz
cd prince-9.0r2-macosx