Skip to content

Instantly share code, notes, and snippets.

View JohnnyMcFadden's full-sized avatar

Johnny McFadden JohnnyMcFadden

View GitHub Profile
@JohnnyMcFadden
JohnnyMcFadden / file-templates.js
Last active April 30, 2021 21:37
The Joe Codes Blog - Productive Tooling - File Templates
// -------------------
/* script.js */
// -------------------
// ... prev code
const rootDirectoryPath = `./src/articles/${readType}/${directoryName}`;
const componentsDirectoryPath = `${rootDirectoryPath}/components`;
// Create directories
@JohnnyMcFadden
JohnnyMcFadden / index.html
Last active April 26, 2021 15:29
The Joe Codes Blog - Web Accessibility - Nav Element
<nav aria-label="Primary">
<ul>
<li><a href="/articles/sass">Sass</a></li>
<li>
<a href="/articles/javascript">Javascript</a>
<!-- Notice how the <nav> element does NOT added again -->
<ul>
<li><a href="/articles/javascript/promises">Promises</a></li>
<li><a href="/articles/javascript/vanilla">Vanilla</a></li>
</ul>
@JohnnyMcFadden
JohnnyMcFadden / react-axe.js
Created April 13, 2021 12:22
The Joe Codes Blog - Web Accessibility - React Axe
import React from 'react';
import ReactDOM from 'react-dom';
if (process.env.NODE_ENV !== 'production') {
import('@axe-core/react').then((axe) => {
axe(React, ReactDOM, 1000, {}, '#root'); // optional 5th arg node or arr
});
}
@JohnnyMcFadden
JohnnyMcFadden / video.js
Created April 10, 2021 12:21
The Joe Codes Blog - Web Accessibility - Video Element
import React from 'react';
import PropTypes from 'prop-types';
const Video = ({ src }) => (
<div className="media-container">
<video className="video" autoPlay loop muted playsInline>
<source src={src} type="video/mp4" loop />
</video>
</div>
);
@JohnnyMcFadden
JohnnyMcFadden / readline.js
Last active March 19, 2021 22:20
The Joe Codes Blog - Productive Tooling - Readline Basic Usage
const readline = require('readline');
const userInterface = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
userInterface.question('What is 5x5?', (answer) => {
Number(answer) === 25
? console.log('WELL DONE... ✔️')
@JohnnyMcFadden
JohnnyMcFadden / readline-example.js
Last active March 27, 2021 15:30
The Joe Codes Blog - Productive Tooling - Readline Example
/* ------------------------------
utils.js
------------------------------ */
const readline = require('readline');
const createUserInterface = () =>
readline.createInterface({
input: process.stdin,
output: process.stdout,
});
@JohnnyMcFadden
JohnnyMcFadden / zsh-chalk.js
Created March 19, 2021 12:37
The Joe Codes Blog - Productive Tooling - ZSH Columns
const chalk = require('chalk');
const drawLine = (color) =>
console.log(chalk[color]('-'.repeat(process.stdout.columns)));
const centerAlign = (string) => {
const padding = (process.stdout.columns - string.length) / 2;
return `${' '.repeat(padding)}`;
};
@JohnnyMcFadden
JohnnyMcFadden / event-loop-async.js
Last active March 14, 2021 18:13
The Joe Codes Blog - Spooky Event Loop - Async
const changeEmojiDisplayAsync = (type = 'show') => {
console.log('2');
const elements = document.getElementsByClassName('spooky-emoji-async');
for (let element of elements) {
setTimeout(() => {
console.log('(3) change element className');
element.className = `spooky-emoji-async spooky-emoji-async--${type}`;
}, 2000);
}
};
@JohnnyMcFadden
JohnnyMcFadden / event-loop-synchronous.js
Last active March 14, 2021 18:23
The Joe Codes Blog - Spooky Event Loop - Synchronous
const changeEmojiDisplay = (type = 'show') => {
console.log('2');
const elements = document.getElementsByClassName('spooky-emoji');
for (let element of elements) {
console.log('(3) change element className');
element.className = `spooky-emoji spooky-emoji--${type}`;
}
};
const changeTextDisplay = (type = 'show') => {
@JohnnyMcFadden
JohnnyMcFadden / color-picker.js
Last active March 26, 2021 16:10
The Joe Codes Blog - CSS Custom Properties Theme - Custom Properties - Color Picker
// imported from utils
const styleInterface = document.documentElement.style;
<label>
Background Color:
<input
type="color"
onChange={(event) =>
styleInterface.setProperty(`--background-body`, event.target.value)
}