Skip to content

Instantly share code, notes, and snippets.

View rmccue's full-sized avatar

Ryan McCue rmccue

View GitHub Profile
@rmccue
rmccue / gist:5727154
Created June 7, 2013 04:57
Add support for privately published achievements See https://github.com/paulgibbs/achievements/issues/34
diff --git a/plugins/achievements/includes/core/functions.php b/plugins/achievements/includes/core/functions.php
index 3ccd9e7..97e1c76 100644
--- a/plugins/achievements/includes/core/functions.php
+++ b/plugins/achievements/includes/core/functions.php
@@ -212,7 +212,7 @@ function dpa_handle_event() {
'ach_populate_progress' => $user_id, // Fetch Progress posts for this user ID
'no_found_rows' => true, // Disable SQL_CALC_FOUND_ROWS
'nopaging' => true, // No pagination
- 'post_status' => 'publish', // We only want active achievements
+ 'post_status' => 'any', // We only want published/private achievements, but need to compensate (see below)
@rmccue
rmccue / gist:4584739
Last active December 11, 2015 10:08 — forked from pippinsplugins/gist:4583339
Code Golf!
<?php
//get the review type based on page custom meta field
function oswc_get_review_meta($postid) {
//try every reasonble conceivable variation that the user my enter to make this as user friendly as possible
$possible = array(
'Review Type',
'review type',
'reviewtype',
'Reviewtype',
@rmccue
rmccue / WPAPI-example-client.php
Last active December 10, 2015 13:19
Example client for v0.0.3-soalphaithurts of the WP JSON API at https://gist.github.com/5022591d312952d1245a
<?php
include './Requests.php';
Requests::register_autoloader();
header('Content-Type: text/plain');
class WPAPI {
public $base = '';
protected $collections = array();
include pear
####
# Make sure we're up-to-date
####
exec { "apt-update":
command => "/usr/bin/apt-get update",
}
class { 'mysql::server':
config_hash => { 'root_password' => 'password' },
}
mysql::db { 'store':
user => 'root',
password => 'password',
host => 'localhost',
grant => ['all'],
sql => '/vagrant/baikonur/schema.sql',
require => Class['mysql::server']
<?php
if (function_exists('get_called_class')) {
$class = get_called_class();
}
else {
$backtrace = debug_backtrace();
$num = count($backtrace);
for ($i = 0; $i < $num; $i++) {
// Ignore the current class, as it's abstract and is never called
if (!empty($backtrace[$i]['class']) && $backtrace[$i]['class'] !== __CLASS__) {
// http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
// http://gist.github.com/raw/63002/b53853727856bad494dcbb7ffed4fc17f289af92/gistfile1.rb
// $z is the pnormaldist with power = 0.05. I.e., pnormaldist(1-power/2)
function score($pos, $n) {
if ($n == 0) { return 0; }
$z = 1.95996397158435;
$phat = 1.0*$pos/$n;
return ($phat + $z*$z/(2*$n) - $z * sqrt(($phat*(1-$phat)+$z*$z/(4*$n))/$n))/(1+$z*$z/$n);
}
@rmccue
rmccue / gist:2634408
Created May 8, 2012 11:42
WordPress problem? Any ideas
<?php
// Querying hundreds of products, limiting to 25 per page
query_posts(array(
'post_type' => 'wpsc-product',
'author' => $user->ID,
'post_status' => 'any',
'paged' => get_query_var('paged'),
'posts_per_page' => 25,
));
import imp
import os.path
import inspect
from collections import defaultdict
def get_classes_from_file(filename):
name, _ = os.path.splitext(os.path.basename(filename))
fp = file(filename)
module = imp.load_module(name, fp, filename, ('.py', 'U', imp.PY_SOURCE))
@rmccue
rmccue / gist:1936664
Created February 29, 2012 00:57
Update Python to 2.7 on OSX 10.6
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
brew install python
# /usr/bin is higher in PATH than /usr/local/bin, so you need to do this to ensure `python` is the right one
sudo mv /usr/bin/python /usr/bin/python-old