Skip to content

Instantly share code, notes, and snippets.

View dimasusername's full-sized avatar
🏇

Dmitrii Kharlamov dimasusername

🏇
View GitHub Profile
@dimasusername
dimasusername / gist:71da282d840763af21f47d59f1ec364a
Created September 18, 2017 15:56
brew install cpp-ethereum
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
[
{
"_id": "supplier-two",
"name": "Supplier Two",
"distance": 249.0844867974628,
"location": {
"_id": {
"$oid": "57743e43f0f32e48e4000004"
},
"number": 2,
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',
suppliers_with_locations.compact!
suppliers_with_locations.to_json
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
)
suppliers_by_id = suppliers.each_with_object({}) do |supplier, memo|
memo[supplier['_id']] = supplier
end
supplier_ids = locations.map { |location| location['sid'] }.uniq
locations.rewind!
suppliers = Supplier.in(_id: supplier_ids)
supplier_ids = locations.map { |location| location['sid'] }.uniq
locations.rewind!
suppliers = settings.mongo_db.collection('suppliers').find(
_id: {
:$in => supplier_ids
}
)
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',
[
{
"_id": {
"$oid": "57743e43f0f32e48e4000004"
},
"number": 2,
"rid": "supplier-two",
"loc": [2,3]
}
]