Skip to content

Instantly share code, notes, and snippets.

View bchiang7's full-sized avatar

Brittany Chiang bchiang7

View GitHub Profile
@bchiang7
bchiang7 / User.js
Last active November 12, 2019 18:26
// models/User.js
class User extends Base {
// Expected schema of the User record
get schema() {
return {
id: Joi.string(),
createdAt: Joi.string().isoDate(),
displayName: Joi.string().allow('').allow(null).default(''),
email: Joi.string().email({ minDomainSegments: 2 }).default(''),
isAdmin: Joi.bool().default(false),
/**
* Fetches the session user from cache if it exists, or sets it if it does not
*/
const getOrSetUserFromCache = async headers => {
const User = require('../models/User');
const userUid = headers['x-userid'];
try {
const firebaseUserUid = await User.getUserIdFromToken(headers.authorization);
if (!userUid || firebaseUserUid !== userUid) {
// Create a new User model instance
const harryPotter = new User({
id: 'abc123',
email: 'harry@hogwarts.com',
displayName: 'The Boy Who Lived',
...
});
// Add it as a document in the `users` collection in Firestore
harryPotter.create();
// Deletes a user by ID in firestore user collection & firebase auth
static async deleteUserById(id) {
const userRef = firestore
.collection(this.collectionName())
.doc(id);
const batch = firestore.batch();
batch.delete(userRef);
const completedTasksToDelete = await firestore
const User = require('../models/User.js');
await User.deleteUserById(id);
// Example document in `completedTasks` collection
{
"completedAt": "2019-10-17T20:14:24.132Z",
"expirationTimestamp": "2019-10-31T08:25:00.000Z",
"userId": "xyz890",
"taskId": "abc123",
}
#!/bin/bash
bold=$(tput bold)
normal=$(tput sgr0)
set -e
echo "-----------------------------------------------"
echo " ๐Ÿš€ Creating a new release ๐Ÿš€"
echo "-----------------------------------------------"
@bchiang7
bchiang7 / event-bus.js
Last active January 11, 2020 05:13
Simple event bus in plain JS
// Inspired by Vue: https://alligator.io/vuejs/global-event-bus/
// Sending events: EventBus.emit('clicky', clickArg);
// Receiving events: EventBus.on('clicky', clickArg => console.log(clickArg));
const EventBus = {
events: {},
emit(event, data) {
if (!this.events[event]) {
return;
}
<?php
if (! (defined('WP_CLI') && WP_CLI)) {
return;
}
class Algolia_Command {
public function reindex($args, $assoc_args) {
...
}
<?php
public function reindex($args, $assoc_args) {
// Init global index
$index = $algolia->initIndex('global_search');
// Clear all objects in the index
$index->clearObjects()->wait();
// Get all blog IDs in multisite network