Skip to content

Instantly share code, notes, and snippets.

@aradnom
aradnom / youtube-embed-existing-iframe.js
Created July 29, 2014 21:28
YouTube API example wrapping existing iframe elements.
/* Youtube */
window.onYouTubeIframeAPIReady = function () {
window.youtube_players = [];
$('.video_container.youtube').each( function () {
// Only set the play functionality up if the video has a thumbnail
if ( $(this).find('.video_thumbnail').length ) {
var thumbnail = $(this).find('.video_thumbnail'),
play = $(this).find('.video_play'),
player = new YT.Player( $(this).children('iframe').attr('id') );
window.youtube_players.push( player );
@aradnom
aradnom / vimeo-embed-existing-iframe.js
Created July 29, 2014 21:29
Simple Vimeo embed example wrapping existing video iframe.
/* Vimeo */
window.vimeo_players = [];
$('.video_container.vimeo').each( function () {
$f($(this).find('iframe')[0]).addEvent( 'ready', (function ( player_id ) {
if ( ! $(this).hasClass('no_thumbnail') ) {
var thumbnail = $(this).find('.video_thumbnail'),
play = $(this).find('.video_play'),
player = $f( player_id );
window.vimeo_players.push( player );
var thumbnail_height = thumbnail.find('img').height();
@aradnom
aradnom / array-intersect.php
Created February 4, 2015 21:00
Performs a true array intersection (array_uintersect will keep items in a1 even if they are not present in a2, a3, etc.)
$combined = array_filter($array1, function ($a) use ($array2) {
$found = array_filter($array2, function ($b) use ($a) {
return ((int) $a->ID) === ((int) $b->ID);
});
return !empty($found);
});
@aradnom
aradnom / camelcase-to-display.js
Created March 2, 2015 19:02
Given a camelcased string, return the formatted (display version) of the string, i.e. returnThisString --> Return This String
return ('' + str).match( /[A-Z]?[a-z]+/g )
.map( function ( v ) { return v.substr( 0, 1 ).toUpperCase() + v.substr( 1, v.length ); } )
.join( ' ' );
@aradnom
aradnom / repeatDoneEvent.js
Created March 30, 2015 17:19
Simple directive for firing an event when ng-repeat is finished populating.
'use strict';
/**
* Simple directive for emitting an event when repeat is finished
*/
App.directive( 'repeatDoneEvent', function ( $window ) {
return function( scope, element, attrs ) {
if ( scope.$last ) {
// At this point, ng-repeat is done populating - but we're not finished
// yet because $compile still has to compile any tags in the repeat
@aradnom
aradnom / dashes-to-camelcase.js
Created July 1, 2015 18:11
Dashes to camelCase
/**
* Given a string-like-this, return a stringLikeThis.
*
* @param {String} str String to transform
*
* @return {String} Returns camelCased string
*/
function dashesToCamelCase ( str ) {
return str
.split( '-' )
@aradnom
aradnom / riotjs-router.js
Created July 15, 2015 05:43
First attempt at a simple router in Riot.js.
// Create new observable for watching route changes
var Router = riot.observable();
// Process routes on both route change and initial load
riot.route( processRoute );
riot.route.exec( processRoute );
// Expose the Router object
riot.mixin( 'Router', Router );
@aradnom
aradnom / auto-paragraph.js
Created August 11, 2015 17:41
Simple auto-paragraph for JavaScript
/**
* Convert text containing newlines to paragraph'd markup.
*
* @param {String} text Text to add p tags to
*
* @return {String} Returns paragraphized text
*/
function autoParagraph ( text ) {
return '<p>' + text.split( /\n+/ ).join( '</p>\n<p>' ) + '</p>';
}
@aradnom
aradnom / sailsjs-hooks.txt
Created September 19, 2015 00:27
Sails.js default hooks - list of all hooks packaged by default with Sails.js
Loaded hooks (in the order they are loaded):
hook:moduleloader:loaded
hook:userconfig:loaded
hook:userhooks:loaded
hook:logger:loaded
hook:request:loaded
hook:blueprints:loaded
hook:responses:loaded
hook:controllers:loaded
@aradnom
aradnom / arrayStringToProperties.js
Created September 28, 2015 19:37
Explode array component string into usable array of properties, i.e. 'field[subfield1][subfield2][subfield3]' => ["field", "subfield1", "subfield2", "subfield3"]
/**
* Explode array component string into usable array of properties, i.e.
* 'field[subfield1][subfield2][subfield3]' =>
* ["field", "subfield1", "subfield2", "subfield3"]
*
* @param {String} string String of fields
*
* @return {Array} Returns array of field properties
*/
function arrayStringToProperties ( string ) {