Skip to content

Instantly share code, notes, and snippets.

View joshcanhelp's full-sized avatar
👋
Open to new connections!

Josh Cunningham joshcanhelp

👋
Open to new connections!
View GitHub Profile
@joshcanhelp
joshcanhelp / app.js
Created October 17, 2024 22:30
Basic Express template
import express from "express";
const { APP_PORT } = process.env;
const appPort = parseInt(APP_PORT, 10) || 3000;
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
import { readFileSync, writeFileSync } from "fs";
import { DateTime } from "luxon";
import { stringify } from "yaml";
// Subfolder in the vault
const PATH_TO_FOLDER = "/Users/joshcanhelp/Notes/Log/Day One/";
// Day One tags as keys, Obsidian tags as values
const tagMap = {
FromTag1: "to-tag-1",
@joshcanhelp
joshcanhelp / checkWordPressForUserAction.js
Last active November 14, 2022 23:20
Auth0 Action to check a WordPress migration endpoint for the existence of a user.
const axios = require("axios");
const customClaimNamespace = "https://wp/has_account";
exports.onExecutePostLogin = async (event, api) => {
const {
WP_API_CLIENT_ID,
WP_API_IDENTIFIER,
WP_API_BASE_URL,
WP_API_TOKEN,
@joshcanhelp
joshcanhelp / step-up-auth-action.js
Created December 7, 2021 18:58
Step-up authentication in Auth0 using Actions
exports.onExecutePostLogin = async (event, api) => {
const CLIENTS_NEEDING_MFA = [
"CLIENT_ID_NEEDING_MFA_1",
"CLIENT_ID_NEEDING_MFA_2"
];
if (!CLIENTS_NEEDING_MFA.includes(event.client.client_id)) {
return;
}
@joshcanhelp
joshcanhelp / convert-roam-daily-to-obsidian.js
Created October 18, 2021 23:56
Convert Roam daily exports to Obsidian default date format
const { opendir, writeFile, readFile } = require('fs/promises');
const uniqueMonth = [];
(async () => {
const dir = await opendir('./_in');
for await (const dirent of dir) {
const namePieces = dirent.name
.replace("st,", "")
.replace("nd,", "")
@joshcanhelp
joshcanhelp / keygen.js
Last active July 11, 2021 19:11
Generate a JWK-formatted private key in Node.js
const { generateKeyPair } = require('jose/util/generate_key_pair');
const { fromKeyLike } = require('jose/jwk/from_key_like');
(async () => {
const { privateKey } = await generateKeyPair('RS256');
const jwk = await fromKeyLike(privateKey);
console.log(JSON.stringify(jwk));
})();
// $ npm install jose
@joshcanhelp
joshcanhelp / checkWordPressForUser.js
Last active December 31, 2020 20:59
Check a WordPress migration endpoint for the existence of a user.
async function checkWordPressForUser(user, context, callback) {
if (!user.email) {
console.log("User does not have an email to use.");
return callback(null, user, context);
}
const customClaimNamespace = "https://custom-claim/has_wp_account";
const {
WP_API_CLIENT_ID,
WP_API_IDENTIFIER,
@joshcanhelp
joshcanhelp / docker-compose.yml
Last active October 10, 2023 20:18
Docker compose for Auth0 WordPress development
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
@joshcanhelp
joshcanhelp / .bashrc
Last active March 17, 2021 17:47
Easy ULP modification with Netlify
# ...
export AUTH0_API2_TOKEN="Your management API token goes here"
export AUTH0_API2_DOMAIN="Your tenant domain goes here"
# https://cli.netlify.com/
alias sync_ulp='netlify deploy --prod --dir . && curl --request PUT \
--data "@./index.html" \
--header "authorization: Bearer $AUTH0_API2_TOKEN" \
--url "https://$AUTH0_API2_DOMAIN/api/v2/branding/templates/universal-login" \
@joshcanhelp
joshcanhelp / delete_unused_files.sh
Created March 9, 2020 21:09
Deletes unused files
while IFS= read -r -d '' file
do
if grep -qr "$file" ../content/md
then echo "Keeping $file";
else rm "$file";
fi
done < <(find _images -type f -print0)