Skip to content

Instantly share code, notes, and snippets.

View plusplus's full-sized avatar
🚲

Julian Russell plusplus

🚲
  • Hobart, Tasmania, Australia
View GitHub Profile
vagrant@precise64:/vagrant/prereqs-rhel-v3$ sudo -u postgres createdb -O postgres -E utf8 -T template0 dbname
createdb: database creation failed: ERROR: encoding UTF8 does not match locale en_US
DETAIL: The chosen LC_CTYPE setting requires encoding LATIN1.
vagrant@precise64:/vagrant/prereqs-rhel-v3$
@plusplus
plusplus / charge_order_balance.rb
Last active December 26, 2015 17:48
Using ActiveModel::Validations in service objects.
# Thoughts on using active model validations for service objects...
#
# NOTE: I edited this code in the GIST - there are probably errors. I even converted
# to old hash syntax for Pat and Warren.
#
# So this is a service or command object, something straight out of a method object refactoring.
# You create it, then execute it (call `call`). I've used `ActiveModel::Validations` to define validations
# that need to be met before the command is run.
#
# It would be perfectly reasonable to define call so it calls valid first, and returns true or false
@plusplus
plusplus / call.rb
Last active December 30, 2015 02:19
class MultiplyTask
def call(a,b)
a * b
end
end
task1 = MultiplyTask.new
task2 = ->(a,b) {a * b}
task1.(2,4)
# number of rows in the file
results.size
# => 105293
# number of unique stock ids
results.map {|l| l[:stock_unique_id]}.uniq.size
# => 95067
# number of stocked lines
stocked_ids = Set.new(results.select {|l| l[:stocked] == '1'}.map {|l| l[:stock_unique_id]})