Skip to content

Instantly share code, notes, and snippets.

View davidpatrick's full-sized avatar

David Patrick davidpatrick

View GitHub Profile
# ======= NVM CUSTOMIZATIONS ======= #
load-nvmrc() {
echo "loading nvm"
if [[ -f .nvmrc && -r .nvmrc ]]; then
nvm use
else
echo "Reverting to nvm default version"
nvm use default
fi
@davidpatrick
davidpatrick / auth0-react-spa.js
Created September 30, 2019 22:22
Auth0 SPA JS React Wrapper
import React, { useState, useEffect, useContext } from "react";
import createAuth0Client from "@auth0/auth0-spa-js";
const DEFAULT_REDIRECT_CALLBACK = () =>
window.history.replaceState({}, document.title, window.location.pathname);
export const Auth0Context = React.createContext();
export const useAuth0 = () => useContext(Auth0Context);
export const Auth0Provider = ({
children,
@davidpatrick
davidpatrick / webtask-magicword.js
Last active July 14, 2016 19:00
WebTask Github Hook used for warning users not push directly to the master branch.
var child_process = require('child_process');
var email_msg = 'Dear Github User, \n\n Please review this video before pushing directly to master: https://www.youtube.com/watch?v=fmz-K2hLwSI \n\n Thanks,\n Dennis Nedry';
module.exports = function (context, cb) {
if (context.body) {
var branch = context.body.ref.split('refs/heads/')[1];
if (branch === context.body.repository.master_branch) {
var pusher = context.body.pusher;
@davidpatrick
davidpatrick / FlattenArray.js
Created June 28, 2016 17:13
Flatten Methods in Ruby and Javascript
function flatten(objects) {
var array = [];
objects.forEach(function(obj){
if(Array.isArray(obj)) {
array = array.concat(flatten(obj));
} else {
array.push(obj);
}
});
@davidpatrick
davidpatrick / Cache.js
Created June 28, 2016 08:14
Requesting data in the component's lifecycle can add a lot of costly overhead to navigation. Each time the user navigates to a component containing an ajax request in its lifecycle, the request will be fired off again, including the forward/back browser buttons. To avoid the costly overhead I've implemented a simple cache store to cache those re…
import $ from 'jquery';
const cache = {};
export const cacheStore = function(key) {
return cache[key];
}
export const requestWithCache = function(url, refresh) {
if (cache[url] && !refresh) {