Skip to content

Instantly share code, notes, and snippets.

@mistercoffee66
mistercoffee66 / jquery-dosomething-ES6.js
Last active November 6, 2019 16:03
ES6 module importing jQuery plugin
//jquery-dosomething-ES6.js
//after modification
//assumes jQuery is avail as global or via NPM etc
import jQuery from 'jquery'
export default function() {
+function($) {
var $this = $(this);
var newText = $this.data('text');
var reggie = {
email: /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i,
password: /^[a-z0-9]{4,25}$/i
},
valid = {
email: false,
password: false
},
data = {};
@mistercoffee66
mistercoffee66 / .gitignore
Last active September 5, 2017 17:14
general purpose .gitignore for VS projects
#npm
node_modules/
bower_components/
#jetbrains
.idea/
#OS junk files
[Tt]humbs.db
*.DS_Store
@mistercoffee66
mistercoffee66 / mobileUtils.js
Created September 8, 2017 19:17
quick n dirty user agent tests
const isMobile = () =>{
return ( navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/BlackBerry/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPad/i) ||
navigator.userAgent.match(/iPod/i) ||
navigator.userAgent.match(/iPhone|iPad|iPod/i) ||
navigator.userAgent.match(/IEMobile/i) )
}
@mistercoffee66
mistercoffee66 / polyfills.js
Created September 25, 2017 21:04
frequently used polyfills
// Element.matches()
if (!Element.prototype.matches)
Element.prototype.matches =
Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector
// NodeList.forEach()
if (window.NodeList && !NodeList.prototype.forEach) {
NodeList.prototype.forEach = function (callback, thisArg) {
@mistercoffee66
mistercoffee66 / .eslintrc
Last active October 10, 2017 19:53
airbnb eslint config all in one file (no "extends") for use in JetBrains IDEs code-style settings (see https://blog.jetbrains.com/webstorm/2017/06/webstorm-2017-2-eap-172-3198/ )
{
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module",
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
"rules": {
"func-names": [
@mistercoffee66
mistercoffee66 / gist:7a44837abef5317c5a87508ec3d39662
Last active May 9, 2019 18:02
Webpack 4 + Express + Hot module reloading without middleware
//*********server.js*********
const express = require('express')
const path = require('path')
const app = express()
const port = process.env.PORT || 3000
@mistercoffee66
mistercoffee66 / trim-anything.js
Last active November 2, 2020 22:43
trim anything
export const trimAnything = (str, trimChar, opts = { start: false, end: true }) => {
if (str.length > 1 || opts.allowEmpty) {
let pattern;
if (opts.start && !opts.end) {
pattern = `^\\${trimChar}+`;
} else if (!opts.start && opts.end) {
pattern = `\\${trimChar}+$`;
} else {
pattern = `^\\${trimChar}+|\\${trimChar}+$`;
}
@mistercoffee66
mistercoffee66 / iterable.js
Last active May 6, 2019 15:05
ES6 iterable Map example
<script>
const els = document.querySelectorAll('li')
const iterables = new Map([
['myObject', {
appetizer: 'Soup',
entree: 'Mahi Mahi',
dessert: 'Pie!'
}],
['myArray', [
@mistercoffee66
mistercoffee66 / isTruthy.js
Created May 6, 2019 15:17
opinionated test for truthy
const isTruthy = (expression) => {
if (typeOf expression === 'number') return true // 0 returns true
if (Array.isArray(expression) && expression.length < 1) return false // empty array returns false
if typeOf expression === 'Object' && Object.keys(expression).length < 1) return false // empty object returns false
return !!expression
}