Skip to content

Instantly share code, notes, and snippets.

View cyberhobo's full-sized avatar

Dylan Kuhn cyberhobo

View GitHub Profile
<?php
require __DIR__ . '/vendor/autoload.php';
use JangoBrick\SVG\SVGImage;
$image = SVGImage::fromFile('test.svg');
$image->getDocument()->setAttribute( 'viewBox', '20 20 200 200' );
@cyberhobo
cyberhobo / freemius-api-client.rb
Created December 19, 2016 23:09
Basis for a Ruby Freemius HTTP API client.
module Freemius
API_HOST = 'api.freemius.com'
SANDBOX_HOST = 'sandbox-api.freemius.com'
class Base
# Options taken from http://docs.freemius.apiary.io/#introduction/the-authentication-header
# * host Default is api.freemius.com
# * api_version Default is v1
# * scope_entity Default is 'plugin'. Could also be 'developer', 'install', 'site', 'user'
# * scope_entity_id Required.
@cyberhobo
cyberhobo / pantheon-wp-mu-cache-exception.php
Last active June 9, 2021 15:25
Example of excluding a couple of checkout pages from Pantheon caching in a WordPress must-use plugin:
<?php
if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ) :
// Disable caching on checkout pages as per https://pantheon.io/docs/cache-control/
$regex_path_match = '#/foundation/donation-options/(checkout|shopping-cart)#';
if (preg_match($regex_path_match, $_SERVER['REQUEST_URI'])) {
// Use a later priority to make sure it runs after native Pantheon caching
add_action( 'send_headers', 'cth_add_header_nocache', 50 );
<div id="comments" class="comment-digest padded" style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6; margin: 25px 0 10px; padding: 5px 25px">
<div class="comment even thread-even depth-1 contextual" style="clear: left; font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: normal; margin: 0; min-height: 55px; padding: 0">
<div class="comment-header" style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6; margin: 0 0 20px; padding: 0">
<img alt="" src="http://1.gravatar.com/avatar/a1f4264de732063c7f18ba9c9b8133c6?s=96&amp;d=mm&amp;r=g" srcset="http://1.gravatar.com/avatar/a1f4264de732063c7f18ba9c9b8133c6?s=192&amp;d=mm&amp;r=g 2x" class="avatar avatar-96 photo" height="96" width="96" style="-ms-interpolation-mode: bicubic; border-radius: 5px; display: block; float: left; font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-s
<?php
function postmatic_multiauthor_remove_single_filter() {
if ( ! class_exists( 'Postmatic_Multi_Author' ) ) {
return;
}
remove_filter(
'prompt/subscribe_widget_object',
array( Postmatic_Multi_Author::get_instance(), 'filter_subscribe_widget_object' )
);
}
@cyberhobo
cyberhobo / wp-get-widget-instance.php
Created May 15, 2015 22:48
Get a WordPress registered widget instance settings.
<?php
function get_widget_instance( $widget_id ) {
global $wp_registered_widgets;
if ( empty( $wp_registered_widgets[$widget_id]['callback'] ) )
return array();
/** @var WP_Widget $widget */
$widget = $wp_registered_widgets[$widget_id]['callback'][0];
@cyberhobo
cyberhobo / qa-customize-text.php
Created April 13, 2015 17:38
Customize Postmatic text
<?php // Cusomtize translated text
function qa_customize_text( $custom, $original, $domain ) {
if ( 'Postmatic' != $domain )
return $custom;
if ( 'Participate in this conversation via e-mail' != $original )
return $custom;
return 'Subscribe to comments on this';
<?php
// First, read the reads
$materials = wp_get_post_terms( get_the_ID(), 'acme_materials' );
$child_count = array_reduce( $materials, function( $count, $material ) {
return $count + count( get_term_children( $material->term_id, 'acme_materials' ) );
});
if ( $child_count > 0 ) {
// Some term has children
} else {
@cyberhobo
cyberhobo / spam.json
Created December 30, 2014 04:28
Samples of comment spam
[
{
"comment_post_ID": "11",
"comment_parent": "0",
"akismet_comment_nonce": "9552459621",
"ak_js": "154",
"submit": "Post Comment",
"author": "nike air max shox pas cher",
"email": "[email protected]",
"url": "http:\/\/www.elegantladies.org\/?shop=nike-air-max-shox-pas-cher&id=3100",
@cyberhobo
cyberhobo / 0_reuse_code.js
Last active August 29, 2015 14:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console