Skip to content

Instantly share code, notes, and snippets.

View staylor's full-sized avatar
💭
GitHub is not a social network

Scott Taylor staylor

💭
GitHub is not a social network
View GitHub Profile
@staylor
staylor / Balls.php
Created April 3, 2012 00:41
Debugs horribly-encoded currency symbols stored inside serialized arrays which won't deserialize
<?php
require( '../wordpress/wp-load.php' );
if ( !class_exists( 'IXR_Client' ) ) {
require( '../wordpress/wp-includes/class-IXR.php' );
}
function repair_strlen( $ser ) {
return preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $ser );
}
@staylor
staylor / KillMe.php
Created April 6, 2012 22:01
This is the kind of annoying as fuck structured data I have to support for legacy Registration and Pitch configs
<?php
class LegacyOfferConfig extends eMusicPostTypes implements PostType {
var $post_type;
var $boxes;
var $lists;
var $qas;
function init() {
$this->post_type = 'legacy_offer_config';
@staylor
staylor / Love.php
Created April 10, 2012 03:40
I found this
<?php
$me = new Lover;
$me->partner = $you;
$me->feelings = array('adore','miss','want','love');
foreach ($feelings as $feeling) {
$me->express_feeling($feeling);
@staylor
staylor / ajax.js
Created April 16, 2012 17:48
a re-write of how eMusic handles site-wide AJAX
/*globals window, document, $, jQuery */
(function ($) {
"use strict";
var loaded = false,
hashbang = '#!',
anychar = '.*?',
the_hash,
lastPath,
thePath,
@staylor
staylor / balls.js
Created April 16, 2012 18:06
The old one
/*
Please do not edit this file directly (unless you intend to fork).
It's been open-sourced here:
http://github.com/dgouldin/django-hashsignal
Requires
* jQuery hashchange event - v1.2 - 2/11/2010
* http://benalman.com/projects/jquery-hashchange-plugin/
*/
/*globals ActiveXObject, _gaq, window, jQuery */
@staylor
staylor / comment-count.php
Created April 20, 2012 19:09
Get the actual number of comments + replies per page, WP comments_per_page is really top-level comments only: allows you to identify 1-12 of 13, etc for comments count UI instead of mistakenly labeling page 1 as 1-10
<?php
function get_cpage_comment_count() {
$counter = $start = 0;
wp_list_comments( array( 'callback' => function ( $comment ) use ( &$counter, &$start ) {
global $wpdb;
if ( 0 === $counter ) {
$sql = $wpdb->prepare(
"SELECT COUNT(comment_ID) FROM {$wpdb->comments}
WHERE comment_approved = 1 AND
@staylor
staylor / wp_ajax_autocomplete_site-patch.php
Created June 4, 2012 19:43
wp_ajax_autocomplete_site
<?php
function wp_ajax_autocomplete_site() {
if ( ! is_multisite() || ! current_user_can( 'manage_sites' ) || wp_is_large_network( 'sites' ) )
wp_die( -1 );
$return = array();
global $wpdb;
$value = stripslashes( $_REQUEST['term'] );
@staylor
staylor / facebook-dialog.php
Created June 6, 2012 22:23
Load barebones for Facebook OAuth handshake
<?php
/**
* Set DOING_AJAX so the app doesn't try to set eMusic cookies
*
*/
define( 'DOING_AJAX', 1 );
define( 'SHORTINIT', 1 );
require( $_SERVER['DOCUMENT_ROOT'] . '/wordpress/wp-load.php' );
require( WP_CONTENT_DIR . '/mu-plugins/emusic-auth.php' );
@staylor
staylor / baller.css
Created June 13, 2012 21:41
Paste these into the Custom CSS box
#access {
background:#2b2b2b;
background:-moz-linear-gradient(#2b2b2b,#2b2b2b);
background:-o-linear-gradient(#2b2b2b,#2b2b2b);
background:-webkit-gradient(linear,0% 0%,0% 100%,from(#252525),to(#2b2b2b));
background:-webkit-linear-gradient(#2b2b2b,#2b2b2b);
}
.singular .hentry {
padding:0;
@staylor
staylor / house-ad.php
Created July 10, 2012 19:15
Multi-Armed Bandit
<?php
class HouseAd extends ModuleType {
const TYPE_QUERY_STRING = 0;
const TYPE_URL_PATH = 1;
const TYPE_COOKIE = 2;
const OPERATOR_EQUALS = 100;
const OPERATOR_NOT_EQUALS = 101;
const OPERATOR_GTE = 102;
const OPERATOR_LTE = 103;