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
{ | |
"users" : { | |
"HvzLGDoF2yZKOFywjuWVGEafEhs1" : { | |
"location" : { | |
"lat" : 37.37016786494953, | |
"lon" : -122.06975715302978 | |
}, | |
"public" : { | |
"city" : "Los Altos", | |
"country" : "United States", |
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
function getCountry(addrComponents) { | |
var address = {}; | |
for (var i = 0; i < addrComponents.length; i++) { | |
if (addrComponents[i].types[0] == "country") { | |
address["country_short"] = addrComponents[i].short_name; | |
address["country"] = addrComponents[i].long_name; | |
} | |
if (addrComponents[i].types[0] == "locality") { | |
address["city"] = addrComponents[i].long_name; | |
} |
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
func updateLocation(_ location: CLLocation) { | |
if let uid = Auth.auth().currentUser?.uid { | |
let latitude = location.coordinate.latitude + (Double(arc4random()) / Double(UINT32_MAX) / 10 - 0.05) | |
let longitude = location.coordinate.longitude + (Double(arc4random()) / Double(UINT32_MAX) / 10 - 0.05) | |
self.ref.child("users/\(uid)/location").setValue(["lat": latitude, "lon": longitude]) | |
} | |
} |
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 realtime database pointer | |
let ref = Database.database().reference() | |
// get currently authenticated user | |
guard let currentUser = Auth.auth().currentUser else { | |
return | |
} | |
// store any data at a given path | |
ref.child("users/\(currentUser.uid)/twitter/token").setValue(authToken) |
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
from flask import Flask | |
from schema import Query | |
from flask_graphql import GraphQLView | |
from graphene import Schema | |
import os | |
view_func = GraphQLView.as_view( | |
'graphql', schema=Schema(query=Query), graphiql=True) |
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 Query(ObjectType): | |
reviews = List(Review, id=Int(required=True)) | |
def resolve_reviews(self, args, context, info): | |
reviews = api_call(args.get("id"))["reviews"] | |
return json2obj(json.dumps(reviews)) |
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
# stolen from https://stackoverflow.com/questions/6578986/how-to-convert-json-data-into-a-python-object/15882054#15882054 | |
def _json_object_hook(d): | |
return namedtuple('X', d.keys())(*d.values()) | |
def json2obj(data): | |
return json.loads(data, object_hook=_json_object_hook) |
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
from graphene import ObjectType, List | |
class Query(ObjectType): | |
reviews = List(Review, id=Int(required=True)) |
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
from graphene import ObjectType, String, Boolean, ID, Field, Int | |
class User(ObjectType): | |
first_name = String() | |
has_profile_pic = Boolean() | |
id = ID() | |
picture_url = String() | |
smart_name = String() | |
thumbnail_url = String() |
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
{ | |
'reviews':[ | |
{ | |
'author':{ | |
'first_name':'Maryann', | |
'has_profile_pic':True, | |
'id':40613795, | |
'picture_url':'https://a0.muscache.com/im/pictures/c77f54a1-c3d0-4742-93af-f2e53b8f5145.jpg?aki_policy=profile_x_medium', | |
'smart_name':'Maryann', | |
'thumbnail_url':'https://a0.muscache.com/im/pictures/c77f54a1-c3d0-4742-93af-f2e53b8f5145.jpg?aki_policy=profile_small' |