Skip to content

Instantly share code, notes, and snippets.

@lgladdy
lgladdy / twitter-application-only-auth.php
Created March 12, 2013 09:46
A working example of Twitter's new application-only auth, written in PHP.
<?php
//This is all you need to configure.
$app_key = '';
$app_token = '';
//These are our constants.
$api_base = 'https://api.twitter.com/';
$bearer_token_creds = base64_encode($app_key.':'.$app_token);
@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 / banes-ishare.php
Last active May 27, 2018 20:46
BANES Council Data from iShare
$pc = 'ba11be';
//HACKY HACKY. GET the first properly in the postcode.
$url = 'http://isharemaps.bathnes.gov.uk/getdata.aspx?service=LocationSearch&RequestType=LocationSearch&location='.$pc.'&pagesize=1&startnum=1';
$data = json_decode(file_get_contents($url),true);
$x = $data['data'][0][4];
$y = $data['data'][0][5];
$id = $data['data'][0][0];
@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 / grunt-sitemap.php
Created April 13, 2014 14:25
Grunt Sitemap Generator plugin for Wordpress
<?php
/**
* Plugin Name: Grunt Sitemap Generator
* Plugin URI: http://www.github.com/lgladdy
* Description: Generate a JSON list of every page on a site so it can be used with grunt and uncss. Create a folder in /wp-content called mu-plugins, and drop this code into that folder, as grunt-sitemap.php
* Author: Liam Gladdy
* Author URI: http://gladdy.co.uk
* Version: 1.0
*/
@lgladdy
lgladdy / _wordpress_core.scss
Created April 13, 2014 19:02
WordPress Core Styles in SASS
/* =WordPress Core - Sassified.
-------------------------------------------------------------- */
.alignnone {
margin: 5px 20px 20px 0;
}
.aligncenter, div.aligncenter {
display: block;
margin: 5px auto 5px auto;
}
@lgladdy
lgladdy / gruntfile
Created May 13, 2014 08:07
This is the gruntfile that powers gladdy.co.uk. It's for the blog post here: http://www.gladdy.co.uk/blog/2014/04/13/using-uncss-and-grunt-uncss-with-wordpress/
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
sourceMap: true,
sourceMapIncludeSources: true,
sourceMapIn: 'js/app.coffee.js.map'
},
@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'];
@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) ) {