Skip to content

Instantly share code, notes, and snippets.

View karlgroves's full-sized avatar

Karl Groves karlgroves

View GitHub Profile
@karlgroves
karlgroves / gist:1d73f80f2a0dcc78f82f
Created June 24, 2015 02:40
*Super* rudimentary bookmarklet for testing document source with Tenon
javascript:(function(){var html=document.documentElement.innerHTML;var loaded=0;var iframe=document.createElement('iframe');iframe.name='bookmarklet-'+Math.floor((Math.random()*10000)+1);iframe.style.display='none';iframe.onload=function(){if(++loaded==1){return}document.body.removeChild(iframe)};var form=document.createElement('form');form.method="POST";form.action="https://tenon.io/api/";form.target=iframe.name;var hidden=document.createElement('input');hidden.type='hidden';hidden.name='key';hidden.value='ADD_YOUR_API_KEY_HERE';var store=document.createElement('input');store.type='hidden';store.name='store';store.value='1';var textarea=document.createElement('textarea');textarea.name='src';textarea.value=html;form.appendChild(hidden);form.appendChild(store);form.appendChild(textarea);iframe.appendChild(form);document.body.appendChild(iframe);form.submit()})();
@karlgroves
karlgroves / gist:cdd532edbe957851f719
Created June 24, 2015 12:13
Uncompressed Tenon Bookmarklet
javascript:(function () {
var html = document.documentElement.innerHTML;
/**
* the iframe's onload event is triggered twice: once when appending it to the document,
* and once when the form finishes submitting and the new URL is loaded
*/
var loaded = 0;
var iframe = document.createElement('iframe');
@karlgroves
karlgroves / clean up array duplicates
Created March 23, 2013 11:31
PHP function to remove duplicate items from an array.
function cleanupduplicates($array){
$n = 0;
$crap = array_values(array_unique($array));
$cc = count($crap);
for ($i = 0; $i < $cc; $i++) {
if ($crap[$i] != ''){
$img[$n] = $crap[$i];
$n++;
}
}
@karlgroves
karlgroves / Time Difference
Created March 23, 2013 11:52
PHP function to get difference between two times
/**
* returns the difference between two times
* @param string $start the starting time for comparison
* @param string $end the ending time for comparison
* @return array an array is populated with the time difference
*/
function timediff($start, $end) {
$timediff = $end - $start;
$days = intval($timediff / 86400);
$remain = $timediff % 86400;
@karlgroves
karlgroves / Array Identical
Created March 23, 2013 11:55
Determines if two arrays are identical.
/**
* compares two arrays to check if they're identical
* @param array $op1 the first array
* @param array $op2 the second array
* @return bool
*/
function arrayIdentical($op1, $op2) {
if (count($op1) < count($op2)) {
return FALSE;
// $op1 < $op2
@karlgroves
karlgroves / gist:5962696
Last active December 19, 2015 13:29
This snippet allows you require a user be logged into Wordpress in order to access non-WP content. For instance, imagine you have another section of your site that isn't part of Wordpress but still requires the user to be authenticated. Using this code, you can share the Wordpress authentication for that part of the site as well. Add this snippe…
<?php
// If your Wordpress blog isn't in the document root,
// you may have to change the path to wherever the
// Wordpress root directory
require($_SERVER['DOCUMENT_ROOT'].'/wp-blog-header.php');
// if the user isn't logged in, this will redirect them
// to the login page. On successful login it will redirect
// them to the page this code is currently in.
if(FALSE === is_user_logged_in()){
<style type="text/css">
.button {
background: #65a9d7;
background: -webkit-linear-gradient(top, #3e779d, #65a9d7);
padding: 13px 26px;
border-radius: 40px;
box-shadow: rgba(0,0,0,1) 0 1px 0;
text-shadow: rgba(0,0,0,.4) 0 1px 0;
color: white;
font-size: 23px;
(function() {
var script = document.createElement('script');
script.async = 1;
script.src = '<url to script>';
document.getElementsByTagName('body')[0].appendChild(script);
})();
@karlgroves
karlgroves / gist:7544535
Created November 19, 2013 12:18
jQuery empty() doesn't tell you if something is blank, it tells you whether something is truly empty - having no other nodes inside it. This function tells whether a string is blank. It returns true in cases where there are no printable text characters are in the string.
function isBlank(str){
return str.replace(/\W/gi, '') == '';
}
@karlgroves
karlgroves / focusable
Created December 24, 2013 14:58
Found this and thought it looked interesting. I saw it at http://test.cita.illinois.edu/aria/tabpanel/tabpanel2.php#lsc1 and in that page they cite "ajpiano on the jQuery forums." Untested but seems sane
// focusable is a small jQuery extension to add a :focusable selector. Credit to ajpiano on the jQuery forums.
//
$.extend($.expr[':'], {
focusable: function(element) {
var nodeName = element.nodeName.toLowerCase();
var tabIndex = $(element).attr('tabindex');
// the element and all of its ancestors must be visible
if (($(element)[(nodeName == 'area' ? 'parents' : 'closest')](':hidden').length) == true) {
return false;