Skip to content

Instantly share code, notes, and snippets.

View jwaltonmedia's full-sized avatar
:shipit:
Shippin'

James Walton jwaltonmedia

:shipit:
Shippin'
View GitHub Profile
@jwaltonmedia
jwaltonmedia / cloudSettings
Created May 1, 2018 14:49
Visual Studio Code Settings Sync Gist
{"lastUpload":"2018-05-01T14:49:08.468Z","extensionVersion":"v2.9.1"}
@jwaltonmedia
jwaltonmedia / _.sortedIndex_example.js
Created November 5, 2014 17:18
_.sortedIndex_example.js
//assuming 'listItems' is non-alphabetical unordered list (response from server, etc.)
var finalArr = [];
var idx;
_.each(listItems, function(el, i) {
// _.sortedIndex magic here... binary compare;
@jwaltonmedia
jwaltonmedia / thoughts.js
Created October 21, 2014 05:07
Thoughts
//removes the need for 'this'
function constructor(spec) {
let {member} = spec,
{other} = other_constructor(spec),
method = function() {
//member, other, method
};
return Object.freeze({
method,
@jwaltonmedia
jwaltonmedia / monobindCSSAnimationListener.js
Created July 17, 2014 13:09
When you really want to know when your CSS transition animations have completed, you'll need something like this... (uses jQuery, but you could get clever and go without). Note the various vendor prefixes.
function monobindCSSAnimationListener(element, type, bind, callback) {
var pfx = ["webkit", "moz", "MS", "o", ""],
i = 0,
j = pfx.length;
element = $(element);
for (; i < j; i++) {
if (!pfx[i]) {
type = type.toLowerCase();
}
if (bind) {
@jwaltonmedia
jwaltonmedia / getStringFromJson.js
Last active December 25, 2015 20:08
recursive javaScript function used to pull all string values from a JSON Object
function getStringsFromJson(json) {
var values = [];
for (var prop in json) {
(function findStr(obj) {
if (typeof obj == 'string') {
values.push(obj);
} else if (obj instanceof Array) {
for (var i = obj.length - 1; i > -1; i--) {
var val = obj[i];
findStr(val);
@jwaltonmedia
jwaltonmedia / closure-example.js
Last active December 24, 2015 00:09
JS closures and anonymous functions...
//jquery
var a_s = $('a');
a_s.each(function(i, e) {
(function(a, num) {
a.on('click', function(e) {
e.preventDefault();
console.log('I\'m number ' + num);
});
})($(e), i);
@jwaltonmedia
jwaltonmedia / jq.numbersOnlyField.js
Created August 20, 2013 18:51
This is a little plugin I wrote to ensure form fields only accept numbers as input
$.fn.numbersOnlyField = function() {
var element = this,
validKeys = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 8, 9],
currentValue;
function onkeydown_field(e) {
currentValue = element.val();
}
function onkeyup_field(e) {
var value = element.val();
if (/[\d]+$/g.test(value)) {
@jwaltonmedia
jwaltonmedia / jq.phoneNumberFormatter.js
Created August 12, 2013 14:59
This is a jQuery plugin used to create formatted phone number values. A list of approved formats can be found in the code comments.
$.fn.phoneNumberFormatter = function(format) {
/*supported formats:
* '(xxx)-xxx-xxxx',
* 'xxx-xxxx',
* '(xxx)xxx-xxxx',
* '+x(xxx)xxx-xxxx',
* '+x-(xxx)-xxx-xxxx'
* */
var element = this,
avoidKeyCodes = [8, 39, 37];
@jwaltonmedia
jwaltonmedia / media-queries.css
Last active December 18, 2015 05:58
Some standard CSS media queries
/*Smaller than standard 960 (devices and browsers)*/
@media only screen and (max-width: 959px) {}
/*Tablet Portrait size to standard 960 (devices and browsers)*/
@media only screen and (min-wdth: 768px) and (max-width: 959px) {}
/*All Mobile Sizes (devices and browsers)*/
@media only screen and (max-width:767px) {}
/*Mobile Landscape Size to Tablet Portrait (devices and browsers)*/
@jwaltonmedia
jwaltonmedia / dust-helper-formatDate.js
Created May 27, 2013 18:24
Dustjs helper for formatting javascript date strings in templates (server-side).
dust.helpers.formatDate = function(chunk, context, bodies, params) {
var value = dust.helpers.tap(params.value, chunk, context),
timestamp,
month,
date,
year;
timestamp = new Date(value);
month = timestamp.getMonth() + 1;
date = timestamp.getDate();
year = timestamp.getFullYear();