Skip to content

Instantly share code, notes, and snippets.

@Jwata
Last active June 11, 2018 08:23
Show Gist options
  • Select an option

  • Save Jwata/03ea406cdfe475cf8d4e876a2d1a5211 to your computer and use it in GitHub Desktop.

Select an option

Save Jwata/03ea406cdfe475cf8d4e876a2d1a5211 to your computer and use it in GitHub Desktop.
var reactionImageUrls = {'angry': 'http://url.com/', 'wow': 'http://url.com/'};
firebase.database().ref('Points').once('value', function(points) {
points.forEach(function(point) {
var location = data.val().Location;
var reaction = data.val().Reaction;
imageUrl = reactionImageUrls[reaction];
// display a point
})
});
users:
user_1:
current_location:
long: 12.345
lat: 12.345
points:
- 'point_1'
- 'point_2'
user_2:
- 'point_3'
user_3:
- 'point_4'
points:
point_1:
user_id: 'user_1'
reaction: 'sad'
state: 'private'
location:
long: 12.345
lat: 12.345
time: 1528191174489
point_2:
...
point_3:
...
point_4:
...
reactions:
sad:
...
joy:
...
angry:
...
@Jwata
Copy link
Author

Jwata commented Jun 5, 2018

Use case: A user gets their points

# Note: This isn't a real programming code. 

user_id = 'some_user_id'
user = users.find_by_id(user_id)

point_ids = user.points
user_points = points.find_by_ids(point_ids)

@Jwata
Copy link
Author

Jwata commented Jun 5, 2018

Use case: A user finds public points around them

# Note: This isn't a real programming code. 

user_id = 'some_user_id'
user = users.find_by_id(user_id)

user_location = user.current_location
distance = 10

# search logic 
filtered_points = []
for point in points:

  # check if it's public or not
  if point.state != 'public':
    continue;

  # you can add any conditions as you need

  # check if it's close to the user or not
  if calculate_distance(point.location, user_location) < distance:
    continue;
  
  # add to filtered if it passes all conditions
  filtered_points.push(point)

@Jwata
Copy link
Author

Jwata commented Jun 11, 2018

SQL Join

id value home_page
1 'a' 'google'
2 'b' 'yahoo'
home_page url
'google' 'http://google.com/'
'yahoo' 'http://yahoo.com'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment