Skip to content

Instantly share code, notes, and snippets.

View phiniezyc's full-sized avatar

Chance phiniezyc

  • Atlanta, GA
View GitHub Profile
@phiniezyc
phiniezyc / withPageAuthRequired.js
Created January 14, 2022 02:32
withPageAuthRequired with getServerSideProps
export const getServerSideProps = withPageAuthRequired({
async getServerSideProps(context) {
return { props: {} };
},
});
@phiniezyc
phiniezyc / Auth0AddUserRolesToTokens.js
Last active December 15, 2021 00:12
Auth0 Rule to Add User Roles to Tokens (Access and Id Tokens). Set in Auth0 Rules:
function setRolesToUser(user, context, callback) {
const namespace = 'http://my-website-name.com';
const assignedRoles = (context.authorization || {}).roles;
let idTokenClaims = context.idToken || {};
let accessTokenClaims = context.accessToken || {};
idTokenClaims[`${namespace}/roles`] = assignedRoles;
accessTokenClaims[`${namespace}/roles`] = assignedRoles;
@phiniezyc
phiniezyc / Auth0SaveUserToLocalDB.js
Created December 14, 2021 07:35
Auth0 Action to Save User in MongoDB
const { MongoClient } = require('mongodb');
/**
* Handler that will be called during the execution of a PostUserRegistration flow.
*
* @param {Event} event - Details about the context and user that has registered.
*/
exports.onExecutePostUserRegistration = async (event) => {
let uri = event.secrets.MONGODB_URI;
let dbName = event.secrets.MONGODB_DB;
@phiniezyc
phiniezyc / dynamicProps.js
Created November 11, 2021 06:18
How To Get Dynamic Properties (from a form input)
const submitUpdate = async (e, propertyName) => {
e.preventDefault();
const res = await fetch('http://localhost:3000/api/landing', {
body: JSON.stringify({
[propertyName]: e.target[propertyName].value,
}),
headers: {
'Content-Type': 'application/json',
},
@phiniezyc
phiniezyc / react-bind.md
Created September 3, 2021 06:37 — forked from fongandrew/react-bind.md
Explaining why we bind things in React

Start With This

Before getting to React, it's helpful to know what this does generally in Javascript. Take the following snippet of code. It's written in ES6 but the principles for this predate ES6.

class Dog {
  constructor() {
import React, { Component, Fragment } from 'react';
import ReactModal from 'react-modal';
import { connect } from 'react-redux';
import { fetchPlaylistTracks } from '../actions/index';
import TracksModalContent from './TracksModalContent';
ReactModal.setAppElement('#root'); // ReactModal use for screen readers (see docs)
const buttonDivStyle = {
flex: '100%'
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
You've now created an alias to git log called git lg that will display the nicer output showed before. Try it out by typing git lg (or git lg -p to see the lines that have changed).
https://dev.to/christopherkade/up-your-git-game-and-clean-up-your-history-4j3j?utm_source=digest_mailer&utm_medium=email&utm_campaign=digest_email
@phiniezyc
phiniezyc / steps.js
Created April 23, 2019 06:58
Stairs problem that console logs the number of # for each level and a space for the appropriate level.
function stairs(num) {
for (let row = 0; row< num; row++) {
let level = "";
for (let column = 0; column< num; column++){
if (column <= row) {
level += "#";
}
else {
level += " ";
@phiniezyc
phiniezyc / reverseStr.js
Created March 27, 2019 07:40
How to reverse a string JS
function strRev(str) {
let left = 0;
let right = str.length-1;
const strArr = str.split("");
while (left < right) {
let tempLeft = strArr[left];
let tempRight = strArr[right];
strArr[left] = tempRight;
strArr[right] = tempLeft;
@phiniezyc
phiniezyc / jSLinkedList.js
Last active July 30, 2019 23:20
Javascript Implementation of a Linked List
class Node {
constructor(value) {
this.value = value;
this. next = null;
}
}
class LinkedList {
constructor(value) {