Skip to content

Instantly share code, notes, and snippets.

View plusplus's full-sized avatar
🚲

Julian Russell plusplus

🚲
  • Hobart, Tasmania, Australia
View GitHub Profile
# 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]})
@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)
@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
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 / README.md
Last active December 19, 2015 20:59
ActiveMerchant NAB Transact scratching

Some notes:

  • This is very much a skeleton that goes JUST as far as we needed it to.
  • It's using the redirect method for the return url, rather than the proxying style. I need to think a little more about whether the POST and proxy our redirect to the client is better/worse.
  • This may not be a super correct AM integration, like I said, JUST as far as we needed to go :)
@plusplus
plusplus / gist:5790169
Last active December 18, 2015 13:29
JaquardCoefficient
class JaquardCoefficient
def similarity( x, y )
raise ArgumentError, "Both sets are empty" if x.empty? && y.empty?
return 0.0 if x.empty? || y.empty?
(x & y).size.to_f / (x | y).size.to_f
end
end
@plusplus
plusplus / date_mongo_type.rb
Created May 23, 2013 01:01
Convert date to string in MM
class Date
def self.from_mongo( v )
return nil if v.nil?
Date.iso8601( v.to_s )
end
def to_mongo
to_s
end
end
@plusplus
plusplus / Gemfile
Created July 1, 2012 05:41
Very Slow MM time handling
source :rubygems
MONGO_VERSION = '~>1.6'
gem 'bson', MONGO_VERSION
gem 'bson_ext', MONGO_VERSION
gem 'mongo', MONGO_VERSION
gem 'mongo_mapper', "0.11.1"
@plusplus
plusplus / install.sh
Created May 31, 2012 10:10
Install Nginx Ubuntu 10.4
set -u -e
echo
echo
echo
echo "--------------------------------------------------------------------------"
echo
echo "NOW: Installing nginx"
echo
echo "--------------------------------------------------------------------------"
<?xml version="1.0" encoding="UTF-8"?>
<FireDangerMap>
<District>
<Name>Far North Coast</Name>
<RegionNumber>1</RegionNumber>
<Councils>Ballina; Byron; Clarence Valley; Kyogle; Lismore; Richmond Valley; Tweed</Councils>
<DangerLevelToday>Low-Moderate</DangerLevelToday>
<DangerLevelTomorrow>None</DangerLevelTomorrow>
<FireBanToday>No</FireBanToday>
<FireBanTomorrow>No</FireBanTomorrow>