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
Updating Homebrew... | |
==> Auto-updated Homebrew! | |
Updated 1 tap (homebrew/core). | |
No changes to formulae. | |
==> Installing cpp-ethereum from ethereum/ethereum | |
==> Cloning https://github.com/ethereum/cpp-ethereum.git | |
Updating /Users/***/Library/Caches/Homebrew/cpp-ethereum--git | |
==> Checking out branch develop | |
==> cmake -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/cpp-eth |
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
[ | |
{ | |
"_id": "supplier-two", | |
"name": "Supplier Two", | |
"distance": 249.0844867974628, | |
"location": { | |
"_id": { | |
"$oid": "57743e43f0f32e48e4000004" | |
}, | |
"number": 2, |
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
get '/suppliers-with-locations' do | |
lat = params.fetch(:lat, 0).to_f | |
lng = params.fetch(:lng, 0).to_f | |
distance = params[:distance].to_i * 1.61 * 1000 | |
query = { | |
loc: { | |
:$near => { | |
:$geometry => { | |
type: 'Point', |
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
suppliers_with_locations.compact! | |
suppliers_with_locations.to_json |
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
suppliers_with_locations = locations.map do |location| | |
next unless suppliers_by_id[location['sid']] | |
location_lat = store['loc'][1] | |
location_lng = store['loc'][0] | |
memo = suppliers_by_id[location['sid']].merge( | |
distance: distance_between([store_lat, store_lng], [lat, lng]), | |
location: location | |
) | |
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
suppliers_by_id = suppliers.each_with_object({}) do |supplier, memo| | |
memo[supplier['_id']] = supplier | |
end |
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
supplier_ids = locations.map { |location| location['sid'] }.uniq | |
locations.rewind! | |
suppliers = Supplier.in(_id: supplier_ids) |
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
supplier_ids = locations.map { |location| location['sid'] }.uniq | |
locations.rewind! | |
suppliers = settings.mongo_db.collection('suppliers').find( | |
_id: { | |
:$in => supplier_ids | |
} | |
) |
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
get '/suppliers-with-locations' do | |
lat = params.fetch(:lat, 0).to_f | |
lng = params.fetch(:lng, 0).to_f | |
distance = params[:distance].to_i * 1.61 * 1000 | |
query = { | |
loc: { | |
:$near => { | |
:$geometry => { | |
type: 'Point', |
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
[ | |
{ | |
"_id": { | |
"$oid": "57743e43f0f32e48e4000004" | |
}, | |
"number": 2, | |
"rid": "supplier-two", | |
"loc": [2,3] | |
} | |
] |