Skip to content

Instantly share code, notes, and snippets.

Avatar
🔥
Working on Firebase

David East davideast

🔥
Working on Firebase
View GitHub Profile
@davideast
davideast / bulkUpdate.js
Last active Apr 20, 2021
Bulk update with .push()
View bulkUpdate.js
/**
* Send a bulk update to Firebase from an array or an object literal.
*
* When .push() is called on a Firebase reference without a parameter passed no
* trip to the server is made.
*
* ex:
* var childRef = ref.push();
*
* A reference is returned which has a push-id that can be returned by calling .name().
@davideast
davideast / index.html
Created Mar 20, 2015
Basic Firebase Chat App
View index.html
<html>
<head>
<title>Firestart</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" media="screen" charset="utf-8">
<script src="https://cdn.firebase.com/js/client/2.2.3/firebase.js"></script>
</head>
<body>
<div class="container">
@davideast
davideast / index.ts
Created Apr 15, 2015
Simple Angular 2 Forms with Firebase
View index.ts
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">
@davideast
davideast / push.js
Last active Apr 20, 2021
Send push notifications with node-apn and Firebase
View push.js
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 fetchpipe.ts
interface IFetchResponse {
text: () => Promise<string>;
json: () => Promise<string>;
}
declare var fetch: (url: string) => Promise<IFetchResponse>;
@Pipe({
name: 'fetch'
})
class FetchJsonPipe {
@davideast
davideast / SyncPath.js
Last active Apr 20, 2021
Firebase Social Network Client Fanout
View SyncPath.js
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);
@davideast
davideast / MyViewController.swift
Last active Dec 27, 2017
Using Firebase references in a UIViewController
View MyViewController.swift
import UIKit
class MyViewController: UIViewController {
// Store ref and handle as implicitly unwrapped optionals
var ref: Firebase!
var handle: UInt!
override func viewDidLoad() {
super.viewDidLoad()
@davideast
davideast / rules.json
Last active Apr 20, 2021
Bolt output
View rules.json
{
"rules": {
"users": {
"$uid": {
".validate": "newData.hasChildren(['uid', 'name', 'username'])",
"uid": {
".validate": "newData.isString()"
},
"name": {
".validate": "newData.isString()"
@davideast
davideast / rules.bolt
Last active Dec 15, 2015
Securing user data - Bolt rules
View rules.bolt
isUser(uid) = auth != null && auth.uid == uid;
type Post {
uid: String;
title: String;
description: String;
timestamp: Number;
}
type User {
@davideast
davideast / transfer.js
Last active Apr 20, 2021
Transfer data from one Firebase database to another
View transfer.js
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 });
})