Skip to content

Instantly share code, notes, and snippets.

View karlgroves's full-sized avatar

Karl Groves karlgroves

View GitHub Profile
@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 / 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>
(function() {
var script = document.createElement('script');
script.async = 1;
script.src = '<url to script>';
document.getElementsByTagName('body')[0].appendChild(script);
})();
<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;
@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()){
@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 / 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 / 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 / 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 / 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++;
}
}