Skip to content

Instantly share code, notes, and snippets.

View johnmurch's full-sized avatar

John Murch johnmurch

View GitHub Profile
function convertStringToSpaces(inputString) {
// List of space-like Unicode characters, excluding zero-width spaces for visual effect
const unicodeSpaces = [
'\u0020', // Space
'\u00A0', // No-Break Space
'\u2002', // En Space
'\u2003', // Em Space
'\u2009', // Thin Space
'\u202F', // Narrow No-Break Space
'\u205F', // Medium Mathematical Space
@johnmurch
johnmurch / trek.txt
Created December 29, 2023 03:48
trek keyword - temp
16 inch trek bike size chart
2010 trek 2.1 alpha road bike
2010 trek 2.1 alpha road bike review
2011 trek fuel ex 8 seatpost diameter
2012 trek 2.1 alpha road bike
2012 trek fuel ex 8 seatpost diameter
2013 trek fuel ex 8 seatpost diameter
2014 trek fuel ex 7 rear shock
2014 trek fuel ex 7 weight
2015 trek crockett geometry
@johnmurch
johnmurch / scrollTrack.js
Created June 16, 2023 14:15
Page Scroll depth tracking
function trackScrollDepth() {
const scrollPercentages = [25, 50, 75, 100];
window.addEventListener('scroll', () => {
const scrollHeight = document.documentElement.scrollHeight - window.innerHeight;
const scrollPosition = window.scrollY;
const scrollRatio = (scrollPosition / scrollHeight) * 100;
if (scrollPercentages.includes(Math.floor(scrollRatio))) {
// Perform scroll depth tracking actions
console.log(`Scrolled to ${Math.floor(scrollRatio)}%`);
}
@johnmurch
johnmurch / validate.js
Created February 7, 2023 15:25
Simple validation
const validKeyNames = ['name', 'gender', 'hasTheForce']
var a = { name: 'Luke Skywalker', gender: 'Male', hasTheForce: true }
var b = { name: 'James Brown', gender: 'Male', hasTheFunk: true }
function check(obj, arr) {
return Object.keys(obj).every(e => arr.includes(e));
}
console.log(check(a, validKeyNames))
console.log(check(b, validKeyNames))
@johnmurch
johnmurch / fetch.js
Created October 6, 2022 14:23
Simple https Fetch for JSON (node.js)
const https = require('https');
async function fetch(url) {
return new Promise(async (resolve, reject) => {
https.get(url, function (res) {
var body = '';
res.on('data', function (chunk) {
body += chunk;
});
res.on('end', function () {
@johnmurch
johnmurch / colr.js
Last active September 19, 2022 15:11
Get Fonts from Website
// via https://stackoverflow.com/a/39900099
function listFonts () {
let fonts = []
for (let node of document.querySelectorAll('*')) {
if (!node.style) continue
for (let pseudo of ['', ':before', ':after']) {
let fontFamily = getComputedStyle(node, pseudo).fontFamily
fonts = fonts.concat(fontFamily.split(/\n*,\n*/g))
}
}
@johnmurch
johnmurch / uniq.sh
Created September 6, 2022 09:59
Get Uniques
sort file | uniq > new_file
@johnmurch
johnmurch / diff.sh
Created August 25, 2022 16:27
Get Diff between 2 files
#!/bin/bash
sort file1 file2 | uniq -c | awk '$1 == 1 {print $2}'
ls -d */
@johnmurch
johnmurch / linksubstringmatch.js
Created May 5, 2022 17:38
Find String in ALL the links
Array.from(document.getElementsByTagName('a')).map((a) => a.href).map((l) => l.includes("keyword") ? l : '').filter(Boolean)