Skip to content

Instantly share code, notes, and snippets.

Avatar
🔥
Working on Firebase

David East davideast

🔥
Working on Firebase
View GitHub Profile
@davideast
davideast / firestore.gs
Last active Sep 23, 2019
Export to Firestore in AppScript
View firestore.gs
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 Feb 8, 2019
syncWithElements
View index.ts
// 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'),
View selectText.js
function selectText(selection) {
var range = selection.getRangeAt(0);
function replaceRange(s, start, end, substitute) {
return s.substring(0, start) + substitute + s.substring(end);
}
var text = selection.baseNode.textContent.substring(range.startOffset, range.endOffset);
var mark = `<mark>${text}</mark>`;
range.startContainer.parentElement.innerHTML = replaceRange(range.startContainer.textContent, range.startOffset, range.endOffset, mark);
}
@davideast
davideast / index.ts
Last active Aug 10, 2017
Angular Universal Server
View index.ts
import { angularUniversal } from 'angular-universal-express';
import * as express from 'express';
const app = express();
// serving static requests
app.use(express.static(__dirname + '/static'));
// serving dynamic requests
app.get('/*', angularUniversal({
index: __dirname + '/index.html',
main: __dirname + '/main.<your-hash>.bundle',
@davideast
davideast / tsconfig.json
Created Aug 10, 2017
Angular Universal Server Build
View tsconfig.json
{
"compilerOptions": {
"outDir": "../dist-server",
"sourceMap": true,
"moduleResolution": "node",
"target": "es5",
"lib": [ "es2017" ]
}
}
@davideast
davideast / build.sh
Last active Aug 10, 2017
Angular Universal + TS server build
View build.sh
# Build the browser bundle
ng build --prod
# Build the universal bundle
ng build --prod --app 1
# Move the browser index.html to generate the SSR version
mv dist/index.html dist-server/
# Treat dist as static within dist-server
mv dist/ dist-server/static
# Transpile TS server code
node_modules/.bin/tsc -p server/tsconfig.json
@davideast
davideast / build.sh
Last active Aug 10, 2017
Angular Universal Build
View build.sh
# Build the browser bundle
ng build --prod
# Build the universal bundle
ng build --prod --app 1
# Move the browser index.html to generate the SSR version
mv dist/index.html dist-server/
# Treat dist as static within dist-server
mv dist/ dist-server/static
@davideast
davideast / server.ts
Last active Aug 10, 2017
Angular Universal Express Sample
View server.ts
import { angularUniversal } from 'angular-universal-express';
import * as express from 'express';
const app = express();
/*
I usually copy my Angular CLI "dist" build into my "dist-server" build
and serve them as static files so they aren't treated as dynamic routes.
*/
app.use(express.static(__dirname + '/dist'));
app.get('/*', angularUniversal({
@davideast
davideast / naked-import.js
Created Mar 21, 2017
Firebase ES2015 imports
View naked-import.js
import * as firebase from 'firebase/app'; // Provides firebase-app.js only
import 'firebase/auth'; // Not named, just naked
const app = firebase.initializeApp({ });
console.log(app.auth()); // auth object
console.log(app.database()); // undefined