Skip to content

Instantly share code, notes, and snippets.

View crates's full-sized avatar
❤️‍🔥
Crates is CEO of llnnll.com, Athames.com, Crates.Media / Cr8s.Net : 844-CR8S-NET

Crates McDade crates

❤️‍🔥
Crates is CEO of llnnll.com, Athames.com, Crates.Media / Cr8s.Net : 844-CR8S-NET
View GitHub Profile
@crates
crates / arrayDedupe.js
Created March 19, 2020 21:36
Javascript Array De-duplication (make items unique)
// There are a lot of ways to handle this need. This one is great for performance in all envs.
const removeDups = xs => {
const collect = (r, x) => {
if (!r.seen[x]) {
r.result.push(x);
r.seen[x] = true;
}
return r;
};
return xs.reduce(collect, { seen: {}, result: [] }).result;
@crates
crates / reactApp.js
Created March 19, 2020 17:05
Basic React App: very simple code for starting a single-file react app
import React from 'react';
import { Router, Switch, Route } from 'react-router-dom';
import ReactDOM from 'react-dom';
import { createBrowserHistory } from 'history';
const history = createBrowserHistory();
const App = () => {
return (
<Router history={history}>
@crates
crates / markdownDateInfo.js
Last active March 27, 2020 15:10
Get some information on the current day of the year, in Markdown format
(function() {
const date = new Date();
const year = date.getFullYear();
const monthNames = [
'January',
'February',
'March',
'April',
'May',
'June',
@crates
crates / safeObjectProxy.js
Created March 17, 2020 02:03
Wrap your JS objects in a Proxy so that you can safely access their properties (ES2015+)
const proxyObj = (obj) {
return new Proxy(obj, {
get: function(target, name) {
const result = target[name];
if (!!result) {
return (result instanceof Object)? proxyObj(result) : result;
}
return proxyObj({});
}
});
@crates
crates / fixOverflow.js
Last active November 11, 2020 16:49
Stop webpages from preventing scroll by overriding changes to "overflow"
(function() {
'use strict';
document.getElementsByTagName("HTML")[0].style.overflow = "auto";
document.getElementsByTagName("BODY")[0].style.overflow = "auto";
document.getElementsByTagName("HTML")[0].style.overflowY = "auto";
document.getElementsByTagName("BODY")[0].style.overflowY = "auto";
if (~window.location.hostname.indexOf('usatoday.com')) {
$('body > header').style.position = 'static';
}
@crates
crates / easing.js
Created February 11, 2020 17:47 — forked from gre/easing.js
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
// no easing, no acceleration
linear: t => t,
// accelerating from zero velocity
easeInQuad: t => t*t,
// decelerating to zero velocity
@crates
crates / find-unused-sass-variables.sh
Created February 11, 2020 17:47 — forked from badsyntax/find-unused-sass-variables.sh
Find unused SCSS variables. Usage: `./find-unused-sass-variables.sh sassDir/`
#!/usr/bin/env bash
#
# Approach:
# 1. Find variable declaration in the form of "$my-var: anyvalue"
# 2. Loop through found variables and find occurrences of each variable in all sass files
# 3. Filter out vars that occurred only once
if [ -z "$1" ]; then
echo "Please specify a directory as the first argument."
exit 1
@crates
crates / JS-error-tracking-with-GA.js
Created February 11, 2020 17:46
Track JavaScript errors using Universal Analytics from Google.
/**
* Track JS error details in Universal Analytics
*/
function trackJavaScriptError(e) {
var errMsg = e.message;
var errSrc = e.filename + ': ' + e.lineno;
ga('send', 'event', 'JavaScript Error', errMsg, errSrc, { 'nonInteraction': 1 });
}
@crates
crates / how-to-view-source-of-chrome-extension.md
Created February 11, 2020 17:42 — forked from paulirish/how-to-view-source-of-chrome-extension.md
How to view-source of a Chrome extension

Option 1: Command-line download extension as zip and extract

extension_id=jifpbeccnghkjeaalbbjmodiffmgedin   # change this ID
curl -L -o "$extension_id.zip" "https://clients2.google.com/service/update2/crx?response=redirect&os=mac&arch=x86-64&nacl_arch=x86-64&prod=chromecrx&prodchannel=stable&prodversion=44.0.2403.130&x=id%3D$extension_id%26uc" 
unzip -d "$extension_id-source" "$extension_id.zip"

Thx to crxviewer for the magic download URL.

@crates
crates / reloadCSS.js
Created February 11, 2020 17:38 — forked from kdzwinel/reloadCSS.js
Reload CSS files without reloading the page
function reloadCSS() {
const links = document.getElementsByTagName('link');
Array.from(links)
.filter(link => link.rel.toLowerCase() === 'stylesheet' && link.href)
.forEach(link => {
const url = new URL(link.href, location.href);
url.searchParams.set('forceReload', Date.now());
link.href = url.href;
});