Skip to content

Instantly share code, notes, and snippets.

@r-i-c-h
r-i-c-h / my.gitignore
Last active April 22, 2023 00:00
Rich's .gitignore File
# Rich's .gitignore file:
# See https://help.github.com/ignore-files/...
# leading-slash stops recursion, trailing slash = directory/
# >>>Notes <<<<
notes.txt
notes.md
localnotes.md
tutsrc.txt
# >>> Dependency directories <<<
@r-i-c-h
r-i-c-h / JS-SubsetSum.js
Created October 21, 2019 20:02
JS SubsetSum
// Will actually work without the 'String()` whatnot, but I'm being particular
const subsetSum = (arr, target) => {
let dictObj = {};
for (let i = 0; i < arr.length; i++) {
const val = arr[i];
const compliment = String(target - val);
if (dictObj.hasOwnProperty(compliment)) { // must use hasOwnProp in case of index=0 which would return as false!!
return [dictObj[compliment],i];
@r-i-c-h
r-i-c-h / Instant DOM Examiner
Created October 18, 2019 08:07
SNIPPET: Display tooltips w/DOM-inspection info about the selected/hovered element
// sauce: https://dev.to/eaich/spy-on-the-dom-3d47
(function SpyOn() {
const _id = 'spyon-container',
_posBuffer = 3;
function init() {
document.body.addEventListener('mousemove', glide);
document.body.addEventListener('mouseover', show);
document.body.addEventListener('mouseleave', hide);
@r-i-c-h
r-i-c-h / GenericImgComponent.js
Created September 12, 2019 22:38
Gatsby Generic Image <Img> Component
// Per https://criscodes.hashnode.dev/how-to-render-multiple-images-in-gatsby-using-image-component-cjxoowlou000pfms1o91x71ts
// Cycles through an array of *all* of the images and uses .find() to pass along one with a matching filename
// Max image width is set as 1200px, but can be changed...
// This component has zero styling (other than the implied max-width)
import React from "react"
import { StaticQuery, graphql } from "gatsby"
import Img from "gatsby-image"
const Image = ({filename, alt}) => (
@r-i-c-h
r-i-c-h / D3 Bound vs Unbound data appending
Created October 6, 2018 08:50
d3: Show diff between adding a callback func or not in the data() join
<html><head><meta charset="utf-8">
<title>Data join with and without key function</title>
<style>
.contentBound, .contentNoFunc {position: relative; height: 40px; }
.contentBound div, .contentNoFunc div {position: absolute; }
</style></head>
<body>
<h1>With Data Callback Function</h1>
<div class="contentBound"></div>
@r-i-c-h
r-i-c-h / APIRequestCacher.js
Created March 29, 2018 23:52
UTIL:TESTING-APIReqCacher - Create file to cache API requests - speed up testing/development. Care of @mpj
const util = require('util')
const fs = require('fs')
const path = require('path')
function makeFileCacheJunction(dir) {
return async function fileCacheJunction(...args) {
const [cacheKey, junction, fn] =
args.length === 3 ? [args[0], args[1], args[2]] : [0, args[0], args[1]]
const directoryTemplate = process.env.JUNCTION_CACHE_DIRECTORY_TEMPLATE