Skip to content

Instantly share code, notes, and snippets.

View jjandoc's full-sized avatar

Jon Jandoc jjandoc

View GitHub Profile
const layerRoot = x => {
let l = Math.ceil(Math.sqrt(x));
return l%2 ? l : ++l
}
const orbit = lr => (lr-1)/2
const centers = lr => [0,1,2,3].map(x => Math.pow(lr,2) - orbit(lr) - (lr-1)*x)
const centerDist = x => Math.min(...centers(layerRoot(x)).map(c => Math.abs(c-x)))
const dist = x => centerDist(x) + orbit(layerRoot(x))
dist(input)
@jjandoc
jjandoc / lazy-img.js
Created June 8, 2016 17:32
Lazy Loading Image Module
/* eslint-env browser */
'use strict';
import _ from 'underscore';
import 'waypoints/lib/noframework.waypoints.js';
const Waypoint = window.Waypoint;
/**
* Lazy loading image component. A JQuery element is supplied with a
* data-src attribute. Using Waypoints to detect when the element enters the
@jjandoc
jjandoc / scroll-monitor.js
Last active June 25, 2016 00:20
Scroll Monitor Module
/* eslint-env browser */
'use strict';
import $ from 'jquery';
import _ from 'underscore';
/**
* A component that fires an event when a scroll on the provided element
* starts, fires an event when scrolling ends, and tracks the scroll position
* of that element then triggers a 'direction-change' event when the new
// This is no longer maintained. See: https://github.com/bsd/utilities/tree/master/tools-utilities
// Adds useful divs around radio/label pairs for credit card type.
$('.cc_type_cd').first().before('<div class="cc_type_container">').end()
.each(function() {
$(this).next('.cc_type_cd_label').andSelf().detach()
.appendTo('.cc_type_container').wrapAll('<div class="cc_pair">');
});
// Sets focus on Other Amount text input when other is chosen