View incrementViews.js
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
/** | |
* Increases view count by one. | |
* @param: db {FirebaseDatabase} - Firebase Database instance | |
* @param: id {String} - id of post | |
* @return: Promise<{committed: boolean, snapshot: nullable firebase.database.DataSnapshot}> | |
* @docs: https://firebase.google.com/docs/reference/js/firebase.database.Reference#transaction | |
*/ | |
const incrementViews = (db, id) => { | |
const ref = db.ref('views').child(id) | |
return ref.transaction(currentViews => { |
View example.js
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 ref = new Firebase('<my-firebase-app>/items'); | |
// Create a push reference (no data has been sent to the server, just a generated id) | |
const childRef = ref.push(); | |
// create an object and with they push-id | |
const data = { name: 'David': key: childRef.key() }; | |
// save it | |
childRef.set(data); | |
// Listen for the update | |
childRef.on('value', (snap) => console.log(snap.val())); |
View transfer.js
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 client = require('firebase-tools'); | |
function transfer(path, options) { | |
var fromDb = options.fromDb; | |
var toDb = options.toDb; | |
var output = options.output; | |
client.data.get(path, { firebase: fromDb, output: output }) | |
.then(function(data) { | |
return client.data.set(path, output, { firebase: toDb, confirm: true }); | |
}) |
View rules.bolt
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
isUser(uid) = auth != null && auth.uid == uid; | |
type Post { | |
uid: String; | |
title: String; | |
description: String; | |
timestamp: Number; | |
} | |
type User { |
View rules.json
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": { | |
"$uid": { | |
".validate": "newData.hasChildren(['uid', 'name', 'username'])", | |
"uid": { | |
".validate": "newData.isString()" | |
}, | |
"name": { | |
".validate": "newData.isString()" |
View MyViewController.swift
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 UIKit | |
class MyViewController: UIViewController { | |
// Store ref and handle as implicitly unwrapped optionals | |
var ref: Firebase! | |
var handle: UInt! | |
override func viewDidLoad() { | |
super.viewDidLoad() |
View SyncPath.js
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
export class SyncPath { | |
constructor(rootRef, path) { | |
this._rootRef = rootRef; | |
this.user = this._rootRef.getAuth(); | |
this._userDataRef = this._rootRef.child(path).child(this.user.uid); | |
this.data = {}; | |
this._userDataRef.on('value', (snap) => this.data = snap.val() || {}); | |
} | |
keys() { | |
return Object.keys(this.data); |
View fetchpipe.ts
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
interface IFetchResponse { | |
text: () => Promise<string>; | |
json: () => Promise<string>; | |
} | |
declare var fetch: (url: string) => Promise<IFetchResponse>; | |
@Pipe({ | |
name: 'fetch' | |
}) | |
class FetchJsonPipe { |
View push.js
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 apn = require("apn"); | |
var Firebase = require("firebase"); | |
var service = new apn.connection({ production: false }); // true for production pipeline | |
// Create a reference to the push notification queue | |
var pushRef = new Firebase("<your-firebase>.firebaseio.com/notificationQueue"); | |
// listen for items added to the queue | |
pushRef.on("child_added", function(snapshot) { |
View index.ts
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 {bootstrap, Component, Decorator, View, If, For, EventEmitter} from 'angular2/angular2'; | |
import {FormBuilder, Validators, FormDirectives, ControlGroup} from 'angular2/forms'; | |
@Component({ | |
selector: 'app', | |
injectables: [FormBuilder] | |
}) | |
@View({ | |
template: ` | |
<div class="container" [control-group]="myForm"> |