Skip to content

Instantly share code, notes, and snippets.

@yegnold
yegnold / test.php
Created December 18, 2015 15:35
Quick Pagepost redirect plugin optimisation
<?php
// OLD QUERY, 0.525s:
$finalSQL = "SELECT * FROM {$wpdb->prefix}postmeta as `m1` WHERE {$whereSQL} m1.post_id IN ( SELECT post_id FROM {$wpdb->prefix}postmeta as `m` WHERE 1 = 1 AND m.meta_key ='_pprredirect_active' AND m.meta_value = '1');";
// NEW query, 0.0007s:
$finalSQL = "SELECT m1.* FROM {$wpdb->prefix}postmeta as `m1` INNER JOIN {$wpdb->prefix}postmeta as `m` WHERE 1 = 1 AND m.meta_key ='_pprredirect_active' AND m.meta_value = '1' AND m.post_id = m1.post_id";
@yegnold
yegnold / gist:8208710
Last active January 1, 2016 22:19
An example of how I'm trying to verify that sometimes() is called twice using Laravel's testing stuff
<?php
class ValidatableModelTest extends TestCase {
public $validatable_model;
public function setUp() {
$this->validatable_model = new ValidatableModel;
}
/**
@yegnold
yegnold / gist:7371340
Created November 8, 2013 13:54
For cole henley, not tested, probably errors all over the place, but this was my general approach
function add_all_integers(i) {
// i is an array that might contain arrrays, integers, strings, add all integers within it
var total = 0;
function add_iterate(item) {
for(var counter=0;counter<item.length;counter++) {
if(typeof item[counter] == 'object') {
add_iterate(item[counter]);
} else if(typeof item[counter] == 'number') {
@yegnold
yegnold / gist:5901983
Last active December 19, 2015 05:09
Helping @cole007 get a htaccess rewrite rule working
RewriteEngine On
# add-ons rewrite rule. Note absence of slash in "rewrite to" (second portion of rewriterule)
# this makes the rewrite relative to the directroy of the .htaccess file unless RewriteBase is defined
RewriteRule ^add-ons/apps/([a-zA-Z0-9-/]+)$ add-ons/apps.php?s=$1 [L]
# The "most generic" rule comes last, as "more specific" rules should match first.
# Added a check to see if we've already got .php in the URL.
RewriteCond %{REQUEST_URI} !.php$
RewriteRule ^(.+)$ $1.php [L,QSA]