Skip to content

Instantly share code, notes, and snippets.

Avatar
🦄
Love Coffee

Tommy Parnell TerribleDev

🦄
Love Coffee
View GitHub Profile
@TerribleDev
TerribleDev / Main.cs
Created Jul 27, 2021
Calling Quala API from UnityWebRequest
View Main.cs
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
public class Main
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static void OnBeforeSceneLoadRuntimeMethod()
@TerribleDev
TerribleDev / a11y.js
Last active Jan 8, 2021
Use axe core to put ugly borders around elements that are not accessible
View a11y.js
import axe from 'axe-core';
function debounce(fn, wait) {
let timeout = null;
return function (...args) {
const next = () => fn.apply(this, args);
clearTimeout(timeout);
timeout = setTimeout(next, wait);
};
}
@TerribleDev
TerribleDev / TimeReporterPlugin.js
Created Nov 7, 2019
Webpack 4 plugin to measure how long an entry takes to build
View TimeReporterPlugin.js
const { performance, PerformanceObserver } = require('perf_hooks');
const PluginName = "TimeReporterPlugin";
class TimeReporterPlugin {
constructor(filterPattern = /HtmlWebpackPlugin|mini-css-extract-plugin/i) {
this.FilterPattern = filterPattern;
}
apply(compiler) {
let _timeEvents = [];
@TerribleDev
TerribleDev / Img.js
Created Oct 12, 2019
A component to render responsive images in gatsby
View Img.js
import React from "react"
import { useStaticQuery, graphql } from "gatsby"
import Img from "gatsby-image"
const Image = ({ imgName }) => {
const data = useStaticQuery(graphql`
query images {
allFile(filter: { sourceInstanceName: { eq: "images" } }) {
nodes {
name
View lazyLoadImages.js
if(window.IntersectionObserver) {
document.addEventListener("DOMContentLoaded", function() {
var lazyImages = [].slice.call(document.querySelectorAll(".lazy"));
var lazyImageObserver = new IntersectionObserver(function(entries, observer) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
var lazyImage = entry.target;
if(lazyImage.dataset.src) {
lazyImage.src = lazyImage.dataset.src;
}
@TerribleDev
TerribleDev / node.sh
Created Apr 30, 2019
force reinstall of node
View node.sh
brew uninstall --ignore-dependencies node@10
brew uninstall --ignore-dependencies node
brew uninstall --ignore-dependencies yarn
brew uninstall --ignore-dependencies icu4c
brew install node@10
brew install --ignore-dependencies yarn
brew link --overwrite --force node@10
brew link --overwrite yarn
@TerribleDev
TerribleDev / checkstyle.java
Created Apr 18, 2019
run checkstyle as git hook when java files have changed
View checkstyle.java
javaCount=`git diff --cached --name-status | grep -i .java | wc -l | awk '{print $1}'`
if [ $javaCount -eq 0 ];
then
exit 0
else
exec ~/cargurus/cg-main/cargurus-build/local/devbox-push/run-checkstyle.sh
fi
@TerribleDev
TerribleDev / TargetLinkExtension.cs
Created Jan 22, 2019
A markdig extension so add target blank to absolute urls
View TargetLinkExtension.cs
public class TargetLinkExtension : IMarkdownExtension
{
public void Setup(MarkdownPipelineBuilder pipeline)
{
}
public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
{
var htmlRenderer = renderer as HtmlRenderer;
@TerribleDev
TerribleDev / createMarkedSelector.js
Last active Jul 16, 2021
Wrap reselect's createSelector with a function that measures how long selectors take to run
View createMarkedSelector.js
import {createSelector} from 'reselect';
const hasPerformanceApi =
window &&
window.performance &&
window.performance.measure &&
window.performance.mark;
const createFuncWithMark = (name, callback) => (...args) => {
const startMark = `${name}-Startmark`;
@TerribleDev
TerribleDev / replace
Created Jan 2, 2019
Regex to Replace createSelector with createMarkedSelector
View replace
const(\s?)(\w*)(\s?)=(\s)createSelector\(
const$1$2$3=$4createMarkedSelector('$2',