Skip to content

Instantly share code, notes, and snippets.

@johnbhartley
johnbhartley / mb-do-shortcode
Created August 18, 2014 19:31
MaxButtons do_shortcode
<?php echo do_shortcode('[maxbutton id="17" text="Search Google" url="http://google.com"]'); ?>
@johnbhartley
johnbhartley / lat-long-distance
Last active August 29, 2015 14:04
Distance between lat/long coordinates
<script>
// from http://html5doctor.com/finding-your-position-with-geolocation/
if (navigator.geolocation) {
var timeoutVal = 10 * 1000 * 1000;
navigator.geolocation.getCurrentPosition(
displayPosition,
displayError,
{ enableHighAccuracy: true, timeout: timeoutVal, maximumAge: 0 }
);
}
@johnbhartley
johnbhartley / first-word
Created July 18, 2014 18:13
Span the first word ya dingus
$string = 'Test me more';
$pattern = '/^(\S+)/';
$replacement = '<span class="first-word">$1</span>';
echo preg_replace($pattern, $replacement, $string);
// or
echo preg_replace('/^(\S+)/', '<span class="first-word">$1</span>', 'Test me more');
// from @greg5green
@johnbhartley
johnbhartley / round-down-clown-frown
Created July 3, 2014 16:15
Round down to nearest hundred
$min = 780;
$floor = 780/100; // 7.8
$floor_fix = floor($floor); // 7.0
$min = $floor_fix*100; // 700
echo $min; // will output 700
<div class="rrssb-buttons">
<a href="https://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>" class="popup facebook">
<span class="icon">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="28px" height="28px" viewBox="0 0 28 28" enable-background="new 0 0 28 28" xml:space="preserve">
<path class="path" d="M27.825,4.783c0-2.427-2.182-4.608-4.608-4.608H4.783c-2.422,0-4.608,2.182-4.608,4.608v18.434
c0,2.427,2.181,4.608,4.608,4.608H14V17.379h-3.379v-4.608H14v-1.795c0-3.089,2.335-5.885,5.192-5.885h3.718v4.608h-3.726
c-0.408,0-0.884,0.492-0.884,1.236v1.836h4.609v4.608h-4.609v10.446h4.916c2.422,0,4.608-2.188,4.608-4.608V4.783z"/>
</svg>
</span>
<span class="text">Share on Facebook</span>
@johnbhartley
johnbhartley / fa-array
Created June 9, 2014 04:43
Font Awesome Icons Array - Title Only
$icon_array = array(
'fa-glass',
'fa-music',
'fa-search',
'fa-envelope-o',
'fa-heart',
'fa-star',
'fa-star-o',
'fa-user',
'fa-film',
@johnbhartley
johnbhartley / 50-states
Created May 20, 2014 20:34
List of 50 States
Alabama
Alaska
Arizona
Arkansas
California
Colorado
Connecticut
Delaware
Florida
Georgia
@johnbhartley
johnbhartley / simple-rotator
Created February 16, 2014 18:37
Simple Rotator
// jQuery
function cycleReviews(){
var $active = $('.content-slider .current');
var $next = ($active.next().length > 0) ? $active.next() : $('.content-slider div:first');
$active.fadeOut(500,function(){
$(this).removeClass('current');
$next.fadeIn().addClass('current');
});