This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Input = () => { | |
const handleKeyDown = (event) => { | |
if (event.key === 'Enter') { | |
console.log('do validate') | |
} | |
} | |
return <input type="text" onKeyDown={handleKeyDown} /> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sendDiscordMessage = async (type = 'info', name, message) => { | |
const webhook = require('webhook-discord'); | |
const Hook = new webhook.Webhook( | |
'your-discord-hook-key' | |
); | |
if (type === 'info') { | |
return Hook.info(name, message); | |
} | |
if (type === 'warn') { | |
return Hook.warn(name, message); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// const admin = require('firebase-admin'); | |
const { sendDiscordMessage } = require('./helpers'); | |
const { google } = require('googleapis'); | |
const { GoogleAuth } = require('google-auth-library'); | |
const PROJECT_ID = 'project-name'; | |
const PROJECT_NAME = `projects/${PROJECT_ID}`; | |
const billing = google.cloudbilling('v1').projects; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# yea yea windows will require WSL | |
red=$(tput setaf 1) | |
green=$(tput setaf 2) | |
bg_blue=$(tput setab 4) | |
bg_cyan=$(tput setab 6) | |
reset=$(tput sgr0) | |
nl=$(tput il 1) | |
echo "${red}red text ${green}green text${reset}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const batchWrapper = async (documentRef, action, update) => { | |
const batchArray = []; | |
batchArray.push(db.batch()); | |
let operationCounter = 0; | |
let batchIndex = 0; | |
documentRef.forEach(doc => { | |
console.log('Org cleanup: deleting notifications', doc.id); | |
if (action === 'delete') { | |
batchArray[batchIndex].delete(doc.ref); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useCallback } from 'react'; | |
import { useFirestoreCollectionData, useFirestore } from 'reactfire'; | |
function useProjects() { | |
// lazy load the Firestore SDK | |
const firestore = useFirestore() | |
const projectsRef = firestore.collection('projects') | |
// subscribe to the do throws a Promise for Suspense to catch, | |
// and then streams live updates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import firebase from "firebase/app"; | |
import "firebase/auth"; | |
import "firebase/functions"; | |
import "firebase/firestore"; | |
let config = { | |
apiKey: process.env.REACT_APP_FIREBASE_API_KEY, | |
authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN, | |
databaseURL: process.env.REACT_APP_FIREBASE_DB_URL, | |
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const users = redeem.data.map(item => item.employeeProfile); | |
const uniques = new Set(users.map(e => JSON.stringify(e))); | |
const uniqueUsers = Array.from(uniques).map(e => JSON.parse(e)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect, useRef, useCallback } from 'react'; | |
const mountedRef = useRef(true); | |
const fetchData = useCallback(async () => { | |
try { | |
// do your async call here | |
const ref = await db | |
.collection('stuff') | |
.where('stuff', '==', id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Paste this in: | |
function clearCollection(path) { | |
const ref = firestore.collection(path) | |
ref.onSnapshot((snapshot) => { | |
snapshot.docs.forEach((doc) => { | |
ref.doc(doc.id).delete() | |
}) | |
}) | |
} | |
// Use it like this: |
NewerOlder