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
{ | |
"albums": { | |
"key1": { | |
"owner": "uid1", | |
"subscribers": { | |
"uid1": true, | |
"uid2": true | |
} | |
} | |
} |
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
const functions = require('firebase-functions'); | |
const util = require('util'); | |
exports.helloWorld = functions.https.onRequest((req, res) => { | |
// For Firebase Hosting URIs, use req.headers['fastly-client-ip'] | |
// For callable functions, use rawRequest | |
// Some users have better success with req.headers['x-appengine-user-ip'] | |
const ipAddress = req.headers['x-forwarded-for'] || req.connection.remoteAddress; | |
const headers = JSON.stringify(req.headers, null, 2); | |
const message = util.format("<pre>Hello world!\n\nYour IP address: %s\n\nRequest headers: %s</pre>", ipAddress, headers); |
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
/** | |
Consider this data structure, used for getting a list of names based on membership | |
/users/<user id>/name | |
/rooms/members/<user id>/true | |
Now let's create a couple simple classes without any real consideration for testing structures, assuming | |
we'll use a mock of Firebase to test them. Note that I see these sorts of errors constantly in the wild; | |
this example is not far fetched or exaggerated (it's rather tame in comparison) | |
*/ |
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 encodeKeys(data) { | |
let encodedData = null; | |
if( typeof(data) === 'function' ) { | |
encodedData = data + ''; | |
} | |
else if (typeof(data) !== 'object') { | |
encodedData = data; | |
} | |
else if(data !== null) { |
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
import { Component } from '@angular/core'; | |
import { AngularFire, FirebaseObjectObservable } from 'angularfire2'; | |
import {ActivatedRoute, Params} from "@angular/router"; | |
import {Observer} from "rxjs"; | |
@Component({ | |
selector: 'app-detail', | |
template: ` | |
<h2>{{book.title}}</h2> | |
<p>{{book.author}}</p> |
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
{ | |
"hosting": { | |
"public": "dist", | |
"rewrites": [ | |
{ | |
"source": "**", | |
"destination": "/index.html" | |
} | |
] | |
} |
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
this.$cordovaOauth.facebook("your_client_id", ["email"]) | |
.then(function (result) { | |
var credentials = firebase.auth.FacebookAuthProvider.credential(result.access_token); | |
return firebase.auth().signInWithCredential(credentials); | |
}) | |
.then(function (firebaseUser) { | |
console.log("Signed in as:", firebaseUser.uid); | |
}) | |
.catch(function (error) { | |
console.error("Authentication failed:", error); |
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
app.factory('DescendingArray', function($firebaseArray) { | |
return $firebaseArray.$extend({ | |
// Modify $$process to handle added events by prepending instead of appending | |
$$process: function(event, rec, prevChild) { | |
var key = this.$$getKey(rec); | |
var changed = false; | |
if( event === 'child_added' ) { | |
curPos = this.$indexFor(key); |
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
angular.factory('Arr', function($firebaseArray) { | |
function Arr(ref) { | |
this.oldVals = {}; | |
return $firebaseArray.call(this, ref); | |
} | |
Arr.prototype.$$process = function(event, rec, prevKey) { | |
$firebaseArray.prototype.$$process.apply(this, arguments); | |
this.oldVals[rec.$id] = rec; | |
}; |
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
{ | |
"rules": { | |
"users": { | |
"$user_id": { | |
// email address is required | |
".validate": "newData.hasChildren(['email'])", | |
} | |
}, | |
"emails_to_users": { |