Skip to content

Instantly share code, notes, and snippets.

Avatar

Jared Grippe deadlyicon

View GitHub Profile
@deadlyicon
deadlyicon / track_back_and_forward_push_state.js
Last active Oct 10, 2020
How to track back and forward capability using history push state
View track_back_and_forward_push_state.js
/*
This is an example of how one could track if going back or forward is
an option for the user.
*/
if (!window.history.state || !window.history.state.visitedAt){
window.history.replaceState(
{...history.state, visitedAt: Date.now()},
@deadlyicon
deadlyicon / CropImage.js
Created Jun 17, 2020
Example of using ReactCrop react-image-crop
View CropImage.js
import React, { useRef, useState } from 'react'
import PropTypes from 'prop-types'
import ReactCrop from 'react-image-crop'
import 'react-image-crop/dist/ReactCrop.css'
export default function CropImage({
className = '',
src,
height,
width,
@deadlyicon
deadlyicon / RawHTML.js
Last active Jun 9, 2020
Rendering raw HTML as Preact components
View RawHTML.js
import { h, Fragment } from 'preact'
import { memo } from 'preact/compat'
import PropTypes from 'prop-types'
import Link from 'components/Link'
const RawHTML = memo(({source = '', ignoreNodes = []}) => {
const parser = new global.DOMParser()
const doc = parser.parseFromString(source, "text/html")
const options = {
View benchmark_example.js
#!/usr/bin/env node
function sortSortedWithArrayManipulation(a, b){
a = [...a]
b = [...b]
const sorted = []
while (a.length || b.length){
if (a.length === 0){
sorted.push(...b)
break
@deadlyicon
deadlyicon / bash.sh
Created Jun 11, 2019
do this to stop Epic Games Launcher from starting at launch boot
View bash.sh
launchctl unload ~/Library/LaunchAgents/com.epicgames.launcher.plist
rm ~/Library/LaunchAgents/com.epicgames.launcher.plist
View 5e-spell-alernatives.js
#!/usr/bin/env node
const fs = require('fs')
const words = fs.readFileSync('/usr/share/dict/words').toString().split(/\n+/g)
const spells = ["Abi-Dalzim’s Horrid Wilting","Absorb Elements","Acid Splash","Aganazzar’s Scorcher","Aid","Alarm (Ritual)","Alter Self","Animal Friendship","Animal Messenger (Ritual)","Animal Shapes","Animate Dead","Animate Objects","Antilife Shell","Antimagic Field","Antipathy/Sympathy","Arcane Eye","Arcane Gate","Arcane Lock","Armor of Agathys","Arms of Hadar","Astral Projection","Augury (Ritual)","Aura of Life","Aura of Purity","Aura of Vitality","Awaken","Bane","Banishing Smite","Banishment","Barkskin","Beacon of Hope","Beast Bond","Beast Sense (Ritual)","Bestow Curse","Bigby’s Hand","Blade Barrier","Blade Ward","Bless","Blight","Blinding Smite","Blindness/Deafness","Blink","Blur","Bones of the Earth","Booming Blade","Branding Smite","Burning Hands","Call Lightning","Calm Emotions","Catapult","Catnap","Cause Fear","Ceremony (Ritual)","Chain Lightning","Chaos Bolt","Charm Monster",
@deadlyicon
deadlyicon / gists_modeling.sql
Last active May 11, 2019
Data modeling for gist clone service
View gists_modeling.sql
CREATE EXTENSION IF NOT EXISTS uuid-ossp;
CREATE TABLE IF NOT EXISTS users (
user_id uuid PRIMARY KEY DEFAULT uuid_generate_v1mc(),
email text UNIQUE,
password_hash text,
username text,
avatar_url text
);
View bears.js
alert('🏂');
alert('🏂');
alert('🏂');
alert('🏂');
@deadlyicon
deadlyicon / README.md
Last active May 17, 2018
A subclass of the Spec reporter that prints the details of a test failure as soon as it fails
View README.md

Customer Mocha Reporter

…that prints the details of the test failure error as soon as a test fails.

Why? I hate having to wait until my long test suite finishes to begin debugging why a test fails.

View cachedRequest.js
const doSomething = (uniqueThing) => {
if (doSomething.currentRequest[uniqueThing]) {
return doSomething.currentRequest[uniqueThing]
}
return doSomething.currentRequest[uniqueThing] = require(url, params)
.then(
response => {
delete doSomething.currentRequest
return response
You can’t perform that action at this time.