Skip to content

Instantly share code, notes, and snippets.

View RadGH's full-sized avatar

Radley Sustaire RadGH

View GitHub Profile
@RadGH
RadGH / gtarating.js
Last active August 29, 2015 14:24
Add ratings to GTA5 Social Club map browser (List view only)
var ratingToInt = function( str ) {
// numstr = ' 18.6k '
str = str.trim(); // "18.6k"
var number = parseFloat(str); // 18.6
var letter = str.replace(/[^kmb]/g, '');//"k"
switch( letter ) {
case 'k':
number = number * 1000;
@RadGH
RadGH / gta5rating-bookmarklet.js
Last active August 29, 2015 14:24
GTA5 Social Club Rating Bookmarklet
javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){var ratingToInt=function(t){t=t.trim();var e=parseFloat(t),i=t.replace(/[^kmb]/g,"");switch(i){case"k":e=1e3*e;break;case"m":e=1e6*e}return parseInt(e)},ratingsGetValues=function(t){var e=t.children("li");if(e.length<3)return!1;var i={up:ratingToInt(e.eq(0).text()),down:ratingToInt(e.eq(1).text()),play:ratingToInt(e.eq(2).text())};return i.rating=(i.up-i.down)/i.up,i},updateList=function(){var t=jQuery("#search-results-list"),e=t.find("tr.mission-result-text");e.each(function(){var t=jQuery(this),i=t.find("ul.ratings");if(!(i.find("li.percent").length>0)){var a=ratingsGetValues
@RadGH
RadGH / convert-term.php
Created July 22, 2015 07:24
Magic term conversion with WordPress
<?php
/*
Takes a term from many input types: object, id, slug, name
Returns one of many outputs: WP_Term (object), id (int), slug, name, or any WP_Term property
Example Inputs:
smart_term_convert( 390, 'category', 'id' ); // Returns 390
smart_term_convert( 'test-category', 'category', 'id' ); // Returns 390
smart_term_convert( 'Test Category', 'category', 'id' ); // Returns 390
@RadGH
RadGH / curl_get_post_url.php
Last active August 29, 2015 14:26
Perform a POST request using curl as a function, with arguments as an array
<?php
/**
* Example Usage
*/
$url = 'http://example.org/';
$vars = array(
'name' => 'Radley',
'awesome' => 1,
);
@RadGH
RadGH / yarp-template-image-previews.php
Created August 3, 2015 22:37
Yet Another Related Posts Plugin (YARPP) - Template with post thumbnails and better markup
<?php
/*
YARPP Template: Image Previews
Description: Four columns of posts, each with a photo.
Author: radgh (RadleyGH@gmail.com)
*/
// Put your placeholder image ID here, from the media tab in the dashboard, or leave it false to disable.
$placeholder_media_id = false;
{
"kind": "metapackage",
"abstract": "A list of modules installed on the default KSP instance",
"name": "installed-default",
"license": "unknown",
"version": "2015.10.23.04.07.26",
"identifier": "installed-default",
"spec_version": "v1.6",
"depends": [
{
@RadGH
RadGH / image-sizes.php
Created November 16, 2015 17:45
define & use custom image sizes
<?php
// $src = wp_get_attachment_image_src( $attachment_id, 'store-archive' );
// $src[0] = "http://.../uploads/my_image-240x350.jpg"
// $src[1] = 240
// $src[2] = 350
add_action( 'after_setup_theme', 'ld_theme_image_sizes' );
function ld_theme_image_sizes() {
// archive pages
@RadGH
RadGH / gist:5556174
Last active December 17, 2015 05:09
MySQL/Wordpress: Select number of posts by month/year/day/etc, optionally filtered by category
-- Select the count of posts grouped by year, month, day, hour, even minutes and seconds!
SELECT
-- Number of posts on the specified time range
COUNT(*) as "count",
-- Time values to return
-- These should also be listed under "group by"
-- If sorting is necessary, also include these in "order by"
YEAR(p.post_date) as "year",
MONTH(p.post_date) as "month",
@RadGH
RadGH / gist:5556804
Last active December 17, 2015 05:19
Convert parts of a string to date components, noted by a percent sign (%)
<?php
/* ----------------------------
Parse a string with percent-signed wildcards, where the wildcards are PHP date characters.
Example:
$string = "Today is %F %j%S"
Returns: Today is January 1st
*/
function parse_date($string, $date = false) {
if ( !$date ) $date = time();
@RadGH
RadGH / gist:5952163
Last active December 19, 2015 11:59
Change the default "From" address for Wordpress.
<?php
function change_wp_mail_sender( $phpmailer ) {
$from_name = 'My Website';
$from_email = get_option('admin_email'); // The same email seen in Settings > General
if (
// We should always have these parameters, but it doesn't hurt to avoid errors in the future
property_exists( $phpmailer, 'From' )
&& property_exists( $phpmailer, 'FromName' )