Skip to content

Instantly share code, notes, and snippets.

View gregfenton's full-sized avatar

Greg Fenton gregfenton

View GitHub Profile
@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
    
@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 / 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 / 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 / FirestoreBackup.js
Last active December 7, 2022 22:57
Backup your Firestore db to a Firebase Storage bucket -- to be called from a Firebase Cloud Function (JavaScript/node)
const functions = require('firebase-functions');
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1.FirestoreAdminClient();
//
// Add config values with CLI command:
// firebase functions:config:set my_app_name='{"fsBackupBucket":"gs://my-fs-backup-bucket"}'
//
const config = functions.config();
@gregfenton
gregfenton / fetch-user-records-from-google-sheets.js
Last active December 7, 2022 23:00
Downloads data from a Google Sheets worksheet and stores in a local JSON file -- command-line JavaScript/node
/**
* A script that:
* 1. loads Google Sheets API keys and spreadsheet IDs (see GOOGLE_API_KEY)
* 2. connects to the identifed Google Sheet
* 3. grabs the data from a named Worksheet (see SHEET_TO_GET)
* 4. iterates over each row (see processUserRows())
* 5. puts them into a JSON structure
* 6. and writes that out to a file (see FILE_NAME)
*
* To run this script, I have this in my package.json:
@gregfenton
gregfenton / .versionrc.js
Last active February 18, 2023 22:43
EXPO: configuration of standard-version-expo for a code base that has multiple configuration files
/* What?
* A configuration for standard-version-expo that updates multiple config files
* by dynamically identifying them from a sub-directory when you bump the
* version using the `standard-version` tool
*
* How?
* Modelled from the post by @bycedric: https://dev.to/bycedric/simplify-expo-releases-with-standard-version-2f4o
* Follow the setup instructions listed at the URL above or at https://github.com/expo-community/standard-version-expo
*
* Why?
@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 / README.md
Last active March 10, 2023 03:33 — forked from acidtone/README.md
Express: Hello World!

Express: Add "Hello World!" API

Prerequisites

  1. Initialized ExpressJS project as per this gist

Example directory structure

project-root
    ├── node_modules
 ├── package-lock.json