Skip to content

Instantly share code, notes, and snippets.

@shelldandy
shelldandy / index.js
Created September 30, 2017 02:37
Modules via data-attributes
// Require and use modules via data attributes
// your modules need to take an element as a param
// the modules live in this same folder to work
const moduleElements = document.querySelectorAll('[data-module]')
Array.prototype.forEach.call(moduleElements, el => {
const name = el.getAttribute('data-module')
const Module = require(`./${name}`)
Module(el)
})
@shelldandy
shelldandy / loopQuery.js
Last active September 30, 2017 07:48
Tabs using vanilla JS
/**
* Make a document.querySelectorAll loopable
* @author Todd Motto
* @tutorial https://toddmotto.com/ditch-the-array-foreach-call-nodelist-hack
* @param {NodeList} elements
* @param {Function} callback function that takes element and index
* @param {this} scope what this refers to
*/
const loopQuery = (elements, callback, scope) => {
for (let i = 0; i < elements.length; i++) {
@shelldandy
shelldandy / package.json
Created October 10, 2017 15:26
Jest Globals for standardJS in package.json
{
...
"standard": {
"globals": [
"afterAll",
"afterEach",
"beforeAll",
"beforeEach",
"describe",
"test",
const webpack = require('webpack')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const {cwd} = require('process')
const production = process.env.NODE_ENV === 'production'
const debug = process.env.NODE_ENV === 'debug'
// When you really want to make the relationship work...
const ENTRY_PATH = cwd() + '/src/index.js'
@shelldandy
shelldandy / App.js
Created October 17, 2017 19:08
nprogress with react-router in create-react-app
import React from 'react'
import { BrowserRouter as Router, Switch } from 'react-router-dom'
import routes from './routes'
import FancyRoute from './components/tools/FancyRoute'
const App = props =>
<Router>
<Switch>
{routes.map((route, i) =>
<FancyRoute key={i} {...route} />
// Paste in console on the product list in the admin
// EXAMPLE
// https://************.myshopify.com/admin/products
// Select all the links to product pages
function downloadSP (name) {
$(`tbody td a[href^="/admin/${name}"]`).each(function (index) {
const me = $(this)
// Grab the original href
@shelldandy
shelldandy / loopQuery.js
Created March 19, 2018 04:55
Make a document.querySelectorAll loopable
/**
* Make a document.querySelectorAll loopable
* @author Todd Motto
* @tutorial https://toddmotto.com/ditch-the-array-foreach-call-nodelist-hack
* @param {NodeList} elements
* @param {Function} callback function that takes element and index
* @param {this} scope what this refers to
*/
const loopQuery = (elements, callback, scope) => {
for (let i = 0; i < elements.length; i++) {
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBFnQbV8BCACyN7kRYtOgi9vY6cCp1BZcVKRBcJd6JZTieABLw6+Rgr2xozyl
e3npvPBtg2ccPQqlG0CgpJkxQfNpo7MhMp3svVcgebwnYzCrJmM95NU9IDYcAI9N
HR+HOAOIiXJTPX7nujoBshxZ2bl8GuJYggVLIyOEX5qtS49TdZ8jvRWkC9bxR3Jh
7O5PADlKe74Tce/k1nwQdlpIRJ+0zu/yDdjOuBtCxCrEX2h0GDHZD3xa8oYE2ed2
DBQO3bAB9x0MTcrwzatvtr163JTxGBKPc2GpC5mEaZCaLd1QhmfqtvlyLjeXHa2Z
TzDdimbDgSyY/HP67Hc0RMuCC8ovxGHIgxcnABEBAAG0Kk1pZ3VlbCBQYWxhdSBa
YXJ6YSA8bXBhbGF1emFyemFAZ21haWwuY29tPokBVAQTAQgAPhYhBIBn5gFjR1dK
CHpqfomJAF5ePzhuBQJZ0G1fAhsDBQkDwmcABQsJCAcCBhUICQoLAgQWAgMBAh4B
@shelldandy
shelldandy / webpack.config.js
Created April 2, 2018 14:54
Update webpack 3 to 4 with separate vendors of node_modules
{
// ...
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'initial',
},
@shelldandy
shelldandy / Toggle.js
Created July 3, 2018 13:07
A React Toggle Componer that uses render props
import { Component, createRef } from 'react';
import PropTypes from 'prop-types';
class Toggle extends Component {
state = {
on: false,
}
wrapper = createRef()