This file contains 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
# Query example call center data | |
# Demonstrates both collection queries and collection group queries | |
# Data generated via https://gist.github.com/dmcgrath/0c404b5f2f17f1383e4f14631e579783 | |
from google.cloud import firestore | |
db = firestore.Client(project="<your project id here>") | |
review_calls = db.collection_group(u'calls').where(u'sample',u'<',5).limit(5) | |
call_docs = review_calls.get() | |
for call_doc in call_docs: |
This file contains 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
# Create example call center data | |
# Each agent has their own subcollection of calls | |
# You can run this generator multiple times in parallel | |
from google.cloud import firestore | |
import random | |
# Default values create 5000 documents. | |
MAX_AGENTS = 100 | |
MAX_CALLS = 50 | |
MAX_RATING = 5 |
This file contains 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 google.cloud import firestore | |
from time import sleep | |
# Add a new document | |
db = firestore.Client() | |
doc_ref = db.collection(u'live_news').document(u'2019-01-31') | |
def pad_message(m): | |
pad_size = len(m) | |
return u'\u00A0'*pad_size + m + u'\u00A0'*(pad_size+1) |
This file contains 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 findItem() { ; | |
; var item ; | |
; while(item_not_found) { ; | |
// search | |
; } ; | |
; return item ; | |
; } ; | |
; var item = findItem() ; |
This file contains 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
var user = null; | |
var provider = new firebase.auth.GoogleAuthProvider(); | |
firebase.auth().useDeviceLanguage(); | |
firebase.auth().signInWithPopup(provider).then(function(result) { | |
user = result.user; | |
// All the Firestore code with 'enablePersistence()' goes here |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>ComputasBrann Notes</title> | |
<!-- update the version number as needed --> | |
<script defer src="/__/firebase/4.8.0/firebase.js"></script> | |
<!-- include only the Firebase features as you need --> |
This file contains 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
noteDocument.set({owner:0}, {merge: true}); | |
noteDocument.onSnapshot(function(documentSnapshot){ | |
noteData = documentSnapshot.data(); | |
if(noteData.owner !== uuid ) { | |
noteElement.innerHTML = noteData.text || ''; | |
} | |
}); |
This file contains 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
noteElement = document.getElementById("note"); | |
noteDocument = dbClient.collection("notes").doc(noteId); | |
noteElement.oninput = function(){ | |
noteDocument.set({ | |
owner: uuid, | |
text: this.innerHTML | |
}); | |
}; |
This file contains 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
noteId = window.location.hash; // was h | |
project = "computasbrann-example"; | |
// f = firebase | |
firebase.initializeApp({ | |
authDomain:project+".firebaseapp.com", | |
projectId:project | |
}); | |
var dbClient=null; | |
var uuid = uuidv4(); |
This file contains 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
html{ | |
background: #CCC; | |
font-family: Monaco, monospace; | |
font-size: 14px; | |
color: #444; | |
line-height: 1.4; | |
max-width: 60rem; | |
margin: 0 auto; | |
height: 100%; | |
} |
NewerOlder