Skip to content

Instantly share code, notes, and snippets.

Kato Richardson katowulf

Block or report user

Report or block katowulf

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
katowulf / DbBatch.ts
Last active Sep 13, 2019
Batch utility for seeding data and deleting collections larger than 500 docs.
View DbBatch.ts
import db from './db';
// Set this to the max ops per batch listed in the Firestore docs
export const MAX_BATCH_OPS = 500;
// A batch processor that will accept any number of requests.
// It processes batches in the maximum number of events allowed.
// Does not guarantee atomicity across batches.
katowulf /
Created Sep 9, 2019
Get multiple app instances of Firestore in Firebase SDKs. More on multiple environments here:
FirebaseApp primary = FirebaseApp.getInstance();
FirebaseFirestore primaryDatabase = FirebaseFirestore.getInstance();
// Reference the same setup/instance
FirebaseOptions options = primary.getOptions();
// Use multiple projects/environments. More here:
FirebaseOptions options = new FirebaseOptions.Builder()
.setApplicationId("1:27992087142:android:ce3b6448250083d1") // Required for Analytics.
katowulf / pseudo_code.js
Last active Jul 18, 2019
Convert Cloud Storage json file to event stream and store output in Firestore
View pseudo_code.js
JSONStream = require('JSONStream');
es = require('event-stream');
fileStream = storage.bucket('your-bucket').file('your-JSON-file').createReadStream();
db = admin.firestore();
return new Promise( (resolve, reject) => {
batchPromises = [];
batchSize = 0;
batch = db.batch();
katowulf / simpleDocSharing_listMembers.js
Last active Jun 7, 2019
Psuedo rules examples for role based document sharing in Firestore.
View simpleDocSharing_listMembers.js
// docs/{docId}/users is an array of user ids allowed to access the doc
/match/docs/{docId} {
allow read if request.auth.uid in getData('docs/$(docId)').users;
* Shortcut to simplify pathing
function getPath(childPath) {
katowulf / logger.ts
Created May 9, 2019
A simple JavaScript/TypeScript logger for outputting messages to console and to DOM
View logger.ts
'use strict';
// Rudimentary logger impl that outputs
// to the JS console and to <div> tag
// in demo app.
// ♡ Firebase
katowulf / client-index.ts
Last active May 9, 2019
Example of validating Firestore writes using Cloud Functions endpoints
View client-index.ts
import './style.css';
import logger from './logger'; // see
import {sendRequest} from './request';
const endpoint = '';
const data = {
string: 'foo',
integer: 23,
boolean: false,
katowulf / client.js
Last active May 9, 2019
Firestore security rules validation example
View client.js
import * as firebase from "firebase/app";
import 'firebase/firestore';
import config from './config';
const data = {
string: 'foo',
integer: 23,
boolean: false,
katowulf / create_user_functions.js
Created Dec 3, 2018
Create a Firebase user from an authenticated Cloud Functions HTTPS endpoint.
View create_user_functions.js
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const express = require('express');
const cookieParser = require('cookie-parser')();
const cors = require('cors')({origin: true});
const app = express();
// See
const validateFirebaseIdToken = require('./validateFirebaseIdToken');
katowulf / rules.js
Created Nov 16, 2018
Group inheritance and doc sharing in Firebase rules. See
View rules.js
"rules": {
".read": false,
".write": false,
"roles-example": {
// grant global read to our admin tools
".read": "auth.uid === 'ACCESS_MANAGER'",
// The documents which we are restricting access to
"docs": {
katowulf / call.js
Last active Jun 4, 2019
Modular Functions layout for Firebase
View call.js
export const run = (data, context) => {
const path = data.path;
if( path !== "bar" ) {
throw new functions.https.HttpsError('invalid-argument', "Path was not valid");
return {foo: "bar"};
You can’t perform that action at this time.