Skip to content

Instantly share code, notes, and snippets.

View kingkool68's full-sized avatar
💻
Coding.

Russell Heimlich kingkool68

💻
Coding.
View GitHub Profile
<?php
/*
Plugin Name: Pew Scripts
Description: Scripts that are used on multiple sites can be registered and maintained in one place through this plugin.
Version: 1.2
Author: Russell Heimlich
Author URI: http://www.russellheimlich.com
*/
function pew_register_global_scripts() {
function chris_coyiers_super_awesome_feed_image_magic( $content ) {
$doc = new DOMDocument();
$doc->LoadHTML( $content );
$images = $doc->getElementsByTagName('img');
foreach ($images as $image) {
// Set the new attribute.
$image->setAttribute( 'style', 'max-width:480px;' );
}
@kingkool68
kingkool68 / Pew Research Archive listing to CSV
Created April 21, 2014 18:58
Download the URL, title, and date for all of the posts on a given archive page URL such as http://www.pewresearch.org/category/publications/fact-tank/project/u-s-politics/2014/pages/all/ Copy and paste this into the Console of the developer tools.
jQuery( document ).ready( function($) {
var csv = "data:text/csv;charset=utf-8,";
var csvData = [];
$('#content .post').each(function() {
$this = $(this);
csvData.push( [this.href, $this.find('h2').text(), $this.find('.meta span:last-of-type').text() ] );
});
for( i=0; i < csvData.length; i++ ) {
var row = '"' + csvData[i].join('","') + '"';

Keybase proof

I hereby claim:

  • I am kingkool68 on github.
  • I am kingkool68 (https://keybase.io/kingkool68) on keybase.
  • I have a public key whose fingerprint is 23B6 C578 8286 FD7B 9E83 4C10 3B56 93AA 987B D9BF

To claim this, I am signing this object:

@kingkool68
kingkool68 / facebook-connect.php
Created August 22, 2014 14:42
Makes it easy for your site to use Facebook Connect, Google Connect, in a wholly modular way. Based on Simple Facebook Connect (http://ottopress.com/wordpress-plugins/simple-facebook-connect/) by Otto
<?php
/*
* Base
*
*/
// basic XFBML load into footer
function psc_fb_load_args() {
/*
global $sfc_comm_comments_form;
<?php
/**
* Plugin Name: Only Certain Logins Allowed
* Description: Only let certain usernames do anything...
* Version: 1.0
* Author: Russell Heimlich
* Author URI: https://twitter.com/kingkool68
*/
function only_certain_logins_allowed() {
@kingkool68
kingkool68 / gist:864a087b0b10cffde677
Last active August 29, 2015 14:16
Basic GET request from Uber's API
<?php
/* Short and sweet */
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
$url = 'https://api.uber.com/v1/estimates/price';
$args = array(
/*
'headers' => array(
'Authorization' => $some_token_goes_here
@kingkool68
kingkool68 / footnotes.php
Last active August 29, 2015 14:21
Simple WordPress Footnotes
<?php
function api_footnotes( $content ) {
$post_id = get_the_ID();
//Need to correct wpautop() which smart-quoteify's the " in the numoffset argument.
$content = preg_replace('/numoffset=&#8221;(\d+)&#8243;/i', 'numoffset="$1"', $content);
//Microsoft has some weird space characters that Mac/Unix systems don't have. What the next line does is replace the weird space characters with a real space character which makes the regex work...
$content = str_replace('[ref ', '[ref ', $content);
@kingkool68
kingkool68 / interactive-unauthorized-immigrants-2012.php
Created September 1, 2015 15:27
The code that powers http://www.pewhispanic.org/interactives/unauthorized-immigrants-2012/ a hybrid (frontend + backend) interactive data visualization.
<?php
function unauthorized_immigrants_enqueue_scripts() {
wp_enqueue_script( 'highmaps-us' );
if( !is_iframe() ) {
wp_enqueue_script( 'pew-sortable-tables' );
}
pew_interactives_enqueue_style( 'interactive-unauthorized-immigrants-2012' ); //Two interactives share the same CSS file.
}
add_action( 'pew_interactive_styles', 'unauthorized_immigrants_enqueue_scripts', 11 );
@kingkool68
kingkool68 / wordpress-environment-conditionals.php
Created October 12, 2015 18:23
WordPress helper conditionals to run code in certain environments.
<?php
/**
* Helper conditionals to run code in certain environments.
*/
if ( ! defined( 'RH_ENV' ) ) {
$hostname = $_SERVER['HTTP_HOST'];
if ( isset( $_SERVER['HTTP_X_FORWARDED_HOST'] ) && ! empty( $_SERVER['HTTP_X_FORWARDED_HOST'] ) ) {
$hostname = $_SERVER['HTTP_X_FORWARDED_HOST'];
}