This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MultiplyTask | |
def call(a,b) | |
a * b | |
end | |
end | |
task1 = MultiplyTask.new | |
task2 = ->(a,b) {a * b} | |
task1.(2,4) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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]}) |
OlderNewer