Skip to content

Instantly share code, notes, and snippets.

Rich Werden r-i-c-h

Block or report user

Report or block r-i-c-h

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@r-i-c-h
r-i-c-h / JS-SubsetSum.js
Created Oct 21, 2019
JavaScript implementation of Subset Sum Algorithm
View JS-SubsetSum.js
// 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 Oct 18, 2019
Code puts a tooltip under your mouse with DOM-inspection info about the selected/hovered element
View Instant DOM Examiner
// 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 Sep 12, 2019
Gatsby Generic Image <Img> Component
View GenericImgComponent.js
// 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 Oct 6, 2018
Some D3 /HTML to show difference between adding a callback func or not in the data() join
View D3 Bound vs Unbound data appending
<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 Mar 29, 2018
Utility for create a file that caches an API request to speed up testing/development. Care of @mpj
View APIRequestCacher.js
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
You can’t perform that action at this time.