Skip to content

Instantly share code, notes, and snippets.

@lgladdy
lgladdy / keybase.md
Last active August 29, 2015 13:59
Keybase Proof

Keybase proof

I hereby claim:

  • I am lgladdy on github.
  • I am lgladdy (https://keybase.io/lgladdy) on keybase.
  • I have a public key whose fingerprint is 97AF E3A6 D88B E71E AE80 4117 486F 64CD 35D9 B362

To claim this, I am signing this object:

@lgladdy
lgladdy / acf-fix
Created November 4, 2014 21:02
ACF 5.1.1 array_key_exists() fix
--- a/wp-content/plugins/advanced-custom-fields-pro/api/api-helpers.php
+++ b/wp-content/plugins/advanced-custom-fields-pro/api/api-helpers.php
@@ -841,6 +841,7 @@ function acf_extract_var( &$array, $key ) {
// vars
$r = null;
+ if (!is_array($array)) return false;
// check if exists
if( array_key_exists($key, $array) ) {
@lgladdy
lgladdy / adLDAP-group_info.php
Created August 14, 2015 07:37
Rewrite group_info to query a group for more than 1500 people in a group on WS 2012 DCs
public function group_info($group_name,$fields=NULL){
if ($group_name===NULL){ return (false); }
if (!$this->_bind){ return (false); }
if (stristr($group_name, '+')) {
$group_name=stripslashes($group_name);
}
$filter="(&(objectCategory=group)(name=".$this->ldap_slashes($group_name)."))";
//echo ($filter."!!!<br>");
@lgladdy
lgladdy / bookmarklet.js
Created April 11, 2013 20:03
Comixology Add All Marvel #1 Free Comics Bookmarklet
javascript:(function(){function%20clickAllNextButtons(){jQuery('a').each(function(){if($(this).html()==%22Next%22){cmd=$(this).attr('href').substr(12);eval(cmd);}});}function%20addAllVisible(){var%20changed=0;jQuery('a.addComicLink.normalBtn').each(function(){if($(this).html()==%22Add%20Comic%22){changed++;$(this).click();}});return%20changed;}var%20run=0;addAllVisible();clickAllNextButtons();while(addAllVisible()%3E%200){clickAllNextButtons();}})();
@lgladdy
lgladdy / quizup.js
Created January 1, 2014 20:10
QuizUp Bookmarklet for profile stats
javascript:(function()%7Bvar%20total%20%3D%20wins%20%3D%20draws%20%3D%20losses%20%3D%200%3Bconsole.log(wins)%3B%24('.wins').each(function()%20%7Bwin%20%3D%20parseInt(%24(this).html())%3Bif%20(isNaN(win))%20return%3Bwins%20%2B%3D%20win%3Btotal%20%2B%3D%20win%3B%7D)%3B%24('.draws').each(function()%20%7Bdraw%20%3D%20parseInt(%24(this).html())%3Bif%20(isNaN(draw))%20return%3Bdraws%20%2B%3D%20draw%3Btotal%20%2B%3D%20draw%3B%7D)%3B%24('.losses').each(function()%20%7Bloss%20%3D%20parseInt(%24(this).html())%3Bif%20(isNaN(loss))%20return%3Blosses%20%2B%3D%20loss%3Btotal%20%2B%3D%20loss%3B%7D)%3Balert(%22Total%20wins%3A%20%22%2Bwins%2B%22%5Cr%5CnTotal%20draws%3A%20%22%2Bdraws%2B%22%5Cr%5CnTotal%20losses%3A%20%22%2Blosses%2B%22%5Cr%5CnTotal%20games%3A%20%22%2Btotal)%7D)()
@lgladdy
lgladdy / composer.json
Last active March 12, 2016 20:06
An example laravel 5.2 composer.json that supports the Mondo API inside orison's oauth-5-laravel. Note the repositories key, and the "dev-master as 0.3" for lusitanian/oauth. Update, then follow lusitanian/oauth's docs.
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"lusitanian/oauth": "dev-master as 0.3",
@lgladdy
lgladdy / PHP-Hex-To-CIE.php
Created May 18, 2014 18:05
Converts a hex color value to a hue-compatible CIE-space-based x, y and brightness.
<?php
$hex = 'ff00ff';
$rgb = hex2rgb($hex);
$xybri = rgbToXyBri($rgb);
echo $hex.' becomes x:'.$xybri['x'].', y: '.$xybri['y'].' and brightness: '.$xybri['bri'];
function rgbToXyBri($rgb) {
$r = $rgb['r'];
$g = $rgb['g'];
function get_responsive_image_tag_for_attachment($attachment_id, $requested_size) {
$data = get_responsive_image_sizes_for_size($requested_size);
$srcset = [];
foreach($data as $image) {
$image_data = wp_get_attachment_image_src($attachment_id, $image);
if ($requested_size == $image) {
$src = $image_data[0];
}
$srcset[] = $image_data[0].' '.$image_data[1].'w';
}
@lgladdy
lgladdy / hello-taylor.php
Last active August 29, 2016 18:15
A WordPress plugin to replace Hello Dolly lyrics with the infinitely better Taylor Swift.
<?php
/*
Plugin Name: Hello Taylor
Plugin URI: https://gist.github.com/lgladdy/9e1a7303c6a6bf43b9b1
Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in <strike>two</strike> words sung most famously by <strike>Louis Armstrong: Hello, Dolly.</strike>Taylor Swift. When activated you will randomly see a lyric from <strike><cite>Hello, Dolly</cite></strike><cite>Taylor Swift</cite> in the upper right of your admin screen on every page.
Author: Liam Gladdy (based on Hello Dolly by Matt Mullenweg)
Version: 1.1
Author URI: http://www.twitter.com/lgladdy & http://ma.tt/
*/
@lgladdy
lgladdy / wrap_jetpack_sharing.php
Created September 28, 2017 13:03
If you're using a build process to manage compilation of multiple javascript files on WordPress and getting errors from jetpack's sharing JS because jQuery isn't ready yet, you can use the following to wrap it in a handler which only inits after the DOM is ready
add_action('wp_footer', 'wrap_jetpack_sharing', 18);
function wrap_jetpack_sharing() {
global $wp_scripts;
$a = $wp_scripts->get_data('sharing-js','after');
$data = 'document.addEventListener( "DOMContentLoaded", function() { ';
$data .= implode("\n", $a);
$data .= ' }, false );';
$script[] = $data;