Skip to content

Instantly share code, notes, and snippets.

View joeyred's full-sized avatar

Brian Hayes joeyred

View GitHub Profile
@joeyred
joeyred / Expandable Search Field.markdown
Created September 13, 2015 22:49
Expandable Search Field
@joeyred
joeyred / debug.js
Created November 30, 2016 19:18
A little debugging object.
/**
* Controls whether debug functions have any output to console.
* @type {Boolean}
*/
var DEBUG_IS_ENABLED = true;
/**
* Debug constructor
* @method Debug
* @param {string} objectName The name of the parent object of all logged data
@joeyred
joeyred / gulpfile.js
Last active December 13, 2016 19:19
Use Jekyll with gulp.js while leveraging the use of a `--production` flag when running `gulp` to set the environment in Jekyll to production as well.
var gulp = require('gulp');
var yargs = require('yargs');
var DEPLOY = Boolean(yargs.argv.production);
/**
* Jekyll Task
*
* Make Jekyll run stuff when told to by gulp.
*
function arraysMatch(arrayOne, arrayTwo) {
let match = false;
if (arrayOne.length !== arrayTwo.length) {
return false;
}
for (let indexOne = 0; indexOne < arrayOne.length; indexOne += 1) {
// For checking for a match to the current ArrayOne value
let valueMatch = false;
for (let indexTwo = 0; indexTwo < arrayTwo.length; indexTwo += 1) {
@joeyred
joeyred / ratio.js
Last active December 9, 2020 08:20
Utilities for dealing with aspect ratio and scaling of rectangles.
/**
* Copyright (c) 2019-present, Brian J. Hayes.
*
* https://github.com/joeyred
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
export function fixedDecimalPlaces(number, places) {
@joeyred
joeyred / reporter.js
Last active December 9, 2020 08:26
Error reporter wrapper for Sentry to prevent reporting to Sentry in dev, but still logging any resulting message or error.
/* eslint-disable no-console */
import * as Sentry from '@sentry/browser';
let production = false;
/**
* Initialize reporter. This should be done as soon as possible.
* @method initReporter
* @param {Boolean} isProduction - If the app is currently running in
* production or not.
@joeyred
joeyred / example.graphql
Last active July 15, 2021 22:39
GraphQL Example Schema
type Tweet {
id: ID!
# The tweet text. No more than 140 characters!
body: String
# When the tweet was published
date: Date
# Who published the tweet
Author: User
# Views, retweets, likes, etc
Stats: Stat
@joeyred
joeyred / arraysMatch.js
Created July 23, 2021 19:09
arraysMatch
function arraysMatch(arrayOne, arrayTwo) {
let match = false;
if (arrayOne.length !== arrayTwo.length) {
return false;
}
for (let indexOne = 0; indexOne < arrayOne.length; indexOne += 1) {
// For checking for a match to the current ArrayOne value
let valueMatch = false;
for (let indexTwo = 0; indexTwo < arrayTwo.length; indexTwo += 1) {
@joeyred
joeyred / pixels-to-ems.js
Created September 15, 2021 20:12
Coverts pixel values to em based on the font size set to the html tag.
/**
* Converts pixel values to em values based on the `html` level `font-size`.
* @method pixelsToEms
* @param {Number|String} pixels - pixel value to be converted to ems.
* @return {Number} - value in ems.
*/
function pixelsToEms(pixels) {
let html = document.querySelector('html');
return pixels / parseFloat(getComputedStyle(html)['font-size']);
}
@joeyred
joeyred / addSuffixToNumber.js
Last active September 30, 2021 21:26
Add a suffix to a number. "st", "nd", "rd", and "th".
/**
* Adds suffix to number passed.
*
* @method _addSuffixToNumber
*
* @param {number} number - The number to have a suffix added to.
*
* @return {string} - Number with suffix added.
*/
function addSuffixToNumber(number) {