Skip to content

Instantly share code, notes, and snippets.

@jhafner
jhafner / removeEmptyElements.js
Last active August 29, 2015 13:59
Remove null, undefined, NaN, and empty strings from an object.
var settings = {
foo: "",
bar: undefined,
hello: "world",
baz: NaN,
what: null,
test: "string",
zero: 0,
falseVal: false
}
@jhafner
jhafner / _color_functions.sass
Created October 25, 2016 16:47
Sass functions for accessible text contrast.
// Power utility to calculate exponents
@function pow($number, $exponent) {
$value: 1;
@if $exponent > 0 {
@for $i from 1 through $exponent {
$value: $value * $number;
}
} @else if $exponent < 0 {
@jhafner
jhafner / js-selecting-that-doesnt-suck.js
Last active February 6, 2018 18:54
3 lines of code, that make writing pure JS so much quicker. Borrowed mostly from http://jsfiddle.net/leaverou/hRz8K/embedded/result,js/
function $(id) { return document.getElementById(id); }
function $c(class) { return document.getElementsByClassName(class); }
function $t(tag, container) { return (container || document).getElementsByTagName(tag); }
function $$(expr, container) { return (container || document).querySelectorAll(expr); }