Skip to content

Instantly share code, notes, and snippets.

View karlgroves's full-sized avatar

Karl Groves karlgroves

View GitHub Profile
@karlgroves
karlgroves / gist:7544592
Created November 19, 2013 12:24
Get DOM path of an element
function getDomPath(el) {
var stack = [];
while ( el.parentNode != null ) {
console.log(el.nodeName);
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 ) {
/**
* cleans up strings so they can be used in URLS
* @author "Borek" - attributed to a post located at:
* http://drupal.org/node/63924
* @param string $string the string we're cleaning
* @return string the input string, ready to go
*/
function pathauto_cleanstring($string)
{
@karlgroves
karlgroves / gist:7545632
Created November 19, 2013 13:49
PHP function to get the MIME type of a remote file.
function getRemoteMimeType($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
# get the content type
return curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
}
@karlgroves
karlgroves / gist:0b03befad2af598a870e0bc8695fe132
Created June 3, 2021 17:50
Post the content of a local file to Tenon APIV2 using Axios and Node
// Obvs you have you `npm install axios`
const axios = require('axios');
const fs = require('fs');
const env = 'https://tenon.io/api/v2/'; // NOTE: if you have a private instance of Tenon, you'd change the domain part of this value
const username = 'YOUR_EMAIL_GOES_HERE';
const password = 'PASSWORD_GOES_HERE';
const projectID = 'PROJECTID_GOES_HERE';
const sourceFile = './file.html'; // replace with the path to the file you want to send to Tenon
@karlgroves
karlgroves / gist:fabaf3720feae436a052f956ae089bb6
Last active February 9, 2021 19:38
Bulk "Unlike" in Twitter
/**
* UNLIKE
* Navigate to your "likes"
* Open devtools & go to Console
* Paste this snippet in & hit Enter
*/
setInterval(() => {
for (const d of document.querySelectorAll('div[data-testid="unlike"]')) {
d.click()
}
@karlgroves
karlgroves / Focus Bookmarklet
Created January 31, 2014 17:57
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
javascript:(function(){var%20ua=navigator.userAgent.toLowerCase(),ie=ua.indexOf(%22msie%22)!=-1?ua.substr(ie+5,1):0,outlineProp=ie%3C8?%22border%22:%22outline%22,activeItem;function%20styleFocus(e){if(activeItem){activeItem.style[outlineProp]=%22%22;}activeItem=e.target||e.srcElement;if(activeItem){activeItem.style[outlineProp]=%22solid%202px%20red%22;}}if(document.addEventListener){document.addEventListener(%22focus%22,styleFocus,true);}else{document.attachEvent(%22onfocusin%22,styleFocus);}}());
@karlgroves
karlgroves / gist:5265670
Created March 28, 2013 18:31
Full list of timezones output by timezone_identifiers_list. May be useful for those wishing to do something with this information in advance. Comments by others in the PHP manual are also helpful: http://www.php.net/manual/en/function.timezone-identifiers-list.php
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
@karlgroves
karlgroves / RandomString
Last active August 3, 2018 06:37
PHP Function to create random alphanumeric strings
/**
* function to generate random strings
* @param int $length number of characters in the generated string
* @return string a new string is created with random characters of the desired length
*/
function RandomString($length = 32) {
$randstr;
srand((double) microtime(TRUE) * 1000000);
//our array add all letters and numbers if you wish
$chars = array(
@karlgroves
karlgroves / StripeTutorialPage.html
Last active March 13, 2018 20:24 — 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.
<!--// Fixed for accessibility by Karl Groves 22-Oct 2013. Original Gist @ https://gist.github.com/briancollins/6365455 //-->
<!DOCTYPE html>
<html lang="en">
<head>
<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="https://js.stripe.com/v2/"></script>
@karlgroves
karlgroves / textOnly.js
Created January 20, 2016 17:31
Strip CSS classes, style attributes, and stylesheets and replace images with their alt attributes
$(document).ready(function(){
$('*').removeClass();
$('*').removeAttr('style');
$('link[rel="stylesheet"]').remove();
$('img').each(function () {
$(this).replaceWith(
$(this).attr('alt')