Skip to content

Instantly share code, notes, and snippets.

View james-jlo-long's full-sized avatar

James Long james-jlo-long

View GitHub Profile
@james-jlo-long
james-jlo-long / post.js
Created May 15, 2018 09:53
A simple function for posting data
function post(url, data) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
var params = new URLSearchParams();
Object.entries(data).forEach(function (pair) {
params.set(pair[0], pair[1]);
});
@james-jlo-long
james-jlo-long / polyfill.js
Last active July 24, 2018 10:29
A simple library for polyfilling missing functionality in older browsers
/**
* Polyfills a property on the given object. If the object already has the
* property, no action is taken.
*
* @param {?} object
* Object whose property should be polyfilled.
* @param {String} name
* Name of the property to polyfill.
* @param {?} value
* Value for the property.
@james-jlo-long
james-jlo-long / number-constants.js
Created July 13, 2018 10:02
A few constants for commonly needed numbers. Not sure how useful this is, but could be helpful to someone
const times = (i, handler, context) => {
let count = 0;
let max = Math.floor(Math.abs(i)) || 0;
while (count < max) {
handler.call(context, count);
count += 1;
@james-jlo-long
james-jlo-long / Breakpoint.js
Last active August 12, 2019 10:41
Listening for break point changes without using the window resize event.
/**
* @file A class that listens for breakpoints. This is far more efficient
* and accurate than relying on the window resize event.
* @license MIT
* @author James "JLo" Long <[email protected]>
* @requires Observer
*/
var BreakPoints = (function () {
@james-jlo-long
james-jlo-long / css-calisthenics.md
Last active July 11, 2019 08:39
CSS Calisthenics - exercises designed to help teach you better CSS.

CSS Calisthenics

Introduction

A series of exercises designed to help you improve your CSS. This are not rules that should be applied to all style sheets and this is not a measure of CSS quality, merely tools to help you learn some of CSS's strengths.

Pre-processors and styled components

These exercises assume that you have 1 style sheet. We're talking about the CSS that is generated after the pre-processors have run. For styled components, extract all styles (even if the component isn't being used on the current view) and put them into a single style sheet. If you have an inline <style> tag for performance, those styles should be in the single style sheet.