Skip to content

Instantly share code, notes, and snippets.

karlgroves / textOnly.js
Created Jan 20, 2016
Strip CSS classes, style attributes, and stylesheets and replace images with their alt attributes
View textOnly.js
$('img').each(function () {
karlgroves / gist:cdd532edbe957851f719
Created Jun 24, 2015
Uncompressed Tenon Bookmarklet
View gist:cdd532edbe957851f719
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 / gist:1d73f80f2a0dcc78f82f
Created Jun 24, 2015
*Super* rudimentary bookmarklet for testing document source with Tenon
View gist:1d73f80f2a0dcc78f82f
javascript:(function(){var html=document.documentElement.innerHTML;var loaded=0;var iframe=document.createElement('iframe');'bookmarklet-'+Math.floor((Math.random()*10000)+1);'none';iframe.onload=function(){if(++loaded==1){return}document.body.removeChild(iframe)};var form=document.createElement('form');form.method="POST";form.action="";;var hidden=document.createElement('input');hidden.type='hidden';'key';hidden.value='ADD_YOUR_API_KEY_HERE';var store=document.createElement('input');store.type='hidden';'store';store.value='1';var textarea=document.createElement('textarea');'src';textarea.value=html;form.appendChild(hidden);form.appendChild(store);form.appendChild(textarea);iframe.appendChild(form);document.body.appendChild(iframe);form.submit()})();
karlgroves / Focus Bookmarklet
Created Jan 31, 2014
Add this bookmarklet to your browser. Activate the bookmarklet and as you tab through the site you should see a red border around whatever gets focus
View Focus Bookmarklet
karlgroves / focusable
Created Dec 24, 2013
Found this and thought it looked interesting. I saw it at and in that page they cite "ajpiano on the jQuery forums." Untested but seems sane
View focusable
// 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;
View pathauto_cleanstring
* cleans up strings so they can be used in URLS
* @author "Borek" - attributed to a post located at:
* @param string $string the string we're cleaning
* @return string the input string, ready to go
function pathauto_cleanstring($string)
karlgroves / gist:7545632
Created Nov 19, 2013
PHP function to get the MIME type of a remote file.
View gist:7545632
function getRemoteMimeType($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
# get the content type
return curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
karlgroves / gist:7544592
Created Nov 19, 2013
Get DOM path of an element
View gist:7544592
function getDomPath(el) {
var stack = [];
while ( el.parentNode != null ) {
var sibCount = 0;
var sibIndex = 0;
for ( var i = 0; i < el.parentNode.childNodes.length; i++ ) {
var sib = el.parentNode.childNodes[i];
if ( sib.nodeName == el.nodeName ) {
if ( sib === el ) {
karlgroves / gist:7544535
Created Nov 19, 2013
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.
View gist:7544535
function isBlank(str){
return str.replace(/\W/gi, '') == '';
karlgroves / StripeTutorialPage.html
Last active Mar 13, 2018 — forked from briancollins/StripeTutorialPage.html
I really hate seeing "examples" that contain accessibility errors, esp. when they're so easy to fix. This forks a tutorial for the Stripe API and makes some relatively minor adjustments to make it much more accessible. Still not perfect but way better than the original.
View StripeTutorialPage.html
<!--// Fixed for accessibility by Karl Groves 22-Oct 2013. Original Gist @ //-->
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Stripe Getting Started Form</title>
<!-- The required Stripe lib -->
<script type="text/javascript" src=""></script>
You can’t perform that action at this time.