Skip to content

Instantly share code, notes, and snippets.

@townivan
townivan / find-that-object.js
Created August 16, 2019 23:22
Get a matching object from an array of objects with a specific value for a property
thingArray.filter(thing => (thing.Name === "Larry"));
@townivan
townivan / .htaccess
Created July 15, 2019 12:59
htaccess which redirects http://domain, https://domain, http://www.domain to https://www.domain
# if host contains www - skip redirect to www
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule .? - [S=1]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# redirect all to https
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@townivan
townivan / gulpfile.esm.js
Created May 31, 2019 14:44
Gulp4 gulpfile w/ basic browserSync+sass. This uses es6 modules via the esm package, hence the .esm.js extension
// renames to gulpfile.esm.js to use the esm package support of es6 module 'import' syntax
import gulp from 'gulp';
import sass from 'gulp-sass';
import browserSync from 'browser-sync';
const myGlobs = {
scssSource: './app/scss/**/*.scss', // includes .scss files in any subfolders of ./scss also
cssDest: './app/css',
htmlSource: './app/*.html',
@townivan
townivan / stuff.js
Created January 8, 2019 19:49
Read all of the .html files in a folder without using a library like glob
const fs = require('fs');
const targetPath = './src/pages/'
// *.html files
let fileNamesArray = fs.readdirSync(targetPath).filter( (file) => {
return file.includes('.html')
})
// 'all-comps.html', 'c090.html', 'c100.html', 'c101.html', 'c102.html', 'index.html' ]
@townivan
townivan / favicon-chrome-error-quick-fix.html
Created November 16, 2018 15:23
favicon-chrome-error-quick-fix
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<!-- credit: https://vsparrow.com/2017/05/01/favicon-ico-failed-to-load-resource-the-server-responded-with-a-status-of-404-not-found/ -->
@townivan
townivan / basic.html
Created November 7, 2018 21:38
standard html page setup
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
@townivan
townivan / online-keyboard-only.html
Last active November 14, 2018 02:48
outline style only for keyboard
<script>
// Let the document know when the mouse is being used
document.body.addEventListener('mousedown', function() {
document.body.classList.add('using-mouse');
});
document.body.addEventListener('keydown', function() {
document.body.classList.remove('using-mouse');
});
</script>
@townivan
townivan / color object
Created September 13, 2018 20:16 — forked from OneCent01/color object
Every color contained in an object with its corresponding hexa value for O(1) time lookup, find function below object
var colors = {
ALICEBLUE: '#F0F8FF',
ANTIQUEWHITE: '#FAEBD7',
AQUA: '#00FFFF',
AQUAMARINE: '#7FFFD4',
AZURE: '#F0FFFF',
BEIGE: '#F5F5DC',
BISQUE: '#FFE4C4',
BLACK: '#000000',
BLANCHEDALMOND: '#FFEBCD',
@townivan
townivan / export-errors
Created May 18, 2018 17:49
Export errors from HTML_CodeSniffer.
Array.from(document.querySelectorAll(".HTMLCS-issue-detail-list li")).map((el) => { return { detail: el.querySelector(".HTMLCS-issue-title").textContent, code: el.querySelector(".HTMLCS-issue-source-inner strong").textContent } })
@townivan
townivan / a11y-img-with-no-alt
Created March 22, 2018 14:49
Chuck's excellent script to deal with tracker images without alt tag - the ones that mess up a11y scans!
document.addEventListener('DOMContentLoaded', function () {
const targetNode = document.body;
const callback = function (mutationsList) {
for (let mutation of mutationsList) {
if (mutation.type == 'childList') {
mutation.addedNodes.forEach((node) => {
if (node && node.src && node.src.match(/.*pages02.net.*/).length >
0) {
observer.disconnect();
node.setAttribute("aria-hidden", true);