Skip to content

Instantly share code, notes, and snippets.

View jmahc's full-sized avatar
🏠
Working from home

Jordan McArdle jmahc

🏠
Working from home
View GitHub Profile
@jmahc
jmahc / index.html
Created December 9, 2016 14:03
Loading page for Webpack while it builds.
<div id="root">
<style type="text/css" scoped>
h1 { z-index: 10; font-family: 'Roboto', 'Helvetica', sans-serif; display: inline-block; }
.loader {
margin: 10% auto;
font-size: 10px;
position: relative;
text-indent: -9999em;
border-top: 1.1em solid rgba(100, 100, 100, 0.2);
@jmahc
jmahc / Root.jsx
Created December 1, 2016 19:40 — forked from vdh/Root.jsx
Moderately-successful hot reloading for react-router v3
import React, { PropTypes } from 'react';
import { Provider } from 'react-redux'; // Or something else, if you're not using Redux
import Router from 'react-router/lib/Router';
const Root = ({ store, history, routes }) => (
<Provider store={store} key="provider">
<Router history={history} routes={routes} />
</Provider>
);
@jmahc
jmahc / eslint-block-example.js
Created November 17, 2016 16:29
ESLint description
// This example would cause an error by ESLint because we are using ES6 JS (it would suggest `const` or `let`)
/* eslint-disable */
var x = 1;
/* eslint-enable */
var y = 2; // throws eslint-error suggestioning to use `const` or `let`
@jmahc
jmahc / validate.js
Created November 4, 2016 17:02
validate form input react
const isEmpty = value => value === undefined || value === null || value === '';
const join = (rules) => (value, data) => rules.map(rule => rule(value, data)).filter(error => !!error)[0 /* first error */ ];
export function email(value) {
// Let's not start a debate on email regex. This is just for an example app!
if (!isEmpty(value) && !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(value)) {
return 'Invalid email address';
}
}
@jmahc
jmahc / fakePromise
Created October 26, 2016 18:55
Fakes a promise and returns "fetched" data from a remote API.
/**
* For demonstration purposes only. Normally this promise would
* do something cool, like fetch data from a remote API.
*
* @param entity
* @returns {Promise}
*/
function fakePromise() {
return new Promise(resolve => {
const delay = _getShortDelay();
@jmahc
jmahc / regex.txt
Created September 7, 2016 19:41
Commonly used Regex by Jordan McArdle
// Selects id's inside of an HTML tag that has a space before it.
` id="[^"]+"`
// Select `headings"` inside of an HTML tag that has a double quote after it, without a space or hyphen before it.
// Used to grab the class name headings in this case
`(?<! )+(?<!-)+(?=headings")\w+([headings"])`
@jmahc
jmahc / _colors.sass
Last active April 4, 2017 03:47
Colors for sass
//
// Colors
//
$color-black: #000;
$color-licorice: #111;
$color-raisin-black: #222;
$color-jet: #333;
$color-arsenic: #444;
$color-davy-gray: #555;
$color-granite-gray: #666;
@jmahc
jmahc / colors.less
Last active August 30, 2016 18:19
List of color variables with names. Consistently used throughout my projects (WIP)
// Color names generated by:
// 1. https://coolors.co/
// 2. http://chir.ag/projects/name-that-color/
// Colors =========================================
// ====== Generic
//
// Black -> Grays w/ #'s
//
@color-black : #000000;
@jmahc
jmahc / smart-underline.js
Created August 28, 2016 22:19
eager.io's JS file for smart-underline
(function() {
var PHI, backgroundPositionYCache, calculateBaselineYRatio, calculateTextHighestY, calculateTypeMetrics, clearCanvas, containerIdAttrName, containsAnyNonInlineElements, containsInvalidElements, countParentContainers, destroy, fontAvailable, getBackgroundColor, getBackgroundColorNode, getFirstAvailableFont, getLinkColor, getUnderlineBackgroundPositionY, hasValidLinkContent, init, initLink, initLinkOnHover, isTransparent, isUnderlined, linkAlwysAttrName, linkBgPosAttrName, linkColorAttrName, linkContainers, linkHoverAttrName, linkLargeAttrName, linkSmallAttrName, performanceTimes, renderStyles, selectionColor, sortContainersForCSSPrecendence, styleNode, time, uniqueLinkContainerID;
window.SmartUnderline = {
init: function() {},
destroy: function() {}
};
if (!(window['getComputedStyle'] && document.documentElement.getAttribute)) {
return;
@jmahc
jmahc / getRatio.js
Created August 27, 2016 23:04
Gets a ratio using javascript.
function getRatio(a, b) {
return Math.min(a, b) / Math.max(a, b);
};