Skip to content

Instantly share code, notes, and snippets.

View imjakechapman's full-sized avatar
⛓️
@6079.ai

Jake Chapman imjakechapman

⛓️
@6079.ai
View GitHub Profile
function randomBetween(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
@imjakechapman
imjakechapman / focus.css
Created July 18, 2020 05:08
Remove focus outline for non keyboard focus
:focus:not(:focus-visible) {
outline: none;
}
@imjakechapman
imjakechapman / hooks
Created May 28, 2020 16:31
Automatically npm install when package.json has changed when git pull
#/usr/bin/env bash
changed="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check() {
echo "$changed" | grep --quiet "$1" && eval "$2"
}
check package.json "npm install"
// import { UserInputError } from 'apollo-server'
import { IResolvers } from "graphql-tools";
import merge from "lodash.merge";
const ChargesRootResolvers: IResolvers = {
// Stripe returns either just a string as the charge id or an expanded object with all charge attributes.
// So we check if it's expanded by if the charge is an instanceof Object or a string
ChargeUnion: {
__resolveType(charge: string | { [key: string]: any }) {
if (charge instanceof Object) {
const data = {
name: "Ted Bundy",
email: "yummy@thatsnotcool.com",
address: {
line1: "9412 39th Street East",
line2: "Suite 456",
country: "",
city: "",
}
};
@imjakechapman
imjakechapman / password_complexity_regex.js
Last active April 21, 2020 22:57
Password Complexity Regex's
// 8 characters minium. 1 uppercase character, 1 lowercase character, 1 number, 1 special character
const strongRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})/;
// 6 characters minium. 1 uppercase character, 1 lowercase character, 1 number
const mediumRegex = /^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})/
@imjakechapman
imjakechapman / useNestedMatch.js
Created April 20, 2020 13:23
React Router V6 Hook to help with nested routers and top level NavLink's maintain an active class
import { useState, useEffect } from "react";
import { useLocation } from "react-router-dom";
export const useNestedMatch = (test, type = "") => {
const { pathname } = useLocation();
const [match, setMatch] = useState(false);
useEffect(() => {
let result;
switch (type) {
@imjakechapman
imjakechapman / nestedMatch.ts
Last active April 20, 2020 12:50
Utility function to temporarily match parts of pathname to add active classes onto top level NavLink component in nested routers
function nestedMatch(test: string, type: string = "", path: string = location.pathname): boolean {
switch(type) {
case 'startsWith':
return path.match(new RegExp(`^\/${test}`))?.length ? true : false
case 'endsWith':
return path.match(new RegExp(`/${test}$`))?.length ? true : false
default:
return path.match(new RegExp(`${test}`))?.length ? true : false
}
}
// V5
<Router>
<Switch>
<Route path="/one" component={ViewOne} />
<Route path="/two" component={ViewTwo} />
<Route path="/three" component={ViewThree} />
<Route render={() => <Redirect to="/one" />} />
</Switch>
</Router>
@imjakechapman
imjakechapman / applyFilter.js
Created April 2, 2020 21:36
Facebook Interview Question
const items = [
{type: 'phone', name: 'iPhone', color: 'gold'},
{type: 'laptop', name: 'Chromebook', color: 'gray'},
];
const excludes = [
{k: 'color', v: 'gold'},
{k: 'color', v: 'silver'},
{k: 'type', v: 'tv'}
];