Skip to content

Instantly share code, notes, and snippets.

View gregfenton's full-sized avatar

Greg Fenton gregfenton

View GitHub Profile
@gregfenton
gregfenton / restore-uistate.jsx
Created March 8, 2024 21:46
Algolia react-instantsearch code not working correctly
<InstantSearch
indexName={ALGOLIA_INDEX_PROJECT}
searchClient={searchClient}
routing={routing}
future={{
preserveSharedStateOnUnmount: true,
}}
onStateChange={({uiState, setUiState}) => {
if (firstRender.current) {
firstRender.current = false;
@gregfenton
gregfenton / create-alerts.js
Created February 10, 2024 17:57
Failing attempt at using @google-cloud/monitoring to add LogEvent policies -- API does not currently support it
// This code fails with the error described in:
// https://github.com/googleapis/google-cloud-node/issues/4361
//
// The Node/JS version of the SDK currently does not support adding LogEvent policies.
//
//
// To run this code:
// - save to a file (e.g. "create-alerts.js")
// - be logged into your gcloud account (`gcloud auth login`)
// - set the env var `PROJ_ID` with your project ID
@gregfenton
gregfenton / functions--index.ts
Last active February 7, 2024 16:43
`index.ts` for my Cloud Functions project that load other CF files dynamically from the directory structure
/*
* This file is used to dynamically import and export functions from the `fs`, `http`, `sched`, and `storage` directories.
* The exported functions are then used in the `index.ts` file to define the Cloud Functions.
*
* Only files with the extension `.f.ts` are imported and exported (well, `.f.js` after `tsc` has run).
*
* Concept for this is inspired by https://codeburst.io/organizing-your-firebase-cloud-functions-67dc17b3b0da
* -- Thank you @TarikHuber !!
*/
import * as fs from 'fs';
@gregfenton
gregfenton / create_firebase_project.bash
Last active June 16, 2023 23:04
Shell script for creating a Firebase project
#!/bin/bash
red=$(tput setaf 1)
green=$(tput setaf 2)
blue=$(tput setaf 6)
yellow=$(tput setaf 3)
reset=$(tput sgr0)
ROOT=$(pwd)
echo ""
@gregfenton
gregfenton / i18NextFirestoreProvider.js
Created May 15, 2022 01:28
An example Context API provider for use with the i18next-node-firestore-backend
import React, {createContext, useEffect, useState} from "react";
import i18next from "i18next";
import {initReactI18next} from "react-i18next";
import Backend from "i18next-node-firestore-backend";
import {FIRESTORE} from "../myFirebase";
// export const I18NEXT_FS_BKEND_LANGUAGE_LIST_FIELD_NAME = 'languages';
const I18NEXT_DEFAULT_NAMESPACE = "core";
const I18NEXT_FS_BKEND_COLLECTION_NAME = "config/type/i18n";
@gregfenton
gregfenton / UploadToFirebaseStorageFromReactNative.js
Last active February 26, 2023 22:13
JavaScript to upload a file/URL from React-Native (Expo) to Firebase Storage -- updated (loosely) to the Firebase v9 API syntax
//
// `npx expo install cuid`
//
import {myStorage} from '../myFirebase';
import {getAuth} from 'firebase/auth';
import {ref, child, put} from 'firebase/storage';
import cuid from 'cuid';
/**
@gregfenton
gregfenton / versionForAppConfig.js
Last active April 25, 2022 06:05
Expo - generate iOS buildNumber and Android versionCode from SemVer
// version.json:
//
// {
// "version": "3.0.23"
// }
let VERSION_JSON = `${PROJECT_CONFIG_DIR}/version.json`;
versionString = getVersionString(VERSION_JSON);
@gregfenton
gregfenton / firestore_add_doc.js
Last active April 3, 2022 16:15
A super simple command-line Node script to add a document to Firestore
/**
* firestore_add_doc.js
*
* This script is assumed to live in an existing Javascript project that has its own package.json.
* I store this script in <PROJECT_ROOT>/tools/misc/.
*
* To use:
* 1. npm init -y
* 2. npm install firebase esm
* 3. Edit this code to set for USER1 and FIREBASE_CONFIG
@gregfenton
gregfenton / App.js
Last active April 19, 2022 12:29
App, FirebaseProvider and AuthProvider for use with v9 Firebase Web SDK
import React from "react";
import {FirebaseProvider} from "contexts/FirebaseContext";
import {AuthProvider} from "contexts/AuthProvider";
const App = () => {
return (
<FirebaseProvider>
<AuthProvider>
@gregfenton
gregfenton / README.md
Last active March 10, 2022 15:31
Express: Handling URL query parameters

Express: Handling URL query parameters

Prerequisites

  1. Express "Hello World!" app created.

Assumptions

  1. GET request includes query parameters after the ? symbol. Example:
    http://locahost:4000/forest?daylight=true