Skip to content

Instantly share code, notes, and snippets.

@aradnom
aradnom / grouped-thousands.js
Last active December 20, 2015 21:18
JS for formatting large numbers with commas ('12,345,678'). Uses reduceRight from http://underscorejs.org.
_.reduceRight( num.toString().split('').reverse(), function ( stack, next, i ) { return stack + ( i % 3 == 0 && i > 0 ? next + ',' : next ); }, '' )
@aradnom
aradnom / youtube-embed.js
Created July 22, 2013 17:57
Simple script for embedding multiple youtube videos via the JS API. Allows video objects to be queued as video params along with a callback on state change (useful for pushing tracking events).
var videos = [],
tag = document.createElement( 'script' );
// Load the API
tag.src = "//www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName( 'script' )[0];
firstScriptTag.parentNode.insertBefore( tag, firstScriptTag );
// Enqueue new youtube video for loading and event tracking