Skip to content

Instantly share code, notes, and snippets.

View davideast's full-sized avatar
💜
Working on Project IDX (and Firebase too)

David East davideast

💜
Working on Project IDX (and Firebase too)
View GitHub Profile
@davideast
davideast / index.ts
Created April 15, 2015 17:25
Simple Angular 2 Forms with Firebase
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 / transfer.js
Last active April 20, 2021 17:19
Transfer data from one Firebase database to another
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 });
})
@davideast
davideast / example.js
Last active April 20, 2021 17:19
Push and return Firebase
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()));
@davideast
davideast / rules.json
Last active April 20, 2021 17:19
Bolt output
{
"rules": {
"users": {
"$uid": {
".validate": "newData.hasChildren(['uid', 'name', 'username'])",
"uid": {
".validate": "newData.isString()"
},
"name": {
".validate": "newData.isString()"
@davideast
davideast / SyncPath.js
Last active April 20, 2021 17:19
Firebase Social Network Client Fanout
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 / push.js
Last active April 20, 2021 17:19
Send push notifications with node-apn and Firebase
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) {
@davideast
davideast / bulkUpdate.js
Last active April 20, 2021 17:18
Bulk update with .push()
/**
* 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 / firestore.gs
Last active September 23, 2019 03:08
Export to Firestore in AppScript
function main() {
var sheet = SpreadsheetApp.getActiveSheet();
// This is set as the collection name
var sheetName = sheet.getName();
var properties = getProperties(sheet);
var records = getData(sheet);
var firestore = getFirestore();
exportToFirestore(firestore, sheetName, records, properties);
}
@davideast
davideast / index.ts
Last active February 8, 2019 18:08
syncWithElements
// https://stackblitz.com/edit/typescript-h68plq?file=index.ts
import firebase from 'firebase/app';
import 'firebase/firestore';
import { syncWithElements } from './sync';
const app = firebase.initializeApp({ projectId: "alwaysbecaching" });
const unsub = syncWithElements(app, {
parent: document.querySelector('.container'),
@davideast
davideast / FIREBASE_WISHLIST.md
Created June 18, 2017 16:32
Firebase Wishlist

COME BACK ADAM