Skip to content

Instantly share code, notes, and snippets.

View bcole808's full-sized avatar

Ben Cole bcole808

View GitHub Profile
@bcole808
bcole808 / throttle.js
Created October 16, 2014 23:40
Throttle Javascript Functions
/**
* Debounce a function so that it will only fire once
*
* USAGE EXAMPLE:
* $scope.search = debounce(performSearch, 500); // Bind to ng-keyup
*
* http://davidwalsh.name/javascript-debounce-function
*
* @param func [Function] - The function to execute
@bcole808
bcole808 / wp_embedly.php
Created May 7, 2015 21:37
WordPress Embedly Integration
<?php
/***************************
* Custom implementation of the Embedly service
****************************/
class Embedly_WordPress_Integration {
private $cache_ttl = WEEK_IN_SECONDS;
private $embedly_uri = 'http://api.embed.ly/1/oembed';
@bcole808
bcole808 / wp-router.php
Created June 2, 2015 20:54
WordPress PHP Router
<?php
######### router.php #########
#
# This file implements basic server routing and rewrite rules;
# Run the following command from the project root:
#
# php -S localhost:5000 -t path/to/wordpress path/to/router.php
#
# ^ hostname ^ root ^ server router
@bcole808
bcole808 / ui-scaffolding.scss
Created August 31, 2015 17:50
SCSS mixin for UI-Scaffolding
@mixin ui-scaffolding($color:"rgba(0,255,100)", $label:"PLACEHOLDER") {
position: relative;
outline: 1px solid $color;
background: rgba($color, 0.2);
&:before {
content: $label;
display: block;
position: absolute;
top: 50%;
@bcole808
bcole808 / class-remove-image-sizes.php
Last active October 14, 2015 16:59
WP Optimize Images Resizing
<?php
// Exit if accessed directly
! defined( 'ABSPATH' ) && exit;
// Check if class already exists
if ( ! class_exists( 'OIR_Remove_Image_Sizes' ) ) :
final class OIR_Remove_Image_Sizes {
@bcole808
bcole808 / slrlounge_env_redirect.js
Created September 30, 2016 16:39
Environment Redirect Bookmarklet
(function(){
var is_slrlounge_url = /https?:\/\/(www.|staging.)?slrlounge\.(dev|com)/;
if (null === is_slrlounge_url.exec(window.location)) {
alert("YES!");
} else {
alert("NO.");
}
@bcole808
bcole808 / get_random_attachment_id_from_post.php
Created May 10, 2017 21:15
Get WordPress attachment from post
<?php
function get_random_attachment_id_from_post($post = 0) {
$post = get_post( $post );
if ( ! preg_match_all( '/<img [^>]+>/', $post->post_content, $matches ) ) {
return 0;
}
$attachment_ids = array();